Author Topic: CSRF Tutorial by Connection  (Read 7612 times)

0 Members and 1 Guest are viewing this topic.

Offline I_Learning_I

  • Knight
  • **
  • Posts: 267
  • Cookies: 26
  • Nor black or white, not even grey. What hat am I?
    • View Profile
    • Hacking F0r Fr33
CSRF Tutorial by Connection
« on: April 04, 2011, 01:09:08 pm »
Code: [Select]
/¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯\
:Finding and Exploiting CSRF Vulnerabilities    : 
\______________________________________________/
/By: Connection  \
\________________/
What is CSRF?
~_¯~_¯~_¯~_¯~_¯~_¯~_¯~_¯~_¯~_¯~

CSRF (Cross-Site Request Forgery) is a vulnerability found in web applications which allow a remote attacker to create a special web page or email which, when viewed by an authenticated viewer on a remote site, will execute a particular script. The script executed  could range from creating usernames with administrative access, changing the admins (or any other user's) password, creating content on the site, deleting content on the site, and any other action that a user with an authenticated session might be able to do.

How do I find CSRF Vulnerabilities?
~_¯~_¯~_¯~_¯~_¯~_¯~_¯~_¯~_¯~_¯~

This is an interactive tutorial on finding CSRF Vulnerabilities using a demo CMS from http://demo.opensourcecms.com. At the time of this writing the vulnerability exists on Dubsite CMS 1.0 but the vendor has been alerted to this and thus I cannot verify that at the time this is written the vulnerability will exist. The tools I use to find CSRF vulnerabilties are Firefox Web Browser, the Tamper Data Firefox Plug-in, and Notepad++ (or any other text-editor).

Step 1: visit http://demo.opensourcecmd.com/dubsite/index.php/login and login with the following credentials:

Username: admin
Password: demo123

Step 2: Navigate to the user control panel of the admin page located at http://demo.opensourcecms.com/dubsite/index.php/admin/users/accounts

Step 3: We are now going to attempt to modify the administrator's password. Click on edit and fill in the data you want. Before you click submit, start tamper data to sniff the requests.

Now make a note of the parameters passed to the website. Mine look like this:



The stuff we interested in are the URL up top and all the POST parameters in the right window. Open up your favorite text-editor and copy down all these values.

Step 4: Here comes the fun part, we are going to create our evil URL. We have to combine our base url with our post parameters.

Our base URL is the URL we copied from tamper data. In this case our base URL is :
http://demo.opensourcecms.com/dubsite/index.php/admin/users/accounts/edit/1

When we append POST parameters to a base URL we start with adding a ? to the base URL and then combine parameters by linking them with a &. An example is http://base.url/goes/here?first=parameter&second=parameter

A more specific example is for our Dubsite CMS base URL:

http://demo.opensourcecms.com/dubsite/index.php/admin/users/accounts/edit/1?username=admin&userpassword=test123&userpassword2=test123&role_id=1&active=1&update=Update

As you can see we send the data back to the server the same way our browser sent it. This example URL will edit the administrator account's password and change it to test123.

Step 5: Now we have a few methods of getting the authenticated administrator to execute this command. First of all we could make a website and set it like this:

Code: [Select]
<html>
<head>
</head>
<body>
<img src = "http://demo.opensourcecms.com/dubsite/index.php/admin/users/accounts/edit/1?username=admin&userpassword=test123&userpassword2=test123&role_id=1&active=1&update=Update" />
</body>
</html>

When the web browser views the page it will send the link to the admin's site trying to get the information for the image which will in turn execute the change password feature.

Another way to get the admin to execute the command is to email the admin with the <img> tag trick in the body of the email. Opening the email will cause the server to try to grab the image and will execute the change password function.

Conclusion
~_¯~_¯~_¯~_¯~_¯~_¯~_¯~_¯~_¯~_¯~

CSRF vulnerabilities could cause a lot of harm to a system admin because the form does not have some sort of validation token in place to make sure the administrator is actually issuing the command. A technique that will stop many attackers is to add HTTP_REFERER checking to the page with the form. Coming from an email or other website, the request for the form will be either blanked out or wrong and thus tip off the admin to what is going on. Combined with session tokens for making sure each visit to the form is unique, this will stop attackers from attacking your site via CSRF techniques.

Bonus Points
~_¯~_¯~_¯~_¯~_¯~_¯~_¯~_¯~_¯~_¯~

The create user function is also vulnerable to CSRF attacks. For more practice try to exploit it and create your own administrator user.

~_¯Connection_¯~_¯Reset_¯~_¯By_¯~_¯Peer_¯~_¯~_¯~

-----
Other supports:
Code: [Select]
http://www.owasp.org/index.php/Cross-Site_Request_Forgery_%28CSRF%29
Once again, just bringing some old tutorials.
Thanks for reading,
I_Learning_I

Offline ande

  • Owner
  • Titan
  • *
  • Posts: 2664
  • Cookies: 256
    • View Profile
Re: CSRF Tutorial by Connection
« Reply #1 on: April 04, 2011, 03:28:28 pm »
I thought of posting this a while back, but found out none of the link in the tutorial is working so I didn't. Not sure how easy this tutorial is to follow when the links are not working..
if($statement) { unless(!$statement) { // Very sure } }
https://evilzone.org/?hack=true

Offline I_Learning_I

  • Knight
  • **
  • Posts: 267
  • Cookies: 26
  • Nor black or white, not even grey. What hat am I?
    • View Profile
    • Hacking F0r Fr33
Re: CSRF Tutorial by Connection
« Reply #2 on: April 04, 2011, 04:20:10 pm »
Ahh, didn't even remember checking =X
Sorry, my bad, I'll make some small tutorial on my own and replace later.
Thanks for reading,
I_Learning_I

Offline sahariar

  • NULL
  • Posts: 3
  • Cookies: 0
    • View Profile
Re: CSRF Tutorial by Connection
« Reply #3 on: May 31, 2012, 05:33:23 am »
make an video tutorial on it .. it will be more clear  ;)

Offline fruitcake2212

  • /dev/null
  • *
  • Posts: 12
  • Cookies: 1
    • View Profile
Re: CSRF Tutorial by Connection
« Reply #4 on: June 23, 2012, 03:50:02 am »
Thanks for the great tut.
There is however one thing that I didn't really understand clearly :


When we append POST parameters to a base URL we start with adding a ? to the base URL and then combine parameters by linking them with a &. An example is http://base.url/goes/here?first=parameter&second=parameter


I thought that the parameters in URLs were GET parameters, so how is this possible?
I tried it on a website; I used Tamper Data to know what the Post Parameters of the Form are, and I then made an URL with the parameters appended to it and it worked great! Nonetheless I still don't understand how it works/how it is possible to pass Post parameters in the URL. Why on some site you can pass the post parameters in the url, and on some other sites you can't ?

I know that in PHP, to get Post variables it is 
Code: [Select]
$_POST['variblename'] and to get Get variables we do 
Code: [Select]
$_GET['variblename'];
Sorry if this sounds like a noob (which I am) question. I'd like to know more about it. If someone can enlighten me, it'd be very appreciated.
« Last Edit: June 23, 2012, 03:57:32 am by fruitcake2212 »

Offline ande

  • Owner
  • Titan
  • *
  • Posts: 2664
  • Cookies: 256
    • View Profile
Re: CSRF Tutorial by Connection
« Reply #5 on: June 23, 2012, 04:48:07 am »
Thanks for the great tut.
There is however one thing that I didn't really understand clearly :

I thought that the parameters in URLs were GET parameters, so how is this possible?
I tried it on a website; I used Tamper Data to know what the Post Parameters of the Form are, and I then made an URL with the parameters appended to it and it worked great! Nonetheless I still don't understand how it works/how it is possible to pass Post parameters in the URL. Why on some site you can pass the post parameters in the url, and on some other sites you can't ?

I know that in PHP, to get Post variables it is 
Code: [Select]
$_POST['variblename'] and to get Get variables we do 
Code: [Select]
$_GET['variblename'];
Sorry if this sounds like a noob (which I am) question. I'd like to know more about it. If someone can enlighten me, it'd be very appreciated.

You are very much correct. Most pages (correctly coded) should not allow POST arguments to be passed in the URL. Guess you could say that it is a part of the CSRF flaw.

The flaw is that the developer used $_REQUEST['derp'] instead of $_GET/POST['derp']. $_REQUEST[] grabs input from POST, GET and even cookies.

Leasson learned, POST != GET != cookies.
if($statement) { unless(!$statement) { // Very sure } }
https://evilzone.org/?hack=true

Offline fruitcake2212

  • /dev/null
  • *
  • Posts: 12
  • Cookies: 1
    • View Profile
Re: CSRF Tutorial by Connection
« Reply #6 on: June 23, 2012, 05:59:10 am »
I see!
Didn't know about $_REQUEST.
Wow, that answers perfectly my question. Thanks Ande.