ABOH 2023: Grape
Watch where you step and what you touch.
Last updated
Watch where you step and what you touch.
Last updated
This writeup is written from the author's perspective to showcase the challenge design, and may or may not reflect the typical approach or methodology involved to solve the challenge.
This challenge serves to educate participants about Execution Guardrails and anti-tamper techniques deployed by Malware Developers to enhance malware resiliency.
Wine Detection: Malware with anti-dynamic capabilities uses Execution Guardrails to prevent code from detonating when executed in a sandbox/emulator environment. Wine is a simple example of emulator used to run Windows applications on Unix-like Operating System.
Code Integrity Checks: To prevent reverse engineers from bypassing these detection checks with binary patching, the integrity of main function is verified during runtime via code checksumming.
Running the executable returns a hash, followed by a line of poetry.
Under a decompiler, the main function contains very minimal functionality (symbols renamed for readability):
In the code_checksum
function, we can find the hardcoded hash:
The essence of this challenge is about bypassing the wine_detection
logic:
The detection logic is broken down into 3 parts:
Library Exports: Identify if wine related functions are exported from Windows kernel32.dll
and ntdll.dll
libraries.
Active Processes: Check if the winlogon.exe
process is alive. For every Windows system, winlogon.exe
is initialized during startup/logon; and since Wine does not emulate the logon process, the process count will be 0.
Registry Key: Check if specific registry key that are exclusive to the Wine emulator presents on the system.
The way these detection logic are implemented (in a nested IF statement) presents an easy opportunity for binary patching. To bypass these detection logic, simply apply an Invert Patch on the following jump instructions:
After applying the patch, the checksum now looks different from the hardcoded hash we have seen previously; and because of this, the poetry is no longer printed because the program is terminated immediately upon a mismatch of checksum.
However, recall that the code integrity check from the main function is also implemented in a similar manner, which allows us to patch the integrity hook itself.
This way, we managed to bypass all the detection logic in place and still have the executable run as usual despite having a different checksum.
Flag: ABOH{w1n3_15_n07_4n_3mul470r}
Another alternative to patching, is to fulfil all the wine requirements that are checked against. Since Library Exports and Active Processes are already automatically True
when executing in a Wine emulator, we will only have to deal with the last criteria.
Note that, not all versions of Wine comes with the max_version_factory
registry key by default, but we can easily re-create this key since Wine supports it's own registry hive.
Finally, run the executable in Wine without patching it.
Flag: ABOH{w1n3_15_n07_4n_3mul470r}