69
ABUSING WEB APIS THROUGH SCRIPTED ANDROID APPLICATIONS impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html 1 of 69 11/19/2013 11:22 PM

impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

ABUSING WEBAPIS THROUGH

SCRIPTEDANDROID

APPLICATIONS

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

1 of 69 11/19/2013 11:22 PM

Page 2: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

2 of 69 11/19/2013 11:22 PM

Page 3: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

DANIEL PECK

Principal Research Scientist at Barracuda Labs

(barracudalabs.com)

Principal at Pragmatic Research (pragmatic.io)

Rapid prototyping

Malicious messaging

Larger studies of the current state of web security and infosec

industry

@Ramblinpeck

@BarracudaLabs

@PragmaticIO

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

3 of 69 11/19/2013 11:22 PM

Page 4: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

Past Lives

Offensive SCADA, Snort Jockey, Reverser

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

4 of 69 11/19/2013 11:22 PM

Page 5: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

SESSION OUTLINE

Target Selection

Foundations

Exploration

Control

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

5 of 69 11/19/2013 11:22 PM

Page 6: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

Hot social app that I want to spam be a part of

Great web interface, great api once we have a few hundred

thousand accounts, but has some restrictions

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

6 of 69 11/19/2013 11:22 PM

Page 7: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

APPROACH

People are too worried about “friction” to put many

safeguard/throttling into mobile apps

Create our own client that mimics mobile app for api

purposes.

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

7 of 69 11/19/2013 11:22 PM

Page 8: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

ASSUMPTIONS AND HOPES

Twacebook has a well documented API thats protected using

Oauth

We'll probably need to extract some keys

They probably use their published API in their apps

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

8 of 69 11/19/2013 11:22 PM

Page 9: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

BUILD ON EXISTING TOOLS

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

9 of 69 11/19/2013 11:22 PM

Page 10: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

INTERCEPTING APP

COMMUNICATIONS

Need to MitM to be able to view tx/rx

Proxydroid

https://github.com/madeye/proxydroid

Run all/some of android traffic through our proxy

SSL

The developers aren't idiots

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

10 of 69 11/19/2013 11:22 PM

Page 11: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

Create and add a cert to your testing device

$ adb pull /system/etc/security/cacerts.bks$ keytool …$ adb push cacerts.bks /system/etc/security

Gotchas

Make sure you have the right version of bouncycastle

otherwise things break in not-fun ways

Different/easier procedures on Android 4.0+ devices

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

11 of 69 11/19/2013 11:22 PM

Page 12: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

BURP PROXY

Invisible proxying, generates cert on demand

Look at dns requests/guess hostname (CN) for generated cert

since 1.4.12

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

12 of 69 11/19/2013 11:22 PM

Page 13: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

INTERCEPTED TRAFFIC

POST /create_account HTTP/1.1Content-Type: application/x-www-form-urlencodedContent-Length: 296Accept-Encoding: gzip,deflateUser-Agent: TwacebookAndroidApp(build 6294, v1.8.64)Host: mobileapi.twacebook.comConnection: Keep-AliveCache-Control: no-cache

auth_consumer_key=40iqOgCcXqfwwqoa02D7nQoauth_nonce=0437A32D733151CABA3A06A12243CD0Aoauth_signature_method=HMAC-SHA1oauth_timestamp=1340141019oauth_version=1.0x_auth_mode=client_auth

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

13 of 69 11/19/2013 11:22 PM

Page 14: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

x_auth_password=f00bar%24x_auth_username=jimbooauth_signature=v%2FVnCJrssg9D07Zdy%2F8dPSapv8s%3D

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

14 of 69 11/19/2013 11:22 PM

Page 15: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

OAUTH

Consumers requests a consumer key and consumer secret

from provider

End users allow provider to grant a token and token secret to

consumer to make requests on their behalf

Signs requests (HMAC-SHA1 usually) with consumer secret &

token secret

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

15 of 69 11/19/2013 11:22 PM

Page 16: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

MORE OAUTH

Users don't have to give their password to third party apps

Providers get to restrict apps accessing their api to only

(honest) approved ones, essentially DRM

Designed and works well for server ← → server

Used extensively for mobile/desktop apps

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

16 of 69 11/19/2013 11:22 PM

Page 17: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

ONTO KEY RETRIEVAL

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

17 of 69 11/19/2013 11:22 PM

Page 18: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

DISASSEMBLY AND DECOMPILATION

Apktool http://code.google.com/p/android-apktool/

Decodes apks

Nice wrapper for smali/baksmali

In theory should allow for some nice debugging..

JD-GUI http://java.decompiler.free.fr/?q=jdgui

dex2jar first

not compilable source, sometimes misleading, good for

general idea

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

18 of 69 11/19/2013 11:22 PM

Page 19: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

ABOUT ANDROID

Runs within a Dalvik application virtual machine

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

19 of 69 11/19/2013 11:22 PM

Page 20: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

DALVIK

Register based machine

Optimized for low memory environments

Runs dex files

Deduped

Dalvik instruction set instead of standard JVM

Smali bytecode

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

20 of 69 11/19/2013 11:22 PM

Page 21: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

SMALI

class public final Lcd;super Ljava/lang/Object;# static fields.field public static final a:Lcd;

.method constructorinit()V.locals 2const/4 v1, 0x0const/4 v0, 0x0invoke-direct {p0, v1, v0, v1}, Lcd;-init(Laa;ILjava/lang/String;)Vreturn-void

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

21 of 69 11/19/2013 11:22 PM

Page 22: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

.end method

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

22 of 69 11/19/2013 11:22 PM

Page 23: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

DECIPHERING SMALI

Register based machine

Parameters are stored in p0...pX

Local registers v0...vY where

Last X local registers are identical to paramer registers

Registers store 32-bit values

64-bit values (J, long, and D, double primitives) are stored

in 2 registers

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

23 of 69 11/19/2013 11:22 PM

Page 24: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

PRIMITIVES

V: void - can only be used for return types

Z: boolean

B: byte

S: short

C: char

I: int

J: long (64 bits)

F: float

D: double (64 bits)

L: objects. You'll see in the form of “Lpackage/name

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

24 of 69 11/19/2013 11:22 PM

Page 25: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

/ObjectName”

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

25 of 69 11/19/2013 11:22 PM

Page 26: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

FUNCTION DECLARATIONS

method private static a #name and type(Lorg/apache/http/client/methods/HttpRequestBase; #p0Laa; #p1J #p2 + #p3Ljava/lang/String; #p4Ljava/lang/String; #p5)Ljava/lang/String; #return type

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

26 of 69 11/19/2013 11:22 PM

Page 27: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

VARIABLE ASSIGNMENT

const v2, 42const-string v4, "this is a static string"

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

27 of 69 11/19/2013 11:22 PM

Page 28: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

READABLE OPCODES

move-result vx

return-object vx

CALLING METHODS

invoke-direct parameters , methodtocall

invoke-direct {v4}, Ljava/lang/StringBuilder;->()V

invoke-static parameters , methodtocall

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

28 of 69 11/19/2013 11:22 PM

Page 29: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

invoke-static {p1, p2}, Ljava/lang/Math;->min(II)I

http://pallergabor.uw.hu/androidblog/dalvik_opcodes.html

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

29 of 69 11/19/2013 11:22 PM

Page 30: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

invoke-virtual {v0, v1}, Ljava/lang/String;->getBytes(Ljava/lang/String;)[B move-result-object v0 new-instance v1, Ljavax/crypto/spec/SecretKeySpec; const-string v2, "HmacSHA1" invoke-direct {v1, v0, v2}, Ljavax/crypto/spec/SecretKeySpec;-><init>([BLjava/lang/String;)V invoke-static {v0}, Ljavax/crypto/Mac;->getInstance(Ljava/lang/String;)Ljavax/crypto/Mac;... invoke-virtual {v0, v1}, Ljavax/crypto/Mac;->init(Ljava/security/Key;)V const-string v1, "UTF8" invoke-virtual {p0, v1}, Ljava/lang/String;->getBytes(Ljava/lang/String;)[B move-result-object v1 invoke-virtual {v0, v1}, Ljavax/crypto

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

30 of 69 11/19/2013 11:22 PM

Page 31: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

/Mac;->doFinal([B)[B move-result-object v0

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

31 of 69 11/19/2013 11:22 PM

Page 32: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

AND FROM JD-GUI

... while (true) { try { str1 = ""; SecretKeySpec localSecretKeySpec = new SecretKeySpec((ch.a(paramString2) + "&" + ch.a(str1)).getBytes("UTF8"), "HmacSHA1"); Mac localMac = Mac.getInstance("HmacSHA1"); localMac.init(localSecretKeySpec); String str3 = ch.a(new String(cc.a(localMac.doFinal(paramString1.getBytes("UTF8"))), "UTF8")); str2 = str3;

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

32 of 69 11/19/2013 11:22 PM

Page 33: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

return str2; } ...

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

33 of 69 11/19/2013 11:22 PM

Page 34: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

LOOK SIMILAR?

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

34 of 69 11/19/2013 11:22 PM

Page 35: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

AGAIN, DUMB THING FIRST

Printf debugging

const-string v2, "SECRETKEY , v0"invoke-static {v2, v0}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)Iinvoke-virtual {v0, v1}, Ljava/lang/String;->getBytes(Ljava/lang/String;)[Bmove-result-object v0new-instance v1, Ljavax/crypto/spec/SecretKeySpec;const-string v2, "HmacSHA1"invoke-direct {v1, v0, v2}, Ljavax/crypto/spec/SecretKeySpec;-init ([BLjava/lang/String;)V

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

35 of 69 11/19/2013 11:22 PM

Page 36: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

Rebuild the apk and run it

$ apktool b twacebook.apk twacebook_new.apk

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

36 of 69 11/19/2013 11:22 PM

Page 37: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

EXAMING THE LOGS

$ adb shell$ adb logcat…"SECRETKEY , v0 - I7PW5lgEkgMrqPOdxIj1o6llAbFdXHhVjFnvUsg1g"

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

37 of 69 11/19/2013 11:22 PM

Page 38: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

SO WE CAN REVERSE AROUND API

CALLS EASILY, BUT CAN WE REVERSE

CUSTOM CODE?

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

38 of 69 11/19/2013 11:22 PM

Page 39: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

.method public final a([BIILjava/io/OutputStream;)I .locals 9

const/4 v8, 0x0

rem-int/lit8 v0, p3, 0x3

sub-int v1, p3, v0

move v2, v8

:goto_0 add-int/lit8 v3, v1, 0x0

if-ge v2, v3, :cond_0

aget-byte v3, p1, v2

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

39 of 69 11/19/2013 11:22 PM

Page 40: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

and-int/lit16 v3, v3, 0xff

add-int/lit8 v4, v2, 0x1

aget-byte v4, p1, v4and-int/lit16 v4, v4, 0xff

add-int/lit8 v5, v2, 0x2

aget-byte v5, p1, v5

and-int/lit16 v5, v5, 0xff

iget-object v6, p0, Ll;->a:[B

ushr-int/lit8 v7, v3, 0x2

and-int/lit8 v7, v7, 0x3f

aget-byte v6, v6, v7

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

40 of 69 11/19/2013 11:22 PM

Page 41: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

invoke-virtual {p4, v6}, Ljava/io/OutputStream;->write(I)V

iget-object v6, p0, Ll;->a:[B

shl-int/lit8 v3, v3, 0x4

ushr-int/lit8 v7, v4, 0x4

or-int/2addr v3, v7

and-int/lit8 v3, v3, 0x3f

aget-byte v3, v6, v3

invoke-virtual {p4, v3}, Ljava/io/OutputStream;->write(I)V

iget-object v3, p0, Ll;->a:[B

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

41 of 69 11/19/2013 11:22 PM

Page 42: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

shl-int/lit8 v4, v4, 0x2

ushr-int/lit8 v6, v5, 0x6

or-int/2addr v4, v6

and-int/lit8 v4, v4, 0x3f

aget-byte v3, v3, v4

invoke-virtual {p4, v3}, Ljava/io/OutputStream;->write(I)V

iget-object v3, p0, Ll;->a:[B

and-int/lit8 v4, v5, 0x3f

aget-byte v3, v3, v4

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

42 of 69 11/19/2013 11:22 PM

Page 43: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

invoke-virtual {p4, v3}, Ljava/io/OutputStream;->write(I)V

add-int/lit8 v2, v2, 0x3

goto :goto_0

:cond_0 packed-switch v0, :pswitch_data_0

:goto_1 :pswitch_0 div-int/lit8 v1, v1, 0x3

mul-int/lit8 v1, v1, 0x4

if-nez v0, :cond_1

move v0, v8

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

43 of 69 11/19/2013 11:22 PM

Page 44: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

:goto_2 add-int/2addr v0, v1

return v0

:pswitch_1 add-int/lit8 v2, v1, 0x0

aget-byte v2, p1, v2

and-int/lit16 v2, v2, 0xff

ushr-int/lit8 v3, v2, 0x2

and-int/lit8 v3, v3, 0x3f

shl-int/lit8 v2, v2, 0x4

and-int/lit8 v2, v2, 0x3f

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

44 of 69 11/19/2013 11:22 PM

Page 45: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

iget-object v4, p0, Ll;->a:[B

aget-byte v3, v4, v3

invoke-virtual {p4, v3}, Ljava/io/OutputStream;->write(I)V

iget-object v3, p0, Ll;->a:[B

aget-byte v2, v3, v2

invoke-virtual {p4, v2}, Ljava/io/OutputStream;->write(I)V

iget-byte v2, p0, Ll;->b:B

invoke-virtual {p4, v2}, Ljava/io/OutputStream;->write(I)V

iget-byte v2, p0, Ll;->b:B

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

45 of 69 11/19/2013 11:22 PM

Page 46: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

invoke-virtual {p4, v2}, Ljava/io/OutputStream;->write(I)V

goto :goto_1

:pswitch_2 add-int/lit8 v2, v1, 0x0

aget-byte v2, p1, v2

and-int/lit16 v2, v2, 0xff

add-int/lit8 v3, v1, 0x0

add-int/lit8 v3, v3, 0x1

aget-byte v3, p1, v3

and-int/lit16 v3, v3, 0xff

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

46 of 69 11/19/2013 11:22 PM

Page 47: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

ushr-int/lit8 v4, v2, 0x2

and-int/lit8 v4, v4, 0x3f

shl-int/lit8 v2, v2, 0x4

ushr-int/lit8 v5, v3, 0x4

or-int/2addr v2, v5

and-int/lit8 v2, v2, 0x3f

shl-int/lit8 v3, v3, 0x2

and-int/lit8 v3, v3, 0x3f

iget-object v5, p0, Ll;->a:[B

aget-byte v4, v5, v4

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

47 of 69 11/19/2013 11:22 PM

Page 48: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

invoke-virtual {p4, v4}, Ljava/io/OutputStream;->write(I)V

iget-object v4, p0, Ll;->a:[B

aget-byte v2, v4, v2

invoke-virtual {p4, v2}, Ljava/io/OutputStream;->write(I)V

iget-object v2, p0, Ll;->a:[B

aget-byte v2, v2, v3

invoke-virtual {p4, v2}, Ljava/io/OutputStream;->write(I)V

iget-byte v2, p0, Ll;->b:B

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

48 of 69 11/19/2013 11:22 PM

Page 49: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

invoke-virtual {p4, v2}, Ljava/io/OutputStream;->write(I)V

goto :goto_1

:cond_1 const/4 v0, 0x4

goto :goto_2

:pswitch_data_0 .packed-switch 0x0 :pswitch_0 :pswitch_1 :pswitch_2 .end packed-switch.end method

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

49 of 69 11/19/2013 11:22 PM

Page 50: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

public final int a(byte[] paramArrayOfByte, int paramInt1, int paramInt2, OutputStream paramOutputStream) { int i = paramInt2 % 3; int j = paramInt2 - i; for (int k = 0; k < j + 0; k += 3) { int i9 = 0xFF & paramArrayOfByte[k]; int i10 = 0xFF & paramArrayOfByte[(k + 1)]; int i11 = 0xFF & paramArrayOfByte[(k + 2)]; paramOutputStream.write(this.a[(0x3F & i9 >>> 2)]); paramOutputStream.write(this.a[(0x3F & (i9 << 4 | i10 >>> 4))]); paramOutputStream.write(this.a[(0x3F & (i10 << 2 | i11 >>> 6))]); paramOutputStream.write(this.a[(i11 & 0x3F)]);

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

50 of 69 11/19/2013 11:22 PM

Page 51: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

} int i4; switch (i) { case 0: default: i4 = 4 * (j / 3); if (i != 0) break; case 1: case 2: } for (int i5 = 0; ; i5 = 4) { return i5 + i4; int i6 = 0xFF & paramArrayOfByte[(j + 0)]; int i7 = 0x3F & i6 >>> 2; int i8 = 0x3F & i6 << 4; paramOutputStream.write(this.a[i7]); paramOutputStream.write(this.a[i8]);

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

51 of 69 11/19/2013 11:22 PM

Page 52: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

paramOutputStream.write(this.b); paramOutputStream.write(this.b); break; int m = 0xFF & paramArrayOfByte[(j + 0)]; int n = 0xFF & paramArrayOfByte[(1 + (j + 0))]; int i1 = 0x3F & m >>> 2; int i2 = 0x3F & (m << 4 | n >>> 4); int i3 = 0x3F & n << 2; paramOutputStream.write(this.a[i1]); paramOutputStream.write(this.a[i2]); paramOutputStream.write(this.a[i3]); paramOutputStream.write(this.b); break; } }

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

52 of 69 11/19/2013 11:22 PM

Page 53: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

ENTER JVM BASED LANGUAGES

JRuby

Jython

Clojure

Scala

Built on the high performance multiplatform JVM

Huge number of Java libraries available

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

53 of 69 11/19/2013 11:22 PM

Page 54: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

JAVA LIBRARIES WITH JRUBY

And thankfully, dex are just another kind of jar

$ unzip twacebook.apk$ d2j-dex2jar.sh classes.dex -o twacebook.jar

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

54 of 69 11/19/2013 11:22 PM

Page 55: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

require 'java'require './jars/twacebook.jar'require './jars/android.jar'

java_import 'cc' do |clasname| "Obfuscater"end

obs_arr = Obfuscater.a(byte_arr)signature = String.from_java_bytes(obs_arr)

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

55 of 69 11/19/2013 11:22 PM

Page 56: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

ITTERATING UP

require 'java'require './jars/twacebook.jar'require './jars/android.jar'

java_import 'ab' do |clasname| "User"end

java_import 'cc' do |clasname| "ApiFactory"end

social_bot = ApiFactory.register_new_user(<name>, <email>)

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

56 of 69 11/19/2013 11:22 PM

Page 57: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

social_bot.post_update("Posting from a JRUBY")

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

57 of 69 11/19/2013 11:22 PM

Page 58: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

jarfile = ARGV[0]require 'java'require jarfilerequire './jars/android.jar'require 'pry'Pry.config.pager = false

jf = java.util.jar.JarFile.new(jarfile)

jf.entries.each do |entry| name = entry.getName name.gsub!(/.class$/, '') #ruby hates lowercase classnames begin java_import name do |classname| @cap_name = name.capitalize end

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

58 of 69 11/19/2013 11:22 PM

Page 59: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

rescue NameError => e puts "got an error, wtf? #{e}" end

puts "#{name} Instance Methods" class_const = Kernel.const_get(@cap_name) methods = Pry::Method.all_from_class(class_const).select { |method| method.visibility == :public && method.owner == class_const && !["==", "__jsend!", "equals", "__jcreate!"].include?(method.name) }

puts methods.map(&:signature).join("\n")end

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

59 of 69 11/19/2013 11:22 PM

Page 60: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

DYNAMIC, AND EVEN FUN, STYLE OF

REVERSING

Acquire Apk

Find interesting function

Load class into JVM session

Call functions in arbitrary ways

Itterate

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

60 of 69 11/19/2013 11:22 PM

Page 61: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

KNOWN ISSUES

Native code methods (eg: extensions written in C and

compiled for system) don't import and you can't load classes

using them.

Going to be some incompatibilities between full JVM and

Dalvik, but you'll seldom run into that.

People might confuse you for someone who likes Java

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

61 of 69 11/19/2013 11:22 PM

Page 62: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

TOWARDS AN ADVERTORIAL WORLD

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

62 of 69 11/19/2013 11:22 PM

Page 63: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

SEEDS

Skull Security torrent dump from Facebook (2010)

100 Million unique names

Male/Female

Unique ID number assigned by Facebook

US Census Data

Associate last name with likelyhood of ethnicity

Ethnicity can map (with weights) to their region

Region randomly maps to area code/city/etc for profile

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

63 of 69 11/19/2013 11:22 PM

Page 64: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

SEEDS (CONT)

Facebook

Gather public profile images from UIDs

Interests

Twitter suggests categories on account creation. Randomly

select a few so your bot knows what they're interested in,

food, movies, books, tv, etc.

Twitter public stream, 1% of traffic, more than your bots could

ever need

Chattiness level, people post at different rates, your bots

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

64 of 69 11/19/2013 11:22 PM

Page 65: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

should too. Some once a day, some a couple of times an hour,

some once a week.

Time zone rand(-3..3) hours before/after dawn and midnight in

their location. They'll only tweet then.

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

65 of 69 11/19/2013 11:22 PM

Page 66: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

BUILDING

Stacey Jackson

Evergreen, Colorado

sassystacey303

Likes book, movies

Moderate poster

Friends easily, about 15% of the users that Twacebook suggests

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

66 of 69 11/19/2013 11:22 PM

Page 67: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

67 of 69 11/19/2013 11:22 PM

Page 68: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

MONITIZATION: EARNING REPORT OF

SELLING FAKE FOLLOWERS BUSINESS

1k Followers sell for ~ $11 USD

Average person who purchases fake followers gets around 50k

Around 50 people selling followers through eBay at any given

time

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

68 of 69 11/19/2013 11:22 PM

Page 69: impress.js presentation generator file:///home/peck ... · MORE OAUTH Users don't have to give their password to third party apps Providers get to restrict apps accessing their api

THANK YOU COUNTERMEASURE

Questions/Thoughts?

[email protected]

[email protected]

@barracudalabs

@ramblinpeck

Huge Thank You to Everyone Who Has Contributed to

Tools Mentioned

impress.js presentation generator file:///home/peck/Dropbox/documents/slidedecks/countermeasure/index.html

69 of 69 11/19/2013 11:22 PM