Docsity

Understanding Obfuscation in JavaScript: Circumventing Analysis, Slides of Javascript programming

Partial preview of the text

Download Understanding Obfuscation in JavaScript: Circumventing Analysis and more Slides Javascript programming in PDF only on Docsity!

Circumventing

Automated JavaScript

Analysis

Overview

  • JavaScript is part of attackers toolkit
    • All the “vanilla” stuff over
    • Packing traditional malware
  • IBM ISS: “In second half 2007 Web attack obfuscation approached
  • Exploit frameworks amplify the problem
    • Rapid adoption of new techniques
  • We need tools to analyze this
  • How are we doing and can we win?
  • From: IBM Internet Security Systems X-Force® 2008 Mid-Year Trend Statistics

Obfuscation Example

Obfuscation != Malicious

  • Legitimate reasons for obfuscating
    • “Protect” client-side code
    • Reducing download size
  • Common packers
    • JSMin
    • Dean Edwards packer
    • Yahoo’s
  • Result: Its tough to know what to analyze

Tricks to Defeating Analysis

  • Deliberate sandbox breaks
  • Integrity Checks
    • Arguments.callee.toString()
      • arguments.callee.toString().replace(/\W/g,"").toUpperCase();
    • Gives source code of function body
      • Length checks
      • Use function body as key

VBScript Wrapper

  • Still in use!
    • Older DHTML web apps
    • Plug-in enumeration (IE8)
    • Malware
  • No open source VBScript parsers
  • No public standard grammar
  • Not very wide-spread VBScript JavaScript JavaScript

For those playing at home

Approach Difficulties

All Approaches Sampling Prevention
The Lazy Method Integrity checks
Running hostile code in browser
The Tom Liston Method Integrity checks
escapes
Running hostile code in browser
Perl Fu Way too time consuming
Translating JavaScript constructs
The Monkey Wrench Approach Does pretty well

Approach Today

  • Combination of automatic and manual
  • Interpreters and debuggers (aka sandboxes)
    • Rhino
    • NJS
    • DecryptJS
    • SpiderMonkey
  • Trap/monitor certain events
    • DOM calls
    • eval()s, etc

Fundamental Issue

Current JavaScript sandboxes fail to fully/properly emulate browser environment. These discrepancies are detectable by the JavaScript running inside the sandbox.

Fundamental Issue

.

DOM Testing

  • Using the DOM values
  • Detecting presence/lack of
  • Get and sets on values
  • Interacting with HTML elements

DOM Testing: Basic

  • Sandbox Specific Functions
    • gc()
    • clone()
    • trap()
    • untrap()
    • readline()
  • Malware forces SpiderMonkey to die
    • try {quit();} catch (e) { }; //more code here

Function Clobbering

  • JavaScript is highly dynamic
  • Can redefine functions at runtime!

Redefining print() as quit()