Book a meeting

What is code obfuscation?

Code obfuscation is the process of modifying an executable so that it is useless to a hacker while remaining fully functional. The functionality of the code remains unchanged, and code obfuscation helps conceal the logic and purpose of an app’s code. It works through transformations like data, layout, and control flow obfuscation, each targeting different aspects of the code to mask its true structure and logic.

Summary

Code obfuscation is a standard method to prevent cybercriminals from decompiling and reverse engineering source code, and to protect apps from intellectual property theft. For JavaScript in hybrid apps and languages like Java or Kotlin in Android apps, obfuscation involves techniques like scrambling variable names and altering execution paths. Unlike encryption, which makes data unreadable without a key, obfuscation makes the code hard to decipher yet operational without decryption.

For enhanced security, obfuscation should be combined with runtime application self-protection (RASP), which monitors app behavior in real-time to detect and respond to threats. This combination is exemplified in technologies like Promon SHIELD™, which provides both obfuscation and dynamic protection, thus strengthening defense against intellectual property theft and reverse engineering. With increasing technological advancements and regulations like GDPR and CCPA, code obfuscation is evolving to incorporate AI and machine learning, promising more efficient and robust methods in the face of sophisticated attacks and regulatory demands for data protection.

Deep dive

How code obfuscation works

Code obfuscation works by applying various transformations to the source code, creating a layered defense that complicates the understanding of the code's structure and logic. These transformations can be classified into different levels depending on the aspect of the code they target:

  • Data obfuscation: Manipulates data storage and variable access to hide the true nature of data usage and storage patterns.
  • Layout obfuscation: Alters the physical structure of the code, including the organization of classes, methods, and variables, to confuse the logical understanding of the code.
  • Control flow obfuscation: Modifies the execution paths within the code without altering its functionality, making the logic difficult to trace and understand.

Let’s take a simple JavaScript function that calculates the sum of two numbers:

function addNumbers(a, b) {return a + b;}

This code is easy to read and understand. However, if you obfuscate this code using layout obfuscation, it might look something like this: function _0x3f5c(_0x1a2d9c,_0x3d512a {return _0x1a2d9c+_0x3d512a;}

In the obfuscated version, variable names are replaced with cryptic strings. The function's logic remains the same, but the readability is significantly reduced, protecting the code from reverse engineering.

JavaScript obfuscation

In the context of hybrid apps that utilize JavaScript, obfuscation is vital due to the inherent vulnerabilities associated with interpreted languages. Obfuscating JavaScript involves hiding or scrambling strings, objects, and variable names.

iOS obfuscation

Research has shown that a common myth surrounding iOS is that it's more secure than Android. To prevent this, using iOS obfuscation techniques such as control flow and string obfuscation can add layers of security that make it harder for attackers to analyze or reverse engineer the app.

Android obfuscation

Android apps, written in languages like Java or Kotlin, are particularly susceptible to reverse engineering due to the use of Java Bytecode. Obfuscation techniques for Android include renaming classes, methods, and variables, namespace flattening, and code shuffling to disrupt readability and structural understanding of code.

Obfuscation vs. encryption

While both obfuscation and encryption are used to protect code, they serve different purposes:

  • Obfuscation disguises the code, making it hard to understand but still functional without decryption.
  • Encryption encodes the data, making it unreadable without a key.
In the context of app security, encryption protects data at rest and in transit, whereas obfuscation protects the source code from being understood.

Combining code obfuscation with RASP

To fully protect mobile apps, code obfuscation should be combined with runtime application self-protection (RASP). RASP provides dynamic protection by monitoring the app's execution environment and behavior, detecting and responding to attacks in real time. This is crucial because obfuscation alone does not protect against runtime attacks or when an attacker manipulates the execution flow directly. With solutions like Promon SHIELD™, apps benefit from both obfuscation and advanced runtime protection.

Examples

  1. String encryption in messaging apps: In secure messaging apps like Signal or WhatsApp, string encryption is used to obfuscate API endpoints, keys, and other sensitive strings. This method transforms readable strings into encrypted formats that are only deciphered during runtime.
  2. Control flow obfuscation in financial apps: Mobile banking apps often employ control flow obfuscation to alter the logical execution paths without changing the app's functionality. This makes the reverse engineering process significantly more complex and time-consuming, thereby deterring attackers from identifying and exploiting logic-specific vulnerabilities like transaction processes or authentication methods.
  3. Renaming obfuscation in health apps: Health applications, which handle sensitive personal health information (PHI), use renaming obfuscation to change the names of classes, methods, and variables into meaningless labels. This protects against threats where attackers could gain insights into how data is processed and stored, thus safeguarding against data breaches.

History

In the 1970s, code obfuscation originated from the need to protect software intellectual property and prevent unauthorized access or modification of code. It was a technique to transform readable code into cryptic versions using languages like C/C++ and Perl.

The evolution of code obfuscation is closely tied to the rise of internet connectivity and mobile technology, which expanded the attack surface for applications. As applications began handling more sensitive data and became integral to business operations, the stakes for protecting software increased dramatically.

A significant milestone occurred in 1984 with the launch of the International Obfuscated C Code Contest, celebrating creatively obfuscated C source code, highlighting the artistry of making code intentionally complex and hard to decipher. In the 1990s, JavaScript’s prominence on the web further popularized obfuscation as developers sought to protect their code from reverse engineering and tampering, especially with the rise of cross-platform frameworks like React Native and Ionic.

Obfuscation has evolved from simple techniques like renaming variables to more sophisticated methods like control flow alteration and string encryption, aimed at defending against advanced reverse engineering and automated attacks.

Future

Today, code obfuscation is a critical component in mobile application security, especially given the ease with which apps can be reverse-engineered once deployed. The future of obfuscation is shifting in connection with new technologies, emerging threats, and growing regulations. AI and machine learning are beginning to play a significant role in code obfuscation. These technologies can automate the obfuscation process, making it more efficient and robust.

While still in the early stages, the potential rise of quantum computing poses a new challenge to current cryptographic methods and, by extension, to code obfuscation techniques that rely on cryptographic security.

Emerging threats such as the development of more sophisticated decompilation tools using AI make it easier to reverse engineer obfuscated code and potentially automate the process of reversing them. The rise of regulations like GDPR and CCPA increases the need for obfuscation of personal data within applications. Emerging requirements for transparency in software development, like the Software Bill of Materials (SBOM), which is part of the US Executive Order on Improving the Nation’s Cybersecurity, could impact code obfuscation practices.

Sources

  1. https://www.bbc.com/news/technology-63255661
  2. https://promon.co/resources/downloads/guide-app-code-obfuscation/
  3. https://csrc.nist.gov/glossary/term/obscured_data
  4. https://mas.owasp.org/MASTG/tests/ios/MASVS-RESILIENCE/MASTG-TEST-0093/