mobile game security€¦ · • introduction to il2cpp • ida plugin • conclusions. attack...

22
Mobile Game Security Is IL2CPP So Secure?

Upload: others

Post on 25-Aug-2020

46 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Mobile Game Security€¦ · • Introduction to IL2CPP • IDA Plugin • Conclusions. Attack & Defense of Mobile Games ... • Cocos2d-x – Dedicated to 2D – Cross Platform –

Mobile Game Security

Is IL2CPP So Secure?

Page 2: Mobile Game Security€¦ · • Introduction to IL2CPP • IDA Plugin • Conclusions. Attack & Defense of Mobile Games ... • Cocos2d-x – Dedicated to 2D – Cross Platform –

About Me• nevermoe– Interest:Swimming, Skiing, (Pretend to be)

Otaku– Bio:

Page 3: Mobile Game Security€¦ · • Introduction to IL2CPP • IDA Plugin • Conclusions. Attack & Defense of Mobile Games ... • Cocos2d-x – Dedicated to 2D – Cross Platform –

Contents• Attack & Defense of Mobile Games• Introduction to IL2CPP• IDA Plugin• Conclusions

Page 4: Mobile Game Security€¦ · • Introduction to IL2CPP • IDA Plugin • Conclusions. Attack & Defense of Mobile Games ... • Cocos2d-x – Dedicated to 2D – Cross Platform –

Attack & Defense of Mobile Games(Cheating)

• Network Traffic Manipulation– Replay– Request or Response Tampering

• Local Modification– Memory Cheat– Speed Hack– File Tampering– Binary Patch– hook

Network Traffic Manipulation

Local Modification

Page 5: Mobile Game Security€¦ · • Introduction to IL2CPP • IDA Plugin • Conclusions. Attack & Defense of Mobile Games ... • Cocos2d-x – Dedicated to 2D – Cross Platform –

Attack & Defense of Mobile Games(Anti-cheating)

• Network Traffic Manipulation – Replay ー> Add Token

– Request or Response Tampering ー> Encryption / SSL Pinning

• Local Tampering– Memory Cheat ー> Memory Encrytion

– Speed Hack ー> Local Detection / Sever Timestamp

– File Tampering ー> Local File Encryption / Hash Check

– Binary Patch -> Packing / Obfuscation / Hash Check

– Hook ー> Anti debug / Hook Framework Detection / Injection Detection

Page 6: Mobile Game Security€¦ · • Introduction to IL2CPP • IDA Plugin • Conclusions. Attack & Defense of Mobile Games ... • Cocos2d-x – Dedicated to 2D – Cross Platform –

Attack & Defense of Mobile Games(Game Engines)

• Unity3D– Both 2D and 3D Supported– Cross Platform– Source Code is Partially Open

• Cocos2d-x– Dedicated to 2D– Cross Platform– Open Source

• FlashAIR/Unreal/Corona etc.• Customized Engine

Market Share is overwhelming

Page 7: Mobile Game Security€¦ · • Introduction to IL2CPP • IDA Plugin • Conclusions. Attack & Defense of Mobile Games ... • Cocos2d-x – Dedicated to 2D – Cross Platform –

Attack & Defense of Mobile Games(Unity3D Anti-cheating Overview)

• Unity3D Anti-cheating Toolkit–Memory Encryption– Speed-hack Detection– Etc.

=>This kind of protection fails once the binary is reversed

Page 8: Mobile Game Security€¦ · • Introduction to IL2CPP • IDA Plugin • Conclusions. Attack & Defense of Mobile Games ... • Cocos2d-x – Dedicated to 2D – Cross Platform –

Attack & Defense of Mobile Games(Purpose)

* This kind of protection fails once the binary is reversed• iOS -> IL2CPP– Easy to get– No Packing or Obfuscation

• Android -> Mono– Packing– Obfuscating

=> Read the Assembly Code!

=> To reverse assembly code?

=> Or to reverse obfuscated code?

Page 9: Mobile Game Security€¦ · • Introduction to IL2CPP • IDA Plugin • Conclusions. Attack & Defense of Mobile Games ... • Cocos2d-x – Dedicated to 2D – Cross Platform –

• Android

• iOS

Introdcution to IL2CPP(Without IL2CPP / Scripting Backend: Mono )

Assembly-Csharp.dll

Java smali file

native so file

IL code、easy to decompile

Page 10: Mobile Game Security€¦ · • Introduction to IL2CPP • IDA Plugin • Conclusions. Attack & Defense of Mobile Games ... • Cocos2d-x – Dedicated to 2D – Cross Platform –

Introdcution to IL2CPP(With IL2CPP / Scripting Backend: IL2CPP)

• Android

• iOS

libil2cpp.so

Page 11: Mobile Game Security€¦ · • Introduction to IL2CPP • IDA Plugin • Conclusions. Attack & Defense of Mobile Games ... • Cocos2d-x – Dedicated to 2D – Cross Platform –

Introdcution to IL2CPP (Overview)

libiPhone.a (libil2cpp)

Bulk_Assembly-Csharp.cpp○○○.cpp…

link

compile DWARF (exe)

h

h

Page 12: Mobile Game Security€¦ · • Introduction to IL2CPP • IDA Plugin • Conclusions. Attack & Defense of Mobile Games ... • Cocos2d-x – Dedicated to 2D – Cross Platform –

Introdcution to IL2CPP (Functions of libil2cpp)

• libil2cpp (libiPhone.a etc.)– Support VM– Garbage Collection–Metadata Loader

Page 13: Mobile Game Security€¦ · • Introduction to IL2CPP • IDA Plugin • Conclusions. Attack & Defense of Mobile Games ... • Cocos2d-x – Dedicated to 2D – Cross Platform –

Introdcution to IL2CPP (Metadata)

Data/Managed/Metadata/global-metadata.dat

void EnemyAttack(…)

Page 14: Mobile Game Security€¦ · • Introduction to IL2CPP • IDA Plugin • Conclusions. Attack & Defense of Mobile Games ... • Cocos2d-x – Dedicated to 2D – Cross Platform –

Introdcution to IL2CPP(Analysis Approach)

• Analysis Approach – By analyzing libiPhone.a• This File is guaranteed to exist• With Symbol

– By analyzing source code of libil2cpp• Source code is attached when building a Windows

Store App

Page 15: Mobile Game Security€¦ · • Introduction to IL2CPP • IDA Plugin • Conclusions. Attack & Defense of Mobile Games ... • Cocos2d-x – Dedicated to 2D – Cross Platform –

Introdcution to IL2CPP(Loading Metadata)

• Read Global-metadata.dat and cast

Page 16: Mobile Game Security€¦ · • Introduction to IL2CPP • IDA Plugin • Conclusions. Attack & Defense of Mobile Games ... • Cocos2d-x – Dedicated to 2D – Cross Platform –

Introdcution to IL2CPP(Loading StringLiteral)

//MetadataCache.cppvoid MetadataCache::InitializeMethodMetadata (uint32_t index){ ...... for (uint32_t i = 0; i < count; i++) { ...... switch (usage) { ...... case kIl2CppMetadataUsageStringLiteral: *s_Il2CppMetadataRegistration->metadataUsages[destinationIndex] = GetStringLiteralFromIndex (decodedIndex); break; default: …. } }

h

Page 17: Mobile Game Security€¦ · • Introduction to IL2CPP • IDA Plugin • Conclusions. Attack & Defense of Mobile Games ... • Cocos2d-x – Dedicated to 2D – Cross Platform –

Introdcution to IL2CPP(Loading MethodInfo)

// Class.cppvoid SetupMethodsLocked (Il2CppClass *klass, const FastAutoLock& lock){ ... for (MethodIndex index = start; index < end; ++index) { ... newMethod->name = MetadataCache::GetStringFromIndex (methodDefinition->nameIndex); ... newMethod->methodPointer = MetadataCache::GetMethodPointerFromIndex (methodDefinition->methodIndex); ... } ...}

// MetadataCache.cppIl2CppMethodPointer MetadataCache::GetMethodPointerFromIndex (MethodIndex index){ … return s_Il2CppCodeRegistration->methodPointers[index];}

h

Page 18: Mobile Game Security€¦ · • Introduction to IL2CPP • IDA Plugin • Conclusions. Attack & Defense of Mobile Games ... • Cocos2d-x – Dedicated to 2D – Cross Platform –

IDA Plugin (Mapping to IDA)

• iOS

String

Method

Page 19: Mobile Game Security€¦ · • Introduction to IL2CPP • IDA Plugin • Conclusions. Attack & Defense of Mobile Games ... • Cocos2d-x – Dedicated to 2D – Cross Platform –

IDA Plugin (Notes)

• Unity Version later than 5.3.6–Metadata version 21

• iOS, Android: Auto-load

• Other platform: Manual-load

• IDA failed to make xref or function when parsing Android’s binary. (So iOS version is recommended)

Page 20: Mobile Game Security€¦ · • Introduction to IL2CPP • IDA Plugin • Conclusions. Attack & Defense of Mobile Games ... • Cocos2d-x – Dedicated to 2D – Cross Platform –

Demonstrations1. Plugin Usage2. Cheating Demo

Page 21: Mobile Game Security€¦ · • Introduction to IL2CPP • IDA Plugin • Conclusions. Attack & Defense of Mobile Games ... • Cocos2d-x – Dedicated to 2D – Cross Platform –

Conclusions• Cheating and Anti-cheating is dynamic• Do NOT rely only on IL2CPP to protect

your binary• Counter measure:Obfuscating strings in

metadata• Source Code: https://github.com/

nevermoe/unity_metadata_loader

Page 22: Mobile Game Security€¦ · • Introduction to IL2CPP • IDA Plugin • Conclusions. Attack & Defense of Mobile Games ... • Cocos2d-x – Dedicated to 2D – Cross Platform –

Thank you!