Insomnidroid Reverse Engineering
Insomnidroid Reverse Engineering
Agenda
Contents of an
APK: manifest,
.dex, resources...
Tutorial: reversing
Android/Spitmo.C!tr.spy
A few other tricks:
logs,
anti-emulator...
Miscellaneous tools
InsomniHack'12 - A. Apvrille
2/42
InsomniHack'12 - A. Apvrille
3/42
$ unzip criptomovil.apk
Archive: criptomovil.apk
inflating: res/layout/main.xml
inflating: AndroidManifest.xml
extracting: resources.arsc
extracting: res/drawable-hdpi/icon.png
extracting: res/drawable-ldpi/icon.png
extracting: res/drawable-mdpi/icon.png
inflating: classes.dex
inflating: META-INF/MANIFEST.MF
inflating: META-INF/CERT.SF
inflating: META-INF/CERT.RSA
InsomniHack'12 - A. Apvrille
4/42
-C
03
3d
00
AndroidManifest.xml |
00 08 00 b0 1c 00 00
00 00 00 00 00 00 00
00 00 00 00 00 00 00
head
01 00 1c 00 8c 0d 00 00 |...........
00 00 00 00 10 01 00 00 |=..........
1a 00 00 00 34 00 00 00 |...........
5/42
$ ./androaxml.py -i criptomovil.apk -o
AndroidManifest.human.xml
InsomniHack'12 - A. Apvrille
6/42
I
I
InsomniHack'12 - A. Apvrille
7/42
http://en.wikipedia.org/wiki/Dalvik_(software)
Opcodes: see http://pallergabor.uw.hu/androidblog/
dalvik_opcodes.html
8/42
InsomniHack'12 - A. Apvrille
9/42
I
I
InsomniHack'12 - A. Apvrille
10/42
Disassembling DEX
I
Apktool: produces
smali
Code syntax
highlight:
I Emacs: Nelson
Elhage or Tim
Strazzere
I Vim: Jon
Larimer
I Notepad++:
lohan+
I UltraEdit:
lohan+
InsomniHack'12 - A. Apvrille
11/42
12/42
InsomniHack'12 - A. Apvrille
13/42
dex2jar + jd-gui
I
$ ./dex2jar.sh criptomovil.apk
dex2jar version: reader-1.7, translator-0.0.9.6, ir-1.4
dex2jar criptomovil.apk -> criptomovil_dex2jar.jar
Done.
I
I
InsomniHack'12 - A. Apvrille
14/42
Figure: Android/Spitmo.C!tr.spy
InsomniHack'12 - A. Apvrille
15/42
InsomniHack'12 - A. Apvrille
16/42
InsomniHack'12 - A. Apvrille
16/42
InsomniHack'12 - A. Apvrille
16/42
InsomniHack'12 - A. Apvrille
16/42
Reversing MainActivity
I
InsomniHack'12 - A. Apvrille
17/42
Reversing MainActivity
I
I
InsomniHack'12 - A. Apvrille
17/42
Reversing MainActivity
I
I
I
InsomniHack'12 - A. Apvrille
17/42
Reversing MainActivity
I
I
I
I
InsomniHack'12 - A. Apvrille
17/42
Reversing KavService
How to start a service
I startService() onCreate() onStartCommand() (or
onStart() for old SDKs)
I bindService() onCreate()
Not started?
$ grep -ri startService ./smali
$ grep -ri bindService ./smali
Not used (yet)?
InsomniHack'12 - A. Apvrille
18/42
InsomniHack'12 - A. Apvrille
19/42
InsomniHack'12 - A. Apvrille
19/42
InsomniHack'12 - A. Apvrille
19/42
InsomniHack'12 - A. Apvrille
19/42
InsomniHack'12 - A. Apvrille
19/42
InsomniHack'12 - A. Apvrille
19/42
InsomniHack'12 - A. Apvrille
19/42
Reversing SmsReceiver
Things we know
I onReceive processes incoming SMS messages
I AntivirusEnabled is a ag, if not enabled, won't do much.
I Calls GetStaticDataString
I Retrieves SMS body and originating phone number
I Formats a string: &from=ORIGIN&text=BODY
I Calls GetRequest
I AntivirusEnabled true: don't forward SMS to others
Things which are unclear yet
I What does GetStaticDataString() do?
I The result of GetStaticDataString() is overwritten...?
I What is variable k?
I What does GetRequest() do?
InsomniHack'12 - A. Apvrille
20/42
GetStaticDataString
InsomniHack'12 - A. Apvrille
21/42
GetStaticDataString
InsomniHack'12 - A. Apvrille
21/42
Reversing SmsReceiver
Things we know
I onReceive processes incoming SMS messages
I AntivirusEnabled is a ag, if not enabled, won't do much.
I Calls GetStaticDataString: ?to=PHONE&i=IMSI&m=IMEI...
I Retrieves SMS body and originating phone number
I Formats a string: &from=ORIGIN&text=BODY
I Calls GetRequest
I AntivirusEnabled true: don't forward SMS to others
Things which are unclear yet
I The result of GetStaticDataString() is overwritten...?
I What is variable k?
I What does GetRequest() do?
InsomniHack'12 - A. Apvrille
22/42
InsomniHack'12 - A. Apvrille
23/42
InsomniHack'12 - A. Apvrille
23/42
InsomniHack'12 - A. Apvrille
23/42
InsomniHack'12 - A. Apvrille
23/42
InsomniHack'12 - A. Apvrille
23/42
InsomniHack'12 - A. Apvrille
23/42
24/42
Reversing SmsReceiver
Things we know
I If OUTGOING_CALL, schedule KavService
I Build string, initialize it to: ?to=PHONE&i=IMSI&m=IMEI...
I Retrieves SMS body and originating phone number
I Append &from=ORIGIN&text=BODY to string
I Calls GetRequest if SendReport true
I AntivirusEnabled true: don't forward SMS to others
Things which are unclear yet
I What does GetRequest() do?
InsomniHack'12 - A. Apvrille
25/42
InsomniHack'12 - A. Apvrille
26/42
InsomniHack'12 - A. Apvrille
27/42
Or read smali
InsomniHack'12 - A. Apvrille
27/42
InsomniHack'12 - A. Apvrille
27/42
GetRequest decompilation
I
I
I
I
InsomniHack'12 - A. Apvrille
28/42
Spitmo: conclusion
What it does
I Displays a fake 3-digit activation code. 2nd digit is based on
IMEI
I KavService not used. Missing start command?
I SMS forwarded to a remote URL:
http://CENSORED?to=PHONE&i=IMSI&m=IMEI&aid=ACTIVATIONCODE&h=BOOLEAN&from=ORIGIN&text=BODY
Lessons learned
Read smali when decompilation fails
InsomniHack'12 - A. Apvrille
29/42
Understanding access$0
.method static synthetic access$0(Lcom/tapjoy/TJCOffersWebView;)
Landroid/widget/ProgressBar;
.locals 1
.parameter
.prologue
.line 28
iget-object v0, p0, Lcom/tapjoy/TJCOffersWebView;->progressBar:Landr
return-object v0
.end method
Compiler created
I Java: Inner classes can access private members of their
enclosing class.
I Byte-code: creates synthetic access$0
InsomniHack'12 - A. Apvrille
30/42
Anti-emulator tricks
Honeynet challenge 2011
// com.fc9.currencyguide.daemon.e.b:
if (a.a(Build.DEVICE).equalsIgnoreCase(
"46a808cfd5beafa5e60aefee867bf92025dc2849"))
localBoolean = Boolean.valueOf(1); // true
}
...
// com.fc9.currencyguide.fc9:
if (!com.fc9.currencyguide.daemon.e.b.a().booleanValue()) {
// MALICIOUS BEHAVIOUR
} else { // DO NOTHING }
I
46a808cfd5beafa5e60aefee867bf92025dc2849 =
sha1sum("generic")
5a374dcd2e5eb762b527af3a5bab6072a4d24493 =
sha1sum("sdk") ...
Dierent behaviour if on an emulator :(
InsomniHack'12 - A. Apvrille
31/42
InsomniHack'12 - A. Apvrille
32/42
I
I
I
call = invoke-static
v0 = what to log
re-use variables with caution...
adb logcat:
..
V/AXELLE: str: (
..
407): CD2ACE300D6687D4
InsomniHack'12 - A. Apvrille
33/42
Patch
emulator-arm
I
Search for
+CGSN:
IMEI
Search for
+CIMI: IMSI
InsomniHack'12 - A. Apvrille
34/42
Patch
emulator-arm
I
Search for
+CGSN:
IMEI
Search for
+CIMI: IMSI
InsomniHack'12 - A. Apvrille
34/42
35/42
InsomniHack'12 - A. Apvrille
36/42
InsomniHack'12 - A. Apvrille
37/42
InsomniHack'12 - A. Apvrille
37/42
Androguard + gephi
Powerful... but is it usable? - Ex: Android/BaseBridge
$ ./androgexf.py -i sendere.apk -o sendere.gexf
InsomniHack'12 - A. Apvrille
38/42
Androguard + gephi
Powerful... but is it usable? - Ex: Android/BaseBridge
$ ./androgexf.py -i sendere.apk -o sendere.gexf
InsomniHack'12 - A. Apvrille
38/42
APKInspector: a front-end
InsomniHack'12 - A. Apvrille
39/42
APKInspector: a front-end
InsomniHack'12 - A. Apvrille
39/42
InsomniHack'12 - A. Apvrille
40/42
InsomniHack'12 - A. Apvrille
40/42
InsomniHack'12 - A. Apvrille
40/42
InsomniHack'12 - A. Apvrille
40/42
Conclusion
I love
I Android Emulator
I Apktool
I baksmali
I dex2jar
I Java Decompiler
To investigate
I AndBug: a debugger,
not immediate to use
I AndroidAuditTools
InsomniHack'12 - A. Apvrille
Thank You !
Follow us on twitter:
@FortiGuardLabs
Axelle Apvrille
aka Crypto Girl
/mobile malware reverse engineering/
[email protected]
InsomniHack'12 - A. Apvrille
Beamer + Editor
42/42