Understanding The Role of Obfuscation in Mobile App Protection
Understanding The Role of Obfuscation in Mobile App Protection
Table of contents
Introduction............................................................................................................................ 3
What is obfuscation?.............................................................................................................. 5
Key considerations when it comes to practical implementation................................ 5
What does obfuscation aim to achieve?........................................................................ 6
Factors influencing the adoption of obfuscation in mobile app development............. 6
Dissecting the Android APK and iOS IPA files.................................................................. 7
Android............................................................................................................................... 7
iOS....................................................................................................................................... 8
Disassembling and repackaging: How are the structures exploited?....................... 9
Obfuscation techniques......................................................................................................... 10
1. Name obfuscation........................................................................................................ 10
2. Control flow transformations...................................................................................... 10
3. Data abstraction........................................................................................................... 11
4. Obfuscation procedural abstractions........................................................................ 11
5. Preventing transformations........................................................................................ 11
6. API call hiding................................................................................................................ 12
7. Code virtualization........................................................................................................ 12
Benefits of code obfuscation................................................................................................ 13
Examples............................................................................................................................ 13
Evaluating code obfuscation effectiveness........................................................................ 15
Conclusion............................................................................................................................... 16
Examples:
To address these threats and strengthen iOS and Android app security,
reputable software security solution providers have introduced app obfuscation.
Understanding obfuscation techniques in Android and iOS app development is vital
to enhance security and protect mobile apps from evolving threats. The benefits of
such understanding mean app publishers and security researchers can refine their
development strategies based on the existing and expected future threat landscape.
Obfuscation is necessary for both the major mobile platforms, Android and iOS.
While the assumption might be that obfuscation on iOS is less necessary due
to its perceived heightened security, recent security incidents challenge this
notion. Sophisticated tools, such as Ghidra, have demonstrated that iOS reverse
engineering is not as challenging as commonly believed. iOS developers experience
similar challenges as their Android counterparts, grappling with severe software
piracy issues.
3. The belief that basic obfuscation tools (ProGuard and R8) are sufficient
Research has shown that software obfuscation is not widely prioritized in mobile
development. Developers in security-sensitive sectors acknowledge malicious
reverse engineering as a significant threat infact global research on mobile
application security reported that 28% of respondents claim an increase in
attempts to reverse engineer or modify apps is driving their organization to
consider or purchase mobile app security products.
Android
An Android Application Package (APK) file is a compressed zip file that contains the
entirety of an Android app, including four main directories ( res , assets , lib ,
and META-INF ) and three essential files ( AndroidManifest.xml , classes.dex , and
resources.arsc ). Let’s outline the functions and contents of these directories and
files below:
res: This directory stores Android resource files, which are subsequently
mapped into the R file in Android, acquiring corresponding IDs.
assets: Similar to the res directory, the assets directory stores static files in
the APK. In contrast to the res directory, developers can create subdirectories at
any depth with an arbitrary file structure.
Info.plist file: This file describes the application to the iOS operating
system, featuring properties such as the icon files, application display name,
version, unique identifier, and the filename of the main executable. The
structure of an IPA file is outlined in the Info.plist .
Resources: Documents, images, icons, video, and audio files essential for
the application’s functionality.
www: For web apps developed using frameworks like Cordova or React Native,
the web data is stored in a folder named www , encompassing web pages,
resources, JavaScript, CSS files, and more.
Attackers can easily inject malicious code and ads into unprotected Android apps
due to the straightforward process of unpacking, disassembling, and repacking.
Android’s lack of a key-pair certification requirement by a Certificate Authority (CA)
allows modified apps to be signed with the attacker’s key, making them appear as
new and legitimate. To further deceive security products relying on APK file hash
values, attackers may use different keys for the same repacked app.
To unpack the APK content, the initial step involves decompressing the APK file,
achievable with standard ZIP file handling software or more advanced tools like
apktool. Decompressed APKs can be modified and repackaged, resulting in a valid
new/modified app that must be re-signed, typically using apksigner.
Analyzing the certificate located in the META-INF folder, often with the file
extension RSA, using Java keytool. Although frequently self-signed, searching for
the certificate fingerprint may provide additional information.
• Investigating the assets folder for familiar logos or indicators of the original app.
To analyze the functionality, reverse engineers analyse the DEX files and native
libraries. For dex files, there are two approaches: either decompile it into Java source
code or disassemble it into a format such as smali. Native libraries, often written in
C and compiled for multiple CPU architectures can be reverse engineered by tools
like IDA Pro and Ghidra.
1. Name obfuscation
The first, most obvious, category involves identifier name transformations which
involves replacing names with meaning with meaningless names.
• Inline and outline functions: Functions are removed after inlining the code,
discarding the presence of abstraction. Outlining selects and uses statements of
a function to create sub-methods.
• Split variables: Variables with a restricted range are divided into two or more
variables, involving functions to record values and perform necessary tasks on
split variables.
5. Preventive transformations
Preventive transformation techniques are implemented to evade debugging and
decompilation tools.
7. Code virtualization
Code virtualization involves transforming your method body into a sequence of
instructions for a randomized virtual machine, which is then injected into your app
during the build process. Code virtualization begins by analyzing the behavior of
your method code and generating compact and efficient virtual machines, each with
its unique instruction set. After generating these virtual machines, your method is
re-implemented based on the new instruction set. When your method is invoked,
the new implementation is loaded, and an interpreter on the native virtual machine
executes the instructions. This result is the original method code being completely
concealed within the application.
Code virtualization synergizes effectively with other techniques such as API call
hiding, string encryption, or control flow obfuscation. For maximum protection, it can
even be combined with code encryption.
Protection
Code obfuscation serves as a robust defense against both static and dynamic
analysis attacks. By introducing complexity and making it challenging for attackers,
it necessitates more time and resources for them to achieve their objectives.
Diversity
The ability to generate various instances of the original program enhances
resilience against global attacks. This diversity hinders attackers from developing
standardized approaches, adding an extra layer of defense.
Cost-effectiveness
Code obfuscation incurs minimal maintenance costs, thanks to the automated
transformation process and compatibility with existing systems. This results in an
efficient and economical approach to enhancing security.
Platform independence
The application of code obfuscation transformations on high-level code ensures the
preservation of platform independence. This feature contributes to the versatility of
the obfuscated code across different environments.
Examples
You can try these examples out in the JavaScript Obfuscator Tool, though these
techniques are, of course, applicable to other languages.
loop = 1; i=1;sum=0;while(i<=100){sum=sum+i;i=i+1;}
loopSum = 0;
while (loop <= 100)
{
loopSum = loopSum + loop;
loop = loop + 1;
}
loop = 1; tempFoo = 1;
loopSum = 0; while(tempFoo != 0)
{
while (loop <= 100)
switch (tempFoo)
{ {
loopSum = loopSum + loop; case 1: loop = 1;
loopSum = 0;
loop = loop + 1;
tempFoo = 2;
} break;
case 2:
if (loop <= 100)
tempFoo = 3;
else tempFoo = 0;
break;
case 3:
loopSum = loopSum + loop;
loop = loop + 1;
tempFoo = 2;
break;
}
}
loop = 1; loop = 1;
loopSum = 0; private: tempFoo;
loopSum = 0;
while (loop <= 100)
{ while (loop <= 100)
loopSum = loopSum + loop; {
tempFoo = loop;
loop = loop + 1;
loopSum = loopSum + tempFoo;
} loop = loop + 1;
}
Potency
Potency measures the degree of obscurity introduced to the code to enhance its
complexity, making it more challenging for an attacker to comprehend. This involves
assessing the increased nesting complexity, control-flow complexity, variables
complexity, and program length resulting from obfuscation techniques.
Resilience
Resilience gauges the robustness of the obfuscation technique against automated
deobfuscators. Evaluation criteria include:
Cost
Cost evaluates the additional resources consumed by obfuscated code during
runtime, including:
Conclusion
In summary, a comprehensive evaluation of code obfuscation techniques involves
considering their impact on potency, resilience against deobfuscation, resource
cost, and effectiveness in maintaining stealth against both automated tools and
human analysis.
DexGuard offers mobile app protection with extensive Android app obfuscation
and security protocols strengthening your app and SDK security by implementing
multiple layers of code-hardening measures.
Request pricing
More than 900 customers worldwide across all major industries rely on Guardsquare
to help them identify security risks and protect their mobile applications against
reverse engineering and tampering.
www.guardsquare.com
17 Understanding the Role of Obfuscation in Mobile App Protection www.guardsquare.com © 2024 Guardsquare - All rights reserved