Book Image

Hands-On Enterprise Automation with Python

By : Bassem Aly
Book Image

Hands-On Enterprise Automation with Python

By: Bassem Aly

Overview of this book

Hands-On Enterprise Automation with Python starts by covering the set up of a Python environment to perform automation tasks, as well as the modules, libraries, and tools you will be using. We’ll explore examples of network automation tasks using simple Python programs and Ansible. Next, we will walk you through automating administration tasks with Python Fabric, where you will learn to perform server configuration and administration, along with system administration tasks such as user management, database management, and process management. As you progress through this book, you’ll automate several testing services with Python scripts and perform automation tasks on virtual machines and cloud infrastructure with Python. In the concluding chapters, you will cover Python-based offensive security tools and learn how to automate your security tasks. By the end of this book, you will have mastered the skills of automating several system administration tasks with Python.
Table of Contents (20 chapters)

Capturing and replaying packets

Scapy has the ability to listen to the network interface and capture all incoming packets on it. It can write it on a pcap file in the same way that tcpdump works, but Scapy provides additional functions that can read and replay a pcap file, in the network again.

Starting with a simple packet replay, we will instruct Scapy to read a normal pcap file captured from the network (either using tcpdump or Scapy itself) and send it again to the network. This is very useful if we need to test the behavior of the network if a specific traffic pattern travels through it. For example, we may have a network firewall configured to block FTP communication. We can test the functionality of the firewall by hitting it with FTP data replayed from Scapy.

In this example, we have the FTP captured pcap file and we need to replay it to the network:

from scapy.layers...