Search in sources :

Example 26 with HistoryReference

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

the class ExtensionAlert method alertFound.

public void alertFound(Alert alert, HistoryReference ref) {
    try {
        logger.debug("alertFound " + alert.getName() + " " + alert.getUri());
        if (ref == null) {
            ref = alert.getHistoryRef();
        }
        if (ref == null) {
            ref = new HistoryReference(getModel().getSession(), HistoryReference.TYPE_SCANNER, alert.getMessage());
            alert.setHistoryRef(ref);
        }
        if (alert.getSource() == Alert.Source.UNKNOWN) {
            alert.setSource(Alert.Source.TOOL);
        }
        alert.setSourceHistoryId(ref.getHistoryId());
        hrefs.put(Integer.valueOf(ref.getHistoryId()), ref);
        this.applyOverrides(alert);
        writeAlertToDB(alert, ref);
        try {
            if (getView() == null || EventQueue.isDispatchThread()) {
                SessionStructure.addPath(Model.getSingleton().getSession(), ref, alert.getMessage());
            } else {
                final HistoryReference fRef = ref;
                final HttpMessage fMsg = alert.getMessage();
                EventQueue.invokeAndWait(new Runnable() {

                    @Override
                    public void run() {
                        SessionStructure.addPath(Model.getSingleton().getSession(), fRef, fMsg);
                    }
                });
            }
            ref.addAlert(alert);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
        }
        addAlertToTree(alert);
        // Clear the message so that it can be GC'ed
        alert.setMessage(null);
        publishAlertEvent(alert, AlertEventPublisher.ALERT_ADDED_EVENT);
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
    }
}
Also used : HistoryReference(org.parosproxy.paros.model.HistoryReference) HttpMessage(org.parosproxy.paros.network.HttpMessage) HttpMalformedHeaderException(org.parosproxy.paros.network.HttpMalformedHeaderException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) DatabaseException(org.parosproxy.paros.db.DatabaseException)

Example 27 with HistoryReference

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

the class SessionStructure method getTempHttpMessage.

private static HttpMessage getTempHttpMessage(Session session, String url, HttpMessage base) {
    try {
        HttpMessage newMsg = base.cloneRequest();
        URI uri = new URI(url, false);
        newMsg.getRequestHeader().setURI(uri);
        newMsg.getRequestHeader().setMethod(HttpRequestHeader.GET);
        newMsg.getRequestBody().setBody("");
        newMsg.getRequestHeader().setHeader(HttpHeader.CONTENT_TYPE, null);
        newMsg.getRequestHeader().setHeader(HttpHeader.CONTENT_LENGTH, null);
        HistoryReference historyRef = new HistoryReference(session, HistoryReference.TYPE_TEMPORARY, newMsg);
        newMsg.setHistoryRef(historyRef);
        return newMsg;
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    return null;
}
Also used : HistoryReference(org.parosproxy.paros.model.HistoryReference) HttpMessage(org.parosproxy.paros.network.HttpMessage) URI(org.apache.commons.httpclient.URI) DatabaseException(org.parosproxy.paros.db.DatabaseException) URIException(org.apache.commons.httpclient.URIException)

Example 28 with HistoryReference

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

the class AuthenticationHelper method addAuthMessageToHistory.

public static void addAuthMessageToHistory(HttpMessage msg) {
    // Add message to history
    try {
        final HistoryReference ref = new HistoryReference(Model.getSingleton().getSession(), HistoryReference.TYPE_AUTHENTICATION, msg);
        ref.addTag(HISTORY_TAG_AUTHENTICATION);
        if (View.isInitialised()) {
            final ExtensionHistory extHistory = Control.getSingleton().getExtensionLoader().getExtension(ExtensionHistory.class);
            if (extHistory != null) {
                EventQueue.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        extHistory.addHistory(ref);
                    }
                });
            }
        }
    } catch (Exception ex) {
        log.error("Cannot add authentication message to History tab.", ex);
    }
}
Also used : HistoryReference(org.parosproxy.paros.model.HistoryReference) ExtensionHistory(org.parosproxy.paros.extension.history.ExtensionHistory) IOException(java.io.IOException) URIException(org.apache.commons.httpclient.URIException)

Example 29 with HistoryReference

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

the class SearchResultsTable method getSelectedHistoryReferences.

@Override
public List<HistoryReference> getSelectedHistoryReferences() {
    final int[] selectedRows = getSelectedRows();
    if (selectedRows.length == 0) {
        return Collections.emptyList();
    }
    ArrayList<HistoryReference> uniqueHistoryReferences = new ArrayList<>(selectedRows.length);
    SortedSet<Integer> historyReferenceIdsAdded = new TreeSet<>();
    for (int selectedRow : selectedRows) {
        HistoryReference historyReference = getHistoryReferenceAtViewRow(selectedRow);
        if (historyReference != null) {
            Integer id = Integer.valueOf(historyReference.getHistoryId());
            if (!historyReferenceIdsAdded.contains(id)) {
                historyReferenceIdsAdded.add(id);
                uniqueHistoryReferences.add(historyReference);
            }
        }
    }
    uniqueHistoryReferences.trimToSize();
    return uniqueHistoryReferences;
}
Also used : HistoryReference(org.parosproxy.paros.model.HistoryReference) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList)

Example 30 with HistoryReference

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

the class SearchResultsTableModel method createSearchResultTableEntry.

private static SearchResultTableEntry createSearchResultTableEntry(SearchResult sr, SearchResultTableEntry previousResult) {
    HistoryReference hRef = sr.getMessage().getHistoryRef();
    Integer historyId = null;
    String uri = null;
    String stringFound = null;
    if (previousResult != null) {
        Integer previousId = previousResult.getHistoryId();
        if (previousId.intValue() == hRef.getHistoryId()) {
            historyId = previousId;
        }
        if (previousResult.getStringFound().equals(sr.getStringFound())) {
            stringFound = previousResult.getStringFound();
        }
        uri = sr.getMessage().getRequestHeader().getURI().toString();
        if (previousResult.getUri().equals(uri)) {
            uri = previousResult.getUri();
        }
    }
    if (historyId == null) {
        historyId = Integer.valueOf(hRef.getHistoryId());
    }
    if (stringFound == null) {
        stringFound = sr.getStringFound();
    }
    if (uri == null) {
        uri = sr.getMessage().getRequestHeader().getURI().toString();
    }
    return new SearchResultTableEntry(hRef, historyId, hRef.getMethod(), uri, stringFound, sr);
}
Also used : HistoryReference(org.parosproxy.paros.model.HistoryReference)

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