-
-
Save EllieJellyBean/75381a36f42f84286d7a1d00f494c1e5 to your computer and use it in GitHub Desktop.
A working Scapy program that sniffs traffic on a live work or from a PCAP file. Goal is to expand this to identify basic vulnerabilities (e.g., credentials sent in plaintext)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python3 | |
| from scapy.all import * | |
| import argparse | |
| def packetcallback(packet): | |
| try: | |
| # The following is an example of Scapy detecting HTTP traffic | |
| # Please remove this case in your actual lab implementation so it doesn't pollute the alerts | |
| if packet[TCP].dport == 80: | |
| print("HTTP (web) traffic detected!") | |
| except: | |
| pass | |
| parser = argparse.ArgumentParser(description='A network sniffer that identifies basic vulnerabilities') | |
| parser.add_argument('-i', dest='interface', help='Network interface to sniff on', default='eth0') | |
| parser.add_argument('-r', dest='pcapfile', help='A PCAP file to read') | |
| args = parser.parse_args() | |
| if args.pcapfile: | |
| try: | |
| print("Reading PCAP file %(filename)s..." % {"filename" : args.pcapfile}) | |
| sniff(offline=args.pcapfile, prn=packetcallback) | |
| except: | |
| print("Sorry, something went wrong reading PCAP file %(filename)s!" % {"filename" : args.pcapfile}) | |
| else: | |
| print("Sniffing on %(interface)s... " % {"interface" : args.interface}) | |
| try: | |
| sniff(iface=args.interface, prn=packetcallback) | |
| except: | |
| print("Sorry, can\'t read network traffic. Are you root?") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment