Skip to content

Commit 559296d

Browse files
committed
Add hitcon-2020
1 parent 9500cf8 commit 559296d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+18557
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,18 @@ These challenges are created by me so there're scripts for creating them.
154154
* Suicune (rev 305pts)
155155
* heXDump (misc 202pts)
156156

157+
## hitcon-2020
158+
159+
These challenges are created by me so there're scripts for creating them.
160+
161+
* Revenge of Pwn (misc, pwn 255pts)
162+
* Tenet (misc, rev 222pts)
163+
* spark (pwn 334pts)
164+
* atoms (misc, pwn 296pts)
165+
* SOP (rev 305pts)
166+
* 11011001 (rev 255pts)
167+
168+
157169
## meepwnctf-2018
158170

159171
* Coin (pwn 960pts)

hitcon-2020/11011001/Makefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
all: src release
2+
3+
src: .PHONY
4+
$(MAKE) -C src
5+
6+
release: src .PHONY
7+
cp src/chal release/
8+
9+
.PHONY:

hitcon-2020/11011001/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# 11011001 [255pts]
2+
3+
0100111001101111001000000110100001101001011011100111010000100000011010000110010101110010011001010010110000100000011101110110100001100001011101000010000001100001011100100110010100100000011110010110111101110101001000000110010101111000011100000110010101100011011101000110100101101110011001110010000001100110011011110111001000111111
4+
5+
11011001-878450f7a8f95309ce756975ce912376d829c1d7caeed7f80da72ee3bc67e5ca
6+
7+
```
8+
Author: david942j
9+
30 Teams solved.
10+
```

hitcon-2020/11011001/release/chal

9.98 KB
Binary file not shown.

hitcon-2020/11011001/sol/solve.cpp

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
// {{{ by david942j
2+
#include <bits/stdc++.h>
3+
4+
#define mpr std::make_pair
5+
#define lg(x) (31-__builtin_clz(x))
6+
#define lgll(x) (63-__builtin_clzll(x))
7+
#define __count __builtin_popcount
8+
#define __countll __builtin_popcountll
9+
#define X first
10+
#define Y second
11+
#define mst(x) memset(x,0,sizeof(x))
12+
#define mst1(x) memset(x,-1,sizeof(x))
13+
#define ALL(c) (c).begin(),(c).end()
14+
#define FOR(i,n) for(int i=0;i<n;i++)
15+
#define FOR1(i,n) for(int i=1;i<=n;i++)
16+
#define FORit(it,c) for(auto it=(c).begin();it!=(c).end();++it)
17+
#define pb push_back
18+
#define RI(x) scanf("%d",&x)
19+
#define RID(x) int x;RI(x)
20+
using namespace std;
21+
22+
typedef long long LL;
23+
typedef double LD;
24+
typedef vector<int> VI;
25+
typedef std::pair<int,int> PII;
26+
template<class T>inline void maz(T &a,T b){if(a<b)a=b;}
27+
template<class T>inline void miz(T &a,T b){if(a>b)a=b;}
28+
template<class T>inline T abs(T a){return a>0?a:-a;}
29+
30+
#ifdef DAVID942J
31+
template<typename T>
32+
void _dump( const char* s, T&& head ) { cerr<<s<<"="<<head<<endl; }
33+
34+
template<typename T, typename... Args>
35+
void _dump( const char* s, T&& head, Args&&... tail ) {
36+
int c=0;
37+
while ( *s!=',' || c!=0 ) {
38+
if ( *s=='(' || *s=='[' || *s=='{' ) c++;
39+
if ( *s==')' || *s==']' || *s=='}' ) c--;
40+
cerr<<*s++;
41+
}
42+
cerr<<"="<<head<<", ";
43+
_dump(s+1,tail...);
44+
}
45+
46+
#define dump(...) do { \
47+
fprintf(stderr, "%s:%d - ", __PRETTY_FUNCTION__, __LINE__); \
48+
_dump(#__VA_ARGS__, __VA_ARGS__); \
49+
} while (0)
50+
51+
template<typename Iter>
52+
ostream& _out( ostream &s, Iter b, Iter e ) {
53+
s<<"[";
54+
for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
55+
s<<"]";
56+
return s;
57+
}
58+
59+
template<typename A, typename B>
60+
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.first<<","<<p.second<<")"; }
61+
template<typename T>
62+
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
63+
template<typename T, size_t N>
64+
ostream& operator <<( ostream &s, const array<T,N> &c ) { return _out(s,ALL(c)); }
65+
template<typename T>
66+
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
67+
template<typename A, typename B>
68+
ostream& operator <<( ostream &s, const map<A,B> &c ) { return _out(s,ALL(c)); }
69+
#else
70+
#define dump(...)
71+
#endif
72+
73+
template<typename T>
74+
void _R( T &x ) { cin>>x; }
75+
void _R( int &x ) { scanf("%d",&x); }
76+
void _R( long long &x ) { scanf("%" PRId64,&x); }
77+
void _R( double &x ) { scanf("%lf",&x); }
78+
void _R( char &x ) { scanf(" %c",&x); }
79+
void _R( char *x ) { scanf("%s",x); }
80+
81+
void R() {}
82+
template<typename T, typename... U>
83+
void R( T& head, U&... tail ) {
84+
_R(head);
85+
R(tail...);
86+
}
87+
88+
template<typename T>
89+
void _W( const T &x ) { cout<<x; }
90+
void _W( const int &x ) { printf("%d",x); }
91+
template<typename T>
92+
void _W( const vector<T> &x ) {
93+
for ( auto i=x.cbegin(); i!=x.cend(); i++ ) {
94+
if ( i!=x.cbegin() ) putchar(' ');
95+
_W(*i);
96+
}
97+
}
98+
99+
void W() {}
100+
template<typename T, typename... U>
101+
void W( const T& head, const U&... tail ) {
102+
_W(head);
103+
putchar(sizeof...(tail)?' ':'\n');
104+
W(tail...);
105+
}
106+
107+
#define FILEIO(name) do {\
108+
freopen(name ".in","r",stdin); \
109+
freopen(name ".out","w",stdout); \
110+
} while (0)
111+
112+
// }}} end of default code
113+
114+
const int N=100010, INF=1e9;
115+
const LD EPS=1e-7;
116+
int n, m;
117+
118+
int main() {
119+
puts("350617 693097 828630 224554 629333 304811 682342 742996 370089 318099 676716 634010 340837 412886 699033 349483 183638 864940 731731 447908");
120+
121+
return 0;
122+
}
123+

hitcon-2020/11011001/src/Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
all: chal
2+
3+
chal: chal.cpp
4+
$(CXX) -o $@ $^ -O3 -lssl -lcrypto
5+
strip -s $@

hitcon-2020/11011001/src/chal

9.98 KB
Binary file not shown.

hitcon-2020/11011001/src/chal.cpp

Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
// {{{ by david942j
2+
#include <bits/stdc++.h>
3+
4+
#define mpr std::make_pair
5+
#define lg(x) (31-__builtin_clz(x))
6+
#define lgll(x) (63-__builtin_clzll(x))
7+
#define __count __builtin_popcount
8+
#define __countll __builtin_popcountll
9+
#define X first
10+
#define Y second
11+
#define mst(x) memset(x,0,sizeof(x))
12+
#define mst1(x) memset(x,-1,sizeof(x))
13+
#define ALL(c) (c).begin(),(c).end()
14+
#define FOR(i,n) for(int i=0;i<n;i++)
15+
#define FOR1(i,n) for(int i=1;i<=n;i++)
16+
#define FORit(it,c) for(auto it=(c).begin();it!=(c).end();++it)
17+
#define pb push_back
18+
using namespace std;
19+
20+
typedef long long LL;
21+
typedef double LD;
22+
typedef vector<int> VI;
23+
typedef std::pair<int,int> PII;
24+
template<class T>inline void maz(T &a,T b){if(a<b)a=b;}
25+
template<class T>inline void miz(T &a,T b){if(a>b)a=b;}
26+
template<class T>inline T abs(T a){return a>0?a:-a;}
27+
28+
#ifdef DAVID942J
29+
template<typename T>
30+
void _dump( const char* s, T&& head ) { cerr<<s<<"="<<head<<endl; }
31+
32+
template<typename T, typename... Args>
33+
void _dump( const char* s, T&& head, Args&&... tail ) {
34+
int c=0;
35+
while ( *s!=',' || c!=0 ) {
36+
if ( *s=='(' || *s=='[' || *s=='{' ) c++;
37+
if ( *s==')' || *s==']' || *s=='}' ) c--;
38+
cerr<<*s++;
39+
}
40+
cerr<<"="<<head<<", ";
41+
_dump(s+1,tail...);
42+
}
43+
44+
#define dump(...) do { \
45+
fprintf(stderr, "%s:%d - ", __PRETTY_FUNCTION__, __LINE__); \
46+
_dump(#__VA_ARGS__, __VA_ARGS__); \
47+
} while (0)
48+
49+
template<typename Iter>
50+
ostream& _out( ostream &s, Iter b, Iter e ) {
51+
s<<"[";
52+
for ( auto it=b; it!=e; it++ ) s<<(it==b?"":" ")<<*it;
53+
s<<"]";
54+
return s;
55+
}
56+
57+
template<typename A, typename B>
58+
ostream& operator <<( ostream &s, const pair<A,B> &p ) { return s<<"("<<p.first<<","<<p.second<<")"; }
59+
template<typename T>
60+
ostream& operator <<( ostream &s, const vector<T> &c ) { return _out(s,ALL(c)); }
61+
template<typename T, size_t N>
62+
ostream& operator <<( ostream &s, const array<T,N> &c ) { return _out(s,ALL(c)); }
63+
template<typename T>
64+
ostream& operator <<( ostream &s, const set<T> &c ) { return _out(s,ALL(c)); }
65+
template<typename A, typename B>
66+
ostream& operator <<( ostream &s, const map<A,B> &c ) { return _out(s,ALL(c)); }
67+
#else
68+
#define dump(...)
69+
#endif
70+
71+
template<typename T>
72+
void _W( const T &x ) { cout<<x; }
73+
void _W( const int &x ) { printf("%d",x); }
74+
template<typename T>
75+
void _W( const vector<T> &x ) {
76+
for ( auto i=x.cbegin(); i!=x.cend(); i++ ) {
77+
if ( i!=x.cbegin() ) putchar(' ');
78+
_W(*i);
79+
}
80+
}
81+
82+
void W() {}
83+
template<typename T, typename... U>
84+
void W( const T& head, const U&... tail ) {
85+
_W(head);
86+
putchar(sizeof...(tail)?' ':'\n');
87+
W(tail...);
88+
}
89+
90+
#define FILEIO(name) do {\
91+
freopen(name ".in","r",stdin); \
92+
freopen(name ".out","w",stdout); \
93+
} while (0)
94+
95+
// }}} end of default code
96+
97+
#include <openssl/sha.h>
98+
const int N=20;
99+
100+
typedef unsigned int u32;
101+
102+
static void convert(u32 brd[]) {
103+
FOR(i, N)
104+
cin >> brd[i];
105+
}
106+
107+
static inline bool three(u32 val) {
108+
// 001100
109+
FOR(_, N - 2) {
110+
if ((val & 7) == 7 || (val & 7) == 0)
111+
return false;
112+
val >>= 1;
113+
}
114+
return true;
115+
}
116+
117+
static inline u32 colval(u32 brd[], int j) {
118+
u32 val = 0;
119+
FOR(i, N) val |= ((brd[i] >> j) & 1) << i;
120+
return val;
121+
}
122+
123+
static bool check(u32 brd[]) {
124+
FOR(i, N)
125+
if (brd[i] & 0xfff00000u)
126+
return false;
127+
static pair<u32, u32> ary[N] = {
128+
{0b10000001000000000010, 0b00000001000000000000},
129+
{0b00101001000001100101, 0b00101001000001100001},
130+
{0b00000000000000000000, 0b00000000000000000000},
131+
{0b00010110110001000000, 0b00010110110000000000},
132+
{0b00100000100100000101, 0b00000000100000000101},
133+
{0b00010000001000100000, 0b00000000001000100000},
134+
{0b10011000100001101000, 0b10000000100001100000},
135+
{0b00100001000100000010, 0b00100001000000000000},
136+
{0b00000000010010010001, 0b00000000010010000001},
137+
{0b00110001000101000000, 0b00000001000000000000},
138+
{0b00000000100000000001, 0b00000000000000000000},
139+
{0b01100000010000000101, 0b00000000010000000000},
140+
{0b00001100100001100000, 0b00000000000001100000},
141+
{0b00000000010100001000, 0b00000000010000000000},
142+
{0b01000000100100000000, 0b00000000100000000000},
143+
{0b00010010001000010011, 0b00010000000000000011},
144+
{0b01000010100011000000, 0b00000000100001000000},
145+
{0b00001000010000001100, 0b00000000000000001100},
146+
{0b01000011010100000000, 0b00000010000000000000},
147+
{0b10000001000001011010, 0b00000001000000000000},
148+
};
149+
FOR(i, N)
150+
if ((brd[i] & ary[i].X) != ary[i].Y)
151+
return false;
152+
// 2. No more than two similar numbers next to or below each other are allowed.
153+
FOR(i, N)
154+
if (!three(brd[i]))
155+
return false;
156+
FOR(j, N)
157+
if (!three(colval(brd, j)))
158+
return false;
159+
// 3. Each row and each column should contain an equal number of zeros and ones.
160+
FOR(i, N)
161+
if (__count(brd[i]) != N / 2)
162+
return false;
163+
FOR(j, N)
164+
if (__count(colval(brd, j)) != N / 2)
165+
return false;
166+
// 4. Each row is unique and each column is unique.
167+
FOR(a, N)
168+
FOR(b, a)
169+
if (brd[a] == brd[b])
170+
return false;
171+
FOR(a, N)
172+
FOR(b, a)
173+
if (colval(brd, a) == colval(brd, b))
174+
return false;
175+
return true;
176+
}
177+
178+
static void print_flag(u32 brd[]) {
179+
cout << "Congratulations!" << endl;
180+
SHA256_CTX context;
181+
SHA256_Init(&context);
182+
SHA256_Update(&context, (unsigned char*)brd, N * sizeof(u32));
183+
unsigned char h[SHA256_DIGEST_LENGTH];
184+
SHA256_Final(h, &context);
185+
cout << "Here's your gift: hitcon{";
186+
FOR(i, SHA256_DIGEST_LENGTH)
187+
cout << setfill('0') << setw(2) << right << hex << (unsigned int) h[i];
188+
cout << "}" << endl;
189+
}
190+
191+
int main() {
192+
u32 brd[N] = {};
193+
convert(brd);
194+
if (check(brd))
195+
print_flag(brd);
196+
else cout << "Zzz.." << endl;
197+
return 0;
198+
}
199+

hitcon-2020/atoms/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/linux/
2+
/deploy/
3+
/disk/

0 commit comments

Comments
 (0)