-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcruehead.py
292 lines (259 loc) · 10.1 KB
/
cruehead.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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
def help():
print("""Classes:
recon()
Methods:
.segments()==> Segments
.functions()==> Functions Name
.strings()==> Strings
.disamFunction(addr) ==> Disassembly functions
.disamString(addr) ==> Disassembly string data references to Code
.FindFunction(addr) ==> Find function through a memory address
.FindString(string)=> Find a particulary string and disasm it
discover()
Methods:
.Dbg(addr) ==> Run Debugger and set breakpoint a specific address
.staticString(string)==> Start enumeration discover through string point
.staticJump(addr,string) ==> Continue enumeration discover throught jump instruction point
.dbgCalls(addr) ==> Discover debugging calls and get value of Registers
.dbgRegisters(addr,register) ==> Discover debugging a specific Register in a particular function""")
class recon():
def __init__(self):
self.ea = BeginEA()
def segments(self):
for segments in Segments():
print idc.SegName(segments), idc.SegStart(segments), idc.SegEnd(segments)
def functions(self):
for func in Functions(SegStart(self.ea), SegEnd(self.ea)):
print(hex(func), GetFunctionName(func))
def strings(self):
sc = Strings()
for s in sc:
print "%x: len=%d type=%d --> '%s'" % (s.ea, s.length, s.type, str(s))
def disamFunction(self,addr):
func = idaapi.get_func(addr)
print "Start: 0x%x, End: 0x%x\n" % (func.startEA, func.endEA)
diss = list(FuncItems(addr))
for i in diss:
print "%x" % i , GetDisasm(i)
def disamString(self,addr):
print hex(addr), idc.GetDisasm(addr), "\n"
print("DataRefsTo:")
for a in DataRefsTo(addr):
print hex(a), GetDisasm(a)
def FindFunction(self,addr):
for seg in Segments():
for func in Functions(seg, SegEnd(seg)):
functionName = GetFunctionName(func)
for (start, end) in Chunks(func):
for head in Heads(start, end):
if hex(head)[:-1] == hex(addr):
print "Function Name: ", functionName
#, ":", hex(head)[:-1], ":", GetDisasm(head)
def FindString(self,string):
self.ea = MinEA()
end = MaxEA()
while self.ea < end:
self.ea = idc.FindText(self.ea, SEARCH_DOWN, 0, 0, string)
if self.ea == idc.BADADDR:
break
else:
if idc.isCode(idc.GetFlags(self.ea)) == True:
print "CODE: ", hex(self.ea), idc.GetDisasm(self.ea)
if idc.isData(idc.GetFlags(self.ea)) == True:
print "DATA: ", hex(self.ea), idc.GetDisasm(self.ea)
if idc.isTail(idc.GetFlags(self.ea)) == True:
print "TAIL: ", hex(self.ea), idc.GetDisasm(self.ea)
if idc.isUnknown(idc.GetFlags(self.ea)) == True:
print "UNKNOWN: ", hex(self.ea), idc.GetDisasm(self.ea)
self.ea = idc.NextHead(self.ea)
class discover():
def __init__(self):
self.ea = BeginEA()
def staticString(self,string):
self.ea = MinEA()
end = MaxEA()
while self.ea < end:
self.ea = idc.FindText(self.ea, SEARCH_DOWN, 0, 0, string)
if self.ea == idc.BADADDR:
break
else:
if idc.isCode(idc.GetFlags(self.ea)) == True:
print hex(self.ea), idc.GetDisasm(self.ea)
addr_ = hex(self.ea)
print "[+]Address: ", addr_[:-1]
for seg in Segments():
for func in Functions(seg, SegEnd(seg)):
functionName = GetFunctionName(func)
for (start, end) in Chunks(func):
for head in Heads(start, end):
if hex(head)[:-1] == addr_[:-1]:
print "[+]Function Name: ", functionName
self.ea = MinEA()
end = MaxEA()
while self.ea < end:
self.ea = idc.FindText(self.ea, SEARCH_DOWN, 0, 0, "call")
if self.ea == idc.BADADDR:
break
else:
try:
if idc.GetDisasm(self.ea) == "call "+functionName:
print "[+]Reference to call function: ", hex(self.ea),idc.GetDisasm(self.ea)
for a in CodeRefsTo(self.ea,0):
print "[+]Reference to location:\t", hex(a), GetDisasm(a)
SecondAddr_ = hex(a)
print "[+]Discover second address maybe is interesting...", SecondAddr_[:-1]
except:
if idc.GetDisasm(self.ea) != "call "+functionName:
print "Sorry it isnt called function"
#print idc.GetDisasm(self.ea)
self.ea = idc.NextHead(self.ea)
self.ea = idc.NextHead(self.ea)
def staticJump(self,addr,jump):
self.ea = MinEA()
end = MaxEA()
while self.ea < end:
self.ea = idc.FindText(self.ea, SEARCH_DOWN, 0, 0, jump)
if self.ea == idc.BADADDR:
break
else:
if idc.isCode(idc.GetFlags(self.ea)) == True:
if hex(self.ea) == hex(addr):
print hex(self.ea), idc.GetDisasm(self.ea)
addr_ = hex(self.ea)
print "[+]Address: ", addr_[:-1]
for seg in Segments():
for func in Functions(seg, SegEnd(seg)):
functionName = GetFunctionName(func)
for (start, end) in Chunks(func):
for head in Heads(start, end):
if hex(head)[:-1] == addr_[:-1]:
print "[+]Function Name: ", functionName
func = idaapi.get_func(self.ea)
print "Start: 0x%x, End: 0x%x" % (func.startEA, func.endEA)
diss = list(FuncItems(addr))
print "[+]Disassembly:"
for i in diss:
print "%x" % i , GetDisasm(i)
self.ea = idc.NextHead(self.ea)
def dbgCalls(self,addr):
count = 0
for seg in Segments():
for func in Functions(seg, SegEnd(seg)):
functionName = GetFunctionName(func)
for (start, end) in Chunks(func):
for head in Heads(start, end):
if hex(head)[:-1] == hex(addr):
print "Function Name: ", functionName
#, ":", hex(head)[:-1], ":", GetDisasm(head)
diss = list(FuncItems(addr))
print "[+]Call:"
for i in diss:
#print "%x" % i , GetDisasm(i).split()
if GetDisasm(i).split()[0] == "call":
if GetDisasm(i).split()[1][:1] == "s":
print hex(i), GetDisasm(i)
print "[+]Call %d fuction" % count
idc.GetDebuggerEvent(WFNE_SUSP,-1)
idc.RunTo(i)
idc.AddBpt(i) #breakpoint
idaapi.step_into()
idc.GetDebuggerEvent(WFNE_SUSP,-1)
print("EAX: ",hex(idc.GetRegValue('EAX')))
print(hex(idc.GetRegValue('EAX')),GetDisasm(idc.GetRegValue('EAX')))
print("ESI: ",hex(idc.GetRegValue('ESI')))
print(hex(idc.GetRegValue('ESI')),GetDisasm(idc.GetRegValue('ESI')))
print("EBX: ",hex(idc.GetRegValue('EBX')))
print(hex(idc.GetRegValue('EBX')),GetDisasm(idc.GetRegValue('EBX')))
print("EDX: ",hex(idc.GetRegValue('EDX')))
print(hex(idc.GetRegValue('EDX')),GetDisasm(idc.GetRegValue('EDX')))
print("EBP: ",hex(idc.GetRegValue('EBP')))
print(hex(idc.GetRegValue('EBP')),GetDisasm(idc.GetRegValue('EBX')))
print("EDI: ",hex(idc.GetRegValue('EDI')))
print(hex(idc.GetRegValue('EDI')),GetDisasm(idc.GetRegValue('EDI')))
print("EIP: ",hex(idc.GetRegValue('EIP')))
print(hex(idc.GetRegValue('EIP')),GetDisasm(idc.GetRegValue('EIP')))
print("ESP: ",hex(idc.GetRegValue('ESP')))
print(hex(idc.GetRegValue('ESP')),GetDisasm(idc.GetRegValue('ESP')))
idc.GetDebuggerEvent(WFNE_SUSP,-1)
count+=1
def dbgRegisters(self,addr,register):
count = 0
for seg in Segments():
for func in Functions(seg, SegEnd(seg)):
functionName = GetFunctionName(func)
for (start, end) in Chunks(func):
for head in Heads(start, end):
if hex(head)[:-1] == hex(addr):
print "Function Name: ", functionName
diss = list(FuncItems(addr))
print "[+]%s:" %register
for i in diss:
#print "%x" % i , GetDisasm(i).split()
try:
if GetDisasm(i).split()[1] == register or GetDisasm(i).split()[1] == register+"," or GetDisasm(i).split()[2] == register or GetDisasm(i).split()[2] == "["+register+"]":
print "%x" % i , GetDisasm(i)
print "[+]Instruction %d %s" % (count,register)
idc.GetDebuggerEvent(WFNE_SUSP,-1)
idc.RunTo(i)
idc.AddBpt(i) #breakpoint
idaapi.step_into()
idc.GetDebuggerEvent(WFNE_SUSP,-1)
print("%s: "%register,hex(idc.GetRegValue(register)))
print(hex(idc.GetRegValue(register)),GetDisasm(idc.GetRegValue(register)))
count+=1
except IndexError:
pass
class solution():
def __init__(self):
self.ea = BeginEA()
def Dbg(self,addr):
idc.RunTo(self.ea)
idc.AddBpt(addr) #breakpoint
idc.GetDebuggerEvent(WFNE_SUSP,-1)
idc.RunTo(addr)
def xor(self,addr): #resultado iterado del bucle dando como resultado el valor de EBX restandole (sub) 30h
GetDebuggerEvent(WFNE_SUSP, -1)
print("Value: ")
len_ = idc.GetRegValue('ESI')
print(hex(len_))
print(type(len_))
print "%x" % len_ , GetDisasm(len_).split()
password = []
for x in GetDisasm(len_).split():
if len(x) == 4:
password.append(x)
print(password)
print(len(password))
for i in range(0,int(len(password))): #loop to get byte to byte sum
ebx_ = idc.GetRegValue('EBX')
print(ebx_)
idc.RunTo(self.ea)
idc.GetDebuggerEvent(WFNE_SUSP,-1)
idaapi.step_into()
GetDebuggerEvent(WFNE_SUSP, -1)
idc.RunTo(0x004013FD) #consiguiendo el valor de EBX en la direccion de retorno de la funcion
GetDebuggerEvent(WFNE_SUSP, -1)
print("Value: ")
value = idc.GetRegValue('EBX')
print(value)
print(hex(value))
'''
XOR
0x5e6774a: 0000 0000 0101 1110 0110 0111 0111 0100 1010
0x1234: 0001 0010 0011 0100
0110 0101 0111 1110
0x5e6657e
'''
def keygen(self,addr):
GetDebuggerEvent(WFNE_SUSP, -1)
print("Value of EAX: ")
value_ = idc.GetRegValue('EAX')
print(hex(value_))
print(type(value_))
correct = hex(value_ ^ 0x1234)
print "Your password for this user is:", int(correct[:-1], 0)
if __name__ == '__main__':
#recon()
#discover()
#solution()
help()