Python Penetration Testing Cookbook

Book description

Over 50+ hands-on recipes to help you pen test networks using Python, discover vulnerabilities, and find a recovery path

About This Book

  • Learn to detect and avoid various types of attack that put system privacy at risk
  • Enhance your knowledge of wireless application concepts and information gathering through practical recipes
  • Learn a pragmatic way to penetration-test using Python, build efficient code, and save time

Who This Book Is For

If you are a developer with prior knowledge of using Python for penetration testing and if you want an overview of scripting tasks to consider while penetration testing, this book will give you a lot of useful code for your toolkit.

What You Will Learn

  • Learn to configure Python in different environment setups.
  • Find an IP address from a web page using BeautifulSoup and Scrapy
  • Discover different types of packet sniffing script to sniff network packets
  • Master layer-2 and TCP/ IP attacks
  • Master techniques for exploit development for Windows and Linux
  • Incorporate various network- and packet-sniffing techniques using Raw sockets and Scrapy

In Detail

Penetration testing is the use of tools and code to attack a system in order to assess its vulnerabilities to external threats. Python allows pen testers to create their own tools. Since Python is a highly valued pen-testing language, there are many native libraries and Python bindings available specifically for pen-testing tasks.

Python Penetration Testing Cookbook begins by teaching you how to extract information from web pages. You will learn how to build an intrusion detection system using network sniffing techniques. Next, you will find out how to scan your networks to ensure performance and quality, and how to carry out wireless pen testing on your network to avoid cyber attacks. After that, we’ll discuss the different kinds of network attack. Next, you’ll get to grips with designing your own torrent detection program. We’ll take you through common vulnerability scenarios and then cover buffer overflow exploitation so you can detect insecure coding. Finally, you’ll master PE code injection methods to safeguard your network.

Style and approach

This book takes a recipe-based approach to solving real-world problems in pen testing. It is structured in stages from the initial assessment of a system through exploitation to post-exploitation tests, and provides scripts that can be used or modified for in-depth penetration testing.

Table of contents

  1. Preface
    1. What this book covers
    2. What you need for this book
    3. Who this book is for
    4. Sections
      1. Getting ready
      2. How to do it…
    5. Conventions
    6. Reader feedback
    7. Customer support
      1. Downloading the example code
      2. Downloading the color images of this book
      3. Errata
      4. Piracy
      5. Questions
  2. Why Python in Penetration Testing?
    1. Introduction
    2. Why Python is a great option for security scripting
      1. Getting ready
      2. How to do it...
        1. Python can be used in both  and interpreted and compiled forms
        2. Syntax and indented layout
        3. Simple learning curve
        4. Powerful third-party libraries
        5. Cross-platform (code anywhere)
    3. Python 3 language basics and differences
      1. Getting ready
      2. How to do it...
        1. Python 2
        2. Python 3
        3. Python 2.7
        4. Key differences between Python 2.7 and Python 3
  3. Setting Up a Python Environment
    1. Introduction
    2. Setting up a Python environment in Linux
      1. Getting ready
      2. How to do it...
        1. Installing Python
        2. Setting up a virtual environment
        3. Setting up the editor or IDE
    3. Setting up a Python environment in macOS
      1. Getting ready
      2. How to do it...
        1. Installing Python
    4. Setting up a Python environment in Windows
      1. How to do it...
  4. Web Scraping with Python
    1. Introduction
    2. Download web pages with Python scripts
      1. Getting ready
      2. How to do it...
        1. With Python 2
        2. With Python 3
    3. Changing the user agent
      1. How to do it...
    4. Downloading files
      1. Getting ready
      2. How to do it...
    5. Using a regular expression to get the information from the downloaded web pages
      1. How to do it...
    6. Requesting and downloading dynamic website pages
      1. Escaping invalid characters
      2. How to do it...
    7. Dynamic GET requests
      1. How to do it...
  5. Data Parsing with Python
    1. Introduction
    2. Parsing HTML tables
      1. Getting ready
      2. How to do it...
    3. Extracting data from HTML documents
      1. Getting ready
      2. How to do it...
    4. Parsing XML data
      1. Getting ready
      2. How to do it...
  6. Web Scraping with Scrapy and BeautifulSoup
    1. Introduction
    2. Web spiders with Scrapy
      1. Getting ready
      2. How to do it...
    3. Scrapy shell
      1. How to do it...
    4. Link extractor with Scrapy
      1. How to do it...
    5. Scraping after logging into websites using Scrapy
      1. Getting ready
      2. How to do it...
  7. Network Scanning with Python
    1. Introduction
    2. Simple port scanner
      1. Getting ready
      2. How to do it...
    3. IP range/network scanner
      1. Getting ready
      2. How to do it...
    4. Stealth scanning
      1. Getting ready
      2. How to do it...
    5. FIN scanning
      1. How to do it...
    6. XMAS scanning
      1. How to do it...
    7. TCP ACK scanning
      1. How to do it...
    8. LanScan
      1. Getting ready
      2. How to do it...
  8. Network Sniffing with Python
    1. Introduction
    2. Packet sniffer in Python
      1. Getting ready
      2. How to do it...
    3. Parsing the packet
      1. How to do it...
    4. PyShark
      1. Getting ready
      2. How to do it...
  9. Scapy Basics
    1. Introduction
    2. Creating a packet with Scapy
      1. Getting ready
      2. How to do it...
    3. Sending and receiving packets with Scapy
      1. How to do it...
    4. Layering packets
      1. How to do it...
    5. Reading and writing to pcap files
      1. How to do it...
    6. Sniffing packets
      1. How to do it...
    7. ARP man-in-the-middle tool with Scapy
      1. How to do it...
  10. Wi-Fi Sniffing
    1. Introduction
    2. Finding Wi-Fi devices
    3. Getting ready
      1. How to do it...
        1. Linux
        2. macOS
    4. Finding SSIDs
      1. How to do it...
    5. Exposing hidden SSIDs
      1. How to do it...
    6. Dictionary attack on hidden SSIDs
      1. How to do it...
    7. Fake access points with Scapy
      1. How to do it...
  11. Layer 2 Attacks
    1. Introduction
    2. ARP Watcher
      1. How to do it...
    3. ARP cache poisoning
      1. Getting ready
        1. Linux
        2. macOS
      2. How to do it...
    4. MAC flooder
      1. How to do it...
    5. VLAN hopping
      1. How to do it...
    6. ARP spoofing over VLAN hopping
      1. How to do it...
    7. DHCP starvation
      1. How to do it...
  12. TCP/IP Attacks
    1. Introduction
    2. IP spoofing
      1. How to do it...
    3. SYN flooding
      1. How to do it...
    4. Password sniffer with Python over LAN
      1. How to do it...
  13. Introduction to Exploit Development
    1. Introduction
      1. CPU registers
      2. Getting ready
        1. General purpose registers
        2. Special purpose registers
      3. How to do it...
    2. Memory dump
      1. How to do it...
    3. CPU instructions
      1. How to do it...
  14. Windows Exploit Development
    1. Introduction
    2. Windows memory layout
      1. Getting ready
        1. The stack
        2. The heap
        3. Program image and dynamic link libraries
        4. Process Environment Block (PEB)
        5. Thread Environment Block (TEB)
      2. How to do it...
    3. Buffer overflow with saved return pointer overwrite
      1. Getting ready
        1. Installing Mona
      2. How to do it...
    4. Structured Exception Handling
      1. Getting ready
      2. How to do it...
    5. Egg hunters
      1. Getting ready
      2. How to do it...
  15. Linux Exploit Development
    1. Introduction
    2. Format string exploitation
      1. Getting ready
        1. Global offset table
        2. Generating shell code
      2. How to do it...
    3. Buffer overflow
      1. How to do it...

Product information

  • Title: Python Penetration Testing Cookbook
  • Author(s): Rejah Rehim
  • Release date: November 2017
  • Publisher(s): Packt Publishing
  • ISBN: 9781784399771