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



Similar documents
ASL IT SECURITY BEGINNERS WEB HACKING AND EXPLOITATION

SQL Injection January 23, 2013

Passing PCI Compliance How to Address the Application Security Mandates

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

The purpose of this report is to educate our prospective clients about capabilities of Hackers Locked.

Offensive Security. Advanced Web Attacks and Exploitation. Mati Aharoni Devon Kearns. v. 1.0

INTRUSION PROTECTION AGAINST SQL INJECTION ATTACKS USING REVERSE PROXY

Webapps Vulnerability Report

Where every interaction matters.

Attacking MongoDB. Firstov Mihail

Creating Stronger, Safer, Web Facing Code. JPL IT Security Mary Rivera June 17, 2011

OWASP OWASP. The OWASP Foundation Selected vulnerabilities in web management consoles of network devices

Application Intrusion Detection

Threat Modeling. Categorizing the nature and severity of system vulnerabilities. John B. Dickson, CISSP

Client logo placeholder XXX REPORT. Page 1 of 37

Web Application Hacking (Penetration Testing) 5-day Hands-On Course

EC-Council CAST CENTER FOR ADVANCED SECURITY TRAINING. CAST 619 Advanced SQLi Attacks and Countermeasures. Make The Difference CAST.

The Top Web Application Attacks: Are you vulnerable?

How I hacked PacketStorm ( )

Secure Web Application Coding Team Introductory Meeting December 1, :00 2:00PM Bits & Pieces Room, Sansom West Room 306 Agenda

CS 558 Internet Systems and Technologies

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

Top 10 Database. Misconfigurations.

1. Building Testing Environment

Advanced Web Security, Lab

ASL IT Security Advanced Web Exploitation Kung Fu V2.0

External Vulnerability Assessment. -Technical Summary- ABC ORGANIZATION

HTTPParameter Pollution. ChrysostomosDaniel

VIDEO intypedia007en LESSON 7: WEB APPLICATION SECURITY - INTRODUCTION TO SQL INJECTION TECHNIQUES. AUTHOR: Chema Alonso

Practical Identification of SQL Injection Vulnerabilities

PHP Magic Tricks: Type Juggling. PHP Magic Tricks: Type Juggling

SECURING APACHE : THE BASICS - III

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

Cross Site Scripting in Joomla Acajoom Component

Security Awareness For Website Administrators. State of Illinois Central Management Services Security and Compliance Solutions

Serious Threat. Targets for Attack. Characterization of Attack. SQL Injection 4/9/2010 COMP On August 17, 2009, the United States Justice

Common Security Vulnerabilities in Online Payment Systems

Perl In Secure Web Development

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

Web Application Guidelines

Ruby on Rails Secure Coding Recommendations

ICTN Enterprise Database Security Issues and Solutions

Using Foundstone CookieDigger to Analyze Web Session Management

STABLE & SECURE BANK lab writeup. Page 1 of 21

SQL Injection. By Artem Kazanstev, ITSO and Alex Beutel, Student

We protect you applications! No, you don t. Digicomp Hacking Day 2013 May 16 th 2013

No SQL! no injection? A talk on the state of NoSQL security

Hacking de aplicaciones Web

Check list for web developers

Essential IT Security Testing

APPLICATION SECURITY: FROM WEB TO MOBILE. DIFFERENT VECTORS AND NEW ATTACK

Penetration Testing Report Client: Business Solutions June 15 th 2015

Criteria for web application security check. Version

Application Security Testing. Generic Test Strategy

Hacking the WordpressEcosystem

Web application security: Testing for vulnerabilities

Data Breaches and Web Servers: The Giant Sucking Sound

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

A Review of Web Application Security for Preventing Cyber Crimes

Hacker Intelligence Initiative, Monthly Trend Report #17

CSCI110 Exercise 4: Database - MySQL

Hack Proof Your Webapps

SAST, DAST and Vulnerability Assessments, = 4

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

Exposed Database( SQL Server) Error messages Delicious food for Hackers

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

5 Mistakes to Avoid on Your Drupal Website

Project 2: Web Security Pitfalls

SECURITY TRENDS & VULNERABILITIES REVIEW 2015

Application Layer Encryption: Protecting against Application Logic and Session Theft Attacks. Whitepaper

Magento Security and Vulnerabilities. Roman Stepanov

Advanced PostgreSQL SQL Injection and Filter Bypass Techniques

SQL Injection Attack Lab

Columbia University Web Security Standards and Practices. Objective and Scope

Integrated Network Vulnerability Scanning & Penetration Testing SAINTcorporation.com

SQL Injection. Slides thanks to Prof. Shmatikov at UT Austin

David Rook. The Principles of Secure Development. OWASP Ireland Conference, Dublin

An Anatomy of a web hack: SQL injection explained

WHITE PAPER. FortiWeb and the OWASP Top 10 Mitigating the most dangerous application security threats

Thick Client Application Security

How To Fix A Web Application Security Vulnerability

Penetration Testing Lessons Learned. Security Research

NO SQL! NO INJECTION?

IOActive Security Advisory

Intrusion detection for web applications

MANAGED SECURITY TESTING

National Information Security Group The Top Web Application Hack Attacks. Danny Allan Director, Security Research

The Weakest Link: Mitigating Web Application Vulnerabilities. webscurity White Paper. webscurity Inc. Minneapolis, Minnesota USA

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

ASP.NET MVC Secure Coding 4-Day hands on Course. Course Syllabus

Securing SharePoint 101. Rob Rachwald Imperva

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

A SQL Injection : Internal Investigation of Injection, Detection and Prevention of SQL Injection Attacks

CTF Web Security Training. Engin Kirda

Still Aren't Doing. Frank Kim

Web application security

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

Transcription:

1

Secure Coding Code development practice Mitigates basic vulnerabilities XSS SQL Injection Made by security experts, for non-security experts Mainly developers In practice, commonly used as the only measure of security in the development cycle 2

How Do I Secure Coding?? There are Secure Coding courses A lot of courses Developers usually choose the same course as their peers Resulting in the same course being the only one taught in the same company Most developers usually pass only 1 or 2 of these courses in their entire career 3

Secure Coding Problems Most developers in a company pass the same course Same course Same mistakes Secure Coding focuses on input sanitization vulnerabilities Neglecting false assumptions and logical vulnerabilities Secure Coding provides a misguided sense of security Resulting in less CR, both internally and externally 4

Secure Coding Problems Secure coding gives you the feeling you are secure Without being secure But I guess I need to prove that 5

How To Prove A Point 101 How can I prove Secure Coding is a fallacy? Using 3 things 0-days 0-days Top-Secret exploits 0-days 6

Case Study 1 - MediaWiki The most popular Wiki platform Open Source PHP Runs on Wikipedia.org And 25,000 more sites Type of Check User Input Sanitization Dangerous Functions Language Quirks False Assumptions Implemented? 7

MediaWiki The integer in the box MediaWiki relies on external binaries For converting images Analyzing documents... and more // Make sure the page parameter is a valid number if ($params['page'] > $image->pagecount()) $params['page'] = $image->pagecount(); else if( $params['page'] < 1 ) $params['page'] = 1; exec('/usr/bin/convert'. // Execute the convert command... $params['page']... ); 8

MediaWiki The integer in the box What happens when page is a string? Var_dump((int) '0'); int(0) Var_dump((int) '123'); int(123) Var_dump((int) 'abcde'); int(0) Var_dump((int) '123abcde'); int(123) Var_dump((int) '1; ifconfig'); int(1) 9

Case Study 1 - MediaWiki CVE-2014-1610 Unauthenticated RCE on MediaWiki 10

Case Study 2 - vbulletin The most popular Forum platform Commercial PHP Runs on ubuntuforums.org And 32,000 more sites Type of Check User Input Sanitization Dangerous Functions Language Quirks False Assumptions Implemented? 11

vbulletin I Didn t See-rialize That Coming vbulletin developers are aware of dangerous functions eval exec popen 12

vbulletin I Didn t See-rialize That Coming Unserialize Creates a PHP value from a stored representation s:12:"hello, world"; "Hello, world" a:0:{} array() O:9:"ClassName":0:{} ClassName{ } When an object is unserialized, several magic methods are automatically called wakeup() Right after the unserialize operation destroy() When the object is destroyed tostring() When the object is converted to a string 13

vbulletin I Didn t See-rialize That Coming Using these magic methods, we can expand our attack surface As a bonus, because we control the object, we control its properties as well So down the rabbit hole we go! 14

vbulletin I Didn t See-rialize That Coming We create an vb_vurl object with the following destruct method: function destruct() { if (file_exists($this->tmpfile)) { @unlink($this->tmpfile); } } vb_vurl:: destruct() Because the tmpfile property is used in an unlink() call It is considered as a string 15

vbulletin I Didn t See-rialize That Coming If tmpfile was an object, tostring() would have been called So we use a vb_view object as our tmpfile property Which executes this code: public function tostring() { return $this->render(); } vb_view:: tostring() 16

vbulletin I Didn t See-rialize That Coming From render() we jump through several functions Until we finally reach this render() code: public function render() { $templatecode=$templatecache->gettemplate($this->template); @eval($templatecode); } Guess who controls $templatecode? 17

Case Study 2 - vbulletin CVE-2015-7808 Unauthenticated RCE on vbulletin 18

Case Study 3 - Bugzilla The most popular Bug Tracker Open Source Perl Runs on bugzilla.mozilla.org And 130 more major projects Type of Check User Input Sanitization Dangerous Functions Language Quirks False Assumptions Implemented? 19

Bugzilla Exploiting, The Quirking Way Perl features an expression called lists Well known and documented @array = (1, 2, 'a', 'b', 'c'); %dict = (1 => 2, 'a' => 'b'); 20

Bugzilla Exploiting, The Quirking Way A list inside a dictionary can create new dictionary pairs Known for Perl Pros, partially documented @list = ('f', 'lol', 'wat'); $hash = {'a' => 'b', 'c' => 'd', 'e' => 'f', @list }; 'lol' => 'wat' }; 21

Bugzilla Exploiting, The Quirking Way A list can be created from the user input Barely known and NOT documented index.cgi?foo=1&bar=a index.cgi?foo=1&foo=2&bar=a&bar=b 22

Bugzilla Exploiting, The Quirking Way Some privileges are given via an email regex Example: *@mozilla.org can view confidential Firefox bugs when a new user registers, his email address is validated using a token sent to the mailbox 23

Bugzilla Exploiting, The Quirking Way After the validation takes place, this code happens: my $otheruser = Bugzilla::User->create({ login_name => $login_name, realname => $cgi->param('realname'), cryptpassword => $password}); $login_name => The email address validated (extracted from the DB) $password => The user defined password (as a scalar) $cgi->param('realname') => Bingo! 24

Bugzilla Exploiting, The Quirking Way a=confirm_new_account&t=[registration _TOKEN]&passwd1=Password1!&passwd2=Password1! &realname=lolzor&realname=login_name&realname=admin@bugzilla.com my $otheruser = Bugzilla::User->create({ login_name => $login_name, realname => 'Lolzor', login_name => 'admin@bugzilla.com' cryptpassword => $password}); We control the email address We control the privileges group we join 25

Case Study 3 - Bugzilla CVE-2014-1572 Authentication mechanism bypass on Bugzilla For more information about this vuln, watch my 31C3 talk The Perl Jam 26

Case Study 4 - Magento The most popular ecommerce platform Open Source PHP Runs on (part of) ebay.com And 270,000 more sites Type of Check User Input Sanitization Dangerous Functions Language Quirks False Assumptions Implemented? 27

Magento Keep Going Forwarded Magento developers made sure regular users can t access the admin panel They checked the user session They checked its privileges They checked that the user is not disabled 28

Magento Keep Going Forwarded But how does Magento does all that? $requestedactionname = $request->getactionname(); if ($user) { // A user exist $user->reload(); // Check validity of user } if (! $user! $user->getid()) { // No user if ($request->getpost('login')) { // login TRY_TO_LOGIN } if (! $request->getparam('forwarded')) { $request->setcontroller('login'); } } 29

Magento Keep Going Forwarded Magento developers used the forwarded parameter as an internal redirect mechanism Used to allow components to create their own authentication mechanisms Unfortunately, they forgot this parameter can also be controlled by the user Using HTTP Parameters This effectively allows anyone to access the admin panel 30

Case Study 4 - Magento CVE-2015-1397, CVE-2015-1398, CVE-2015-1399 Authentication mechanism bypass SQLI 2 LFIs RFI 31

Case Study 5 - WordPress The most popular CMS/Blogging platform Open Source PHP WordPress is massively deployed It handles 126M users a month! Type of Check User Input Sanitization Dangerous Functions Language Quirks False Assumptions Implemented? 32

WordPress - How WordPress Works Any user can access the admin panel But using a capabilities system, not every admin page read_page read_post edit_posts install_themes edit_plugins Subscriber Administrator 33

WordPress - Exploiting The Un-Exploitable We assume we are subscribers at the site The lowest role possible We can only read public posts and pages Can t even comment We need more capabilities! 34

WordPress - Exploiting The Un-Exploitable How does WordPress check our capabilities? if(current_user_can('edit_posts')) // Can we edit posts? if(current_user_can('edit_post', 1)) // Can we edit post ID 1? Each role has specific permissions current_user_can() maps a requested capability into the appropriate role permission And returns true/false based on our permissions But how? 35

WordPress - Exploiting The Un-Exploitable current_user_can() is a giant SWITCH statement Let s look on the edit_post capability check Responsible for checking if the user can edit a specific post case 'edit_post': // Edit Post/Page case 'edit_page': $post = get_post( $args[0] ); // Get the post // If the post doesn't exist, no capabilities needed if ( empty( $post ) ) break; If the post ID doesn t exist => no permissions needed! 36

WordPress - Exploiting The Un-Exploitable We can access code that checks capabilities for a post ID, but doesn t check it exists But we want to be able to edit a post that does exist! How can we do that? 37

WordPress - The Need For Speed Using the capabilities bug, we could access the post editing code function edit_post( $post_data = null ) { if ( empty($post_data) ) $post_data = &$_POST; $post_id = (int) $post_data['post_id']; // Get the post ID $post = get_post( $post_id ); // Get the post $success = wp_update_post( $post_data ); // Update the post in the DB } 38

WordPress - The Need For Speed But before the DB update occurs, a post ID validation check takes place function wp_update_post($postarr = array(), $wp_error = false){ // First, get all of the original fields. $post = get_post($postarr['id'], ARRAY_A); } if ( is_null( $post ) ) { if ( $wp_error ) return new WP_Error('invalid_post', 'Invalid post'); return 0; }... 39

WordPress - The Need For Speed We re stuck :( We need an INVALID post ID for edit_post() But a VALID post ID for wp_update_post() Wait What if we could create the post between these function calls? 40

WordPress - The Need For Speed WordPress doesn t allow subscribers to create a post In fact, when we try to do so it blocks our access by calling wp_dashboard_quick_press() : switch($action) { case 'post-quickdraft-save': if (! current_user_can( 'edit_posts' ) ) $error_msg = "You don t have access to add new posts."; // If there s an error (no token, no capabilities) if ( $error_msg ) return wp_dashboard_quick_press( $error_msg ); 41

WordPress - The Need For Speed But what does wp_dashboard_quick_press() do? It creates a post. function wp_dashboard_quick_press( $error_msg = false ) {... $post = get_default_post_to_edit( 'post', true);... } 42

WordPress - The Need For Speed Now we can create a post But how do we create it exactly at the right time? We will delay the script By executing a lot of DB queries But again, how? 43

WordPress - The Need For Speed foreach ((array) $post_data['tax_input'] as $taxonomy => $terms) { // Make sure the terms variable is an array $terms = explode(',', trim( $terms, " \n\t\r\0\x0b," ) ); } // Fetch the required terms from the DB foreach ( $terms as $term ) { $_term = get_terms( $term ) ); } We control the taxonomy array Each element is inserted into get_terms() get_terms() executes an SQL SELECT query We control the array => we control the number of elements => We control the number of SELECT queries 44

WordPress - The Need For Speed Using the race condition, we were able to edit a real post 1. We send an edit post request with invalid post ID containing our large taxonomy array 2. While the script executes, we send a create post request, which creates that post 3. When the taxonomy queries are done, the post already exists in the DB Allowing us to update it as we wish 45

WordPress - PE ing Like It s 1999 Editing a post doesn t compromise anything But this Privilege Escalation granted us access to more code More code => More attack surface More attack surface => More vulnerabilities Using that attack surface, we discovered a: Persistent XSS on the front page of the site SQL Injection, allowing us to compromise the DB Basically, total WordPress PWNGE 46

Case Study 5 - WordPress CVE-2015-5623 Privilege Escalation CVE-2015-2213 SQL Injection CVE-2015-5714 Shortcode XSS CVE-2015-5715 Post Publish Privilege Escalation 47

Why Even Secure Coding?? Secure coding does not guarantee secure code It provides another layer of security Developers ARE NOT hackers Because they don t have the time to Because they don t have the budget to Because they (sometimes) don t have the skillset to 48

So What Should I Do? HIRE HACKERS TO DO THE HACKING Penetration Testing Code Reviews Consulting DO NOT rely on Secure Coding alone! 49

Thanks! 50