Exemple #1
0
 def input_ip(self, eth, ip, timestamp):
     src = dnet.eth_ntoa(str(eth.src))
     dst = dnet.eth_ntoa(str(eth.dst))
     
     good = False
     for h in self.hosts:
         (ip, rand_mac, iter, reply) = self.hosts[h]
         if src == h:
             eth.src = dnet.eth_aton(rand_mac)
             ref_src = h
             if good:
                 self.dnet.send(str(eth))
                 if self.ui == 'gtk':
                     self.spoof_treestore.foreach(self.inc_packet_counter, (ref_src, ref_dst))
                 return
             else:
                 good = True
         if dst == rand_mac:
             eth.dst = dnet.eth_aton(h)
             ref_dst = h
             if good:
                 self.dnet.send(str(eth))
                 if self.ui == 'gtk':
                     self.spoof_treestore.foreach(self.inc_packet_counter, (ref_src, ref_dst))
                 return
             else:
                 good = True
Exemple #2
0
 def input_eth(self, eth, timestamp):
     src = dnet.eth_ntoa(str(eth.src))
     dst = dnet.eth_ntoa(str(eth.dst))
     good = False
     for h in self.hosts:
         (ip, rand_mac, iter, reply) = self.hosts[h]
         if src == h:
             eth.src = dnet.eth_aton(rand_mac)
             ref_src = h
             if good:
                 self.dnet.send(str(eth))
                 if self.ui == 'gtk':
                     self.spoof_treestore.foreach(self.inc_packet_counter, (ref_src, ref_dst))
                 return
             else:
                 good = True
         if dst == rand_mac:
             eth.dst = dnet.eth_aton(h)
             ref_dst = h
             if good:
                 self.dnet.send(str(eth))
                 if self.ui == 'gtk':
                     self.spoof_treestore.foreach(self.inc_packet_counter, (ref_src, ref_dst))
                 return
             else:
                 good = True
Exemple #3
0
 def input_eth(self, eth, timestamp):
     src = dnet.eth_ntoa(eth.src)
     if src not in self.connection_list:
         dst = dnet.eth_ntoa(eth.dst)
         self.connection_list[src] = connection(self, src, dst)
     hdr = dot1x_header()
     #try:
     data = hdr.parse(eth.data)
     self.connection_list[src].dissect(hdr, data)
Exemple #4
0
 def input_eth(self, eth, timestamp):
     src = dnet.eth_ntoa(eth.src)
     dst = dnet.eth_ntoa(eth.dst)
     data = eth.data
     src_dst = src + ":" + dst
     if src_dst not in self.peers:
         iter = self.peer_treestore.append(None, [src, dst, "", -1])
         dict = self.parse_tag(data, iter, {})
         self.peers[src_dst] = (iter, dict)
         self.log("DOT1Q: Got new DOT1Q communication: %s -> %s" % (src, dst))
     else:
         (iter, dict) = self.peers[src_dst]
         self.parse_tag(data, iter, dict)
Exemple #5
0
 def input_eth(self, eth, timestamp):
     src = dnet.eth_ntoa(eth.src)
     dst = dnet.eth_ntoa(eth.dst)
     data = eth.data
     src_dst = src + ":" + dst
     if src_dst not in self.peers:
         iter = self.peer_treestore.append(None, [src, dst, "", "", "", -1])
         dict = self.parse_label(data, iter, {})
         self.peers[src_dst] = (iter, dict)
         self.log("MPLS: Got new MPLS communication: %s -> %s" % (src, dst))
     else:
         (iter, dict) = self.peers[src_dst]
         self.parse_label(data, iter, dict)
Exemple #6
0
 def recv_pkt(self, pc, pkt):
     arp = dpkt.ethernet.Ethernet(pkt).arp
     try:
         old = self.cache[arp.spa]
         if old != arp.sha:
             self.cache[arp.spa] = arp.sha
             print 'CHANGE: %s is-at %s (was-at %s)' % \
                   (dnet.ip_ntoa(arp.spa), dnet.eth_ntoa(arp.sha),
                    dnet.eth_ntoa(old))
     except KeyError:
         self.cache[arp.spa] = arp.sha
         print 'NEW: %s is-at %s' % (dnet.ip_ntoa(arp.spa),
                               dnet.eth_ntoa(arp.sha))
Exemple #7
0
 def recv_pkt(self, pc, pkt):
     arp = dpkt.ethernet.Ethernet(pkt).arp
     try:
         old = self.cache[arp.spa]
         if old != arp.sha:
             self.cache[arp.spa] = arp.sha
             print 'CHANGE: %s is-at %s (was-at %s)' % \
                   (dnet.ip_ntoa(arp.spa), dnet.eth_ntoa(arp.sha),
                    dnet.eth_ntoa(old))
     except KeyError:
         self.cache[arp.spa] = arp.sha
         print 'NEW: %s is-at %s' % (dnet.ip_ntoa(
             arp.spa), dnet.eth_ntoa(arp.sha))
Exemple #8
0
 def input_udp(self, eth, ip, udp, timestamp):
     if ip.src != self.ip:
         pkg = glbp_packet()
         data = pkg.parse(str(udp.data))
         req_resp = []
         auth = None
         nonce = None
         auth_str = "Unauthenticated"
         while len(data) > 0:
             #~ print "len: %d data: %s" % (len(data), data.encode("hex"))
             tlv = glbp_tlv()
             tlv.parse(data)
             if tlv.tlv_type == glbp_tlv.TYPE_HELLO:                    
                 hello = glbp_tlv_hello()
                 data = hello.parse(data)
             elif tlv.tlv_type == glbp_tlv.TYPE_REQ_RESP:
                 tmp = glbp_tlv_req_resp()
                 data = tmp.parse(data)
                 if not tmp.vmac == "\x00\x00\x00\x00\x00\x00":
                     req_resp.append(tmp)
             elif tlv.tlv_type == glbp_tlv.TYPE_AUTH:
                 auth = glbp_tlv_auth()
                 data = auth.parse(data)
                 if auth.auth_type == glbp_tlv_auth.TYPE_PLAIN:
                     auth_str = "Plaintext: '%s'" % auth.secret[:-1]
                 elif auth.auth_type == glbp_tlv_auth.TYPE_MD5_STRING:
                     auth_str = "MD5 String: '%s'" % auth.secret.encode("hex")
                 elif auth.auth_type == glbp_tlv_auth.TYPE_MD5_CHAIN:
                     auth_str = "MD5 Chain: '%s'" % auth.secret.encode("hex")
                 else:
                     auth_str = "Unknown"
             else:
                 #~ print "type: %d len: %d" % (tlv.tlv_type, tlv.tlv_length)
                 data = data[tlv.tlv_length:]
         try:
             src = dnet.ip_ntoa(ip.src)
         except:
             pass
         
         if ip.src in self.peers:
             (iter, _, _, req_resp_old, _, _, _) = self.peers[ip.src]
             for i in req_resp:
                 if not i in req_resp_old:
                     req_resp_old.append(i)
                     self.treestore.append(iter, ["", "", i.weight, dnet.eth_ntoa(i.vmac), ""])
         else:
             iter = self.treestore.append(None, [src, dnet.ip_ntoa(hello.addr), hello.prio, "Seen", auth_str])
             for req in req_resp:
                 self.treestore.append(iter, ["", "", req.weight, dnet.eth_ntoa(req.vmac), ""])
             self.peers[ip.src] = (iter, pkg, hello, req_resp, auth, False, False)
             self.log("GLBP: Got new peer %s" % (src))
Exemple #9
0
 def __repr__(self):
     try:
         if self.t == self.TYPE_DOMAIN:
             return self.v.strip("\x00")  # .encode("hex")
         elif self.t == self.TYPE_STATUS:
             t = "Access"
             m = "Off"
             d, = struct.unpack("!B", self.v[0])
             if d & 0x80 > 0:
                 t = "Trunk"
             if d & 0x07 == self.STATUS_ON:  # todo: get more administative states ?
                 m = "On"
             elif d & 0x07 == self.STATUS_DESIRABLE:
                 m = "Desirable"
             elif d & 0x07 == self.STATUS_AUTO:
                 m = "Auto"
             return "%s/%s" % (t, m)
         elif self.t == self.TYPE_TRUNK:
             t, = struct.unpack("!B", self.v[0])
             if (t & 0xE0) >> 5 == self.ENCAP_8021Q:
                 return "802.1Q"
             elif (t & 0xE0) >> 5 == self.ENCAP_ISL:
                 return "ISL"
             return "Unknown"  # todo: get more trunk states ?
         elif self.t == self.TYPE_SENDER:
             return dnet.eth_ntoa(self.v)
     except:
         pass
     return "%d, %d, %s" % (self.t, self.l, self.v.encode("hex"))
Exemple #10
0
 def __repr__(self):
     try:
         if self.t == self.TYPE_DOMAIN:
             return self.v.strip('\x00')  #.encode("hex")
         elif self.t == self.TYPE_STATUS:
             t = "Access"
             m = "Off"
             d, = struct.unpack("!B", self.v[0])
             if d & 0x80 > 0:
                 t = "Trunk"
             if d & 0x07 == self.STATUS_ON:  #todo: get more administative states ?
                 m = "On"
             elif d & 0x07 == self.STATUS_DESIRABLE:
                 m = "Desirable"
             elif d & 0x07 == self.STATUS_AUTO:
                 m = "Auto"
             return "%s/%s" % (t, m)
         elif self.t == self.TYPE_TRUNK:
             t, = struct.unpack("!B", self.v[0])
             if (t & 0xe0) >> 5 == self.ENCAP_8021Q:
                 return "802.1Q"
             elif (t & 0xe0) >> 5 == self.ENCAP_ISL:
                 return "ISL"
             return "Unknown"  #todo: get more trunk states ?
         elif self.t == self.TYPE_SENDER:
             return dnet.eth_ntoa(self.v)
     except:
         pass
     return "%d, %d, %s" % (self.t, self.l, self.v.encode("hex"))
Exemple #11
0
 def test_eth_misc(self):
     n = "\x00\x0d\x0e\x0a\x0d\x00"
     a = '00:0d:0e:0a:0d:00'
     self.failUnless(dnet.eth_ntoa(n) == a)
     self.failUnless(dnet.eth_aton(a) == n)
     dst = "\x00\x0d\x0e\x0a\x0d\x01"
     self.failUnless(dnet.eth_pack_hdr(n, dst, dnet.ETH_TYPE_IP) ==
                     '\x00\r\x0e\n\r\x00\x00\r\x0e\n\r\x01\x08\x00')
Exemple #12
0
 def recv_pkt(self, pc, pkt):
     eth = dpkt.ethernet.Ethernet(pkt)
     if eth.src not in self.cache and eth.type == dpkt.ethernet.ETH_TYPE_CDP:
         d = dict([ (tlv.type, tlv.data) for tlv in eth.cdp.data ])
         self.cache[eth.src] = d
         print "%s [%s] - %s [%s]" % (d[1], dnet.eth_ntoa(eth.src), dnet.ip_ntoa(d[2][0].data), d[3])
         pprint.pprint(d)
         print
Exemple #13
0
 def recv_pkt(self, pc, pkt):
     eth = dpkt.ethernet.Ethernet(pkt)
     if eth.src not in self.cache and eth.type == dpkt.ethernet.ETH_TYPE_CDP:
         d = dict([(tlv.type, tlv.data) for tlv in eth.cdp.data])
         self.cache[eth.src] = d
         print "%s [%s] - %s [%s]" % (d[1], dnet.eth_ntoa(
             eth.src), dnet.ip_ntoa(d[2][0].data), d[3])
         pprint.pprint(d)
         print
Exemple #14
0
 def test_eth_misc(self):
     n = b'\x00\x0d\x0e\x0a\x0d\x00'
     a = '00:0d:0e:0a:0d:00'
     self.assertTrue(dnet.eth_ntoa(n) == a)
     self.assertTrue(dnet.eth_aton(a) == n)
     dst = b'\x00\x0d\x0e\x0a\x0d\x01'
     self.assertTrue(
         dnet.eth_pack_hdr(n, dst, dnet.ETH_TYPE_IP) ==
         b'\x00\r\x0e\n\r\x00\x00\r\x0e\n\r\x01\x08\x00')
Exemple #15
0
 def test_eth_misc(self):
     n = "\x00\x0d\x0e\x0a\x0d\x00"
     a = '00:0d:0e:0a:0d:00'
     self.failUnless(dnet.eth_ntoa(n) == a)
     self.failUnless(dnet.eth_aton(a) == n)
     dst = "\x00\x0d\x0e\x0a\x0d\x01"
     self.failUnless(
         dnet.eth_pack_hdr(n, dst, dnet.ETH_TYPE_IP) ==
         '\x00\r\x0e\n\r\x00\x00\r\x0e\n\r\x01\x08\x00')
Exemple #16
0
 def input_eth(self, eth, timestamp):
     arp = dpkt.arp.ARP(str(eth.data))
     mac = dnet.eth_ntoa(str(eth.src))
     if self.flood_thread and self.flood_thread.is_alive():
         return
     if self.mac:
         if not eth.src == self.mac:
             if arp.op == dpkt.arp.ARP_OP_REQUEST and arp.spa != arp.tpa:
                 ip_dst = dnet.ip_ntoa(str(arp.tpa))
                 for h in self.hosts:
                     if mac == h:
                         (ip_src, rand_mac_src, iter_src, reply_src) = self.hosts[mac]
                         for i in self.hosts:
                             (ip, rand_mac_dst, iter_dst, reply_dst) = self.hosts[i]
                             if ip_dst == ip:
                                 break
                             else:
                                 reply_dst = None
                         if reply_src and reply_dst:
                             _arp = dpkt.arp.ARP(    hrd=dpkt.arp.ARP_HRD_ETH,
                                                     pro=dpkt.arp.ARP_PRO_IP,
                                                     op=dpkt.arp.ARP_OP_REPLY,
                                                     sha=dnet.eth_aton(rand_mac_dst),
                                                     spa=arp.tpa,
                                                     tha=arp.sha,
                                                     tpa=arp.spa
                                                     )
                             _eth = dpkt.ethernet.Ethernet(  dst=arp.sha,
                                                             src=dnet.eth_aton(rand_mac_dst),
                                                             type=dpkt.ethernet.ETH_TYPE_ARP,
                                                             data=str(_arp)
                                                             )
                             self.dnet.send(str(_eth))
                             break
             #return #???
     for h in self.hosts:
         if mac == h:
             return
         (ip, random_mac, iter, reply) = self.hosts[h]
         if mac == random_mac:
             return
     ip = dnet.ip_ntoa(str(arp.spa))
     if ip == "0.0.0.0":
         return
     rand_mac = [ 0x00, random.randint(0x00, 0xff), random.randint(0x00, 0xff), random.randint(0x00, 0xff), random.randint(0x00, 0xff), random.randint(0x00, 0xff) ]
     rand_mac = ':'.join(map(lambda x: "%02x" % x, rand_mac))
     if self.ui == 'gtk':
         iter = self.hosts_liststore.append([mac, ip, self.mac_to_vendor(mac)])
     elif self.ui == 'urw':
         self.hostlist.append(self.parent.menu_button("%s(%s) - %s" % (mac, self.mac_to_vendor(mac), ip), self.urw_hostlist_activated, mac))
         iter = None
     self.hosts[mac] = (ip, rand_mac, iter, False)
     if self.ui == 'gtk':
         self.mappings_liststore.append([mac, rand_mac])
Exemple #17
0
 def input_ip6(self, eth, ip6, timestamp):
     if eth.src == self.mac:
         return
     
     if ip6.nxt == dpkt.ip.IP_PROTO_ICMP6:
         icmp6 = dpkt.icmp6.ICMP6(str(ip6.data))
         mac = dnet.eth_ntoa(str(eth.src))
         if self.mac:
             if icmp6.type == dpkt.icmp6.ND_NEIGHBOR_SOLICIT:
                 ip6_dst = dnet.ip6_ntoa(str(icmp6.data)[4:20])
                 for h in self.hosts:
                     if mac == h:
                         (ip6_src, rand_mac_src, iter_src, reply_src) = self.hosts[mac]
                         for i in self.hosts:
                             (ip6, rand_mac_dst, iter_dst, reply_dst) = self.hosts[i]
                             if ip6_dst == ip6:
                                 break
                         if reply_src and reply_dst:
                             _icmp6 = dpkt.icmp6.ICMP6(  type=dpkt.icmp6.ND_NEIGHBOR_SOLICIT,
                                                         code=0,
                                                         data=struct.pack("!L16sBB6s", 0x60000000, dnet.ip6_aton(ip6_dst), 1, 1, rand_mac_dst)
                                                         )
                             _eth = dpkt.ethernet.Ethernet(  dst=eth.src,
                                                             src=dnet.eth_aton(rand_mac_dst),
                                                             type=dpkt.ip.IP_PROTO_IP6,
                                                             data=str(_icmp6)
                                                             )
                             self.dnet.send(str(_eth))
                             break
         if icmp6.type == dpkt.icmp6.ND_ROUTER_ADVERT:
             if mac in self.hosts:
                 (ip, random_mac, iter, reply) = self.hosts[mac]
                 if self.ui == 'gtk':
                     self.hosts_liststore.set(iter, 2, "R")
         for h in self.hosts:
             if mac == h:
                 return
             (ip, random_mac, iter, reply) = self.hosts[h]
             if mac == random_mac:
                 return
         ip = dnet.ip6_ntoa(ip6.src)
         if ip == "::":
             return            
         rand_mac = [ 0x00, random.randint(0x00, 0xff), random.randint(0x00, 0xff), random.randint(0x00, 0xff), random.randint(0x00, 0xff), random.randint(0x00, 0xff) ]
         rand_mac = ':'.join(map(lambda x: "%02x" % x, rand_mac))
         if self.ui == 'gtk':
             iter = self.hosts_liststore.append([mac, ip, "", self.mac_to_vendor(mac)])
         elif self.ui == 'urw':
             self.hostlist.append(self.parent.menu_button("%s(%s) - %s" % (mac, self.mac_to_vendor(mac), ip), self.urw_hostlist_activated, mac))
             iter = None
         self.hosts[mac] = (dnet.ip6_ntoa(ip6.src), rand_mac, iter, False)
         if self.ui == 'gtk':
             self.mappings_liststore.append([mac, rand_mac])
Exemple #18
0
 def recv_pkt(self, pc, pkt):
     ip = dpkt.ethernet.Ethernet(pkt).ip
     msg = dpkt.dhcp.DHCP(ip.udp.data)
     opts = dict(msg.opts)
     if dpkt.dhcp.DHCP_OPT_PARAM_REQ in opts:
         l = map(ord, opts[dpkt.dhcp.DHCP_OPT_PARAM_REQ])
         fp = ','.join(map(str, l))
         print fp
         print '%s: %s (%s [%s] - %s):\n%s\n' % (
             self.types[map(ord, opts[dpkt.dhcp.DHCP_OPT_MSGTYPE])[0] - 1],
             dnet.eth_ntoa(msg.chaddr), dnet.ip_ntoa(
                 ip.src), opts.get(dpkt.dhcp.DHCP_OPT_HOSTNAME, 'unknown'),
             opts.get(dpkt.dhcp.DHCP_OPT_VENDOR_ID,
                      'unknown'), self.fpos.get(fp, 'UNKNOWN: %s' % fp))
Exemple #19
0
 def input_eth(self, eth, timestamp):
     header = wlccp_header()
     ret = header.parse(eth.data)
     orig = dnet.eth_ntoa(header.orig_node_mac)
     dst = dnet.eth_ntoa(header.dst_node_mac)
     if header.msg_type == 0x01:
         #SCM advertisment request
         if not orig == "00:00:00:00:00:00":
             if orig not in self.hosts:
                 type = self.node_types[header.orig_node_type]
                 iter = self.hosts_liststore.append([orig, type, ""])
                 self.hosts[orig] = (iter,)
     elif header.msg_type == 0x41:
         #SCM advertisment reply
         if not dst == "00:00:00:00:00:00":
             type = self.node_types[header.dst_node_type]
             prio = str(ord(ret[10]))
             if dst not in self.hosts:
                 iter = self.hosts_liststore.append([dst, type, prio])
                 self.hosts[dst] = (iter,)
             else:
                 (iter,) = self.hosts[dst]
                 self.hosts_liststore.set(iter, self.HOSTS_TYPE_ROW, type, self.HOSTS_PRIO_ROW, prio)
Exemple #20
0
 def input_eth(self, eth, timestamp):
     if not eth.src == self.mac:
         src = dnet.eth_ntoa(str(eth.src))
         pdu = dtp_pdu()
         pdu.parse(str(eth.data)[8:])
         domain = pdu.get_tlv(dtp_tlv.TYPE_DOMAIN)
         status = pdu.get_tlv(dtp_tlv.TYPE_STATUS)
         trunk = pdu.get_tlv(dtp_tlv.TYPE_TRUNK)
         sender = pdu.get_tlv(dtp_tlv.TYPE_SENDER)
         if domain is None or status is None or trunk is None or sender is None:
             return
         if src not in self.peers:
             if self.ui == "gtk":
                 row_iter = self.liststore.append([src, str(domain), str(status), str(trunk), str(sender), ""])
             elif self.ui == "urw":
                 button = self.parent.menu_button(
                     "%s - DOMAIN(%s) %s %s %s" % (src, str(domain), str(status), str(trunk), str(sender)),
                     self.urw_peerlist_activated,
                     src,
                 )
                 self.peerlist.append(button)
                 row_iter = self.peerlist.index(button)
             peer = {"pdu": pdu, "row_iter": row_iter}
             self.peers[src] = peer
             self.log("DTP: Got new peer %s" % src)
         else:
             if self.ui == "gtk":
                 self.liststore.set(
                     self.peers[src]["row_iter"],
                     self.STORE_DOMAIN_ROW,
                     str(domain),
                     self.STORE_STATUS_ROW,
                     str(status),
                     self.STORE_TRUNK_ROW,
                     str(trunk),
                     self.STORE_SENDER_ROW,
                     str(sender),
                 )
             elif self.ui == "urw":
                 new_button = self.parent.menu_button(
                     "%s - DOMAIN(%s) %s %s %s" % (src, str(domain), str(status), str(trunk), str(sender)),
                     self.urw_peerlist_activated,
                     src,
                 )
                 self.peerlist[self.peers[src]["row_iter"]] = new_button
Exemple #21
0
 def input_eth(self, eth, timestamp):
     if not eth.src == self.mac:
         src = dnet.eth_ntoa(str(eth.src))
         pdu = dtp_pdu()
         pdu.parse(str(eth.data)[8:])
         domain = pdu.get_tlv(dtp_tlv.TYPE_DOMAIN)
         status = pdu.get_tlv(dtp_tlv.TYPE_STATUS)
         trunk = pdu.get_tlv(dtp_tlv.TYPE_TRUNK)
         sender = pdu.get_tlv(dtp_tlv.TYPE_SENDER)
         if domain is None or status is None or trunk is None or sender is None:
             return
         if src not in self.peers:
             if self.ui == "gtk":
                 row_iter = self.liststore.append([
                     src,
                     str(domain),
                     str(status),
                     str(trunk),
                     str(sender), ""
                 ])
             elif self.ui == "urw":
                 button = self.parent.menu_button(
                     "%s - DOMAIN(%s) %s %s %s" %
                     (src, str(domain), str(status), str(trunk),
                      str(sender)), self.urw_peerlist_activated, src)
                 self.peerlist.append(button)
                 row_iter = self.peerlist.index(button)
             peer = {"pdu": pdu, "row_iter": row_iter}
             self.peers[src] = peer
             self.log("DTP: Got new peer %s" % src)
         else:
             if self.ui == "gtk":
                 self.liststore.set(self.peers[src]["row_iter"],
                                    self.STORE_DOMAIN_ROW,
                                    str(domain), self.STORE_STATUS_ROW,
                                    str(status), self.STORE_TRUNK_ROW,
                                    str(trunk), self.STORE_SENDER_ROW,
                                    str(sender))
             elif self.ui == "urw":
                 new_button = self.parent.menu_button(
                     "%s - DOMAIN(%s) %s %s %s" %
                     (src, str(domain), str(status), str(trunk),
                      str(sender)), self.urw_peerlist_activated, src)
                 self.peerlist[self.peers[src]["row_iter"]] = new_button
def table(ip, mac, dumpall):
	global theTable
	if (dumpall == 0):
		try:
			asd = theTable[0]
		except NameError:
			theTable={}
			theTable[0] = 0
			theTable[len(theTable) + 1] = {}
			theTable[len(theTable)]['ip'] = ip
			theTable[len(theTable)]['mac'] = mac
		except KeyError:
			print "not done yet"
		else:
			theTable[len(theTable) + 1] = {}
			theTable[len(theTable)]['ip'] = ip
			theTable[len(theTable)]['mac'] = mac
	else:
		print "-------------------------------"
		for key in range(1, len(theTable)):
			print "%s at %s" % (dnet.eth_ntoa(theTable[key+1]['mac']),dnet.ip_ntoa(theTable[key+1]['ip']))
Exemple #23
0
def table(ip, mac, dumpall):
    global theTable
    if (dumpall == 0):
        try:
            asd = theTable[0]
        except NameError:
            theTable = {}
            theTable[0] = 0
            theTable[len(theTable) + 1] = {}
            theTable[len(theTable)]['ip'] = ip
            theTable[len(theTable)]['mac'] = mac
        except KeyError:
            print "not done yet"
        else:
            theTable[len(theTable) + 1] = {}
            theTable[len(theTable)]['ip'] = ip
            theTable[len(theTable)]['mac'] = mac
    else:
        print "-------------------------------"
        for key in range(1, len(theTable)):
            print "%s at %s" % (dnet.eth_ntoa(theTable[key + 1]['mac']),
                                dnet.ip_ntoa(theTable[key + 1]['ip']))
Exemple #24
0
    def input_ip6(self, eth, ip6, timestamp):
        if eth.src == self.mac:
            return

        if ip6.nxt == dpkt.ip.IP_PROTO_ICMP6:
            icmp6 = dpkt.icmp6.ICMP6(str(ip6.data))
            mac = dnet.eth_ntoa(str(eth.src))
            if self.mac:
                if icmp6.type == dpkt.icmp6.ND_NEIGHBOR_SOLICIT:
                    ip6_dst = dnet.ip6_ntoa(str(icmp6.data)[4:20])
                    for h in self.hosts:
                        if mac == h:
                            (ip6_src, rand_mac_src, iter_src,
                             reply_src) = self.hosts[mac]
                            for i in self.hosts:
                                (ip6, rand_mac_dst, iter_dst,
                                 reply_dst) = self.hosts[i]
                                if ip6_dst == ip6:
                                    break
                            if reply_src and reply_dst:
                                _icmp6 = dpkt.icmp6.ICMP6(
                                    type=dpkt.icmp6.ND_NEIGHBOR_SOLICIT,
                                    code=0,
                                    data=struct.pack("!L16sBB6s", 0x60000000,
                                                     dnet.ip6_aton(ip6_dst), 1,
                                                     1, rand_mac_dst))
                                _eth = dpkt.ethernet.Ethernet(
                                    dst=eth.src,
                                    src=dnet.eth_aton(rand_mac_dst),
                                    type=dpkt.ip.IP_PROTO_IP6,
                                    data=str(_icmp6))
                                self.dnet.send(str(_eth))
                                break
            if icmp6.type == dpkt.icmp6.ND_ROUTER_ADVERT:
                if mac in self.hosts:
                    (ip, random_mac, iter, reply) = self.hosts[mac]
                    if self.ui == 'gtk':
                        self.hosts_liststore.set(iter, 2, "R")
            for h in self.hosts:
                if mac == h:
                    return
                (ip, random_mac, iter, reply) = self.hosts[h]
                if mac == random_mac:
                    return
            ip = dnet.ip6_ntoa(ip6.src)
            if ip == "::":
                return
            rand_mac = [
                0x00,
                random.randint(0x00, 0xff),
                random.randint(0x00, 0xff),
                random.randint(0x00, 0xff),
                random.randint(0x00, 0xff),
                random.randint(0x00, 0xff)
            ]
            rand_mac = ':'.join(map(lambda x: "%02x" % x, rand_mac))
            if self.ui == 'gtk':
                iter = self.hosts_liststore.append(
                    [mac, ip, "", self.mac_to_vendor(mac)])
            elif self.ui == 'urw':
                self.hostlist.append(
                    self.parent.menu_button(
                        "%s(%s) - %s" % (mac, self.mac_to_vendor(mac), ip),
                        self.urw_hostlist_activated, mac))
                iter = None
            self.hosts[mac] = (dnet.ip6_ntoa(ip6.src), rand_mac, iter, False)
            if self.ui == 'gtk':
                self.mappings_liststore.append([mac, rand_mac])
Exemple #25
0
 def input_udp(self, eth, ip, udp, timestamp):
     header = wlccp_header()
     ret = header.parse(udp.data)
     try:
         if DEBUG:
             print "WLCCP-TYPE %X" % header.msg_type
         if header.msg_type & 0x3f == 0x0b:
             #EAP AUTH
             eap_auth = wlccp_eap_auth()
             ret = eap_auth.parse(ret)
             host = dnet.eth_ntoa(eap_auth.requestor_mac)
             if DEBUG:
                 print "addr %s, type %X @ %s" % (dnet.eth_ntoa(eap_auth.requestor_mac), eap_auth.aaa_msg_type, timestamp)
             if host in self.comms:
                 (iter, leap, leap_pw, nsk, nonces, ctk) = self.comms[host]
             elif not host == "00:00:00:00:00:00":
                 iter = self.comms_treestore.append(None, ["%s\n       <=>\n%s" % (dnet.eth_ntoa(header.orig_node_mac), dnet.eth_ntoa(header.dst_node_mac)), self.node_types[eap_auth.requestor_type], "", host])
                 self.comms[host] = (iter, (None, None, None, None), None, None, (None, None, None, None, None, (None, None)), None)
             (eapol_version, eapol_type, eapol_len) = struct.unpack("!BBH", ret[2:6])
             ret = ret[6:]
             #check EAP-TYPE
             if eapol_type == 0x00:
                 (eap_code, eap_id, eap_len) = struct.unpack("!BBH", ret[:4])
                 ret = ret[4:]
                 #check EAP-CODE
                 if eap_code == 0x01:
                     (leap_type, leap_version, leap_reserved, leap_count) = struct.unpack("!BBBB", ret[:4])
                     ret = ret[4:]
                     #EAP-REQUEST
                     #check the leap hdr
                     if leap_type == 0x11 and leap_version == 0x01 and leap_reserved == 0x00 and leap_count == 0x08:
                         (leap_auth_chall, leap_auth_resp, leap_supp_chall, leap_supp_resp) = leap
                         if not leap_auth_chall and not leap_auth_resp and not leap_supp_chall and not leap_supp_resp:
                             id = eap_id
                             chall = ret[:8]
                             user = ret[8:16]
                             self.comms_treestore.set(iter, self.COMMS_STATE_ROW, "EAP-AUTH challenge from authenticator seen")
                             self.comms_treestore.append(iter, [ "User", user, "", "" ])
                             self.log("WLCCP: EAP-AUTH challenge from authenticator seen for %s" % host)
                             self.comms[host] = (iter, ((id, chall, user), leap_auth_resp, leap_supp_chall, leap_supp_resp), leap_pw, nsk, nonces, ctk)
                         elif leap_auth_chall and leap_auth_resp and not leap_supp_chall and not leap_supp_resp:
                             chall = ret[:8]
                             self.comms_treestore.set(iter, self.COMMS_STATE_ROW, "EAP-AUTH challenge from supplicant seen")
                             self.log("WLCCP: EAP-AUTH challenge from supplicant seen for %s" % host)
                             self.comms[host] = (iter, (leap_auth_chall, leap_auth_resp, chall, leap_supp_resp), leap_pw, nsk, nonces, ctk)
                         else:
                             if DEBUG:
                                 self.log("WLCCP: fail 5 %s %s %s %s" % (leap_auth_chall, leap_auth_resp, leap_supp_chall, leap_supp_resp))
                     else:
                         if DEBUG:
                             self.log("WLCCP: fail 3 %X %X %X %X" % (leap_type, leap_version, leap_reserved, leap_count))
                 elif eap_code == 0x02:
                     (leap_type, leap_version, leap_reserved, leap_count) = struct.unpack("!BBBB", ret[:4])
                     ret = ret[4:]
                     #EAP-RESPONSE
                     #check the leap hdr
                     if leap_type == 0x11 and leap_version == 0x01 and leap_reserved == 0x00 and leap_count == 0x18:
                         (leap_auth_chall, leap_auth_resp, leap_supp_chall, leap_supp_resp) = leap
                         if leap_auth_chall and not leap_auth_resp and not leap_supp_chall and not leap_supp_resp:
                             resp = ret[:24]
                             self.comms_treestore.set(iter, self.COMMS_STATE_ROW, "EAP-AUTH response from authenticator seen")
                             self.log("WLCCP: EAP-AUTH response from authenticator seen for %s" % host)
                             self.comms[host] = (iter, (leap_auth_chall, resp, leap_supp_chall, leap_supp_resp), leap_pw, nsk, nonces, ctk)
                         elif leap_auth_chall and leap_auth_resp and leap_supp_chall and not leap_supp_resp:
                             resp = ret[:24]
                             self.comms_treestore.set(iter, self.COMMS_STATE_ROW, "EAP-AUTH response from supplicant seen")
                             self.comms_treestore.append(iter, [ "Password", "*ready to crack*", "", "" ])
                             self.log("WLCCP: EAP-AUTH response from supplicant seen for %s" % host)
                             self.comms[host] = (iter, (leap_auth_chall, leap_auth_resp, leap_supp_chall, resp), leap_pw, nsk, nonces, ctk)
                         else:
                             if DEBUG:
                                 self.log("WLCCP: fail 6 %s %s %s %s" % (leap_auth_chall, leap_auth_resp, leap_supp_chall, leap_supp_resp))
                     else:
                         if DEBUG:
                             self.log("WLCCP: fail 4 %X %X %X %X" % (leap_type, leap_version, leap_reserved, leap_count))
                 else:
                     if DEBUG:
                         self.log("WLCCP: fail 2 %X" % eap_code)
             else:
                 if DEBUG:
                     self.log("WLCCP: fail 1 %X" % eapol_type)
         elif header.msg_type & 0x3f == 0x0c:
             host = dnet.eth_ntoa(header.orig_node_mac)
             if header.msg_type & 0xc0 == 0x40:
                 #cmPathInit_Reply found
                 if host in self.comms:
                     (iter, leap, leap_pw, nsk, (supp_node, dst_node, nonce_req, nonce_repl, counter, mic), ctk) = self.comms[host]
                     #skip WTLV_CM_PATH_INIT header
                     ret = ret[18:]
                     #skip WTLV_INIT_SESSION header
                     ret = ret[8:]
                     (type, len) = struct.unpack("!HH", ret[:4])
                     if not type == 0x10a or not len == 0x5a:
                         if DEBUG:
                             self.log("WLCCP: malformed WTLV_IN_SECURE_CONTEXT_REPLY header")
                         return
                     #get nonces from WTLV_IN_SECURE_CONTEXT_REPLY header
                     counter = ret[4:8]
                     supp_node = ret[8:16]
                     dst_node = ret[16:24]
                     nonces = ret[24:56]
                     #skip session timeout in WTLV_IN_SECURE_CONTEXT_REPLY header
                     ret = ret[60:]
                     #check for WTLV_MIC header
                     (type, len) = struct.unpack("!HH", ret[:4])
                     if not type == 0x108 or not len == 0x1e:
                         if DEBUG:
                             self.log("WLCCP: malformed WTLV_MIC header")
                         return
                     mic = ret[14:30]
                     if DEBUG:
                         self.log("WLCCP: found MIC %s" % mic.encode("hex"))
                     self.log("WLCCP: PATH-REPLY seen for %s" % host)
                     self.comms[host] = (iter, leap, leap_pw, nsk, (supp_node, dst_node, nonce_req, nonces, counter, (mic, udp.data)), ctk)
             else:
                 #cmPathInit_Request found
                 if host in self.comms:
                     (iter, leap, leap_pw, nsk, (supp_node, dst_node, nonce_req, nonce_repl, counter, mic), ctk) = self.comms[host]
                     #skip WTLV_CM_PATH_INIT header
                     ret = ret[18:]
                     #skip WTLV_INIT_SESSION header
                     ret = ret[8:]
                     #get nonces from WTLV_IN_SECURE_CONTEXT_REPLY header
                     nonces = ret[26:58]                            
                     self.log("WLCCP: PATH-REQUEST seen for %s" % host)
                     self.comms[host] = (iter, leap, leap_pw, nsk, (supp_node, dst_node, nonces, nonce_repl, counter, mic), ctk)
         elif header.msg_type & 0x3f == 0x09:
             host = dnet.eth_ntoa(header.orig_node_mac)
             if header.msg_type & 0xc0 == 0x40:
                 #PreRegistration_Reply found
                 if host in self.comms:
                     (iter, leap, leap_pw, nsk, (supp_node, dst_node, nonce_req, nonce_repl, counter, mic), ctk) = self.comms[host]
                     #skip PreRegistration header
                     ret = ret[22:]
                     (contextreq_len,) = struct.unpack("!H", ret[2:4])
                     #substract WLCCP_MIC_len
                     contextreq_len = contextreq_len - 30
                     #get Supplicant-ID from WLCCP_MN_SECURE_CONTEXT_REQ
                     id = ret[16:24]
                     (id_type,) = struct.unpack("!H", id[:2])
                     if id_type == self.NODE_TYPE_CLIENT:
                         client = dnet.eth_ntoa(id[2:])
                         if client in self.clients:
                             (iter, org_host, ssid, key_mgmt, ap, crypt, msc, pmk) = self.clients[client]
                             #get Destination-ID from WLCCP_MN_SECURE_CONTEXT_REQ
                             ap = dnet.eth_ntoa(ret[10:16])
                             crypt = ret[24:contextreq_len]
                             #skip WLCCP_MN_SECURE_CONTEXT_REPLY
                             ret = ret[contextreq_len:]
                             #get Message Sequence Counter from WLCCP_MIC
                             msc = ret[4:12]
                             self.clients[client] = (iter, org_host, ssid, key_mgmt, ap, crypt, msc, pmk)
                             self.log("WLCCP: PREREGISTRATION-REPLY seen for %s" % client)
                             self.get_pmk(client)
             else:
                 #PreRegistration_Request found
                 if host in self.comms:
                     (iter, leap, leap_pw, nsk, (supp_node, dst_node, nonce_req, nonce_repl, counter, mic), ctk) = self.comms[host]
                     #skip PreRegistration header
                     ret = ret[22:]
                     (type, len) = struct.unpack("!HH", ret[:4])
                     if type == 0x10b and len == 0x95:
                         #get Supplicant-ID from WLCCP_MN_SECURE_CONTEXT_REQ
                         id = ret[16:24]
                         (id_type,) = struct.unpack("!H", id[:2])
                         if id_type == self.NODE_TYPE_CLIENT:
                             client = dnet.eth_ntoa(id[2:])
                             #get key management type
                             key_mgmt = ret[25:26]
                             #get ssid len and ssid
                             (ssid_len,) = struct.unpack("!H", ret[68:70])
                             ssid = ret[70:70 + ssid_len]
                             if client not in self.clients:
                                 iter = self.clients_liststore.append([client, ssid, ""])
                                 self.clients[client] = (iter, None, ssid, key_mgmt, None, None, None, None)
                             else:
                                 (iter, org_host, org_ssid, org_key_mgmt, ap, crypt, msc, pmk) = self.clients[client]
                                 self.clients[client] = (iter, host, ssid, key_mgmt, ap, crypt, msc, pmk)
                             self.log("WLCCP: PREREGISTRATION-REQUEST seen for %s on ssid %s" % (client, ssid))
                         else:
                             if DEBUG:
                                 self.log("WLCCP: FAIL 3 %s" % id.encode("hex"))
                     else:
                         if DEBUG:
                             self.log("WLCCP: FAIL 2 %i:%i" % (type, len))
                 else:
                     if DEBUG:
                         self.log("WLCCP: FAIL 1 %s" % host)
     except:
         if DEBUG:
             print '-'*60
             traceback.print_exc(file=sys.stdout)
             print '-'*60
Exemple #26
0
 def set_dnet(self, dnet_thread):
     self.dnet = dnet_thread
     self.mac = dnet.eth_ntoa(dnet_thread.eth.get())
     self.mac_entry.set_text(self.mac)
Exemple #27
0
    def input_udp(self, eth, ip, udp, timestamp):
        if ip.src != self.ip:
            pkg = glbp_packet()
            data = pkg.parse(str(udp.data))
            req_resp = []
            auth = None
            nonce = None
            auth_str = "Unauthenticated"
            while len(data) > 0:
                #~ print "len: %d data: %s" % (len(data), data.encode("hex"))
                tlv = glbp_tlv()
                tlv.parse(data)
                if tlv.tlv_type == glbp_tlv.TYPE_HELLO:
                    hello = glbp_tlv_hello()
                    data = hello.parse(data)
                elif tlv.tlv_type == glbp_tlv.TYPE_REQ_RESP:
                    tmp = glbp_tlv_req_resp()
                    data = tmp.parse(data)
                    if not tmp.vmac == "\x00\x00\x00\x00\x00\x00":
                        req_resp.append(tmp)
                elif tlv.tlv_type == glbp_tlv.TYPE_AUTH:
                    auth = glbp_tlv_auth()
                    data = auth.parse(data)
                    if auth.auth_type == glbp_tlv_auth.TYPE_PLAIN:
                        auth_str = "Plaintext: '%s'" % auth.secret[:-1]
                    elif auth.auth_type == glbp_tlv_auth.TYPE_MD5_STRING:
                        auth_str = "MD5 String: '%s'" % auth.secret.encode(
                            "hex")
                    elif auth.auth_type == glbp_tlv_auth.TYPE_MD5_CHAIN:
                        auth_str = "MD5 Chain: '%s'" % auth.secret.encode(
                            "hex")
                    else:
                        auth_str = "Unknown"
                else:
                    #~ print "type: %d len: %d" % (tlv.tlv_type, tlv.tlv_length)
                    data = data[tlv.tlv_length:]
            try:
                src = dnet.ip_ntoa(ip.src)
            except:
                pass

            if ip.src in self.peers:
                (iter, _, _, req_resp_old, _, _, _) = self.peers[ip.src]
                for i in req_resp:
                    if not i in req_resp_old:
                        req_resp_old.append(i)
                        self.treestore.append(
                            iter,
                            ["", "", i.weight,
                             dnet.eth_ntoa(i.vmac), ""])
            else:
                iter = self.treestore.append(None, [
                    src,
                    dnet.ip_ntoa(hello.addr), hello.prio, "Seen", auth_str
                ])
                for req in req_resp:
                    self.treestore.append(
                        iter,
                        ["", "", req.weight,
                         dnet.eth_ntoa(req.vmac), ""])
                self.peers[ip.src] = (iter, pkg, hello, req_resp, auth, False,
                                      False)
                self.log("GLBP: Got new peer %s" % (src))
Exemple #28
0
 def check_eth(self, eth):
     if dnet.eth_ntoa(str(eth.dst)) == DTP_DEST_MAC:
         return (True, True)
     return (False, False)
Exemple #29
0
 def check_eth(self, eth):
     if dnet.eth_ntoa(str(eth.dst)) == DTP_DEST_MAC:
         return (True, True)
     return (False, False)