Search in sources :

Example 6 with SiteMap

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

the class PopupExcludeFromProxyMenu method performAction.

@Override
public void performAction(SiteNode sn) {
    try {
        Session session = Model.getSingleton().getSession();
        session.getExcludeFromProxyRegexs().add(new StructuralSiteNode(sn).getRegexPattern());
        SiteMap map = (SiteMap) View.getSingleton().getSiteTreePanel().getTreeSite().getModel();
        ExtensionHistory extHistory = Control.getSingleton().getExtensionLoader().getExtension(ExtensionHistory.class);
        if (extHistory != null) {
            extHistory.purge(map, sn);
        }
    } catch (DatabaseException e) {
    // Ignore
    }
}
Also used : StructuralSiteNode(org.zaproxy.zap.model.StructuralSiteNode) SiteMap(org.parosproxy.paros.model.SiteMap) ExtensionHistory(org.parosproxy.paros.extension.history.ExtensionHistory) DatabaseException(org.parosproxy.paros.db.DatabaseException) Session(org.parosproxy.paros.model.Session)

Example 7 with SiteMap

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

the class Context method checkNode.

private boolean checkNode(SiteNode sn) {
    // Loop backwards through the children TODO change for lowmem!
    // log.debug("checkNode " + sn.getHierarchicNodeName());		// Useful for debugging
    int origChildren = sn.getChildCount();
    int movedChildren = 0;
    for (SiteNode childNode : getChildren(sn)) {
        if (checkNode(childNode)) {
            movedChildren++;
        }
    }
    if (this.isInContext(sn)) {
        SiteMap sitesTree = this.session.getSiteTree();
        HistoryReference href = sn.getHistoryReference();
        try {
            SiteNode sn2;
            if (HttpRequestHeader.POST.equals(href.getMethod())) {
                // Have to go to the db as POST data can be used in the name
                sn2 = sitesTree.findNode(href.getHttpMessage());
            } else {
                // This is better as it doesnt require a db read
                sn2 = sitesTree.findNode(href.getURI());
            }
            if (sn2 == null || !sn.getHierarchicNodeName().equals(sn2.getHierarchicNodeName())) {
                if (!sn.isDataDriven()) {
                    moveNode(sitesTree, sn);
                    return true;
                }
            }
            if (movedChildren > 0 && movedChildren == origChildren && sn.getChildCount() == 0) {
                if (href.getHistoryType() == HistoryReference.TYPE_TEMPORARY) {
                    // Remove temp old node, no need to add new one in - 
                    // that will happen when moving child nodes (if required)
                    deleteNode(sitesTree, sn);
                    return true;
                }
            }
        // log.debug("Didnt need to move " + sn.getHierarchicNodeName());	// Useful for debugging
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
    return false;
}
Also used : HistoryReference(org.parosproxy.paros.model.HistoryReference) SiteMap(org.parosproxy.paros.model.SiteMap) PatternSyntaxException(java.util.regex.PatternSyntaxException) SiteNode(org.parosproxy.paros.model.SiteNode)

Example 8 with SiteMap

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

the class ScanPanel method getSiteNode.

protected SiteNode getSiteNode(String siteName) {
    SiteMap siteTree = this.getExtension().getModel().getSession().getSiteTree();
    SiteNode rootNode = (SiteNode) siteTree.getRoot();
    @SuppressWarnings("unchecked") Enumeration<SiteNode> en = rootNode.children();
    while (en.hasMoreElements()) {
        SiteNode sn = en.nextElement();
        String nodeName = sn.getNodeName();
        if (nodeName.toLowerCase().startsWith("https:") && !hasPort(nodeName)) {
            nodeName += ":443";
        }
        if (nodeName.toLowerCase().startsWith("http:") && !hasPort(nodeName)) {
            nodeName += ":80";
        }
        if (nodeName.indexOf("//") >= 0) {
            nodeName = nodeName.substring(nodeName.indexOf("//") + 2);
        }
        if (siteName.equals(nodeName)) {
            return sn;
        }
    }
    return null;
}
Also used : SiteMap(org.parosproxy.paros.model.SiteMap) SiteNode(org.parosproxy.paros.model.SiteNode)

Example 9 with SiteMap

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

the class ExtensionAlert method refreshAlert.

private void refreshAlert(Session session) throws DatabaseException {
    if (Constant.isLowMemoryOptionSet()) {
        return;
    }
    SiteMap siteTree = this.getModel().getSession().getSiteTree();
    TableAlert tableAlert = getModel().getDb().getTableAlert();
    // TODO this doesnt work, but should be used when its fixed :/
    //Vector<Integer> v = tableAlert.getAlertListBySession(Model.getSingleton().getSession().getSessionId());
    Vector<Integer> v = tableAlert.getAlertList();
    final ExtensionHistory extensionHistory = (ExtensionHistory) Control.getSingleton().getExtensionLoader().getExtension(ExtensionHistory.NAME);
    for (int i = 0; i < v.size(); i++) {
        int alertId = v.get(i).intValue();
        RecordAlert recAlert = tableAlert.read(alertId);
        int historyId = recAlert.getHistoryId();
        HistoryReference historyReference = null;
        if (extensionHistory != null) {
            historyReference = extensionHistory.getHistoryReference(historyId);
        }
        if (historyReference == null) {
            historyReference = this.hrefs.get(Integer.valueOf(historyId));
        }
        Alert alert;
        if (historyReference != null) {
            alert = new Alert(recAlert, historyReference);
        } else {
            alert = new Alert(recAlert);
        }
        historyReference = alert.getHistoryRef();
        if (historyReference != null) {
            // The ref can be null if hrefs are purged
            addAlertToTree(alert);
            Integer key = Integer.valueOf(historyId);
            if (!hrefs.containsKey(key)) {
                this.hrefs.put(key, alert.getHistoryRef());
            }
        }
    }
    siteTree.nodeStructureChanged((SiteNode) siteTree.getRoot());
}
Also used : HistoryReference(org.parosproxy.paros.model.HistoryReference) TableAlert(org.parosproxy.paros.db.TableAlert) SiteMap(org.parosproxy.paros.model.SiteMap) ExtensionHistory(org.parosproxy.paros.extension.history.ExtensionHistory) Alert(org.parosproxy.paros.core.scanner.Alert) RecordAlert(org.parosproxy.paros.db.RecordAlert) TableAlert(org.parosproxy.paros.db.TableAlert) RecordAlert(org.parosproxy.paros.db.RecordAlert)

Example 10 with SiteMap

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

the class PopupMenuPurgeHistory method purgeHistory.

private void purgeHistory(HistoryReference ref) {
    if (ref == null) {
        return;
    }
    extension.removeFromHistoryList(ref);
    ExtensionAlert extAlert = (ExtensionAlert) Control.getSingleton().getExtensionLoader().getExtension(ExtensionAlert.NAME);
    if (extAlert != null) {
        extAlert.deleteHistoryReferenceAlerts(ref);
    }
    extension.delete(ref);
    SiteNode node = ref.getSiteNode();
    if (node == null) {
        return;
    }
    SiteMap map = Model.getSingleton().getSession().getSiteTree();
    if (node.getHistoryReference() == ref) {
        // same active Node
        extension.purge(map, node);
    } else {
        node.getPastHistoryReference().remove(ref);
        map.removeHistoryReference(ref.getHistoryId());
    }
}
Also used : SiteMap(org.parosproxy.paros.model.SiteMap) ExtensionAlert(org.zaproxy.zap.extension.alert.ExtensionAlert) SiteNode(org.parosproxy.paros.model.SiteNode)

Aggregations

SiteMap (org.parosproxy.paros.model.SiteMap)10 SiteNode (org.parosproxy.paros.model.SiteNode)7 DatabaseException (org.parosproxy.paros.db.DatabaseException)4 HistoryReference (org.parosproxy.paros.model.HistoryReference)3 PatternSyntaxException (java.util.regex.PatternSyntaxException)2 Alert (org.parosproxy.paros.core.scanner.Alert)2 RecordAlert (org.parosproxy.paros.db.RecordAlert)2 TableAlert (org.parosproxy.paros.db.TableAlert)2 ExtensionHistory (org.parosproxy.paros.extension.history.ExtensionHistory)2 Session (org.parosproxy.paros.model.Session)2 ExtensionAlert (org.zaproxy.zap.extension.alert.ExtensionAlert)2 File (java.io.File)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)1 JSONException (net.sf.json.JSONException)1 URI (org.apache.commons.httpclient.URI)1