-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathspoofDetect.py
47 lines (41 loc) · 1.36 KB
/
spoofDetect.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# coding=UTF-8
import time
import optparse
from scapy.all import *
from IPy import IP as IPTEST
ttlValues = {}
THRESH = 5
def checkTTL(ipsrc, ttl):
if IPTEST(ipsrc).iptype() == 'PRIVATE':
return
if not ttlValues.has_key(ipsrc):
pkt = sr1(IP(dst=ipsrc)/ICMP(), retry=0, timeout=1, verbose=0)
ttlValues[ipsrc] = pkt.ttl
if abs(int(ttl) - int(ttlValues[ipsrc])) > THRESH:
print('\n[!] Detected Possible Spoofed Packet From: ' + ipsrc)
print('[!] TTL: ' + ttl + ', Actual TTL: ' + str(ttlValues[ipsrc]))
def testTTL(pkt):
try:
if pkt.haslayer(IP):
ipsrc = pkt.getlayer(IP).src
ttl = str(pkt.ttl)
#print('[+] Pkt Received From:'+ ipsrc+' with TTL:' + ttl)
checkTTL(ipsrc, ttl)
except:
pass
def main():
parser = optparse.OptionParser("usage%prog -i<interface> -t <thresh>")
parser.add_option('-i', dest='iface', type='string', help='specify network interface')
parser.add_option('-t', dest='thresh', type='int', help='specify threshold count ')
(options, args) = parser.parse_args()
if options.iface == None:
conf.iface = 'eth0'
else:
conf.iface = options.iface
if options.thresh != None:
THRESH = options.thresh
else:
THRESH = 5
sniff(prn=testTTL, store=0)
if __name__ == '__main__':
main()