Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
96 lines (80 sloc) 2.38 KB
using System.Diagnostics;
using System.Threading;
using ZAPPenTester.Interfaces;
using ZAPPenTester.Models;
namespace ZAPPenTester
{
/// <summary>
/// This class is responsible for managing the ZAP application.
/// The functionality of the tool relies on the application being running, because the API is not available when ZAP is not running.
/// </summary>
public class Zap
{
private Process process;
private readonly ISettings settings;
private readonly ILogger logger;
private readonly IScanner scanner;
private readonly IReporting reporting;
private readonly ISpider spider;
public int sleepTimeBetweenRequests = 15000;
public Zap(ISettings settings, ILogger logger, IScanner scanner, IReporting reporting, ISpider spider)
{
this.settings = settings;
this.logger = logger;
this.scanner = scanner;
this.reporting = reporting;
this.spider = spider;
}
public void Open()
{
logger.Log("Opening ZAP");
process = new Process
{
StartInfo =
{
FileName = settings.ZapStartFile,
WorkingDirectory = settings.ZapWorkingDirectory,
Arguments = "-daemon"
}
};
process.Start();
process.WaitForExit();
Thread.Sleep(sleepTimeBetweenRequests);
}
public void Close()
{
logger.Log("Closing ZAP");
if (process.HasExited)
{
return;
}
process.Kill();
}
public void Scan(string urlToScan)
{
if (!spider.Start(urlToScan))
{
return;
}
do
{
Thread.Sleep(sleepTimeBetweenRequests);
}
while (!spider.HasCompleted());
if (!scanner.Scan(urlToScan))
{
return;
}
do
{
Thread.Sleep(sleepTimeBetweenRequests);
}
while (!scanner.HasCompleted());
logger.Log("Scan complete");
}
public Report GetReport(string url)
{
return reporting.GetReport(url);
}
}
}