how to configure ZAP to bypass csrf tokens in spider attack

2,841 views
Skip to first unread message

Neena

unread,
Nov 18, 2015, 5:03:55 PM11/18/15
to OWASP ZAP User Group
Hi,
I'm testing a django app on a local host using ZAP as a proxy. I have added authentication in context as form-based. The problem is that django generates csrf tokens for login form and ZAP puts this info into the Login Request POST data field

When I run the spider I get these alerts:


So how can I have ZAP bypass the csrf tokens or take the newly generated one?

Thanks..

ryerson...@gmail.com

unread,
Nov 19, 2015, 11:36:35 AM11/19/15
to OWASP ZAP User Group
I got the same issue :)

Simon Bennetts

unread,
Nov 20, 2015, 8:19:57 AM11/20/15
to OWASP ZAP User Group
OK, so its not a 'simple' form based authentication then.
I'd try recording a Zest authentication script.
Make sure that the anti CSRF token is configured in ZAP, then start recording the script and make sure you go to the page that generates the token first.
You can run Zest auth scripts on their own - try that and see if the authentication actually works.
Then we can look into using it for the spider and scanning :)

Cheers,

Simon

Neena

unread,
Nov 20, 2015, 12:07:50 PM11/20/15
to OWASP ZAP User Group
Ok I'll give it a shot. Thanks!
Message has been deleted

Xavi

unread,
Sep 1, 2018, 3:00:56 AM9/1/18
to OWASP ZAP User Group
Neena, did Simon's suggestion worked, I am facing the same issue :(?

Zabee

unread,
Sep 4, 2018, 2:05:29 AM9/4/18
to OWASP ZAP User Group

Thee recorded ZEST script is not working. It is throwing errors.

ZEST Script login recording output.png



Zabee

unread,
Sep 4, 2018, 2:18:56 AM9/4/18
to OWASP ZAP User Group
The target web application is a single page app. Also, only one session service to handle login and logout.

Simon Bennetts

unread,
Sep 4, 2018, 3:15:05 AM9/4/18
to OWASP ZAP User Group
Right click on the first failing line and compare the request and response with the original.
Where is the anti CSRF token used?
If its in the first POST request then you'll have started recording the script too late - the script needs to know where to get the CSRF token from, which is often the result of a GET request.

Zabee

unread,
Sep 4, 2018, 5:25:21 AM9/4/18
to OWASP ZAP User Group
Thanks for the information.
This time I started recording before opening the browser itself and stopped as soon as I logged in to the target application.

Below headers are extra in comparison to the original request,
Host: <host>
Cookie: <cookie name and value> 
 
Response comparison shows that the original response has "OK" followed by proper response contents and the ZEST script ran response has something like this - //EX[x,x,["com.google.gwt.user.client.rpc.RpcTokenException/xxxxxxxxxxxx","Invalid RPC token (Invalid XSRF token)"],x,x] 


hauschu...@gmail.com

unread,
Sep 6, 2018, 7:15:25 AM9/6/18
to OWASP ZAP User Group
Hello!

Could you post a screenshot of the Zest script responses/errors you are seeing?

One thing to know is that the Zest recording will at first hardcode any unique session identifiers and tokens, so you will have to manually edit the Zest script in order to set the proper elements as variables.  

Zabee

unread,
Sep 7, 2018, 6:34:57 AM9/7/18
to zaprox...@googlegroups.com
Thanks for the reply. I got this sorted out. Assigned the values to as a regex and used them in subsequent request. 

--
You received this message because you are subscribed to the Google Groups "OWASP ZAP User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to zaproxy-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/zaproxy-users/1ec97691-67e0-4123-8f6e-d5d6f25d5302%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

hauschu...@gmail.com

unread,
Sep 7, 2018, 7:40:35 AM9/7/18
to OWASP ZAP User Group
Great!
Reply all
Reply to author
Forward
0 new messages