bsideslondon | your money, your media - a drmtastic android (reverse|re

37
Your money, your media A DRMtastic (reverse|re)engineering tutorial

Upload: chandra-pratap

Post on 20-Aug-2015

686 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

Your money, your mediaA DRMtastic (reverse|re)engineering tutorial

Page 2: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

Who dat dude with the mic?

● Hi, I'm Manuel. An academic researcher without

academic title.

Page 3: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

What's this talk about

Page 4: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

Kobo

● Global eBook retailer

● “We believe consumers should be able to read any book, anytime,

anywhere, and on the device of their choice”

● “We believe open standards for eBooks are best for consumers,

publishers, retailers and hardware manufacturers. Closed systems

stifle innovation and growth. Kobo proudly supports EPUB and

encourages our users to read a Kobo-purchased eBook on their

smartphone, Sony Reader, laptop, or whichever device they

choose.”

Page 5: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

No problem, then!

Page 6: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

fbreader

Page 7: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

I AM DISAPPOINT

Page 8: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

trollface.jpg

Page 9: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

● I BUY books. I don't

“lend them under

certain terms”.

● $10 for a digital copy,

and you restrict how I

use it?

Page 10: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

NOTICE

● I ONLY WANTED TO ACHIEVE

INTEROPABILITY WITH OTHER PROGRAMS

● THAT ARE NOT COMPETING WITH THE KOBO

READER

● KOBOPIER ONLY REPRODUCES THE

DECRYPTION INTERFACE

● DON'T PIRATE XOR DON'T GET CAUGHT

Page 11: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

Whoo, look at my ePeni...nsula!

Page 12: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

Android reversing

● Dalvik

● Smali

● Can haz apktool?

Page 13: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

smali example code

Page 14: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

Workflow example

● adb pull /data/app/com.MyLittlePony.apk /tmp/

● java -jar baksmali.jar -o /tmp/pony MyLittlePony.apk

● OR apktool d MyLittlePony.apk /tmp/pony

● vim /tmp/pony/smali/com/mylilpony/Main.smali

Page 15: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

MOAR DATA

● adb pull /data/data/com.kobobooks.android/ kobothings

Page 16: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

OMG Obfuscation

Page 17: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

OMG Obfuscation

Page 18: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

Your reaction: Anger

Page 19: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

Your reaction: Resignation

Page 20: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

Your reaction: The Right One

Page 21: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

Java/smali is hard to obfuscate

● MADE to be readable

● invoke-static {p0, v1, v0}, Lcom/kobobooks/android/f/i;-

> a([BLjavax/crypto/Cipher;Ljavax/crypto/SecretKey;)[B

Page 22: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

The search begins

grep -Ri javax.crypto...?

...Algorithm="http://www.w3.org/2001/04/xmlenc#aes128-

cbc"/>

...so I'm searching for “AES”.

Page 23: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

Bingo!...FAIL.

● Found a decryption!

● sqlite3 <kobo

datadir>/databases/Kobo

● '.tables' + '.headers on'

● ParentContentID|...|

DecryptKey|...

Page 24: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

BUT I WANNA!!!!! ;_;

Page 25: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

Moar reversing

● Who's calling my decryption?

● What other methods is it calling?

● Learn to read smali. It's a somewhat neat language.

● What data is it using?

● ...remote Dalvik debugging?

Page 26: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

apktool

● Disassemble

● Modify (theme, patch, break...)

● Build (apktool b...)

● Sign (jarsigner)

● adb install hax.apk

● Uninstall the old version first

Page 27: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

Bingo!...FAIL...ish.

Page 28: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

On the right track!

● Then: “Is it possible?”

● Now: “How to make it practical?”

● More patching: Dumping all parts of the key

● Caller of the decryption method creates the key

● Three strings as input

● Does some weirdass stuff, more on that later

Page 29: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

Key parts

/OzEca8ESalQNvd/xknj8g==

ee13373-bb8a-5a09-ccdd-af9c4fbgf844

503668452247539

May the logs be with you.

Page 30: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

Hashing IDs && Base64 decode

● H(DeviceID || UserID).substring(16);

● Algorithms (hardcoded arrays/tables) look

intimidating in smali

● Public Domain Base64.java :)

Page 31: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

Part Three: WTF Crypto?

Page 32: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

Part Three: WTF Crypto

Hardcoded Strings, again!

Page 33: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

Part Three: WTF Crypto

● Rijndael

● BouncyCastle AND own implementation

● I'm here to break, not question it.

● encrypt() and decrypt() have the same signature...

Page 34: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

Putting the parts together

● Read chapter (cp /sdcard/Kobo/epubs ...)

● H(DeviceID || UserID)

● base64_decode(DecryptKey)

● D(encoded_decryptkey, hash_part)

● Clever (and common) from a DRM perspective

● D(chapter, decrypted_key)

Page 35: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

BINGO!

Page 36: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

Result: Kobopier

* Kobopier - a Kobo Android ePub DRM stripper

*

* You can reach the author at [email protected].

* New versions of Kobopier will be made available at http://sporkbomb.eu/kobopier/.

*

* Important note: Kobopier is not made for piracy. It does not break any encryption,

* it simply replicates a few steps the original Android Kobo reader does.

* Please read the license below. Also, consider that it is YOUR responsibility to deal

* with any legal issues that arise from YOU using this tool.

* If you buy one copy of an ebook, decrypt it with this tool and then give it away,

* that's fine with me - but you alone are responsible if Kobo sues you.

*

* Copyright (C) 2011 sporkbomb

http://sporkbomb.eu/kobopier/

Page 37: BSidesLondon | Your Money, Your Media - A DRMtastic Android (reverse|re

@__sporkbomb

● Questions?

● Complaints?

● Compliments?

● Suggestions?