-
Notifications
You must be signed in to change notification settings - Fork 0
/
jsprotocol.py
30 lines (27 loc) · 1.05 KB
/
jsprotocol.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
from scapy.all import *
# A new protocol that looks a lot like TCP
class JSTCP(Packet):
name = "JSTCP"
fields_desc = [ ShortEnumField("sport", 53, TCP_SERVICES),
ShortEnumField("dport", 53, TCP_SERVICES),
ShortField("ackseq", None),
XShortField("chksum", None),
ShortField("seq", None),
ShortField("window", 0),
FlagsField("flags", 0, 32, ["A", "P", "F", "S", "R", "SA"]),
IntField("left", 0),
IntField("right", 0), ]
def post_build(self, pkt, pay):
p = pkt+pay
if self.chksum is None:
if isinstance(self.underlayer, IP):
psdhdr = struct.pack("!4s4sHH",
inet_aton(self.underlayer.src),
inet_aton(self.underlayer.dst),
self.underlayer.proto,
len(p))
ck=checksum(psdhdr+p)
p=p[:6]+chr(ck >> 8)+chr(ck & 0xff)+p[8:]
else:
warning("No IP underlayer to compute checksum. Leaving null.")
return p