rem stringlengths 0 322k | add stringlengths 0 2.05M | context stringlengths 8 228k |
|---|---|---|
if tlv and (val & ~0xffff): | if (val & ~0xffff): if not tlv: warning("%r should not be TLV but is too big => using TLV encoding" % typ) | def type2num(self, (typ,val)): type_val,enc_dict,tlv = ISAKMPTransformTypes.get(typ, (typ,{},0)) val = enc_dict.get(val, val) s = "" if tlv and (val & ~0xffff): n = 0 while val: s = chr(val&0xff)+s val >>= 8 n += 1 val = n else: type_val |= 0x8000 return struct.pack("!HH",type_val, val)+s |
"SIG","Nonce","N","D","VendorID"] | "SIG","Nonce","Notification","Delete","VendorID"] | def post_build(self, p, pay): p += pay l = self.len if l is None: l = len(p) p = p[:2]+struct.pack("!H",l)+p[4:] return p |
if self.ancount > 0: | if self.ancount > 0 and isinstance(self.an, DNSRR): | def mysummary(self): type = ["Qry","Ans"][self.qr] name = "" if self.qr: type = "Ans" if self.ancount > 0: name = ' "%s"' % self.an.rdata else: type = "Qry" if self.qdcount > 0: name = ' "%s"' % self.qd.qname return 'DNS %s%s ' % (type, name) |
if self.qdcount > 0: | if self.qdcount > 0 and isinstance(self.qd, DNSQR): | def mysummary(self): type = ["Qry","Ans"][self.qr] name = "" if self.qr: type = "Ans" if self.ancount > 0: name = ' "%s"' % self.an.rdata else: type = "Qry" if self.qdcount > 0: name = ' "%s"' % self.qd.qname return 'DNS %s%s ' % (type, name) |
warning("Unable to guess type (interface=%s protocol=% | warning("Unable to guess datalink type (interface=%s linktype=%i). Using Ethernet" % (self.iface, ll)) | def recv(self,x): ll = self.ins.datalink() if LLTypes.has_key(ll): cls = LLTypes[ll] else: warning("Unable to guess type (interface=%s protocol=%#x family=%i). Using Ethernet" % (sa_ll[0],sa_ll[1],sa_ll[3])) cls = Ether |
LEShortField("beacon_interval", 0x6400), | LEShortField("beacon_interval", 0x0064), | def unwep(self, key=None, warn=1): if self.FCfield & 0x40 == 0: if warn: warning("No WEP to remove") return if isinstance(self.payload.payload, NoPayload): if key or conf.wepkey: self.payload.decrypt(key) if isinstance(self.payload.payload, NoPayload): if warn: warning("Dot11 can't be decrypted. Check conf.wepkey.") r... |
fields_desc = [ ShortEnumField("reason", 1, reason_code) ] | fields_desc = [ LEShortEnumField("reason", 1, reason_code) ] | def mysummary(self): if self.ID == 0: return "SSID=%s"%repr(self.info),[Dot11] else: return "" |
ShortField("listen_interval", 0xc800) ] | LEShortField("listen_interval", 0x00c8) ] | def mysummary(self): if self.ID == 0: return "SSID=%s"%repr(self.info),[Dot11] else: return "" |
ShortField("status", 0), ShortField("AID", 0) ] | LEShortField("status", 0), LEShortField("AID", 0) ] | def mysummary(self): if self.ID == 0: return "SSID=%s"%repr(self.info),[Dot11] else: return "" |
fields_desc = [ LongField("timestamp", 0), ShortField("beacon_interval", 0x6400), | fields_desc = [ LELongField("timestamp", 0), LEShortField("beacon_interval", 0x0064), | def mysummary(self): if self.ID == 0: return "SSID=%s"%repr(self.info),[Dot11] else: return "" |
fields_desc = [ ShortEnumField("algo", 0, ["open", "sharedkey"]), | fields_desc = [ LEShortEnumField("algo", 0, ["open", "sharedkey"]), | def mysummary(self): if self.ID == 0: return "SSID=%s"%repr(self.info),[Dot11] else: return "" |
ShortEnumField("status", 0, status_code) ] | LEShortEnumField("status", 0, status_code) ] | def mysummary(self): if self.ID == 0: return "SSID=%s"%repr(self.info),[Dot11] else: return "" |
fields_desc = [ ShortEnumField("reason", 1, reason_code) ] | fields_desc = [ LEShortEnumField("reason", 1, reason_code) ] | def answers(self, other): if self.seqnum == other.seqnum+1: return 1 return 0 |
( LLC, STP, { "dsap" : 0x42 , "ssap" : 0x42 } ), ( LLC, SNAP, { "dsap" : 0xAA , "ssap" : 0xAA } ), | ( LLC, STP, { "dsap" : 0x42 , "ssap" : 0x42, "ctrl":3 } ), ( LLC, SNAP, { "dsap" : 0xAA , "ssap" : 0xAA, "ctrl":3 } ), | def bind_layers(lower, upper, fval): bind_top_down(lower, upper, fval) bind_bottom_up(lower, upper, fval) |
locals()[am.function_name] = lambda *args,**kargs: am(*args,**kargs).run() | locals()[am.function_name] = lambda am=am,*args,**kargs: am(*args,**kargs).run() | def sniff(self): sniff(iface=self.iface, **self.optsniff) |
style_not_printable = r"\textcolor{grey}{%s}" style_layer_name = r"\textcolor{red}{%s}" | style_not_printable = r"\textcolor{gray}{%s}" style_layer_name = r"\textcolor{red}{\bf %s}" | def do_style(val, fmt=None, col=col): if fmt is None: if type(val) is not str: val = str(val) else: val = fmt % val return col % val |
if tlv: return struct.pack("!HHI",type_val, 4, val) | s = "" if tlv and (val & ~0xffff): n = 0 while val: s = chr(val&0xff)+s val >>= 8 n += 1 val = n | def type2num(self, (typ,val)): type_val,enc_dict,tlv = ISAKMPTransformTypes.get(typ, (typ,{},0)) val = enc_dict.get(val, val) if tlv: return struct.pack("!HHI",type_val, 4, val) else: type_val |= 0x8000 return struct.pack("!HH",type_val, val) |
return struct.pack("!HH",type_val, val) | return struct.pack("!HH",type_val, val)+s | def type2num(self, (typ,val)): type_val,enc_dict,tlv = ISAKMPTransformTypes.get(typ, (typ,{},0)) val = enc_dict.get(val, val) if tlv: return struct.pack("!HHI",type_val, 4, val) else: type_val |= 0x8000 return struct.pack("!HH",type_val, val) |
while len(m) > 4: | while len(m) >= 4: | def m2i(self, pkt, m): |
value = m[4:value_len] value = reduce(lambda x,y: (x<<8)|y, struct.unpack("!%s" % ("B"*len(value),), value),0) | value = m[4:4+value_len] print "value=",repr(value) value = reduce(lambda x,y: (x<<8L)|y, struct.unpack("!%s" % ("B"*len(value),), value),0) | def m2i(self, pkt, m): |
def Ether_Dot3_Dispatcher(pkt, **kargs): if len(pkt) >= 14 and struct.unpack("!H", pkt[12:14])[0] < 1500: | def Ether_Dot3_Dispatcher(pkt=None, **kargs): if pkt is str and len(pkt) >= 14 and struct.unpack("!H", pkt[12:14])[0] < 1500: | def Ether_Dot3_Dispatcher(pkt, **kargs): if len(pkt) >= 14 and struct.unpack("!H", pkt[12:14])[0] < 1500: return Dot3(pkt, **kargs) return Ether(pkt, **kargs) |
ans, unans = sr(tests, timeout=2, verbose=2) | ans, unans = sr(tests, timeout=2) | def nmap_sig(target, oport=80, cport=81, ucport=1): res = {} tcpopt = [ ("WScale", 10), ("NOP",None), ("MSS", 256), ("Timestamp",(123,0)) ] tests = [ IP(dst=target, id=1)/TCP(seq=1, sport=5001, dport=oport, options=tcpopt, flags="CS"), IP(dst=target, id=1)/TCP(seq=1, sport=5002, dport=oport, options=tcpopt, flags=0), ... |
print lines | def attach_filter(s, filter): # XXX We generate the filter on the interface conf.iface # because tcpdump open the "any" interface and ppp interfaces # in cooked mode. As we use them in raw mode, the filter will not # work... one solution could be to use "any" interface and translate # the filter from cooked mode to raw... | |
mac=req.src | def bootpd(ipset=Net("192.168.1.128/25"),gw="192.168.1.1",filter="udp and port 68 and port 67",iface=None, *args,**kargs): if iface is None: iface=conf.iface leases = {} if isinstance(ipset,Gen): ipset = [k for k in ipset] ipset.reverse() ip=ipset try: while 1: req=sniff(filter=filter, iface=iface, count=1, **kargs) if... | |
x = "ff:ff:ff:ff:ff:ff" | def i2h(self, pkt, x): if x is None: dstip = None if isinstance(pkt.payload, IP): dstip = pkt.payload.dst elif isinstance(pkt.payload, ARP): dstip = pkt.payload.pdst if isinstance(dstip, Gen): dstip = dstip.__iter__().next() if dstip is not None: x=getmacbyip(dstip) if x is None: x = "ff:ff:ff:ff:ff:ff" warning("Mac ad... | |
val = self.fieldtype[fld].i2repr(self,(getattr(self,fld))) | val = getattr(self,fld) if fld in self.fieldtype: val = self.fieldtype[fld].i2repr(self,val) | def sprintf(self, fmt, relax=1): s = "" while "%" in fmt: i = fmt.index("%") s += fmt[:i] fmt = fmt[i+1:] if fmt[0] == "%": fmt = fmt[1:] s += "%" continue else: try: i = fmt.index("%") sfclsfld = fmt[:i] fclsfld = sfclsfld.split(",") if len(fclsfld) == 1: f = "s" clsfld = fclsfld[0] elif len(fclsfld) == 2: f,clsfld = ... |
def wrpcap(filename, pkt): f=open(filename,"w") if isinstance(pkt,Packet): linktype = LLNumTypes.get(pkt.__class__,1) else: linktype = LLNumTypes.get(pkt[0].__class__,1) f.write(struct.pack("IHHIIII", 0xa1b2c3d4L, 2, 4, 0, 0, MTU, linktype)) for p in pkt: s = str(p) l = len(s) sec = int(p.time) usec = int((p.time-sec)... | def wrpcap(filename, pkt, *args, **kargs): PcapWriter(filename, *args, **kargs).write(pkt) | def wrpcap(filename, pkt): f=open(filename,"w") if isinstance(pkt,Packet): linktype = LLNumTypes.get(pkt.__class__,1) else: linktype = LLNumTypes.get(pkt[0].__class__,1) f.write(struct.pack("IHHIIII", 0xa1b2c3d4L, 2, 4, 0, 0, MTU, linktype)) for p in pkt: s = str(p) l = len(s) sec = int(p.time) usec = int((p.time-sec)... |
res=[] f=open(filename) magic = f.read(4) if struct.unpack("<I",magic) == (0xa1b2c3d4L,): endian = "<" elif struct.unpack(">I",magic) == (0xa1b2c3d4L,): endian = ">" else: warning("Not a pcap capture file (bad magic)") return [] hdr = f.read(20) if len(hdr)<20: warning("Invalid pcap file") return res vermaj,vermin,tz,s... | return PcapReader(filename).read_all(count=count) | def rdpcap(filename, count=-1): res=[] f=open(filename) magic = f.read(4) if struct.unpack("<I",magic) == (0xa1b2c3d4L,): endian = "<" elif struct.unpack(">I",magic) == (0xa1b2c3d4L,): endian = ">" else: warning("Not a pcap capture file (bad magic)") return [] hdr = f.read(20) if len(hdr)<20: warning("Invalid pcap file... |
hdr = self.f.read(24) if len(hdr)<24: raise RuntimeWarning, "Invalid pcap file" magic,vermaj,vermin,tz,sig,snaplen,linktype = struct.unpack("IHHIIII",hdr) if magic != 0xa1b2c3d4L: | magic = self.f.read(4) if magic == "\xa1\xb2\xc3\xd4": self.endian = ">" elif magic == "\xd4\xc3\xb2\xa1": self.endian = "<" else: | def __init__(self, filename): self.filename = filename self.f = open(filename,"r") hdr = self.f.read(24) if len(hdr)<24: raise RuntimeWarning, "Invalid pcap file" magic,vermaj,vermin,tz,sig,snaplen,linktype = struct.unpack("IHHIIII",hdr) if magic != 0xa1b2c3d4L: raise RuntimeWarning, "Not a pcap capture file (bad magic... |
sec,usec,caplen,olen = struct.unpack("IIII", hdr) p = self.LLcls(self.f.read(caplen)) | sec,usec,caplen,olen = struct.unpack(self.endian+"IIII", hdr) s = self.f.read(caplen) try: p = self.LLcls(s) except: if conf.debug_dissector: raise p = Raw(s) | def read_packet(self): """return a single packet read from the file returns None when no more packets are available """ hdr = self.f.read(16) if len(hdr) < 16: return None sec,usec,caplen,olen = struct.unpack("IIII", hdr) p = self.LLcls(self.f.read(caplen)) p.time = sec+0.000001*usec return p |
def read_all(self): | def read_all(self,count=-1): | def read_all(self): """return a list of all packets in the pcap file """ res=[] p = self.read_packet() while p != None: res.append(p) return(p) |
p = self.read_packet() while p != None: | while count != 0: count -= 1 p = self.read_packet() if p is None: break | def read_all(self): """return a list of all packets in the pcap file """ res=[] p = self.read_packet() while p != None: res.append(p) return(p) |
return(p) def read_PacketList(self): """return a PacketList() of all packets in the pcap file """ return PacketList(self.read_all(), self.filename) | return PacketList(res,name = os.path.basename(self.filename)) | def read_all(self): """return a list of all packets in the pcap file """ res=[] p = self.read_packet() while p != None: res.append(p) return(p) |
def __init__(self, filename, linktype=None): | def __init__(self, filename, linktype=None, endianness=""): | def __init__(self, filename, linktype=None): self.linktype = linktype self.header_done = 0 self.f = open(filename,"w") |
print "x",pkt.__class__ | def write(self, pkt): """accepts a either a single packet or a list of packets to be written to the dumpfile """ if self.header_done == 0: if self.linktype == None: if isinstance(pkt,Packet): print "x",pkt.__class__ linktype = LLNumTypes.get(pkt.__class__,1) else: print "xx",pkt[0].__class__ linktype = LLNumTypes.get(... | |
print "xx",pkt[0].__class__ | def write(self, pkt): """accepts a either a single packet or a list of packets to be written to the dumpfile """ if self.header_done == 0: if self.linktype == None: if isinstance(pkt,Packet): print "x",pkt.__class__ linktype = LLNumTypes.get(pkt.__class__,1) else: print "xx",pkt[0].__class__ linktype = LLNumTypes.get(... | |
print linktype self.f.write(struct.pack("IHHIIII", 0xa1b2c3d4L, | self.f.write(struct.pack(self.endian+"IHHIIII", 0xa1b2c3d4L, | def write(self, pkt): """accepts a either a single packet or a list of packets to be written to the dumpfile """ if self.header_done == 0: if self.linktype == None: if isinstance(pkt,Packet): print "x",pkt.__class__ linktype = LLNumTypes.get(pkt.__class__,1) else: print "xx",pkt[0].__class__ linktype = LLNumTypes.get(... |
print "yo" | def write(self, pkt): """accepts a either a single packet or a list of packets to be written to the dumpfile """ if self.header_done == 0: if self.linktype == None: if isinstance(pkt,Packet): print "x",pkt.__class__ linktype = LLNumTypes.get(pkt.__class__,1) else: print "xx",pkt[0].__class__ linktype = LLNumTypes.get(... | |
self.write_packet(p) def write_packet(self, packet): | self._write_packet(p) def _write_packet(self, packet): | def write(self, pkt): """accepts a either a single packet or a list of packets to be written to the dumpfile """ if self.header_done == 0: if self.linktype == None: if isinstance(pkt,Packet): print "x",pkt.__class__ linktype = LLNumTypes.get(pkt.__class__,1) else: print "xx",pkt[0].__class__ linktype = LLNumTypes.get(... |
self.f.write(struct.pack("IIII", sec, usec, l, l)) | self.f.write(struct.pack(self.endian+"IIII", sec, usec, l, l)) | def write_packet(self, packet): """writes a single packet to the pcap file """ s = str(packet) l = len(s) sec = int(packet.time) usec = int((packet.time-sec)*1000000) self.f.write(struct.pack("IIII", sec, usec, l, l)) self.f.write(s) |
class Dot11Addr2MACField(MACField): | class Dot11Addr2MACField(Dot11AddrMACField): | def getfield(self, pkt, s): if self.is_applicable(pkt): return MACField.getfield(self, pkt, s) else: return s,None |
return 0 class Dot11Addr3MACField(MACField): | return 1 class Dot11Addr3MACField(Dot11AddrMACField): | def is_applicable(self, pkt): if pkt.type == 1: return pkt.subtype in [ 0xb, 0xa, 0xe, 0xf] # RTS, PS-Poll, CF-End, CF-End+CF-Ack return 0 |
class Dot11Addr4MACField(MACField): | class Dot11Addr4MACField(Dot11AddrMACField): | def is_applicable(self, pkt): if pkt.type in [0,2]: return 1 return 0 |
def addfield(self, pkt, s, val): if self.is_applicable(pkt): return MACField.addfield(self, pkt, s, val) else: return s def getfield(self, pkt, s): if self.is_applicable(pkt): return MACField.getfield(self, pkt, s) else: return s,None | def addfield(self, pkt, s, val): if self.is_applicable(pkt): return MACField.addfield(self, pkt, s, val) else: return s | |
def sum(self): return self.name | def sum(self): return self.name | |
ret += self.underlayer.mysummary() ret += " / " return ret+self.sum() def summary(self): ret = self.payload.summary() if ret == "": ret = self.mysummary() | ret = "%s / %s" % (self.underlayer.summaryback(smallname),ret) | def mysummary(self): ret = "" if self.underlayer is not None: ret += self.underlayer.mysummary() ret += " / " return ret+self.sum() |
return "" | return self.summaryback() | def summary(self): return "" |
warning("Can't find Crypto python lib. Won't be able to decrypt WEP") | print "WARNING: Can't find Crypto python lib. Won't be able to decrypt WEP" | def attr_matches(self, text): m = re.match(r"(\w+(\.\w+)*)\.(\w*)", text) if not m: return expr, attr = m.group(1, 3) try: object = eval(expr) except: object = eval(expr, session) if isinstance(object, scapy.Packet): words = filter(lambda x: x[0]!="_",dir(object)) words += map(str, object.fields_desc) else: words = dir... |
x += " "*(self.length/2-1) x = x[:(self.length/2-1)] | x += " "*(self.length/2) x = x[:(self.length/2)] | def i2m(self, pkt, x): if x is None: x = "" x += " "*(self.length/2-1) x = x[:(self.length/2-1)] x = "".join(map(lambda x: chr(0x41+(ord(x)>>4))+chr(0x41+(ord(x)&0xf)), x)) x = " "+x return x |
if pkt is str and len(pkt) >= 14 and struct.unpack("!H", pkt[12:14])[0] < 1500: | if type(pkt) is str and len(pkt) >= 14 and struct.unpack("!H", pkt[12:14])[0] < 1500: | def Ether_Dot3_Dispatcher(pkt=None, **kargs): if pkt is str and len(pkt) >= 14 and struct.unpack("!H", pkt[12:14])[0] < 1500: return Dot3(pkt, **kargs) return Ether(pkt, **kargs) |
return s+"\x00"+self.i2m(pkt, val) | return s+self.i2m(pkt, val)+"\x00" | def addfield(self, pkt, s, val): return s+"\x00"+self.i2m(pkt, val) |
if self.haslayer(eval(cond)): | if self.haslayer_str(cond): | def sprintf(self, fmt, relax=1): """sprintf(format, [relax=1]) -> str |
def rdpcap(filename): | def rdpcap(filename, count=-1): | def rdpcap(filename): res=[] f=open(filename) magic = f.read(4) if struct.unpack("<I",magic) == (0xa1b2c3d4L,): endian = "<" elif struct.unpack(">I",magic) == (0xa1b2c3d4L,): endian = ">" else: warning("Not a pcap capture file (bad magic)") return [] hdr = f.read(20) if len(hdr)<20: warning("Invalid pcap file") return ... |
while 1: | while count != 0: count -= 1 | def rdpcap(filename): res=[] f=open(filename) magic = f.read(4) if struct.unpack("<I",magic) == (0xa1b2c3d4L,): endian = "<" elif struct.unpack(">I",magic) == (0xa1b2c3d4L,): endian = ">" else: warning("Not a pcap capture file (bad magic)") return [] hdr = f.read(20) if len(hdr)<20: warning("Invalid pcap file") return ... |
def __init__(self, iface = None, type = ETH_P_IP, promisc=None, filter=None): | def __init__(self, iface = None, type = ETH_P_ALL, promisc=None, filter=None): | def __init__(self, iface = None, type = ETH_P_IP, promisc=None, filter=None): self.type = type self.outs = None self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type)) if iface is not None: self.ins.bind((iface, type)) if filter is not None: attach_filter(self.ins, filter) if promisc is None: pr... |
def __init__(self, type = ETH_P_IP, filter=None, promisc=None, iface=None): | def __init__(self, type = None, filter=None, promisc=None, iface=None): | def __init__(self, type = ETH_P_IP, filter=None, promisc=None, iface=None): self.iflist = {} self.ins = pcap.pcapObject() if iface is None: iface = "any" self.ins.open_live(iface, 1600, 0, 100) if filter: self.ins.setfilter(filter, 0, 0) |
if type(x) is str and len(x) == 4: x = self.m2i(pkt, x) | def any2i(self, pkt, x): if type(x) is str and len(x) == 4: x = self.m2i(pkt, x) return self.h2i(pkt,x) | |
opt = {} | opt = [] | def m2i(self, pkt, x): opt = {} while x: onum = ord(x[0]) if onum == 0: break if onum == 1: opt["NOP"] = () x=x[1:] continue olen = ord(x[1]) oval = x[2:olen] if TCPOptions[0].has_key(onum): oname, ofmt = TCPOptions[0][onum] if ofmt: oval = struct.unpack(ofmt, oval) if len(oval) == 1: oval = oval[0] opt[oname] = oval e... |
opt["NOP"] = () | opt.append(("NOP",None)) | def m2i(self, pkt, x): opt = {} while x: onum = ord(x[0]) if onum == 0: break if onum == 1: opt["NOP"] = () x=x[1:] continue olen = ord(x[1]) oval = x[2:olen] if TCPOptions[0].has_key(onum): oname, ofmt = TCPOptions[0][onum] if ofmt: oval = struct.unpack(ofmt, oval) if len(oval) == 1: oval = oval[0] opt[oname] = oval e... |
opt[oname] = oval | opt.append((oname, oval)) | def m2i(self, pkt, x): opt = {} while x: onum = ord(x[0]) if onum == 0: break if onum == 1: opt["NOP"] = () x=x[1:] continue olen = ord(x[1]) oval = x[2:olen] if TCPOptions[0].has_key(onum): oname, ofmt = TCPOptions[0][onum] if ofmt: oval = struct.unpack(ofmt, oval) if len(oval) == 1: oval = oval[0] opt[oname] = oval e... |
opt[onum] = oval | opt.append((onum, oval)) | def m2i(self, pkt, x): opt = {} while x: onum = ord(x[0]) if onum == 0: break if onum == 1: opt["NOP"] = () x=x[1:] continue olen = ord(x[1]) oval = x[2:olen] if TCPOptions[0].has_key(onum): oname, ofmt = TCPOptions[0][onum] if ofmt: oval = struct.unpack(ofmt, oval) if len(oval) == 1: oval = oval[0] opt[oname] = oval e... |
for oname in x: oval = x[oname] | for oname,oval in x: | def i2m(self, pkt, x): opt = "" for oname in x: oval = x[oname] if type(oname) is str: if oname == "NOP": opt += "\x01" continue elif TCPOptions[1].has_key(oname): onum = TCPOptions[1][oname] ofmt = TCPOptions[0][onum][1] if ofmt is not None: if type(oval) is not tuple: oval = (oval,) oval = struct.pack(ofmt, *oval) el... |
elt = SetGen(elt) | if self.fieldtype[eltname].islist: elt = SetGen([elt]) else: elt = SetGen(elt) | def loop(todo, done, self=self): if todo: eltname = todo.pop() elt = self.__getattr__(eltname) if not isinstance(elt, Gen): elt = SetGen(elt) for e in elt: done[eltname]=e for x in loop(todo[:], done): yield x else: if isinstance(self.payload,NoPayload): payloads = [None] else: payloads = self.payload for payl in paylo... |
if (abs(other.seq-self.ack) >= 2): | if (abs(other.seq-self.ack) > 2): | def answers(self, other): if not isinstance(other, TCP): return 0 if not ((self.sport == other.dport) and (self.dport == other.sport)): return 0 if (abs(other.seq-self.ack) >= 2): return 0 return 1 |
s += fl[i] | s = fl[i]+s | def TCPflags2str(f): fl="FSRPAUEC" s="" for i in range(len(fl)): if f & 1: s += fl[i] f >>= 1 return s |
r["Ops"] = "".join(map(lambda x: x[0],pkt.payload.options.keys())) | r["Ops"] = "".join(map(lambda x: x[0][0],pkt.payload.options)) | def nmap_packet_sig(pkt): r = {} if pkt is not None: |
if ref.has_key(k) and seen[k] in ref[k].split("|"): c += 1 | if ref.has_key(k): if seen[k] in ref[k].split("|"): c += 1 | def nmap_match_one_sig(seen, ref): c = 0 for k in seen.keys(): if ref.has_key(k) and seen[k] in ref[k].split("|"): c += 1 return 1.0*c/len(seen.keys()) |
def nmap_sig(target, oport=80, cport=81): | def nmap_sig(target, oport=80, cport=81, ucport=1): | def nmap_sig(target, oport=80, cport=81): res = {} tcpopt = { "WScale": 10, "NOP":(), "MSS": 256, "Timestamp" : (123,0) } tests = { "T1": IP(dst=target)/TCP(seq=1, dport=oport, options=tcpopt, flags="CS"), "T2": IP(dst=target)/TCP(seq=1, dport=oport, options=tcpopt, flags=0), "T3": IP(dst=target)/TCP(seq=1, dport=opor... |
tcpopt = { "WScale": 10, "NOP":(), "MSS": 256, "Timestamp" : (123,0) } | tcpopt = [ ("WScale", 10), ("NOP",None), ("MSS", 256), ("Timestamp",(123,0)) ] | def nmap_sig(target, oport=80, cport=81): res = {} tcpopt = { "WScale": 10, "NOP":(), "MSS": 256, "Timestamp" : (123,0) } tests = { "T1": IP(dst=target)/TCP(seq=1, dport=oport, options=tcpopt, flags="CS"), "T2": IP(dst=target)/TCP(seq=1, dport=oport, options=tcpopt, flags=0), "T3": IP(dst=target)/TCP(seq=1, dport=opor... |
T = sr1(tests[t], timeout=2) | T = sr1(tests[t], timeout=2, verbose=2) if T is not None and T.haslayer(ICMP): warning("Test %s answered by an ICMP" % t) T=None | def nmap_sig(target, oport=80, cport=81): res = {} tcpopt = { "WScale": 10, "NOP":(), "MSS": 256, "Timestamp" : (123,0) } tests = { "T1": IP(dst=target)/TCP(seq=1, dport=oport, options=tcpopt, flags="CS"), "T2": IP(dst=target)/TCP(seq=1, dport=oport, options=tcpopt, flags=0), "T3": IP(dst=target)/TCP(seq=1, dport=opor... |
PU = IP(str(IP(dst=target)/UDP(dport=ucport)/(300*"i"))) T = sr1(PU, verbose=2, timeout=2) r={} if T is None: r["Resp"] = "N" else: r["DF"] = (T.flags & 2) and "Y" or "N" r["TOS"] = "%X" % T.tos r["IPLEN"] = "%X" % T.len r["RIPTL"] = "%X" % T.payload.payload.len r["RID"] = PU.id == T.payload.payload.id and "E" or "F" r... | def nmap_sig(target, oport=80, cport=81): res = {} tcpopt = { "WScale": 10, "NOP":(), "MSS": 256, "Timestamp" : (123,0) } tests = { "T1": IP(dst=target)/TCP(seq=1, dport=oport, options=tcpopt, flags="CS"), "T2": IP(dst=target)/TCP(seq=1, dport=oport, options=tcpopt, flags=0), "T3": IP(dst=target)/TCP(seq=1, dport=opor... | |
def nmap_fp(target, oport=80, cport=81): sigs = nmap_sig(target, oport, cport) | def nmap_search(sigs): | def nmap_sig(target, oport=80, cport=81): res = {} tcpopt = { "WScale": 10, "NOP":(), "MSS": 256, "Timestamp" : (123,0) } tests = { "T1": IP(dst=target)/TCP(seq=1, dport=oport, options=tcpopt, flags="CS"), "T2": IP(dst=target)/TCP(seq=1, dport=oport, options=tcpopt, flags=0), "T3": IP(dst=target)/TCP(seq=1, dport=opor... |
c = 0 | c = 0.0 | def nmap_fp(target, oport=80, cport=81): sigs = nmap_sig(target, oport, cport) guess = 0,[] for os,fp in nmap_base: c = 0 for t in sigs.keys(): c += nmap_match_one_sig(sigs[t], fp[t]) if c > guess[0]: guess = c,[ os ] elif c == guess[0]: guess[1].append(os) return guess |
c += nmap_match_one_sig(sigs[t], fp[t]) | if t in fp: c += nmap_match_one_sig(sigs[t], fp[t]) c /= len(sigs.keys()) | def nmap_fp(target, oport=80, cport=81): sigs = nmap_sig(target, oport, cport) guess = 0,[] for os,fp in nmap_base: c = 0 for t in sigs.keys(): c += nmap_match_one_sig(sigs[t], fp[t]) if c > guess[0]: guess = c,[ os ] elif c == guess[0]: guess[1].append(os) return guess |
return socket.ntohl((0xffffffff00000000L>>x)&0xffffffffL) | return socket.ntohl((0xffffffff00000000L>>x)&0xffffffffL)&0xffffffffL | def itom(x): return socket.ntohl((0xffffffff00000000L>>x)&0xffffffffL) |
def __init__(self, iptemplate="0/0"): | def __init__(self, iptemplate="0.0.0.0/0"): | def __init__(self, iptemplate="0/0"): self.ip = Net(iptemplate) |
def any2i(self, pkt, x): | def any2i_one(self, pkt, x): | def any2i(self, pkt, x): if type(x) is str: x = self.s2i[x] return x |
return self.i2s.get(x, repr(x)) | if type(x) is list: return map(lambda z,pkt=pkt:self.i2repr_one(pkt,z), x) else: return self.i2repr_one(pkt,x) | def i2repr(self, pkt, x): return self.i2s.get(x, repr(x)) |
def any2i(self, pkt, x): | def any2i_one(self, pkt, x): | def any2i(self, pkt, x): if len(x) != 1: x = self.s2i[x] return x |
def i2repr(self, pkt, x): | def i2repr_one(self, pkt, x): | def i2repr(self, pkt, x): return self.i2s.get(x, hex(x)) |
BTsocket = BluetoothSocket | BTsocket = BluetoothL2CAPSocket | def reset(self): self.__dict__ = {} |
def addfield(self, packet, s, val): | def addfield(self, pkt, s, val): | def addfield(self, packet, s, val): if val is None: val = 0 if type(s) is tuple: s,bitsdone,v = s else: bitsdone = 0 v = 0 v <<= self.size v |= val & ((1<<self.size) - 1) bitsdone += self.size while bitsdone >= 8: bitsdone -= 8 s = s+struct.pack("!B", v >> bitsdone) v &= (1<<bitsdone)-1 if bitsdone: return s,bitsdone,v... |
def getfield(self, packet, s): | def getfield(self, pkt, s): | def getfield(self, packet, s): if type(s) is tuple: s,bn = s else: bn = 0 fmt,sz=[("!B",1),("!H",2),("!I",4),("!I",4)][self.size/8] b = struct.unpack(fmt, s[:sz])[0] << bn b >>= (sz*8-self.size) b &= (1 << self.size)-1 bn += self.size s = s[bn/8:] bn = bn%8 if bn: return (s,bn),b else: return s,b |
def getfield(self, packet, s): opsz = (packet.ihl-5)*4 | def getfield(self, pkt, s): opsz = (pkt.ihl-5)*4 | def getfield(self, packet, s): opsz = (packet.ihl-5)*4 if opsz < 0: warning("bad ihl (%i). Assuming ihl=5"%packet.ihl) opsz = 0 return s[opsz:],s[:opsz] |
warning("bad ihl (%i). Assuming ihl=5"%packet.ihl) | warning("bad ihl (%i). Assuming ihl=5"%pkt.ihl) | def getfield(self, packet, s): opsz = (packet.ihl-5)*4 if opsz < 0: warning("bad ihl (%i). Assuming ihl=5"%packet.ihl) opsz = 0 return s[opsz:],s[:opsz] |
def getfield(self, packet, s): opsz = (packet.dataofs-5)*4 | def getfield(self, pkt, s): opsz = (pkt.dataofs-5)*4 | def getfield(self, packet, s): opsz = (packet.dataofs-5)*4 if opsz < 0: warning("bad dataofs (%i). Assuming dataofs=5"%packet.dataofs) opsz = 0 return s[opsz:],self.m2i(pkt,s[:opsz]) |
warning("bad dataofs (%i). Assuming dataofs=5"%packet.dataofs) | warning("bad dataofs (%i). Assuming dataofs=5"%pkt.dataofs) | def getfield(self, packet, s): opsz = (packet.dataofs-5)*4 if opsz < 0: warning("bad dataofs (%i). Assuming dataofs=5"%packet.dataofs) opsz = 0 return s[opsz:],self.m2i(pkt,s[:opsz]) |
return self == other | return isinstance(other, NoPayload) or isinstance(other, Padding) | def answers(self, other): return self == other |
pkt=socket.socket(socket.AF_PACKET, socket.SOCK_RAW, 0) pkt.bind(("eth0", 0)) raw=socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW) raw.setsockopt(socket.SOL_IP, socket.IP_HDRINCL, 1) | def fragment(pkt, fragsize=1480): fragsize = (fragsize/8)*8 h = pkt.copy() h.flags = "MF" del(h.payload) lst = [] for p in pkt.payload: s = str(p) nb = len(s)/fragsize+1 for i in range(nb): r = Raw(load=s[i*fragsize:(i+1)*fragsize]) r.overload_fields = p.overload_fields.copy() h2 = h.copy() if i == nb-1: h2.flags=0 h2.... | |
def __init__(self, iface = None, type = ETH_P_IP): if iface is None: iface = conf.iff | def __init__(self, type = ETH_P_IP): | def __init__(self, iface = None, type = ETH_P_IP): if iface is None: iface = conf.iff self.outs = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW) self.outs.setsockopt(socket.SOL_IP, socket.IP_HDRINCL, 1) self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, type) self.ins.bind((iface, type)) |
self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, type) self.ins.bind((iface, type)) | self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type)) | def __init__(self, iface = None, type = ETH_P_IP): if iface is None: iface = conf.iff self.outs = socket.socket(socket.AF_INET, socket.SOCK_RAW, socket.IPPROTO_RAW) self.outs.setsockopt(socket.SOL_IP, socket.IP_HDRINCL, 1) self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, type) self.ins.bind((iface, type)) |
def __init__(self, type = ETH_P_IP, filter=None, promisc=None, iface=None): | def __init__(self, type = ETH_P_ALL, filter=None, promisc=None, iface=None): | def __init__(self, type = ETH_P_IP, filter=None, promisc=None, iface=None): self.type = type self.ins = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(type)) self.ins.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 2**30) if filter is not None: attach_filter(self.ins, filter) self.outs = socket.socket(so... |
iff,a,gw = choose_route(x.dst) | if hasattr(x,"dst"): iff,a,gw = choose_route(x.dst) else: iff = conf.iff | def send(self, x): iff,a,gw = choose_route(x.dst) self.outs.bind((iff, self.type)) sn = self.outs.getsockname() if LLTypes.has_key(sn[3]): x = LLTypes[sn[3]]()/x self.outs.sendto(str(x), (iff, self.type)) |
if not isinstance(pkt, Packet): | if not isinstance(pkt, Gen): | def sndrcv(pks, pkt, timeout = 2, inter = 0, verbose=None): if not isinstance(pkt, Packet): pkt = SetGen(pkt) if verbose is None: verbose = conf.verb recv = [] ans = [] # do it here to fix random fields, so that parent and child have the same sent = [p for p in pkt] if timeout < 0: timeout = None rdpipe,wrpipe = o... |
s=L3PacketSocket(*args, **kargs) | if not isinstance(x, Gen): x = SetGen(x) s=conf.L3socket(*args, **kargs) | def send(x, inter=0, *args, **kargs): """Send packets at layer 3""" s=L3PacketSocket(*args, **kargs) for p in x: s.send(p) time.sleep(inter) |
s=L2Socket(*args, **kargs) | if not isinstance(x, Gen): x = SetGen(x) s=conf.L2socket(*args, **kargs) | def sendp(x, inter=0, *args, **kargs): """Send packets at layer 2""" s=L2Socket(*args, **kargs) for p in x: s.send(p) time.sleep(inter) |
a,b,c=sndrcv(L3PacketSocket(filter=filter),x,*args,**kargs) | a,b,c=sndrcv(conf.L3socket(filter=filter),x,*args,**kargs) | def sr(x,filter=None, *args,**kargs): """Send and receive packets at layer 3""" if not kargs.has_key("timeout"): kargs["timeout"] = -1 a,b,c=sndrcv(L3PacketSocket(filter=filter),x,*args,**kargs) return a,b |
a,b,c=sndrcv(L3PacketSocket(filter=filter),x,*args,**kargs) | a,b,c=sndrcv(conf.L3socket(filter=filter),x,*args,**kargs) | def sr1(x,filter=None, *args,**kargs): """Send and receive packets at layer 3 and return only the first answer""" if not kargs.has_key("timeout"): kargs["timeout"] = -1 a,b,c=sndrcv(L3PacketSocket(filter=filter),x,*args,**kargs) if len(a) > 0: return a[0][1] else: return None |
a,b,c=sndrcv(L2Socket(iface=iface, filter=filter),x,*args,**kargs) | a,b,c=sndrcv(conf.L2socket(iface=iface, filter=filter),x,*args,**kargs) | def srp(x,iface=None,filter=None, *args,**kargs): """Send and receive packets at layer 2""" if not kargs.has_key("timeout"): kargs["timeout"] = -1 a,b,c=sndrcv(L2Socket(iface=iface, filter=filter),x,*args,**kargs) return a,b |
a,b,c=sndrcv(L2Socket(iface=iface, filter=filter),x,*args,**kargs) | a,b,c=sndrcv(conf.L2socket(iface=iface, filter=filter),x,*args,**kargs) | def srp1(x,iface=None,filter=None, *args,**kargs): """Send and receive packets at layer 2 and return only the first answer""" if not kargs.has_key("timeout"): kargs["timeout"] = -1 a,b,c=sndrcv(L2Socket(iface=iface, filter=filter),x,*args,**kargs) if len(a) > 0: return a[0][1] else: return None |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.