26
Android game hacking :) Seokha Lee (wh1ant) Security Researcher at SEWORKS seworks.co SECUINSIDE 2015

Android game hacking :) - SECUINSIDEsecuinside.com/archive/2015/2015-1-4.pdf · Android game hacking :) ... (gdb)dump memory FileName 0xb6edb000 0xb6ee4000. seworks.co Anti-decompile

Embed Size (px)

Citation preview

Page 1: Android game hacking :) - SECUINSIDEsecuinside.com/archive/2015/2015-1-4.pdf · Android game hacking :) ... (gdb)dump memory FileName 0xb6edb000 0xb6ee4000. seworks.co Anti-decompile

Android game hacking :) 

Seokha Lee (wh1ant)Security Researcher at SEWORKS

seworks.co

SECUINSIDE 2015

Page 2: Android game hacking :) - SECUINSIDEsecuinside.com/archive/2015/2015-1-4.pdf · Android game hacking :) ... (gdb)dump memory FileName 0xb6edb000 0xb6ee4000. seworks.co Anti-decompile

Memory manipulationCode injection

Explanation Unity3dReverse engineering

Speed hackDemoQ&A

seworks.co

Agenda

Page 3: Android game hacking :) - SECUINSIDEsecuinside.com/archive/2015/2015-1-4.pdf · Android game hacking :) ... (gdb)dump memory FileName 0xb6edb000 0xb6ee4000. seworks.co Anti-decompile

My first mobile hacking

seworks.co

Saving game file

Send to me a game item

Save to mobile

Page 4: Android game hacking :) - SECUINSIDEsecuinside.com/archive/2015/2015-1-4.pdf · Android game hacking :) ... (gdb)dump memory FileName 0xb6edb000 0xb6ee4000. seworks.co Anti-decompile

seworks.co

Easy hack using ptrace()

Page 5: Android game hacking :) - SECUINSIDEsecuinside.com/archive/2015/2015-1-4.pdf · Android game hacking :) ... (gdb)dump memory FileName 0xb6edb000 0xb6ee4000. seworks.co Anti-decompile

seworks.co

/proc/<pid>/mem

/proc/<pid>/maps

memory scan!

Hack!

lseek()

Page 6: Android game hacking :) - SECUINSIDEsecuinside.com/archive/2015/2015-1-4.pdf · Android game hacking :) ... (gdb)dump memory FileName 0xb6edb000 0xb6ee4000. seworks.co Anti-decompile

seworks.co

Page 7: Android game hacking :) - SECUINSIDEsecuinside.com/archive/2015/2015-1-4.pdf · Android game hacking :) ... (gdb)dump memory FileName 0xb6edb000 0xb6ee4000. seworks.co Anti-decompile

seworks.co

Code injection 1

Page 8: Android game hacking :) - SECUINSIDEsecuinside.com/archive/2015/2015-1-4.pdf · Android game hacking :) ... (gdb)dump memory FileName 0xb6edb000 0xb6ee4000. seworks.co Anti-decompile

seworks.co

Unity3dAPK —> libs —> armeabi-v7a

Page 9: Android game hacking :) - SECUINSIDEsecuinside.com/archive/2015/2015-1-4.pdf · Android game hacking :) ... (gdb)dump memory FileName 0xb6edb000 0xb6ee4000. seworks.co Anti-decompile

seworks.co

Unity3dAPK —> Assets —> bin —> Data —> Managed

Page 10: Android game hacking :) - SECUINSIDEsecuinside.com/archive/2015/2015-1-4.pdf · Android game hacking :) ... (gdb)dump memory FileName 0xb6edb000 0xb6ee4000. seworks.co Anti-decompile

seworks.co

Code injection 2APK —> libs —> armeabi-v7a

dlopen()dlsym()dlclose()

Page 11: Android game hacking :) - SECUINSIDEsecuinside.com/archive/2015/2015-1-4.pdf · Android game hacking :) ... (gdb)dump memory FileName 0xb6edb000 0xb6ee4000. seworks.co Anti-decompile

seworks.co

.NET Decompiler

Page 12: Android game hacking :) - SECUINSIDEsecuinside.com/archive/2015/2015-1-4.pdf · Android game hacking :) ... (gdb)dump memory FileName 0xb6edb000 0xb6ee4000. seworks.co Anti-decompile

seworks.co

https://en.wikipedia.org/wiki/List_of_CIL_instructions

Page 13: Android game hacking :) - SECUINSIDEsecuinside.com/archive/2015/2015-1-4.pdf · Android game hacking :) ... (gdb)dump memory FileName 0xb6edb000 0xb6ee4000. seworks.co Anti-decompile

seworks.co

Packing and Encryption

(gdb)dump memory FileName 0xb6edb000 0xb6ee4000

Page 14: Android game hacking :) - SECUINSIDEsecuinside.com/archive/2015/2015-1-4.pdf · Android game hacking :) ... (gdb)dump memory FileName 0xb6edb000 0xb6ee4000. seworks.co Anti-decompile

seworks.co

Anti-decompile

Normal header for x64 ELF

Modified header for x64 ELF

Page 15: Android game hacking :) - SECUINSIDEsecuinside.com/archive/2015/2015-1-4.pdf · Android game hacking :) ... (gdb)dump memory FileName 0xb6edb000 0xb6ee4000. seworks.co Anti-decompile

seworks.co

Anti-decompile

… or Insert “pop {pc}” instruction

Page 16: Android game hacking :) - SECUINSIDEsecuinside.com/archive/2015/2015-1-4.pdf · Android game hacking :) ... (gdb)dump memory FileName 0xb6edb000 0xb6ee4000. seworks.co Anti-decompile

seworks.co

…or “/etc/hosts” falsification

Page 17: Android game hacking :) - SECUINSIDEsecuinside.com/archive/2015/2015-1-4.pdf · Android game hacking :) ... (gdb)dump memory FileName 0xb6edb000 0xb6ee4000. seworks.co Anti-decompile

seworks.co

Kernel Level HookLKM (Loadable kernel module)

Page 18: Android game hacking :) - SECUINSIDEsecuinside.com/archive/2015/2015-1-4.pdf · Android game hacking :) ... (gdb)dump memory FileName 0xb6edb000 0xb6ee4000. seworks.co Anti-decompile

seworks.co

Speed hackPast time and current time network time synchronization

Page 19: Android game hacking :) - SECUINSIDEsecuinside.com/archive/2015/2015-1-4.pdf · Android game hacking :) ... (gdb)dump memory FileName 0xb6edb000 0xb6ee4000. seworks.co Anti-decompile

seworks.co

DEMO

Page 20: Android game hacking :) - SECUINSIDEsecuinside.com/archive/2015/2015-1-4.pdf · Android game hacking :) ... (gdb)dump memory FileName 0xb6edb000 0xb6ee4000. seworks.co Anti-decompile

seworks.co

Anti-breakpoint1. get memory information ‘r-xp’ from /proc/self/maps map_fd = open(“/proc/self/maps”, O_RDONLY);

2. create a file for code, like this. fd = open(“code”, O_WRONLY|O_CREAT, 0500);

3. write code to the ‘code’ file. write(fd, 0xb6d5e000, 0xb6d69000-0xb6d5e000);

4. open new ‘code’ file for file mapping using mmap() mmap(new_fd, 0xb6d5e000, 0xb6d69000-0xb6d5e000, PROT_READ|PROT_EXEC, MAP_SHARED|MAP_FIXED, new_fd, 0);

Page 21: Android game hacking :) - SECUINSIDEsecuinside.com/archive/2015/2015-1-4.pdf · Android game hacking :) ... (gdb)dump memory FileName 0xb6edb000 0xb6ee4000. seworks.co Anti-decompile

seworks.co

Anti-breakpoint

b6d5e000-b6d69000 r-xp 00000000 b3:19 1097

to

b6d5e000-b6d69000 r-xs 00000000 b3:19 1097

but…

Page 22: Android game hacking :) - SECUINSIDEsecuinside.com/archive/2015/2015-1-4.pdf · Android game hacking :) ... (gdb)dump memory FileName 0xb6edb000 0xb6ee4000. seworks.co Anti-decompile

seworks.co

How to defense

Control flow Data flowObfuscation

… and randomization!

Page 23: Android game hacking :) - SECUINSIDEsecuinside.com/archive/2015/2015-1-4.pdf · Android game hacking :) ... (gdb)dump memory FileName 0xb6edb000 0xb6ee4000. seworks.co Anti-decompile

seworks.co

Obfuscation

mov %r0, #1mov %r1, #2bl 0x4000

push {r3} mov %r3, #16384 mov %r2, #0 mov %r1, #1 add %r2, %r2, %r2 add %r0, %r2, %r1 mov %r1, #9 add %r1, %r0, %r1 sub %r1, #8 blx r3 pop {r3}

Page 24: Android game hacking :) - SECUINSIDEsecuinside.com/archive/2015/2015-1-4.pdf · Android game hacking :) ... (gdb)dump memory FileName 0xb6edb000 0xb6ee4000. seworks.co Anti-decompile

seworks.co

Fast update!

Page 25: Android game hacking :) - SECUINSIDEsecuinside.com/archive/2015/2015-1-4.pdf · Android game hacking :) ... (gdb)dump memory FileName 0xb6edb000 0xb6ee4000. seworks.co Anti-decompile

Q&A

seworks.co