示例#1
0
def find_interface(interfaces: List[str], escalate: bool = True) -> str:
    """Find out if one of the possible network interfaces is indeed present.
    Return the first one found or exit (with a message) if none can be found.
    We are trying to deal with a renaming that Airmon sometimes does (adding "mon")
    Attention: Airmon tends to completely rename interfaces, too, so it makes sense to check both
               original factory name and airmon-edited name. This is why the parameter is a list."""
    found_interface = None
    if not isinstance(interfaces, list):
        interfaces = str(interfaces).split(",")
    for interface in interfaces:
        if interface not in net_interfaces():
            # Try to see if the interface was already put into monitoring mode. Airmon renames it then.
            monitoring_interface = interface + "mon"
            if monitoring_interface in net_interfaces():
                logger.warning(
                    '%s interface %s does not exist, but with "mon" added it does.'
                    % (settings.TERM_LBL, interface))
                found_interface = monitoring_interface
        else:
            found_interface = interface
    if found_interface is None and escalate:
        logger.error(
            "%s Error: the interfaces you specified (%s) cannot be found. Available interfaces: %s\n Maybe tweak the setting WIFI_INTERFACES ..."
            % (settings.TERM_LBL, interfaces, net_interfaces()))
        exit(2)
    return found_interface
示例#2
0
def put_wifi_interface_in_monitor_mode(interface: str, path_to_airmon_ng: str,
                                       sudo_pwd: str) -> str:
    """Run airmon-ng on this wifi interface. Airmon-ng usually changes the name, so we return the new one."""
    interfaces_before = net_interfaces()
    run_with_sudo(
        "%s start %s" % (path_to_airmon_ng, interface),
        sudo_pwd,
        "PHY",
        ["processes that could cause trouble"],
    )
    print(" monitor mode activated! ")
    interfaces_after = net_interfaces()
    # check if there is a difference in the two lists
    if set(interfaces_before) == set(interfaces_after):
        return interface
    else:
        return list(set(interfaces_after) - set(interfaces_before))[0]
示例#3
0
def put_wifi_interface_in_monitor_mode(
    interface: str, path_to_airmon_ng: str, sudo_pwd: str = None
) -> str:
    """Run airmon-ng to start this wifi interface. Airmon-ng usually changes the name, so we return the new one."""
    interfaces_before = net_interfaces()
    run_cmd_and_check_response(
        "%s start %s" % (path_to_airmon_ng, interface),
        "PHY",
        # ["processes that could cause trouble", "Run it as root"],
        ["Run it as root"],
        sudo_pwd,
    )
    interfaces_after = net_interfaces()
    # check if there is a difference in the two lists
    if set(interfaces_before) == set(interfaces_after):
        return interface
    else:
        return list(set(interfaces_after) - set(interfaces_before))[0]
示例#4
0
def start(
    sudo_pwd,
    airmon_ng_path,
    airodump_path,
    airodump_file_prefix,
    wifi_interfaces,
    airodump_log_interval_in_seconds,
) -> Optional[str]:
    """Start airodump, be sure airomon monitors the right interface beforehand.
    Return interface name actually being used."""
    wifi_interface = None
    wifi_interfaces = wifi_interfaces.split(",") 
    try:
        # This trick is handy if the card was already in monitor mode (e.g. if Aileen restarts this sensor)
        if find_interface(settings.WIFI_INTERFACES, escalate=False) is None:
            interfaces_visible = net_interfaces()
            if len(interfaces_visible) > 0:
                stop_interface_from_being_monitored(
                    interfaces_visible[-1],
                    settings.FULL_PATH_TO_AIRMON_NG,
                    settings.SUDO_PWD)

        wifi_interface = find_interface(wifi_interfaces)
        wifi_interface = put_wifi_interface_in_monitor_mode(
            wifi_interface, airmon_ng_path, sudo_pwd
        )
        logging.info(
            "%s Monitor mode activated for wifi interface: '%s'"
            % (settings.TERM_LBL, wifi_interface)
        )
        start_airodump(
            wifi_interface,
            airodump_path,
            airodump_file_prefix,
            airodump_log_interval_in_seconds,
            sudo_pwd,
        )
    except KeyboardInterrupt:
        logging.error("%s KeyboardInterrupt!" % settings.TERM_LBL)
        exit(1)
    except Exception as e:
        logging.error("%s Problem: %s" % (settings.TERM_LBL, e))
        exit(2)
    return wifi_interface