The malware forensics lab identified a new technique for hiding and executing code dynamically. A sample that seems to use this technique has just arrived in their queue. Can you help them?
It seems like there’s only one activity to focus on. I then have a look in it. Inside the MainActivity.java, there’s a few that I think its interesting and useful.
This is the code where it use native library. This means that I’ll need to have a look at the native library which can be found in Resources > lib > x86 (or any other) > libdefault.so inside the jadx-gui.
Bundle extras = getIntent().getExtras();
if (extras ==null) {
finish();
return;
}
if (!extras.getString("open").equalsIgnoreCase("sesame")) {
finish();
return;
}
This code is interesting as it requires user to provide extra strings inside the Intent in order to open the apps. This means that opening directly is impossible in this case.
A weird f function that seems to be related to window manager. After asking big boss CHATGPT, it’s trying to create an overlay button. The number 2038 is TYPE_APPLICATION_OVERLAY and it requires some permission to make it work.
publicfinal String alert() {
final EditText editText =new EditText(this);
new AlertDialog.Builder(this).setTitle("XOR XOR XOR").setMessage("XOR ME !").setView(editText).setPositiveButton("XORIFY", new DialogInterface.OnClickListener() { // from class: com.stego.saw.MainActivity.4@Override// android.content.DialogInterface.OnClickListenerpublicvoidonClick(DialogInterface dialogInterface, int i) {
MainActivity.this.answer= editText.getText().toString();
MainActivity mainActivity = MainActivity.this;
mainActivity.a(mainActivity.FILE_PATH_PREFIX, MainActivity.this.answer);
}
}).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { // from class: com.stego.saw.MainActivity.3@Override// android.content.DialogInterface.OnClickListenerpublicvoidonClick(DialogInterface dialogInterface, int i) {
MainActivity.this.finish();
}
}).show();
returnthis.answer;
}
This one is the alert function where it seems to be some kind of XOR ?? From what I know, this seems to be taking one input and try to send it into a(<filepath>,<input>) and the a function should be coming from native library.
After going through abit, I started by looking into the function a. Based on the Java code, it takes in 2 input. The function a decompiled by ghidra has 4 argument, which I assume the last 2 is the one that the input is placed. Based on the code, it seems like it’s taking param_3 and param_4 as pcVar1 and pcVar2 which then put into function _Z1aP7_JNIEnvP8_1. Focusing on the function, I noticed that theres a weird function that seems to be interested.
While its abit messy, I noticed that its trying to take the characters of param_2 and try to XOR with some random variable. After understanding it, it seems like the variable consist of some hex numbers. here’s all the hex number after getting it.
Moving on to the next part of the code where it uses the param_1, It seem’s like it is trying to open a file and write something into it. Since I have no idea what’s the remaining, I then tried to see how things works first.
After this, the next thing looks like some click me button. I tried clicking it but it does not show anything. It seems to be the overlay function f which requires some additional permission. After some research, I came across this article which could manually enable the setting. Mine is located at Privacy Protection > special permission > Display over other apps.
After enabling it, clicking the button now appear another new square.
I then click it again and it shows another overlay screen.
This looks like the input that will be used to XOR. I then tried to get the correct input first be decrypting it.
Now I have a potential string, I tried to use this as the input and see what happened. Somehow, nothing happened and I just assume everything is working as intended. Now I need to search for the file location. it should be in /data/data/io.stego.saw/ as the path is taken from getApplicationContext().getApplicationInfo().dataDir + File.separatorChar.
Since this challenge focus on the native library and I had fully understand how it works, I think it is possible to use frida script to skip the overlay permission.
Another method is to abuse the native library by importing into my own project. This is much more complicated as it need to code using either Kotlin or Java. This requires abit more step to do so.
First step is to build a project with an exact same app name which in this case com.stego.saw.
After creating the project, add all the native library under the folder name of jniLibs.
After adding it, sync the project first and then start adding the required code to use the native library.
val context = LocalContext.current
var result by remember { mutableStateOf("Waiting for result...") }
var fleg by remember { mutableStateOf("Waiting for fleg") }
Column(
modifier = Modifier.fillMaxSize().padding(16.dp),
verticalArrangement = Arrangement.Center
) {
Button(onClick = {
result = MainActivity().a(context.applicationInfo.dataDir + File.separator,"fl0ating").toString()
val file = File(context.applicationInfo.dataDir + File.separator+"h")
fleg = if (file.exists()) file.readText() else"File not found" }) { Text(text="test") }
Text(text = result)
Text(text = fleg)
}
Focus on the onclick where it has 2 important function there. First is using the function a to provide the required filepath and also the correct strings. The another function is for us to easily read the file. Here’s an example of the result.
The first solution is still important as the remaining solution could only works after understanding how everything works.