OWASP Top 10 for Mobile Apps: M8 – Code Tampering
In an era where mobile applications have become integral to business operations, security remains a critical concern. One of the top threats to mobile applications, as outlined by the OWASP (Open Web Application Security Project) Mobile Security Top 10, is Code Tampering. For software developers and penetration testers, understanding the intricacies of this risk is crucial. This blog post delves into M8: Code Tampering—why it matters, its potential impact, and how businesses can mitigate the associated risks.
Understanding Code Tampering in Mobile Apps
Code tampering occurs when an attacker manipulates or alters the source code, binaries, or execution flow of a mobile application. This tampering can take various forms, including modifying the code to bypass security checks, reverse engineering to steal intellectual property, or injecting malicious code to steal sensitive data. Mobile apps, which often handle sensitive information like personal data, payment details, and corporate data, are prime targets for these attacks.
Code tampering is part of the OWASP Mobile Security Top 10 and holds the M8 ranking. Given the sensitive nature of data handled by mobile apps, businesses must understand the impact of code tampering on their operations, data security, and bottom line.
The Business Impact of Code Tampering
Code tampering is not just a technical vulnerability—it can have serious financial and reputational consequences for businesses. Let’s break down the primary business impacts of code tampering:
1. Intellectual Property Theft
For businesses that invest significant resources into developing unique features or proprietary algorithms, code tampering represents a severe risk. Attackers can reverse-engineer apps to gain access to source code, stealing intellectual property. This can lead to lost competitive advantage, especially if attackers replicate and distribute the stolen code for malicious purposes.
2. Data Breaches
When attackers tamper with the code of a mobile app, they can manipulate it to gain unauthorised access to sensitive user data. This includes personal details, payment information, or corporate secrets. Data breaches often result in substantial financial losses due to fines, lawsuits, and loss of customer trust.
3. Reputational Damage
When users discover that an app has been compromised, it severely damages the reputation of the business. The breach of trust can lead to a loss of customers, lower app ratings, and negative media coverage. Trust is difficult to rebuild, especially for businesses that rely on mobile apps for customer engagement and transactions.
4. Regulatory and Legal Consequences
Data protection regulations, such as GDPR in Europe or CCPA in California, impose stringent penalties on businesses that fail to protect user data. Code tampering that leads to data breaches or privacy violations can result in regulatory fines, lawsuits, and legal action.
5. Revenue Losses
When an app’s functionality is compromised through code tampering—whether to disrupt operations, steal revenue-generating information, or manipulate app behaviour—businesses risk direct revenue loss. For example, if an e-commerce app is tampered with to alter pricing or process fraudulent transactions, it directly impacts profitability.
How Code Tampering Works
Understanding the technical mechanics of code tampering is essential for both developers and penetration testers. Here’s a closer look at how code tampering typically occurs in mobile apps:
1. Reverse Engineering
Reverse engineering involves deconstructing the compiled code of an app to understand its logic and structure. Attackers use decompilers or disassemblers to convert the app’s binary code back into human-readable code. Once reverse engineering is successful, they can identify vulnerabilities, such as hardcoded credentials, encryption weaknesses, or poorly implemented authentication mechanisms.
2. Modifying the Code
Once the code has been reverse-engineered, attackers can alter it to achieve their objectives. This might include:
- Bypassing security checks, such as authentication or in-app purchase verifications.
- Injecting malicious code that can steal or send user data to external servers.
- Cracking apps to remove licensing checks, enabling the app to be used without proper authorization.
3. Tampering with the App’s Behaviour
Attackers can also modify the runtime environment of the app by injecting malicious code into the app’s execution flow. This can be done by:
- Memory tampering to change the app’s behaviour at runtime.
- Hooking into system calls or API requests to intercept and manipulate data before it reaches the app.
Tampering with the App’s Behaviour
Tampering with an app’s behaviour is a more sophisticated form of code manipulation, where attackers don’t just modify static code or app resources, but actively manipulate the app during runtime. This dynamic approach allows attackers to bypass security measures and alter the app’s execution flow, often in real time. By doing so, they can gain unauthorised access to features, bypass security checks, or even cause the app to perform unintended actions.
There are two primary techniques used by attackers to tamper with an app’s behaviour: memory tampering and hooking.
1. Memory Tampering
Memory tampering is the process of altering the app’s memory while it is running, which can change the app’s behaviour without needing to modify its code directly. This can be done through a variety of tools and techniques that allow attackers to inspect, modify, or corrupt the memory space that the app occupies during execution.
How Memory Tampering Works
Memory tampering typically involves using tools like Frida, Xposed Framework, or Ghidra to inject malicious code or modify the app’s runtime variables. By modifying the contents of the app’s memory (such as changing values in memory buffers or altering specific variables), attackers can change the app’s behaviour to suit their needs. For example, they could:
- Alter financial data: In a mobile banking app, an attacker could change the balance displayed in the app, enabling them to fake a larger balance than the user actually has. This would not affect the server-side data but could trick the user into believing they have more funds than they do.
- Skip verification steps: Memory tampering could allow attackers to bypass security checks, such as skipping multi-factor authentication or validation steps. This could grant them access to restricted sections of the app without proper authorisation.
Real-World Example:
Imagine a scenario where a mobile gaming app includes an in-app purchase option. An attacker, through memory tampering, could change the amount of in-game currency that the app displays, without actually paying for it. By modifying the memory that stores the in-app currency value, the attacker can bypass the payment system entirely, obtaining free currency.
Mitigating Memory Tampering
- Encryption of Sensitive Data: Encrypting sensitive data stored in memory, especially key data like session tokens, passwords, or financial information, can reduce the risk of memory tampering.
- Runtime Integrity Checks: Implement runtime integrity checks that detect any modification of the app’s memory, either by checking for discrepancies in memory hashes or detecting abnormal changes to the app’s internal variables.
- Obfuscation and Anti-Tamper Techniques: Using obfuscation and tamper-detection techniques can make it more difficult for attackers to understand the app’s memory structure and alter its behaviour. These techniques can hide or obscure the memory locations, making tampering more challenging.
2. Hooking
Hooking is another technique where attackers intercept and manipulate system calls, API requests, or app functions during execution. By hooking into these functions, attackers can modify the data being passed between the app and the underlying operating system or external services. This allows them to tamper with the app’s behaviour by either modifying inputs before they are processed or altering the app’s output.
How Hooking Works
Hooking typically involves attaching custom code to a specific function or API that the app calls. This allows the attacker to intercept and control the data being sent to or from the app. For example, an attacker could hook into an app’s login API to intercept login credentials and redirect them to a malicious server. This could lead to the theft of user credentials or compromise sensitive personal data.
- System Call Hooking: Attackers can hook into system-level functions that the app relies on, such as network or file operations. By manipulating these calls, they can cause the app to behave differently or leak sensitive information.
- API Request Hooking: Attackers can hook into APIs used by the app to send or receive data, such as payment processing APIs or database access calls. By modifying the responses from these APIs, they can alter the app’s functionality.
Real-World Example:
A more sophisticated attack might involve an attacker using hooking techniques to intercept the network calls of a mobile banking app. The attacker could modify the API responses that return the account balance, displaying a falsified balance or even intercepting a funds transfer request, causing the money to be rerouted to the attacker’s account.
Mitigating Hooking
- Code Integrity Checks: Performing integrity checks on critical functions or system calls used by the app can help detect whether hooking has been used. If an app detects that a system call has been modified or tampered with, it can raise an alert or block the tampered functionality.
- Obfuscation and Anti-Hooking Techniques: To make hooking more difficult, developers can use code obfuscation techniques to make it harder for attackers to understand how the app interacts with system calls. Additionally, techniques like function signature validation and using encrypted API requests can help prevent hooking attacks.
- App Hardening Tools: Tools such as AppSealing or DexGuard can help harden mobile apps against runtime manipulation by making it more difficult for attackers to inject hooks or modify app behaviour.
Practical Insights for Developers
Understanding how attackers can tamper with an app’s behaviour is crucial for developers who wish to build secure mobile applications. Here are some practical steps developers can take to protect their apps from runtime tampering:
- Use Strong Encryption: Always encrypt sensitive data both in transit and at rest. This applies to any data being stored on the device or sent between the app and server. By encrypting the data, attackers will be less able to modify it during runtime.
- Regularly Update and Patch: Keep the app up-to-date with the latest security patches. Address any vulnerabilities as they are discovered and release updates to ensure that the app remains resistant to the latest tampering techniques.
- Secure APIs and Endpoints: Ensure that any APIs or web services used by the app are secure. This includes validating inputs, using strong authentication methods, and verifying the integrity of API responses before they are processed by the app.
- Use Runtime Protection Libraries: There are several libraries and frameworks available to help protect your app from tampering at runtime. Integrating these libraries into your app can help detect suspicious activity and protect against memory tampering and hooking.
- Testing and Penetration Testing: Regularly test your app for security vulnerabilities using penetration testing and security audits. Penetration testers can help identify weaknesses in your app’s design and implementation that could be exploited by attackers.
4. Rooted/Jailbroken Devices
Rooted or jailbroken devices present a significant risk to mobile app security, as they remove many of the built-in protections that operating systems like Android and iOS offer to safeguard against malicious activity. Once a device is rooted or jailbroken, attackers gain greater control over the device, enabling them to manipulate the mobile operating system, install custom firmware, and bypass security measures that would otherwise prevent code tampering.
Rooting and Jailbreaking Defined
- Rooting (Android): Rooting refers to the process of gaining root access to an Android device. It allows users to access the device’s system files and make changes that are typically restricted by the manufacturer. Once a device is rooted, an attacker can install and run any software, including malicious apps that would normally be blocked by Android’s security protocols.
- Jailbreaking (iOS): Jailbreaking is the equivalent process for iOS devices, such as iPhones and iPads. By jailbreaking a device, users can remove the limitations imposed by Apple and gain root-level access to the operating system. This allows for the installation of non-App Store apps, custom modifications, and in some cases, the ability to alter the device’s core functions.
While rooting and jailbreaking may have legitimate uses for developers or power users who want more control over their devices, these modifications make the device much more susceptible to attacks. Once a device is rooted or jailbroken, security mechanisms are often weakened or entirely bypassed, making it easier for attackers to tamper with mobile apps.
The Risks of Rooted and Jailbroken Devices
Rooted or jailbroken devices are particularly vulnerable to a wide range of security threats, including code tampering. Below are some key risks associated with these devices:
1. Bypassing App Security Controls
On a rooted or jailbroken device, attackers can bypass a mobile app’s built-in security controls. For example, they could disable security features like SSL pinning or code obfuscation, making it easier for them to reverse-engineer the app or tamper with its behaviour.
- Example: In a typical mobile banking app, SSL pinning ensures that the app only communicates with trusted servers. On a rooted device, attackers can disable this feature, allowing them to intercept communication and potentially steal login credentials or transaction data.
2. Accessing and Modifying App Data
Rooted and jailbroken devices allow attackers to access the underlying file system of the device. This means that they can extract sensitive data from an app’s local storage, modify that data, or even inject malicious code into the app.
- Example: A malicious actor could tamper with an app’s database, altering the balance of a mobile payment application, or injecting fake transactions into a financial app. This could result in fraud or financial loss for both the business and the users.
3. Installation of Malicious Software
Rooted and jailbroken devices are more susceptible to the installation of malicious software, including trojans, spyware, and adware. Once installed, these malicious programs can monitor user activities, steal personal information, or even act as a launching point for further attacks.
- Example: An attacker could install a keylogger on a rooted device to monitor every keystroke, including sensitive information like passwords and PINs, which could then be used to compromise user accounts.
4. Exploitation of Vulnerabilities
By modifying the operating system, attackers can exploit security vulnerabilities that would otherwise be protected on non-rooted devices. With administrative privileges, attackers can disable security patches and updates, leaving the device vulnerable to known exploits.
- Example: A mobile app that relies on the security of the device’s operating system for protecting encryption keys could be compromised if the device has a security vulnerability that is actively exploited by an attacker.
5. Tampering with App Code
On a rooted or jailbroken device, attackers can directly modify the app’s code or runtime behaviour. This can be achieved by manipulating the app’s code with tools like Frida, or by modifying the app’s APK (for Android) or IPA (for iOS) files to alter functionality.
- Example: In an app designed to enforce a specific behaviour, such as limiting the number of times a user can redeem a coupon, attackers could modify the app’s code to bypass this limit, allowing them to redeem coupons without restriction.
Mitigating the Risks of Rooted and Jailbroken Devices
For developers and penetration testers, it is crucial to understand the impact of rooted and jailbroken devices on mobile app security. Below are several strategies to mitigate the risks associated with these devices:
1. Device Integrity Checks
Mobile apps should implement integrity checks to detect whether the device has been rooted or jailbroken. This can be done by checking for specific files, processes, or system properties that are indicative of a compromised device. For instance, checking for the presence of a superuser (root) app on Android or Cydia on iOS can indicate a rooted or jailbroken device.
- Example: An app could check if the device has an unusual binary file, such as su on Android (which provides root access), or if the /system/app directory has been altered, which is common in rooted Android devices.
2. Root/Jailbreak Detection Libraries
There are several open-source libraries available for both Android and iOS that can help detect rooted or jailbroken devices. These libraries typically scan the device for signs of tampering, such as unusual file system changes or the presence of root management tools, and trigger a response.
- Example: Libraries like RootBeer for Android or Objection for iOS can be integrated into mobile apps to detect root or jailbreak and alert the app when a suspicious device is detected.
3. Runtime Protections
In addition to preemptively detecting rooted and jailbroken devices, apps should employ runtime protections to prevent tampering during execution. These can include anti-debugging techniques, code obfuscation, and dynamic analysis resistance.
- Example: Implementing anti-debugging measures can make it difficult for attackers to run the app in a debugger, preventing them from inspecting or modifying the app’s code during runtime. Similarly, adding runtime checks to ensure that the app isn’t being executed on a compromised device can further protect the app.
4. Server-Side Validation
Important security checks and sensitive operations should not rely solely on the client side. By moving critical business logic and validation processes to the server, developers can protect against tampered apps. For example, instead of relying on the app to verify a user’s transaction, the server should be responsible for verifying the transaction’s legitimacy.
- Example: In a mobile payment app, critical financial operations should be validated server-side, ensuring that even if the client-side app is tampered with, the transaction is still securely processed according to the correct rules.
5. Restricting App Functionality
When a rooted or jailbroken device is detected, developers can restrict certain functionalities within the app. This can involve locking the app entirely or limiting access to certain sensitive features, such as in-app purchases or data storage. While this approach might impact the user experience, it can help mitigate the risk of data theft and tampering.
- Example: A banking app may restrict the ability to view or transfer funds from a jailbroken device. Alternatively, the app could display a warning message informing users about the potential risks of using a compromised device.
Penetration Testing for Code Tampering
Penetration testing is essential for identifying vulnerabilities in your mobile app and determining how resistant it is to code tampering. A thorough penetration test can identify weaknesses such as insecure code, insufficient obfuscation, or poor runtime protections.
Penetration testers should focus on the following areas when assessing mobile apps for code tampering:
- Reverse Engineering: Use tools to decompile and reverse engineer the app’s code to check for weaknesses or exposed sensitive data.
- Dynamic Analysis: Test how the app behaves during runtime by injecting malicious code or manipulating the app’s execution flow.
- APK/IPA Analysis: For Android and iOS apps, analyse the APK or IPA files for vulnerabilities, such as the inclusion of debugging symbols or weak obfuscation.
- Root/Jailbreak Testing: Test the app’s resilience against attacks on rooted or jailbroken devices.
- Exploit Development: Attempt to exploit vulnerabilities within the app by injecting malicious payloads, modifying the app’s behaviour, or bypassing security mechanisms.
Final Thoughts
Code tampering is a serious threat that every mobile app developer and penetration tester must address. By understanding the methods of code tampering, the risks associated with it, and implementing the best practices and security measures outlined in this article, developers can ensure the integrity and security of their mobile apps. Penetration testers play a vital role in identifying vulnerabilities and verifying the effectiveness of security controls.
For businesses, the cost of ignoring code tampering is high, with risks including data breaches, financial loss, and damage to reputation. Investing in robust security practices, conducting regular penetration tests, and maintaining a proactive approach to security will help mitigate the risks and ensure the longevity of your mobile app’s security.
By adhering to these best practices and embracing the latest security techniques, developers and penetration testers can build and maintain secure mobile applications that protect both users and business interests.
Rooted and jailbroken devices present a unique and significant challenge to mobile app security. Attackers can manipulate apps, steal sensitive data, or inject malicious code, often without the knowledge of the user. For developers and penetration testers, it is vital to implement robust security mechanisms to detect and mitigate the risks associated with rooted and jailbroken devices.
By integrating device integrity checks, runtime protections, server-side validation, and restricting functionality when necessary, developers can enhance the security of their mobile apps and protect both their users and business interests from the threats posed by code tampering and device compromises.
Ultimately, ensuring the integrity of your mobile app and its environment is an ongoing process. Regular updates, security patches, and penetration testing are essential to maintain a strong security posture in the face of evolving threats.
Tampering with an app’s behaviour through memory tampering or hooking is a highly effective technique for attackers to gain control over a mobile app and bypass security measures. As these attacks target the app at runtime, they present a serious risk to app integrity and user security.
By understanding the mechanics of these attacks and taking proactive steps to implement protective measures such as memory encryption, code obfuscation, integrity checks, and secure API handling, developers can significantly reduce the risk of their app being tampered with. For penetration testers, it is critical to perform thorough testing, simulating these types of attacks to identify and remediate potential vulnerabilities.

Ultimately, securing mobile applications against runtime tampering requires continuous vigilance, regular updates, and the adoption of the latest security practices to stay ahead of evolving threats.