Пример #1
0
        private void CleanAndSave()
        {
            UpdateRtx("[+] Saving file...");
            ComponentsList = ExploitdbList.Concat(PacketstormList).Concat(ExploitalertList).ToList();
            if (!Directory.Exists(path: "Databases"))
            {
                Directory.CreateDirectory(path: "Databases");
            }
            //File.WriteAllLines(path: "Databases\\database.txt", contents: ComponentsList); // id,description,component
            List <DatabaseItems> jsonDatabase = new List <DatabaseItems>();

            foreach (string s in ComponentsList)
            {
                string[] info = s.Split(':');
                jsonDatabase.Add(new DatabaseItems()
                {
                    id          = info[0],
                    description = info[1],
                    component   = info[2],
                    version     = info[3],
                    exploit     = ""
                });
            }
            string data = JsonConvert.SerializeObject(jsonDatabase.ToArray(), Formatting.Indented);

            File.WriteAllText(path: "Databases\\database.txt", contents: data);
            UpdateRtx(txt: "[+] Cleaning...");

            if (File.Exists(path: Path.Combine(path1: TempPath, path2: "db.csv")))
            {
                File.Delete(path: Path.Combine(path1: TempPath, path2: "db.csv"));
            }
            ComponentsList   = new List <string>();
            ExploitalertList = new List <string>();
            ExploitdbList    = new List <string>();
            PacketstormList  = new List <string>();
            jsonDatabase     = new List <DatabaseItems>();

            UpdateRtx(txt: "Done.");
        }
Пример #2
0
        private void UpdateExploitdb()
        {
            try
            {
                new Thread(new ThreadStart(() =>
                {
                    UpdateRtx(txt: $"[+] Downloading exploit database from offensive-security's github...");
                    using (WebClient webClient = new WebClient())
                    {
                        ErrorCode = 0x1; // error in connecting to github server
                        webClient.DownloadFile(
                            "https://raw.githubusercontent.com/offensive-security/exploit-database/master/files_exploits.csv",
                            Path.Combine(TempPath, "db.csv"));
                    }
                    ErrorCode = 0x2; // error in reading file
                    UpdateRtx(txt: "[+] Reading database...");
                    string[] csvDatabase = File.ReadAllLines(Path.Combine(TempPath, "db.csv"));
                    UpdateRtx(txt: "[+] Searching for components...");
                    UpdateRtx(txt: $"[+] Exploitdb Components: {ExploitdbList.Count}");
                    ParallelOptions parallelOptions = new ParallelOptions()
                    {
                        MaxDegreeOfParallelism = Threads
                    };

                    int sleepCounter = 0;
                    object sleepLock = new object();
                    try
                    {
                        Parallel.ForEach(csvDatabase.ToArray().ToList(), parallelOptions, match =>
                        {
                            if (match.ToLower().Contains("joomla"))
                            {
                                string[] info = match.Split(',');
                                string id     = info[0],
                                description   = info[2],
                                component     = string.Empty,
                                version       = "n\a",
                                webpageSource = string.Empty;

                                using (WebClient webClient = new WebClient())
                                {
                                    ErrorCode = 0x3; // error in searching components
                                    ExploitID = id;
                                    webClient.Headers.Add(name: "user-agent",
                                                          value: " Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0");
                                    try
                                    {
                                        webpageSource = webClient.DownloadString(address: $"{Exploitdb_Server}{id}");

                                        if (Regex.IsMatch(webpageSource, Date_Pattern))
                                        {
                                            version = versionDetector.GetVersion(
                                                date: Regex.Match(input: webpageSource,
                                                                  pattern: Date_Pattern)
                                                .Value);
                                        }

                                        if (Regex.IsMatch(input: description, pattern: Component_Pattern))
                                        {
                                            component = Regex.Match(
                                                input: description,
                                                pattern: Component_Pattern)
                                                        .Value;
                                        }
                                        else
                                        {
                                            webpageSource = webpageSource.Substring(startIndex: 0,
                                                                                    length: webpageSource.IndexOf(
                                                                                        value: "<h2>Related Exploits</h2>")); // prevent adding related components
                                            if (Regex.IsMatch(input: webpageSource, pattern: Component_Pattern))
                                            {
                                                component = Regex.Match(input: webpageSource,
                                                                        pattern: Component_Pattern)
                                                            .Value;
                                            }
                                        }

                                        if (!string.IsNullOrEmpty(component))
                                        {
                                            ExploitdbList.Add(item:
                                                              $"{id}:{description}:{component}:{version}"
                                                              );
                                        }

                                        Rtx.Invoke((System.Windows.Forms.MethodInvoker) delegate
                                        {
                                            Rtx.Text = (Rtx.Text.Replace(oldValue: Regex.Match(input: Rtx.Text,
                                                                                               pattern: @".*Exploitdb Components.*").Value, newValue: $"[{DateTime.Now.ToString("hh:mm:ss tt")}]\t[+] Exploitdb Components: {ExploitdbList.Count}"));
                                        });
                                    }
                                    catch (Exception ex) { UpdateRtx(txt: $"[-] Error in ExploitID:{ExploitID}.{ex.Message}"); };
                                }
                                lock (sleepLock)
                                {
                                    sleepCounter++;
                                }
                                if (sleepCounter > MaxSleep)
                                {
                                    Thread.Sleep(Timeout);
                                    lock (sleepLock)
                                    {
                                        sleepCounter = 0;
                                    }
                                }
                            }
                        });
                    }
                    catch (AggregateException ex) { UpdateRtx(txt: $"[-] Error description: {ex.Message}"); };

                    UpdateRtx("[+] Database updated from exploit-db.com.");
                    Exploitdb = false;
                    CheckPriority();
                }))
                {
                    IsBackground = true
                }.Start();
            }
            catch (Exception ex)
            {
                switch (ErrorCode)
                {
                case 0x1:
                    UpdateRtx(txt: $"[-] Error code: {ErrorCode}");
                    UpdateRtx(txt: $"[-] Error description: Problem in connecting to github server or file not found.{ex.Message}");
                    break;

                case 0x2:
                    UpdateRtx(txt: $"[-] Error code: {ErrorCode}");
                    UpdateRtx(txt: $"[-] Error description: Problem in reading database.{ex.Message}");
                    break;

                case 0x3:
                    UpdateRtx(txt: $"[-] Error code: {ErrorCode}");
                    UpdateRtx(txt: $"[-] Error description: Problem in searching component.{ex.Message}\tExploitID:{ExploitID}");
                    break;

                default:
                    UpdateRtx(txt: $"[-] Error code:Unkown");
                    UpdateRtx(txt: $"[-] Error description: {ex.Message}");
                    break;
                }
            };
        }