Android Packer. facing the challenges, building solutions. Rowland YU. Senior Threat Researcher Virus Bulletin 2014



Similar documents
The OWASP Foundation

Hacking your Droid ADITYA GUPTA

Pentesting Android Apps. Sneha Rajguru

Advanced ANDROID & ios Hands-on Exploitation

Post-Mortem Memory Analysis of Cold-Booted Android Devices

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

Beginners Guide to Android Reverse Engineering

This is DEEPerent: Tracking App behaviors with (Nothing changed) phone for Evasive android malware

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

Penetration Testing Android Applications

How To Develop Android On Your Computer Or Tablet Or Phone

Android Development. Marc Mc Loughlin

Mobile Application Security and Penetration Testing Syllabus

Messing with the Android Runtime

Mobile Application Security: Who, How and Why

l What is Android? l Getting Started l The Emulator l Hello World l ADB l Text to Speech l Other APIs (camera, bitmap, etc)

Overview. The Android operating system is like a cake consisting of various layers.

HP AppPulse Mobile. Adding HP AppPulse Mobile to Your Android App

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

Blackbox Android. Breaking Enterprise Class Applications and Secure Containers. Marc Blanchou Mathew Solnik 10/13/

Reversing Android Malware

Android Programming and Security

Mobile Application Security Testing ASSESSMENT & CODE REVIEW

Covering the global threat landscape

Android Basics. Xin Yang

Sandy. The Malicious Exploit Analysis. Static Analysis and Dynamic exploit analysis. Garage4Hackers

SYLLABUS MOBILE APPLICATION SECURITY AND PENETRATION TESTING. MASPT at a glance: v1.0 (28/01/2014) 10 highly practical modules

Frameworks & Android. Programmeertechnieken, Tim Cocx

An Introduction to Android Application Development. Serdar Akın, Haluk Tüfekçi

The Behavioral Analysis of Android Malware

Detecting Malware With Memory Forensics. Hal Pomeranz SANS Institute

OpenCV on Android Platforms

Introduction to Android

Smartphone Security for Android Applications

Introduction to Android. CSG250 Wireless Networks Fall, 2008

Smartphone market share

Version 7.7 PREEMPTIVE SOLUTIONS DASHO. User Guide

Introduction to Native Android Development with NDK

All Your Code Belongs To Us Dismantling Android Secrets With CodeInspect. Steven Arzt Secure Software Engineering Group Steven Arzt 1

AllJoyn Android Environment Setup Guide

Fahim Uddin 1. Java SDK

Post-Mortem Memory Analysis of Cold-Booted Android Devices

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

Intel Integrated Native Developer Experience (INDE): IDE Integration for Android*

AppUse - Android Pentest Platform Unified

Forensics II. Android reverse engineering Logs [repetition]

Detecting the One Percent: Advanced Targeted Malware Detection

Mobile security, forensics & malware analysis with Santoku Linux. * Copyright 2013 viaforensics, LLC. Proprietary Information.

Popular Android Exploits

Parasitics: The Next Generation. Vitaly Zaytsev Abhishek Karnik Joshua Phillips

TitanMist: Your First Step to Reversing Nirvana TitanMist. mist.reversinglabs.com

MASTER'S THESIS. Android Application Security with OWASP Mobile Top James King 2014

Obfuscation: know your enemy

Table of Contents. Adding Build Targets to the SDK 8 The Android Developer Tools (ADT) Plug-in for Eclipse 9

Attacking Obfuscated Code with IDA Pro. Chris Eagle

How to Create an Android Application using Eclipse on Windows 7

Mobile Application Development Android

AGENDA. Background. The Attack Surface. Case Studies. Binary Protections. Bypasses. Conclusions

Introduction to Android

Lab 4 In class Hands-on Android Debugging Tutorial

CHAD TILBURY.

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

Getting started with Android and App Engine

WebView addjavascriptinterface Remote Code Execution 23/09/2013

Islamic University of Gaza. Faculty of Engineering. Computer Engineering Department. Mobile Computing ECOM Eng. Wafaa Audah.

Chapter 2 Getting Started

Introduction to Android Development. Jeff Avery CS349, Mar 2013

Android Security Evaluation Framework

Introduction to NaviGenie SDK Client API for Android

Peeking into Pandora s Bochs. Instrumenting a Full System Emulator to Analyse Malicious Software

Tushar Dalvi Sr. Security Engineer at LinkedIn Penetration Tester. Responsible for securing a large suite mobile apps

Storm Worm & Botnet Analysis

CS378 -Mobile Computing. Android Overview and Android Development Environment

Leave The App Alone! - Attack and Defense of Android App Hijack

Threema security assessment

Defending Behind The Device Mobile Application Risks

Mobile Payment Security

ITG Software Engineering

Melde- und Analysestelle Informationssicherung MELANI Torpig/Mebroot Reverse Code Engineering (RCE)

Technical Note. TN_134 FTDI Android D2XX Driver

Running a Program on an AVD

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

Streamlined Malware Incident Response with EnCase

What else can you do with Android? Inside Android. Chris Simmonds. Embedded Linux Conference Europe Copyright 2010, 2net Limited.

ANDROID BASED MOBILE APPLICATION DEVELOPMENT and its SECURITY

Analysis of advanced issues in mobile security in android operating system

CROSS-PLATFORM MOBILE MALWARE - WRITE ONCE INFECT EVERYWHERE. William Lee & Xinran Wu {william.lee, xinran.wu}@sophos.com.

Two-factor Protection Scheme in Securing the Source Code of Android Applications

An Introduction to Android

Android Hands-On Labs

Friendly ARM MINI2440 & Dalvik Virtual Machine with Android

The Decaffeinated Robot

TEGRA X1 DEVELOPER TOOLS SEBASTIEN DOMINE, SR. DIRECTOR SW ENGINEERING

An Android-based Instant Message Application

Transcription:

Android Packer facing the challenges, building solutions Rowland YU Senior Threat Researcher Virus Bulletin 2014 1

What is Android Packer? Android packers are able to encrypt an original classes.dex file, decrypt the dex file to memory at runtime, and then execute via DexClassLoader. 2

What is Particular about Android Packer? Difference between Obfuscation and Packer Popular packer services Growth of packed threats Opening the black box of Android Packers 3

How to Evade Android Packer? Challenges Solutions Demonstration Summary The Future 4

Packer Obfuscation Difference between Obfuscation and Packer Investigate files from.apk Obfuscate & optimize binary XML files Encrypt strings, classes, add temp detection code and use Java reflection Build a new APK classes.dex junk Configure XML file New classes.dex Loader Build a new APK Pack classes.dex classes.dex Unpacker 5

Popular packer services Ijiami Protecting legitimate applications in loss of intellectual property Online Android packing services Anti-Tamper, Anti-Decompiler, Anti-Runtime injection, and Anti-Debug Employing virus scan engines to prevent malware being packed 6

Growth of Packed Threats 3000 2500 2000 1500 1000 500 0 13-07 13-08 13-09 13-10 13-11 13-12 14-01 14-02 14-03 14-04 14-05 14-06 14-07 14-08 Bangcle ApkProtect Ijiami 7

Opening the Black Box of Android Packers Pack Provider Added File Comments ApkProtect lib/armeabi/libapkprotect2.so // ARM shared native library binary Bangcle Ijiami assets/meta-data/manifest.mf assets/meta-data/rsa.pub assets/meta-data/rsa.sig assets/bangcle_classes.jar assets/bangcleplugin/collector.dex assets/bangcleplugin/container.dex assets/bangcleplugin/dgc assets/com.sophos.andrpacker assets/com.sophos.andrpacker.x86 assets/libsecexe.x86.so assets/libsecmain.x86.so lib/armeabi/libsecexe.so lib/armeabi/libsecmain.so META-INF/signed.bin META-INF/af.bin META-INF/sdata.bin assets/ijiami.dat lib/armeabi/libexecmain.so lib/armeabi/libexec.so // APK manifest file // Signature file // The real signature file with certificate // Encrypted original classes.dex file // Bangcle information collector plugin // Bangcle Implementation plugin // Bangcle plugin logfile // ARM executable file // x86 executable file // x86 shared native library binary // x86 native main binary // ARM shared native library binary // ARM native main binary // Ijiami signed binary file // Ijiami binary file // Ijiami RSA signature file // Encrypted original Apk file // ARM JNI load/unload native binary // ARM shared native library binary 8

Opening the Black Box of Android Packer Pack Provider Modified/Replaced File Comments ApkProtect classes.dex // Modified original classes.dex file Bangcle AndroidManifest.xml classes.dex // Configure to implement Bangcle class // classes.dex replaced by Bangcle Ijiami AndroidManifest.xml classes.dex // Configure to implement Ijiami class // classes.dex replaced by Ijiami 9

Code Tree of Decompiled classes.dex Original classes.dex ApkProtect Ijiami Bangcle 10

Investigation on Ijiami entrypoint Application class the start point to execute unpacker <application android:allowbackup="true" android:debuggable="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme"> <application android:allowbackup="true" android:debuggable="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:name="com.shell.superapplication" android:theme="@style/apptheme"> 11

Investigation on Ijiami working process libexec.so Its the main code is deinit. It verifies the signature and integrity of encrypted data. It decrypts assets/ijiami.dat to original classes.dex. libexecmain.so It calls deinit and startsload and run functions in Dalvik layer. 12

Investigation on Ijiami dex header modification Modify original dex header in memory The modification starts from the beginning of dex file to 0x28 bytes 13

Additional studies on Entrypoint of Bangcle source code ApplicationWrapper class public void oncreate() { super.oncreate(); if (Util.getCustomClassLoader() == null) { Util.runAll(this); } String str = FirstApplication; try { this.cl = ((DexClassLoader)Util.getCustomClassLoader()); realapplication = (Application)getClassLoader().loadClass(str).newInstance(); if (realapplication!= null) { localacall = ACall.getACall(); localacall.at1(realapplication, getbasecontext()); localacall.set2(this, realapplication, this.cl, getbasecontext()); } } 14

Additional studies on runall method of Bangcle Util class public static void runall(context paramcontext) { x86ctx = paramcontext; docheck(paramcontext); // checking integrity of classes.jar checkupdate(paramcontext); try { File localfile = new File("/data/data/" + paramcontext.getpackagename() + "/.cache/"); if (!localfile.exists()) { localfile.mkdir(); } checkx86(paramcontext); // If it is x86 platform, copy related library binary CopyBinaryFile(paramContext); // copy encrypted classes.jar and JNI binary createchildprocess(paramcontext); // create child processes trydo(paramcontext); runpkg(paramcontext, paramcontext.getpackagename()); // call MyClassLoader return; } 15

Additional studies on the ACall class of Bangcle deals with binary such as libsecexe.so in the Library layer of Android libsecexe.so is responsible for JNI call 16

Additional studies on Mutually tracing in three Bangcle processes to block analysis from debugging tools 17

Technology Review of Bangcle and Ijiami Anti-Temper checks the integrity check of encrypted dex. Anti-Decompiler decrypts the encrypted dex in memory and employs MyClassLoader to load decrypted original dex in runtime. Anti-Runtime injection It is impossible to establish relationship between ACall class with libsecexe.so due to the encryption. Anti-Debug Both packers use techniques to block analysis from debugging tools 18

PART 2 19

Facing Challenges - Ineffective reverse engineering (RE) tools IDA Pro Dex2jar Apktool BakSmali/Smali JEB 20

Facing Challenges - Failure of dynamic analysis systems 21

Facing Challenges - Runtime Anti-Debug gdb, gcore, memory searching, dd Anti-ptrace technique to block analysis from debugging tools 22

Facing Challenges - Difficult to detect by security solutions Certificate Package name AndroidManifest.xml 23

Building Solutions Acquire Memory 1. Initialize an Android build environment including path and required package on either Linux or OSX system. 2. Download the Android SDK and NDK. 3. Download the Android Kernel Source Code. 4. Cross Compile the Kernel. 5. Create AVD then Emulate the Custom Kernel with the AVD. 6. Download and Cross Compile LiME. 7. Load LiME on the Android Device/Emulator. 8. Acquire Memory. 24

Building Solutions Memory forensics with Volatility plugins linux_pslist gathers active tasks by walking the task_struct. linux_proc_maps gathers process maps for Linux. linux_dump_map writes selected process memory mappings to disk. 25

Building Solutions Memory forensics with Volatility plugins 26

Building Solutions Memory forensics with Volatility plugins apk_packer_find_dex signatures = { 'map_header' : 'rule map_header { \ strings: \ $hex = {00 00???? 01 00 00 00 00 00 00 00 01 00???????????? 70 00 00 00 02 00} \ } condition: $hex }' class apk_packer_find_dex(linux_common.abstractlinuxcommand): """Gather information about the dex Dump in Memory running in the system""" def init (self, config, *args, **kwargs): linux_common.abstractlinuxcommand. init (self, config, *args, **kwargs) self._config.add_option('pid', short_option='p', default=none, help='operate on a specific Android application Process ID', action='store', type='str') 27

def calculate(self): """ Required: Runs YARA search to find hits """ rules = yara.compile(sources = signatures) proc_maps = linux_proc_maps.linux_proc_maps(self._config).calculate() for task, vma in proc_maps: if not vma.vm_file:. proc_as = task.get_process_address_space() maxlen = vma.vm_end - vma.vm_start data = proc_as.zread(vma.vm_start, maxlen - 1) if data: for match in rules.match(data = data): for moffset, _name, _value in match.strings: (usize,) = struct.unpack('i', data[moffset - 4 : moffset]) i = 0 offset = moffset while i < usize: (maptype,) = struct.unpack('h', data[offset: offset+2]) (mapoffset,) = struct.unpack('i', data[offset+8: offset+12]) if maptype == 0x1000: yield task, vma, moffset - 4 - mapoffset, moffset break i += 1 offset += 12 28

Building Solutions Memory forensics with Volatility plugins apk_packer_find_dex def render_text(self, outfd, data): self.table_header(outfd, [("Task", "10"), ("VM Start", "[addrpad]"), ("VM End", "[addrpad]"), ("Dex Offset", "[addr]"), ("Map Offset", "[addr]")]) for (task, vma, offset, moffset) in data: self.table_row(outfd, task.pid, vma.vm_start, vma.vm_end, offset, moffset - 4) 29

Demonstration Memory Acquisition emulator -wipe-data -avd myavd -kernel ~/androidkernal/arch/arm/boot/zimage -show-kernel -verbose adb push ~/lime-forensics/src/lime-goldfish.ko /sdcard/lime.ko adb shell root@android:/ # insmod /sdcard/lime.ko "path=/sdcard/lime.dump format=lime" root@android:/ # ls -al /sdcard/lime.dump fls ~/.android/avd/myavd.avd/sdcard.img icat ~/.android/avd/myavd.avd/sdcard.img 27 > ~/lime.dmp 30

Demonstration Bangcle 1. Find PID: python ~/android-volatility/vol.py --profile=linuxgolfish- 2_6_29ARM -f Bangcle_lime.dmp linux_pslist 2. Find original dex in memory: python ~/android-volatility/vol.py --profile=linuxgolfish- 2_6_29ARM -f Bangcle_lime.dmp apk_packer_find_dex -p876 31

Demonstration Bangcle 3. Dump memory map: python ~/android-volatility/vol.py --profile=linuxgolfish- 2_6_29ARM -f Bangcle_lime.dmp linux_dump_map -p876 -s 0x4c10d000 --dump-dir ~/Downloads/ 4. Truncate to get original dex: 32

Demonstration Ijiami Patch DEX_FILE_MAGIC header 33

Detection Solution AndroidManifest.xml Classname in Bangcle Size of encrypted payload Resource files resources.arsc 34

Summary Popular Android packing service Ijiami and Bangcle Explosive growth of packed malware Anti-Temper, Anti-Decompiler, Anti-Runtime injection and Anti-Debug Challenges to security threat researchers Solutions Memory forensics with Volatility plugins Demonstration 35

The Future 36

Q&A 37