Understanding and Automatically Preventing Injection Attacks on Node.js

Similar documents
Synode: Understanding and Automatically Preventing Injection Attacks on Node.js

Synode: Understanding and Automatically Preventing Injection Attacks on Node.js

Understanding and Automatically Preventing Injection Attacks on Node.js

ZigZag - Automatically Hardening Web Applications Against Client-side Validation Vulnerabilities

OWASP Top 10 The Ten Most Critical Web Application Security Risks

Sandboxing Untrusted Code: Software-Based Fault Isolation (SFI)

Securing Production Applications & Data at Runtime. Prevoty

DLint: Dynamically Checking Bad Coding Practices in JavaScript

Freezing the Web: A Study of ReDoS Vulnerabilities in JavaScript-based Web Servers

The security of Mozilla Firefox s Extensions. Kristjan Krips

Code-Reuse Attacks for the Web: Breaking XSS mitigations via Script Gadgets

VirtualSwindle: An Automated Attack Against In-App Billing on Android

SoK: Eternal War in Memory Laszlo Szekeres, Mathias Payer, Tao Wei, and Dawn Song In: Oakland 14

DLint: Dynamically Checking Bad Coding Practices in JavaScript

Defend Your Web Applications Against the OWASP Top 10 Security Risks. Speaker Name, Job Title

DreamFactory Security Guide

Web Security: Vulnerabilities & Attacks

ISOLATION DEFENSES GRAD SEC OCT

Practical Techniques for Regeneration and Immunization of COTS Applications

ISSA: EXPLOITATION AND SECURITY OF SAAS APPLICATIONS. Waqas Nazir - CEO - DigitSec, Inc.

Threat Modeling. Bart De Win Secure Application Development Course, Credits to

We will show you how we bypassed every XSS mitigation we tested. Mitigation bypass-ability via script gadget chains in 16 popular libraries

Application Security through a Hacker s Eyes James Walden Northern Kentucky University

C1: Define Security Requirements

WHITE PAPER. AirGap. The Technology That Makes Isla a Powerful Web Malware Isolation System

TypeDevil: Dynamic Type Inconsistency Analysis for JavaScript

Advanced Threat Defense Certification Testing Report. Trend Micro Incorporated Trend Micro Deep Discovery Inspector

CuriousDroid: Automated User Interface Interaction for Android Application Analysis Sandboxes

Saving Time and Costs with Virtual Patching and Legacy Application Modernizing

Defining a Model for Defense in Depth

Static analysis of PHP applications

Sandboxing untrusted code: policies and mechanisms

Ex-Ray: Detection of History-Leaking Browser Extensions

Security. CSC309 TA: Sukwon Oh

At a Glance: Symantec Security.cloud vs Microsoft O365 E3

in memory: an evolution of attacks Mathias Payer Purdue University

Generating String Attack Inputs Using Constrained Symbolic Execution. presented by Kinga Dobolyi

2 Lecture Embedded System Security A.-R. Darmstadt, Android Security Extensions

Looking Forward: Challenges in Mobile Security. John Mitchell Stanford University

CERT C++ COMPLIANCE ENFORCEMENT

Inject malicious code Call any library functions Modify the original code

How to Identify Advanced Persistent, Targeted Malware Threats with Multidimensional Analysis

Maximum Security with Minimum Impact : Going Beyond Next Gen

JITProf: Pinpointing JIT-Unfriendly JavaScript Code

OWASP AppSec Research The OWASP Foundation New Insights into Clickjacking

Injection. CSC 482/582: Computer Security Slide #1

Subversive-C: Abusing and Protecting Dynamic Message Dispatch

Stefan Heule, Devon Rifkin, Alejandro Russo, Deian Stefan. Stanford University, Chalmers University of Technology

Node.js. Could a few lines of code it all up? Head of AppSec Research

DLint: Dynamically Checking Bad Coding Practices in JavaScript

Node.js Vulnerabilities

Ch 1: The Mobile Risk Ecosystem. CNIT 128: Hacking Mobile Devices. Updated

DEFENSIVE PROGRAMMING. Lecture for EDA 263 Magnus Almgren Department of Computer Science and Engineering Chalmers University of Technology

Securing Software Applications Using Dynamic Dataflow Analysis. OWASP June 16, The OWASP Foundation

Web Application Vulnerabilities: OWASP Top 10 Revisited

BOOSTING THE SECURITY

Trusted Types - W3C TPAC

WHITEPAPER THE EVOLUTION OF APPSEC: FROM WAFS TO AUTONOMOUS APPLICATION PROTECTION

SYMANTEC ENTERPRISE SECURITY. Symantec Internet Security Threat Report September 2005 Power and Energy Industry Data Sheet

The Top 6 WAF Essentials to Achieve Application Security Efficacy

TangeloHub Documentation

Performance Issues and Optimizations in JavaScript: An Empirical Study

An Introduction to the Waratek Application Security Platform

IS 2620: Developing Secure Systems. Building Security In Lecture 2

Advanced Threat Defense Certification Testing Report. Symantec Corporation Symantec Advanced Threat Protection

CFIXX: Object Type Integrity. Nathan Burow, Derrick McKee, Scott A. Carr, Mathias Payer

Department of Electrical Engineering and Computer Science MASSACHUSETTS INSTITUTE OF TECHNOLOGY Fall Quiz I

Static Analysis. Systems and Internet Infrastructure Security

AN EVALUATION OF THE GOOGLE CHROME EXTENSION SECURITY ARCHITECTURE

Securing Untrusted Code


TREND MICRO SMART PROTECTION SUITES

Who is Docker and how he can help us? Heino Talvik

TREND MICRO SMART PROTECTION SUITES

Web Security: Vulnerabilities & Attacks

Buffer overflow background

Program Testing and Analysis: Manual Testing Prof. Dr. Michael Pradel Software Lab, TU Darmstadt

Application Security Using Runtime Protection

COMP 2718: Shell Scripts: Part 1. By: Dr. Andrew Vardy

CS261 Scribe Notes: Secure Computation 1

ROSAEC Survey Workshop SELab. Soohyun Baik

SentinelOne Technical Brief

BUFFERZONE Advanced Endpoint Security

Using Threat Modeling To Find Design Flaws

Security Philosophy. Humans have difficulty understanding risk

Configuring BIG-IP ASM v12.1 Application Security Manager

Lecture 10. Denial of Service Attacks (cont d) Thursday 24/12/2015

The Mimecast Security Risk Assessment Quarterly Report May 2017

An Introduction to Runtime Application Self-Protection (RASP)

Self-defending software: Automatically patching errors in deployed software

QuantDroid: Quantitative Approach towards Mitigating Privilege Escalation on Android

Detecting Drive-by-Download Attacks based on HTTP Context-Types Ryo Kiire, Shigeki Goto Waseda University

On Mobile Malware Infections N. Asokan

BREAKTHROUGH CYBER SECURITY FREQUENTLY ASKED QUESTIONS

Honours/Master/PhD Thesis Projects Supervised by Dr. Yulei Sui

last time: command injection

Building Secure PHP Apps

RKN 2015 Application Layer Short Summary

Defense-in-depth techniques. for modern web applications

Browser Exploits? Grab em by the Collar! Presented By: Debasish Mandal

Transcription:

Understanding and Automatically Preventing Injection Attacks on Node.js Michael Pradel TU Darmstadt Joint work with Cristian Staicu (TU Darmstadt) and Ben Livshits (Microsoft Research, Redmond) 1

Why JavaScript? Relevant and challenging Rank of top languages on GitHub over time (Source: GitHub.com) 2

Why JavaScript? Relevant and challenging 1096 pages 153 pages 3

Motivation: JavaScript (In)Security JavaScript: Popular beyond the browser Client-side web app Browser Operating system 4

Motivation: JavaScript (In)Security JavaScript: Popular beyond the browser Client-side web app Server-side or desktop app Mobile app Browser Node.js Dalvik VM Operating system Operating system Operating system 4

Motivation: JavaScript (In)Security JavaScript: Popular beyond the browser Sandbox Client-side web app Server-side or desktop app Sandbox Mobile app Browser Node.js Dalvik VM Operating system Operating system Operating system 4

Motivation: JavaScript (In)Security JavaScript: Popular beyond the browser Sandbox Client-side web app No sandbox! Server-side or desktop app Sandbox Mobile app Browser Node.js Dalvik VM Operating system Operating system Operating system 4

Culture of Naive Reuse Node.js code: Builds on 3rd-party code Over 300.000 modules No specified trust relationships between modules Many indirect dependences 5

Culture of Naive Reuse Node.js code: Builds on 3rd-party code Over 300.000 modules No specified trust relationships between modules Many indirect dependences Risk of vulnerable and malicious code 5

Real Example: Growl Module var msg = /* receive growl(msg); from network */ 6

Real Example: Growl Module var msg = /* receive growl(msg); from network */ Growl module: Platform-specific command to show notifications Pass message to command without any checks 6

Running Example function backupfile(name, ext) { var cmd = []; cmd.push("cp"); cmd.push(name + "." + ext); cmd.push(" /.localbackup/"); exec(cmd.join(" ")); var kind = (ext === "jpg")? "pics" : "other"; console.log(eval("messages.backup_" + kind)); } 7

Running Example function backupfile(name, ext) { } var cmd = []; cmd.push("cp"); cmd.push(name + "." + ext); cmd.push(" /.localbackup/"); exec(cmd.join(" ")); Construct shell command Execute it var kind = (ext === "jpg")? "pics" : "other"; console.log(eval("messages.backup_" + kind)); 7

Running Example function backupfile(name, ext) { var cmd = []; cmd.push("cp"); cmd.push(name + "." + ext); cmd.push(" /.localbackup/"); exec(cmd.join(" ")); var kind = (ext === "jpg")? "pics" : "other"; console.log(eval("messages.backup_" + kind)); } Construct JavaScript code and execute it 7

Running Example function backupfile(name, ext) { var cmd = []; } cmd.push("cp"); cmd.push(name + "." + ext); cmd.push(" /.localbackup/"); exec(cmd.join(" ")); Injection APIs: Interpret string as code var kind = (ext === "jpg")? "pics" : "other"; console.log(eval("messages.backup_" + kind)); 7

Running Example function backupfile(name, ext) { var cmd = []; cmd.push("cp"); cmd.push(name + "." + ext); cmd.push(" /.localbackup/"); exec(cmd.join(" ")); var kind = (ext === "jpg")? "pics" : "other"; console.log(eval("messages.backup_" + kind)); } Injection attack: backupfile("-h && rm -rf * && echo ", "") 7

Our Contributions 1. Study of injection vulnerabilities First large-scale study of Node.js security 236K modules, 816M lines of JavaScript 2. Repair of vulnerabilities Static analysis and runtime enforcement Automatic and easy to deploy Small overhead and high accuracy 8

Our Contributions 1. Study of injection vulnerabilities First large-scale study of Node.js security 236K modules, 816M lines of JavaScript 2. Repair of vulnerabilities Static analysis and runtime enforcement Automatic and easy to deploy Small overhead and high accuracy 8

Study: Prevalence Are injection vulnerabilities widespread? 9

Study: Prevalence Are injection vulnerabilities widespread? 9

Study: Prevalence Are injection vulnerabilities widespread? Direct uses 9

Study: Prevalence Are injection vulnerabilities widespread? Indirect uses via other modules 9

Study: Prevalence Are injection vulnerabilities widespread? Manual inspection of 150 call sites Attacker-controlled data may reach API: 58% Defense mechanisms None: 90% Regular expression: 9% 9

Study: Developer Reactions Do developers fix vulnerabilities? Reported 20 previously unknown vulnerabilities After several months, only 3 fixed 10

Study: Developer Reactions Do developers fix vulnerabilities? Reported 20 previously unknown vulnerabilities After several months, only 3 fixed 10

Study: Developer Reactions Do developers fix vulnerabilities? Reported 20 previously unknown vulnerabilities After several months, only 3 fixed Need mitigation technique that requires very little developer attention 10

Our Contributions 1. Study of injection vulnerabilities First large-scale study of Node.js security 236K modules, 816M lines of JavaScript 2. Repair of vulnerabilities Static analysis and runtime enforcement Automatic and easy to deploy Small overhead and high accuracy 11

Our Contributions 1. Study of injection vulnerabilities First large-scale study of Node.js security 236K modules, 816M lines of JavaScript 2. Repair of vulnerabilities Static analysis and runtime enforcement Automatic and easy to deploy Small overhead and high accuracy 11

Preventing Injections Vulnerable code Static analysis String templates Statically safe code Synthesize policy Code with Runtime inputs runtime checks Dynamic enforcement Safe runtime behavior 12

Static Analysis: Template Trees 1. Backward data flow analysis Overapproximate strings passed to injection API Represent possible values as a tree 13

Static Analysis: Template Trees 1. Backward data flow analysis Overapproximate strings passed to injection API Represent possible values as a tree function backupfile(name, ext) { var cmd = []; cmd.push("cp"); cmd.push(name + "." + ext); cmd.push(" /.localbackup/"); exec(cmd.join(" ")); } 13

Static Analysis: Template Trees 1. Backward data flow analysis Overapproximate strings passed to injection API Represent possible values as a tree function backupfile(name, ext) { var cmd = []; cmd.push("cp"); cmd.push(name + "." + ext); cmd.push(" /.localbackup/"); exec(cmd.join(" ")); } $cmd join 13

Static Analysis: Template Trees 1. Backward data flow analysis Overapproximate strings passed to injection API Represent possible values as a tree function backupfile(name, ext) { var cmd = []; cmd.push("cp"); cmd.push(name + "." + ext); cmd.push(" /.localbackup/"); exec(cmd.join(" ")); } join push $cmd /.localbackup/ 13

Static Analysis: Template Trees 1. Backward data flow analysis Overapproximate strings passed to injection API Represent possible values as a tree function backupfile(name, ext) { var cmd = []; cmd.push("cp"); cmd.push(name + "." + ext); cmd.push(" /.localbackup/"); exec(cmd.join(" ")); } $cmd push join push /.localbackup/ + $name. $ext 13

Static Analysis: Template Trees 1. Backward data flow analysis Overapproximate strings passed to injection API Represent possible values as a tree function backupfile(name, ext) { var cmd = []; cmd.push("cp"); cmd.push(name + "." + ext); cmd.push(" /.localbackup/"); exec(cmd.join(" ")); } join push push /.localbackup/ push + $cmd cp $name. $ext 13

Static Analysis: Template Trees 1. Backward data flow analysis Overapproximate strings passed to injection API Represent possible values as a tree function backupfile(name, ext) { } var cmd = []; cmd.push("cp"); cmd.push(name + "." + ext); cmd.push(" /.localbackup/"); exec(cmd.join(" ")); empty array push push push join /.localbackup/ + cp $name. $ext 13

Static Analysis: Templates 2. Evaluate template trees into templates Statically model operations (bottom-up) Unknown parts to be filled at runtime 14

Static Analysis: Templates 2. Evaluate template trees into templates Statically model operations (bottom-up) Unknown parts to be filled at runtime join push push /.localbackup/ push + empty array cp $name. $ext cp $name.$ext /.localbackup/ 14

Synthesizing a Policy Create runtime policy from templates Enforce structure via partial AST For unknown parts, allow only benign AST nodes 15

Synthesizing a Policy Create runtime policy from templates Enforce structure via partial AST For unknown parts, allow only benign AST nodes cp $name.$ext /.localbackup/ Bash grammar Command Arguments cp??? /.localbackup/ 15

Runtime Enforcement Enforce policy on strings passed to injection APIs Policy: Command Arguments cp??? /.localbackup/ 16

Runtime Enforcement Enforce policy on strings passed to injection APIs Policy: Runtime string: cp f.txt /.localbackup/ Command Command Arguments Arguments cp cp??? /.localbackup/ f.txt /.localbackup/ 16

Runtime Enforcement Enforce policy on strings passed to injection APIs Policy: Runtime string: cp f.txt /.localbackup/ Command Command Accepted Arguments Arguments cp cp??? /.localbackup/ f.txt /.localbackup/ 16

Runtime Enforcement Enforce policy on strings passed to injection APIs Policy: Command Runtime string: cp -h && rm -rf * && echo /.localbackup/ CompoundCmd Arguments Command Command Command cp.........??? /.localbackup/... 16

Runtime Enforcement Enforce policy on strings passed to injection APIs Policy: Command Runtime string: cp -h && rm -rf * && echo /.localbackup/ CompoundCmd Arguments Command Command Command cp.........??? /.localbackup/... Rejected 16

Evaluation: Static Analysis Setup: 51K call sites of injection APIs Precision: Statically safe: To be checked at runtime: 63.3% 36.7% Most call sites: Performance: 4.4 seconds per module At least 10 known characters Only 1 hole 17

Evaluation: Runtime Enforcement Setup 24 modules 56 benign and 65 malicious inputs Results: Zero false negatives (i.e., no missed injections) Five false positives (i.e., overly conservative) Overhead (avg.): 0.74 milliseconds per call 18

Conclusion Understand injection vulnerabilities First large-scale empirical study of Node.js (in)security Detect and prevent injections Static inference of expected string values AST-based runtime policy Automated repair of vulnerabilities More details: Technical report on my web site 19