).
But I faced issue when spider is not recognizing response correctly (index.php is not found and active scan is not attacking it).
I think root cause is in authentication script but do not know how to correct it.
When I do page browsing with Firefox then after Post request to login.php there is 302 redirect to index.php.
But when I authenticate by script then after Post to login.php I receive response from index.php without mention that it is separate page. So I think this is the reason why spider is not detecting index.php page.
I am using standard auth script:
function authenticate(helper, paramsValues, credentials) {
var loginUrl = paramsValues.get("LoginURL");
var csrfTokenName = paramsValues.get("CSRFField");
var csrfTokenValue = extractInputFieldValue(getPageContent(helper, loginUrl), csrfTokenName);
var postData = paramsValues.get("POSTData");
postData = postData.replace('{%username%}', encodeURIComponent(credentials.getParam("Username")));
postData = postData.replace('{%password%}', encodeURIComponent(credentials.getParam("Password")));
postData = postData.replace('{%' + csrfTokenName + '%}', encodeURIComponent(csrfTokenValue));
var msg = sendAndReceive(helper, loginUrl, postData);
return msg;
}
function getRequiredParamsNames() {
return [ "LoginURL", "CSRFField", "POSTData" ];
}
function getOptionalParamsNames() {
return [];
}
function getCredentialsParamsNames() {
return [ "Username", "Password" ];
}
function getPageContent(helper, url) {
var msg = sendAndReceive(helper, url);
return msg.getResponseBody().toString();
}
function sendAndReceive(helper, url, redirectUrl, postData) {
var msg = helper.prepareMessage();
var method = "GET";
if (postData) {
method = "POST";
msg.setRequestBody(postData);
}
var requestUri = new org.apache.commons.httpclient.URI(url, true); //true to false
var requestHeader = new org.parosproxy.paros.network.HttpRequestHeader(method, requestUri, "HTTP/1.0");
msg.setRequestHeader(requestHeader);
helper.sendAndReceive(msg);
return msg;
}
function extractInputFieldValue(page, fieldName) {
// Rhino:
//var src = new net.htmlparser.jericho.Source(page);
// Nashorn:
var Source = Java.type("net.htmlparser.jericho.Source");
var src = new Source(page);
var it = src.getAllElements('input').iterator();
while (it.hasNext()) {
var element = it.next();
if (element.getAttributeValue('name') == fieldName) {
return element.getAttributeValue('value');
}
}
return '';
}
I tried to modify function sendAndReceive so it will send second request to index.php page:
var requestUri = new org.apache.commons.httpclient.URI(url, false); //true to false
var requestHeader = new org.parosproxy.paros.network.HttpRequestHeader(method, requestUri, "HTTP/1.0");
msg.setRequestHeader(requestHeader);
helper.sendAndReceive(msg, false); // don't follow redirects in order to set correctly the cookie
AuthenticationHelper.addAuthMessageToHistory(msg);
requestUri = new org.apache.commons.httpclient.URI(redirectUrl, false);
requestMethod = HttpRequestHeader.GET;
requestHeader = new org.parosproxy.paros.network.HttpRequestHeader(requestMethod, requestUri, "HTTP/1.0");
msg = helper.prepareMessage();
msg.setRequestHeader(requestHeader);
msg.getRequestHeader().setContentLength(msg.getRequestBody().length());
helper.sendAndReceive(msg, true);
return msg;
but
in this case ZAP is sending only get request to login.php.
What is the correct way to avoid this issue or what changes are needed to auth script?
Yes, checked. But didn't understand how to apply this to script.
I will appreciate if somebody could point to solution.
I am trying to run scan from script: