Training
/
Masterclass
/
React Native

Editing and Patching React Native Applications

4
min read
Payatu Research Team
Beginner
Four people working with laptops around a futuristic transparent table at sunset, with an illuminated blue atom-like digital graphic and floating lines of code in the background.

In the previous blog of the React Native Pentesting for Android Security Masterclass, we covered methods for decompiling APK files and analyzing their structure.

Let’s now move to editing and patching React Native apps.

Modifying and patching React Native applications is relatively easier than doing so with Java-native Android applications. As we already learned, when an APK of a React Native project is built, all of the React Native JavaScript code gets compiled into one single file, i.e., “index.android.bundle.”

We have to find the correct piece of code in the “index.android.bundle” file, and then we can modify the code right away. We can find the code block by searching for the specific keywords in the application. For example, we can search for text (like the text on the button, touchable opacity, etc.) shown in the application’s UI to find specific functions associated with that text.

We can utilize the react-native-decompiler module to analyze the code more efficiently and later modify it by referencing it as “index.android.bundle.”

Steps:

There are several ways to edit and patch the React Native Android application. Below are the two most effective methods demonstrated. You can choose any method at your convenience.

Method 1: Modification using any simple compression tool

1. Open the installed application, and you will notice that the counter only increases by 5 digits.

Mobile app screen showing a Counter App with a Mario character jumping, current counter value 1340, and an orange button labeled 'Increase by 5'. Below is a challenge message to make the counter value 1337 and get the flag.

2. Change the extension of the vulnerable APK to “.zip”

A file icon with four small colorful squares, labeled 'rnmodify.apk.zip'.

3. Open the zip file in Winzip and open /assets/index.android.bundle. Note that you have to open the zip file in WinZip. Extracting and compressing the zip again might give an error.

Archive utility window displaying contents of rnmodyfy.apk.zip file, showing one folder named 'assets' and one BUNDLE file named 'index.android.bundle' with their sizes and packed sizes listed.

4. In the “index.android.bundle” file, all of the compiled code of the React Native application exists. You can beautify the code with any online JS beautifier tool such as “codebeautify.org”

5. As per our challenge, we have to change the counter value to 1337. Thus, we will change the increment value from 5 to 1 so the counter will increase only by 1 digit per button click.

Tip: You can search in code with custom keywords that you see in the application. Usually, the “hand-written” code can be found at the bottom of this file.

Notepad window showing a code file with syntax including functions and children properties; a Find dialog box is open with the search term 'increase by 5' typed in, and text in the code highlighted matching 'increase by 5'.

6. Now, we have to delete previous signing certificates. Go to the “META-INF” file and delete the following files:

  • CERT.RSA
  • CERT.SF
  • MANIFEST.MF

7. Exit the “Winzip” app and rename the file extension back to “.apk”

Icon showing an Android robot on top of a blue and green package file labeled 'rnmodify.apk'.

8. Now, we need to sign the modified APK with a new certificate. To generate a custom certificate, run the following command and fill out the details:

Terminal command to generate a keystore with keytool, including options for verbose output, keystore file name, alias name, RSA algorithm, 2048 key size, and validity of 10000 days.
Command prompt window showing the use of keytool command to generate an RSA key pair with a 2048-bit key size and 10000 days validity, including prompts for keystore password, personal and organizational details, and confirmation of correctness before generating and storing the self-signed certificate in rnmodify.keystore.

9. We will sign our APK with the generated keystore. Run the following command and enter the keystore password set while creating the keystore in step 6.

Terminal command for signing an APK using jarsigner with options for verbose output, signature algorithm SHA1withRSA, digest algorithm SHA1, specifying a keystore file named <my-keyname>.keystore, with placeholders for the APK file <modify.APK> and alias name <alias_name>.
Command prompt terminal showing a jar signing process using jarsigner with verbose output, displaying added and signed META-INF files and AndroidX library version metadata.

10. Install the modified APK with adb.

Terminal or command prompt with the command 'adb install modified.APK' typed in light yellow and green text on a dark background.
Command prompt window showing the command 'adb install rnmodify.apk' executed successfully with messages 'Performing Streamed Install' and 'Success'.

11. The modified application will be successfully installed.

Screenshot of a Counter App interface with an alert box displaying the message: flag-{I'm_the_Batman} over an image of a Mario character.

Method 2: Modification using APKTool

Mobile screen of a Counter App displaying a jumping Mario figure, counter value 1340, an orange button labeled 'Increase by 5', and a challenge text: 'Make counter value 1337 and get the flag'.

1. Open the installed application, and you will notice that the counter only increases by 5 digits.

2. Run the following command to decompile the application with APKTool: apktool d VulnerableApp.apk

Command prompt window showing Apktool command to decode an APK file named VulnerableApp.apk with messages indicating loading resource table, decoding AndroidManifest.xml, decoding file-resources, baksmaling classes.dex, copying assets, libs, unknown files, and original files.

3. Goto “/VulnerableApp/assets” folder and open the “index.android.bundle” file

4. Search for keywords such as “Increase by 5” and then for the “onPress” function. You can copy the entire code and beatify it for convenience.

Tip: You can search in code with custom keywords that you see in the application. Usually, the “hand-written” code can be found at the bottom of this file.

Screenshot of JavaScript Beautifier tool interface showing code on the left with syntax, buttons in the center for File, URL, Beautify JS, Run/View, Minify JS, Obfuscator JS, Download, and output code on the right highlighting 'children: Counter Value:', 'onPress: function', and 'children: Increase by 5'.

5. Change the counter value from “5” to “1” in the “index.android.bundle” file.

Screenshot of a code snippet in a developer console highlighting JavaScript handling of a 'TouchableOpacity' component's onPress event and an increase in child element text 'Increase by'.

6. Save this file and run the following APKTool command: apktool b VulnerableApp

7. Modified APK will be generated in the “/VulnerableApp/dist” folder.

8. Goto this folder and create a keystore with the following command:

Command line text on a black screen showing a keytool command to generate an RSA key with 2048 bits and 10000 days validity.

9. Sign the APK with “jarsigner”.

Terminal window showing a jarsigner command with verbose, sigalg SHA1withRSA, digestalg SHA1, keystore file loki.keystore, signing VulnerableApp.apk with alias loki, followed by output listing added and signed files like META-INF/MANIFEST.MF, AndroidManifest.xml, classes.dex, multiple Kotlin builtins, and several native libraries in lib/arm64-v8a/.

10. Install the signed application with:

adb install VulnerableApp.apk

11. Open the application, and you can increase the counter by 1 digit now.

Screenshot of a Counter App with a Super Mario figure in the background and an alert box in the foreground displaying the message: "flag-{'I'm_the_Batman🦇'}" with an OK button.

Note: You can use the abovementioned method to modify and patch the React Native application.

Conclusion

We now know what React Native is, what the bridge concept is, how to find out if an application is built on React Native, how to reverse engineer it, attack surfaces static analysis, and how to edit and patch React Native applications.

In the next blog, we will learn how to modify Hermes bytecode.

Till then, stay tuned!