2016-08-18 33 views
0

我正在嘗試使用zap proxy進行主動掃描。代碼如下所示:如何主動掃描(ascan)多個URL

// /spider/action/scan/ and wait till it finishes 
int scanId = StartScanning(clientApi, API_KEY, "https://contosco.com/Home.aspx"); 
PollTheSpiderTillCompletion(clientApi, scanId); 

// /ascan/action/scan/ and wait till it finishes 
int activeScanId = StartActiveScanning(clientApi, API_KEY, "https://contosco.com/Home.aspx"); 
PollTheActiveScannerTillCompletion(clientApi, activeScanId); 

蜘蛛正確遍歷應用程序中的所有URL。然而,主動掃描僅命中第一個URL並停止。有沒有辦法如何積極掃描所有的網址(或者我應該先得到蜘蛛報告,然後通過蜘蛛報告迭代,並從蜘蛛報告中掃描每一個網址)?

完整的源:

private static int StartScanning(ClientApi api, string apiKey, string url) 
{ 
    var apiResponse = api.spider.scan(apiKey, url, ""); 
    string scanid = ((ApiResponseElement)apiResponse).Value; 
    return int.Parse(scanid); 
} 

private static int StartActiveScanning(ClientApi api, string apiKey, string url) 
{ 
    var apiResponse = api.ascan.scan(apiKey, url, "true", "", "", "", ""); 
    string activeScanId = ((ApiResponseElement)apiResponse).Value; 
    return int.Parse(activeScanId); 
} 

private static void PollTheSpiderTillCompletion(ClientApi api, int scanid) 
{ 
    int spiderProgress; 
    while (true) 
    { 
    Thread.Sleep(1000); 
    spiderProgress = int.Parse(((ApiResponseElement)api.spider.status(Convert.ToString(scanid))).Value); 
    if (spiderProgress >= 100) 
     break; 
    } 

    Thread.Sleep(10000); 
} 

private static void PollTheActiveScannerTillCompletion(ClientApi api, int activeScanId) 
{ 
    int activeScannerprogress; 
    while (true) 
    { 
    Thread.Sleep(5000); 
    activeScannerprogress = int.Parse(((ApiResponseElement)api.ascan.status(Convert.ToString(activeScanId))).Value); 
    if (activeScannerprogress >= 100) 
     break; 
    } 
} 

回答

0

哪個客戶端庫,您使用的?

你應該等待,直到蜘蛛完成,但'PollTheSpiderTillCompletion'意味着發生。

在底層ZAP API中,您需要指定活動掃描器是否應遞歸到子頁面中。我懷疑你的代碼沒有這樣做,但我不認識這個API,所以不知道它的發。。

+0

我使用的是.NET api(雖然那真的沒關係:))我將recurse設置爲true。我想我已經解決了這個問題 - ascan遞歸URL是https://contosco.com/Home.aspx(蜘蛛的根網址),它應該是https://contosco.com(只是域根目錄)。 –

+0

很高興現在排序:) –