blob: 010151d54e328a63e0b08319f18b334f6e9cf792 (
plain)
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
|
#!/usr/local/bin/python2.7
# check ip and udp checksum in returned icmp packet
import os
from addr import *
from scapy.all import *
dstaddr=sys.argv[1]
pid=os.getpid() & 0xffff
payload="a" * 1472
p=(Ether(src=SRC_MAC, dst=PF_MAC)/IP(flags="DF", src=SRC_OUT, dst=dstaddr)/
UDP(sport=pid,dport=9)/payload)
ipcksum=IP(str(p.payload)).chksum
print "ipcksum=%#04x" % (ipcksum)
udpcksum=IP(str(p.payload)).payload.chksum
print "udpcksum=%#04x" % (udpcksum)
a=srp1(p, iface=SRC_IF, timeout=2)
if a and a.type == ETH_P_IP and \
a.payload.proto == 1 and \
icmptypes[a.payload.payload.type] == 'dest-unreach' and \
icmpcodes[a.payload.payload.type][a.payload.payload.code] == \
'fragmentation-needed':
outeripcksum=a.payload.chksum
print "outeripcksum=%#04x" % (outeripcksum)
outercksum=a.payload.payload.chksum
print "outercksum=%#04x" % (outercksum)
q=a.payload.payload.payload
inneripcksum=q.chksum
print "inneripcksum=%#04x" % (inneripcksum)
if q.proto == 17:
innercksum=q.payload.chksum
print "innercksum=%#04x" % (innercksum)
if innercksum == udpcksum:
exit(0)
print "INNERCKSUM!=UDPCKSUM"
exit(1)
print "NO INNER UDP REQUEST"
exit(2)
print "NO FRAGMENTATION NEEDED"
exit(2)
|