小编典典

如何使用与Jenkins集成的Python API脚本为zap(Owasp)创建HTML报告

jenkins

我使用Python API触发了zap,如下所示:

脚本来源:

https://github.com/zaproxy/zaproxy/wiki/ApiPython

我想要通过命令行生成的HTML报告。

我正在尝试将其与詹金斯集成。我在Jenkins中发现了很少的Owasp插件,但似乎没有按预期工作。

任何想法,链接,教程都会对我有帮助。


阅读 623

收藏
2020-07-25

共1个答案

小编典典

用户可以通过此URL / API(http:// ZAP-IP:PORT / UI / core / other / htmlreport
/
)获取报告。

我没有找到任何zap支持插件,所以我写了selenium webdriver Java脚本来完成任务。代码是:-

    @Test
    public void Report() {
            System.setProperty("webdriver.chrome.driver",System.getProperty("user.dir")+"\\src\\lib\\chromedriver.exe");
            ChromeOptions chromeOptions = new ChromeOptions();
            chromeOptions.addArguments("--start-maximized");
            WebDriver driver = new ChromeDriver(chromeOptions);
            driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
            driver.get("http://localhost:8080/UI/core/other/htmlreport");
            driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
            driver.findElement(By.id("apikey")).sendKeys("ChangeMe");
            driver.findElement(By.id("button")).click();

            SimpleDateFormat dateFormatForFoldername = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");
            Date currentDate = new Date();
            String folderDateFormat = dateFormatForFoldername.format(currentDate);
        try {
            URL oracle = new URL(driver.getCurrentUrl());
            BufferedReader in = new BufferedReader(
            new InputStreamReader(oracle.openStream()));
            BufferedWriter writer = new BufferedWriter(new FileWriter("Reports"+File.separator+"OwaspReport-"+folderDateFormat+".html"));

            String inputLine;
            while ((inputLine = in.readLine()) != null){
                try{
                    writer.write(inputLine);
                }
                catch(IOException e){
                    e.printStackTrace();
                    return;
                }
            }
            in.close();
            writer.close();
            driver.quit();
        }
        catch(Exception ex) {
            System.out.println(ex.getMessage());
            ex.printStackTrace();
        }   
    }

注意:-根据您的zap端口更改URL中的端口并替换apiKey

希望它能对您有所帮助:)

2020-07-25