Example #1
0
    def StartApFake(self):
        if len(self.selectCard.currentText()) == 0:
            return QMessageBox.warning(self, 'Error interface ',
                                       'Network interface is not found')
        if not type(self.SoftDependencies()) is bool: return

        self.interfacesLink = Refactor.get_interfaces()
        if len(self.EditGateway.text()
               ) == 0 or self.interfacesLink['activated'] == None:
            return QMessageBox.warning(
                self, 'Internet Connection',
                'No internet connection not found, '
                'sorry WiFi-Pumpkin tool requires an internet connection to mount MITM attack. '
                'check your connection and try again')

        if str(self.selectCard.currentText()
               ) == self.interfacesLink['activated']:
            iwconfig = Popen(['iwconfig'],
                             stdout=PIPE,
                             shell=False,
                             stderr=PIPE)
            for line in iwconfig.stdout.readlines():
                if str(self.selectCard.currentText()) in line:
                    return QMessageBox.warning(
                        self, 'Wireless Interface',
                        'An connection with {} has been detected '
                        ' : Device or resource busy\n{}'.format(
                            str(self.selectCard.currentText()), line))

        import platform
        if platform.dist()[0] == 'Kali':
            if str(self.interfacesLink['activated']).startswith('wl'):
                return QMessageBox.information(
                    self, 'Error network card',
                    'You are connected with interface wireless, try again with local connection'
                )

        dh, gateway = self.PumpSettingsTAB.getPumpkinSettings()['router'], str(
            self.EditGateway.text())
        if dh[:len(dh) - len(dh.split('.').pop(
        ))] == gateway[:len(gateway) - len(gateway.split('.').pop())]:
            return QMessageBox.warning(
                self, 'DHCP Server Settings',
                'The DHCP server check if range ip class is same.'
                'it works, but not share internet connection in some case.\n'
                'for fix this, You need change on tab (Pumpkin-Settings -> Class Ranges)'
                'now you have choose the Class range different of your network.'
            )
        self.btn_start_attack.setDisabled(True)
        popen('ulimit -n 64000')

        self.APactived = self.FSettings.Settings.get_setting(
            'accesspoint', 'using')
        if self.APactived == 'hostapd':
            self.ConfigTwin['AP_iface'] = str(self.selectCard.currentText())
            if str(self.interfacesLink['activated']).startswith('eth') or \
               str(self.interfacesLink['activated']).startswith('enp'):
                try:
                    check_output(['nmcli', 'radio', 'wifi', "off"])
                except Exception:
                    try:
                        check_output(['nmcli', 'nm', 'wifi', "off"])
                    except Exception as e:
                        return QMessageBox.warning(self, 'Error nmcli', e)
                finally:
                    call(['rfkill', 'unblock', 'wifi'])
            elif str(self.interfacesLink['activated']).startswith('wl'):
                if not Refactor.settingsNetworkManager(
                        self.ConfigTwin['AP_iface'], Remove=False):
                    return QMessageBox.warning(
                        self, 'Network Manager',
                        'Not found file NetworkManager.conf in folder /etc/NetworkManager/'
                    )

            leases = '/var/lib/dhcp/dhcpd.leases'
            if not path.exists(leases[:-12]):
                mkdir(leases[:-12])
            if not path.isfile(leases):
                with open(leases, 'wb') as leaconf:
                    leaconf.close()
            uid = getpwnam('root').pw_uid
            gid = getgrnam('root').gr_gid
            chown(leases, uid, gid)
            self.CoreSettings()
            ignore = ('interface=', 'ssid=', 'channel=')
            with open('Settings/hostapd.conf', 'w') as apconf:
                for i in self.SettingsAP['hostapd']:
                    apconf.write(i)
                for config in str(
                        self.FSettings.ListHostapd.toPlainText()).split('\n'):
                    if not config.startswith('#') and len(config) > 0:
                        if not config.startswith(ignore):
                            apconf.write(config + '\n')
                apconf.close()
            self.Thread_hostapd = ProcessHostapd(
                ['hostapd', '-d', 'Settings/hostapd.conf'])
            self.Thread_hostapd.setObjectName('hostapd')
            self.Thread_hostapd.statusAP_connected.connect(
                self.GetHostapdStatus)
            self.Apthreads['RougeAP'].append(self.Thread_hostapd)

        # thread dhcp
        popen('ifconfig {} up'.format(str(self.selectCard.currentText())))
        selected_dhcp = self.FSettings.Settings.get_setting(
            'accesspoint', 'dhcp_server')
        if selected_dhcp == 'iscdhcpserver':
            Thread_dhcp = ThRunDhcp([
                'sudo', 'dhcpd', '-d', '-f', '-lf',
                '/var/lib/dhcp/dhcpd.leases', '-cf', '/etc/dhcp/dhcpd.conf',
                self.ConfigTwin['AP_iface']
            ])
            Thread_dhcp.sendRequest.connect(self.GetDHCPRequests)
            Thread_dhcp.setObjectName('DHCP')
            self.Apthreads['RougeAP'].append(Thread_dhcp)

        ##### dnsmasq disabled
        # elif selected_dhcp == 'dnsmasq':
        #     Thread_dhcp = ThRunDhcp(['dnsmasq','-C','Core/config/dnsmasq.conf','-d'])
        #     self.connect(Thread_dhcp ,SIGNAL('Activated ( QString ) '), self.dhcpLog)
        #     Thread_dhcp .setObjectName('DHCP')
        #     self.Apthreads['RougeAP'].append(Thread_dhcp)
        #     Thread_dhcp .start()
        self.Started(True)
        self.ProxyPluginsTAB.GroupSettings.setEnabled(False)
        self.FSettings.Settings.set_setting('accesspoint', 'statusAP', True)

        if self.PopUpPlugins.check_sslstrip.isChecked(
        ) or not self.PopUpPlugins.check_dns2proy.isChecked():
            popen(
                'iptables -t nat -A PREROUTING -p udp -j DNAT --to {}'.format(
                    str(self.EditGateway.text())))
        # load ProxyPLugins
        self.plugin_classes = Plugin.PluginProxy.__subclasses__()
        self.plugins = {}
        for p in self.plugin_classes:
            self.plugins[p._name] = p()

        # thread plugins
        if self.PopUpPlugins.check_sslstrip.isChecked(
        ) and not self.PopUpPlugins.check_sergioProxy.isChecked():
            self.Threadsslstrip = Thread_sslstrip(
                self.ConfigTwin['PortRedirect'], self.plugins,
                self.ProxyPluginsTAB._PluginsToLoader)
            self.Threadsslstrip.setObjectName("sslstrip")
            self.Apthreads['RougeAP'].append(self.Threadsslstrip)

        elif not self.PopUpPlugins.check_sslstrip.isChecked(
        ) and self.PopUpPlugins.check_sergioProxy.isChecked():
            self.Threadsslstrip = Thread_sergioProxy(
                self.ConfigTwin['PortRedirect'], self.plugins,
                self.ProxyPluginsTAB._PluginsToLoader)
            self.Threadsslstrip.setObjectName("sslstrip")
            self.Apthreads['RougeAP'].append(self.Threadsslstrip)

        elif self.PopUpPlugins.check_sergioProxy.isChecked(
        ) and self.PopUpPlugins.check_sergioProxy.isChecked():
            self.Threadsslstrip = Thread_sergioProxy(
                self.ConfigTwin['PortRedirect'], self.plugins,
                self.ProxyPluginsTAB._PluginsToLoader)
            self.Threadsslstrip.setObjectName("sslstrip")
            self.Apthreads['RougeAP'].append(self.Threadsslstrip)

        if self.PopUpPlugins.check_dns2proy.isChecked():
            Thread_dns2proxy = ProcessThread(
                ['python', 'Plugins/dns2proxy/dns2proxy.py'])
            Thread_dns2proxy.setName('Dns2Proxy')
            self.Apthreads['RougeAP'].append(Thread_dns2proxy)

        if self.PopUpPlugins.check_netcreds.isChecked():
            Thread_netcreds = ProcessThread([
                'python', 'Plugins/net-creds/net-creds.py', '-i',
                str(self.selectCard.currentText())
            ])
            Thread_netcreds.setName('Net-Creds')
            self.Apthreads['RougeAP'].append(Thread_netcreds)

        iptables = []
        for index in xrange(self.FSettings.ListRules.count()):
            iptables.append(str(self.FSettings.ListRules.item(index).text()))
        for rules in iptables:
            if search('--append FORWARD --in-interface', rules):
                popen(rules.replace('$$', self.ConfigTwin['AP_iface']))
            elif search('--append POSTROUTING --out-interface', rules):
                popen(
                    rules.replace('$$',
                                  str(Refactor.get_interfaces()['activated'])))
            else:
                popen(rules)

        self.PumpSettingsTAB.GroupArea.setEnabled(False)
        self.progress.change_color('#FFA500')
        for thread in self.Apthreads['RougeAP']:
            thread.start()
            self.progress.setText(thread.getNameThread())
            self.progress.update_bar_simple(20)
            QThread.sleep(3)
        self.progress.setValue(100)
        self.progress.change_color('grey')
        self.progress.setText('')
        if self.FSettings.Settings.get_setting('dockarea',
                                               'advanced',
                                               format=bool):
            self.PumpSettingsTAB.doCheckAdvanced()
            if hasattr(self, 'dockAreaList'):
                filelist = [
                    f for f in listdir('Logs/AccessPoint/.')
                    if f.endswith('.log.offset')
                ]
                for f in filelist:
                    system('rm Logs/AccessPoint/{}'.format(f))
                for dock in self.dockAreaList.keys():
                    self.dockAreaList[dock].RunThread()