Scanner SetFormatPlugin(Scanner S) { Request RequestToScan = S.OriginalRequest; if (!FormatPlugin.IsNormal(RequestToScan)) { string FPName = FormatPlugin.Get(RequestToScan, FormatPlugins); if (FPName.Length > 0 && FPName != "Normal") { S.BodyFormat = FormatPlugin.Get(FPName); } } return(S); }
static void DoScan() { Spider = new Crawler(); try { Spider.PrimaryHost = PrimaryHost; Spider.BaseUrl = BaseUrl; Spider.StartingUrl = StartingUrl; Spider.PerformDirAndFileGuessing = PerformDirAndFileGuessing; Spider.IncludeSubDomains = IncludeSubDomains; Spider.HTTP = HTTP; Spider.HTTPS = HTTPS; Spider.UrlsToAvoid = UrlsToAvoid; Spider.HostsToInclude = HostsToInclude; Spider.Start(); } catch (Exception Exp) { IronException.Report("Error starting Crawler", Exp); try { Stop(); } catch { } return; } ScanItemUniquenessChecker UniqueChecker = new ScanItemUniquenessChecker(Mode != ScanMode.Default); List <int> ScanIDs = new List <int>(); bool ScanActive = true; List <string> ActivePlugins = ActivePlugin.List(); int TotalRequestsCrawled = 0; int TotalScanJobsCreated = 0; int TotalScanJobsCompleted = 0; List <Request> ScannedRequests = new List <Request>(); int SleepCounter = 0; while (ScanActive) { ScanActive = false; List <Request> Requests = Spider.GetCrawledRequests(); if (Stopped) { return; } if (Requests.Count > 0 || Spider.IsActive()) { ScanActive = true; if (CrawlAndScan) { TotalRequestsCrawled = TotalRequestsCrawled + Requests.Count; //update the ui with the number of requests crawled foreach (Request Req in Requests) { if (Stopped) { return; } if (!CanScan(Req)) { continue; } if (!UniqueChecker.IsUniqueToScan(Req, ScannedRequests, false)) { continue; } try { Scanner S = new Scanner(Req); S.CheckAll(); if (S.OriginalRequest.Query.Count == 0 && S.OriginalRequest.File.Length != 3 && S.OriginalRequest.File.Length != 4) { S.InjectUrl(); } S.InjectQuery(); S.InjectBody(); //S.InjectHeaders(); //S.InjectCookie(); if (!FormatPlugin.IsNormal(Req)) { List <FormatPlugin> RightList = FormatPlugin.Get(Req); if (RightList.Count > 0) { S.BodyFormat = RightList[0]; } } if (S.InjectionPointsCount == 0) { continue; } TotalScanJobsCreated++; if (Stopped) { return; } int ScanID = S.LaunchScan(); if (Stopped) { Stop(true); return; } if (ScanID > 0) { ScannedRequests.Add(Req); ScanIDs.Add(ScanID); } } catch (Exception Exp) { IronException.Report(string.Format("Error creating Scan Job with Request - {0}", Req.Url), Exp); } } } } if (CrawlAndScan) { List <int> ScanIDsToRemove = new List <int>(); List <int> AbortedScanIDs = Scanner.GetAbortedScanIDs(); List <int> CompletedScanIDs = Scanner.GetCompletedScanIDs(); for (int i = 0; i < ScanIDs.Count; i++) { if (Stopped) { return; } if (CompletedScanIDs.Contains(ScanIDs[i])) { ScanIDsToRemove.Add(i); TotalScanJobsCompleted++; } else if (AbortedScanIDs.Contains(ScanIDs[i])) { ScanIDsToRemove.Add(i); } } for (int i = 0; i < ScanIDsToRemove.Count; i++) { if (Stopped) { return; } ScanIDs.RemoveAt(ScanIDsToRemove[i] - i); } } if (ScanActive) { Thread.Sleep(2000); } else { if (ScanIDs.Count > 0) { ScanActive = true; Thread.Sleep(5000); } else if (SleepCounter < 10) { ScanActive = true; Thread.Sleep(2000); SleepCounter = SleepCounter + 2; } } if (Stopped) { return; } IronUI.UpdateConsoleCrawledRequestsCount(TotalRequestsCrawled); IronUI.UpdateConsoleScanJobsCreatedCount(TotalScanJobsCreated); IronUI.UpdateConsoleScanJobsCompletedCount(TotalScanJobsCompleted); } if (Stopped) { return; } Stop(); }