SlideShare a Scribd company logo
Memory Analysis of the Dalvik
 (Android) Virtual Machine
            Andrew Case
     Digital Forensics Solutions
Who Am I?
• Security Analyst at Digital Forensics Solutions
  – Also perform wide ranging forensics investigations
• Volatility Developer
• Former Blackhat and DFRWS speaker




                                                     2
Agenda
• What is Dalvik / why do we care?
• Brief overview of memory forensics
• Extracting allocated and historical data from
  Dalvik instances
• Target specific Android applications




                                                  3
What is Dalvik?
• Dalvik is the software VM for all Android
  applications
• Nearly identical to the Java Virtual Machine
  (JVM) [1]
• Open source, written in C / Java




                                                 4
Why do we care?
• Android-based phones leading in US mobile
  market
  – Which makes for many phones to investigate
• Memory forensics capabilities against Android
  applications have numerous uses/implications
• Entire forensics community (LEO, .gov, private
  firms) already urging development of such
  capabilities


                                                 5
Memory Forensics Introduction
• Memory forensics is vital to orderly recovery of
  runtime information
• Unstructured methods (strings, grep, etc) are
  brittle and only recover superficial info
• Structured methods allow for recovery of data
  structures, variables, and code from memory
• Previous work at operating system level led to
  recovery of processes, open files, network
  connections, etc [4,5]

                                                     6
Memory Analysis Process
• First, need to acquire memory
  – Acquisition depends on environment [6]
• Next, requires locating information in memory
  and interpreting it correctly
  – Also requires re-implementing functionality offline
• Then it needs to be displayed in a useful way
  to the investigator



                                                      7
Dalvik Memory Analysis




                         8
Acquiring Memory – Approach 1
• The normal method is to acquire a complete
  capture of physical RAM
• Works well when analyzing kernel data
  structures as their pages are not swapped out
• Allows for recovery of allocated and historical
  processes, open files, network connections,
  and so on



                                                    9
Approach 1 on Android
• Without /dev/mem support, need a LKM to
  read memory
• No current module works for Android (ARM)
• We developed our own (mostly by @jtsylve)
• Benefits of full capture:
  – Can target any process (including its mappings)
  – Can recover information from unmapped pages in
    processes


                                                  10
Acquiring Memory – Approach 2
• Memory can be acquired on a per-process
  basis
• Ensures that all pages of the process will be
  acquired
• Easiest to perform with memfetch[8]
  – After a few small changes, was statically compiled
    for ARM
• No unmapped pages will be recovered though
  – Heap and GC don’t munmap immediately
                                                     11
Analyzing C vs Java
• Most previous forensics research has had the
  “luxury” of analyzing C
  – Nearly 1:1 mapping of code/data to in-memory
    layout
• Declaration of a C “string”
  – char buffer*+ = “Hello World”;
• Memory Layout (xxd)
  – 4865 6c6c 6f20 576f 726c 6400 Hello World.


                                                   12
A Dalvik String in Memory
• First, need the address of the “StringObject”
• Next, need the offsets of the
  “java/lang/String” value and byte offset
  members
• StringObject + value offset leads us to an
  “ArrayObject”
• ArrayObject + byte offset leads to an UTF-16
  array of characters
• … finally we have the string (in Unicode)
                                                  13
Now for the memory analysis…
• The real goal of the research was to be able to
  locate arbitrary class instances and fields in
  memory
• Other goals included replicating commonly
  used features of the Android debugging
  framework




                                                14
Locating Data Structures
• The base of Dalvik loads as a shared library
  (libdvm.so)
• Contains global variables that we use to locate
  classes and other information
• Also contains the C structures needed to parse
  and gather evidence we need




                                                15
Gathering libdvm’s Structures
1) Grab the shared library from the phone (adb)
2) Use Volatility’s dwarfparse.py:
   • Builds a profile of C structures along with
     members, types, and byte offsets
   • Records offsets of global variables
3) Example structure definition
  'ClassObject': [ 0xa0, {        Class name and size
      'obj': [0x0, ['Object']],   member name, offset,
                                  and type

                                                         16
Volatility Plugin Sample
• Accessing structures is as simple as knowing
  the type and offset
    intval = obj.Object(“int”, offset=intOffset, ..)
• Volatility code to access ‘descriptor’ of an
  ‘Object’:
    o = obj.Object("Object", offset=objectAddress, ..)
    c = obj.Object("ClassObject", offset=o.clazz, …)
    desc = linux_common.get_string(c.descriptor)


                                                         17
gDvm
• gDvm is a global structure of type DvmGlobals
• Holds info about a specific Dalvik instance
• Used to locate a number of structures needed
  for analysis




                                              18
Locating Loaded Classes
• gDvm.loadedClasses is a hash table of
  ClassObjects for each loaded class
• Hash table is stored as an array
• Analysis code walks the backing array and
  handles active entries
  – Inactive entries are NULL or have a pointer value
    of 0xcbcacccd



                                                        19
Information Per Class
• Type and (often) name of the source code file
• Information on backing DexFile
  – DexFile stores everything Dalvik cares about for a
    binary
• Data Fields
  – Static
  – Instance
• Methods
  – Name and Type
  – Location of Instructions

                                                         20
Static Fields
• Stored once per class (not instance)
• Pre-initialized if known
• Stored in an array with element type
  StaticField
• Leads directly to the value of the specific field




                                                      21
Instance Fields
• Per instance of a Class
• Fields are stored in an array of element type
  InstField
• Offset of each field stored in byteOffset
  member
  – Relative offset from ClassObject structure




                                                  22
Listing Instance Members
Source file: ComposeMessageActivity.java
Class: Lcom/android/mms/ui/ComposeMessageActivity;
Instance Fields:
   name:      m_receiver
   signature: Landroid/content/BroadcastReceiver;

  name:      m_filter
  signature: Landroid/content/IntentFilter;

  name:      mAppContext
  signature: Landroid/content/Context;

  name:     mAvailableDirPath
  signature: Ljava/lang/String;

                                                     23
Analyzing Methods
• We can enumerate all methods (direct, virtual)
  and retrieve names and instructions
• Not really applicable to this talk
• Can be extremely useful for malware analysis
  though
  – If .apk is no longer on disk or if code was changed
    at runtime



                                                          24
Methods in Memory vs on Disk
• Dalvik makes a number of runtime
  optimizations [1]
• Example: When class members are accessed
  (iget, iput) the field table index is replaced
  with the direct byte offset
• Would likely need to undo some of the
  optimizations to get complete baksmali
  output

                                                   25
Analyzing Specific Applications




                                  26
Recovery Approach
• Best approach seems to be
  locating data structures of UI
  screens
  – UI screens represented by
    uniform (single type) lists of
    displayed information
  – Data for many views are pre-
    loaded



                                     27
Finding Data Structures
• Can save substantial time by using adb’s
  logcat (next slide)
  – Shows the classes and often methods involved in
    handling UI events
• Otherwise, need to examine source code
  – Some applications are open source
  – Others can be “decompiled” with baksmali [9]




                                                      28
logcat example
The following is a snippet of output when clicking on the text
message view:
 D/ConversationList(12520): onResume Start
 D/ComposeMessageActivity(12520): onConatctInfoChange
 D/RecipientList(12520): mFilterHandler not null
 D/RecipientList(12520): get recipient: 0
 D/RecipientList(12520): r.name: John Smith
 D/RecipientList(12520): r.filter() return result
 D/RecipientList(12520): indexOf(r)0
 D/RecipientList(12520): prepare set, index/name: 0/John Smith



                                                            29
Phone Call History
• Call history view controlled
  through a
  DialerContactCard$OnCard
  ClickListener
• Each contact stored as a
  DialerContactCard
• Contains the name,
  number, convo length, and
  photo of contact

                                 30
Per Contact Call History
• Can (sometimes) retrieve call history per-
  contact
• Requires the user to actually view a contact’s
  history before being populated




                                                   31
Text Messages
• Recovery through ComposeMessageActivity &
  TextMessageView
• Complete conversations can be recovered
• Not pre-populated




                                          32
Voicemail
• Audio file is open()’ed
• Not mapped contiguously into the process
  address space
• No method to recover deleted voicemails..




                                              33
Browser (Opera Mini)
• Opera Mini is the most used mobile browser
• Can recover some session information
  – The history file is always mapped in memory
    (including information from current session)
• HTTP requests and page information is
  (possibly) recoverable
  – Can recover <title> information
  – Stored in Opera Binary Markup Language
  – Not publicly documented?

                                                   34
Recovering Wireless Information
• Screenshot on the right
  shows results of a scan for
  wireless networks
• Recovery of this view
  provides the SSID, MAC
  address, and enc type for
  routers found
• Recovery of “Connected”
  routers show which were
  associated with

                                    35
Other Wireless Information
• Potentially interesting information:
  – Wireless keys
  – Connection stats
• These are not controlled by Dalvik
  – Keys only initially entered through Dalvik, but then
    saved
• Stored by the usual Linux applications
  – wpa_supplicant, dhcpd, in-kernel stats

                                                       36
Location Recovery
• Associating location & time not always
  important
  – But makes for better slides *hint*
• Interesting for a number of reasons
  – Forensics & Privacy concerns
  – Not part of a “standard” forensics investigation




                                                       37
Google Maps
• Did not do source code analysis
  – Most phones won’t be using Google Maps while
    being seized
  – Wanted to find ways to get historical data cleanly
• Found two promising searches
  – mTime=TIME,mLatitude=LAT,mLongitude=LON
  – point: LAT,LON … lastFix: TIME
     • TIME is the last location, extra work needed to verify



                                                                38
“Popular” Weather Application
• The weather application uses your location to
  give you relevant information
• http://vendor.site.com/widget/search.asp?
  lat=LAT&lon=LON&nocache=TIME




                                                  39
More GPS Fun
• All of the following applications do not clear
  GPS data from memory, and all send their
  lat/lon using GET with HTTP
  – Urban Spoon
  – Weather Channel
  – WeatherBug
  – Yelp
  – Groupon
  – Movies

                                                   40
Implementation
• Recovery code written as Volatility [7] plugins
  – Most popular memory analysis framework
  – Has support for all Windows versions since XP and
    2.6 Intel Linux
  – Now also supports ARM Linux/Android
• Makes rapid development of memory analysis
  capabilities simple
• Also can be used for analyzing other binary
  formats

                                                    41
Testing
• Tested against a HTC EVO 4G
  – No phone-specific features used in analysis
  – Only a few HTC-specific packages were analyzed
• Visually tested against other Dalvik versions
  – No drastic changes in core Dalvik functionality




                                                      42
Research Applications
• Memory forensics (obviously)
• Testing of privacy assurances
• Malware analysis
  – Can enumerate and recover methods and their
    instructions




                                                  43
Future Avenues of Research
• Numerous applications with potentially
  interesting information
  – Too much to manually dig through
  – Need automation
  – Baksmali/Volatility/logcat integration?
• Automated determination of interesting
  evidence across the whole system
  – Combing work done in [2] and [3]


                                              44
Questions/Comments?
• andrew@digdeeply.com
• @attrc




                             45
References - 1
[1] http://bit.ly/dalvikvsjava
[2] Brendan Dolan-Gavitt, et al, “Virtuoso: Narrowing
    the Semantic Gap in Virtual Machine
    Introspection”, IEEE Security and Privacy, 2011
[3] TaintDroid, http://www.appanalysis.org/
[4] http://bit.ly/windowsmemory
[5] http://bit.ly/linuxmem
[6] http://bit.ly/memimaging
[7] http://code.google.com/p/volatility/
[8] http://lcamtuf.coredump.cx/soft/memfetch.tgz
                                                        46
References - 2
[9] baksmali - http://code.google.com/p/smali/




                                                 47

More Related Content

What's hot (20)

PDF
(120513) #fitalk an introduction to linux memory forensics
INSIGHT FORENSIC
 
PDF
Workshop - Linux Memory Analysis with Volatility
Andrew Case
 
PPTX
Memory forensics
Sunil Kumar
 
PPTX
Malware analysis using volatility
Yashashree Gund
 
PDF
Dfrws eu 2014 rekall workshop
Tamas K Lengyel
 
PDF
Hunting Mac Malware with Memory Forensics
Andrew Case
 
PPTX
Memory Forensic - Investigating Memory Artefact
Satria Ady Pradana
 
PDF
I Know You Want Me - Unplugging PlugX
Takahiro Haruyama
 
PPT
Live Memory Forensics on Android devices
Nikos Gkogkos
 
PPTX
Unmasking Careto through Memory Forensics (video in description)
Andrew Case
 
PDF
One-Byte Modification for Breaking Memory Forensic Analysis
Takahiro Haruyama
 
PPTX
REMnux tutorial-2: Extraction and decoding of Artifacts
Rhydham Joshi
 
PPTX
Winnti Polymorphism
Takahiro Haruyama
 
PDF
Forensics of a Windows System
Conferencias FIST
 
PPTX
44CON London 2015: NTFS Analysis with PowerForensics
Jared Atkinson
 
PPTX
Leveraging NTFS Timeline Forensics during the Analysis of Malware
tmugherini
 
PPTX
Autopsy Digital forensics tool
Sreekanth Narendran
 
PDF
Disk forensics
Chiawei Wang
 
ODP
File carving tools
Marco Alamanni
 
(120513) #fitalk an introduction to linux memory forensics
INSIGHT FORENSIC
 
Workshop - Linux Memory Analysis with Volatility
Andrew Case
 
Memory forensics
Sunil Kumar
 
Malware analysis using volatility
Yashashree Gund
 
Dfrws eu 2014 rekall workshop
Tamas K Lengyel
 
Hunting Mac Malware with Memory Forensics
Andrew Case
 
Memory Forensic - Investigating Memory Artefact
Satria Ady Pradana
 
I Know You Want Me - Unplugging PlugX
Takahiro Haruyama
 
Live Memory Forensics on Android devices
Nikos Gkogkos
 
Unmasking Careto through Memory Forensics (video in description)
Andrew Case
 
One-Byte Modification for Breaking Memory Forensic Analysis
Takahiro Haruyama
 
REMnux tutorial-2: Extraction and decoding of Artifacts
Rhydham Joshi
 
Winnti Polymorphism
Takahiro Haruyama
 
Forensics of a Windows System
Conferencias FIST
 
44CON London 2015: NTFS Analysis with PowerForensics
Jared Atkinson
 
Leveraging NTFS Timeline Forensics during the Analysis of Malware
tmugherini
 
Autopsy Digital forensics tool
Sreekanth Narendran
 
Disk forensics
Chiawei Wang
 
File carving tools
Marco Alamanni
 

Viewers also liked (7)

PDF
Memory management in Android
Keyhan Asghari
 
PDF
Android Multimedia Support
Jussi Pohjolainen
 
PDF
Memory management for_android_apps
Bin Shao
 
PPTX
Memory management in Andoid
Monkop Inc
 
PDF
Android memory fundamentals
Taras Leskiv
 
PDF
Tuning android for low ram devices
Droidcon Berlin
 
PDF
Understanding the Dalvik Virtual Machine
National Cheng Kung University
 
Memory management in Android
Keyhan Asghari
 
Android Multimedia Support
Jussi Pohjolainen
 
Memory management for_android_apps
Bin Shao
 
Memory management in Andoid
Monkop Inc
 
Android memory fundamentals
Taras Leskiv
 
Tuning android for low ram devices
Droidcon Berlin
 
Understanding the Dalvik Virtual Machine
National Cheng Kung University
 
Ad

Similar to Memory Analysis of the Dalvik (Android) Virtual Machine (20)

PPTX
Omfw 2013
504ensics
 
PDF
Vk.amberfog.com gtug part1_introduction2_javaandroid_gtug
ketan_patel25
 
PDF
150104 3 methods for-binary_analysis_and_valgrind
Raghu Palakodety
 
PPTX
Android village @nullcon 2012
hakersinfo
 
PDF
Chronon - A Back-In-Time-Debugger for Java
tsauerwein
 
PDF
Beyond Breakpoints: A Tour of Dynamic Analysis
Fastly
 
PDF
Jvm internals
Luiz Fernando Teston
 
PPTX
Decompiling Android
Godfrey Nolan
 
PDF
Improving DroidBox
Kelwin Yang
 
PPT
Security Applications For Emulation
Silvio Cesare
 
PDF
Introduction to Android Development and Security
Kelwin Yang
 
PDF
Understanding the Dalvik bytecode with the Dedexer tool
Gabor Paller
 
PPTX
Android sandbox
Anusha Chavan
 
PPTX
Performance #5 cpu and battery
Vitali Pekelis
 
PDF
Android : How Do I Code Thee?
Viswanath J
 
PPTX
Simple insites into JVM
Ramakanth Tarimala
 
PDF
Dynamic Languages in Production: Progress and Open Challenges
bcantrill
 
PDF
Android : Revolutionizing Mobile Devices
Ritesh Puthran
 
PDF
JDK Tools For Performance Diagnostics
Baruch Sadogursky
 
PDF
IBM Java PackedObjects
Marcel Mitran
 
Omfw 2013
504ensics
 
Vk.amberfog.com gtug part1_introduction2_javaandroid_gtug
ketan_patel25
 
150104 3 methods for-binary_analysis_and_valgrind
Raghu Palakodety
 
Android village @nullcon 2012
hakersinfo
 
Chronon - A Back-In-Time-Debugger for Java
tsauerwein
 
Beyond Breakpoints: A Tour of Dynamic Analysis
Fastly
 
Jvm internals
Luiz Fernando Teston
 
Decompiling Android
Godfrey Nolan
 
Improving DroidBox
Kelwin Yang
 
Security Applications For Emulation
Silvio Cesare
 
Introduction to Android Development and Security
Kelwin Yang
 
Understanding the Dalvik bytecode with the Dedexer tool
Gabor Paller
 
Android sandbox
Anusha Chavan
 
Performance #5 cpu and battery
Vitali Pekelis
 
Android : How Do I Code Thee?
Viswanath J
 
Simple insites into JVM
Ramakanth Tarimala
 
Dynamic Languages in Production: Progress and Open Challenges
bcantrill
 
Android : Revolutionizing Mobile Devices
Ritesh Puthran
 
JDK Tools For Performance Diagnostics
Baruch Sadogursky
 
IBM Java PackedObjects
Marcel Mitran
 
Ad

More from Andrew Case (7)

PDF
Proactive Measures to Defeat Insider Threat
Andrew Case
 
PPTX
OMFW 2012: Analyzing Linux Kernel Rootkits with Volatlity
Andrew Case
 
PPTX
Memory Forensics: Defeating Disk Encryption, Skilled Attackers, and Advanced ...
Andrew Case
 
PDF
Hunting Mac Malware with Memory Forensics
Andrew Case
 
PPTX
My Keynote from BSidesTampa 2015 (video in description)
Andrew Case
 
PPT
Mac Memory Analysis with Volatility
Andrew Case
 
PDF
Investigating Cooridinated Data Exfiltration
Andrew Case
 
Proactive Measures to Defeat Insider Threat
Andrew Case
 
OMFW 2012: Analyzing Linux Kernel Rootkits with Volatlity
Andrew Case
 
Memory Forensics: Defeating Disk Encryption, Skilled Attackers, and Advanced ...
Andrew Case
 
Hunting Mac Malware with Memory Forensics
Andrew Case
 
My Keynote from BSidesTampa 2015 (video in description)
Andrew Case
 
Mac Memory Analysis with Volatility
Andrew Case
 
Investigating Cooridinated Data Exfiltration
Andrew Case
 

Recently uploaded (20)

PDF
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PPTX
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
PDF
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
PDF
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
Biography of Daniel Podor.pdf
Daniel Podor
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Mastering Financial Management in Direct Selling
Epixel MLM Software
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
AUTOMATION AND ROBOTICS IN PHARMA INDUSTRY.pptx
sameeraaabegumm
 
What Makes Contify’s News API Stand Out: Key Features at a Glance
Contify
 
CIFDAQ Weekly Market Wrap for 11th July 2025
CIFDAQ
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Biography of Daniel Podor.pdf
Daniel Podor
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 

Memory Analysis of the Dalvik (Android) Virtual Machine

  • 1. Memory Analysis of the Dalvik (Android) Virtual Machine Andrew Case Digital Forensics Solutions
  • 2. Who Am I? • Security Analyst at Digital Forensics Solutions – Also perform wide ranging forensics investigations • Volatility Developer • Former Blackhat and DFRWS speaker 2
  • 3. Agenda • What is Dalvik / why do we care? • Brief overview of memory forensics • Extracting allocated and historical data from Dalvik instances • Target specific Android applications 3
  • 4. What is Dalvik? • Dalvik is the software VM for all Android applications • Nearly identical to the Java Virtual Machine (JVM) [1] • Open source, written in C / Java 4
  • 5. Why do we care? • Android-based phones leading in US mobile market – Which makes for many phones to investigate • Memory forensics capabilities against Android applications have numerous uses/implications • Entire forensics community (LEO, .gov, private firms) already urging development of such capabilities 5
  • 6. Memory Forensics Introduction • Memory forensics is vital to orderly recovery of runtime information • Unstructured methods (strings, grep, etc) are brittle and only recover superficial info • Structured methods allow for recovery of data structures, variables, and code from memory • Previous work at operating system level led to recovery of processes, open files, network connections, etc [4,5] 6
  • 7. Memory Analysis Process • First, need to acquire memory – Acquisition depends on environment [6] • Next, requires locating information in memory and interpreting it correctly – Also requires re-implementing functionality offline • Then it needs to be displayed in a useful way to the investigator 7
  • 9. Acquiring Memory – Approach 1 • The normal method is to acquire a complete capture of physical RAM • Works well when analyzing kernel data structures as their pages are not swapped out • Allows for recovery of allocated and historical processes, open files, network connections, and so on 9
  • 10. Approach 1 on Android • Without /dev/mem support, need a LKM to read memory • No current module works for Android (ARM) • We developed our own (mostly by @jtsylve) • Benefits of full capture: – Can target any process (including its mappings) – Can recover information from unmapped pages in processes 10
  • 11. Acquiring Memory – Approach 2 • Memory can be acquired on a per-process basis • Ensures that all pages of the process will be acquired • Easiest to perform with memfetch[8] – After a few small changes, was statically compiled for ARM • No unmapped pages will be recovered though – Heap and GC don’t munmap immediately 11
  • 12. Analyzing C vs Java • Most previous forensics research has had the “luxury” of analyzing C – Nearly 1:1 mapping of code/data to in-memory layout • Declaration of a C “string” – char buffer*+ = “Hello World”; • Memory Layout (xxd) – 4865 6c6c 6f20 576f 726c 6400 Hello World. 12
  • 13. A Dalvik String in Memory • First, need the address of the “StringObject” • Next, need the offsets of the “java/lang/String” value and byte offset members • StringObject + value offset leads us to an “ArrayObject” • ArrayObject + byte offset leads to an UTF-16 array of characters • … finally we have the string (in Unicode) 13
  • 14. Now for the memory analysis… • The real goal of the research was to be able to locate arbitrary class instances and fields in memory • Other goals included replicating commonly used features of the Android debugging framework 14
  • 15. Locating Data Structures • The base of Dalvik loads as a shared library (libdvm.so) • Contains global variables that we use to locate classes and other information • Also contains the C structures needed to parse and gather evidence we need 15
  • 16. Gathering libdvm’s Structures 1) Grab the shared library from the phone (adb) 2) Use Volatility’s dwarfparse.py: • Builds a profile of C structures along with members, types, and byte offsets • Records offsets of global variables 3) Example structure definition 'ClassObject': [ 0xa0, { Class name and size 'obj': [0x0, ['Object']], member name, offset, and type 16
  • 17. Volatility Plugin Sample • Accessing structures is as simple as knowing the type and offset intval = obj.Object(“int”, offset=intOffset, ..) • Volatility code to access ‘descriptor’ of an ‘Object’: o = obj.Object("Object", offset=objectAddress, ..) c = obj.Object("ClassObject", offset=o.clazz, …) desc = linux_common.get_string(c.descriptor) 17
  • 18. gDvm • gDvm is a global structure of type DvmGlobals • Holds info about a specific Dalvik instance • Used to locate a number of structures needed for analysis 18
  • 19. Locating Loaded Classes • gDvm.loadedClasses is a hash table of ClassObjects for each loaded class • Hash table is stored as an array • Analysis code walks the backing array and handles active entries – Inactive entries are NULL or have a pointer value of 0xcbcacccd 19
  • 20. Information Per Class • Type and (often) name of the source code file • Information on backing DexFile – DexFile stores everything Dalvik cares about for a binary • Data Fields – Static – Instance • Methods – Name and Type – Location of Instructions 20
  • 21. Static Fields • Stored once per class (not instance) • Pre-initialized if known • Stored in an array with element type StaticField • Leads directly to the value of the specific field 21
  • 22. Instance Fields • Per instance of a Class • Fields are stored in an array of element type InstField • Offset of each field stored in byteOffset member – Relative offset from ClassObject structure 22
  • 23. Listing Instance Members Source file: ComposeMessageActivity.java Class: Lcom/android/mms/ui/ComposeMessageActivity; Instance Fields: name: m_receiver signature: Landroid/content/BroadcastReceiver; name: m_filter signature: Landroid/content/IntentFilter; name: mAppContext signature: Landroid/content/Context; name: mAvailableDirPath signature: Ljava/lang/String; 23
  • 24. Analyzing Methods • We can enumerate all methods (direct, virtual) and retrieve names and instructions • Not really applicable to this talk • Can be extremely useful for malware analysis though – If .apk is no longer on disk or if code was changed at runtime 24
  • 25. Methods in Memory vs on Disk • Dalvik makes a number of runtime optimizations [1] • Example: When class members are accessed (iget, iput) the field table index is replaced with the direct byte offset • Would likely need to undo some of the optimizations to get complete baksmali output 25
  • 27. Recovery Approach • Best approach seems to be locating data structures of UI screens – UI screens represented by uniform (single type) lists of displayed information – Data for many views are pre- loaded 27
  • 28. Finding Data Structures • Can save substantial time by using adb’s logcat (next slide) – Shows the classes and often methods involved in handling UI events • Otherwise, need to examine source code – Some applications are open source – Others can be “decompiled” with baksmali [9] 28
  • 29. logcat example The following is a snippet of output when clicking on the text message view: D/ConversationList(12520): onResume Start D/ComposeMessageActivity(12520): onConatctInfoChange D/RecipientList(12520): mFilterHandler not null D/RecipientList(12520): get recipient: 0 D/RecipientList(12520): r.name: John Smith D/RecipientList(12520): r.filter() return result D/RecipientList(12520): indexOf(r)0 D/RecipientList(12520): prepare set, index/name: 0/John Smith 29
  • 30. Phone Call History • Call history view controlled through a DialerContactCard$OnCard ClickListener • Each contact stored as a DialerContactCard • Contains the name, number, convo length, and photo of contact 30
  • 31. Per Contact Call History • Can (sometimes) retrieve call history per- contact • Requires the user to actually view a contact’s history before being populated 31
  • 32. Text Messages • Recovery through ComposeMessageActivity & TextMessageView • Complete conversations can be recovered • Not pre-populated 32
  • 33. Voicemail • Audio file is open()’ed • Not mapped contiguously into the process address space • No method to recover deleted voicemails.. 33
  • 34. Browser (Opera Mini) • Opera Mini is the most used mobile browser • Can recover some session information – The history file is always mapped in memory (including information from current session) • HTTP requests and page information is (possibly) recoverable – Can recover <title> information – Stored in Opera Binary Markup Language – Not publicly documented? 34
  • 35. Recovering Wireless Information • Screenshot on the right shows results of a scan for wireless networks • Recovery of this view provides the SSID, MAC address, and enc type for routers found • Recovery of “Connected” routers show which were associated with 35
  • 36. Other Wireless Information • Potentially interesting information: – Wireless keys – Connection stats • These are not controlled by Dalvik – Keys only initially entered through Dalvik, but then saved • Stored by the usual Linux applications – wpa_supplicant, dhcpd, in-kernel stats 36
  • 37. Location Recovery • Associating location & time not always important – But makes for better slides *hint* • Interesting for a number of reasons – Forensics & Privacy concerns – Not part of a “standard” forensics investigation 37
  • 38. Google Maps • Did not do source code analysis – Most phones won’t be using Google Maps while being seized – Wanted to find ways to get historical data cleanly • Found two promising searches – mTime=TIME,mLatitude=LAT,mLongitude=LON – point: LAT,LON … lastFix: TIME • TIME is the last location, extra work needed to verify 38
  • 39. “Popular” Weather Application • The weather application uses your location to give you relevant information • http://vendor.site.com/widget/search.asp? lat=LAT&lon=LON&nocache=TIME 39
  • 40. More GPS Fun • All of the following applications do not clear GPS data from memory, and all send their lat/lon using GET with HTTP – Urban Spoon – Weather Channel – WeatherBug – Yelp – Groupon – Movies 40
  • 41. Implementation • Recovery code written as Volatility [7] plugins – Most popular memory analysis framework – Has support for all Windows versions since XP and 2.6 Intel Linux – Now also supports ARM Linux/Android • Makes rapid development of memory analysis capabilities simple • Also can be used for analyzing other binary formats 41
  • 42. Testing • Tested against a HTC EVO 4G – No phone-specific features used in analysis – Only a few HTC-specific packages were analyzed • Visually tested against other Dalvik versions – No drastic changes in core Dalvik functionality 42
  • 43. Research Applications • Memory forensics (obviously) • Testing of privacy assurances • Malware analysis – Can enumerate and recover methods and their instructions 43
  • 44. Future Avenues of Research • Numerous applications with potentially interesting information – Too much to manually dig through – Need automation – Baksmali/Volatility/logcat integration? • Automated determination of interesting evidence across the whole system – Combing work done in [2] and [3] 44
  • 46. References - 1 [1] http://bit.ly/dalvikvsjava [2] Brendan Dolan-Gavitt, et al, “Virtuoso: Narrowing the Semantic Gap in Virtual Machine Introspection”, IEEE Security and Privacy, 2011 [3] TaintDroid, http://www.appanalysis.org/ [4] http://bit.ly/windowsmemory [5] http://bit.ly/linuxmem [6] http://bit.ly/memimaging [7] http://code.google.com/p/volatility/ [8] http://lcamtuf.coredump.cx/soft/memfetch.tgz 46
  • 47. References - 2 [9] baksmali - http://code.google.com/p/smali/ 47