From c3098883a274bfabda612faf05a6b70766216b94 Mon Sep 17 00:00:00 2001 From: Omar Santos Date: Thu, 12 Jan 2023 13:37:57 -0500 Subject: [PATCH] Create another_scapy_sniffer_walkthrough.md --- .../another_scapy_sniffer_walkthrough.md | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 programming_and_scripting_for_cybersecurity/recon_scripts/another_scapy_sniffer_walkthrough.md diff --git a/programming_and_scripting_for_cybersecurity/recon_scripts/another_scapy_sniffer_walkthrough.md b/programming_and_scripting_for_cybersecurity/recon_scripts/another_scapy_sniffer_walkthrough.md new file mode 100644 index 0000000..c2d01c2 --- /dev/null +++ b/programming_and_scripting_for_cybersecurity/recon_scripts/another_scapy_sniffer_walkthrough.md @@ -0,0 +1,23 @@ +# Simple Scapy Packet Capture +Here is a Python script that uses the Scapy library to capture a packet: + +``` +from scapy.all import * + +# Define a callback function +def packet_callback(packet): + print(packet.show()) + +# Use the sniff() function to capture packets +sniff(prn=packet_callback, filter="tcp", count=1) +``` + +This script uses the `sniff()` function from Scapy to capture packets. The `prn` argument is set to a callback function, `packet_callback`, which is called for each packet captured. The filter argument is set to "tcp" to capture only TCP packets, and the count argument is set to 1 to stop capturing after the first packet is captured. The `show()` function is used to display the packet information. + +You can also use `filter` to capture specific IP or port. + +``` +sniff(prn=packet_callback, filter="tcp and host 10.1.1.2 and port 80", count=1) +``` +It's important to note that capturing packets may require root/admin permissions. +