简体   繁体   English

如何在ZAP中配置主动扫描输入向量?

[英]How to configure active scan input vectors in ZAP?

I want to develop an application using the ZAP API for Java that performs an active scan over a site. 我想使用ZAP API for Java开发一个在站点上执行主动扫描的应用程序。 I have the following code: 我有以下代码:

private static final String ZAP_ADDRESS = "localhost";
private static final int ZAP_PORT = 8090;
private static final String ZAP_API_KEY =
        null; // Change this if you have set the apikey in ZAP via Options / API

private static final String TARGET = "http://localhost:8080/examples/jsp/jsp2/el/basic-arithmetic.jsp";

public static void main(String[] args) {
    ClientApi api = new ClientApi(ZAP_ADDRESS, ZAP_PORT, ZAP_API_KEY);

    try {
         //*********** SPIDER *******************
        System.out.println("Spider : " + TARGET);


        //Probamos OPCIONES del spider
        String maxChildren="0";//Limite de hijos a explorar por nodo (0 es sin limite)
        String recurse="true";//Recursividad (boolean)
        String contextName=null;//nombre del contexto
        String subtreeOnly="false";//Para restringir el escaneo al subarbol de la url especificada (boolean)


        api.spider.setOptionMaxDepth(5);//Profundidad máxima para realizar el rastreo
        api.spider.setOptionMaxDuration(0);//Tiempo maximo del escaneo, 0 es hasta que explore todo
        api.spider.setOptionMaxParseSizeBytes(2621440); // Tamaño maximo  en bytes de las respuestas a analizar
        api.spider.setOptionSendRefererHeader(true);//si las consultas del spider han de incluir el ‘Referer’ header. 
        api.spider.setOptionAcceptCookies(true);//Si aceptamos o no cookies durante el spider
        api.spider.setOptionProcessForm(true);//Si se deben procesar los forms encontrados
        api.spider.setOptionPostForm(true);//Si los form que usen POST se procesan
        api.spider.setOptionParseComments(true);//Si se procesaran los comentarios html buscando enlaces a recursos
        api.spider.setOptionParseRobotsTxt(true);//Si se procesan los archivos robots.txt que se encuentren buscando enlaces a recursos
        api.spider.setOptionParseSitemapXml(true);//Si se procesa el siteMap.xml
        api.spider.setOptionParseSVNEntries(false);//Si se procesa metadata de SVN
        api.spider.setOptionParseGit(false);//Si se procesa metadata de Git
        api.spider.setOptionHandleODataParametersVisited(false);//Indica si se deben detectar parametros de OData


        ApiResponse resp = api.spider.scan(TARGET, maxChildren, recurse, contextName, subtreeOnly);



        // The scan now returns a scan id to support concurrent scanning
        String scanid = ((ApiResponseElement) resp).getValue();

        // Poll the status until it completes
        int progress;
        while (true) {
            progress =
                    Integer.parseInt(
                            ((ApiResponseElement) api.spider.status(scanid)).getValue());
            System.out.println("Spider progress : " + progress + "%");
            if (progress >= 100) {
                break;
            }
            Thread.sleep(1000);
        }
        System.out.println("Analisis Spider completo");

        //*********** ASCAN *******************

        System.out.println("Active scan : " + TARGET);

        //Probamos OPCIONES del Active Scan
          recurse="true";//Recursividad (boolean)
          String inScopeOnly="false";//se puede usar para restringir el escaneo a las URL que están en el alcance 
          String scanPolicyName=null;//permite especificar la política de exploración (si no se proporciona ninguna, usa la política de exploración predeterminada)
          String method=null;//
          String postData="true";//Si usa datos POST

          api.ascan.setOptionScanHeadersAllRequests(false);//Si se activa escanea las cabeceras de todas las peticiones, no solo las que envían parámetros.
          api.
          api.ascan.excludeFromScan("1234abc");//Expresion regular que indica los que se va ignorar en el escaneo

          resp = api.ascan.scan(TARGET, recurse, inScopeOnly, scanPolicyName, method, postData);

          // The scan now returns a scan id to support concurrent scanning
          scanid = ((ApiResponseElement) resp).getValue();
          // Poll the status until it completes
          while (true) {

              progress =
                      Integer.parseInt(
                              ((ApiResponseElement) api.ascan.status(scanid)).getValue());
              System.out.println("Active Scan progress : " + progress + "%");
              if (progress >= 100) {
                  break;
              }
              Thread.sleep(1000);
          }
          System.out.println("Active Scan complete");


        //GUARDO EL RESULTADO Conjunto
        //HTML
         System.out.println("Creando REPORT...");
         File archivo = new File("./REPORT.html");
         BufferedWriter bw = new BufferedWriter(new FileWriter(archivo));
         bw.write(new String(api.core.htmlreport()));
         bw.close();
         System.out.println("Resultado del SPIDER Y ASCAN guardado en REPORT.html");

         //JSON
         archivo = new File("./REPORT.json");
         bw = new BufferedWriter(new FileWriter(archivo));
         bw.write(new String(api.core.jsonreport()));
         bw.close();
         System.out.println("Resultado del SPIDER Y ASCAN guardado en REPORT.json");



    } catch (Exception e) {
        System.out.println("Exception : " + e.getMessage());
        e.printStackTrace();
    }
}

This code performs an active scan over a site with custom configuration. 此代码对具有自定义配置的站点执行主动扫描。 I have set several configurations for the Spider scan, but I could not the Active Input Vector Options for the active scan. 我已经为Spider扫描设置了几种配置,但无法为主动扫描设置“主动输入矢量选项”。 How could I do that? 我该怎么办?

For the record this was answered in a ZAP User Group thread: https://groups.google.com/forum/#!topic/zaproxy-users/x6lpQ92kjkY 为了记录,在ZAP用户组线程中回答了这个问题: https : //groups.google.com/forum/#!topic/ zaproxy-users/ x6lpQ92kjkY


The solution is not straight forward but here goes: 解决方案不是直接的,但是这里是:

If you look at the defaults (or current values) via the optionTargetParamsInjectable and optionTargetParamsEnabledRPC end points, you'll see two integer values such as: 11 and 39 respectively. 如果通过optionTargetParamsInjectableoptionTargetParamsEnabledRPC端点查看默认值(或当前值),则会看到两个整数值,例如:11和39。

Looking at https://github.com/zaproxy/zaproxy/blob/b48deb898066d2e8d23f567b58758daf3eed3be1/src/org/parosproxy/paros/core/scanner/ScannerParam.java#L105-L123 看着https://github.com/zaproxy/zaproxy/blob/b48deb898066d2e8d23f567b58758daf3eed3be1/src/org/parosproxy/paros/core/scanner/ScannerParam.java#L105-L123

We can make sense of this: 我们可以这样理解:
1+2+8 = 11 1 + 2 + 8 = 11
1+2+4+32 = 39 [Multipart (1), XML (2), JSON (4), and DWR (32) is 39.] 1 + 2 + 4 + 32 = 39 [多部分(1),XML(2),JSON(4)和DWR(32)为39。]

ZAP代码和主动扫描输入选项屏幕截图

So for the API endpoints: 因此,对于API端点:

  • setOptionTargetParamsEnabledRPC (Integer* ) setOptionTargetParamsEnabledRPC(Integer *)
  • setOptionTargetParamsInjectable (Integer* ) setOptionTargetParamsInjectable(Integer *)

Calculate the value and pass it to the API.... 计算值并将其传递给API。...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM