Threats & Research

Using Remote Asset Bundle in Unity3D framework really safe?

CyStack image

Trung Nguyen

CEO @CyStack|April 5, 2023

Introdution

If you are a mobile application developer, you may be interested in exposing sensitive information from your application because of decompilation a mobile app such as Android app is not too difficult.

A friend of mine recently developed an Android application using Unity framework, it can hide code by downloading the required modules from a trusted-server at the runtime.

I really doubt this method, so I try to reverse this app to obtain the hidden code. And in this article, I will describe my work process.

You can download the APK file here. Notice this file is not the original version, it was modified to fit the article.

Analysis

Running

When running the application on an Android Emulator, you will see results like bellow.

Static Testing

In Unity Framework, the main code is written by C# language and compiled to a dll file. It’s compressed in the the binary file. After extract the apk file, we can see it at: /assets/bin/Data/Managed/Assembly-CSharp.dll

We easily decompile a dll written in C# by using decompilers such as dnspy, ilspy or dotpeek…

At line 39, the app loads Component ExtendModuleActivity

At line 40 and 41, displaying the content of the Component above to screen. It is
“Find me if you can!” string that we have seen when runing the app.

So, where is ExtendModuleActivity? I haven’t seen it in the decompiled code. I assume that the decompiler is not effective and it does not show the source code completely

Dynamic Testing

I suspect the app downloaded required modules via HTTP, so I do some configs to force this app goes through a HTTP Proxy (such as ZAP, BurpSuite …) to know what it actually does. Note that you make sure your proxy can sniff the HTTPS Request by trusting Proxy’s Certificate in Android Client.

Then open the app and observe at the proxy

This app downloaded two resource from a remote server:

The first resource is a text file that contains the content that appears on the screen, and bundle seems to contain ExtendModuleActivity that we are looking for.
In Unity Framework:

An AssetBundle is a collection of assets and/or scenes from a project saved in a compact file with the purpose of being loaded separately to the built executable application.
AssetBundles can contain scripts as TextAssets but as such they will not be actual executable code.

Extract the Bundle

I found a pretty good tool to extract bundles called Unity Assets Bundle Extractor

Load our bundle to UABE and view its information

Then Export Raw to obtain the bytecode. Using an editor / hex editor, we can realize that it is PE File (beginning with MZ), but was inserted into the previous another section. We just remove this section to restore PE header file.

The rest is decompiling the new file, and this is what we are looking for 🙂

Conclusion

As you can see, securing applications is not an easy task. Using Remote Asset Bundle is not a perfect way to hide your source code in Unity Framework, and in addition it is appropriate only when your application requires an internet connection. This article does not go into how to prevent attacks, I just hope it can be to raise awareness about some risks in your application. Good luck!

P/s: Maybe I will implement this technique into a CTF challenge in the future.

Related posts

Flash Loan Attack
Flash Loan Attack
June 27 2022|Threats & Research

Mở đầu Flash Loan Attack là một hình thức tấn công DeFi đã xuất hiện từ lâu, gây ra rất nhiều thiệt hại cho các nền tảng DeFi. Tính từ đầu năm 2022 đến nay, đã có nhiều cuộc tấn công dựa trên hình thức này, điển hình như các cuộc tấn công nhắm đến […]

Cuộc tấn công vào ONUS – Góc nhìn kỹ thuật từ lỗ hổng Log4Shell
Cuộc tấn công vào ONUS – Góc nhìn kỹ thuật từ lỗ hổng Log4Shell
April 5 2023|Threats & Research

Read the English version here Log4Shell hiện đang là một cơn ác mộng (có lẽ là tồi tệ nhất cho tới thời điểm hiện tại) đối với nhiều doanh nghiệp. Không may thay, ONUS, một trong số những khách hàng của chúng tôi, đã trở thành nạn nhân của lỗ hổng này. Với tư cách […]

The attack on ONUS – A real-life case of the Log4Shell vulnerability
The attack on ONUS – A real-life case of the Log4Shell vulnerability
April 5 2023|Threats & Research

Đọc bản tiếng Việt tại đây Log4Shell has recently been a nightmare (probably the worst one for now) to businesses. ONUS, a client of ours, was an unfortunate victim. As their security partner, CyStack informed ONUS of the risks right after Log4Shell came to light; when the attack actually happened, we supported them in finding […]