hacking web sites cross site scripting
play

Hacking Web Sites Cross Site Scripting Emmanuel Benoist Fall Term - PowerPoint PPT Presentation

Hacking Web Sites Cross Site Scripting Emmanuel Benoist Fall Term 2020/2021 Berner Fachhochschule | Haute ecole sp ecialis ee bernoise | Berne University of Applied Sciences 1 Table of Contents Presentation Stored XSS Reflected


  1. Hacking Web Sites Cross Site Scripting Emmanuel Benoist Fall Term 2020/2021 Berner Fachhochschule | Haute ´ ecole sp´ ecialis´ ee bernoise | Berne University of Applied Sciences 1

  2. Table of Contents Presentation � Stored XSS Reflected XSS DOM based XSS What can be achieved? � Testing strategies � Countermeasures � Anti XSS HTTP-Headers Berner Fachhochschule | Haute ´ ecole sp´ ecialis´ ee bernoise | Berne University of Applied Sciences 2

  3. Presentation Berner Fachhochschule | Haute ´ ecole sp´ ecialis´ ee bernoise | Berne University of Applied Sciences 3

  4. Cross Site Scripting - XSS If the web site allows uncontrolled content to be supplied by users User can write content in a Guest-book or Forum User can introduce malicious code in the content Example of malicious code Modification of the Document Object Model - DOM (change some links, add some buttons) Send personal information to thirds (javascript can send cookies to other sites) Berner Fachhochschule | Haute ´ ecole sp´ ecialis´ ee bernoise | Berne University of Applied Sciences 4

  5. modus Operandi Attacker Executes Script on the Victim’s machine Is usually Javascript Can be any script language supported by the victim’s browser Three types of Cross Site Scripting Reflected Stored DOM injection Berner Fachhochschule | Haute ´ ecole sp´ ecialis´ ee bernoise | Berne University of Applied Sciences 5

  6. Stored XSS Berner Fachhochschule | Haute ´ ecole sp´ ecialis´ ee bernoise | Berne University of Applied Sciences 6

  7. Stored XSS Hostile Data is taken and stored In a file In a Database or in any other backend system Then Data is sent back to any visitor of the web site Risk when large number of users can see unfiltered content Very dangerous for Content Management Systems (CMS) Blogs forums Berner Fachhochschule | Haute ´ ecole sp´ ecialis´ ee bernoise | Berne University of Applied Sciences 7

  8. Example of Stored XSS A user has access to a CMS (Content Management System) The user can write some content (home page, news, blogs, ...) The user can modify the layout and edit content Hello world <b>Everybody</b><br> I want to say something! This content will be saved in a database The content will be shown to all (or some) visitors of the site The user can write: Hello <b> World</b><script>alert("Hello");</ ց → script> Any visitor reading the page will execute the script Page shows an alert message But can be much more dangerous Berner Fachhochschule | Haute ´ ecole sp´ ecialis´ ee bernoise | Berne University of Applied Sciences 8

  9. Other stored XSS One can manipulate the DOM in JavaScript Access a DOM node, change its content document.getElementById() and change innerHTML Suppose the page contains this HTML <h1 id="title">This is the title</h1> The following can be injected Hello <b>World</b> <script>document.getElementById(title).innerHTML ց → ="This �������site�was�hacked’’;</script> ���� Berner Fachhochschule | Haute ´ ecole sp´ ecialis´ ee bernoise | Berne University of Applied Sciences 9

  10. Reflected XSS Berner Fachhochschule | Haute ´ ecole sp´ ecialis´ ee bernoise | Berne University of Applied Sciences 10

  11. Reflected XSS The easiest exploit A page will reflect user supplied data directly back to the user It contains something like: echo $_REQUEST[’userinput’]; So when the user types: <script> alert("Hello�World"); </script> He receives an alert in his browser Danger If the URL (containing GET parameters) is delivered by a third to the victim The Victim will access a modified page SSL certificate and security warning are OK!!! Berner Fachhochschule | Haute ´ ecole sp´ ecialis´ ee bernoise | Berne University of Applied Sciences 11

  12. Where is reflected XSS? I In any form where input is displayed Search form <form method="GET"> <input type="text" name="val"> <input type="submit" value="Send"> </form> <?php echo "The�search�you�did�is:".$_GET[’val’ ց → ]; print_results($_GET[’val’]); ?> Error message $x = $_GET[’val’]; if(!validation_is_OK($x)){ echo "Value�is�not�correct:".$x; } Berner Fachhochschule | Haute ´ ecole sp´ ecialis´ ee bernoise | Berne University of Applied Sciences 12

  13. Where is reflected XSS? II XSS often in pages not intended for web browsers AJAX URL’s (normally for transferring data) JSON addresses (for data also) If they are loaded inside a browser, can they be misused. Berner Fachhochschule | Haute ´ ecole sp´ ecialis´ ee bernoise | Berne University of Applied Sciences 13

  14. Exploit Reflected XSS Not easy: The message is normally only returned to the same person The reflecting XSS is difficult to exploit Idea: transfer an URL to the browser containing the parameters Parameters can be included inside the URL (GET requests and URL encoded parameters) https://www.mysite.com/?param=value URL is included inside a mail Can be a spam (for phishing) Or a targeted email (for spare phishing) The victim will click on the link The link looks very legitimate (right site, https, ...) : impossible to see it is not valide Berner Fachhochschule | Haute ´ ecole sp´ ecialis´ ee bernoise | Berne University of Applied Sciences 14

  15. Example: Change an error message into a login page I Suppose we have this code: <?php $x = $_GET[’val’]; if(!validation_is_OK($x)){ echo "Value�is�not�correct:".$x; } ... ?> One will write the following link https://www.mysite.com/?val=%3Cscript+src%3D% 22evilProgram.js%22%3E%3C%2Fscript%3E Val is URL encoded: <script src="evilProgram.js"></script> Berner Fachhochschule | Haute ´ ecole sp´ ecialis´ ee bernoise | Berne University of Applied Sciences 15

  16. Example Change an error message into a login page II Program does: Errase the content of the page Create new nodes Build a totally new Document Object Model (see later how to manipulate the DOM) Berner Fachhochschule | Haute ´ ecole sp´ ecialis´ ee bernoise | Berne University of Applied Sciences 16

  17. DOM based XSS Berner Fachhochschule | Haute ´ ecole sp´ ecialis´ ee bernoise | Berne University of Applied Sciences 17

  18. DOM Based XSS Document Object Model The document is represented using a tree The tree is rooted with the document node Each tag and text is part of the tree JavaScript is manipulated directly inside the client Does not need to be reflected by the server. Using misconfiguration of client side code Using flows in frameworks (AngularJS, JQuery, . . . ) XSS is directly injected inside the DOM Using JavaScript misprogramming Using a flow in a framework Using evaluation of rogue data XSS Modifies the Document Object Model (DOM) Javascript can manipulate all the document It can create new nodes, Remove existing nodes Change the content of some nodes Berner Fachhochschule | Haute ´ ecole sp´ ecialis´ ee bernoise | Berne University of Applied Sciences 18

  19. Example of DOM based XSS Suppose we have the following JS-code <script> document.write("<b>Current�URL</b>�:�" + ց → document.baseURI); </script> If you send the following link to the browser (just URL encoded) http: //www.example.com/test.html#<script>alert ց → (1)</script> When the script is interpreted The document.wirte() function adds the content to the page: <script>alert(1)</script> It is executed! Nothing was ever sent to the server! Anchor (i.e. after the #) is used for navigation only Berner Fachhochschule | Haute ´ ecole sp´ ecialis´ ee bernoise | Berne University of Applied Sciences 19

  20. Principles Input (source) is transfered to an output (sink) Input provided by the user If the output is written without being encoded : can be exploited Popular sources document.URL , document.documentURI , location.href , location.search , location.* , window.name , document.referrer Popular sinks document.write() , anything.innerHTML= someelements.src (for specific elements) Berner Fachhochschule | Haute ´ ecole sp´ ecialis´ ee bernoise | Berne University of Applied Sciences 20

  21. What can be achieved? Berner Fachhochschule | Haute ´ ecole sp´ ecialis´ ee bernoise | Berne University of Applied Sciences 21

  22. Document Object Model HTML is converted into a tree <html> <body> <div id="header"> <h1>Title of the page</h1> </div> <div id="menu"> <ul id="menu-list"> <li class="menuitem"> <a href="index.php?id=1">One</a> </li> <li class="menuitem"><a href="index.php?id=2">Two</a></ ց → li> <li class="menuitem"><a href="index.php?id=3">Three</a ց → ></li> </ul> </div> <div id="content"> <p> Hello World </p> </div> </div> Berner Fachhochschule | Haute ´ ecole sp´ ecialis´ ee bernoise | Berne University of Applied Sciences 22

  23. Document Object Model (Cont.) Berner Fachhochschule | Haute ´ ecole sp´ ecialis´ ee bernoise | Berne University of Applied Sciences 23

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend