This script is designed to monitor network traffic and detect large downloads based on TCP packets with specific flags. It utilizes the scapy
library to capture and analyze packets, focusing on TCP packets with ACK+PSH flags. If a packet with this combination of flags is found and the payload size is greater than 20MB, the script logs an alert message and prints details about the download.
- Python 3.x
scapy
library (install usingpip install scapy
)
-
Install the required packages:
pip install scapy
-
Run the script:
python script.py
-
The script will start capturing network traffic and analyze TCP packets. If a packet with the ACK+PSH flags is detected and its payload size exceeds 20MB, an alert will be logged in the
download_alerts.log
file.
- The script uses the
scapy
library to capture network packets. - It filters for TCP packets using the provided
filter
parameter. - For each TCP packet with ACK+PSH flags, the script extracts relevant information such as source IP, destination IP, source port, destination port, and payload length.
- If the payload length is greater than 20MB, an alert is logged in the
download_alerts.log
file, and information about the download is printed.
You can customize the script by modifying the following parameters:
filter
: Change the packet filter as needed to capture specific types of network traffic.payload_length_threshold
: Adjust the threshold for payload size that triggers an alert.
The script logs download alerts to the download_alerts.log
file in the same directory. Each alert message includes the timestamp and information about the detected download.
This script is provided as-is and may require further adaptation to suit specific network environments. Use it responsibly and ensure that you have the necessary permissions before monitoring network traffic.