Search in sources :

Example 6 with SpiderParser

use of org.zaproxy.zap.spider.parser.SpiderParser in project zaproxy by zaproxy.

the class SpiderScanController method startScan.

@Override
public int startScan(String name, Target target, User user, Object[] contextSpecificObjects) {
    spiderScansLock.lock();
    try {
        int id = this.scanIdCounter++;
        SpiderParam spiderParams = extension.getSpiderParam();
        List<SpiderParser> customSpiderParsers = new ArrayList<SpiderParser>();
        List<FetchFilter> customFetchFilters = new ArrayList<FetchFilter>();
        List<ParseFilter> customParseFilters = new ArrayList<ParseFilter>();
        URI startUri = null;
        if (contextSpecificObjects != null) {
            for (Object obj : contextSpecificObjects) {
                if (obj instanceof SpiderParam) {
                    log.debug("Setting custom spider params");
                    spiderParams = (SpiderParam) obj;
                } else if (obj instanceof SpiderParser) {
                    customSpiderParsers.add((SpiderParser) obj);
                } else if (obj instanceof FetchFilter) {
                    customFetchFilters.add((FetchFilter) obj);
                } else if (obj instanceof ParseFilter) {
                    customParseFilters.add((ParseFilter) obj);
                } else if (obj instanceof URI) {
                    startUri = (URI) obj;
                } else {
                    log.error("Unexpected contextSpecificObject: " + obj.getClass().getCanonicalName());
                }
            }
        }
        if (spiderParams.getMaxChildren() > 0) {
            // Add the filters to filter on maximum number of children
            MaxChildrenFetchFilter maxChildrenFetchFilter = new MaxChildrenFetchFilter();
            maxChildrenFetchFilter.setMaxChildren(spiderParams.getMaxChildren());
            maxChildrenFetchFilter.setModel(extension.getModel());
            MaxChildrenParseFilter maxChildrenParseFilter = new MaxChildrenParseFilter();
            maxChildrenParseFilter.setMaxChildren(spiderParams.getMaxChildren());
            maxChildrenParseFilter.setModel(extension.getModel());
            customFetchFilters.add(maxChildrenFetchFilter);
            customParseFilters.add(maxChildrenParseFilter);
        }
        SpiderScan scan = new SpiderScan(extension, spiderParams, target, startUri, user, id, name);
        scan.setCustomSpiderParsers(customSpiderParsers);
        scan.setCustomFetchFilters(customFetchFilters);
        scan.setCustomParseFilters(customParseFilters);
        this.spiderScanMap.put(id, scan);
        this.spiderScanList.add(scan);
        scan.start();
        return id;
    } finally {
        spiderScansLock.unlock();
    }
}
Also used : MaxChildrenParseFilter(org.zaproxy.zap.spider.filters.MaxChildrenParseFilter) ParseFilter(org.zaproxy.zap.spider.filters.ParseFilter) MaxChildrenParseFilter(org.zaproxy.zap.spider.filters.MaxChildrenParseFilter) MaxChildrenFetchFilter(org.zaproxy.zap.spider.filters.MaxChildrenFetchFilter) ArrayList(java.util.ArrayList) SpiderParam(org.zaproxy.zap.spider.SpiderParam) SpiderParser(org.zaproxy.zap.spider.parser.SpiderParser) URI(org.apache.commons.httpclient.URI) FetchFilter(org.zaproxy.zap.spider.filters.FetchFilter) MaxChildrenFetchFilter(org.zaproxy.zap.spider.filters.MaxChildrenFetchFilter)

Aggregations

SpiderParser (org.zaproxy.zap.spider.parser.SpiderParser)6 ArrayList (java.util.ArrayList)2 FetchFilter (org.zaproxy.zap.spider.filters.FetchFilter)2 ParseFilter (org.zaproxy.zap.spider.filters.ParseFilter)2 Source (net.htmlparser.jericho.Source)1 URI (org.apache.commons.httpclient.URI)1 URIException (org.apache.commons.httpclient.URIException)1 Spider (org.zaproxy.zap.spider.Spider)1 SpiderListener (org.zaproxy.zap.spider.SpiderListener)1 SpiderParam (org.zaproxy.zap.spider.SpiderParam)1 MaxChildrenFetchFilter (org.zaproxy.zap.spider.filters.MaxChildrenFetchFilter)1 MaxChildrenParseFilter (org.zaproxy.zap.spider.filters.MaxChildrenParseFilter)1 SpiderGitParser (org.zaproxy.zap.spider.parser.SpiderGitParser)1 SpiderHtmlFormParser (org.zaproxy.zap.spider.parser.SpiderHtmlFormParser)1 SpiderHtmlParser (org.zaproxy.zap.spider.parser.SpiderHtmlParser)1 SpiderODataAtomParser (org.zaproxy.zap.spider.parser.SpiderODataAtomParser)1 SpiderRedirectParser (org.zaproxy.zap.spider.parser.SpiderRedirectParser)1 SpiderRobotstxtParser (org.zaproxy.zap.spider.parser.SpiderRobotstxtParser)1 SpiderSVNEntriesParser (org.zaproxy.zap.spider.parser.SpiderSVNEntriesParser)1 SpiderSitemapXMLParser (org.zaproxy.zap.spider.parser.SpiderSitemapXMLParser)1