use of org.parosproxy.paros.extension.history.ExtensionHistory in project zaproxy by zaproxy.
the class ExtensionAntiCSRF method generateForm.
public String generateForm(int hrefId) throws Exception {
ExtensionHistory extHist = (ExtensionHistory) Control.getSingleton().getExtensionLoader().getExtension(ExtensionHistory.NAME);
if (extHist != null) {
HistoryReference hr = extHist.getHistoryReference(hrefId);
if (hr == null) {
return null;
}
HttpMessage msg = hr.getHttpMessage();
StringBuilder sb = new StringBuilder(300);
sb.append("<html>\n");
sb.append("<body>\n");
sb.append("<h3>");
sb.append(msg.getRequestHeader().getURI());
sb.append("</h3>");
sb.append("<form id=\"f1\" method=\"POST\" action=\"" + hr.getURI() + "\">\n");
sb.append("<table>\n");
TreeSet<HtmlParameter> params = msg.getFormParams();
// Let the message be GC'ed as it's no longer needed.
msg = null;
Iterator<HtmlParameter> iter = params.iterator();
while (iter.hasNext()) {
HtmlParameter htmlParam = iter.next();
String name = URLDecoder.decode(htmlParam.getName(), "UTF-8");
String value = URLDecoder.decode(htmlParam.getValue(), "UTF-8");
sb.append("<tr><td>\n");
sb.append(name);
sb.append("<td>");
sb.append("<input name=\"");
sb.append(name);
sb.append("\" value=\"");
sb.append(value);
sb.append("\" size=\"100\">");
sb.append("</tr>\n");
}
sb.append("</table>\n");
sb.append("<input id=\"submit\" type=\"submit\" value=\"Submit\"/>\n");
sb.append("</form>\n");
sb.append("</body>\n");
sb.append("</html>\n");
return sb.toString();
}
return null;
}
use of org.parosproxy.paros.extension.history.ExtensionHistory in project zaproxy by zaproxy.
the class AntiCsrfAPI method handleApiOther.
@Override
public HttpMessage handleApiOther(HttpMessage msg, String name, JSONObject params) throws ApiException {
if (OTHER_GENERATE_FORM.equals(name)) {
String hrefIdStr = params.getString(OTHER_GENERATE_FORM_PARAM_HREFID);
if (hrefIdStr == null || hrefIdStr.length() == 0) {
throw new ApiException(ApiException.Type.MISSING_PARAMETER, OTHER_GENERATE_FORM_PARAM_HREFID);
}
int hrefId;
try {
hrefId = Integer.parseInt(hrefIdStr);
String response = extension.generateForm(hrefId);
if (response == null) {
throw new ApiException(ApiException.Type.HREF_NOT_FOUND, hrefIdStr);
}
// Get the charset from the original message
ExtensionHistory extHist = (ExtensionHistory) Control.getSingleton().getExtensionLoader().getExtension(ExtensionHistory.NAME);
String charset = extHist.getHistoryReference(hrefId).getHttpMessage().getResponseHeader().getCharset();
if (charset == null || charset.length() == 0) {
charset = "";
} else {
charset = " charset=" + charset;
}
msg.setResponseHeader(API.getDefaultResponseHeader("text/html; " + charset, response.length()));
msg.setResponseBody(response);
} catch (NumberFormatException e) {
throw new ApiException(ApiException.Type.ILLEGAL_PARAMETER, OTHER_GENERATE_FORM_PARAM_HREFID);
} catch (ApiException e) {
throw e;
} catch (Exception e) {
throw new ApiException(ApiException.Type.INTERNAL_ERROR);
}
} else {
throw new ApiException(ApiException.Type.BAD_OTHER, name);
}
return msg;
}
use of org.parosproxy.paros.extension.history.ExtensionHistory in project zaproxy by zaproxy.
the class HttpPanelSender method handleSendMessage.
@Override
public void handleSendMessage(Message aMessage) throws IllegalArgumentException, IOException {
final HttpMessage httpMessage = (HttpMessage) aMessage;
try {
final ModeRedirectionValidator redirectionValidator = new ModeRedirectionValidator();
if (getButtonFollowRedirects().isSelected()) {
getDelegate().sendAndReceive(httpMessage, redirectionValidator);
} else {
getDelegate().sendAndReceive(httpMessage, false);
}
EventQueue.invokeAndWait(new Runnable() {
@Override
public void run() {
if (!httpMessage.getResponseHeader().isEmpty()) {
// Indicate UI new response arrived
responsePanel.updateContent();
try {
Session session = Model.getSingleton().getSession();
HistoryReference ref = new HistoryReference(session, HistoryReference.TYPE_ZAP_USER, httpMessage);
final ExtensionHistory extHistory = getHistoryExtension();
if (extHistory != null) {
extHistory.addHistory(ref);
}
SessionStructure.addPath(session, ref, httpMessage);
} catch (final Exception e) {
logger.error(e.getMessage(), e);
}
if (!redirectionValidator.isRequestValid()) {
View.getSingleton().showWarningDialog(Constant.messages.getString("manReq.outofscope.redirection.warning", redirectionValidator.getInvalidRedirection()));
}
}
}
});
ZapGetMethod method = (ZapGetMethod) httpMessage.getUserObject();
notifyPersistentConnectionListener(httpMessage, null, method);
} catch (final HttpMalformedHeaderException mhe) {
throw new IllegalArgumentException("Malformed header error.", mhe);
} catch (final UnknownHostException uhe) {
throw new IOException("Error forwarding to an Unknown host: " + uhe.getMessage(), uhe);
} catch (final SSLException sslEx) {
throw sslEx;
} catch (final IOException ioe) {
throw new IOException("IO error in sending request: " + ioe.getClass() + ": " + ioe.getMessage(), ioe);
} catch (final Exception e) {
logger.error(e.getMessage(), e);
}
}
use of org.parosproxy.paros.extension.history.ExtensionHistory in project zaproxy by zaproxy.
the class ExtensionPassiveScan method getPassiveScanThread.
private PassiveScanThread getPassiveScanThread() {
if (pst == null) {
final ExtensionLoader extensionLoader = Control.getSingleton().getExtensionLoader();
final ExtensionHistory extHist = (ExtensionHistory) extensionLoader.getExtension(ExtensionHistory.NAME);
final ExtensionAlert extAlert = (ExtensionAlert) extensionLoader.getExtension(ExtensionAlert.NAME);
pst = new PassiveScanThread(getPassiveScannerList(), extHist, extAlert, getPassiveScanParam());
pst.start();
}
return pst;
}
use of org.parosproxy.paros.extension.history.ExtensionHistory in project zaproxy by zaproxy.
the class PopupExcludeFromProxyMenu method performAction.
@Override
public void performAction(SiteNode sn) {
try {
Session session = Model.getSingleton().getSession();
session.getExcludeFromProxyRegexs().add(new StructuralSiteNode(sn).getRegexPattern());
SiteMap map = (SiteMap) View.getSingleton().getSiteTreePanel().getTreeSite().getModel();
ExtensionHistory extHistory = Control.getSingleton().getExtensionLoader().getExtension(ExtensionHistory.class);
if (extHistory != null) {
extHistory.purge(map, sn);
}
} catch (DatabaseException e) {
// Ignore
}
}
Aggregations