예제 #1
0
def fixRouting():
  for r in conf.route.routes:
    if (r[3]!='lo'):
      conf.route.delt(net=ltoa(r[0])+'/8',dev=r[3])
      conf.route.add(net='0.0.0.0/0',dev=r[3]);
      break;
  conf.route
예제 #2
0
파일: net.py 프로젝트: Shadiesna/ooni-probe
def getNetworksFromRoutes():
    from scapy.all import conf, ltoa, read_routes
    from ipaddr    import IPNetwork, IPAddress

    ## Hide the 'no routes' warnings
    conf.verb = 0

    networks = []
    for nw, nm, gw, iface, addr in read_routes():
        n = IPNetwork( ltoa(nw) )
        (n.netmask, n.gateway, n.ipaddr) = [IPAddress(x) for x in [nm, gw, addr]]
        n.iface = iface
        if not n.compressed in networks:
            networks.append(n)

    return networks
예제 #3
0
  def __init__( self, interface, gateway = None, network = None, kill = False, ip = None ):
    # scapy, you're pretty cool ... but shut the f**k up bitch!
    conf.verb = 0

    self.interface    = interface
    self.network      = network
    self.targets      = [] 
    self.gateway      = gateway
    self.all          = all
    self.gateway_hw   = None
    self.packets      = []
    self.restore      = []
    self.endpoints    = []
    self.mac_prefixes = {}

    if not os.geteuid() == 0:
      raise Exception( "Only root can run this script." )

    print "@ Searching for the network gateway address ..."

    # for route in conf.route.routes:
    for net, msk, gw, iface, addr in conf.route.routes:
      # found a route for given interface
      if iface == self.interface:
        network = ltoa( net )
        # compute network representation if not yet done
        if network.split('.')[0] == addr.split('.')[0]:
          bits = self.__bit_count( msk )
          self.network = "%s/%d" % ( network, bits )
        # search for a valid network gateway
        if self.gateway is None and gw != '0.0.0.0':
          self.gateway = gw
    
    if self.gateway is not None and self.network is not None:
      print "@ Gateway is %s on network %s ." % ( self.gateway, self.network )
    else:
      raise Exception( "Could not find any network gateway." )

    # Populate the self.endpoints array
    self.find_alive_hosts()

    # Find the ip in the endpoints
    for i, item in enumerate( self.endpoints ):
      ( mac, ip ) = item
      if ip == self.ip:
        self.targets.append( self.endpoints[ i ] )
        self.targets=self.endpoints[ip]
예제 #4
0
파일: net.py 프로젝트: Shadiesna/ooni-probe
def getNetworksFromRoutes():
    from scapy.all import conf, ltoa, read_routes
    from ipaddr import IPNetwork, IPAddress

    ## Hide the 'no routes' warnings
    conf.verb = 0

    networks = []
    for nw, nm, gw, iface, addr in read_routes():
        n = IPNetwork(ltoa(nw))
        (n.netmask, n.gateway,
         n.ipaddr) = [IPAddress(x) for x in [nm, gw, addr]]
        n.iface = iface
        if not n.compressed in networks:
            networks.append(n)

    return networks
예제 #5
0
    def __init__(self,
                 interface,
                 gateway=None,
                 network=None,
                 kill=False,
                 all=False):
        # scapy, you're pretty cool ... but shut the f**k up bitch!
        conf.verb = 0

        self.interface = interface
        self.network = network
        self.targets = []
        self.gateway = gateway
        self.all = all
        self.gateway_hw = None
        self.packets = []
        self.restore = []
        self.endpoints = []
        self.mac_prefixes = {}

        if not os.geteuid() == 0:
            raise Exception("Only root can run this script.")

        self.__preload_mac_table()

        print "@ Searching for the network gateway address ..."

        # for route in conf.route.routes:
        for net, msk, gw, iface, addr in conf.route.routes:
            # found a route for given interface
            if iface == self.interface:
                network = ltoa(net)
                # compute network representation if not yet done
                if network.split('.')[0] == addr.split('.')[0]:
                    bits = self.__bit_count(msk)
                    self.network = "%s/%d" % (network, bits)
                # search for a valid network gateway
                if self.gateway is None and gw != '0.0.0.0':
                    self.gateway = gw

        if self.gateway is not None and self.network is not None:
            print "@ Gateway is %s on network %s ." % (self.gateway,
                                                       self.network)
        else:
            raise Exception("Could not find any network gateway.")

        self.find_alive_hosts()

        print "@ Please choose your target :"
        choice = None

        if all:
            self.targets = self.endpoints
        else:
            while choice is None:
                for i, item in enumerate(self.endpoints):
                    (mac, ip) = item
                    vendor = self.__find_mac_vendor(mac)
                    print "  [%d] %s %s %s" % (i, mac, ip, "( %s )" %
                                               vendor if vendor else '')
                choice = raw_input(
                    "@ Choose [0-%d] (* to select all, r to refresh): " %
                    (len(self.endpoints) - 1))
                try:
                    choice = choice.strip()
                    if choice == '*':
                        self.targets = self.endpoints
                    elif choice.lower() == 'r':
                        choice = None
                        self.find_alive_hosts()
                    else:
                        self.targets.append(self.endpoints[int(choice)])
                except Exception as e:
                    print "@ Invalid choice!"
                    choice = None

        self.craft_packets()

        if not kill:
            print "@ Enabling ipv4 forwarding system wide ..."
            self.__set_forwarding(True)
        else:
            print "@ Disabling ipv4 forwarding system wide to kill target connections ..."
            self.__set_forwarding(False)

        atexit.register(self.restore_cache)
예제 #6
0
  def __init__( self, interface, gateway = None, network = None, kill = False, all = False ):
    # scapy, you're pretty cool ... but shut the f**k up bitch!
    conf.verb = 0

    self.interface    = interface
    self.network      = network
    self.targets      = []
    self.gateway      = gateway
    self.all          = all
    self.gateway_hw   = None
    self.packets      = []
    self.restore      = []
    self.endpoints    = []
    self.mac_prefixes = {}

    if not os.geteuid() == 0:
      raise Exception( "Only root can run this script." )

    self.__preload_mac_table()

    print "@ Searching for the network gateway address ..."

    # for route in conf.route.routes:
    for net, msk, gw, iface, addr in conf.route.routes:
      # found a route for given interface
      if iface == self.interface:
        network = ltoa( net )
        # compute network representation if not yet done
        if network.split('.')[0] == addr.split('.')[0]:
          bits = self.__bit_count( msk )
          self.network = "%s/%d" % ( network, bits )
        # search for a valid network gateway
        if self.gateway is None and gw != '0.0.0.0':
          self.gateway = gw

    if self.gateway is not None and self.network is not None:
      print "@ Gateway is %s on network %s ." % ( self.gateway, self.network )
    else:
      raise Exception( "Could not find any network gateway." )

    self.find_alive_hosts()

    print "@ Please choose your target :"
    choice = None

    if all:
      self.targets = self.endpoints
    else:
      while choice is None:
        for i, item in enumerate( self.endpoints ):
          ( mac, ip ) = item
          vendor      = self.__find_mac_vendor( mac )
          print "  [%d] %s %s %s" % ( i, mac, ip, "( %s )" % vendor if vendor else '' )
        choice = raw_input( "@ Choose [0-%d] (* to select all, r to refresh): " % (len(self.endpoints) - 1) )
        try:
          choice = choice.strip()
          if choice == '*':
            self.targets = self.endpoints
          elif choice.lower() == 'r':
            choice = None
            self.find_alive_hosts()
          else:
            self.targets.append( self.endpoints[ int(choice) ] )
        except Exception as e:
          print "@ Invalid choice!"
          choice = None

    self.craft_packets()

    if not kill:
      print "@ Enabling ipv4 forwarding system wide ..."
      self.__set_forwarding( True )
    else:
      print "@ Disabling ipv4 forwarding system wide to kill target connections ..."
      self.__set_forwarding( False )

    atexit.register( self.restore_cache )
예제 #7
0
파일: core.py 프로젝트: caoimhinp/inguma
 def getLocalNetwork(self):
     for net,msk,gw,iface,addr in scapy.read_routes():
         if iface == scapy.conf.iface and scapy.ltoa(msk) != '0.0.0.0':
             net = IPy.IP( str(net) + "/" + scapy.ltoa(msk) )
             return net
예제 #8
0
파일: core.py 프로젝트: antaema/IN-Botnet
 def getLocalNetwork(self):
     for net, msk, gw, iface, addr in scapy.read_routes():
         if iface == scapy.conf.iface and scapy.ltoa(msk) != '0.0.0.0':
             net = IPy.IP(str(net) + "/" + scapy.ltoa(msk))
             return net