Back To The Future Going Back In Time To Abuse Android’s JIT
1
Back To The Future Going Back In Time To Abuse Androids JIT 1 $ - - PowerPoint PPT Presentation
Back To The Future Going Back In Time To Abuse Androids JIT 1 $ whoami Benjamin Watson Director of Security Research @VerSprite Security Android @rotlogix 2 Agenda Inspiration and Overview Android 4.4.4 JIT
1
2
3
4
5
6
7
@mattifestation @rwincey
8
9
10
11
12
AD Network
Malicious PNG
Embedded Shellcode Malware Installation Download Shellcode from PNG
Google Play
Extract shellcode from PNG and execute it in memory via JIT technique
13
14
15
16
17
18
19
20
21
Java Source Code Java Bytecode Dalvik Bytecode Dalvik Executable Dalvik VM
22
23
{}
24
{}
more JitEntry structures
method’s bytecode and a pointer to its translated JIT code
25
26
An available JitEntry slot within the pJitEntryTable hash table is updated with the hash of the target dPC The JitEntry is populated with the code address for the target Dalvik method The translated address member is initialized and the JitEntry is returned
27
{}
28
29
{}
30
The translated JIT code pointer within a JitEntry will point somewhere in the JIT Code Cache
31
dvmCallMethod dvmCallMethodV dvmInterpret dvmInvokeMethod dvmMterpStd dvmMterpStdRun
32
33
34
35
36
37
38
39
{}
being held by checking the pthread_mutex_t structure’s state member
the state to “locked” in Java through our memory write primitive
checked
to the JitTable would be required
40
41
42
43
The VM globals contains a hash table for all of the loaded classes Each class contains of a vtable of Method structures representing its methods
{} {}
44
The Method structure contains the insns field, which points to the method’s Dalvik bytecode If the method has been JIT’ed, the dPC field in the JitEntry should match
{}
45
dPC* codeAddress* dPC* codeAddress*
Shellcode JIT Code Cache JitEntry
target JitEntry
46
47
48
methods, because we observed they were most likely to be JIT’ed
process maps parser
49
50
=
51
52
The entry_point_from_quick_compiled_code_ typically points into an ART entry point, unless the method has been JIT’ed
{}
53
In the Android Runtime Java methods are implemented through the ArtMethod C++ class
When a method is JIT’ed, that JIT code is stored as an entry point in the JIT code cache
54
{}
The JIT code cached maintains r-x permissions
55
New JIT code is added through JitCodeCache::CommitCodeInternal
{}
A map is maintained internally which contains the following (ArtMethod, JIT Code)
This map is updated after the translation operations finish
56
{}
57
Force JIT a target Java method that we control Find that target method’s ArtMethod object in memory Overwrite the ArtMethod(s) entry_point with a pointer to our shellcode Invoke the JIT’ed method from Java
58
59
60
{}
The ArtMethod contains the method_ids index for itself in the associated DEX file We can parse the DEX file mapped into memory for the method name that corresponds with the dex_method_index Finally we validate its our method!
61
62
63
Infect Device! Download and Execute Shellcode from Memory Download and Load DEX into Memory
64
65
{}
With the ability to write memory within the VM, it’s easier to convert a method into a JNI method by modifying it’s access flags With the ability to write memory within the VM, it’s easier to convert a regular method into a JNI method by modifying it’s access flags Once you replace the method’s data pointer with your shellcode, you can easily invoke order to achieve native execution
66
java.lang.reflect
67
68
69
70
71
72
@rotlogix @VerSprite