Search in sources :

Example 31 with Session

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

the class Control method runCommandLineNewSession.

public void runCommandLineNewSession(String fileName) throws Exception {
    log.debug("runCommandLineNewSession " + fileName);
    getExtensionLoader().sessionAboutToChangeAllPlugin(null);
    model.createAndOpenUntitledDb();
    final Session session = createNewSession();
    model.saveSession(fileName);
    if (hasView()) {
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                view.getSiteTreePanel().getTreeSite().setModel(session.getSiteTree());
                // refresh display
                view.getOutputPanel().clear();
            }
        });
    }
    log.info("New session file created: " + Paths.get(fileName).toRealPath());
    control.getExtensionLoader().databaseOpen(model.getDb());
    control.getExtensionLoader().sessionChangedAllPlugin(session);
}
Also used : Session(org.parosproxy.paros.model.Session)

Example 32 with Session

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

the class MenuFileControl method saveAsSession.

public void saveAsSession() {
    if (!informStopActiveActions()) {
        return;
    }
    Session session = model.getSession();
    JFileChooser chooser = new SessionFileChooser(model.getOptionsParam().getUserDirectory(), session);
    // ZAP: set session name as file name proposal
    File fileproposal = new File(session.getSessionName());
    if (session.getFileName() != null && session.getFileName().trim().length() > 0) {
        // if there is already a file name, use it
        fileproposal = new File(session.getFileName());
    }
    chooser.setSelectedFile(fileproposal);
    File file = null;
    int rc = chooser.showSaveDialog(view.getMainFrame());
    if (rc == JFileChooser.APPROVE_OPTION) {
        file = chooser.getSelectedFile();
        if (file == null) {
            return;
        }
        String fileName = createSessionFileName(file);
        try {
            waitMessageDialog = view.getWaitMessageDialog(Constant.messages.getString(// ZAP: i18n
            "menu.file.savingSession"));
            control.saveSession(fileName, this);
            log.info("save as session file " + session.getFileName());
            waitMessageDialog.setVisible(true);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) File(java.io.File) IllegalContextNameException(org.zaproxy.zap.model.IllegalContextNameException) DatabaseException(org.parosproxy.paros.db.DatabaseException) Session(org.parosproxy.paros.model.Session) RecordSession(org.parosproxy.paros.db.RecordSession)

Example 33 with Session

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

the class MenuFileControl method saveSnapshot.

public void saveSnapshot() {
    String activeActions = wrapEntriesInLiTags(control.getExtensionLoader().getActiveActions());
    if (!activeActions.isEmpty()) {
        view.showMessageDialog(Constant.messages.getString("menu.file.snapshot.activeactions", activeActions));
        return;
    }
    Session session = model.getSession();
    JFileChooser chooser = new SessionFileChooser(model.getOptionsParam().getUserDirectory(), session);
    // ZAP: set session name as file name proposal
    File fileproposal = new File(session.getSessionName());
    if (session.getFileName() != null && session.getFileName().trim().length() > 0) {
        String proposedFileName;
        // if there is already a file name, use it and add a timestamp
        proposedFileName = StringUtils.removeEnd(session.getFileName(), ".session");
        proposedFileName += "-" + dateFormat.format(new Date()) + ".session";
        fileproposal = new File(proposedFileName);
    }
    chooser.setSelectedFile(fileproposal);
    File file = null;
    int rc = chooser.showSaveDialog(view.getMainFrame());
    if (rc == JFileChooser.APPROVE_OPTION) {
        file = chooser.getSelectedFile();
        if (file == null) {
            return;
        }
        String fileName = createSessionFileName(file);
        try {
            waitMessageDialog = view.getWaitMessageDialog(Constant.messages.getString(// ZAP: i18n
            "menu.file.savingSnapshot"));
            control.snapshotSession(fileName, this);
            log.info("Snapshotting: " + session.getFileName() + " as " + fileName);
            waitMessageDialog.setVisible(true);
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
}
Also used : JFileChooser(javax.swing.JFileChooser) File(java.io.File) Date(java.util.Date) IllegalContextNameException(org.zaproxy.zap.model.IllegalContextNameException) DatabaseException(org.parosproxy.paros.db.DatabaseException) Session(org.parosproxy.paros.model.Session) RecordSession(org.parosproxy.paros.db.RecordSession)

Example 34 with Session

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

the class CustomScanDialog method targetSelected.

@Override
public void targetSelected(String field, Target node) {
    List<String> ctxNames = new ArrayList<>();
    if (node != null) {
        // The user has selected a new node
        this.target = node;
        if (node.getStartNode() != null) {
            populateRequestField(node.getStartNode());
            Session session = Model.getSingleton().getSession();
            List<Context> contexts = session.getContextsForNode(node.getStartNode());
            for (Context context : contexts) {
                ctxNames.add(context.getName());
            }
        } else if (node.getContext() != null) {
            ctxNames.add(node.getContext().getName());
        }
        this.setTech();
    }
    this.setComboFields(FIELD_CONTEXT, ctxNames, "");
    this.getField(FIELD_CONTEXT).setEnabled(ctxNames.size() > 0);
}
Also used : Context(org.zaproxy.zap.model.Context) ArrayList(java.util.ArrayList) Session(org.parosproxy.paros.model.Session)

Example 35 with Session

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

the class ActiveScanController method startScan.

@Override
public int startScan(String name, Target target, User user, Object[] contextSpecificObjects) {
    activeScansLock.lock();
    try {
        int id = this.scanIdCounter++;
        RuleConfigParam ruleConfigParam = null;
        ExtensionRuleConfig extRC = Control.getSingleton().getExtensionLoader().getExtension(ExtensionRuleConfig.class);
        if (extRC != null) {
            ruleConfigParam = extRC.getRuleConfigParam();
        }
        ActiveScan ascan = new ActiveScan(name, extension.getScannerParam(), extension.getModel().getOptionsParam().getConnectionParam(), null, ruleConfigParam) {

            @Override
            public void alertFound(Alert alert) {
                alert.setSource(Alert.Source.ACTIVE);
                if (extAlert != null) {
                    extAlert.alertFound(alert, null);
                }
                super.alertFound(alert);
            }
        };
        Session session = extension.getModel().getSession();
        List<String> excludeList = new ArrayList<>();
        excludeList.addAll(extension.getExcludeList());
        excludeList.addAll(session.getExcludeFromScanRegexs());
        excludeList.addAll(session.getGlobalExcludeURLRegexs());
        ascan.setExcludeList(excludeList);
        ScanPolicy policy = null;
        ascan.setId(id);
        ascan.setUser(user);
        boolean techOverridden = false;
        if (contextSpecificObjects != null) {
            for (Object obj : contextSpecificObjects) {
                if (obj instanceof ScannerParam) {
                    logger.debug("Setting custom scanner params");
                    ascan.setScannerParam((ScannerParam) obj);
                } else if (obj instanceof ScanPolicy) {
                    policy = (ScanPolicy) obj;
                    logger.debug("Setting custom policy " + policy.getName());
                    ascan.setScanPolicy(policy);
                } else if (obj instanceof TechSet) {
                    ascan.setTechSet((TechSet) obj);
                    techOverridden = true;
                } else if (obj instanceof ScriptCollection) {
                    ascan.addScriptCollection((ScriptCollection) obj);
                } else if (obj instanceof ScanFilter) {
                    ascan.addScanFilter((ScanFilter) obj);
                } else {
                    logger.error("Unexpected contextSpecificObject: " + obj.getClass().getCanonicalName());
                }
            }
        }
        if (policy == null) {
            // use the default
            policy = extension.getPolicyManager().getDefaultScanPolicy();
            logger.debug("Setting default policy " + policy.getName());
            ascan.setScanPolicy(policy);
        }
        if (!techOverridden && target.getContext() != null) {
            ascan.setTechSet(target.getContext().getTechSet());
        }
        this.activeScanMap.put(id, ascan);
        this.activeScanList.add(ascan);
        ascan.start(target);
        return id;
    } finally {
        activeScansLock.unlock();
    }
}
Also used : TechSet(org.zaproxy.zap.model.TechSet) ScanFilter(org.zaproxy.zap.extension.ascan.filters.ScanFilter) ArrayList(java.util.ArrayList) ScriptCollection(org.zaproxy.zap.extension.script.ScriptCollection) RuleConfigParam(org.zaproxy.zap.extension.ruleconfig.RuleConfigParam) ExtensionRuleConfig(org.zaproxy.zap.extension.ruleconfig.ExtensionRuleConfig) ScannerParam(org.parosproxy.paros.core.scanner.ScannerParam) Alert(org.parosproxy.paros.core.scanner.Alert) ExtensionAlert(org.zaproxy.zap.extension.alert.ExtensionAlert) Session(org.parosproxy.paros.model.Session)

Aggregations

Session (org.parosproxy.paros.model.Session)51 DatabaseException (org.parosproxy.paros.db.DatabaseException)18 Context (org.zaproxy.zap.model.Context)14 ArrayList (java.util.ArrayList)8 JMenuItem (javax.swing.JMenuItem)7 ExtensionPopupMenuItem (org.parosproxy.paros.extension.ExtensionPopupMenuItem)7 File (java.io.File)5 SiteNode (org.parosproxy.paros.model.SiteNode)5 HttpMalformedHeaderException (org.parosproxy.paros.network.HttpMalformedHeaderException)5 URIException (org.apache.commons.httpclient.URIException)4 RecordStructure (org.parosproxy.paros.db.RecordStructure)4 HttpMessage (org.parosproxy.paros.network.HttpMessage)4 ApiException (org.zaproxy.zap.extension.api.ApiException)4 ApiResponseElement (org.zaproxy.zap.extension.api.ApiResponseElement)4 Date (java.util.Date)3 HashMap (java.util.HashMap)3 PatternSyntaxException (java.util.regex.PatternSyntaxException)3 JFileChooser (javax.swing.JFileChooser)3 JSONException (net.sf.json.JSONException)3 ExtensionHistory (org.parosproxy.paros.extension.history.ExtensionHistory)3