diff --git a/scapy/asn1fields.py b/scapy/asn1fields.py index d368f4c0b149f55185975d56af800e56d8350c32..d5d1add3cdf4e5bba588c15825d9f0d86b20418d 100644 --- a/scapy/asn1fields.py +++ b/scapy/asn1fields.py @@ -182,7 +182,7 @@ class ASN1F_enum_INTEGER(ASN1F_INTEGER): def i2m(self, pkt, s): if isinstance(s, str): s = self.s2i.get(s) - return super(ASN1F_INTEGER, self).i2m(pkt, s) + return super(ASN1F_enum_INTEGER, self).i2m(pkt, s) def i2repr(self, pkt, x): if x is not None and isinstance(x, ASN1_INTEGER): r = self.i2s.get(x.val) diff --git a/scapy/config.py b/scapy/config.py index 12c6d0d7e9d3196502bcf46fb6750ab2bd51e5aa..568dada8a60cb3e45a0efa8d69779ec169db9e01 100755 --- a/scapy/config.py +++ b/scapy/config.py @@ -172,6 +172,8 @@ class CacheInstance(dict): self.timeout = timeout self.name = name self._timetable = {} + def flush(self): + self.__init__(name=self.name, timeout=self.timeout) def __getitem__(self, item): val = dict.__getitem__(self,item) if self.timeout is not None: @@ -329,6 +331,7 @@ contribs: a dict which can be used by contrib layers to store local configuratio interactive_shell = "" stealth = "not implemented" iface = None + iface6 = None readfunc = None layers = LayersList() commands = CommandsList() @@ -383,7 +386,8 @@ contribs: a dict which can be used by contrib layers to store local configuratio stats_dot11_protocols = [] temp_files = [] netcache = NetCache() - geoip_city = '/usr/share/GeoIP/GeoLiteCity.dat' + geoip_city = '/usr/share/GeoIP/GeoIPCity.dat' + geoip_city_ipv6 = '/usr/share/GeoIP/GeoIPCityv6.dat' load_layers = ["l2", "inet", "dhcp", "dns", "dot11", "gprs", "tls", "hsrp", "inet6", "ir", "isakmp", "l2tp", "mgcp", "mobileip", "netbios", "netflow", "ntp", "ppp", diff --git a/scapy/layers/bluetooth.py b/scapy/layers/bluetooth.py index 2f236cff3eddbde480ecdf2332452a904468ad8e..ab48fbb34f8c69bee738efe9b7a776a1399f5bff 100644 --- a/scapy/layers/bluetooth.py +++ b/scapy/layers/bluetooth.py @@ -526,16 +526,6 @@ class HCI_Cmd_LE_Create_Connection(Packet): LEShortField("min_ce", 0), LEShortField("max_ce", 0), ] -class HCI_Cmd_LE_Connection_Update(Packet): - name = "LE Connection Update" - fields_desc = [ LEShortField("conn_handle", 64), - LEShortField("conn_interval_min", 0), - LEShortField("conn_interval_max", 0), - LEShortField("conn_latency", 0), - LEShortField("timeout", 600), - LEShortField("min_ce_len", 0), - LEShortField("max_ce_len", 0),] - class HCI_Cmd_LE_Create_Connection_Cancel(Packet): name = "LE Create Connection Cancel" diff --git a/scapy/layers/dhcp.py b/scapy/layers/dhcp.py index 612d72f75cff832285058f295756e39b78258e7b..8572fe9c1be7691ca339a3b2d8bd5104335b35a4 100644 --- a/scapy/layers/dhcp.py +++ b/scapy/layers/dhcp.py @@ -7,6 +7,7 @@ DHCP (Dynamic Host Configuration Protocol) d BOOTP """ +from collections import Iterable import struct from scapy.packet import * @@ -301,8 +302,6 @@ class BOOTP_am(AnsweringMachine): send_function = staticmethod(sendp) def parse_options(self, pool=Net("192.168.1.128/25"), network="192.168.1.0/24",gw="192.168.1.1", domain="localnet", renewal_time=60, lease_time=1800): - if type(pool) is str: - poom = Net(pool) self.domain = domain netw,msk = (network.split("/")+["32"])[:2] msk = itom(int(msk)) @@ -310,7 +309,9 @@ class BOOTP_am(AnsweringMachine): self.network = ltoa(atol(netw)&msk) self.broadcast = ltoa( atol(self.network) | (0xffffffff&~msk) ) self.gw = gw - if isinstance(pool,Gen): + if isinstance(pool, basestring): + pool = Net(pool) + if isinstance(pool, Iterable): pool = [k for k in pool if k not in [gw, self.network, self.broadcast]] pool.reverse() if len(pool) == 1: diff --git a/scapy/layers/inet6.py b/scapy/layers/inet6.py index 0e510fae89b658c48c71a6ebbf02e327c3a0140c..385d471289294c937da706c1d6f0215b0196224c 100644 --- a/scapy/layers/inet6.py +++ b/scapy/layers/inet6.py @@ -2850,7 +2850,7 @@ class MIP6MH_HoT(_MobilityHeader): overload_fields = { IPv6: { "nh": 135 } } def hashret(self): return self.cookie - def answers(self): + def answers(self, other): if (isinstance(other, MIP6MH_HoTI) and self.cookie == other.cookie): return 1 diff --git a/scapy/layers/l2.py b/scapy/layers/l2.py index c13bbc681a23a24f7bf84ae79c3d795159156dc9..9edbf710a0f533057379813e716fc453c6acd0b4 100644 --- a/scapy/layers/l2.py +++ b/scapy/layers/l2.py @@ -16,7 +16,7 @@ from scapy.packet import * from scapy.ansmachine import * from scapy.plist import SndRcvList from scapy.fields import * -from scapy.sendrecv import srp,srp1 +from scapy.sendrecv import srp, srp1, srpflood from scapy.arch import get_if_hwaddr from scapy.arch.consts import LOOPBACK_NAME from scapy.utils import inet_ntoa, inet_aton diff --git a/scapy/layers/tls/crypto/pkcs1.py b/scapy/layers/tls/crypto/pkcs1.py index 9c43cf4a5381b6b11568286d61523f0ee7532b32..6a3dceca18c82b847a6b349d7bc7676dcd709a81 100644 --- a/scapy/layers/tls/crypto/pkcs1.py +++ b/scapy/layers/tls/crypto/pkcs1.py @@ -172,7 +172,7 @@ def pkcs_mgf1(mgfSeed, maskLen, h): # steps are those of Appendix B.2.1 if not _hashFuncParams.has_key(h): - _warning("pkcs_mgf1: invalid hash (%s) provided") + _warning("pkcs_mgf1: invalid hash (%s) provided" % h) return None hLen = _hashFuncParams[h][0] hFunc = _hashFuncParams[h][2] @@ -891,7 +891,7 @@ class _DecryptAndSignRSA(object): if h is None: h = "sha1" if not _hashFuncParams.has_key(h): - _warning("Key._rsaes_oaep_decrypt(): unknown hash function %s.", h) + _warning("Key._rsaes_oaep_decrypt(): unknown hash function %s." % h) return None hLen = _hashFuncParams[h][0] hFun = _hashFuncParams[h][2] diff --git a/scapy/plist.py b/scapy/plist.py index ea9464c55cc23949bc90d14ffccf6266b37bb911..d4d82629a45cb53911813f401d657be76e3c0357 100644 --- a/scapy/plist.py +++ b/scapy/plist.py @@ -34,7 +34,7 @@ class PacketList(BasePacketList): self.stats = stats if res is None: res = [] - if isinstance(res, PacketList): + elif isinstance(res, PacketList): res = res.res self.res = res self.listname = name @@ -257,7 +257,7 @@ lfilter: truth function to apply to each packet to decide whether it will be dis def padding(self, lfilter=None): """Same as hexraw(), for Padding layer""" - for i in enumerate(self.res): + for i, res in enumerate(self.res): p = self._elt2pkt(res) if p.haslayer(conf.padding_layer): if lfilter is None or lfilter(p): @@ -268,7 +268,7 @@ lfilter: truth function to apply to each packet to decide whether it will be dis def nzpadding(self, lfilter=None): """Same as padding() but only non null padding""" - for i in enumerate(self.res): + for i, res in enumerate(self.res): p = self._elt2pkt(res) if p.haslayer(conf.padding_layer): pad = p.getlayer(conf.padding_layer).load @@ -407,9 +407,8 @@ lfilter: truth function to apply to each packet to decide whether it will be dis import pyx d = pyx.document.document() l = len(self.res) - for i in enumerate(self.res): - elt = res - c = self._elt2pkt(elt).canvas_dump(**kargs) + for i, res in enumerate(self.res): + c = self._elt2pkt(res).canvas_dump(**kargs) cbb = c.bbox() c.text(cbb.left(),cbb.top()+1,r"\font\cmssfont=cmss12\cmssfont{Frame %i/%i}" % (i,l),[pyx.text.size.LARGE]) if conf.verb >= 2: diff --git a/scapy/route6.py b/scapy/route6.py index 82c6f8f350ea13d621d24775660775df42140012..e00edfc4757ba8d9e43dcbc17a96dd0ebfea70d5 100644 --- a/scapy/route6.py +++ b/scapy/route6.py @@ -128,11 +128,11 @@ class Route6: if iface != iff: continue if gw == '::': - self.routes[i] = (the_net,the_plen,gw,iface,the_addr) + self.routes[i] = (the_net,the_plen,gw,iface,[the_addr]) else: - self.routes[i] = (net,the_plen,gw,iface,the_addr) + self.routes[i] = (net,plen,gw,iface,[the_addr]) self.invalidate_cache() - ip6_neigh_cache.flush() + conf.netcache.in6_neighbor.flush() def ifdel(self, iff): """ removes all route entries that uses 'iff' interface. """ diff --git a/test/regression.uts b/test/regression.uts index ae2954d38f999df35f66f6c6382a77e3584ea21f..a5a2f710bce3696d4ce3c291b67c4f9ffe6dbbd4 100644 --- a/test/regression.uts +++ b/test/regression.uts @@ -67,6 +67,11 @@ if len(routes6): else: True += Test ifchange() +conf.route6.ifchange(LOOPBACK_NAME, "::1/128") +True + + ############ ############ + Basic tests @@ -4497,6 +4502,15 @@ a=IPv6('`\x00\x00\x00\x00\x18\x87@ \x01\r\xb8\x00\x00\x00\x00\x00\x00\x00\x00\x0 b = a.payload a.nh == 135 and isinstance(b, MIP6MH_HoT) and b.nh==59 and b.mhtype == 3 and b.len== 2 and b.res == 0x77 and b.cksum == 0x8899 and b.index == 0xAABB and b.cookie == '\xAA'*8 and b.token == '\xCC'*8 += MIP6MH_HoT answers +a1, a2 = "2001:db8::1", "2001:db8::2" +cookie = RandString(8)._fix() +p1 = IPv6(src=a1, dst=a2)/MIP6MH_HoTI(cookie=cookie) +p2 = IPv6(src=a2, dst=a1)/MIP6MH_HoT(cookie=cookie) +p2_ko = IPv6(src=a2, dst=a1)/MIP6MH_HoT(cookie="".join(chr((ord('\xff') + 1) % 256))) +assert p1.hashret() == p2.hashret() and p2.answers(p1) and not p1.answers(p2) +assert p1.hashret() != p2_ko.hashret() and not p2_ko.answers(p1) and not p1.answers(p2_ko) + ############ ############