|
Fixes in netstat parsing... back !: msg#00013security.scapy.general
Hi all, I'm back with the "netmask bug" ;-) : Under (Open)BSD, I have this bug when reading the system routes if there are netmasks different from /0, /8, /16, /24, and /32. The same bug may be shown under Linux : lalet@euclide ~/work/python/scapy $ ./scapy.py.orig Welcome to Scapy (1.0.0.47beta) >>> conf.route.add(net="10.1.0.0/22",gw="172.16.0.3") >>> conf.route Network Netmask Gateway Iface Output IP [...] 10.1.0.0 255.255.63.0 172.16.0.3 eth0 172.16.0.7 The netmask is 255.255.63.0, which makes no sense. The patch attached fixed this issue, and also removes the useless routes present in "netstat -rn" output (one for each IP/MAC association in the cache, at least under OpenBSD). The new itom(x) function computes the netmask value (as stored in scapy routing table) from the number of bits to 1 (i.e., the value after the '/'). Unlike the previous patch I've posted here for the same bug, as I've had a little more time, this one fixes this bug everywhere (unless I've missed something, of course). So even under Linux, we now have: lalet@euclide ~/work/python/scapy $ ./scapy.py Welcome to Scapy (1.0.0.47beta) >>> conf.route.add(net="10.1.0.0/22",gw="172.16.0.3") >>> conf.route Network Netmask Gateway Iface Output IP [...] 10.1.0.0 255.255.252.0 172.16.0.3 eth0 172.16.0.7 255.255.252.0 sounds better to me. Pierre --- scapy.py.orig 2005-10-06 15:04:08.000000000 +0200 +++ scapy.py 2005-10-08 13:39:55.000000000 +0200 @@ -1373,7 +1373,8 @@ def atol(x): return struct.unpack("I", ip)[0] def ltoa(x): return socket.inet_ntoa(struct.pack("I", x)) - +def itom(x): + return socket.htonl((1L << x) - 1 << 32 - x) def do_graph(graph,type="svg",target="| display"): """do_graph(graph, type="svg",target="| display"): @@ -1510,7 +1511,7 @@ class Route: dev,ifaddr,x = self.route(nhop) else: ifaddr = get_if_addr(dev) - return (atol(thenet),(1L<<msk)-1, gw, dev, ifaddr) + return (atol(thenet), itom(msk), gw, dev, ifaddr) def add(self, *args, **kargs): """Ex: @@ -1529,7 +1530,7 @@ class Route: def ifchange(self, iff, addr): the_addr,the_msk = (addr.split("/")+["32"])[:2] - the_msk = (1L << int(the_msk))-1 + the_msk = itom(int(the_msk)) the_rawaddr, = struct.unpack("I",inet_aton(the_addr)) the_net = the_rawaddr & the_msk @@ -1556,7 +1557,7 @@ class Route: def ifadd(self, iff, addr): the_addr,the_msk = (addr.split("/")+["32"])[:2] - the_msk = (1L << int(the_msk))-1 + the_msk = itom(int(the_msk)) the_rawaddr, = struct.unpack("I",inet_aton(the_addr)) the_net = the_rawaddr & the_msk self.routes.append((the_net,the_msk,'0.0.0.0',iff,the_addr)) @@ -1721,15 +1722,17 @@ if not LINUX: dest,gw,fl,ref,use,mtu,netif = l.split()[:7] else: dest,gw,fl,ref,use,netif = l.split()[:6] + if fl.find("Lc") >= 0: + continue if dest == "default": dest = 0L netmask = 0L else: if "/" in dest: dest,netmask = dest.split("/") - netmask = (1L << int(netmask))-1 + netmask = itom(int(netmask)) else: - netmask = (1L << ((dest.count(".")+1)*8))-1 + netmask = itom((dest.count(".") + 1) * 8) dest += ".0"*(3-dest.count(".")) dest, = struct.unpack("I",inet_aton(dest)) if not "G" in fl: --------------------------------------------------------------------- Desinscription: envoyez un message a: scapy.ml-unsubscribe@xxxxxxxxxx Pour obtenir de l'aide, ecrivez a: scapy.ml-help@xxxxxxxxxx |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | scapywin.py patch: 00013, Payton, Zack |
|---|---|
| Next by Date: | TLV based protocols: 00013, Payton, Zack |
| Previous by Thread: | scapywin.py patchi: 00013, Payton, Zack |
| Next by Thread: | TLV based protocols: 00013, Payton, Zack |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |