/
hookthreaded.py
219 lines (211 loc) · 7.02 KB
/
hookthreaded.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
from pydbg import *
from pydbg.defines import *
import logging
import struct
import utils
import sys
import datetime
import threading
import os
from os import system
import platform
import time
import subprocess
import getpass
#import snapshot
#snapit = snapshot.snapshotter()
import win32gui
import win32con
import sys
hwnd = win32gui.GetForegroundWindow()
win32gui.ShowWindow(hwnd, win32con.SW_MAXIMIZE)
user = str(getpass.getuser())
cwd = os.getcwd()
os.system('title IMVU Debugger')
animation = '''|/-\\'''
snapshot = '%s\\snapshot.exe'%(cwd)
path = '''C:\Users\\"%s"\\AppData\\Roaming\\IMVUClient\\imvuclient.exe'''%(user)
buffer = ""
dbg = pydbg()
def handler_breakpoint(dbg):
print '--------------------------------Dumping context'
print dbg.dump_context()
return DBG_CONTINUE
# register a breakpoint handler function.
def check_accessv(dbg):
# We skip first-chance exceptions
if dbg.dbg.u.Exception.dwFirstChance:
return DBG_EXCEPTION_NOT_HANDLED
crash_bin = utils.crash_binning.crash_binning()
crash_bin.record_crash(dbg)
print crash_bin.crash_synopsis()
dbg.terminate_process()
#dbg.set_callback(EXCEPTION_ACCESS_VIOLATION,check_accessv)
#dbg.set_callback(EXCEPTION_BREAKPOINT, handler_breakpoint)
def logo():print '''
G#: # ####tK#
# j# #
,# D# #; #####.
#W # # #W;# W# #
#E # # ## # .# #
## # # W# # : #
## # GE D ##
## ########:GG IMVU Debug Hook
#####i;## : By Exploit
## ;# ## E 2.1
#, # ## . # ## #
## ### ;# #### #
## ## ## ## K#
## GW ### E#
W## ########.
##### ###
E##\npress p to pause execution\t(experimental)\npress r to search for a new string(experimental)\npress s to open the snapshotter\t(experimental)\npress d to dump registars\t(experimental)\npress q to quit\n'''
def clear_screen():
platClear = platform.system().lower()
if platClear == "linux" or platClear == "unix":
os.system('clear')
elif platClear == "windows":
os.system('cls')
def printreg():
print 'EAX is',pydbg.context.Eax
print pydbg.context.Edp
print pydbg.context.Esp
print pydbg.context.Eip
#this code left intentionally undocumented
exe = "imvuclient.exe"
for (pid, name) in dbg.enumerate_processes():
x = name.lower()
if x == exe:
break
elif x != exe:
clear_screen()
print '[*] Making sure imvu isnt running, so we get a clean startup\n'
dbg.detach()
system('taskkill /F /IM imvuclient.exe')
print '\n[*] Wait about 5 seconds while we start IMVU, alright?'
system('start %s'%(path))
time.sleep(2)
print '3....'
time.sleep(1)
print '2...'
time.sleep(1)
print '1...'
break
now = datetime.datetime.now()
class _Getch:
def __init__(self):
try:
self.impl = _GetchWindows()
except ImportError:
self.impl = _GetchUnix()
def __call__(self): return self.impl()
class _GetchUnix:
def __init__(self):
import tty, sys
def __call__(self):
import sys, tty, termios
fd = sys.stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(sys.stdin.fileno())
ch = sys.stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
class _GetchWindows:
def __init__(self):
import msvcrt
def __call__(self):
import msvcrt
return msvcrt.getch()
inkey = _Getch()
class readinput(threading.Thread):
def run(self):
for i in xrange(sys.maxint):
k=inkey()
if k >='':break
if k == "q":
print '''[!]QUITTING, IMVU WILL CRASH WITH THIS (EXPECTED) ERROR:\n\n\nStructuredException: EXCEPTION_BREAKPOINT(80000003)\nParameters: [Something, Something, Something]\n\n''',system('pause'),os._exit(1)
if k == "s":
print '[*] To do snapshots we have to reopen and reattach'
system('taskkill /IM imvuclient.exe')
system('start %s'%(snapshot))
imdbg()
if k == "r":
dbg.detach()
dbg.attach(int(pid))
pattern = None
imdbg()
if k == "d":
handler_breakpoint(pid)
def imdbg():
clear_screen()
dbg = pydbg()
found_imvu = False
logging.basicConfig(filename='hook.log',level=logging.DEBUG)
logo()
print 'Python',(sys.version),'\n'
pattern = raw_input("\n[?] What string to search for? >\n")
logme = raw_input("\n[?] Would you like to log my output to a text file? ( y/n )")
v = raw_input('\n[?] Use verbose mode?(no output at all)(y/n)')
if logme == "y":
print "[@] OUTPUT LOGGING ENABLED!"
print "[@] Placing search string in log..."
logging.debug("Searched on %s for the string: %s" % (now,pattern))
print '\n[!] Searching for pattern: %s'% (pattern)
def ssl_sniff( dbg, args ):
buffer = ""
offset = 0
while 1:
byte = dbg.read_process_memory( args[1] + offset, 1 )
if byte != "\x00":
buffer += byte
offset += 1
continue
else:
break
if v == "y":
logging.debug("[>] Pre-Encrypted: %s %s" %(now,buffer) )
else:
if pattern in buffer:
if logme == "y":
logging.debug("[>] Pre-Encrypted: %s %s" %(now,buffer) )
print "[>] Pre-Encrypted: %s" % buffer
else:
print "[>] Pre-Encrypted: %s" % buffer
return DBG_CONTINUE
for (pid, name) in dbg.enumerate_processes():
if name.lower() == "imvuclient.exe":
found_imvu = True
hooks = utils.hook_container()
dbg.set_callback(EXCEPTION_ACCESS_VIOLATION,check_accessv)
dbg.attach(int(pid))
print "[!] Attaching to IMVU with PID: %d..." % pid
hook_address = dbg.func_resolve_debuggee("nspr4.dll","PR_Write")
if hook_address:
hooks.add( dbg, hook_address, 2, ssl_sniff, None)
print "[*] nspr4.PR_Write hooked at: 0x%08x" % hook_address
break
else:
print "[!] Error: Couldn't resolve hook address."
dbg.detach()
print "[!] Error: Couldn't find the process. Please wait while I fire up IMVU and try again"
system('start %s'%(path))
imdbg()
if found_imvu:
print "[*] Hook set, continuing process.\n\n"
if v == "y":
print '[*] Verbose mode '
readinput().start()
dbg.run()
else:
readinput().start()
dbg.run()
else:
print "[!] Error: Couldn't find the process. Please wait while I fire up IMVU and try again"
system('start %s'%(path))
system('pause')
imdbg()
if __name__ == '__main__':
while 1:
imdbg()