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);
}
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);
}
}
}
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);
}
}
}
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);
}
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();
}
}
Aggregations