Пример #1
0
def main():
    global ssids
    networkconf.stop_nm()
    time.sleep(2)
    networkconf.set_iface()
    ssids = scan_wifi.scan()
    hostapd.start()
    dnsmasq.start()
Пример #2
0
def main(address, port, ui_path, simulate, delete_connections):

    # See if caller wants to delete all existing connections first
    if delete_connections and not simulate:
        netman.delete_all_wifi_connections()

    # Check if we are already connected, if so we are done.
    if netman.have_active_internet_connection() and not simulate:
        print('Already connected to the internet, nothing to do, exiting.')
        sys.exit()

    # Get list of available AP from net man.
    # Must do this AFTER deleting any existing connections (above),
    # and BEFORE starting our hotspot (or the hotspot will be the only thing
    # in the list).
    ssids = netman.get_list_of_access_points()

    # Start the hotspot
    if not netman.start_hotspot() and not simulate:
        print('Error starting hotspot, exiting.')
        sys.exit(1)

    # Start dnsmasq (to advertise us as a router so captured portal pops up
    # on the users machine to vend our UI in our http server)
    if not simulate:
        dnsmasq.start()

    # Find the ui directory which is up one from where this file is located.
    web_dir = os.path.join(os.path.dirname(__file__), ui_path)
    print(f'HTTP serving directory: {web_dir} on {address}:{port}')

    # Change to this directory so the HTTPServer returns the index.html in it
    # by default when it gets a GET.
    os.chdir(web_dir)

    # Host:Port our HTTP server listens on
    server_address = (address, port)

    # Custom request handler class (so we can pass in our own args)
    MyRequestHandlerClass = RequestHandlerClassFactory(simulate, address,
                                                       ssids)

    # Start an HTTP server to serve the content in the ui dir and handle the
    # POST request in the handler class.
    print(
        f'Waiting for a connection to our hotspot {netman.get_hotspot_SSID()} ...'
    )
    httpd = MyHTTPServer(web_dir, server_address, MyRequestHandlerClass)
    try:
        httpd.serve_forever()
    except KeyboardInterrupt:
        dnsmasq.stop()
        netman.stop_hotspot()
        httpd.server_close()
Пример #3
0
def start(interface):
    # Checking processes with airmon-ng
    res = net.kill_unwanted()
    style.print_call_info(res, "airmon-ng", "Killed unwanted processes.")

    # Unblocking wifi if needed
    res = net.check_rfkill()
    style.print_call_info(res, "rfkill",
                          "Unblocked Wifi (Soft and Hardware mode)")

    # Saving actual iptables rules to restore it after stopping the ap
    iptables.save_rules()
    style.checked('Saved actual iptables rules')

    # Flushing iptables
    res = iptables.flush_nat()
    style.print_call_info(res, 'iptables', 'Flushed iptables rules')

    # Setting interface to listen on for dnsmasq
    dnsmasq.write_conf(interface)

    # Starting dnsmasq service
    res = dnsmasq.start()
    style.print_call_info(res, 'dnsmasq', 'Started dnsmasq service')

    # Loading iptables rules for SSLSplit and hostapd
    res = iptables.restore(iptables.SSLSPLIT_CONF)
    style.print_call_info(res, 'iptables',
                          'Updated iptables rules for SSL Split')

    # Confiuguring interface
    res = net.configure_interface(interface)
    style.print_call_info(res, "ifconfig", "Configured interface")

    # Enabling IP forward
    res = net.ip_forward(enable=True)
    style.print_call_info(res, "ip_forward", "Enabled IP forwarding")

    # Starting hostapd
    subhostapd = hostapd.start()
    style.print_call_info(0, "hostapd", "Started hostapd")

    # Starting SSL Split
    subssl = subprocess.Popen([
        'xterm', '-T', XTERM_TITLE, '-e', 'sslsplit', '-D', '-l', CONN_FILE,
        '-S', LOGS_DIR, '-k', "{}/ca.key".format(KEYS_DIR), '-c',
        "{}/ca.crt".format(KEYS_DIR), 'ssl', '0.0.0.0', SSL_PORT, 'tcp',
        '0.0.0.0', TCP_PORT
    ])
    style.print_call_info(0, "sslsplit", "Started SSLSplit")

    return subhostapd, subssl