Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulate CSRF Attack

I want to simulate CSRF Attack to check my website vulnerability. I tried it on my asp.net webapplication but failed to simulate. So please help me to simulate the CSRF attack. I have simulated by having a test.aspx.

  <form name="form1" id="form1" runat="server" method="post" action="mysite.com">
 <script type="text/javascript">
        document.cookie[".ASPXAUTH"] = "someaspxauth";
        document.cookie["ASP.NET_SessionId"] = "somesessionid";
        document.form1.submit();
    </script>
</form>

What else am i missing? Thanks in advance.

like image 654
Tej Avatar asked Jul 06 '11 23:07

Tej


People also ask

What is CSRF and how do you exploit it?

Cross-Site Request Forgery (CSRF) is an attack that forces authenticated users to submit a request to a Web application against which they are currently authenticated. CSRF attacks exploit the trust a Web application has in an authenticated user.

Is CSRF possible on PUT request?

If the server is using PUT method for sensitive actions then there is no need for any additional CSRF protection(unless Cross-Origin Resource Sharing is enabled) at that endpoint. It is because the PUT request cannot be duplicated through a web page like POST request(HTTP forms do not allow PUT requests ).

What is the difference between CSRF and XSRF?

What is the difference between XSS and CSRF? Cross-site scripting (or XSS) allows an attacker to execute arbitrary JavaScript within the browser of a victim user. Cross-site request forgery (or CSRF) allows an attacker to induce a victim user to perform actions that they do not intend to.

What is CSRF example?

In a successful CSRF attack, the attacker causes the victim user to carry out an action unintentionally. For example, this might be to change the email address on their account, to change their password, or to make a funds transfer.


1 Answers

To simulate CSRF, you won't include the cookie or session information in the malicious code. The whole point of CSRF is that the code that executes doesn't know your session or cookie info. It just assumes that the browser will include that in its request to the application.

So to test, assume you have a page Transfer.aspx which accepts a POST method and parameters of txtFrom, txtTo, and txtAmount, with a button btnSubmit, and you want to try to transfer from account 1 to account 2. Your malicious code could be something like:

<form action="http://www.mysite.com/Transfer.aspx" method="post">
    <input type="hidden" name="txtFrom" value="1" />
    <input type="hidden" name="txtTo" value="2" />
    <input type="hidden" name="txtAmount" value="500" />
    <input type="hidden" name="__VIEWSTATE" value="[PUT VIEWSTATE VALUE HERE]" />
    <input type="hidden" name="__EVENTVALIDATION" value="[PUT EVENTVALIDATION VALUE HERE]" />
    <input type="submit" name="btnSubmit" value="Go" />
</form>

You'd have to know in advance what the viewstate and eventvalidation values would be, so you'd need to copy that from your page when you're logged in properly. This assumes that your viewstate is constant, regardless of user or session.

Now you have a malicious page. If you are logged in on one tab, open this in another tab, and submit it, if you are vulnerable, then your transfer will occur. The reason is that the cookies belonging to mysite.com are sent, which means that your session, which is alive on another tab, will be used.

To fix this, you need a unique per-session value to be included in your post. This is most easily accomplished by using the ViewStateUserKey, and setting it to your ASP.NET session ID or a hash of it. This will make your __VIEWSTATE value unique with every session, which means you will no longer be vulnerable because nobody can predict what your __VIEWSTATE value will be.

like image 161
Joe Enos Avatar answered Sep 24 '22 20:09

Joe Enos