-
Notifications
You must be signed in to change notification settings - Fork 3
/
Exploit.py
240 lines (231 loc) · 7.5 KB
/
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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
import pymem
import re
class Exploit:
def __init__(self,ProgramName=None):
self.ProgramName = ProgramName
self.Program = pymem.Pymem()
self.Addresses = {}
if type(ProgramName) == str:
self.Program = pymem.Pymem(ProgramName)
elif type(ProgramName) == int:
self.Program.open_process_from_id(ProgramName)
def h2d(self,hz:str) -> int:
if type(hz) == int:
return hz
return int(hz,16)
def d2h(self,dc:int) -> str:
if type(dc) == str:
return dc
if abs(dc) > 4294967295:
dc = hex(dc & (2**64-1)).replace('0x','')
else:
dc = hex(dc & (2**32-1)).replace('0x','')
if len(dc) > 8:
while len(dc) < 16:
dc = '0' + dc
if len(dc) < 8:
while len(dc) < 8:
dc = '0' + dc
return dc
def PLAT(self,aob:str):
if type(aob) == bytes:
return aob
trueB = bytearray(b'')
aob = aob.replace(' ','')
PLATlist = []
for i in range(0,len(aob), 2):
PLATlist.append(aob[i:i+2])
for i in PLATlist:
if "?" in i:
trueB.extend(b'.')
if "?" not in i:
trueB.extend(re.escape(bytes.fromhex(i)))
return bytes(trueB)
def AOBSCANALL(self,AOB_Sig,xreturn_multiple=False):
return pymem.pattern.pattern_scan_all(self.Program.process_handle,self.PLAT(AOB_Sig),return_multiple=xreturn_multiple)
def gethexc(self,hex:str):
hex = hex.replace(' ','')
hxlist = []
for i in range(0,len(hex), 2):
hxlist.append(hex[i:i+2])
return len(hxlist)
def hex2le(self, hex: str):
lehex = hex.replace(" ", "")
reniL = 0
zqSij = ""
lelist = []
for i in range(0, len(lehex), 2):
lelist.append(lehex[i : i + 2])
if len(lelist) != 4:
reniL = len(lelist) - 4
zqSij = zqSij + "0"
for i in range(0, reniL):
zqSij = zqSij + "00"
lelist.insert(0, zqSij)
if len("".join(lelist)) != 8:
lelist.insert(0, "0")
lelist.reverse()
lehex = "".join(lelist)
return lehex
def calcjmpop(self, des, cur):
jmpopc = (self.h2d(des) - self.h2d(cur)) - 5
jmpopc = hex(jmpopc & (2**32 - 1)).replace("0x", "")
if len(jmpopc) % 2 != 0:
jmpopc = "0" + str(jmpopc)
return jmpopc
def isProgramGameActive(self):
try:
self.Program.read_char(self.Program.base_address)
return True
except:
return False
def DRP(self,Address:int) -> int:
Address = Address
if type(Address) == str:
Address = self.h2d(Address)
return int.from_bytes(self.Program.read_bytes(Address,4),'little')
def isValidPointer(self,Address:int) -> bool:
try:
if type(Address) == str:
Address = self.h2d(Address)
self.Program.read_bytes(self.DRP(Address),1)
return True
except:
return False
def HookAddressBase(self,AccessLocation,AccessLocationBytes,movOP):
mem = self.Program
BaseAddress = 0
OriginalHexArray = bytes.hex(self.Program.read_bytes(AccessLocation,AccessLocationBytes))
BaseAddressA = mem.allocate(4)
newmem = mem.allocate(256)
BAOP = movOP + self.hex2le(self.d2h(BaseAddressA))
hookLoc = AccessLocation
returnJmp = 'E9' + self.hex2le(self.calcjmpop(self.d2h(hookLoc + (self.gethexc(OriginalHexArray))),self.d2h(newmem + (self.gethexc(BAOP + OriginalHexArray)))))
newmemArrayW = BAOP + OriginalHexArray + returnJmp
mem.write_bytes(newmem,bytes.fromhex(newmemArrayW),self.gethexc(newmemArrayW))
mem.write_bytes(hookLoc,bytes.fromhex('E9 ' + self.hex2le(self.calcjmpop(self.d2h(newmem),self.d2h(hookLoc)))),AccessLocationBytes)
BaseAddress = mem.read_int(BaseAddressA)
HookData = [BaseAddressA,newmem,BaseAddress,OriginalHexArray,AccessLocation]
return HookData
def UnHookAddressBase(self,HookData):
self.Program.write_bytes(HookData[4],bytes.fromhex(HookData[3]),self.gethexc(HookData[3]))
self.Program.free(HookData[0])
self.Program.free(HookData[1])
return HookData[4]
def YieldForHookA(self,AAP,amount = 0.5,bounds = 50):
looped = 0
while self.Program.read_int(AAP) == 0:
if looped > bounds:
print("Outside maximum loop allowed.")
return False
time.sleep(amount)
looped += 1
return True
def GetModules(self) -> list:
return list(self.Program.list_modules())
def getAddressFromName(self,Address:str) -> int:
if type(Address) == int:
return Address
AddressBase = 0
AddressOffset = 0
for i in self.GetModules():
if i.name in Address:
AddressBase = i.lpBaseOfDll
AddressOffset = self.h2d(Address.replace(i.name + '+',''))
AddressNamed = AddressBase + AddressOffset
return AddressNamed
print("Unable to find Address: " + Address)
return Address
def getNameFromAddress(self,Address:int) -> str:
memoryInfo = pymem.memory.virtual_query(self.Program.process_handle,Address)
AllocationBase = memoryInfo.AllocationBase
NameOfDLL = ''
AddressOffset = 0
for i in self.GetModules():
if i.lpBaseOfDll == AllocationBase:
NameOfDLL = i.name
AddressOffset = Address - AllocationBase
break
if NameOfDLL == '':
return Address
NameOfAddress = NameOfDLL + '+' + self.d2h(AddressOffset)
return NameOfAddress
def getRawProcesses(self):
toreturn = []
for i in pymem.process.list_processes():
toreturn.append([i.cntThreads,i.cntUsage,i.dwFlags,i.dwSize,i.pcPriClassBase,i.szExeFile,i.th32DefaultHeapID,i.th32ModuleID,i.th32ParentProcessID,i.th32ProcessID])
return toreturn
def SimpleGetProcesses(self):
toreturn = []
for i in self.getRawProcesses():
toreturn.append({"Name":i[5].decode(),"Threads":i[0],"ProcessId":i[9]})
return toreturn
def YieldForProgram(self,programName,AutoOpen:bool = False,Limit = 15):
Count = 0
while True:
if Count > Limit:
print("Yielded too long, failed!")
return False
ProcessesList = self.SimpleGetProcesses()
for i in ProcessesList:
if i['Name'] == programName:
print("Found " + programName + " with Process ID: " + str(i['ProcessId']))
if AutoOpen:
self.Program.open_process_from_id(i['ProcessId'])
print("Successfully attached to Process.")
return True
print("Waiting for the Program...")
time.sleep(1)
Count += 1
def GetProcessesByName(self, Name):
result = []
for process in self.SimpleGetProcesses():
if process["Name"] == Name:
result.append(process)
def ReadStringUntilEnd(self, Address:int) -> str:
if type(Address) == str:
Address = self.h2d(Address)
if Address == 0:
return ""
CurrentAddress = Address
StringData = []
LoopedTimes = 0
while LoopedTimes < 15000:
if self.Program.read_bytes(CurrentAddress,1) == b'\x00':
break
StringData.append(self.Program.read_bytes(CurrentAddress,1))
CurrentAddress += 1
LoopedTimes += 1
String = bytes()
for i in StringData:
String = String + i
return str(String)[2:-1]
def ReadInstaceString(self, Address:int) -> str:
length = self.Program.read_int(self.DRP(Address) + 0x10)
if (length < 16 and length > 0):
return self.ReadStringUntilEnd(self.DRP(Address))
else:
return self.ReadStringUntilEnd(self.DRP(self.DRP(Address)))
def ReadNormalString(self, Address:int) -> str:
length = self.Program.read_int(Address + 0x10)
if (length < 16 and length > 0):
return self.ReadStringUntilEnd(Address)
else:
return self.ReadStringUntilEnd(self.DRP(Address))
def GetProcessIdByNameWithBiggestSize(NameOfProgram:str):
x = Exploit()
x.GetProcessesByName(NameOfProgram)
y = x.SimpleGetProcesses()
dictionaryOfData = {}
for i in y:
if i['Name'] == NameOfProgram:
x.Program.open_process_from_id(i['ProcessId'])
Size = x.Program.process_base.SizeOfImage
dictionaryOfData.update({Size:i['ProcessId']})
tempVa = 0
for i in dictionaryOfData.keys():
if i > tempVa:
tempVa = i
return dictionaryOfData.get(tempVa)
roblox = Exploit(GetProcessIdByNameWithBiggestSize('RobloxPlayerBeta.exe'))
__all__ = ["Exploit", "roblox"]