Example #1
0
    def run(self):
        self.parent.log("VRRP-3: Thread started")
        while self.running:
            for i in self.parent.peers:
                (iter, pkg, state, arp) = self.parent.peers[i]
                if state:
                    src_mac = dnet.eth_aton("00:00:5e:00:01:%02x" % (pkg.id))
                    vrrp = vrrp_packet(pkg.id, 255, pkg.auth_type, pkg.auth_data, 1, pkg.ips)
                    data = vrrp.render()
                    ip_hdr = dpkt.ip.IP(    ttl=255,
                                            p=dpkt.ip.IP_PROTO_VRRP,
                                            src=self.parent.ip,
                                            dst=dnet.ip_aton(VRRP3_MULTICAST_ADDRESS),
                                            data=data
                                            )
                    ip_hdr.len += len(ip_hdr.data)
                    ip_hdr.data = vrrp.build_checksum(ip_hdr.data, ip_hdr)
                    eth_hdr = dpkt.ethernet.Ethernet(   dst=dnet.eth_aton(VRRP3_MULTICAST_MAC),
                                                        src=src_mac,
                                                        type=dpkt.ethernet.ETH_TYPE_IP,
                                                        data=str(ip_hdr)
                                                        )
                    self.parent.dnet.send(str(eth_hdr))
                    if arp:
                        brdc_mac = dnet.eth_aton("ff:ff:ff:ff:ff:ff")
                        stp_uplf_mac = dnet.eth_aton("01:00:0c:cd:cd:cd")
                        src_mac = self.parent.mac
                        for j in pkg.ips:
                            arp_hdr = dpkt.arp.ARP( hrd=dpkt.arp.ARP_HRD_ETH,
                                                pro=dpkt.arp.ARP_PRO_IP,
                                                op=dpkt.arp.ARP_OP_REPLY,
                                                sha=src_mac,
                                                spa=j,
                                                tha=brdc_mac,
                                                tpa=j
                                                )
                            eth_hdr = dpkt.ethernet.Ethernet(   dst=brdc_mac,
                                                                src=src_mac,
                                                                type=dpkt.ethernet.ETH_TYPE_ARP,
                                                                data=str(arp_hdr)
                                                                )
                            self.parent.dnet.send(str(eth_hdr))

                            arp_hdr = dpkt.arp.ARP( hrd=dpkt.arp.ARP_HRD_ETH,
                                                pro=dpkt.arp.ARP_PRO_IP,
                                                op=dpkt.arp.ARP_OP_REPLY,
                                                sha=src_mac,
                                                spa=j,
                                                tha=stp_uplf_mac,
                                                tpa=j
                                                )
                            eth_hdr = dpkt.ethernet.Ethernet(   dst=stp_uplf_mac,
                                                                src=src_mac,
                                                                type=dpkt.ethernet.ETH_TYPE_ARP,
                                                                data=str(arp_hdr)
                                                                )
                            self.parent.dnet.send(str(eth_hdr))
                        self.parent.peers[i] = (iter, pkg, state, arp - 1)
            time.sleep(1)
        self.parent.log("VRRP-3: Thread terminated")
Example #2
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
Example #3
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
Example #4
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])
Example #5
0
 def invalid_option(self):
     echo6 = dpkt.icmp6.ICMP6.Echo(  id=1234,
                                     seq=56789,
                                     data="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                                     )
     icmp6 = dpkt.icmp6.ICMP6(   type=dpkt.icmp6.ICMP6_ECHO_REQUEST,
                                 code=0,
                                 data=echo6
                                 )
     icmp6_str = str(icmp6)
     ip6 = dpkt.ip6.IP6( src=dnet.ip6_aton(self.ip6_ll),
                         dst=dnet.ip6_aton("ff02::1"),
                         nxt=dpkt.ip.IP_PROTO_HOPOPTS,
                         hlim=1,
                         data=icmp6,
                         plen=len(icmp6_str)
                         )
     ip6.extension_hdrs={}
     for i in dpkt.ip6.ext_hdrs:
         ip6.extension_hdrs[i]=None
     rand = "".join([ chr(random.randint(0x00, 0xff)) for i in xrange(13) ])
     hopopt = dpkt.ip6.IP6HopOptsHeader(nxt=dpkt.ip.IP_PROTO_ICMP6, len=1, data=struct.pack("!B13s", 1, rand))
     ip6.extension_hdrs[dpkt.ip.IP_PROTO_HOPOPTS] = hopopt
     ip6.plen = ip6.plen + len(str(hopopt))
     ip6_pseudo = struct.pack('!16s16sIxxxB', ip6.src, ip6.dst, len(icmp6_str), dpkt.ip.IP_PROTO_ICMP6)
     icmp6.sum = ichecksum_func(ip6_pseudo + icmp6_str)
     eth = dpkt.ethernet.Ethernet(   dst=dnet.eth_aton("33:33:00:00:00:01"),
                                     src=self.mac,
                                     data=str(ip6),
                                     type=dpkt.ethernet.ETH_TYPE_IP6
                                     )
     self.dnet.send(str(eth))
Example #6
0
 def invalid_header(self):
     echo6 = dpkt.icmp6.ICMP6.Echo(  id=1234,
                                     seq=56789,
                                     data="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                                     )
     icmp6 = dpkt.icmp6.ICMP6(   type=dpkt.icmp6.ICMP6_ECHO_REQUEST,
                                 code=0,
                                 data=echo6
                                 )
     icmp6_str = str(icmp6)
     rand = "".join([ chr(random.randint(0x00, 0xff)) for i in xrange(14) ])
     data_str = struct.pack("!BB14s", dpkt.ip.IP_PROTO_ICMP6, 1, rand) + icmp6_str
     ip6 = dpkt.ip6.IP6( src=dnet.ip6_aton(self.ip6_ll),
                         dst=dnet.ip6_aton("ff02::1"),
                         nxt=159,
                         hlim=64,
                         plen=len(data_str)
                         )
     ip6.extension_hdrs={}
     for i in dpkt.ip6.ext_hdrs:
         ip6.extension_hdrs[i]=None
     ip6_pseudo = struct.pack('!16s16sIxxxB', ip6.src, ip6.dst, len(icmp6_str), dpkt.ip.IP_PROTO_ICMP6)
     icmp6.sum = ichecksum_func(ip6_pseudo + icmp6_str)
     icmp6_str = str(icmp6)
     data_str = struct.pack("!BB14s", dpkt.ip.IP_PROTO_ICMP6, 1, rand) + icmp6_str
     ip6.data = data_str
     eth = dpkt.ethernet.Ethernet(   src=self.mac,
                                     dst=dnet.eth_aton("33:33:00:00:00:01"),
                                     data=str(ip6),
                                     type=dpkt.ethernet.ETH_TYPE_IP6
                                     )
     self.dnet.send(str(eth))
Example #7
0
 def scan(self):
     echo6 = dpkt.icmp6.ICMP6.Echo(  id=1234,
                                     seq=56789,
                                     data="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
                                     )
     icmp6 = dpkt.icmp6.ICMP6(   type=dpkt.icmp6.ICMP6_ECHO_REQUEST,
                                 code=0,
                                 data=echo6
                                 )
     icmp6_str = str(icmp6)
     ip6 = dpkt.ip6.IP6( src=dnet.ip6_aton(self.ip6_ll),
                         dst=dnet.ip6_aton("ff02::1"),
                         nxt=dpkt.ip.IP_PROTO_ICMP6,
                         hlim=64,
                         data=icmp6,
                         plen=len(icmp6_str)
                         )
     ip6.extension_hdrs={}
     for i in dpkt.ip6.ext_hdrs:
         ip6.extension_hdrs[i]=None
     ip6_pseudo = struct.pack('!16s16sIxxxB', ip6.src, ip6.dst, ip6.plen, ip6.nxt)
     icmp6.sum = ichecksum_func(ip6_pseudo + icmp6_str)
     eth = dpkt.ethernet.Ethernet(   src=self.mac,
                                     dst=dnet.eth_aton("33:33:00:00:00:01"),
                                     data=str(ip6),
                                     type=dpkt.ethernet.ETH_TYPE_IP6
                                     )
     self.dnet.send(str(eth))
Example #8
0
 def run(self):
     self.parent.log("RIP: Thread started")
     timer = 15
     while self.running:
         if timer == 15:
             timer = 0
             rlist = []
             for ip in self.parent.routes:
                 (iter, mask, nh, metrik) = self.parent.routes[ip]
                 rlist.append(rip_entry(rip_entry.AF_INET, 0, dnet.ip_aton(ip), dnet.ip_aton(mask), dnet.ip_aton(nh), int(metrik)))
             msg = rip_message(rip_message.COMMAND_RESPONSE, rlist)
             data = msg.render()
             for dst in self.parent.hosts:
                 udp_hdr = dpkt.udp.UDP( sport=RIP_PORT,
                                         dport=RIP_PORT,
                                         data=data
                                         )
                 udp_hdr.ulen += len(udp_hdr.data)
                 ip_hdr = dpkt.ip.IP(    ttl=2,
                                         p=dpkt.ip.IP_PROTO_UDP,
                                         src=self.parent.ip,
                                         dst=dnet.ip_aton(RIP_MULTICAST_ADDRESS),
                                         data=str(udp_hdr)
                                         )
                 ip_hdr.len += len(ip_hdr.data)
                 eth_hdr = dpkt.ethernet.Ethernet(   dst=dnet.eth_aton(RIP_MULTICAST_MAC),
                                                     src=self.parent.mac,
                                                     type=dpkt.ethernet.ETH_TYPE_IP,
                                                     data=str(ip_hdr)
                                                     )
                 self.parent.dnet.send(str(eth_hdr))
         timer = timer + 1
         time.sleep(1)
     self.parent.log("RIP: Thread terminated")
Example #9
0
 def hello(self):
     timer = DEFAULT_HOLD_TIME
     while self.running:
         if timer == DEFAULT_HOLD_TIME:
             timer = 0
             params = eigrp_param(1, 0, 1, 0, 0, 15)
             version = eigrp_version(self.parent.ios_ver, self.parent.eigrp_ver)  # (0xc02, 0x300)
             args = [params, version]
             if self.auth:
                 args.insert(0, self.auth)
             msg = eigrp_packet(eigrp_packet.EIGRP_OPTCODE_HELLO, 0, 0, 0, self.as_num, args)
             data = msg.render()
             if not self.parent.spoof:
                 self.send_multicast(data)
             else:
                 ip_hdr = dpkt.ip.IP(
                     ttl=2,
                     p=dpkt.ip.IP_PROTO_EIGRP,
                     src=self.parent.spoof,
                     dst=dnet.ip_aton(EIGRP_MULTICAST_ADDRESS),
                     data=data,
                 )
                 ip_hdr.len += len(ip_hdr.data)
                 eth_hdr = dpkt.ethernet.Ethernet(
                     dst=dnet.eth_aton(EIGRP_MULTICAST_MAC),
                     src=self.parent.mac,
                     type=dpkt.ethernet.ETH_TYPE_IP,
                     data=str(ip_hdr),
                 )
                 self.parent.dnet.send(str(eth_hdr))
         timer += 1
         time.sleep(1)
Example #10
0
 def invalid_option(self):
     echo6 = dpkt.icmp6.ICMP6.Echo(id=1234,
                                   seq=56789,
                                   data="ABCDEFGHIJKLMNOPQRSTUVWXYZ")
     icmp6 = dpkt.icmp6.ICMP6(type=dpkt.icmp6.ICMP6_ECHO_REQUEST,
                              code=0,
                              data=echo6)
     icmp6_str = str(icmp6)
     ip6 = dpkt.ip6.IP6(src=dnet.ip6_aton(self.ip6_ll),
                        dst=dnet.ip6_aton("ff02::1"),
                        nxt=dpkt.ip.IP_PROTO_HOPOPTS,
                        hlim=1,
                        data=icmp6,
                        plen=len(icmp6_str))
     ip6.extension_hdrs = {}
     for i in dpkt.ip6.ext_hdrs:
         ip6.extension_hdrs[i] = None
     rand = "".join([chr(random.randint(0x00, 0xff)) for i in xrange(13)])
     hopopt = dpkt.ip6.IP6HopOptsHeader(nxt=dpkt.ip.IP_PROTO_ICMP6,
                                        len=1,
                                        data=struct.pack("!B13s", 1, rand))
     ip6.extension_hdrs[dpkt.ip.IP_PROTO_HOPOPTS] = hopopt
     ip6.plen = ip6.plen + len(str(hopopt))
     ip6_pseudo = struct.pack('!16s16sIxxxB', ip6.src, ip6.dst,
                              len(icmp6_str), dpkt.ip.IP_PROTO_ICMP6)
     icmp6.sum = ichecksum_func(ip6_pseudo + icmp6_str)
     eth = dpkt.ethernet.Ethernet(dst=dnet.eth_aton("33:33:00:00:00:01"),
                                  src=self.mac,
                                  data=str(ip6),
                                  type=dpkt.ethernet.ETH_TYPE_IP6)
     self.dnet.send(str(eth))
Example #11
0
 def hello(self):
     timer = DEFAULT_HOLD_TIME
     while self.running:
         if timer == DEFAULT_HOLD_TIME:
             timer = 0
             params = eigrp_param(1, 0, 1, 0, 0, 15)
             version = eigrp_version(self.parent.ios_ver,
                                     self.parent.eigrp_ver)  #(0xc02, 0x300)
             args = [params, version]
             if self.auth:
                 args.insert(0, self.auth)
             msg = eigrp_packet(eigrp_packet.EIGRP_OPTCODE_HELLO, 0, 0, 0,
                                self.as_num, args)
             data = msg.render()
             if not self.parent.spoof:
                 self.send_multicast(data)
             else:
                 ip_hdr = dpkt.ip.IP(
                     ttl=2,
                     p=dpkt.ip.IP_PROTO_EIGRP,
                     src=self.parent.spoof,
                     dst=dnet.ip_aton(EIGRP_MULTICAST_ADDRESS),
                     data=data)
                 ip_hdr.len += len(ip_hdr.data)
                 eth_hdr = dpkt.ethernet.Ethernet(
                     dst=dnet.eth_aton(EIGRP_MULTICAST_MAC),
                     src=self.parent.mac,
                     type=dpkt.ethernet.ETH_TYPE_IP,
                     data=str(ip_hdr))
                 self.parent.dnet.send(str(eth_hdr))
         timer += 1
         time.sleep(1)
Example #12
0
 def invalid_header(self):
     echo6 = dpkt.icmp6.ICMP6.Echo(id=1234,
                                   seq=56789,
                                   data="ABCDEFGHIJKLMNOPQRSTUVWXYZ")
     icmp6 = dpkt.icmp6.ICMP6(type=dpkt.icmp6.ICMP6_ECHO_REQUEST,
                              code=0,
                              data=echo6)
     icmp6_str = str(icmp6)
     rand = "".join([chr(random.randint(0x00, 0xff)) for i in xrange(14)])
     data_str = struct.pack("!BB14s", dpkt.ip.IP_PROTO_ICMP6, 1,
                            rand) + icmp6_str
     ip6 = dpkt.ip6.IP6(src=dnet.ip6_aton(self.ip6_ll),
                        dst=dnet.ip6_aton("ff02::1"),
                        nxt=159,
                        hlim=64,
                        plen=len(data_str))
     ip6.extension_hdrs = {}
     for i in dpkt.ip6.ext_hdrs:
         ip6.extension_hdrs[i] = None
     ip6_pseudo = struct.pack('!16s16sIxxxB', ip6.src, ip6.dst,
                              len(icmp6_str), dpkt.ip.IP_PROTO_ICMP6)
     icmp6.sum = ichecksum_func(ip6_pseudo + icmp6_str)
     icmp6_str = str(icmp6)
     data_str = struct.pack("!BB14s", dpkt.ip.IP_PROTO_ICMP6, 1,
                            rand) + icmp6_str
     ip6.data = data_str
     eth = dpkt.ethernet.Ethernet(src=self.mac,
                                  dst=dnet.eth_aton("33:33:00:00:00:01"),
                                  data=str(ip6),
                                  type=dpkt.ethernet.ETH_TYPE_IP6)
     self.dnet.send(str(eth))
Example #13
0
 def scan(self):
     echo6 = dpkt.icmp6.ICMP6.Echo(id=1234,
                                   seq=56789,
                                   data="ABCDEFGHIJKLMNOPQRSTUVWXYZ")
     icmp6 = dpkt.icmp6.ICMP6(type=dpkt.icmp6.ICMP6_ECHO_REQUEST,
                              code=0,
                              data=echo6)
     icmp6_str = str(icmp6)
     ip6 = dpkt.ip6.IP6(src=dnet.ip6_aton(self.ip6_ll),
                        dst=dnet.ip6_aton("ff02::1"),
                        nxt=dpkt.ip.IP_PROTO_ICMP6,
                        hlim=64,
                        data=icmp6,
                        plen=len(icmp6_str))
     ip6.extension_hdrs = {}
     for i in dpkt.ip6.ext_hdrs:
         ip6.extension_hdrs[i] = None
     ip6_pseudo = struct.pack('!16s16sIxxxB', ip6.src, ip6.dst, ip6.plen,
                              ip6.nxt)
     icmp6.sum = ichecksum_func(ip6_pseudo + icmp6_str)
     eth = dpkt.ethernet.Ethernet(src=self.mac,
                                  dst=dnet.eth_aton("33:33:00:00:00:01"),
                                  data=str(ip6),
                                  type=dpkt.ethernet.ETH_TYPE_IP6)
     self.dnet.send(str(eth))
Example #14
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')
Example #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')
Example #16
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')
def arp_request(ipaddr):
	sha_str = str(dnet.intf().get(ifname)['link_addr'])
	sha = dnet.eth_aton(sha_str)
	spa_str = str(dnet.intf().get(ifname)['addr']).split("/")[0]
	spa = dnet.ip_aton(spa_str)
	tha = dnet.ETH_ADDR_BROADCAST
	tpa = dnet.ip_aton(ipaddr)
	pkt = ip_header(tha,sha,'\x08\x06') 
	pkt += arp_header('\x00\x01\x08\x00\x06\x04','\x00\x01', sha, spa, '\x00\x00\x00\x00\x00\x00', tpa)
	interface.send(pkt)
Example #18
0
def arp_request(ipaddr):
    sha_str = str(dnet.intf().get(ifname)['link_addr'])
    sha = dnet.eth_aton(sha_str)
    spa_str = str(dnet.intf().get(ifname)['addr']).split("/")[0]
    spa = dnet.ip_aton(spa_str)
    tha = dnet.ETH_ADDR_BROADCAST
    tpa = dnet.ip_aton(ipaddr)
    pkt = ip_header(tha, sha, '\x08\x06')
    pkt += arp_header('\x00\x01\x08\x00\x06\x04', '\x00\x01', sha, spa,
                      '\x00\x00\x00\x00\x00\x00', tpa)
    interface.send(pkt)
Example #19
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])
Example #20
0
 def run(self):
     self.parent.log("WLCCP: Election Thread started")
     header = wlccp_header(0xc1, 0x0, 0x8003, 0x41, 0x0, 0x2800, 0x0, dnet.eth_aton("00:00:00:00:00:00"), 0x2, dnet.eth_aton(self.mac))
     h_data = header.render("%s\x00\x01\x00\x00\xff\x00%s\x00\x00\x00\x00\x00\x02\x00\x00\x00\x05%s%s%s%s%s%s%s%s"
                 % ( dnet.eth_aton(self.mac),
                     dnet.eth_aton(self.mac),
                     self.BLOB1,
                     dnet.eth_aton(self.mac),
                     dnet.ip_aton(self.ip),
                     self.BLOB2,
                     dnet.ip_aton(self.ip),
                     self.BLOB3,
                     self.BLOB4,
                     self.BLOB5
                     )  )
     data = dnet.eth_pack_hdr(dnet.eth_aton(self.WLCCP_DST_MAC), dnet.eth_aton(self.mac), socket.htons(self.WLCCP_ETH_TYPE)) + h_data
     
     while self.running:
         if self.parent.dnet:
             self.parent.dnet.send(data)
             for x in xrange(self.delay):
                 if not self.running:
                     break
                 time.sleep(1)
     self.parent.log("WLCCP: Election Thread terminated")
Example #21
0
 def send_multicast(self, data):
     ip_hdr = dpkt.ip.IP(ttl=2,
                         p=dpkt.ip.IP_PROTO_EIGRP,
                         src=self.parent.address,
                         dst=dnet.ip_aton(EIGRP_MULTICAST_ADDRESS),
                         data=data)
     ip_hdr.len += len(ip_hdr.data)
     eth_hdr = dpkt.ethernet.Ethernet(
         dst=dnet.eth_aton(EIGRP_MULTICAST_MAC),
         src=self.parent.mac,
         type=dpkt.ethernet.ETH_TYPE_IP,
         data=str(ip_hdr))
     self.parent.dnet.send(str(eth_hdr))
Example #22
0
    def build_arp_reply(self, rec_mac, rec_ip, send_mac, impersonate_ip):
        """ Build an ARP-Reply-Packet
        """

        # (1) Building the ARP-Packet
        arp_p = arp.ARP()

        # sender's hardware address
        arp_p.sha = dnet.eth_aton(send_mac)

        # sender's protocol address
        arp_p.spa = socket.inet_aton(impersonate_ip)

        # target's hardware address
        arp_p.tha = dnet.eth_aton(rec_mac)

        # target's protocol address
        arp_p.tpa = socket.inet_aton(rec_ip)

        # type of operation
        arp_p.op = arp.ARP_OP_REPLY

        # (2) Building the wrapping Ethernet-Packet
        packet = ethernet.Ethernet()

        # sender's hardware address
        packet.src = dnet.eth_aton(send_mac)

        # target's hardware address
        packet.dst = dnet.eth_aton(rec_mac)

        # payload (ARP-Packet)
        packet.data = arp_p

        # type of ethernet packet
        packet.type = ethernet.ETH_TYPE_ARP

        return packet
Example #23
0
 def run(self):
     self.parent.log("ARP: Flood thread started")
     while self.running and self.no > 0:
         if self.parent.dnet:
             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))
             _eth = dpkt.ethernet.Ethernet(  dst=dnet.ETH_ADDR_BROADCAST,
                                             src=dnet.eth_aton(rand_mac),
                                             type=0x9000,
                                             data="\x00\x00\x01\x00\x00\x00" + "\x00" * 40
                                             )
             self.parent.dnet.send(str(_eth))
             self.no -= 1
         time.sleep(self.parent.flood_delay)
     self.parent.flood_togglebutton.set_active(False)
     self.parent.log("ARP: Flood thread terminated")
Example #24
0
 def scan(self, ips):
     for i in ips:
         arp = dpkt.arp.ARP( hrd=dpkt.arp.ARP_HRD_ETH,
                             pro=dpkt.arp.ARP_PRO_IP,
                             op=dpkt.arp.ARP_OP_REQUEST,
                             sha=self.mac,
                             spa=self.ip,
                             tpa=dnet.ip_aton(str(i))
                             )
         eth = dpkt.ethernet.Ethernet(   dst=dnet.eth_aton("ff:ff:ff:ff:ff:ff"),
                                         src=self.mac,
                                         type=dpkt.ethernet.ETH_TYPE_ARP,
                                         data=str(arp)
                                         )
         self.dnet.eth.send(str(eth))
         time.sleep(0.0001)
Example #25
0
 def send_multicast(self, data):
     ip_hdr = dpkt.ip.IP(
         ttl=2,
         p=dpkt.ip.IP_PROTO_EIGRP,
         src=self.parent.address,
         dst=dnet.ip_aton(EIGRP_MULTICAST_ADDRESS),
         data=data,
     )
     ip_hdr.len += len(ip_hdr.data)
     eth_hdr = dpkt.ethernet.Ethernet(
         dst=dnet.eth_aton(EIGRP_MULTICAST_MAC),
         src=self.parent.mac,
         type=dpkt.ethernet.ETH_TYPE_IP,
         data=str(ip_hdr),
     )
     self.parent.dnet.send(str(eth_hdr))
Example #26
0
 def run(self):
     self.parent.log("DTP: Thread started")
     timer = 30
     while self.running:
         if timer == 30:
             if not self.parent.target is None:
                 pdu = dtp_pdu(
                     1,
                     [
                         dtp_tlv(0x1,
                                 self.parent.target["pdu"].get_tlv(0x1).v),
                         dtp_tlv(0x2, "\x81"),
                         dtp_tlv(
                             0x3, "\xa5"
                         ),  #self.parent.target["pdu"].get_tlv(0x3).v),
                         dtp_tlv(0x4, self.parent.mac)
                     ])
             else:
                 if self.parent.ui == 'gtk':
                     domain = self.parent.domainentry.get_text()
                 elif self.parent.ui == 'urw':
                     domain = self.parent.domain.get_edit_text()
                 pdu = dtp_pdu(1, [
                     dtp_tlv(0x1, domain),
                     dtp_tlv(0x2, "\x81"),
                     dtp_tlv(0x3, "\xa5"),
                     dtp_tlv(0x4, self.parent.mac)
                 ])
             pkg = "\xaa\xaa\x03\x00\x00\x0c\x20\x04" + pdu.render()
             eth_hdr = dpkt.ethernet.Ethernet(
                 dst=dnet.eth_aton(DTP_DEST_MAC),
                 src=self.parent.mac,
                 type=len(pkg),
                 data=pkg)
             self.parent.dnet.send(str(eth_hdr))
             timer = 0
         timer = timer + 1
         time.sleep(1)
     self.parent.log("DTP: Thread terminated")
Example #27
0
 def run(self):
     self.parent.log("DTP: Thread started")
     timer = 30
     while self.running:
         if timer == 30:
             if not self.parent.target is None:
                 pdu = dtp_pdu(
                     1,
                     [
                         dtp_tlv(0x1, self.parent.target["pdu"].get_tlv(0x1).v),
                         dtp_tlv(0x2, "\x81"),
                         dtp_tlv(0x3, "\xa5"),  # self.parent.target["pdu"].get_tlv(0x3).v),
                         dtp_tlv(0x4, self.parent.mac),
                     ],
                 )
             else:
                 if self.parent.ui == "gtk":
                     domain = self.parent.domainentry.get_text()
                 elif self.parent.ui == "urw":
                     domain = self.parent.domain.get_edit_text()
                 pdu = dtp_pdu(
                     1,
                     [
                         dtp_tlv(0x1, domain),
                         dtp_tlv(0x2, "\x81"),
                         dtp_tlv(0x3, "\xa5"),
                         dtp_tlv(0x4, self.parent.mac),
                     ],
                 )
             pkg = "\xaa\xaa\x03\x00\x00\x0c\x20\x04" + pdu.render()
             eth_hdr = dpkt.ethernet.Ethernet(
                 dst=dnet.eth_aton(DTP_DEST_MAC), src=self.parent.mac, type=len(pkg), data=pkg
             )
             self.parent.dnet.send(str(eth_hdr))
             timer = 0
         timer = timer + 1
         time.sleep(1)
     self.parent.log("DTP: Thread terminated")
Example #28
0
 def run(self):
     self.parent.log("RIP: Thread started")
     timer = 15
     while self.running:
         if timer == 15:
             timer = 0
             rlist = []
             for ip in self.parent.routes:
                 (iter, mask, nh, metrik) = self.parent.routes[ip]
                 rlist.append(
                     rip_entry(rip_entry.AF_INET, 0, dnet.ip_aton(ip),
                               dnet.ip_aton(mask), dnet.ip_aton(nh),
                               int(metrik)))
             msg = rip_message(rip_message.COMMAND_RESPONSE, rlist)
             data = msg.render()
             for dst in self.parent.hosts:
                 udp_hdr = dpkt.udp.UDP(sport=RIP_PORT,
                                        dport=RIP_PORT,
                                        data=data)
                 udp_hdr.ulen += len(udp_hdr.data)
                 ip_hdr = dpkt.ip.IP(
                     ttl=2,
                     p=dpkt.ip.IP_PROTO_UDP,
                     src=self.parent.ip,
                     dst=dnet.ip_aton(RIP_MULTICAST_ADDRESS),
                     data=str(udp_hdr))
                 ip_hdr.len += len(ip_hdr.data)
                 eth_hdr = dpkt.ethernet.Ethernet(
                     dst=dnet.eth_aton(RIP_MULTICAST_MAC),
                     src=self.parent.mac,
                     type=dpkt.ethernet.ETH_TYPE_IP,
                     data=str(ip_hdr))
                 self.parent.dnet.send(str(eth_hdr))
         timer = timer + 1
         time.sleep(1)
     self.parent.log("RIP: Thread terminated")
Example #29
0
    def run(self):
        self.parent.log("HSRP: Thread started")
        while self.running:
            for i in self.parent.peers:
                if self.parent.peers[i]["state"]:
                    pkg = self.parent.peers[i]["pkg"]
                    auth = self.parent.peers[i]["auth"]
                    if not auth is None:
                        hsrp = hsrp_packet(hsrp_packet.OP_HELLO, hsrp_packet.STATE_ACTIVE, pkg.hello, pkg.hold, 255, pkg.group, "\x00" * 8, pkg.ip)
                        auth = hsrp_auth_tlv(auth.algo, auth.flags, self.parent.ip, auth.keyid, "\x00" * 16)
                        if self.parent.ui == 'gtk':
                            secret = self.parent.auth_entry.get_text()
                        elif self.parent.ui == 'urw':
                            secret = self.parent.auth_edit.get_edit_text()
                        key_length = struct.pack("<Q", (len(secret) << 3))
                        key_fill = secret + '\x80' + '\x00' * (55 - len(secret)) + key_length
                        salt = hsrp.render() + auth.render()
                        m = hashlib.md5()
                        m.update(key_fill)
                        m.update(salt)
                        m.update(secret)
                        auth.csum = m.digest()
                        data = hsrp.render() + auth.render()
                    else:
                        hsrp = hsrp_packet(hsrp_packet.OP_HELLO, hsrp_packet.STATE_ACTIVE, pkg.hello, pkg.hold, 255, pkg.group, pkg.auth_data, pkg.ip)
                        data = hsrp.render()
                    udp_hdr = dpkt.udp.UDP( sport=HSRP_PORT,
                                            dport=HSRP_PORT,
                                            data=data
                                            )
                    udp_hdr.ulen += len(udp_hdr.data)
                    ip_hdr = dpkt.ip.IP(    ttl=1,
                                            p=dpkt.ip.IP_PROTO_UDP,
                                            src=self.parent.ip,
                                            dst=dnet.ip_aton(HSRP_MULTICAST_ADDRESS),
                                            data=str(udp_hdr)
                                            )
                    ip_hdr.len += len(ip_hdr.data)
                    eth_hdr = dpkt.ethernet.Ethernet(   dst=dnet.eth_aton(HSRP_MULTICAST_MAC),
                                                        src=self.parent.mac,
                                                        type=dpkt.ethernet.ETH_TYPE_IP,
                                                        data=str(ip_hdr)
                                                        )
                    self.parent.dnet.send(str(eth_hdr))
                    if self.parent.peers[i]["arp"]:
                        src_mac = dnet.eth_aton("00:00:0c:07:ac:%02x" % (pkg.group))
                        brdc_mac = dnet.eth_aton("ff:ff:ff:ff:ff:ff")
                        stp_uplf_mac = dnet.eth_aton("01:00:0c:cd:cd:cd")
                        ip = struct.pack("!I", pkg.ip)
                        arp_hdr = dpkt.arp.ARP( hrd=dpkt.arp.ARP_HRD_ETH,
                                            pro=dpkt.arp.ARP_PRO_IP,
                                            op=dpkt.arp.ARP_OP_REPLY,
                                            sha=src_mac,
                                            spa=ip,
                                            tha=brdc_mac,
                                            tpa=ip
                                            )
                        eth_hdr = dpkt.ethernet.Ethernet(   dst=brdc_mac,
                                                            src=src_mac,
                                                            type=dpkt.ethernet.ETH_TYPE_ARP,
                                                            data=str(arp_hdr)
                                                            )
                        self.parent.dnet.send(str(eth_hdr))

                        arp_hdr = dpkt.arp.ARP( hrd=dpkt.arp.ARP_HRD_ETH,
                                            pro=dpkt.arp.ARP_PRO_IP,
                                            op=dpkt.arp.ARP_OP_REPLY,
                                            sha=src_mac,
                                            spa=ip,
                                            tha=stp_uplf_mac,
                                            tpa=ip
                                            )
                        eth_hdr = dpkt.ethernet.Ethernet(   dst=stp_uplf_mac,
                                                            src=src_mac,
                                                            type=dpkt.ethernet.ETH_TYPE_ARP,
                                                            data=str(arp_hdr)
                                                            )
                        self.parent.dnet.send(str(eth_hdr))
                        self.parent.peers[i]["arp"] = self.parent.peers[i]["arp"] - 1
            time.sleep(1)
        self.parent.log("HSRP: Thread terminated")
Example #30
0
    def add_spoof(self):
        data = []
        org_data = []
        hosts = []
        for host_upper in self.upper_add:
            (ip_upper, rand_mac_upper, iter_upper) = self.upper_add[host_upper]
            for host_lower in self.lower_add:
                (ip_lower, rand_mac_lower, iter_lower) = self.lower_add[host_lower]
                
                advert = struct.pack("!I16sBB6s", 0x60000000, dnet.ip6_aton(ip_upper), 2, 1, dnet.eth_aton(rand_mac_upper))
                icmp6 = dpkt.icmp6.ICMP6(   type=dpkt.icmp6.ND_NEIGHBOR_ADVERT,
                                            code=0,
                                            data=advert
                                            )
                icmp6_str = str(icmp6)
                ip6 = dpkt.ip6.IP6( src=dnet.ip6_aton(ip_upper),
                                    dst=dnet.ip6_aton(ip_lower),
                                    nxt=dpkt.ip.IP_PROTO_ICMP6,
                                    hlim=255,
                                    data=icmp6,
                                    plen=len(icmp6_str)
                                    )
                ip6.extension_hdrs={}
                for i in dpkt.ip6.ext_hdrs:
                    ip6.extension_hdrs[i]=None
                ip6_pseudo = struct.pack('!16s16sIxxxB', ip6.src, ip6.dst, ip6.plen, ip6.nxt)
                icmp6.sum = ichecksum_func(ip6_pseudo + icmp6_str)
                eth = dpkt.ethernet.Ethernet(   dst=dnet.eth_aton(host_lower),
                                                src=dnet.eth_aton(rand_mac_upper),
                                                data=str(ip6),
                                                type=dpkt.ethernet.ETH_TYPE_IP6
                                                )
                data.append(str(eth))
                advert = struct.pack("!I16sBB6s", 0x60000000, dnet.ip6_aton(ip_lower), 2, 1, dnet.eth_aton(host_upper))
                icmp6 = dpkt.icmp6.ICMP6(   type=dpkt.icmp6.ND_NEIGHBOR_ADVERT,
                                            code=0,
                                            data=advert
                                            )
                icmp6_str = str(icmp6)
                ip6 = dpkt.ip6.IP6( src=dnet.ip6_aton(ip_upper),
                                    dst=dnet.ip6_aton(ip_lower),
                                    nxt=dpkt.ip.IP_PROTO_ICMP6,
                                    hlim=255,
                                    data=icmp6,
                                    plen=len(icmp6_str)
                                    )
                ip6.extension_hdrs={}
                for i in dpkt.ip6.ext_hdrs:
                    ip6.extension_hdrs[i]=None
                ip6_pseudo = struct.pack('!16s16sIxxxB', ip6.src, ip6.dst, ip6.plen, ip6.nxt)
                icmp6.sum = ichecksum_func(ip6_pseudo + icmp6_str)
                eth = dpkt.ethernet.Ethernet(   dst=dnet.eth_aton(host_lower),
                                                src=dnet.eth_aton(host_upper),
                                                data=str(ip6),
                                                type=dpkt.ethernet.ETH_TYPE_IP6
                                                )
                org_data.append(str(eth))
                

                advert = struct.pack("!I16sBB6s", 0x60000000, dnet.ip6_aton(ip_lower), 2, 1, dnet.eth_aton(rand_mac_lower))
                icmp6 = dpkt.icmp6.ICMP6(   type=dpkt.icmp6.ND_NEIGHBOR_ADVERT,
                                            code=0,
                                            data=advert
                                            )
                icmp6_str = str(icmp6)
                ip6 = dpkt.ip6.IP6( src=dnet.ip6_aton(ip_lower),
                                    dst=dnet.ip6_aton(ip_upper),
                                    nxt=dpkt.ip.IP_PROTO_ICMP6,
                                    hlim=255,
                                    data=icmp6,
                                    plen=len(icmp6_str)
                                    )
                ip6.extension_hdrs={}
                for i in dpkt.ip6.ext_hdrs:
                    ip6.extension_hdrs[i]=None
                ip6_pseudo = struct.pack('!16s16sIxxxB', ip6.src, ip6.dst, ip6.plen, ip6.nxt)
                icmp6.sum = ichecksum_func(ip6_pseudo + icmp6_str)
                eth = dpkt.ethernet.Ethernet(   dst=dnet.eth_aton(host_upper),
                                                src=dnet.eth_aton(rand_mac_lower),
                                                data=str(ip6),
                                                type=dpkt.ethernet.ETH_TYPE_IP6
                                                )
                data.append(str(eth))
                advert = struct.pack("!I16sBB6s", 0x60000000, dnet.ip6_aton(ip_lower), 2, 1, dnet.eth_aton(host_lower))
                icmp6 = dpkt.icmp6.ICMP6(   type=dpkt.icmp6.ND_NEIGHBOR_ADVERT,
                                            code=0,
                                            data=advert
                                            )
                icmp6_str = str(icmp6)
                ip6 = dpkt.ip6.IP6( src=dnet.ip6_aton(ip_lower),
                                    dst=dnet.ip6_aton(ip_upper),
                                    nxt=dpkt.ip.IP_PROTO_ICMP6,
                                    hlim=255,
                                    data=icmp6,
                                    plen=len(icmp6_str)
                                    )
                ip6.extension_hdrs={}
                for i in dpkt.ip6.ext_hdrs:
                    ip6.extension_hdrs[i]=None
                ip6_pseudo = struct.pack('!16s16sIxxxB', ip6.src, ip6.dst, ip6.plen, ip6.nxt)
                icmp6.sum = ichecksum_func(ip6_pseudo + icmp6_str)
                eth = dpkt.ethernet.Ethernet(   dst=dnet.eth_aton(host_upper),
                                                src=dnet.eth_aton(host_lower),
                                                data=str(ip6),
                                                type=dpkt.ethernet.ETH_TYPE_IP6
                                                )
                org_data.append(str(eth))
                
            hosts.append(host_upper)

            mld = struct.pack("!xxHBBH16s", 1, 4, 0, 0, dnet.ip6_aton("ff02::1:ff00:0000")[:13] + dnet.ip6_aton(ip_upper)[13:])
            icmp6 = dpkt.icmp6.ICMP6(   type=143,
                                        code=0,
                                        data=mld
                                        )
            icmp6_str = str(icmp6)
            ip6 = dpkt.ip6.IP6( src=dnet.ip6_aton(ip_upper),
                                dst=dnet.ip6_aton("ff02::16"),
                                nxt=dpkt.ip.IP_PROTO_HOPOPTS,
                                hlim=1,
                                data=icmp6,
                                plen=len(icmp6_str) + 8
                                )
            ip6.extension_hdrs={}
            for i in dpkt.ip6.ext_hdrs:
                ip6.extension_hdrs[i]=None
            ip6.extension_hdrs[dpkt.ip.IP_PROTO_HOPOPTS] = dpkt.ip6.IP6HopOptsHeader(nxt=dpkt.ip.IP_PROTO_ICMP6, data=struct.pack("!BBHBB", 5, 2, 0, 1, 0))
            
            ip6_pseudo = struct.pack('!16s16sIxxxB', ip6.src, ip6.dst, len(icmp6_str), 
            dpkt.ip.IP_PROTO_ICMP6)
            icmp6.sum = ichecksum_func(ip6_pseudo + icmp6_str)
            eth = dpkt.ethernet.Ethernet(   dst=dnet.eth_aton("33:33:00:00:00:16"),
                                            src=self.mac,
                                            data=str(ip6),
                                            type=dpkt.ethernet.ETH_TYPE_IP6
                                            )
            self.dnet.send(str(eth))
            self.log("ICMP6: Joined multicast group " + dnet.ip6_ntoa(dnet.ip6_aton("ff02::1:ff00:0000")[:13] + dnet.ip6_aton(ip_upper)[13:]))
        for host_lower in self.lower_add:
            hosts.append(host_lower)
            (ip_lower, rand_mac_lower, iter_lower) = self.lower_add[host_lower]
            mld = struct.pack("!xxHBBH16s", 1, 4, 0, 0, dnet.ip6_aton("ff02::1:ff00:0000")[:13] + dnet.ip6_aton(ip_lower)[13:])
            icmp6 = dpkt.icmp6.ICMP6(   type=143,
                                        code=0,
                                        data=mld
                                        )
            icmp6_str = str(icmp6)
            ip6 = dpkt.ip6.IP6( src=dnet.ip6_aton(ip_lower),
                                dst=dnet.ip6_aton("ff02::16"),
                                nxt=dpkt.ip.IP_PROTO_HOPOPTS,
                                hlim=1,
                                data=icmp6,
                                plen=len(icmp6_str) + 8
                                )
            ip6.extension_hdrs={}
            for i in dpkt.ip6.ext_hdrs:
                ip6.extension_hdrs[i]=None
            ip6.extension_hdrs[dpkt.ip.IP_PROTO_HOPOPTS] = dpkt.ip6.IP6HopOptsHeader(nxt=dpkt.ip.IP_PROTO_ICMP6, data=struct.pack("!BBHBB", 5, 2, 0, 1, 0))
            
            ip6_pseudo = struct.pack('!16s16sIxxxB', ip6.src, ip6.dst, len(icmp6_str), 
            dpkt.ip.IP_PROTO_ICMP6)
            icmp6.sum = ichecksum_func(ip6_pseudo + icmp6_str)
            eth = dpkt.ethernet.Ethernet(   dst=dnet.eth_aton("33:33:00:00:00:16"),
                                            src=self.mac,
                                            data=str(ip6),
                                            type=dpkt.ethernet.ETH_TYPE_IP6
                                            )
            self.dnet.send(str(eth))
            self.log("ICMP6: Joined multicast group " + dnet.ip6_ntoa(dnet.ip6_aton("ff02::1:ff00:0000")[:13] + dnet.ip6_aton(ip_lower)[13:]))
        self.upper_add = {}
        self.lower_add = {}
        return (data, org_data, hosts)
Example #31
0
    def add_spoof(self):
        data = []
        org_data = []
        hosts = []
        for host_upper in self.upper_add:
            (ip_upper, rand_mac_upper, iter_upper) = self.upper_add[host_upper]
            for host_lower in self.lower_add:
                (ip_lower, rand_mac_lower, iter_lower) = self.lower_add[host_lower]
                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_upper),
                                    spa=dnet.ip_aton(ip_upper),
                                    tpa=dnet.ip_aton(ip_lower)
                                    )
                eth = dpkt.ethernet.Ethernet(   dst=dnet.eth_aton(host_lower),
                                                src=dnet.eth_aton(rand_mac_upper),
                                                type=dpkt.ethernet.ETH_TYPE_ARP,
                                                data=str(arp)
                                                )
                data.append(str(eth))
                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(host_upper),
                                    spa=dnet.ip_aton(ip_upper),
                                    tpa=dnet.ip_aton(ip_lower)
                                    )
                eth = dpkt.ethernet.Ethernet(   dst=dnet.eth_aton(host_lower),
                                                src=dnet.eth_aton(host_upper),
                                                type=dpkt.ethernet.ETH_TYPE_ARP,
                                                data=str(arp)
                                                )
                org_data.append(str(eth))

                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_lower),
                                    spa=dnet.ip_aton(ip_lower),
                                    tpa=dnet.ip_aton(ip_upper)
                                    )
                eth = dpkt.ethernet.Ethernet(   dst=dnet.eth_aton(host_upper),
                                                src=dnet.eth_aton(rand_mac_lower),
                                                type=dpkt.ethernet.ETH_TYPE_ARP,
                                                data=str(arp)
                                                )
                data.append(str(eth))
                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(host_lower),
                                    spa=dnet.ip_aton(ip_lower),
                                    tpa=dnet.ip_aton(ip_upper)
                                    )
                eth = dpkt.ethernet.Ethernet(   dst=dnet.eth_aton(host_upper),
                                                src=dnet.eth_aton(host_lower),
                                                type=dpkt.ethernet.ETH_TYPE_ARP,
                                                data=str(arp)
                                                )
                org_data.append(str(eth))
            hosts.append(host_upper)
        for host_lower in self.lower_add:
            hosts.append(host_lower)
        self.upper_add = {}
        self.lower_add = {}
        return (data, org_data, hosts)
Example #32
0
    def run(self):
        self.parent.log("GLBP: Thread started")
        while self.running:
            for i in self.parent.peers:
                (iter, pkg, hello, req_resp, auth, state, arp) = self.parent.peers[i]
                if state:
                    glbp = glbp_packet(pkg.group, self.parent.mac)
                    glbp_hello = glbp_tlv_hello(glbp_tlv_hello.STATE_ACTIVE, 255, hello.hello_int, hello.hold_int,
                                        hello.redirect, hello.timeout, hello.addr_type, hello.addr_len, hello.addr)
                    reqs = ""
                    for req in req_resp:
                        req.prio = 255
                        req.weight = 255
                        reqs += req.render()
                    
                    if not auth is None:
                        if auth.auth_type == glbp_tlv_auth.TYPE_PLAIN:
                            data = glbp.render() + auth.render() + glbp_hello.render() + reqs
                        elif auth.auth_type == glbp_tlv_auth.TYPE_MD5_STRING:
                            nonce = "\x00\x01\x02\x03\x04\x05\x06\x07"
                            data = glbp_tlv_nonce().render(nonce) + glbp_hello.render() + reqs
                            import hashlib
                            m = hashlib.md5()
                            m.update(data)
                            auth.secret = m.digest()
                            data = glbp.render() + auth.render() + data
                    else:
                        data = glbp.render() + glbp_hello.render() + reqs
                    udp_hdr = dpkt.udp.UDP( sport=GLBP_PORT,
                                            dport=GLBP_PORT,
                                            data=data
                                            )
                    udp_hdr.ulen += len(udp_hdr.data)
                    ip_hdr = dpkt.ip.IP(    ttl=255,
                                            p=dpkt.ip.IP_PROTO_UDP,
                                            src=self.parent.ip,
                                            dst=dnet.ip_aton(GLBP_MULTICAST_ADDRESS),
                                            data=str(udp_hdr)
                                            )
                    ip_hdr.len += len(ip_hdr.data)
                    eth_hdr = dpkt.ethernet.Ethernet(   dst=dnet.eth_aton(GLBP_MULTICAST_MAC),
                                                        src=self.parent.mac,
                                                        type=dpkt.ethernet.ETH_TYPE_IP,
                                                        data=str(ip_hdr)
                                                        )
                    self.parent.dnet.send(str(eth_hdr))
                    if arp:
                        if arp < 4:
                            src_mac = self.parent.mac
                            brdc_mac = dnet.eth_aton("ff:ff:ff:ff:ff:ff")
                            stp_uplf_mac = dnet.eth_aton("01:00:0c:cd:cd:cd")
                            ip = hello.addr #struct.pack("!I", hello.addr)
                            arp_hdr = dpkt.arp.ARP( hrd=dpkt.arp.ARP_HRD_ETH,
                                                pro=dpkt.arp.ARP_PRO_IP,
                                                op=dpkt.arp.ARP_OP_REPLY,
                                                sha=src_mac,
                                                spa=ip,
                                                tha=brdc_mac,
                                                tpa=ip
                                                )
                            eth_hdr = dpkt.ethernet.Ethernet(   dst=brdc_mac,
                                                                src=src_mac,
                                                                type=dpkt.ethernet.ETH_TYPE_ARP,
                                                                data=str(arp_hdr)
                                                                )
                            self.parent.dnet.send(str(eth_hdr))

                            arp_hdr = dpkt.arp.ARP( hrd=dpkt.arp.ARP_HRD_ETH,
                                                pro=dpkt.arp.ARP_PRO_IP,
                                                op=dpkt.arp.ARP_OP_REPLY,
                                                sha=src_mac,
                                                spa=ip,
                                                tha=stp_uplf_mac,
                                                tpa=ip
                                                )
                            eth_hdr = dpkt.ethernet.Ethernet(   dst=stp_uplf_mac,
                                                                src=src_mac,
                                                                type=dpkt.ethernet.ETH_TYPE_ARP,
                                                                data=str(arp_hdr)
                                                                )
                            self.parent.dnet.send(str(eth_hdr))
                        self.parent.peers[i] = (iter, pkg, hello, req_resp, auth, state, arp - 1)
            time.sleep(1)
        self.parent.log("GLBP: Thread terminated")
Example #33
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])
Example #34
0
    def add_spoof(self):
        data = []
        org_data = []
        hosts = []
        for host_upper in self.upper_add:
            (ip_upper, rand_mac_upper, iter_upper) = self.upper_add[host_upper]
            for host_lower in self.lower_add:
                (ip_lower, rand_mac_lower,
                 iter_lower) = self.lower_add[host_lower]

                advert = struct.pack("!I16sBB6s", 0x60000000,
                                     dnet.ip6_aton(ip_upper), 2, 1,
                                     dnet.eth_aton(rand_mac_upper))
                icmp6 = dpkt.icmp6.ICMP6(type=dpkt.icmp6.ND_NEIGHBOR_ADVERT,
                                         code=0,
                                         data=advert)
                icmp6_str = str(icmp6)
                ip6 = dpkt.ip6.IP6(src=dnet.ip6_aton(ip_upper),
                                   dst=dnet.ip6_aton(ip_lower),
                                   nxt=dpkt.ip.IP_PROTO_ICMP6,
                                   hlim=255,
                                   data=icmp6,
                                   plen=len(icmp6_str))
                ip6.extension_hdrs = {}
                for i in dpkt.ip6.ext_hdrs:
                    ip6.extension_hdrs[i] = None
                ip6_pseudo = struct.pack('!16s16sIxxxB', ip6.src, ip6.dst,
                                         ip6.plen, ip6.nxt)
                icmp6.sum = ichecksum_func(ip6_pseudo + icmp6_str)
                eth = dpkt.ethernet.Ethernet(dst=dnet.eth_aton(host_lower),
                                             src=dnet.eth_aton(rand_mac_upper),
                                             data=str(ip6),
                                             type=dpkt.ethernet.ETH_TYPE_IP6)
                data.append(str(eth))
                advert = struct.pack("!I16sBB6s", 0x60000000,
                                     dnet.ip6_aton(ip_lower), 2, 1,
                                     dnet.eth_aton(host_upper))
                icmp6 = dpkt.icmp6.ICMP6(type=dpkt.icmp6.ND_NEIGHBOR_ADVERT,
                                         code=0,
                                         data=advert)
                icmp6_str = str(icmp6)
                ip6 = dpkt.ip6.IP6(src=dnet.ip6_aton(ip_upper),
                                   dst=dnet.ip6_aton(ip_lower),
                                   nxt=dpkt.ip.IP_PROTO_ICMP6,
                                   hlim=255,
                                   data=icmp6,
                                   plen=len(icmp6_str))
                ip6.extension_hdrs = {}
                for i in dpkt.ip6.ext_hdrs:
                    ip6.extension_hdrs[i] = None
                ip6_pseudo = struct.pack('!16s16sIxxxB', ip6.src, ip6.dst,
                                         ip6.plen, ip6.nxt)
                icmp6.sum = ichecksum_func(ip6_pseudo + icmp6_str)
                eth = dpkt.ethernet.Ethernet(dst=dnet.eth_aton(host_lower),
                                             src=dnet.eth_aton(host_upper),
                                             data=str(ip6),
                                             type=dpkt.ethernet.ETH_TYPE_IP6)
                org_data.append(str(eth))

                advert = struct.pack("!I16sBB6s", 0x60000000,
                                     dnet.ip6_aton(ip_lower), 2, 1,
                                     dnet.eth_aton(rand_mac_lower))
                icmp6 = dpkt.icmp6.ICMP6(type=dpkt.icmp6.ND_NEIGHBOR_ADVERT,
                                         code=0,
                                         data=advert)
                icmp6_str = str(icmp6)
                ip6 = dpkt.ip6.IP6(src=dnet.ip6_aton(ip_lower),
                                   dst=dnet.ip6_aton(ip_upper),
                                   nxt=dpkt.ip.IP_PROTO_ICMP6,
                                   hlim=255,
                                   data=icmp6,
                                   plen=len(icmp6_str))
                ip6.extension_hdrs = {}
                for i in dpkt.ip6.ext_hdrs:
                    ip6.extension_hdrs[i] = None
                ip6_pseudo = struct.pack('!16s16sIxxxB', ip6.src, ip6.dst,
                                         ip6.plen, ip6.nxt)
                icmp6.sum = ichecksum_func(ip6_pseudo + icmp6_str)
                eth = dpkt.ethernet.Ethernet(dst=dnet.eth_aton(host_upper),
                                             src=dnet.eth_aton(rand_mac_lower),
                                             data=str(ip6),
                                             type=dpkt.ethernet.ETH_TYPE_IP6)
                data.append(str(eth))
                advert = struct.pack("!I16sBB6s", 0x60000000,
                                     dnet.ip6_aton(ip_lower), 2, 1,
                                     dnet.eth_aton(host_lower))
                icmp6 = dpkt.icmp6.ICMP6(type=dpkt.icmp6.ND_NEIGHBOR_ADVERT,
                                         code=0,
                                         data=advert)
                icmp6_str = str(icmp6)
                ip6 = dpkt.ip6.IP6(src=dnet.ip6_aton(ip_lower),
                                   dst=dnet.ip6_aton(ip_upper),
                                   nxt=dpkt.ip.IP_PROTO_ICMP6,
                                   hlim=255,
                                   data=icmp6,
                                   plen=len(icmp6_str))
                ip6.extension_hdrs = {}
                for i in dpkt.ip6.ext_hdrs:
                    ip6.extension_hdrs[i] = None
                ip6_pseudo = struct.pack('!16s16sIxxxB', ip6.src, ip6.dst,
                                         ip6.plen, ip6.nxt)
                icmp6.sum = ichecksum_func(ip6_pseudo + icmp6_str)
                eth = dpkt.ethernet.Ethernet(dst=dnet.eth_aton(host_upper),
                                             src=dnet.eth_aton(host_lower),
                                             data=str(ip6),
                                             type=dpkt.ethernet.ETH_TYPE_IP6)
                org_data.append(str(eth))

            hosts.append(host_upper)

            mld = struct.pack(
                "!xxHBBH16s", 1, 4, 0, 0,
                dnet.ip6_aton("ff02::1:ff00:0000")[:13] +
                dnet.ip6_aton(ip_upper)[13:])
            icmp6 = dpkt.icmp6.ICMP6(type=143, code=0, data=mld)
            icmp6_str = str(icmp6)
            ip6 = dpkt.ip6.IP6(src=dnet.ip6_aton(ip_upper),
                               dst=dnet.ip6_aton("ff02::16"),
                               nxt=dpkt.ip.IP_PROTO_HOPOPTS,
                               hlim=1,
                               data=icmp6,
                               plen=len(icmp6_str) + 8)
            ip6.extension_hdrs = {}
            for i in dpkt.ip6.ext_hdrs:
                ip6.extension_hdrs[i] = None
            ip6.extension_hdrs[
                dpkt.ip.IP_PROTO_HOPOPTS] = dpkt.ip6.IP6HopOptsHeader(
                    nxt=dpkt.ip.IP_PROTO_ICMP6,
                    data=struct.pack("!BBHBB", 5, 2, 0, 1, 0))

            ip6_pseudo = struct.pack('!16s16sIxxxB', ip6.src, ip6.dst,
                                     len(icmp6_str), dpkt.ip.IP_PROTO_ICMP6)
            icmp6.sum = ichecksum_func(ip6_pseudo + icmp6_str)
            eth = dpkt.ethernet.Ethernet(
                dst=dnet.eth_aton("33:33:00:00:00:16"),
                src=self.mac,
                data=str(ip6),
                type=dpkt.ethernet.ETH_TYPE_IP6)
            self.dnet.send(str(eth))
            self.log("ICMP6: Joined multicast group " + dnet.ip6_ntoa(
                dnet.ip6_aton("ff02::1:ff00:0000")[:13] +
                dnet.ip6_aton(ip_upper)[13:]))
        for host_lower in self.lower_add:
            hosts.append(host_lower)
            (ip_lower, rand_mac_lower, iter_lower) = self.lower_add[host_lower]
            mld = struct.pack(
                "!xxHBBH16s", 1, 4, 0, 0,
                dnet.ip6_aton("ff02::1:ff00:0000")[:13] +
                dnet.ip6_aton(ip_lower)[13:])
            icmp6 = dpkt.icmp6.ICMP6(type=143, code=0, data=mld)
            icmp6_str = str(icmp6)
            ip6 = dpkt.ip6.IP6(src=dnet.ip6_aton(ip_lower),
                               dst=dnet.ip6_aton("ff02::16"),
                               nxt=dpkt.ip.IP_PROTO_HOPOPTS,
                               hlim=1,
                               data=icmp6,
                               plen=len(icmp6_str) + 8)
            ip6.extension_hdrs = {}
            for i in dpkt.ip6.ext_hdrs:
                ip6.extension_hdrs[i] = None
            ip6.extension_hdrs[
                dpkt.ip.IP_PROTO_HOPOPTS] = dpkt.ip6.IP6HopOptsHeader(
                    nxt=dpkt.ip.IP_PROTO_ICMP6,
                    data=struct.pack("!BBHBB", 5, 2, 0, 1, 0))

            ip6_pseudo = struct.pack('!16s16sIxxxB', ip6.src, ip6.dst,
                                     len(icmp6_str), dpkt.ip.IP_PROTO_ICMP6)
            icmp6.sum = ichecksum_func(ip6_pseudo + icmp6_str)
            eth = dpkt.ethernet.Ethernet(
                dst=dnet.eth_aton("33:33:00:00:00:16"),
                src=self.mac,
                data=str(ip6),
                type=dpkt.ethernet.ETH_TYPE_IP6)
            self.dnet.send(str(eth))
            self.log("ICMP6: Joined multicast group " + dnet.ip6_ntoa(
                dnet.ip6_aton("ff02::1:ff00:0000")[:13] +
                dnet.ip6_aton(ip_lower)[13:]))
        self.upper_add = {}
        self.lower_add = {}
        return (data, org_data, hosts)
Example #35
0
    def run(self):
        self.parent.log("HSRP2: Thread started")
        while self.running:
            for i in self.parent.peers:
                (iter, pkg, state, arp) = self.parent.peers[i]
                if state:
                    hsrp2_group_state = hsrp2_group_state_tlv(
                        hsrp2_group_state_tlv.OP_CODE_HELLO,
                        hsrp2_group_state_tlv.STATE_ACTIVE,
                        pkg["hsrp2_group_state_tlv"].ip_ver,
                        pkg["hsrp2_group_state_tlv"].group, self.parent.mac,
                        255, pkg["hsrp2_group_state_tlv"].hello_time,
                        pkg["hsrp2_group_state_tlv"].hold_time,
                        pkg["hsrp2_group_state_tlv"].ip)
                    data = hsrp2_group_state.render()
                    if "hsrp2_text_auth_tlv" in pkg:
                        hsrp2_text_auth = hsrp2_text_auth_tlv(
                            pkg["hsrp2_text_auth_tlv"].auth_data)
                        data += hsrp2_text_auth.render()
                    elif "hsrp2_md5_auth_tlv" in pkg:
                        if pkg["hsrp2_group_state_tlv"].ip_ver == 4:
                            ip = self.parent.ip
                        else:
                            ip = self.parent.ip6_ll[0] + self.parent.ip6_ll[-3:]
                        auth = hsrp2_md5_auth_tlv(
                            pkg["hsrp2_md5_auth_tlv"].algo,
                            pkg["hsrp2_md5_auth_tlv"].flags, ip,
                            pkg["hsrp2_md5_auth_tlv"].keyid, "\x00" * 16)
                        if self.parent.ui == 'gtk':
                            secret = self.parent.auth_entry.get_text()
                        elif self.parent.ui == 'urw':
                            secret = self.parent.auth_edit.get_edit_text()
                        key_length = struct.pack("<Q", (len(secret) << 3))
                        key_fill = secret + '\x80' + '\x00' * (
                            55 - len(secret)) + key_length
                        salt = data + auth.render()
                        m = hashlib.md5()
                        m.update(key_fill)
                        m.update(salt)
                        m.update(secret)
                        auth.csum = m.digest()
                        data += auth.render()
                        pass

                    if pkg["hsrp2_group_state_tlv"].ip_ver == 4:
                        udp_hdr = dpkt.udp.UDP(sport=HSRP2_PORT,
                                               dport=HSRP2_PORT,
                                               data=data)
                        udp_hdr.ulen += len(udp_hdr.data)
                        ip_hdr = dpkt.ip.IP(
                            ttl=1,
                            p=dpkt.ip.IP_PROTO_UDP,
                            src=self.parent.ip,
                            dst=dnet.ip_aton(HSRP2_MULTICAST_ADDRESS),
                            data=str(udp_hdr))
                        ip_hdr.len += len(ip_hdr.data)
                        ipt = dpkt.ethernet.ETH_TYPE_IP
                    else:
                        udp_hdr = dpkt.udp.UDP(sport=HSRP2_PORT6,
                                               dport=HSRP2_PORT6,
                                               data=data)
                        udp_hdr.ulen += len(udp_hdr.data)
                        ip_hdr = dpkt.ip6.IP6(
                            hlim=255,
                            nxt=dpkt.ip.IP_PROTO_UDP,
                            src=self.parent.ip6_ll,
                            dst=dnet.ip6_aton(HSRP2_MULTICAST6_ADDRESS),
                            data=udp_hdr,
                            plen=len(str(udp_hdr)))
                        ip_hdr.extension_hdrs = {
                            0: None,
                            43: None,
                            44: None,
                            51: None,
                            50: None,
                            60: None
                        }
                        ipt = dpkt.ethernet.ETH_TYPE_IP6
                    eth_hdr = dpkt.ethernet.Ethernet(
                        dst=dnet.eth_aton(HSRP2_MULTICAST_MAC),
                        src=self.parent.mac,
                        type=ipt,
                        data=str(ip_hdr))
                    self.parent.dnet.send(str(eth_hdr))
                    if arp:
                        src_mac = dnet.eth_aton(
                            "00:00:0c:9f:f0:%02x" %
                            (pkg["hsrp2_group_state_tlv"].group))
                        brdc_mac = dnet.eth_aton("ff:ff:ff:ff:ff:ff")
                        stp_uplf_mac = dnet.eth_aton("01:00:0c:cd:cd:cd")
                        ip = pkg["hsrp2_group_state_tlv"].ip
                        arp_hdr = dpkt.arp.ARP(hrd=dpkt.arp.ARP_HRD_ETH,
                                               pro=dpkt.arp.ARP_PRO_IP,
                                               op=dpkt.arp.ARP_OP_REPLY,
                                               sha=src_mac,
                                               spa=ip,
                                               tha=brdc_mac,
                                               tpa=ip)
                        eth_hdr = dpkt.ethernet.Ethernet(
                            dst=brdc_mac,
                            src=src_mac,
                            type=dpkt.ethernet.ETH_TYPE_ARP,
                            data=str(arp_hdr))
                        self.parent.dnet.send(str(eth_hdr))

                        arp_hdr = dpkt.arp.ARP(hrd=dpkt.arp.ARP_HRD_ETH,
                                               pro=dpkt.arp.ARP_PRO_IP,
                                               op=dpkt.arp.ARP_OP_REPLY,
                                               sha=src_mac,
                                               spa=ip,
                                               tha=stp_uplf_mac,
                                               tpa=ip)
                        eth_hdr = dpkt.ethernet.Ethernet(
                            dst=stp_uplf_mac,
                            src=src_mac,
                            type=dpkt.ethernet.ETH_TYPE_ARP,
                            data=str(arp_hdr))
                        self.parent.dnet.send(str(eth_hdr))
                        self.parent.peers[i] = (iter, pkg, state, arp - 1)
            time.sleep(1)
        self.parent.log("HSRP2: Thread terminated")
Example #36
0
    def run(self):
        self.parent.log("GLBP: Thread started")
        while self.running:
            for i in self.parent.peers:
                (iter, pkg, hello, req_resp, auth, state,
                 arp) = self.parent.peers[i]
                if state:
                    glbp = glbp_packet(pkg.group, self.parent.mac)
                    glbp_hello = glbp_tlv_hello(glbp_tlv_hello.STATE_ACTIVE,
                                                255, hello.hello_int,
                                                hello.hold_int, hello.redirect,
                                                hello.timeout, hello.addr_type,
                                                hello.addr_len, hello.addr)
                    reqs = ""
                    for req in req_resp:
                        req.prio = 255
                        req.weight = 255
                        reqs += req.render()

                    if not auth is None:
                        if auth.auth_type == glbp_tlv_auth.TYPE_PLAIN:
                            data = glbp.render() + auth.render(
                            ) + glbp_hello.render() + reqs
                        elif auth.auth_type == glbp_tlv_auth.TYPE_MD5_STRING:
                            nonce = "\x00\x01\x02\x03\x04\x05\x06\x07"
                            data = glbp_tlv_nonce().render(
                                nonce) + glbp_hello.render() + reqs
                            import hashlib
                            m = hashlib.md5()
                            m.update(data)
                            auth.secret = m.digest()
                            data = glbp.render() + auth.render() + data
                    else:
                        data = glbp.render() + glbp_hello.render() + reqs
                    udp_hdr = dpkt.udp.UDP(sport=GLBP_PORT,
                                           dport=GLBP_PORT,
                                           data=data)
                    udp_hdr.ulen += len(udp_hdr.data)
                    ip_hdr = dpkt.ip.IP(
                        ttl=255,
                        p=dpkt.ip.IP_PROTO_UDP,
                        src=self.parent.ip,
                        dst=dnet.ip_aton(GLBP_MULTICAST_ADDRESS),
                        data=str(udp_hdr))
                    ip_hdr.len += len(ip_hdr.data)
                    eth_hdr = dpkt.ethernet.Ethernet(
                        dst=dnet.eth_aton(GLBP_MULTICAST_MAC),
                        src=self.parent.mac,
                        type=dpkt.ethernet.ETH_TYPE_IP,
                        data=str(ip_hdr))
                    self.parent.dnet.send(str(eth_hdr))
                    if arp:
                        if arp < 4:
                            src_mac = self.parent.mac
                            brdc_mac = dnet.eth_aton("ff:ff:ff:ff:ff:ff")
                            stp_uplf_mac = dnet.eth_aton("01:00:0c:cd:cd:cd")
                            ip = hello.addr  #struct.pack("!I", hello.addr)
                            arp_hdr = dpkt.arp.ARP(hrd=dpkt.arp.ARP_HRD_ETH,
                                                   pro=dpkt.arp.ARP_PRO_IP,
                                                   op=dpkt.arp.ARP_OP_REPLY,
                                                   sha=src_mac,
                                                   spa=ip,
                                                   tha=brdc_mac,
                                                   tpa=ip)
                            eth_hdr = dpkt.ethernet.Ethernet(
                                dst=brdc_mac,
                                src=src_mac,
                                type=dpkt.ethernet.ETH_TYPE_ARP,
                                data=str(arp_hdr))
                            self.parent.dnet.send(str(eth_hdr))

                            arp_hdr = dpkt.arp.ARP(hrd=dpkt.arp.ARP_HRD_ETH,
                                                   pro=dpkt.arp.ARP_PRO_IP,
                                                   op=dpkt.arp.ARP_OP_REPLY,
                                                   sha=src_mac,
                                                   spa=ip,
                                                   tha=stp_uplf_mac,
                                                   tpa=ip)
                            eth_hdr = dpkt.ethernet.Ethernet(
                                dst=stp_uplf_mac,
                                src=src_mac,
                                type=dpkt.ethernet.ETH_TYPE_ARP,
                                data=str(arp_hdr))
                            self.parent.dnet.send(str(eth_hdr))
                        self.parent.peers[i] = (iter, pkg, hello, req_resp,
                                                auth, state, arp - 1)
            time.sleep(1)
        self.parent.log("GLBP: Thread terminated")
Example #37
0
    def run(self):
        self.parent.log("HSRP2: Thread started")
        while self.running:
            for i in self.parent.peers:
                (iter, pkg, state, arp) = self.parent.peers[i]
                if state:
                    hsrp2_group_state = hsrp2_group_state_tlv(  hsrp2_group_state_tlv.OP_CODE_HELLO,
                                                                hsrp2_group_state_tlv.STATE_ACTIVE,
                                                                pkg["hsrp2_group_state_tlv"].ip_ver,
                                                                pkg["hsrp2_group_state_tlv"].group,
                                                                self.parent.mac,
                                                                255,
                                                                pkg["hsrp2_group_state_tlv"].hello_time,
                                                                pkg["hsrp2_group_state_tlv"].hold_time,
                                                                pkg["hsrp2_group_state_tlv"].ip
                                                                )
                    data = hsrp2_group_state.render()
                    if "hsrp2_text_auth_tlv" in pkg:
                        hsrp2_text_auth = hsrp2_text_auth_tlv(pkg["hsrp2_text_auth_tlv"].auth_data)
                        data += hsrp2_text_auth.render()
                    elif "hsrp2_md5_auth_tlv" in pkg:
                        if pkg["hsrp2_group_state_tlv"].ip_ver == 4:
                            ip = self.parent.ip
                        else:
                            ip = self.parent.ip6_ll[0] + self.parent.ip6_ll[-3:]
                        auth = hsrp2_md5_auth_tlv(pkg["hsrp2_md5_auth_tlv"].algo, pkg["hsrp2_md5_auth_tlv"].flags, ip, pkg["hsrp2_md5_auth_tlv"].keyid, "\x00" * 16)
                        if self.parent.ui == 'gtk':
                            secret = self.parent.auth_entry.get_text()
                        elif self.parent.ui == 'urw':
                            secret = self.parent.auth_edit.get_edit_text()
                        key_length = struct.pack("<Q", (len(secret) << 3))
                        key_fill = secret + '\x80' + '\x00' * (55 - len(secret)) + key_length
                        salt = data + auth.render()
                        m = hashlib.md5()
                        m.update(key_fill)
                        m.update(salt)
                        m.update(secret)
                        auth.csum = m.digest()
                        data += auth.render()
                        pass
                    
                    if pkg["hsrp2_group_state_tlv"].ip_ver == 4:
                        udp_hdr = dpkt.udp.UDP( sport=HSRP2_PORT,
                                                dport=HSRP2_PORT,
                                                data=data
                                                )
                        udp_hdr.ulen += len(udp_hdr.data)
                        ip_hdr = dpkt.ip.IP(    ttl=1,
                                                p=dpkt.ip.IP_PROTO_UDP,
                                                src=self.parent.ip,
                                                dst=dnet.ip_aton(HSRP2_MULTICAST_ADDRESS),
                                                data=str(udp_hdr)
                                                )
                        ip_hdr.len += len(ip_hdr.data)
                        ipt = dpkt.ethernet.ETH_TYPE_IP
                    else:
                        udp_hdr = dpkt.udp.UDP( sport=HSRP2_PORT6,
                                                dport=HSRP2_PORT6,
                                                data=data
                                                )
                        udp_hdr.ulen += len(udp_hdr.data)
                        ip_hdr = dpkt.ip6.IP6(  hlim=255,
                                                nxt=dpkt.ip.IP_PROTO_UDP,
                                                src=self.parent.ip6_ll,
                                                dst=dnet.ip6_aton(HSRP2_MULTICAST6_ADDRESS),
                                                data=udp_hdr,
                                                plen = len(str(udp_hdr))
                                                )
                        ip_hdr.extension_hdrs = {   0  : None,
                                                    43 : None,
                                                    44 : None,
                                                    51 : None,
                                                    50 : None,
                                                    60 : None
                                                    }
                        ipt = dpkt.ethernet.ETH_TYPE_IP6
                    eth_hdr = dpkt.ethernet.Ethernet(   dst=dnet.eth_aton(HSRP2_MULTICAST_MAC),
                                                        src=self.parent.mac,
                                                        type=ipt,
                                                        data=str(ip_hdr)
                                                        )
                    self.parent.dnet.send(str(eth_hdr))
                    if arp:
                        src_mac = dnet.eth_aton("00:00:0c:9f:f0:%02x" % (pkg["hsrp2_group_state_tlv"].group))
                        brdc_mac = dnet.eth_aton("ff:ff:ff:ff:ff:ff")
                        stp_uplf_mac = dnet.eth_aton("01:00:0c:cd:cd:cd")
                        ip = pkg["hsrp2_group_state_tlv"].ip
                        arp_hdr = dpkt.arp.ARP( hrd=dpkt.arp.ARP_HRD_ETH,
                                            pro=dpkt.arp.ARP_PRO_IP,
                                            op=dpkt.arp.ARP_OP_REPLY,
                                            sha=src_mac,
                                            spa=ip,
                                            tha=brdc_mac,
                                            tpa=ip
                                            )
                        eth_hdr = dpkt.ethernet.Ethernet(   dst=brdc_mac,
                                                            src=src_mac,
                                                            type=dpkt.ethernet.ETH_TYPE_ARP,
                                                            data=str(arp_hdr)
                                                            )
                        self.parent.dnet.send(str(eth_hdr))

                        arp_hdr = dpkt.arp.ARP( hrd=dpkt.arp.ARP_HRD_ETH,
                                            pro=dpkt.arp.ARP_PRO_IP,
                                            op=dpkt.arp.ARP_OP_REPLY,
                                            sha=src_mac,
                                            spa=ip,
                                            tha=stp_uplf_mac,
                                            tpa=ip
                                            )
                        eth_hdr = dpkt.ethernet.Ethernet(   dst=stp_uplf_mac,
                                                            src=src_mac,
                                                            type=dpkt.ethernet.ETH_TYPE_ARP,
                                                            data=str(arp_hdr)
                                                            )
                        self.parent.dnet.send(str(eth_hdr))
                        self.parent.peers[i] = (iter, pkg, state, arp - 1)
            time.sleep(1)
        self.parent.log("HSRP2: Thread terminated")
Example #38
0
    def run(self):
        self.parent.log("HSRP: Thread started")
        while self.running:
            for i in self.parent.peers:
                if self.parent.peers[i]["state"]:
                    pkg = self.parent.peers[i]["pkg"]
                    auth = self.parent.peers[i]["auth"]
                    if not auth is None:
                        hsrp = hsrp_packet(hsrp_packet.OP_HELLO,
                                           hsrp_packet.STATE_ACTIVE, pkg.hello,
                                           pkg.hold, 255, pkg.group,
                                           "\x00" * 8, pkg.ip)
                        auth = hsrp_auth_tlv(auth.algo, auth.flags,
                                             self.parent.ip, auth.keyid,
                                             "\x00" * 16)
                        if self.parent.ui == 'gtk':
                            secret = self.parent.auth_entry.get_text()
                        elif self.parent.ui == 'urw':
                            secret = self.parent.auth_edit.get_edit_text()
                        key_length = struct.pack("<Q", (len(secret) << 3))
                        key_fill = secret + '\x80' + '\x00' * (
                            55 - len(secret)) + key_length
                        salt = hsrp.render() + auth.render()
                        m = hashlib.md5()
                        m.update(key_fill)
                        m.update(salt)
                        m.update(secret)
                        auth.csum = m.digest()
                        data = hsrp.render() + auth.render()
                    else:
                        hsrp = hsrp_packet(hsrp_packet.OP_HELLO,
                                           hsrp_packet.STATE_ACTIVE, pkg.hello,
                                           pkg.hold, 255, pkg.group,
                                           pkg.auth_data, pkg.ip)
                        data = hsrp.render()
                    udp_hdr = dpkt.udp.UDP(sport=HSRP_PORT,
                                           dport=HSRP_PORT,
                                           data=data)
                    udp_hdr.ulen += len(udp_hdr.data)
                    ip_hdr = dpkt.ip.IP(
                        ttl=1,
                        p=dpkt.ip.IP_PROTO_UDP,
                        src=self.parent.ip,
                        dst=dnet.ip_aton(HSRP_MULTICAST_ADDRESS),
                        data=str(udp_hdr))
                    ip_hdr.len += len(ip_hdr.data)
                    eth_hdr = dpkt.ethernet.Ethernet(
                        dst=dnet.eth_aton(HSRP_MULTICAST_MAC),
                        src=self.parent.mac,
                        type=dpkt.ethernet.ETH_TYPE_IP,
                        data=str(ip_hdr))
                    self.parent.dnet.send(str(eth_hdr))
                    if self.parent.peers[i]["arp"]:
                        src_mac = dnet.eth_aton("00:00:0c:07:ac:%02x" %
                                                (pkg.group))
                        brdc_mac = dnet.eth_aton("ff:ff:ff:ff:ff:ff")
                        stp_uplf_mac = dnet.eth_aton("01:00:0c:cd:cd:cd")
                        ip = struct.pack("!I", pkg.ip)
                        arp_hdr = dpkt.arp.ARP(hrd=dpkt.arp.ARP_HRD_ETH,
                                               pro=dpkt.arp.ARP_PRO_IP,
                                               op=dpkt.arp.ARP_OP_REPLY,
                                               sha=src_mac,
                                               spa=ip,
                                               tha=brdc_mac,
                                               tpa=ip)
                        eth_hdr = dpkt.ethernet.Ethernet(
                            dst=brdc_mac,
                            src=src_mac,
                            type=dpkt.ethernet.ETH_TYPE_ARP,
                            data=str(arp_hdr))
                        self.parent.dnet.send(str(eth_hdr))

                        arp_hdr = dpkt.arp.ARP(hrd=dpkt.arp.ARP_HRD_ETH,
                                               pro=dpkt.arp.ARP_PRO_IP,
                                               op=dpkt.arp.ARP_OP_REPLY,
                                               sha=src_mac,
                                               spa=ip,
                                               tha=stp_uplf_mac,
                                               tpa=ip)
                        eth_hdr = dpkt.ethernet.Ethernet(
                            dst=stp_uplf_mac,
                            src=src_mac,
                            type=dpkt.ethernet.ETH_TYPE_ARP,
                            data=str(arp_hdr))
                        self.parent.dnet.send(str(eth_hdr))
                        self.parent.peers[i][
                            "arp"] = self.parent.peers[i]["arp"] - 1
            time.sleep(1)
        self.parent.log("HSRP: Thread terminated")