Search in sources :

Example 16 with HistoryReference

use of org.parosproxy.paros.model.HistoryReference in project zaproxy by zaproxy.

the class PopupMenuExportSelectedURLs method getOutputSet.

private SortedSet<String> getOutputSet(TreePath[] startingPoints) {
    JTree siteTree = extension.getView().getSiteTreePanel().getTreeSite();
    ArrayList<TreePath> startingPts = new ArrayList<TreePath>();
    if (ArrayUtils.isEmpty(startingPoints)) {
        startingPts.add(new TreePath(siteTree.getModel().getRoot()));
    } else {
        startingPts.addAll(Arrays.asList(startingPoints));
    }
    SortedSet<String> outputSet = new TreeSet<String>();
    for (TreePath aPath : startingPts) {
        Enumeration<?> en = (((SiteNode) aPath.getLastPathComponent()).preorderEnumeration());
        while (en.hasMoreElements()) {
            SiteNode node = (SiteNode) en.nextElement();
            if (node.isRoot()) {
                continue;
            }
            HistoryReference nodeHR = node.getHistoryReference();
            if (nodeHR != null && !HistoryReference.getTemporaryTypes().contains(nodeHR.getHistoryType())) {
                outputSet.add(nodeHR.getURI().toString());
            }
        }
    }
    return outputSet;
}
Also used : HistoryReference(org.parosproxy.paros.model.HistoryReference) JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) SiteNode(org.parosproxy.paros.model.SiteNode)

Example 17 with HistoryReference

use of org.parosproxy.paros.model.HistoryReference in project zaproxy by zaproxy.

the class SearchThread method search.

private void search() {
    Session session = Model.getSingleton().getSession();
    Pattern pattern = Pattern.compile(filter, Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);
    Matcher matcher = null;
    try {
        if (Type.Custom.equals(reqType)) {
            if (searchers != null && customSearcherName != null) {
                HttpSearcher searcher = searchers.get(customSearcherName);
                if (searcher != null) {
                    List<SearchResult> results;
                    if (pcc.hasMaximumMatches()) {
                        results = searcher.search(pattern, inverse, pcc.getMaximumMatches());
                    } else {
                        results = searcher.search(pattern, inverse);
                    }
                    for (SearchResult sr : results) {
                        searchListenner.addSearchResult(sr);
                    }
                }
            }
            return;
        }
        List<Integer> list = Model.getSingleton().getDb().getTableHistory().getHistoryIdsOfHistType(session.getSessionId(), HistoryReference.TYPE_PROXIED, HistoryReference.TYPE_ZAP_USER, HistoryReference.TYPE_SPIDER, HistoryReference.TYPE_SPIDER_AJAX);
        int last = list.size();
        int currentRecordId = 0;
        for (int index = 0; index < last; index++) {
            if (stopSearch) {
                break;
            }
            int historyId = list.get(index).intValue();
            try {
                currentRecordId = index;
                // Create the href to ensure the msg is set up correctly
                HistoryReference href = new HistoryReference(historyId);
                HttpMessage message = href.getHttpMessage();
                if (searchJustInScope && !session.isInScope(message.getRequestHeader().getURI().toString())) {
                    // Not in scope, so ignore
                    continue;
                }
                if (this.baseUrl != null && !message.getRequestHeader().getURI().toString().startsWith(baseUrl)) {
                    // doesnt start with the specified baseurl
                    continue;
                }
                if (Type.URL.equals(reqType)) {
                    // URL
                    String url = message.getRequestHeader().getURI().toString();
                    matcher = pattern.matcher(url);
                    if (inverse && !pcc.allMatchesProcessed()) {
                        if (!matcher.find()) {
                            notifyInverseMatchFound(currentRecordId, message, SearchMatch.Location.REQUEST_HEAD);
                        }
                    } else {
                        int urlStartPos = message.getRequestHeader().getPrimeHeader().indexOf(url);
                        while (matcher.find() && !pcc.allMatchesProcessed()) {
                            notifyMatchFound(currentRecordId, matcher.group(), message, SearchMatch.Location.REQUEST_HEAD, urlStartPos + matcher.start(), urlStartPos + matcher.end());
                            if (!searchAllOccurrences) {
                                break;
                            }
                        }
                    }
                }
                if (Type.Header.equals(reqType)) {
                    // Header
                    // Request header
                    matcher = pattern.matcher(message.getRequestHeader().toString());
                    if (inverse && !pcc.allMatchesProcessed()) {
                        if (!matcher.find()) {
                            notifyInverseMatchFound(currentRecordId, message, SearchMatch.Location.REQUEST_HEAD);
                        }
                    } else {
                        while (matcher.find() && !pcc.allMatchesProcessed()) {
                            notifyMatchFound(currentRecordId, matcher.group(), message, SearchMatch.Location.REQUEST_HEAD, matcher.start(), matcher.end());
                            if (!searchAllOccurrences) {
                                break;
                            }
                        }
                    }
                    // Response header
                    matcher = pattern.matcher(message.getResponseHeader().toString());
                    if (inverse && !pcc.allMatchesProcessed()) {
                        if (!matcher.find()) {
                            notifyInverseMatchFound(currentRecordId, message, SearchMatch.Location.RESPONSE_HEAD);
                        }
                    } else {
                        while (matcher.find() && !pcc.allMatchesProcessed()) {
                            notifyMatchFound(currentRecordId, matcher.group(), message, SearchMatch.Location.RESPONSE_HEAD, matcher.start(), matcher.end());
                            if (!searchAllOccurrences) {
                                break;
                            }
                        }
                    }
                }
                if (Type.Request.equals(reqType) || Type.All.equals(reqType)) {
                    if (inverse && !pcc.allMatchesProcessed()) {
                        // Check for no matches in either Request Header or Body 
                        if (!pattern.matcher(message.getRequestHeader().toString()).find() && !pattern.matcher(message.getRequestBody().toString()).find()) {
                            notifyInverseMatchFound(currentRecordId, message, SearchMatch.Location.REQUEST_HEAD);
                        }
                    } else {
                        // Request Header 
                        matcher = pattern.matcher(message.getRequestHeader().toString());
                        while (matcher.find() && !pcc.allMatchesProcessed()) {
                            notifyMatchFound(currentRecordId, matcher.group(), message, SearchMatch.Location.REQUEST_HEAD, matcher.start(), matcher.end());
                            if (!searchAllOccurrences) {
                                break;
                            }
                        }
                        // Request Body
                        matcher = pattern.matcher(message.getRequestBody().toString());
                        while (matcher.find() && !pcc.allMatchesProcessed()) {
                            notifyMatchFound(currentRecordId, matcher.group(), message, SearchMatch.Location.REQUEST_BODY, matcher.start(), matcher.end());
                            if (!searchAllOccurrences) {
                                break;
                            }
                        }
                    }
                }
                if (Type.Response.equals(reqType) || Type.All.equals(reqType)) {
                    if (inverse && !pcc.allMatchesProcessed()) {
                        // Check for no matches in either Response Header or Body 
                        if (!pattern.matcher(message.getResponseHeader().toString()).find() && !pattern.matcher(message.getResponseBody().toString()).find()) {
                            notifyInverseMatchFound(currentRecordId, message, SearchMatch.Location.RESPONSE_HEAD);
                        }
                    } else {
                        // Response header
                        matcher = pattern.matcher(message.getResponseHeader().toString());
                        while (matcher.find() && !pcc.allMatchesProcessed()) {
                            notifyMatchFound(currentRecordId, matcher.group(), message, SearchMatch.Location.RESPONSE_HEAD, matcher.start(), matcher.end());
                            if (!searchAllOccurrences) {
                                break;
                            }
                        }
                        // Response body
                        matcher = pattern.matcher(message.getResponseBody().toString());
                        while (matcher.find() && !pcc.allMatchesProcessed()) {
                            notifyMatchFound(currentRecordId, matcher.group(), message, SearchMatch.Location.RESPONSE_BODY, matcher.start(), matcher.end());
                            if (!searchAllOccurrences) {
                                break;
                            }
                        }
                    }
                }
            } catch (HttpMalformedHeaderException e1) {
                log.error(e1.getMessage(), e1);
            }
            if (pcc.hasPageEnded()) {
                break;
            }
        }
    } catch (DatabaseException e) {
        log.error(e.getMessage(), e);
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) HistoryReference(org.parosproxy.paros.model.HistoryReference) HttpMalformedHeaderException(org.parosproxy.paros.network.HttpMalformedHeaderException) HttpMessage(org.parosproxy.paros.network.HttpMessage) DatabaseException(org.parosproxy.paros.db.DatabaseException) Session(org.parosproxy.paros.model.Session)

Example 18 with HistoryReference

use of org.parosproxy.paros.model.HistoryReference in project zaproxy by zaproxy.

the class ExtensionHistory method purge.

public void purge(SiteMap map, SiteNode node) {
    SiteNode child = null;
    synchronized (map) {
        while (node.getChildCount() > 0) {
            try {
                child = (SiteNode) node.getChildAt(0);
                purge(map, child);
            } catch (Exception e) {
                logger.error(e.getMessage(), e);
            }
        }
        if (node.isRoot()) {
            return;
        }
        // delete reference in node
        removeFromHistoryList(node.getHistoryReference());
        ExtensionAlert extAlert = Control.getSingleton().getExtensionLoader().getExtension(ExtensionAlert.class);
        if (node.getHistoryReference() != null) {
            deleteAlertsFromExtensionAlert(extAlert, node.getHistoryReference());
            node.getHistoryReference().delete();
            map.removeHistoryReference(node.getHistoryReference().getHistoryId());
        }
        // delete past reference in node
        while (node.getPastHistoryReference().size() > 0) {
            HistoryReference ref = node.getPastHistoryReference().get(0);
            deleteAlertsFromExtensionAlert(extAlert, ref);
            removeFromHistoryList(ref);
            delete(ref);
            node.getPastHistoryReference().remove(0);
            map.removeHistoryReference(ref.getHistoryId());
        }
        map.removeNodeFromParent(node);
    }
}
Also used : HistoryReference(org.parosproxy.paros.model.HistoryReference) DatabaseException(org.parosproxy.paros.db.DatabaseException) ExtensionAlert(org.zaproxy.zap.extension.alert.ExtensionAlert) SiteNode(org.parosproxy.paros.model.SiteNode)

Example 19 with HistoryReference

use of org.parosproxy.paros.model.HistoryReference in project zaproxy by zaproxy.

the class PopupMenuHistoryReference method getSelectedHistoryReference.

private HistoryReference getSelectedHistoryReference() {
    HistoryReference ref = null;
    try {
        switch(lastInvoker) {
            case sites:
                SiteNode sNode = (SiteNode) treeInvoker.getLastSelectedPathComponent();
                ref = sNode.getHistoryReference();
                break;
            case ascan:
            case history:
            case bruteforce:
            case search:
            case fuzz:
                ref = hrefsTableInvoker.getSelectedHistoryReference();
                break;
            case alerts:
                AlertNode aNode = (AlertNode) treeInvoker.getLastSelectedPathComponent();
                if (aNode.getUserObject() != null) {
                    Alert alert = aNode.getUserObject();
                    ref = alert.getHistoryRef();
                }
                break;
            case hreftable:
                ref = hrefTableInvoker.getSelectedHistoryReference();
                break;
        }
    } catch (Exception e2) {
        log.error(e2.getMessage(), e2);
    }
    return ref;
}
Also used : HistoryReference(org.parosproxy.paros.model.HistoryReference) AlertNode(org.zaproxy.zap.extension.alert.AlertNode) Alert(org.parosproxy.paros.core.scanner.Alert) SiteNode(org.parosproxy.paros.model.SiteNode)

Example 20 with HistoryReference

use of org.parosproxy.paros.model.HistoryReference in project zaproxy by zaproxy.

the class PopupMenuHistoryReference method getSelectedHistoryReferences.

private List<HistoryReference> getSelectedHistoryReferences() {
    List<HistoryReference> refs = new ArrayList<>();
    TreePath[] treePaths = null;
    try {
        switch(lastInvoker) {
            case sites:
                treePaths = treeInvoker.getSelectionPaths();
                if (treePaths != null) {
                    for (TreePath path : treePaths) {
                        SiteNode node = (SiteNode) path.getLastPathComponent();
                        refs.add(node.getHistoryReference());
                    }
                }
                break;
            case ascan:
            case history:
            case bruteforce:
            case fuzz:
            case search:
                refs = hrefsTableInvoker.getSelectedHistoryReferences();
                break;
            case alerts:
                // Only support single items
                AlertNode aNode = (AlertNode) treeInvoker.getLastSelectedPathComponent();
                if (aNode.getUserObject() != null) {
                    Alert alert = aNode.getUserObject();
                    refs.add(alert.getHistoryRef());
                }
                break;
            case hreftable:
                refs = hrefTableInvoker.getSelectedHistoryReferences();
                break;
        }
    } catch (Exception e2) {
        log.error(e2.getMessage(), e2);
    }
    return refs;
}
Also used : HistoryReference(org.parosproxy.paros.model.HistoryReference) TreePath(javax.swing.tree.TreePath) ArrayList(java.util.ArrayList) AlertNode(org.zaproxy.zap.extension.alert.AlertNode) Alert(org.parosproxy.paros.core.scanner.Alert) SiteNode(org.parosproxy.paros.model.SiteNode)

Aggregations

HistoryReference (org.parosproxy.paros.model.HistoryReference)36 DatabaseException (org.parosproxy.paros.db.DatabaseException)11 SiteNode (org.parosproxy.paros.model.SiteNode)10 HttpMalformedHeaderException (org.parosproxy.paros.network.HttpMalformedHeaderException)7 ArrayList (java.util.ArrayList)6 Alert (org.parosproxy.paros.core.scanner.Alert)6 HttpMessage (org.parosproxy.paros.network.HttpMessage)6 JTree (javax.swing.JTree)5 ExtensionHistory (org.parosproxy.paros.extension.history.ExtensionHistory)5 TreePath (javax.swing.tree.TreePath)4 IOException (java.io.IOException)3 TreeSet (java.util.TreeSet)3 Session (org.parosproxy.paros.model.Session)3 SiteMap (org.parosproxy.paros.model.SiteMap)3 Component (java.awt.Component)2 MalformedURLException (java.net.MalformedURLException)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 URIException (org.apache.commons.httpclient.URIException)2 Event (org.zaproxy.zap.eventBus.Event)2 AlertNode (org.zaproxy.zap.extension.alert.AlertNode)2