-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathskeleton.py
69 lines (54 loc) · 1.29 KB
/
skeleton.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
64
65
66
67
68
69
#!/usr/bin/env python2
from pwn import *
import sys
argv = sys.argv
DEBUG = False
BINARY = './binary'
context.binary = BINARY
context.terminal = ['tmux', 'splitw', '-v']
if context.bits == 64:
r = process(['ROPgadget', '--binary', BINARY])
gadgets = r.recvall().strip().split('\n')[2:-2]
gadgets = map(lambda x: x.split(' : '),gadgets)
gadgets = map(lambda x: (int(x[0],16),x[1]),gadgets)
r.close()
pop_rdi = 0
pop_rsi_r15 = 0
pop_rdx = 0
for addr, name in gadgets:
if 'pop rdi ; ret' in name:
pop_rdi = addr
if 'pop rsi ; pop r15 ; ret' in name:
pop_rsi_r15 = addr
if 'pop rdx ; ret' in name:
pop_rdx = addr
def call(f, a1, a2, a3):
out = ''
if a1 != None:
out += p64(pop_rdi)+p64(a1)
if a2 != None:
out += p64(pop_rsi_r15)+p64(a2)*2
if a3 != None:
if pop_rdx == 0:
print 'RDX GADGET NOT FOUND'
exit(-1)
else:
out += p64(rdx)+p64(a3)
return out+p64(f)
def attach_gdb():
gdb.attach(sh)
if DEBUG:
context.log_level = 'debug'
def start():
global sh
if len(argv) < 2:
stdout = process.PTY
stdin = process.PTY
sh = process(BINARY, stdout=stdout, stdin=stdin)
# if DEBUG:
# attach_gdb()
REMOTE = False
else:
sh = remote('IP', 1337)
REMOTE = True
start()