web security vulnerabilities attacks
play

Web Security: Vulnerabilities & Attacks Dawn Song Cross-site - PowerPoint PPT Presentation

Computer Security Course. Dawn Song Web Security: Vulnerabilities & Attacks Dawn Song Cross-site Request Forgery Dawn Song Example Application Consider a social networking site, GraceBook, that allows users to share happenings from


  1. Computer Security Course. Dawn Song Web Security: Vulnerabilities & Attacks Dawn Song

  2. Cross-site Request Forgery Dawn Song

  3. Example Application Consider a social networking site, GraceBook, that allows users to ‘share’ happenings from around the web. Users can click the “Share with GraceBook” button which publishes content to GraceBook. When users press the share button, a POST request to http://www.gracebook.com/share.php is made and gracebook.com makes the necessary updates on the server. Dawn Song

  4. Running Example Web Server Client Browser GET form.php URL Request form.php www.gracebook.com Dawn Song

  5. Running Example Web Server Client Browser GET form.php URL Request <html><body>… form.php Request Response www.gracebook.com Dawn Song

  6. Running Example <html><body> <div> Update your status: <form action= "http://www.gracebook.com/share.php" method= "post" > <input name= "text" value= "Feeling good!" ></input> <input type= "submit" value= "Share" ></input> </form> </div> </body></html> Dawn Song

  7. Running Example Update your status: Share Feeling good! Displays to user Web Server Client Browser www.gracebook.com Dawn Song

  8. Running Example Update your status: Share Feeling good! Displays to user Web Server Client Browser share.php text=Feeling Good! On “Share” click share.php www.gracebook.com Dawn Song

  9. Running Example Update your status: Share Feeling good! Displays to user Web Server Client Browser share.php text=Feeling Good! On “Share” click share.php Session Cookie www.gracebook.com Dawn Song

  10. Running Example Update your status: Share Feeling good! Displays to user Web Server Client Browser share.php text=Feeling Good! On “Share” click share.php valid session cookie? Session Cookie www.gracebook.com Dawn Song

  11. Running Example status: Update your status: DB “Feeling Share Feeling good! Server Good!” Displays to user Web Server Client Browser share.php text=Feeling Good! On “Share” click share.php update user’s status with the text “Feeling good!” Session Cookie www.gracebook.com Dawn Song

  12. Network Requests The HTTP POST Request looks like this: POST /share.php HTTP/1.1 Host: www.gracebook.com User-Agent: Mozilla/5.0 Accept: */* Content-Type: application/x-www-form-urlencoded; charset=UTF-8 Referer: https://www.gracebook.com/form.php Cookie: auth=beb18dcd75f2c225a9dcd71c73a8d77b5c304fb8 text=Feeling good! Dawn Song

  13. CSRF Attack • The attacker , on attacker.com , creates a page containing the following HTML: <form action= "http://www.gracebook.com/share.php" method= "post" id= " f" > <input type= "hidden" name= "text" value= "SPAM COMMENT" ></input> <script>document.getElementById ( 'f' ). submit (); </script> • What will happen when the user visits the page? a) The spam comment will be posted to user’s share feed on gracebook.com b) The spam comment will be posted to user’s share feed if the user is currently logged in on gracebook.com c) The spam comment will not be posted to user’s share feed on gracebook.com Dawn Song

  14. CSRF Attack • The attacker , on attacker.com , creates a page containing the following HTML: <form action= "http://www.gracebook.com/share.php" method= "post" id= " f" > <input type= "hidden" name= "text" value= "SPAM COMMENT" ></input> <script>document.getElementById ( 'f' ). submit (); </script> • What will happen when the user visits the page? a) The spam comment will be posted to user’s share feed on gracebook.com b) The spam comment will be posted to user’s share feed if the user is currently logged in on gracebook.com c) The spam comment will not be posted to user’s share feed on gracebook.com Dawn Song

  15. CSRF Attack • JavaScript code can automatically submit the form in the background to post spam to the user’s GraceBook feed. • Similarly, a GET based CSRF is also possible. Making GET requests is easier: just an img tag suffices. <img src= "http://www.gracebook.com/share.php?text=SPAM%20COMMENT" /> Dawn Song

  16. Example Attack status: <input type="hidden" … DB “SPAM Server COMMENT!” Welcome to my harmless site! Displays to user Web Server Client Browser share.php text=SPAM COMMENT! Via JavaScript share.php POST update user’s status with a spam comment Session Cookie Dawn Song

  17. CSRF Defense • Origin headers – Introduction of a new header, similar to Referer. – Unlike Referer, only shows scheme, host, and port (no path data or query string) • Nonce-based – Use a nonce to ensure that only form.php can get to share.php. Dawn Song

  18. CSRF via POST requests Consider the Referer value from the POST request outlined earlier. In the case of the CSRF attacks, will it be different? a. Yes b. No Dawn Song

  19. CSRF via POST requests Consider the Referer value from the POST request outlined earlier. In the case of the CSRF attacks, will it be different? a. Yes b. No Dawn Song

  20. Origin Header • Instead of sending whole referring URL, which might leak private information, only send the referring scheme, host, and port. POST /share.php HTTP/1.1 Host: www.gracebook.com User-Agent: Mozilla/5.0 Accept: */* Content-Type: application/x-www-form-urlencoded; charset=UTF-8 Origin: http://www.gracebook.com/ Cookie: auth=beb18dcd75f2c225a9dcd71c73a8d77b5c304fb8 text=hi Dawn Song

  21. Origin Header • Instead of sending whole referring URL, which might leak private information, only send the referring scheme, host, and port. POST /share.php HTTP/1.1 No path string Host: www.gracebook.com User-Agent: Mozilla/5.0 or query data Accept: */* Content-Type: application/x-www-form-urlencoded; charset=UTF-8 Origin: http://www.gracebook.com/ Cookie: auth=beb18dcd75f2c225a9dcd71c73a8d77b5c304fb8 text=hi Dawn Song

  22. Nonce based protection • Recall the expected flow of the application: – The message to be shared is first shown to the user on form.php (the GET request) – When user assents, a POST request to share.php makes the actual post • The server creates a nonce, includes it in a hidden field in form.php and checks it in share.php. Dawn Song

  23. Nonce based protection The form with nonce <form action= "share.php" method= "post" > <input type= "hidden" name= "csrfnonce" value= "av834favcb623" > <input type= "textarea" name= "text" value= "Feeling good!" > POST /share.php HTTP/1.1 Host: www.gracebook.com User-Agent: Mozilla/5.0 Accept: */* Content-Type: application/x-www-form-urlencoded; charset=UTF-8 Origin: http://www.gracebook.com/ Cookie: auth=beb18dcd75f2c225a9dcd71c73a8d77b5c304fb8 Text=Feeling good!&csrfnonce=av834favcb623 Server code compares nonce Dawn Song

  24. Legitimate Case Web Server Client Browser GET form.php URL Request form.php Dawn Song

  25. Legitimate Case Web Server Client Browser GET form.php URL Request <html><body> <input type="hidden" name=" form.php csrfnonce" value="av834favcb623">… Request Response Dawn Song

  26. Legitimate Case Update your status: Share Feeling good! <input type="hidden" name="csrfnonce" … Displays to user Web Server Client Browser Dawn Song

  27. Legitimate Case status: Update your status: DB “Feeling Share Feeling good! Server Good!” <input type="hidden" name="csrfnonce" … Displays to user Web Server Client Browser share.php text=Feeling Good! share.php csrfnonce=av834favcb623 update user’s status with the text “Feeling On “Share” click good!” after checking nonce Session Cookie Dawn Song

  28. Attack Case <input type="hidden“ … Welcome to my harmless site! Displays to user Web Server Client Browser share.php text=SPAM COMMENT! Via JavaScript share.php POST fails to update because nonce value is incorrect Session Cookie Dawn Song

  29. Recap • CSRF: Cross Site Request Forgery • An attack which forces an end user to execute unwanted actions on a web application in which he/she is currently authenticated. • Caused because browser automatically includes authorization credentials such as cookies. • Fixed using Origin headers and nonces – Origin headers not supported in older browsers. Dawn Song

  30. Web Session Management Slides credit: Dan Boneh Dawn Song

  31. Same origin policy: “high level” Same Origin Policy (SOP) for DOM: – Origin A can access origin B’s DOM if match on (scheme, domain, port) Same Original Policy (SOP) for cookies: – Based on: ([scheme], domain, path ) optional scheme://domain:port/path?params

  32. Setting/deleting cookies by server GET … Brows er Server HTTP Header: Set-cookie: NAME=VALUE ; domain = (when to send) ; scope if expires=NULL: path = (when to send) this session only secure = (only send over SSL); if expires=past date: expires = (when expires) ; browser deletes cookie HttpOnly Default scope is domain and path of setting URL

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