RIPS. A static source code analyser for vulnerabilities in PHP scripts. NDS Seminar. A static source code analyser for vulnerabilities in PHP scripts



Similar documents
RIPS - A static source code analyser for vulnerabilities in PHP scripts

RIPS - A static source code analyser for vulnerabilities in PHP scripts

Security Products Development. Leon Juranic

Pixy: A Static Analysis Tool for Detecting Web Application Vulnerabilities (Technical Report)

Toward A Taxonomy of Techniques to Detect Cross-site Scripting and SQL Injection Vulnerabilities

WebCruiser Web Vulnerability Scanner Test Report. Input Vector Test Cases Cases Count Report Pass Rate. Erroneous 200 Responses %

State of The Art: Automated Black Box Web Application Vulnerability Testing. Jason Bau, Elie Bursztein, Divij Gupta, John Mitchell

Hardening Joomla 1. HARDENING PHP. 1.1 Installing Suhosin. 1.2 Disable Remote Includes. 1.3 Disable Unneeded Functions & Classes

Automated vulnerability scanning and exploitation

3. Broken Account and Session Management. 4. Cross-Site Scripting (XSS) Flaws. Web browsers execute code sent from websites. Account Management

Application Security Testing. Erez Metula (CISSP), Founder Application Security Expert

Security Basics - Lessons From a Paranoid. Stuart Larsen Yahoo! Paranoids - Pentest

Network Security In Linux: Scanning and Hacking

Web Application Security Payloads. Andrés Riancho Director of Web Security OWASP AppSec USA Minneapolis

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

Securing PHP Based Web Application Using Vulnerability Injection

Cyber Security Challenge Australia 2014

CS 558 Internet Systems and Technologies

Web Vulnerability Assessment Report

Client logo placeholder XXX REPORT. Page 1 of 37

Automatic vs. Manual Code Analysis

Web Application Attacks And WAF Evasion

Web Application Vulnerability Testing with Nessus

Webapps Vulnerability Report

Detecting and Exploiting XSS with Xenotix XSS Exploit Framework

ICT. PHP coding. Universityy. in any

Web Application Report

Intrusion detection for web applications

Web development... the server side (of the force)

INFORMATION BROCHURE Certificate Course in Web Design Using PHP/MySQL

Integrated Network Vulnerability Scanning & Penetration Testing SAINTcorporation.com

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

Secure Application Development with the Zend Framework

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

ASL IT SECURITY BEGINNERS WEB HACKING AND EXPLOITATION

Attack Vector Detail Report Atlassian

Finding Your Way in Testing Jungle. A Learning Approach to Web Security Testing.

Institutionen för datavetenskap

External Vulnerability Assessment. -Technical Summary- ABC ORGANIZATION

WEB SECURITY CONCERNS THAT WEB VULNERABILITY SCANNING CAN IDENTIFY

Advanced Web Security, Lab

EVALUATING COMMERCIAL WEB APPLICATION SECURITY. By Aaron Parke

OWASP TOP 10 ILIA

QualysGuard WAS. Getting Started Guide Version 3.3. March 21, 2014

Chapter 1 Web Application (In)security 1

Web Application Threats and Vulnerabilities Web Server Hacking and Web Application Vulnerability

Cross Site Scripting in Joomla Acajoom Component

Shellshock. Oz Elisyan & Maxim Zavodchik

Secure in 2010? Broken in 2011! Matias Madou, PhD Principal Security Researcher

Web Application Security

Facebook Twitter YouTube Google Plus Website

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

Securing Network Software using Static Analysis

Adobe Systems Incorporated

Application security testing: Protecting your application and data

Early Vulnerability Detection for Supporting Secure Programming

HackMiami Web Application Scanner 2013 PwnOff

Source Code Review Using Static Analysis Tools

PHP Debugging. Draft: March 19, Christopher Vickery

COURSE CONTENT FOR WINTER TRAINING ON Web Development using PHP & MySql

Secure Coding. Code development practice Mitigates basic vulnerabilities. Made by security experts, for non-security experts

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

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

WHITEPAPER. Nessus Exploit Integration

Web Application Security

Exploiting nginx chunked overflow bug, the undisclosed attack vector

WebCruiser Web Vulnerability Scanner User Guide

Implementation of Web Application Firewall

Manage cloud infrastructures using Zend Framework

Web applications. Web security: web basics. HTTP requests. URLs. GET request. Myrto Arapinis School of Informatics University of Edinburgh

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

The Devils Behind Web Application Vulnerabilities

PHP Tutorial From beginner to master

Project 2: Web Security Pitfalls

A Test Suite for Basic CWE Effectiveness. Paul E. Black.

Systematically Enhancing Black-Box Web Vulnerability Scanners

Dissecting and digging application source code for vulnerabilities

Mavituna Security Ltd. Finance House, 522A Uxbridge Rd. Pinner. HA5 3PU / UK

Criteria for web application security check. Version

Fachgebiet Technische Informatik, Joachim Zumbrägel

SANS Dshield Webhoneypot Project. OWASP November 13th, The OWASP Foundation Jason Lam

Protection, Usability and Improvements in Reflected XSS Filters

Is Drupal secure? A high-level perspective on web vulnerabilities, Drupal s solutions, and how to maintain site security

Using Web Security Scanners to Detect Vulnerabilities in Web Services

Check list for web developers

Magento Security and Vulnerabilities. Roman Stepanov

Application Code Development Standards

Using a Web Server Test Bed to Analyze the Limitations of Web Application Vulnerability Scanners

1. Building Testing Environment

Transcription:

NDS Seminar 1

1.1 Motivation 1.2 PHP Vulnerabilities 1.3 Taint Analysis 1.4 Static VS Dynamic Code Analysis : RIPS 2.1 Configuration 2.2 The Tokenizer 2.3 Token Analysis 2.4 Webinterface 2.5 Results 2.6 Limitations & Future Work 2

3

1.1 Motivation - vulnerabilities 2.0 with web 2.0 - PHP is the most popular scripting language - 30% of all vulnerabilities were PHP related in 2009 - finding vulnerabilities can be automated (minimizes time and costs) - lots of free blackbox scanners available - very few open source whitebox scanners (for PHP) - Capture The Flag (CTF) contests 4

1.2 Basic Concept of PHP Vulnerabilities PVF user input (potentially vulnerable functions) vulnerability $_GET $_POST $_COOKIE $_FILES $_SERVER $_ENV... getenv() mysql_fetch_result() file_get_contents()... + system() fopen() eval() include() mysql_query() print() header() mail()... = Remote Command Execution File Disclosure Remote Code Execution Local/Remote File Inclusion SQL Injection Cross-Site Scripting HTTP Response Splitting Email Header Injection... 5

1.3 The Concept of Taint Analysis - identify PVF (file_get_contents(), system()) - trace back parameters and check if they are tainted 6

1.3 The Concept of Taint Analysis Not a vulnerability (file name cannot be influenced by a user): Vulnerability detected (user can execute system commands): /vuln.php?pass=foobar; nc l p 7777 e /bin/bash 7

1.4 Static VS Dynamic Code Analysis Static Source Code Analysis: - parse source code - lexical analysis (tokens) - interprocedual/flow-sensitive analysis - taint analysis Dynamic Code Analysis: - compile source code - parse byte code - taint analysis 8

1.4 Static VS Dynamic Code Analysis Static Source Code Analysis: - parse source code - lexical analysis (tokens) - interprocedual/flow-sensitive analysis - taint analysis Dynamic Code Analysis: - compile source code - parse byte code - taint analysis 9

10

2.1 Configuration PVF parameter securing functions system 1 escapeshellarg, escapeshellcmd file_put_contents 1,2 printf 0 htmlentities, htmlspecialchars... array_walk_recursive 2 preg_replace_callback 1,2 preg_quote RIPS in its current state scans for 167 PVF 11

2.1 Configuration global securing functions intval count round strlen md5 base64_encode... user input $_GET $_POST $_COOKIE $_FILES $_SERVER $_ENV... file input file_get_contents zip_read... database input mysql_fetch_array mysql_fetch_row... 12

2.2 Most apparent approach - grep / search by regular expression for PVF: $lines = file($file); foreach($lines as $line) { if(preg_match(' /exec\(.*\$/ ', $line)) echo 'vulnerable: '. $line; } - fail: exec ($cmd); noexec($cmd); /* exec($cmd); */ $t='exec() and $var'; exec('./transfer $100'); 13

2.2 Most apparent approach - grep / search by regular expression for PVF: $lines = file($file); foreach($lines as $line) { if(preg_match(' /exec\(.*\$/ ', $line)) echo 'vulnerable: '. $line; } - fail: exec ($cmd); noexec($cmd); /* exec($cmd); */ $t='exec() and $var'; exec('./transfer $100'); 14

2.2 The Tokenizer - splits source code into tokens for correct analysis - token_get_all() parses the given source string into PHP language tokens (using the Zend engine's lexical scanner) array token_get_all(string $source) - returns three element array or single character for each token array(token_name, STRING, LINENR) 15

2.2 The Tokenizer token_get_all(): 1 <?php 2 $cmd = $_GET['cmd']; 3 system($cmd); 4?> 16 array( array(t_open_tag, '<?php', 1), array(t_variable, '$cmd', 2), array(t_whitespace, ' ', 2), '=', array(t_whitespace, ' ', 2), array(t_variable, '$_GET', 2), '[', array(t_constant_encapsed_string, 'cmd', 2), ']', ';', array(t_string, 'system', 3), '(', array(t_variable, '$cmd', 3), ')', ';', array(t_close_tag, '?>', 4) );

2.2 The Tokenizer token_get_all(): 1 <?php 2 $cmd = $_GET['cmd']; 3 system($cmd); 4?> delete insignificant tokens for correct analysis 17 array( array(t_open_tag, '<?php', 1), array(t_variable, '$cmd', 2), array(t_whitespace, ' ', 2), '=', array(t_whitespace, ' ', 2), array(t_variable, '$_GET', 2), '[', array(t_constant_encapsed_string, 'cmd', 2), ']', ';', array(t_string, 'system', 3), '(', array(t_variable, '$cmd', 3), ')', ';', array(t_close_tag, '?>', 4) );

2.2 The Tokenizer Fix token list: 1 if(isset($_get['cmd'])) 2 $cmd = $_GET['cmd']; 3 else 4 $cmd = '2010'; 5 system('cal '. $cmd); 18

2.2 The Tokenizer Fix token list: 1 if(isset($_get['cmd'])) 2 { $cmd = $_GET['cmd']; } 3 else 4 { $cmd = '2010'; } 5 system('cal '. $cmd); Add braces for correct token analysis 19

2.3 Token Analysis - loop through all tokens, detect connected language constructs $tokens = fix_tokens( token_get_all($code) ); foreach($tokens as $token) { list($token_name, $token_value, $line_nr) = $token; } if($token_name === T_VARIABLE &&... if($token_name === T_STRING &&... if($token_name === T_FUNCTION &&...... 20

2.3 Token Analysis (flow-sensitive) curly braces if(condition) {...} T_FUNCTION function foo($a, $b) {...} T_R ETUR N function check($a) {return (int)$a;} T_INC LUDE include($base_dir.'index.php'); T_EXIT if(empty($a)) exit; 21

2.3 Token Analysis T_VAR IAB LE global $text[] = 'hello'; - identify variable declarations - add to either local (in function) or global variable list - add current program flow dependency Variable Declaration Dependency $m $m = $_GET['mode']; $b $b+=$a; if($m == 2) $c['name'] $c['name'] = $b; $d while($d=fopen($c['name'], 'r')) 22

2.3 Token Analysis (taint-style) T_S TR ING exec($a); - check if function in PVF list - trace parameters with local or global variable list - fetch parameter from variable list - trace all other variables in variable declaration - detect securing - loop until declaration not found or tainted by user input - if tainted and not secured: - output tree of traced parameters - add dependencies 23

2.3 Token Analysis (taint-style) 1 $default = 'sleep 1'; 2 if(isset($_get['cmd'])) { 3 $cmd = $_GET['cmd']; 4 } else { 5 $cmd = $default; 6 } 7 exec($cmd); Registers in_func 0 braces_open 0 Variable List $default = 'sleep 1'; $cmd = $_GET['cmd']; if $cmd = $default; else Dependency Stack PVF Config system, exec,... User Input Config $_GET, $POST,... 24

2.3 Token Analysis (interprocedual) Vulnerability in function declaration detected: <?php function myexec($a,$b,$c) { exec($b); } $aa = 'test'; $bb = $_GET['cmd']; myexec($aa, $bb, $cc);?> PVF param securing functions exec 1 escapeshellarg,...... myexec 2 escapeshellarg,... 25

2.4 Webinterface - choose verbosity level 1-5 - choose vulnerability type - integrated code viewer (highlights vulnerable lines) - mouse-over for user defined functions - jumping between user defined function declarations and calls - integrated exploit creator - show list of entry points (user input) - show list of user defined functions - syntax highlighting with 7 different stylesheets 26

2.5 Results - source code of virtual online banking internship platform - 16870 lines in 84 files scanned refl. XSS pers. XSS SQL Inj. File Discl. Code Eval RCE HRS False Pos. Time / seconds 1. user input tainted 1/2+1 0/1 2/2 1/1 1/1 1/1 +1 3 2.277 2. File/DB tainted +1 1/2+1 1/1 2/2 1/1 1/1 1/1 +1 19 2.359 3. secured +1,2 2/2+1 1/1 2/2 1/1 1/1 1/1 +1 151 2.707 - RIPS finds known and unknown security vulnerabilities - missed flaws can be found with higher verbosity level (FP!) 27

2.6 Limitations & Future Work - implementing a control flow graph (CFG) $v = $_GET['v']; if($a == $b) $v = 'hello'; system($v); - automatic type casts $vuln=$_get['v']; $secure = $vuln + 1; exec($secure); - object oriented programming only partially supported - dynamic includes, function calls, variables include(str_replace($base_dir, '.', ''). $file); $a = base64_decode('c3lzdgvt'); $a($_get['v']); $$b = $_GET['v']; 28

29

+ new approach of open source PHP vulnerability scanner written in PHP + fast, capable of finding known and unknown security flaws + vulnerabilities are easily traceable and exploitable - RIPS makes assumptions on the program code - some limitations regarding OOP, data types and data flow - false positives / false negatives manual review has to be made (verbosity level) 30

+ RIPS helps analysing PHP source code for security flaws - RIPS is not (yet ;) an ultimate security flaw finder 31

RIPS was released during the Month of PHP Security: http://www.php-security.org It is open source (BSD License) and freely available at: http://sourceforge.net/projects/rips-scanner/ Download! Scan! Feedback is highly appreciated. 32

Questions? 33

Demo? 34

Thank you...... all for you attention... Dominik Birk for supervising 35