Exemple #1
0
 def set_int(self, interface):
     self.interface = interface
     self.eigrp_filter = {
         "device": self.interface,
         "op": dumbnet.FW_OP_BLOCK,
         "dir": dumbnet.FW_DIR_IN,
         "proto": dpkt.ip.IP_PROTO_EIGRP,
         "src": dumbnet.addr("0.0.0.0/0", dumbnet.ADDR_TYPE_IP),
         "dst": dumbnet.addr("0.0.0.0/0", dumbnet.ADDR_TYPE_IP),
         "sport": [0, 0],
         "dport": [0, 0]
     }
Exemple #2
0
    def set(self, d, name=None):
        """
        Set the configuration for an interface from a dict like interfaces(5).
        """
        if name is not None:
            d['name'] = name

        iface = self.get(d['name'])

        address = d.get('address', iface['address'])
        netmask = d.get('netmask', iface['netmask'])

        d['addr'] = dumbnet.addr("%s/%s" % (address, netmask))

        newgateway = None
        delgateway = None

        if d.has_key('gateway'):
            if iface['type'] != 'eth' or iface['family'] != 'inet':
                raise NotImplementedError("This method only supports modify IPv4 gateway for ethernet interface")

            gwstr = network.format_ipv4(network.parse_ipv4("%s" % d['gateway']))

            if iface.get('gateway', None) != gwstr:
                newgateway = dumbnet.addr("%s" % d['gateway'])
        # If d hasn't gateway but iface has a gateway, remove previous gateway.
        elif iface.has_key('gateway'):
            if iface['type'] != 'eth' or iface['family'] != 'inet':
                raise NotImplementedError("This method only supports modify IPv4 gateway for ethernet interface")

            delgateway = d['addr']

        if d.has_key('pointopoint'):
            d['dst_addr'] = dumbnet.addr("%s" % d['pointopoint'])

        if d.has_key('hwaddress'):
            d['link_addr'] = dumbnet.addr("%s" % d['hwaddress'], dumbnet.ADDR_TYPE_ETH)

        dumbnet.intf.set(self, d)

        # If iface has previously a default gateway
        if delgateway:
            try:
                self.route.delete(self.default_dst_ipv4)
            except OSError, e:
                # If an error has occurred, rollback
                if iface.has_key('gateway'):
                    del iface['gateway']

                self.set(iface)
                raise OSError(str(e))
Exemple #3
0
    def set(self, d, name=None):
        """
        Set the configuration for an interface from a dict like interfaces(5).
        """
        if name is not None:
            d["name"] = name

        iface = self.get(d["name"])

        address = d.get("address", iface["address"])
        netmask = d.get("netmask", iface["netmask"])

        d["addr"] = dumbnet.addr("%s/%s" % (address, netmask))

        newgateway = None
        delgateway = None

        if d.has_key("gateway"):
            if iface["type"] != "eth" or iface["family"] != "inet":
                raise NotImplementedError("This method only supports modify IPv4 gateway for ethernet interface")

            gwstr = network.format_ipv4(network.parse_ipv4("%s" % d["gateway"]))

            if iface.get("gateway", None) != gwstr:
                newgateway = dumbnet.addr("%s" % d["gateway"])
        # If d hasn't gateway but iface has a gateway, remove previous gateway.
        elif iface.has_key("gateway"):
            if iface["type"] != "eth" or iface["family"] != "inet":
                raise NotImplementedError("This method only supports modify IPv4 gateway for ethernet interface")

            delgateway = d["addr"]

        if d.has_key("pointopoint"):
            d["dst_addr"] = dumbnet.addr("%s" % d["pointopoint"])

        if d.has_key("hwaddress"):
            d["link_addr"] = dumbnet.addr("%s" % d["hwaddress"], dumbnet.ADDR_TYPE_ETH)

        dumbnet.intf.set(self, d)

        # If iface has previously a default gateway
        if delgateway:
            try:
                self.route.delete(self.default_dst_ipv4)
            except OSError, e:
                # If an error has occurred, rollback
                if iface.has_key("gateway"):
                    del iface["gateway"]

                self.set(iface)
                raise OSError(str(e))
Exemple #4
0
 def _send(self, data, ipaddr=None, mac=None, to_server=False):
     '''Write Next Packet'''
     if ipaddr is None:
         ipaddr = self.ipaddr
     if mac is None:
         mac = self.mac
     udp = None
     if to_server:
         udp = dpkt.udp.UDP(
             sport=DHCPCLIENT,
             dport=DHCPSERVER,
             data=data,
             sum=0,
             ulen=len(data) + 8,
         )
     else:
         udp = dpkt.udp.UDP(
             sport=DHCPSERVER,
             dport=DHCPCLIENT,
             data=data,
             sum=0,
             ulen=len(data) + 8,
         )
     udp.pack()
     # pylint: disable=no-member
     ip_p = dpkt.ip.IP(
         src=dumbnet.addr(ipaddr).ip,
         dst=dumbnet.addr("255.255.255.255").ip,
         tos=16,
         ttl=128,
         p=17,
         len=len(data) + 28,
         data=udp,
     )
     # pylint: disable=no-member
     eth = dpkt.ethernet.Ethernet(data=_cksum_packet(ip_p),
                                  src=mac,
                                  dst=ETH_BROADCAST)
     if to_server:
         logging.debug("Raw socket to server on %s using %s/%s", self.iface,
                       format_ip(ipaddr), format_mac(mac))
         self.trust_sock.send(str(eth))
     else:
         logging.debug("Raw socket to client on %s using %s/%s", self.iface,
                       format_ip(ipaddr), format_mac(mac))
         self.rawio.write(str(eth))
         self.rawio.flush(
         )  # needed, otherwise python buffering messes it up
Exemple #5
0
def jail_ap(lock,value):
  global jail_ap_count

  print("%s: starting jailer" % datetime.datetime.now())
  print lock, value

  while 1: 
    with lock:
      value.value += 1

    time.sleep(1)
    arpTable = arp()
    
    try: 
      ssh = paramiko.SSHClient()
      ssh.set_missing_host_key_policy(paramiko.WarningPolicy())
      ssh.connect("192.168.1.20", 22, 'ubnt', 'ubnt', timeout=5, allow_agent=False, look_for_keys=False)
      print "Connected to 192.168.1.20"

      mac = str(arpTable.get(addr('192.168.1.20')))
      print "MAC IS", mac

      if mac == "None":
        print "XXX: Error getting MAC Address"
        continue

      print "Applying jail IP to '%s'" % mac
      p_id = None

      # the actual jailing of the default config.
      # the IP of the autoconfig server, or whatever is providing captive dns
      # should be used for the nameserver
      ip_dot = app.get_ip(mac)
      ssh.exec_command("ip addr add %s/24 dev br0" % ip_dot, timeout=5)
      print(" ip %s added" % ip_dot)
      ssh.exec_command("sysctl -w net.ipv4.conf.br0.promote_secondaries=1", timeout=5)
      print(" sysctl changed")
      ssh.exec_command("echo 'nameserver 192.168.1.10' > /etc/resolv.conf", timeout=5)
      print(" nameserver added")
      ssh.exec_command("ip addr delete 192.168.1.20/24 dev br0", timeout=5)
      print(" primary ip deleted")
      ssh.close()

      print "%s: Connected to AP and applied IP %s" % (datetime.datetime.now(), ip_dot)
    except Exception, e:
      print e
      if "Authentication failed." in str(e):
        arpTable.delete('192.168.1.20')
        print "%s: Error trying to jail AP" % datetime.datetime.now() , e
      pass 
Exemple #6
0
    def _netiface_from_address(self, function):
        """
        Find best interface from destination or source address.
        """
        if 'address' in self.options:
            addresses = helpers.extract_scalar(self.options['address'])
        else:
            addresses = None

        if not addresses:
            raise HttpReqError(415, "invalid option 'address'")
        else:
            try:
                addresses = [dumbnet.addr(x) for x in addresses]
            except ValueError, e:
                raise HttpReqError(415, "%s: %s" % (e, x))
Exemple #7
0
	def arping(self):
		""" find the ether address. """

		if self.ether is not None:
			return

		if Machine.arp_table is None:
			Machine.arp_table = dumbnet.arp()

		caller = current_thread().name

		#assert ltrace(TRACE_MACHINES, '> %s: arping(%s)' % (caller, self.mid))

		with self.lock:
			try:
				# str() is needed to convert from dumbnet.addr() type.
				self.ether = str(Machine.arp_table.get(dumbnet.addr(self.mid)))

			except Exception, e:
				assert ltrace(TRACE_MACHINES, '  %s: cannot arping %s (was: %s).'
													% (caller, self.mid, e))
Exemple #8
0
 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 = dumbnet.arp()
             mac = arp.get(dumbnet.addr(peer))
             if not mac:
                 raise Exception("Unable to get mac address")
             self.add_peer(mac.data, dumbnet.ip_aton(peer),
                           int(self.as_spinbutton.get_value()))
         except Exception, e:
             self.log("EIGRP: Cant add peer %s: %s" % (peer, e))
Exemple #9
0
 def __init__(self):
     dumbnet.intf.__init__(self)
     self.route = dumbnet.route()
     self.default_dst_ipv4 = dumbnet.addr('0.0.0.0/0')
Exemple #10
0
def get_mac():
  app.logger.debug('get_mac')
  arpTable = arp()
  session['ip'] = request.environ['REMOTE_ADDR']
  session['mac'] = str(arpTable.get(pa=addr(session['ip'])))
  return(session)
Exemple #11
0
 def getMacFromARP(self, protocolAddress):
     arp = dumbnet.arp()
     return arp.get(dumbnet.addr(protocolAddress))