Search in sources :

Example 1 with TableAlert

use of org.parosproxy.paros.db.TableAlert in project zaproxy by zaproxy.

the class CoreAPI method processAlerts.

private void processAlerts(String baseUrl, int start, int count, Processor<Alert> processor) throws ApiException {
    List<Alert> alerts = new ArrayList<>();
    try {
        TableAlert tableAlert = Model.getSingleton().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();
        PaginationConstraintsChecker pcc = new PaginationConstraintsChecker(start, count);
        for (int i = 0; i < v.size(); i++) {
            int alertId = v.get(i).intValue();
            RecordAlert recAlert = tableAlert.read(alertId);
            Alert alert = new Alert(recAlert);
            if (alert.getConfidence() != Alert.CONFIDENCE_FALSE_POSITIVE && !alerts.contains(alert)) {
                if (baseUrl != null && !alert.getUri().startsWith(baseUrl)) {
                    // Not subordinate to the specified URL
                    continue;
                }
                pcc.recordProcessed();
                alerts.add(alert);
                if (!pcc.hasPageStarted()) {
                    continue;
                }
                processor.process(alert);
                if (pcc.hasPageEnded()) {
                    break;
                }
            }
        }
    } catch (DatabaseException e) {
        logger.error(e.getMessage(), e);
        throw new ApiException(ApiException.Type.INTERNAL_ERROR);
    }
}
Also used : TableAlert(org.parosproxy.paros.db.TableAlert) ArrayList(java.util.ArrayList) Alert(org.parosproxy.paros.core.scanner.Alert) RecordAlert(org.parosproxy.paros.db.RecordAlert) ExtensionAlert(org.zaproxy.zap.extension.alert.ExtensionAlert) TableAlert(org.parosproxy.paros.db.TableAlert) DatabaseException(org.parosproxy.paros.db.DatabaseException) RecordAlert(org.parosproxy.paros.db.RecordAlert)

Example 2 with TableAlert

use of org.parosproxy.paros.db.TableAlert in project zaproxy by zaproxy.

the class AlertAPI method processAlerts.

private void processAlerts(String baseUrl, int start, int count, int riskId, Processor<Alert> processor) throws ApiException {
    List<Alert> alerts = new ArrayList<>();
    try {
        TableAlert tableAlert = Model.getSingleton().getDb().getTableAlert();
        TableAlertTag tableAlertTag = Model.getSingleton().getDb().getTableAlertTag();
        // TODO this doesn't work, but should be used when its fixed :/
        // Vector<Integer> v =
        // tableAlert.getAlertListBySession(Model.getSingleton().getSession().getSessionId());
        Vector<Integer> v = tableAlert.getAlertList();
        PaginationConstraintsChecker pcc = new PaginationConstraintsChecker(start, count);
        for (int alertId : v) {
            RecordAlert recAlert = tableAlert.read(alertId);
            Alert alert = new Alert(recAlert);
            if (alert.getConfidence() != Alert.CONFIDENCE_FALSE_POSITIVE && !alerts.contains(alert)) {
                if (baseUrl != null && !alert.getUri().startsWith(baseUrl)) {
                    // Not subordinate to the specified URL
                    continue;
                }
                if (riskId != NO_RISK_ID && alert.getRisk() != riskId) {
                    continue;
                }
                pcc.recordProcessed();
                alerts.add(alert);
                if (!pcc.hasPageStarted()) {
                    continue;
                }
                alert.setTags(tableAlertTag.getTagsByAlertId(alertId));
                processor.process(alert);
                if (pcc.hasPageEnded()) {
                    break;
                }
            }
        }
    } catch (DatabaseException e) {
        logger.error(e.getMessage(), e);
        throw new ApiException(ApiException.Type.INTERNAL_ERROR);
    }
}
Also used : TableAlert(org.parosproxy.paros.db.TableAlert) TableAlertTag(org.zaproxy.zap.db.TableAlertTag) ArrayList(java.util.ArrayList) Alert(org.parosproxy.paros.core.scanner.Alert) RecordAlert(org.parosproxy.paros.db.RecordAlert) TableAlert(org.parosproxy.paros.db.TableAlert) DatabaseException(org.parosproxy.paros.db.DatabaseException) RecordAlert(org.parosproxy.paros.db.RecordAlert) ApiException(org.zaproxy.zap.extension.api.ApiException)

Example 3 with TableAlert

use of org.parosproxy.paros.db.TableAlert in project zaproxy by zaproxy.

the class ExtensionAlert method getAllAlerts.

public List<Alert> getAllAlerts() {
    List<Alert> allAlerts = new ArrayList<>();
    TableAlert tableAlert = getModel().getDb().getTableAlert();
    TableAlertTag tableAlertTag = getModel().getDb().getTableAlertTag();
    Vector<Integer> v;
    try {
        // TODO this doesn't work, but should be used when its fixed :/
        // v =
        // tableAlert.getAlertListBySession(Model.getSingleton().getSession().getSessionId());
        v = tableAlert.getAlertList();
        for (int i = 0; i < v.size(); i++) {
            int alertId = v.get(i);
            RecordAlert recAlert = tableAlert.read(alertId);
            Alert alert = new Alert(recAlert);
            if (alert.getHistoryRef() != null) {
                // Only use the alert if it has a history reference.
                if (!allAlerts.contains(alert)) {
                    alert.setTags(tableAlertTag.getTagsByAlertId(alertId));
                    allAlerts.add(alert);
                }
            }
        }
    } catch (DatabaseException e) {
        logger.error(e.getMessage(), e);
    }
    return allAlerts;
}
Also used : TableAlert(org.parosproxy.paros.db.TableAlert) TableAlertTag(org.zaproxy.zap.db.TableAlertTag) ArrayList(java.util.ArrayList) Alert(org.parosproxy.paros.core.scanner.Alert) RecordAlert(org.parosproxy.paros.db.RecordAlert) TableAlert(org.parosproxy.paros.db.TableAlert) DatabaseException(org.parosproxy.paros.db.DatabaseException) RecordAlert(org.parosproxy.paros.db.RecordAlert)

Example 4 with TableAlert

use of org.parosproxy.paros.db.TableAlert in project zaproxy by zaproxy.

the class ExtensionAlert method writeAlertToDB.

private void writeAlertToDB(Alert alert, HistoryReference ref) throws HttpMalformedHeaderException, DatabaseException {
    TableAlert tableAlert = getModel().getDb().getTableAlert();
    int scanId = 0;
    if (recordScan != null) {
        scanId = recordScan.getScanId();
    }
    RecordAlert recordAlert = tableAlert.write(scanId, alert.getPluginId(), alert.getName(), alert.getRisk(), alert.getConfidence(), alert.getDescription(), alert.getUri(), alert.getParam(), alert.getAttack(), alert.getOtherInfo(), alert.getSolution(), alert.getReference(), alert.getEvidence(), alert.getCweId(), alert.getWascId(), ref.getHistoryId(), alert.getSourceHistoryId(), alert.getSource().getId(), alert.getAlertRef());
    int alertId = recordAlert.getAlertId();
    alert.setAlertId(alertId);
    TableAlertTag tableAlertTag = getModel().getDb().getTableAlertTag();
    for (Map.Entry<String, String> e : alert.getTags().entrySet()) {
        tableAlertTag.insertOrUpdate(alertId, e.getKey(), e.getValue());
    }
}
Also used : TableAlert(org.parosproxy.paros.db.TableAlert) TableAlertTag(org.zaproxy.zap.db.TableAlertTag) Map(java.util.Map) HashMap(java.util.HashMap) SiteMap(org.parosproxy.paros.model.SiteMap) RecordAlert(org.parosproxy.paros.db.RecordAlert)

Example 5 with TableAlert

use of org.parosproxy.paros.db.TableAlert in project zaproxy by zaproxy.

the class ExtensionAlert method updateAlertInDB.

private void updateAlertInDB(Alert alert) throws HttpMalformedHeaderException, DatabaseException {
    TableAlert tableAlert = getModel().getDb().getTableAlert();
    tableAlert.update(alert.getAlertId(), alert.getName(), alert.getRisk(), alert.getConfidence(), alert.getDescription(), alert.getUri(), alert.getParam(), alert.getAttack(), alert.getOtherInfo(), alert.getSolution(), alert.getReference(), alert.getEvidence(), alert.getCweId(), alert.getWascId(), alert.getSourceHistoryId());
    int alertId = alert.getAlertId();
    TableAlertTag tableAlertTag = getModel().getDb().getTableAlertTag();
    Map<String, String> existingTags = tableAlertTag.getTagsByAlertId(alertId);
    Map<String, String> newTags = alert.getTags();
    for (Map.Entry<String, String> e : existingTags.entrySet()) {
        if (!newTags.containsKey(e.getKey())) {
            tableAlertTag.delete(alertId, e.getKey());
        }
    }
    for (Map.Entry<String, String> e : newTags.entrySet()) {
        tableAlertTag.insertOrUpdate(alertId, e.getKey(), e.getValue());
    }
}
Also used : TableAlert(org.parosproxy.paros.db.TableAlert) TableAlertTag(org.zaproxy.zap.db.TableAlertTag) Map(java.util.Map) HashMap(java.util.HashMap) SiteMap(org.parosproxy.paros.model.SiteMap)

Aggregations

TableAlert (org.parosproxy.paros.db.TableAlert)8 RecordAlert (org.parosproxy.paros.db.RecordAlert)6 TableAlertTag (org.zaproxy.zap.db.TableAlertTag)6 Alert (org.parosproxy.paros.core.scanner.Alert)5 DatabaseException (org.parosproxy.paros.db.DatabaseException)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 SiteMap (org.parosproxy.paros.model.SiteMap)3 ApiException (org.zaproxy.zap.extension.api.ApiException)2 Enumeration (java.util.Enumeration)1 JSONObject (net.sf.json.JSONObject)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 RecordHistory (org.parosproxy.paros.db.RecordHistory)1 TableHistory (org.parosproxy.paros.db.TableHistory)1 ExtensionHistory (org.parosproxy.paros.extension.history.ExtensionHistory)1 HistoryReference (org.parosproxy.paros.model.HistoryReference)1 HttpMessage (org.parosproxy.paros.network.HttpMessage)1 ExtensionAlert (org.zaproxy.zap.extension.alert.ExtensionAlert)1 ApiResponse (org.zaproxy.zap.extension.api.ApiResponse)1