Changeset 918:c6d5e354eb6f

Show
Ignore:
Timestamp:
09/12/08 17:57:20 (4 months ago)
Author:
Phil <phil@secdev.org>
Message:

Scapy6 adapatations to have it work inside scapy 2

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • scapy/config.py

    r914 r918  
    313313    temp_files = [] 
    314314    netcache = NetCache() 
    315     load_layers = ["l2", "inet", "dhcp", "dns", "dot11", "gprs", "hsrp", "ip6", "ir", "isakmp", "l2tp", 
     315    load_layers = ["l2", "inet", "dhcp", "dns", "dot11", "gprs", "hsrp", "inet6", "ir", "isakmp", "l2tp", 
    316316                   "mgcp", "mobileip", "netbios", "netflow", "ntp", "ppp", "radius", "rip", "rtp", 
    317317                   "sebek", "skinny", "smb", "snmp", "tftp", "x509", "bluetooth" ] 
  • scapy/layers/inet.py

    r880 r918  
    278278                ck=checksum(psdhdr+p) 
    279279                p = p[:16]+struct.pack("!H", ck)+p[18:] 
    280             elif isinstance(self.underlayer, IPv6) or isinstance(self.underlayer, _IPv6OptionHeader): 
     280            elif isinstance(self.underlayer, inet6.IPv6) or isinstance(self.underlayer, inet6._IPv6ExtHdr): 
    281281                ck = in6_chksum(socket.IPPROTO_TCP, self.underlayer, p) 
    282282                p = p[:16]+struct.pack("!H", ck)+p[18:] 
     
    302302        if isinstance(self.underlayer, IP): 
    303303            return self.underlayer.sprintf("TCP %IP.src%:%TCP.sport% > %IP.dst%:%TCP.dport% %TCP.flags%") 
    304         elif isinstance(self.underlayer, IPv6): 
     304        elif isinstance(self.underlayer, inet6.IPv6): 
    305305            return self.underlayer.sprintf("TCP %IPv6.src%:%TCP.sport% > %IPv6.dst%:%TCP.dport% %TCP.flags%") 
    306306        else: 
     
    332332                ck=checksum(psdhdr+p) 
    333333                p = p[:6]+struct.pack("!H", ck)+p[8:] 
    334             elif isinstance(self.underlayer, IPv6) or isinstance(self.underlayer, _IPv6OptionHeader): 
     334            elif isinstance(self.underlayer, inet6.IPv6) or isinstance(self.underlayer, inet6._IPv6ExtHdr): 
    335335                ck = in6_chksum(socket.IPPROTO_UDP, self.underlayer, p) 
    336336                p = p[:6]+struct.pack("!H", ck)+p[8:] 
     
    353353        if isinstance(self.underlayer, IP): 
    354354            return self.underlayer.sprintf("UDP %IP.src%:%UDP.sport% > %IP.dst%:%UDP.dport%") 
    355         elif isinstance(self.underlayer, IPv6): 
     355        elif isinstance(self.underlayer, inet6.IPv6): 
    356356            return self.underlayer.sprintf("UDP %IPv6.src%:%UDP.sport% > %IPv6.dst%:%UDP.dport%") 
    357357        else: 
     
    926926        ports_done = {} 
    927927        for s,r in self.res: 
    928             r = r[IP] or r[IPv6] or r 
    929             s = s[IP] or s[IPv6] or s 
     928            r = r[IP] or r[inet6.IPv6] or r 
     929            s = s[IP] or s[inet6.IPv6] or s 
    930930            ips[r.src] = None 
    931931            if TCP in s: 
     
    938938                trace_id = (s.src,s.dst,s.proto,0) 
    939939            trace = rt.get(trace_id,{}) 
    940             ttl = IPv6 in s and s.hlim or s.ttl 
    941             if not (ICMP in r and r[ICMP].type == 11) and not (IPv6 in r and ICMPv6TimeExceeded in r): 
     940            ttl = inet6.IPv6 in s and s.hlim or s.ttl 
     941            if not (ICMP in r and r[ICMP].type == 11) and not (inet6.IPv6 in r and ICMPv6TimeExceeded in r): 
    942942                if trace_id in ports_done: 
    943943                    continue 
     
    12221222conf.stats_classic_protocols += [TCP,UDP,ICMP] 
    12231223conf.stats_dot11_protocols += [TCP,UDP,ICMP] 
     1224 
     1225from scapy.layers import inet6 
  • scapy/layers/inet6.py

    r917 r918  
    22############################################################################# 
    33##                                                                         ## 
    4 ## scapy6.py --- IPv6 support for Scapy                                    ## 
    5 ##              see http://namabiiru.hongo.wide.ad.jp/scapy6/             ## 
    6 ##              for more informations                                     ## 
     4## inet6.py --- IPv6 support for Scapy                                     ## 
     5##              see http://natisbad.org/IPv6/                              ## 
     6##              for more informations                                      ## 
    77##                                                                         ## 
    88## Copyright (C) 2005  Guillaume Valadon <guedou@hongo.wide.ad.jp>         ## 
     
    1111## This program is free software; you can redistribute it and/or modify it ## 
    1212## under the terms of the GNU General Public License version 2 as          ## 
    13 ## published by the Free Software Foundation; version 2.                   ## 
     13## published by the Free Software Foundation.                              ## 
    1414##                                                                         ## 
    1515## This program is distributed in the hope that it will be useful, but     ## 
     
    2020############################################################################# 
    2121 
    22 from scapy import * 
    23 import __builtin__ 
     22 
     23from scapy.layers.l2 import * 
     24from scapy.layers.inet import * 
     25from scapy.layers.dns import * 
     26from scapy.fields import * 
     27from scapy.packet import * 
     28from scapy.volatile import * 
     29from scapy.config import conf 
     30from scapy.sendrecv import sr,sr1,srp1 
     31from scapy.as_resolvers import AS_resolver_riswhois 
     32from scapy.supersocket import SuperSocket,L3RawSocket 
     33from scapy.arch import * 
    2434 
    2535 
     
    2939 
    3040def get_cls(name, fallback_cls): 
    31     return __builtin__.__dict__.get(name, fallback_cls) 
     41    return globals().get(name, fallback_cls) 
    3242 
    3343 
     
    4353WINDOWS = sys.platform.startswith("win") 
    4454 
    45 if OPENBSD or FREEBSD or NETBSD or DARWIN: 
    46         loname = "lo0" 
    47 else: 
    48         loname = "lo" 
    4955 
    5056# From net/ipv6.h on Linux (+ Additions) 
     
    9197    elif in6_ismaddr(addr): 
    9298        if in6_ismnladdr(addr): 
    93             cset = [('::1', 16, loname)] 
     99            cset = [('::1', 16, LOOPBACK_NAME)] 
    94100        elif in6_ismgladdr(addr): 
    95101            cset = filter(lambda x: x[1] == IPV6_ADDR_GLOBAL, laddr) 
     
    322328        if not pathes: 
    323329            warning("No route found for IPv6 destination %s (no default route?)" % dst) 
    324             return (loname, "::", "::") # XXX Linux specific 
     330            return (LOOPBACK_NAME, "::", "::") # XXX Linux specific 
    325331 
    326332        pathes.sort() 
     
    342348        #    6to4 address in those available 
    343349        #  - dst is link local (unicast or multicast) and multiple output 
    344         #    interfaces are available. Take main one (conf.iface
     350        #    interfaces are available. Take main one (conf.iface6
    345351        #  - if none of the previous or ambiguity persists, be lazy and keep 
    346352        #    first one 
     
    355361            elif in6_ismaddr(dst) or in6_islladdr(dst): 
    356362                # TODO : I'm sure we are not covering all addresses. Check that 
    357                 tmp = filter(lambda x: x[1][0] == conf.iface, res) 
     363                tmp = filter(lambda x: x[1][0] == conf.iface6, res) 
    358364 
    359365            if tmp: 
     
    442448 
    443449            cset = [] # candidate set (possible source addresses) 
    444             if dev == loname
     450            if dev == LOOPBACK_NAME
    445451                if d == '::': 
    446452                    continue 
     
    469475        xx = "::1" 
    470476        scope = 128 
    471         ifname = loname 
     477        ifname = LOOPBACK_NAME 
    472478        ret.append(xx, scope, ifname) 
    473479        return ret 
     
    479485        dp = 0 
    480486        nh = '::' 
    481         dev = loname 
     487        dev = LOOPBACK_NAME 
    482488        cset = ['::1'] 
    483489        routes.append((d, dp, nh, dev, cset)) 
     
    551557            if '%' in nh: 
    552558                nh,dev = nh.split('%') 
    553             if loname in dev: 
     559            if LOOPBACK_NAME in dev: 
    554560                cset = ['::1'] 
    555561                nh = '::' 
     
    604610     
    605611    def __init__(self): 
    606         self.neighcache = arp_cache 
     612        self.neighcache = {} 
    607613 
    608614    def flush(self, statictoo=True): 
     
    686692            return mac 
    687693     
    688         iff,a,nh = conf.route6.route(ip6, dev=conf.iface
    689  
    690         if iff == loname
     694        iff,a,nh = conf.route6.route(ip6, dev=conf.iface6
     695 
     696        if iff == LOOPBACK_NAME
    691697            return "ff:ff:ff:ff:ff:ff" 
    692698 
     
    10251031    tod = struct.pack("!II", i,j) 
    10261032    # TODO: Add some check regarding system address gathering 
    1027     rawmac = get_if_raw_hwaddr(conf.iface)[1] 
     1033    rawmac = get_if_raw_hwaddr(conf.iface6)[1] 
    10281034    mac = ":".join(map(lambda x: "%.02x" % ord(x), list(rawmac))) 
    10291035    # construct modified EUI-64 ID 
     
    15651571                    SourceIP6Field("src", "dst"), # dst is for src @ selection 
    15661572                    IP6Field("dst", "::1") ] 
     1573 
     1574    def route(self): 
     1575        dst = self.dst 
     1576        if isinstance(dst,Gen): 
     1577            dst = iter(dst).next() 
     1578        return conf.route6.route(dst) 
     1579 
    15671580    def mysummary(self): 
    15681581        return "%s > %s (%i)" % (self.src,self.dst, self.nh) 
     
    16741687            return self.payload.answers(other.payload) 
    16751688 
    1676 import scapy  
    1677 scapy.IPv6 = IPv6 
     1689 
     1690conf.neighbor.register_l3(Ether, IPv6, lambda l2,l3: getmacbyip6(l3.dst)) 
     1691 
    16781692 
    16791693class IPerror6(IPv6): 
     
    18331847    name = 'Abstract IPV6 Option Header' 
    18341848    aliastypes = [IPv6, IPerror6] # TODO ... 
    1835  
    1836 scapy._IPv6OptionHeader = _IPv6ExtHdr 
    18371849 
    18381850 
     
    46964708        msg = """ 
    46974709dhcp6d( dns="2001:500::1035", domain="localdomain, local", duid=None) 
    4698         iface=conf.iface, advpref=255, sntpservers=None,  
     4710        iface=conf.iface6, advpref=255, sntpservers=None,  
    46994711        sipdomains=None, sipservers=None,  
    47004712        nisdomain=None, nisservers=None,  
     
    47104722   
    47114723   iface : the interface to listen/reply on if you do not want to use  
    4712            conf.iface
     4724           conf.iface6
    47134725 
    47144726   advpref : Value in [0,255] given to Advertise preference field. 
     
    47644776                      nisdomain=None, nisservers=None, nispdomain=None, 
    47654777                      nispservers=None, bcmcsservers=None, bcmcsdomains=None, 
    4766                       iface=conf.iface, debug=0, advpref=255): 
     4778                      iface=None, debug=0, advpref=255): 
    47674779        def norm_list(val, param_name): 
    47684780            if val is None: 
     
    47784790                return -1 
    47794791 
     4792        if iface is None: 
     4793            iface = conf.iface6 
     4794         
    47804795        self.debug = debug 
    47814796 
     
    59315946############################################################################# 
    59325947 
    5933 L3Types[ETH_P_IPV6] =  IPv6 
    5934 LLTypes[31] = IPv6 
    5935 LLNumTypes[IPv6] = 31 
     5948conf.l3types.register(ETH_P_IPV6, IPv6) 
     5949conf.l2types.register(31, IPv6) 
    59365950 
    59375951bind_layers(Ether,     IPv6,     type = 0x86dd ) 
     
    59495963def get_working_if6(): 
    59505964    """ 
    5951     try to guess the best interface for conf.iface by looking for the  
     5965    try to guess the best interface for conf.iface6 by looking for the  
    59525966    one used by default route if any. 
    59535967    """ 
     
    59595973 
    59605974conf.route6 = Route6() 
    5961 conf.iface = get_working_if6() 
     5975conf.iface6 = get_working_if6() 
    59625976 
    59635977if __name__ == '__main__':