![]() |
Cross-Site Request Forgeries
Cross-Site Request Forgeries
Here's a short, concise article on CSRF. A cross-site request forgery (CSRF) is an attack that attempts to exploit an applications trust in a user. For this article I want you to visualise the following scenario. A library has setup an online booking system where users can reserve books online. However, reservations for books that are not picked up will incur a penalty. This is where a malicious user may decide to have some fun. In order to reserve a book the user simply sends the following request to reserve.php Code:
reserve.php?book=12345&duration=14Code:
<img src=http://www.library.com/reserve.php?book=99999&duration=99 />CSRF attacks do require the attackers to target users who are already logged in, however, with today’s websites logins are usually remembered for long periods of time so this usually isn’t a problem. How to Protect Yourself In order to combat CSRF you must determine whether a request is coming from a valid or malicious user. One common technique to achieve this is through the use of tokens. Let’s say, for example, that the following form is used to reserve a book: Code:
<form method=”get” action=”reserve.php” enctype=”multipart/form-data”>Code:
<input type=”hidden” name=”token” value=”<?php echo $token ?>” /> |
You could also use POST for the book number and the number of days.
|
You could, but it wouldn't really offer you much more protection against CSRF. Malicious users can also forge a POST request just as easily as a GET, I just thought the GET method made the example easier to grasp.
|
Quote:
|
You actually can still do this type of attack using a POST it just isn't as simple as embedding an image, here's an example:
http://www.businessinfo.co.uk/labs/c...cks/holder.php |
Google's search uses get data, not post.
|
Quote:
|
You can use standard Fputs to post variables, basically if you can change the header, you can change the POST and GET vars, cookies etc fairly easily.
|
You cant fwrite (Fputs) a properly configured remote server, not with writing privileges anyway.
|
You can write to the HEADER quite easily though using the same function....
|
So basicly, how would you do the check if the tokens match?
|
An exmaple would be to first set the token as the users cookie:
PHP Code:
PHP Code:
|
| All times are GMT. The time now is 12:30 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0