Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from scapy.all import *
- from scapy.layers.http import HTTPRequest # import HTTP packet
- from colorama import init, Fore
- init()
- # define colors
- GREEN = Fore.GREEN
- RED = Fore.RED
- RESET = Fore.RESET
- def process_packet(packet):
- if packet.haslayer(HTTPRequest):
- # if this packet is an HTTP Request
- # get the requested URL
- url = packet[HTTPRequest].Host.decode() + packet[HTTPRequest].Path.decode()
- # get the requester's IP Address
- ip = packet[IP].src
- # get the request method
- method = packet[HTTPRequest].Method.decode()
- print(f"\n{GREEN}[+] {ip} Requested {url} with {method}{RESET}")
- if show_raw and packet.haslayer(Raw) and method == "POST":
- # if show_raw flag is enabled, has raw data, and the requested method is "POST"
- # then show raw
- print(f"\n{RED}[*] Some useful Raw data: {packet[Raw].load}{RESET}")
- def sniff_packets(iface=None):
- """
- Sniff 80 port packets with `iface`, if None (default), then the
- Scapy's default interface is used
- """
- if iface:
- # port 80 for http (generally)
- # `process_packet` is the callback
- sniff(filter="port 80", prn=process_packet, iface=iface, store=False)
- else:
- # sniff with default interface
- sniff(filter="port 80", prn=process_packet, store=False)
- sniff_packets(iface)
Add Comment
Please, Sign In to add comment