Changeset 891:1a296eb42561
- Timestamp:
- 08/30/08 23:55:23
(4 months ago)
- Author:
- Phil <phil@secdev.org>
- Message:
Created conf.default_l2 layer
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r890 |
r891 |
|
| 263 | 263 | lvl = 3 |
|---|
| 264 | 264 | else: |
|---|
| 265 | | warning("Unable to guess type (interface=%s protocol=%#x family=%i). Using Ethernet" % (sa_ll[0],sa_ll[1],sa_ll[3])) |
|---|
| 266 | | cls = Ether |
|---|
| | 265 | cls = conf.default_l2 |
|---|
| | 266 | warning("Unable to guess type (interface=%s protocol=%#x family=%i). Using %s" % (sa_ll[0],sa_ll[1],sa_ll[3],cls.name)) |
|---|
| 267 | 267 | lvl = 2 |
|---|
| 268 | 268 | |
|---|
| … | … | |
| 335 | 335 | self.LL = conf.l3types[sa_ll[1]] |
|---|
| 336 | 336 | else: |
|---|
| 337 | | warning("Unable to guess type (interface=%s protocol=%#x family=%i). Using Ethernet" % (sa_ll[0],sa_ll[1],sa_ll[3])) |
|---|
| 338 | | self.LL = Ether |
|---|
| | 337 | self.LL = conf.default_l2 |
|---|
| | 338 | warning("Unable to guess type (interface=%s protocol=%#x family=%i). Using %s" % (sa_ll[0],sa_ll[1],sa_ll[3],self.LL.name)) |
|---|
| 339 | 339 | |
|---|
| 340 | 340 | def recv(self, x): |
|---|
| … | … | |
| 399 | 399 | cls = conf.l3types[sa_ll[1]] |
|---|
| 400 | 400 | else: |
|---|
| 401 | | warning("Unable to guess type (interface=%s protocol=%#x family=%i). Using Ethernet" % (sa_ll[0],sa_ll[1],sa_ll[3])) |
|---|
| 402 | | cls = Ether |
|---|
| | 401 | cls = conf.default_l2 |
|---|
| | 402 | warning("Unable to guess type (interface=%s protocol=%#x family=%i). Using %s" % (sa_ll[0],sa_ll[1],sa_ll[3],cls.name)) |
|---|
| 403 | 403 | |
|---|
| 404 | 404 | try: |
|---|
| r890 |
r891 |
|
| 4 | 4 | ## This program is published under a GPLv2 license |
|---|
| 5 | 5 | |
|---|
| | 6 | import time,struct |
|---|
| | 7 | from fcntl import ioctl |
|---|
| 6 | 8 | from scapy.data import * |
|---|
| 7 | 9 | from scapy.config import conf |
|---|
| … | … | |
| 104 | 106 | cls = conf.l2types[ll] |
|---|
| 105 | 107 | else: |
|---|
| 106 | | warning("Unable to guess datalink type (interface=%s linktype=%i). Using Ethernet" % (self.iface, ll)) |
|---|
| 107 | | cls = Ether |
|---|
| | 108 | cls = conf.default_l2 |
|---|
| | 109 | warning("Unable to guess datalink type (interface=%s linktype=%i). Using %s" % (self.iface, ll, cls.name)) |
|---|
| 108 | 110 | |
|---|
| 109 | 111 | pkt = None |
|---|
| … | … | |
| 155 | 157 | i = dnet.intf() |
|---|
| 156 | 158 | return i.get(ifname)["addr"].data |
|---|
| 157 | | |
|---|
| 158 | 159 | |
|---|
| 159 | 160 | |
|---|
| … | … | |
| 163 | 164 | def __init__(self, type = ETH_P_ALL, filter=None, promisc=None, iface=None, nofilter=0): |
|---|
| 164 | 165 | self.iflist = {} |
|---|
| | 166 | self.intf = dnet.intf() |
|---|
| 165 | 167 | if iface is None: |
|---|
| 166 | 168 | iface = conf.iface |
|---|
| … | … | |
| 193 | 195 | if iff is None: |
|---|
| 194 | 196 | iff = conf.iface |
|---|
| 195 | | ifs = self.iflist.get(iff) |
|---|
| | 197 | ifs,cls = self.iflist.get(iff,(None,None)) |
|---|
| 196 | 198 | if ifs is None: |
|---|
| 197 | | self.iflist[iff] = ifs = dnet.eth(iff) |
|---|
| 198 | | sx = str(Ether()/x) |
|---|
| | 199 | iftype = self.intf.get(iff)["type"] |
|---|
| | 200 | if iftype == dnet.INTF_TYPE_ETH: |
|---|
| | 201 | try: |
|---|
| | 202 | cls = conf.l2types[1] |
|---|
| | 203 | except KeyError: |
|---|
| | 204 | warning("Unable to find Ethernet class. Using nothing") |
|---|
| | 205 | ifs = dnet.eth(iff) |
|---|
| | 206 | else: |
|---|
| | 207 | ifs = dnet.ip() |
|---|
| | 208 | self.iflist[iff] = ifs,cls |
|---|
| | 209 | if cls is None: |
|---|
| | 210 | sx = str(x) |
|---|
| | 211 | else: |
|---|
| | 212 | sx = str(cls()/x) |
|---|
| 199 | 213 | x.sent_time = time.time() |
|---|
| 200 | 214 | ifs.send(sx) |
|---|
| … | … | |
| 204 | 218 | cls = conf.l2types[ll] |
|---|
| 205 | 219 | else: |
|---|
| 206 | | warning("Unable to guess datalink type (interface=%s linktype=%i). Using Ethernet" % (self.iface, ll)) |
|---|
| 207 | | cls = Ether |
|---|
| | 220 | cls = conf.default_l2 |
|---|
| | 221 | warning("Unable to guess datalink type (interface=%s linktype=%i). Using %s" % (self.iface, ll, cls.name)) |
|---|
| 208 | 222 | |
|---|
| 209 | 223 | pkt = self.ins.next() |
|---|
| … | … | |
| 271 | 285 | cls = conf.l2types[ll] |
|---|
| 272 | 286 | else: |
|---|
| 273 | | warning("Unable to guess datalink type (interface=%s linktype=%i). Using Ethernet" % (self.iface, ll)) |
|---|
| 274 | | cls = Ether |
|---|
| | 287 | cls = conf.default_l2 |
|---|
| | 288 | warning("Unable to guess datalink type (interface=%s linktype=%i). Using %s" % (self.iface, ll, cls.name)) |
|---|
| 275 | 289 | |
|---|
| 276 | 290 | pkt = self.ins.next() |
|---|
| r880 |
r891 |
|
| 47 | 47 | if (tmp[0] & 0xf0) == 0xe0: # mcast @ |
|---|
| 48 | 48 | return "01:00:5e:%.2x:%.2x:%.2x" % (tmp[1]&0x7f,tmp[2],tmp[3]) |
|---|
| 49 | | iff,a,gw = config.conf.route.route(ip) |
|---|
| 50 | | if ( (iff == "lo") or (ip == config.conf.route.get_if_bcast(iff)) ): |
|---|
| | 49 | iff,a,gw = conf.route.route(ip) |
|---|
| | 50 | if ( (iff == "lo") or (ip == conf.route.get_if_bcast(iff)) ): |
|---|
| 51 | 51 | return "ff:ff:ff:ff:ff:ff" |
|---|
| 52 | 52 | if gw != "0.0.0.0": |
|---|
| 53 | 53 | ip = gw |
|---|
| 54 | 54 | |
|---|
| 55 | | mac = config.conf.netcache.arp_cache.get(ip) |
|---|
| | 55 | mac = conf.netcache.arp_cache.get(ip) |
|---|
| 56 | 56 | if mac: |
|---|
| 57 | 57 | return mac |
|---|
| … | … | |
| 66 | 66 | if res is not None: |
|---|
| 67 | 67 | mac = res.payload.hwsrc |
|---|
| 68 | | config.conf.netcache.arp_cache[ip] = mac |
|---|
| | 68 | conf.netcache.arp_cache[ip] = mac |
|---|
| 69 | 69 | return mac |
|---|
| 70 | 70 | return None |
|---|