Harman5007

Untitled

Jul 18th, 2020
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1.  
  2. from scapy.all import *
  3. from scapy.layers.http import HTTPRequest # import HTTP packet
  4. from colorama import init, Fore
  5.  
  6. init()
  7. # define colors
  8. GREEN = Fore.GREEN
  9. RED = Fore.RED
  10. RESET = Fore.RESET
  11.  
  12. def process_packet(packet):
  13.  
  14. if packet.haslayer(HTTPRequest):
  15. # if this packet is an HTTP Request
  16. # get the requested URL
  17. url = packet[HTTPRequest].Host.decode() + packet[HTTPRequest].Path.decode()
  18. # get the requester's IP Address
  19. ip = packet[IP].src
  20. # get the request method
  21. method = packet[HTTPRequest].Method.decode()
  22. print(f"\n{GREEN}[+] {ip} Requested {url} with {method}{RESET}")
  23. if show_raw and packet.haslayer(Raw) and method == "POST":
  24. # if show_raw flag is enabled, has raw data, and the requested method is "POST"
  25. # then show raw
  26. print(f"\n{RED}[*] Some useful Raw data: {packet[Raw].load}{RESET}")
  27.  
  28.  
  29. def sniff_packets(iface=None):
  30. """
  31. Sniff 80 port packets with `iface`, if None (default), then the
  32. Scapy's default interface is used
  33. """
  34. if iface:
  35. # port 80 for http (generally)
  36. # `process_packet` is the callback
  37. sniff(filter="port 80", prn=process_packet, iface=iface, store=False)
  38. else:
  39. # sniff with default interface
  40. sniff(filter="port 80", prn=process_packet, store=False)
  41.  
  42. sniff_packets(iface)
Add Comment
Please, Sign In to add comment