Search in sources :

Example 21 with Target

use of org.zaproxy.zap.model.Target in project zaproxy by zaproxy.

the class ExtensionSpider method startScanNode.

/**
 * Start the scan of an URL (Node) from the POV of a User.
 *
 * @param node the node
 */
public void startScanNode(SiteNode node, User user) {
    Target target = new Target(node);
    target.setRecurse(true);
    this.startScan(target, user, null);
}
Also used : Target(org.zaproxy.zap.model.Target)

Example 22 with Target

use of org.zaproxy.zap.model.Target in project zaproxy by zaproxy.

the class NodeSelectDialog method populateContexts.

private void populateContexts(SiteNode root) {
    // Uncomment to hide contexts tree if there are no valid contexts -
    // not sure if this is a good idea or not :/
    // int contexts = 0;
    int contextsInScope = 0;
    for (Context ctx : Model.getSingleton().getSession().getContexts()) {
        // TODO ignore handle protected mode?
        if (ctx.getIncludeInContextRegexs().size() > 0) {
            SiteNode node = new SiteNode(null, HistoryReference.TYPE_PROXIED, ctx.getName());
            node.setUserObject(new Target(ctx));
            root.add(node);
            // contexts ++;
            if (ctx.isInScope()) {
                contextsInScope++;
            }
        }
    }
    if (contextsInScope > 1) {
        // Allow user to choose everything in scope
        SiteNode node = new SiteNode(null, HistoryReference.TYPE_PROXIED, Constant.messages.getString("context.allInScope"));
        node.setUserObject(new Target(null, null, true, true));
        root.add(node);
    }
    // this.getTreeContext().setVisible(contexts > 0);
    this.getTreeContext().expandRow(0);
}
Also used : Context(org.zaproxy.zap.model.Context) Target(org.zaproxy.zap.model.Target) SiteNode(org.parosproxy.paros.model.SiteNode)

Example 23 with Target

use of org.zaproxy.zap.model.Target in project zaproxy by zaproxy.

the class ContextsTreeCellRenderer method getTreeCellRendererComponent.

/**
 * Sets custom tree node logos.
 */
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
    SiteNode node = null;
    Target target = null;
    if (value instanceof SiteNode) {
        node = (SiteNode) value;
        if (node.getUserObject() instanceof Target) {
            target = (Target) node.getUserObject();
        }
    }
    if (node != null) {
        if (node.isRoot()) {
            setIcon(DisplayUtils.getScaledIcon(ROOT_ICON));
        } else if (target != null) {
            if (target.getContext() != null) {
                if (target.getContext().isInScope()) {
                    setIcon(DisplayUtils.getScaledIcon(CONTEXT_IN_SCOPE_ICON));
                } else {
                    setIcon(DisplayUtils.getScaledIcon(CONTEXT_ICON));
                }
            } else if (target.isInScopeOnly()) {
                setIcon(DisplayUtils.getScaledIcon(ALL_IN_SCOPE_ICON));
            }
        }
    }
    return this;
}
Also used : Target(org.zaproxy.zap.model.Target) SiteNode(org.parosproxy.paros.model.SiteNode)

Example 24 with Target

use of org.zaproxy.zap.model.Target in project zaproxy by zaproxy.

the class ExtensionAlert method publishAlertEvent.

private void publishAlertEvent(Alert alert, String event) {
    HistoryReference historyReference = hrefs.get(alert.getSourceHistoryId());
    if (historyReference == null) {
        historyReference = Control.getSingleton().getExtensionLoader().getExtension(ExtensionHistory.class).getHistoryReference(alert.getSourceHistoryId());
    }
    Map<String, String> map = new HashMap<>();
    map.put(AlertEventPublisher.ALERT_ID, Integer.toString(alert.getAlertId()));
    map.put(AlertEventPublisher.HISTORY_REFERENCE_ID, Integer.toString(alert.getSourceHistoryId()));
    map.put(AlertEventPublisher.NAME, alert.getName());
    map.put(AlertEventPublisher.URI, alert.getUri().toString());
    map.put(AlertEventPublisher.PARAM, alert.getParam());
    map.put(AlertEventPublisher.RISK, Integer.toString(alert.getRisk()));
    map.put(AlertEventPublisher.RISK_STRING, Alert.MSG_RISK[alert.getRisk()]);
    map.put(AlertEventPublisher.CONFIDENCE, Integer.toString(alert.getConfidence()));
    map.put(AlertEventPublisher.CONFIDENCE_STRING, Alert.MSG_CONFIDENCE[alert.getConfidence()]);
    map.put(AlertEventPublisher.SOURCE, Integer.toString(alert.getSource().getId()));
    ZAP.getEventBus().publishSyncEvent(AlertEventPublisher.getPublisher(), new Event(AlertEventPublisher.getPublisher(), event, new Target(historyReference.getSiteNode()), map));
}
Also used : HistoryReference(org.parosproxy.paros.model.HistoryReference) Target(org.zaproxy.zap.model.Target) HashMap(java.util.HashMap) Event(org.zaproxy.zap.eventBus.Event)

Example 25 with Target

use of org.zaproxy.zap.model.Target in project zaproxy by zaproxy.

the class StandardFieldsDialog method addTargetSelectField.

/*
     * Add a 'node select' field which provides a button for showing a Node Select Dialog and a
     * non editable field for showing the node selected
     */
public void addTargetSelectField(int tabIndex, final String fieldLabel, final Target value, final boolean editable, final boolean allowRoot) {
    validateTabbed(tabIndex);
    final ZapTextField text = new ZapTextField();
    text.setEditable(editable);
    this.setTextTarget(text, value);
    JButton selectButton = new JButton(Constant.messages.getString("all.button.select"));
    selectButton.setIcon(// Globe icon
    new ImageIcon(View.class.getResource("/resource/icon/16/094.png")));
    selectButton.addActionListener(new java.awt.event.ActionListener() {

        // Keep a local copy so that we can always select the last node chosen
        Target target = value;

        @Override
        public void actionPerformed(java.awt.event.ActionEvent e) {
            NodeSelectDialog nsd = new NodeSelectDialog(StandardFieldsDialog.this);
            nsd.setAllowRoot(allowRoot);
            target = nsd.showDialog(target);
            setTextTarget(text, target);
            targetSelected(fieldLabel, target);
        }
    });
    JPanel panel = new JPanel();
    panel.setLayout(new GridBagLayout());
    panel.add(text, LayoutHelper.getGBC(0, 0, 1, 1.0D, 0.0D, GridBagConstraints.BOTH, new Insets(4, 4, 4, 4)));
    panel.add(selectButton, LayoutHelper.getGBC(1, 0, 1, 0.0D, 0.0D, GridBagConstraints.BOTH, new Insets(4, 4, 4, 4)));
    this.addField(this.tabPanels.get(tabIndex), this.tabOffsets.get(tabIndex), fieldLabel, text, panel, 0.0D);
    this.incTabOffset(tabIndex);
}
Also used : ImageIcon(javax.swing.ImageIcon) JPanel(javax.swing.JPanel) ActionListener(java.awt.event.ActionListener) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JButton(javax.swing.JButton) ActionEvent(java.awt.event.ActionEvent) Target(org.zaproxy.zap.model.Target) ZapTextField(org.zaproxy.zap.utils.ZapTextField)

Aggregations

Target (org.zaproxy.zap.model.Target)25 SiteNode (org.parosproxy.paros.model.SiteNode)9 ArrayList (java.util.ArrayList)4 ImageIcon (javax.swing.ImageIcon)3 JButton (javax.swing.JButton)3 TreePath (javax.swing.tree.TreePath)3 URI (org.apache.commons.httpclient.URI)3 Context (org.zaproxy.zap.model.Context)3 StructuralNode (org.zaproxy.zap.model.StructuralNode)3 GridBagLayout (java.awt.GridBagLayout)2 Insets (java.awt.Insets)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 HashMap (java.util.HashMap)2 JPanel (javax.swing.JPanel)2 JTree (javax.swing.JTree)2 JSONObject (net.sf.json.JSONObject)2 URIException (org.apache.commons.httpclient.URIException)2 Event (org.zaproxy.zap.eventBus.Event)2 ApiException (org.zaproxy.zap.extension.api.ApiException)2