コード例 #1
0
ファイル: __init__.py プロジェクト: Epiann1/shiva
def route_add_loopback(routes=None, ipv6=False, iflist=None):
    """Add a route to 127.0.0.1 and ::1 to simplify unit tests on Windows"""
    if not WINDOWS:
        warning("Not available")
        return
    warning("This will completly mess up the routes. Testing purpose only !")
    # Add only if some adpaters already exist
    if ipv6:
        if not conf.route6.routes:
            return
    else:
        if not conf.route.routes:
            return
    data = {}
    data['name'] = LOOPBACK_NAME
    data['description'] = "Loopback"
    data['win_index'] = -1
    data['guid'] = "{0XX00000-X000-0X0X-X00X-00XXXX000XXX}"
    data['invalid'] = True
    data['mac'] = '00:00:00:00:00:00'
    adapter = NetworkInterface(data)
    if iflist:
        iflist.append(six.text_type("\\Device\\NPF_" + adapter.guid))
        return
    # Remove all LOOPBACK_NAME routes
    for route in list(conf.route.routes):
        iface = route[3]
        if iface.name == LOOPBACK_NAME:
            conf.route.routes.remove(route)
    # Remove LOOPBACK_NAME interface
    for devname, iface in IFACES.items():
        if iface.name == LOOPBACK_NAME:
            IFACES.pop(devname)
    # Inject interface
    IFACES[data['guid']] = adapter
    # Build the packed network addresses
    loop_net = struct.unpack("!I", socket.inet_aton("127.0.0.0"))[0]
    loop_mask = struct.unpack("!I", socket.inet_aton("255.0.0.0"))[0]
    # Build the fake routes
    loopback_route = (loop_net, loop_mask, "0.0.0.0", adapter, "127.0.0.1")
    loopback_route6 = ('::1', 128, '::', adapter, ["::1"])
    loopback_route6_custom = ("fe80::", 128, "::", adapter, ["::1"])
    if routes == None:
        # Injection
        conf.route6.routes.append(loopback_route6)
        conf.route6.routes.append(loopback_route6_custom)
        conf.route.routes.append(loopback_route)
        # Flush the caches
        conf.route6.invalidate_cache()
        conf.route.invalidate_cache()
    else:
        if ipv6:
            routes.append(loopback_route6)
            routes.append(loopback_route6_custom)
        else:
            routes.append(loopback_route)
コード例 #2
0
ファイル: __init__.py プロジェクト: mcpat/scapy
def route_add_loopback(routes=None, ipv6=False, iflist=None):
    """Add a route to 127.0.0.1 and ::1 to simplify unit tests on Windows"""
    if not WINDOWS:
        warning("Not available")
        return
    warning("This will completly mess up the routes. Testing purpose only !")
    # Add only if some adpaters already exist
    if ipv6:
        if len(conf.route6.routes) == 0:
            return
    else:
        if len(conf.route.routes) == 0:
            return
    data = {}
    data['name'] = LOOPBACK_NAME
    data['description'] = "Loopback"
    data['win_index'] = -1
    data['guid'] = "{0XX00000-X000-0X0X-X00X-00XXXX000XXX}"
    data['invalid'] = True
    data['mac'] = '00:00:00:00:00:00'
    adapter = NetworkInterface(data)
    if iflist:
        iflist.append(six.text_type("\\Device\\NPF_" + adapter.guid))
        return
    # Remove all LOOPBACK_NAME routes
    for route in list(conf.route.routes):
        iface = route[3]
        if iface.name == LOOPBACK_NAME:
            conf.route.routes.remove(route)
    # Remove LOOPBACK_NAME interface
    for devname, iface in IFACES.items():
        if iface.name == LOOPBACK_NAME:
            IFACES.pop(devname)
    # Inject interface
    IFACES[data['guid']] = adapter
    # Build the packed network addresses
    loop_net = struct.unpack("!I", socket.inet_aton("127.0.0.0"))[0]
    loop_mask = struct.unpack("!I", socket.inet_aton("255.0.0.0"))[0]
    # Build the fake routes
    loopback_route = (loop_net, loop_mask, "0.0.0.0", adapter, "127.0.0.1")
    loopback_route6 = ('::1', 128, '::', adapter, ["::1"])
    loopback_route6_custom = ("fe80::", 128, "::", adapter, ["::1"])
    if routes == None:
        # Injection
        conf.route6.routes.append(loopback_route6)
        conf.route6.routes.append(loopback_route6_custom)
        conf.route.routes.append(loopback_route)
        # Flush the caches
        conf.route6.invalidate_cache()
        conf.route.invalidate_cache()
    else:
        if ipv6:
            routes.append(loopback_route6)
            routes.append(loopback_route6_custom)
        else:
            routes.append(loopback_route)
コード例 #3
0
 def readLineScapy(prompt):
     result = ""
     end = False
     while not end:
         if not end and result != "":
             line = readline.rl.readline("... ")
         else:
             line = readline.rl.readline(prompt)
         if line.strip().endswith(":"):
             end = False
         elif result == "":
             end = True
         if line.strip() == "":
             end = True
         result = result + "\n" + line
     return six.text_type(result)
コード例 #4
0
ファイル: __init__.py プロジェクト: mcpat/scapy
 def readLineScapy(prompt):
     result = ""
     end = False
     while not end :
         if not end and result != "":
             line = readline.rl.readline("... ")
         else:
             line = readline.rl.readline(prompt)
         if line.strip().endswith(":"):
             end = False
         elif result == "":
             end = True
         if line.strip() == "":
             end = True
         result = result + "\n" + line
     return six.text_type(result)
コード例 #5
0
ファイル: __init__.py プロジェクト: conordavis/scapy
def route_add_loopback(routes=None, ipv6=False, iflist=None):
    """Add a route to 127.0.0.1 and ::1 to simplify unit tests on Windows"""
    if not WINDOWS:
        warning("Not available")
        return
    warning("This will completly mess up the routes. Testing purpose only !")
    # Add only if some adpaters already exist
    if ipv6:
        if not conf.route6.routes:
            return
    else:
        if not conf.route.routes:
            return
    data = {
        'name': scapy.consts.LOOPBACK_NAME,
        'description': "Loopback",
        'win_index': -1,
        'guid': _get_valid_guid(),
        'invalid': False,
        'mac': '00:00:00:00:00:00',
    }
    data['pcap_name'] = six.text_type("\\Device\\NPF_" + data['guid'])
    adapter = NetworkInterface(data)
    adapter.ip = "127.0.0.1"
    if iflist:
        iflist.append(adapter.pcap_name)
        return
    # Remove all LOOPBACK_NAME routes
    for route in list(conf.route.routes):
        iface = route[3]
        if iface.name == scapy.consts.LOOPBACK_NAME:
            conf.route.routes.remove(route)
    # Remove LOOPBACK_NAME interface
    for devname, iface in list(IFACES.items()):
        if iface.name == scapy.consts.LOOPBACK_NAME:
            IFACES.pop(devname)
    # Inject interface
    IFACES["{0XX00000-X000-0X0X-X00X-00XXXX000XXX}"] = adapter
    scapy.consts.LOOPBACK_INTERFACE = adapter
    if isinstance(conf.iface, NetworkInterface):
        if conf.iface.name == LOOPBACK_NAME:
            conf.iface = adapter
    if isinstance(conf.iface6, NetworkInterface):
        if conf.iface6.name == LOOPBACK_NAME:
            conf.iface6 = adapter
    # Build the packed network addresses
    loop_net = struct.unpack("!I", socket.inet_aton("127.0.0.0"))[0]
    loop_mask = struct.unpack("!I", socket.inet_aton("255.0.0.0"))[0]
    # Build the fake routes
    loopback_route = (loop_net, loop_mask, "0.0.0.0", adapter, "127.0.0.1", 1)
    loopback_route6 = ('::1', 128, '::', adapter, ["::1"], 1)
    loopback_route6_custom = ("fe80::", 128, "::", adapter, ["::1"], 1)
    if routes == None:
        # Injection
        conf.route6.routes.append(loopback_route6)
        conf.route6.routes.append(loopback_route6_custom)
        conf.route.routes.append(loopback_route)
        # Flush the caches
        conf.route6.invalidate_cache()
        conf.route.invalidate_cache()
    else:
        if ipv6:
            routes.append(loopback_route6)
            routes.append(loopback_route6_custom)
        else:
            routes.append(loopback_route)
コード例 #6
0
ファイル: __init__.py プロジェクト: dark-lbp/scapy
def route_add_loopback(routes=None, ipv6=False, iflist=None):
    """Add a route to 127.0.0.1 and ::1 to simplify unit tests on Windows"""
    if not WINDOWS:
        warning("Not available")
        return
    warning("This will completly mess up the routes. Testing purpose only !")
    # Add only if some adpaters already exist
    if ipv6:
        if not conf.route6.routes:
            return
    else:
        if not conf.route.routes:
            return
    data = {
        'name': scapy.consts.LOOPBACK_NAME,
        'description': "Loopback",
        'win_index': -1,
        'guid': _get_valid_guid(),
        'invalid': False,
        'mac': '00:00:00:00:00:00',
    }
    data['pcap_name'] = six.text_type("\\Device\\NPF_" + data['guid'])
    adapter = NetworkInterface(data)
    if iflist:
        iflist.append(adapter.pcap_name)
        return
    # Remove all LOOPBACK_NAME routes
    for route in list(conf.route.routes):
        iface = route[3]
        if iface.name == scapy.consts.LOOPBACK_NAME:
            conf.route.routes.remove(route)
    # Remove LOOPBACK_NAME interface
    for devname, iface in list(IFACES.items()):
        if iface.name == scapy.consts.LOOPBACK_NAME:
            IFACES.pop(devname)
    # Inject interface
    IFACES[data['guid']] = adapter
    scapy.consts.LOOPBACK_INTERFACE = adapter
    if isinstance(conf.iface, NetworkInterface):
        if conf.iface.name == LOOPBACK_NAME:
            conf.iface = adapter
    if isinstance(conf.iface6, NetworkInterface):
        if conf.iface6.name == LOOPBACK_NAME:
            conf.iface6 = adapter
    # Build the packed network addresses
    loop_net = struct.unpack("!I", socket.inet_aton("127.0.0.0"))[0]
    loop_mask = struct.unpack("!I", socket.inet_aton("255.0.0.0"))[0]
    # Build the fake routes
    loopback_route = (loop_net, loop_mask, "0.0.0.0", adapter, "127.0.0.1", 1)
    loopback_route6 = ('::1', 128, '::', adapter, ["::1"], 1)
    loopback_route6_custom = ("fe80::", 128, "::", adapter, ["::1"], 1)
    if routes == None:
        # Injection
        conf.route6.routes.append(loopback_route6)
        conf.route6.routes.append(loopback_route6_custom)
        conf.route.routes.append(loopback_route)
        # Flush the caches
        conf.route6.invalidate_cache()
        conf.route.invalidate_cache()
    else:
        if ipv6:
            routes.append(loopback_route6)
            routes.append(loopback_route6_custom)
        else:
            routes.append(loopback_route)