01 BitsOfBinary
Search

Days 78–99 · 45 min read

Case Study: Signaturing the AcidBox Framework

End-to-end malware rule-writing walkthrough against AcidBox SSP and worker DLLs—covering format strings, PE rich/export metadata, custom crypto opcodes in Ghidra, unique error codes, and stack strings.

On this page (23)

Day 78 - AcidBox - SSP DLL Strings - Format Strings Part 1

In Palo Alto Unit42’s blog on AcidBox, it breaks down the malware framework into roughly three components:

  • A main worker DLL
  • Security Support Provider (SSP) DLLs to load the main worker
  • A kernel mode payload embedded in the main worker

I will start by looking at the SSP DLLs; in particular looking at 003669761229d3e1db0f5a5b333ef62b3dffcc8e27c821ce9018362e0a2df7e9. As highlighted in the previous post, I’ll start by looking at plaintext strings to see if there is anything obvious to base a YARA rule on.

At a first glance, there doesn’t appear to much to work with! There are some representing the exported functions (we’ll get to those later), some representing imported functions, and version information (which we’ll also get to later).

However, near the start of the file (more specifically near the beginning of the .text section), there are some format strings of interest:

%s\%s
%s\%s{%s}
s\{%s}

All of these strings in combination may be good enough for a first rule as follows:

rule AcidBox_SSP_DLL_Loader_Format_Strings {
meta:
description = "Detects AcidBox SSP DLL loaders, based on a combination of format strings"
author = "BitsOfBinary"
reference = "https://unit42.paloaltonetworks.com/acidbox-rare-malware/"
hash = "003669761229d3e1db0f5a5b333ef62b3dffcc8e27c821ce9018362e0a2df7e9"
strings:
$ = "%s\\%s"
$ = "%s\\%s{%s}"
$ = "s\\{%s}"
condition:
all of them
}

Day 79 - AcidBox - SSP DLL Strings - Format Strings Part 2

An alternative way to search for the format strings in AcidBox would be to look for them all in one chunk. Each string is sequential to the other, separated by null bytes to make sure they’re aligned in 8-byte segments. So that rule would look like this:

rule AcidBox_SSP_DLL_Loader_Format_String_Chunk {
meta:
description = "Detects AcidBox SSP DLL loaders, based on a unique string chunk of format strings"
author = "BitsOfBinary"
reference = "https://unit42.paloaltonetworks.com/acidbox-rare-malware/"
hash = "003669761229d3e1db0f5a5b333ef62b3dffcc8e27c821ce9018362e0a2df7e9"
strings:
// %s\%s
// %s\%s{%s}
// s\{%s}
$ = {25 73 5C 25 73 00 00 00 00 00 00 00 25 73 5C 25 73 7B 25 73 7D 00 00 00 00 00 00 00 25 73 5C 7B 25 73 7D 00}
condition:
any of them
}

While this rule is stricter than the previous one, it guarantees to only hit on samples that have these format strings in order like this, making it potentially less FP-prone, at the risk of missing samples that have these format strings more spread out/out of order, etc.

Day 80 - AcidBox - SSP DLL Strings - Format Strings Part 3

Using the fact that that the AcidBox format strings all appear to be aligned by the same amount of bytes, we can create a further rule that is slightly more loose in that it doesn’t require all three format strings to be present. We can do this by listing out the different orders each format string could appear next to one another, to make the following rule:

rule AcidBox_SSP_DLL_Loader_Format_String_Combos {
meta:
description = "Detects AcidBox SSP DLL loaders, based on combinations of format strings seen in samples"
author = "BitsOfBinary"
reference = "https://unit42.paloaltonetworks.com/acidbox-rare-malware/"
hash = "003669761229d3e1db0f5a5b333ef62b3dffcc8e27c821ce9018362e0a2df7e9"
strings:
// Combinations of the following (with alignment bytes):
// %s\%s
// %s\%s{%s}
// s\{%s}
$ = {25 73 5C 25 73 00 00 00 00 00 00 00 25 73 5C 25 73 7B 25 73 7D 00}
$ = {25 73 5C 25 73 00 00 00 00 00 00 00 25 73 5C 7B 25 73 7D 00}
$ = {25 73 5C 25 73 7B 25 73 7D 00 00 00 00 00 00 00 25 73 5C 25 73 00}
$ = {25 73 5C 25 73 7B 25 73 7D 00 00 00 00 00 00 00 25 73 5C 7B 25 73 7D 00}
$ = {25 73 5C 7B 25 73 7D 00 00 00 00 00 00 00 25 73 5C 25 73 00}
$ = {25 73 5C 7B 25 73 7D 00 00 00 00 00 00 00 25 73 5C 25 73 7B 25 73 7D 00}
condition:
any of them
}

Day 81 - AcidBox - SSP DLL Strings - Format Strings Part 4

Finally for these format strings in AcidBox, if we wanted to hunt for more samples, we could attempt to loosen the rule further by adding in variable ranges into the hex strings (in case the number of alignment bytes changes):

rule AcidBox_SSP_DLL_Loader_Format_String_Combos_Loose {
meta:
description = "Detects AcidBox SSP DLL loaders, based on combinations of format strings seen in samples. This rule uses a looser set of strings, so may be more false positive-prone."
author = "BitsOfBinary"
reference = "https://unit42.paloaltonetworks.com/acidbox-rare-malware/"
hash = "003669761229d3e1db0f5a5b333ef62b3dffcc8e27c821ce9018362e0a2df7e9"
strings:
// Combinations of the following (with alignment bytes):
// %s\%s
// %s\%s{%s}
// s\{%s}
$ = {25 73 5C 25 73 00 [0-16] 25 73 5C 25 73 7B 25 73 7D 00}
$ = {25 73 5C 25 73 00 [0-16] 25 73 5C 7B 25 73 7D 00}
$ = {25 73 5C 25 73 7B 25 73 7D 00 [0-16] 25 73 5C 25 73 00}
$ = {25 73 5C 25 73 7B 25 73 7D 00 [0-16] 25 73 5C 7B 25 73 7D 00}
$ = {25 73 5C 7B 25 73 7D 00 [0-16] 25 73 5C 25 73 00}
$ = {25 73 5C 7B 25 73 7D 00 [0-16] 25 73 5C 25 73 7B 25 73 7D 00}
condition:
any of them
}

This version of the rule appears to yield some false positives vs. the previous rules, so may only be useful from a threat hunting perspective, with some possible extra heuristics applied (such as a filesize modifier).

I hope these first set of rules shows that even if there are no individual strings in samples that can used on their own for classification, by understanding ways you can combine them together in a condition you can still use a collection of them. In general, if I see strings that on there own yield FPs, but in chunked combination classify malicious samples, I try to use them as often as possible!

I also hope that this approach shows that we’re already building a bit of redundancy into our rules. We’ve written different versions of the same rule multiple times, but each has a slightly different aim that we’re being specific about in our rulename/description. If all four of the rules we’ve written hit on a sample, then that already gives us a different level of confidence about the sample vs. if only one rule hits on it.

Day 82 - AcidBox - SSP DLL PE Meta Features - Part 1

We’re done with strings for now, so let’s move on to some of the meta features of the sample. Specifically, what PE metadata can we see?

One that I always start with is both the import hash and rich header hash, as it is quick and easy to put these in rules:

import "pe"
import "hash"
rule AcidBox_SSP_DLL_Loader_Imphash {
meta:
description = "Detects AcidBox SSP DLL loaders, based on a unique import hash"
author = "BitsOfBinary"
reference = "https://unit42.paloaltonetworks.com/acidbox-rare-malware/"
hash = "003669761229d3e1db0f5a5b333ef62b3dffcc8e27c821ce9018362e0a2df7e9"
condition:
pe.imphash() == "30851d4a2b31e9699084a06e765e21b0"
}
import "pe"
import "hash"
rule AcidBox_SSP_DLL_Loader_Rich_Header_Hash {
meta:
description = "Detects AcidBox SSP DLL loaders, based on a unique rich header hash"
author = "BitsOfBinary"
reference = "https://unit42.paloaltonetworks.com/acidbox-rare-malware/"
hash = "003669761229d3e1db0f5a5b333ef62b3dffcc8e27c821ce9018362e0a2df7e9"
condition:
hash.md5(pe.rich_signature.clear_data) == "269af2751efee65b1ab00622816c83e6"
}

I’ve got a script that automatically can pull out these values and put them in a rule: https://github.com/BitsOfBinary/yarabuilder-examples/tree/main/pe

Day 83 - AcidBox - SSP DLL PE Meta Features - Part 2

Many PE files will have a VERSIONINFO resource: https://learn.microsoft.com/en-us/windows/win32/menurc/versioninfo-resource

As described, this resource contains information such as the intended operating system, and original name of the file. This resource is also parsed by the PE module: https://yara.readthedocs.io/en/stable/modules/pe.html#c.version_info

For the sample of AcidBox we’ve been looking at, it has an internal name of windigest.dll, and a file description of Windows Digest Access. Both these values appear to be unique, and can be the basis for a YARA rule:

import "pe"
rule AcidBox_SSP_DLL_Loader_windigest_Version_Info {
meta:
description = "Detects AcidBox SSP DLL loaders, based on a unique version information of 'windigest' and a description"
author = "BitsOfBinary"
reference = "https://unit42.paloaltonetworks.com/acidbox-rare-malware/"
hash = "003669761229d3e1db0f5a5b333ef62b3dffcc8e27c821ce9018362e0a2df7e9"
condition:
pe.version_info["InternalName"] == "windigest.dll" or
pe.version_info["FileDescription"] == "Windows Digest Access"
}

Day 84 - AcidBox - SSP DLL PE Meta Features - Part 3

While on the topic of version info, the Palo Alto blog for AcidBox mentions that the following filenames (which are similar to known Windows binaries) were used:

  • msv1_1.dll
  • pku.dll
  • windigest.dll

We’ve covered windigest.dll in our previous post, and we can write rules for the two remaining filenames, even if we don’t have any samples to work with:

import "pe"
rule AcidBox_SSP_DLL_Loader_msv1_1_Version_Info {
meta:
description = "Detects AcidBox SSP DLL loaders, based on a unique version information of 'msv1_1.dll'"
author = "BitsOfBinary"
reference = "https://unit42.paloaltonetworks.com/acidbox-rare-malware/"
condition:
pe.version_info["InternalName"] == "msv1_1.dll"
}
import "pe"
rule AcidBox_SSP_DLL_Loader_pku_Version_Info {
meta:
description = "Detects AcidBox SSP DLL loaders, based on a unique version information of 'pku.dll'"
author = "BitsOfBinary"
reference = "https://unit42.paloaltonetworks.com/acidbox-rare-malware/"
condition:
pe.version_info["InternalName"] == "pku.dll"
}

It is worth looking for opportunities to write YARA rules for indicators of compromise mentioned in open source research, even if a sample isn’t available.

Day 85 - AcidBox - SSP DLL PE Meta Features - Part 4

The AcidBox loaders have four exported functions:

  • InitPhysicalInterfaceA
  • InitSecurityInterfaceA
  • SpLsaModeInitialize
  • UpdateSecurityContext

While the middle two exports appear to be named after standard Windows API functions (e.g. InitSecurityInterfaceA and SpLsaModeInitialize), the first and last exports appear to be unique. So we can look for DLLs that export those in our rules:

import "pe"
rule AcidBox_SSP_DLL_Loader_Unique_Exports {
meta:
description = "Detects AcidBox SSP DLL loaders, based on having unique exported functions"
author = "BitsOfBinary"
reference = "https://unit42.paloaltonetworks.com/acidbox-rare-malware/"
hash = "003669761229d3e1db0f5a5b333ef62b3dffcc8e27c821ce9018362e0a2df7e9"
condition:
pe.exports("InitPhysicalInterfaceA") or
pe.exports("UpdateSecurityContext")
}

While we can use the PE module for this purpose, it also makes sense to search for the strings too, in case they are embedded in another file, being called elsewhere, etc.

rule AcidBox_SSP_DLL_Loader_Unique_Exports_Strings {
meta:
description = "Detects the strings of unique exported functions of AcidBox SSP DLL loaders"
author = "BitsOfBinary"
reference = "https://unit42.paloaltonetworks.com/acidbox-rare-malware/"
hash = "003669761229d3e1db0f5a5b333ef62b3dffcc8e27c821ce9018362e0a2df7e9"
strings:
$ = "InitPhysicalInterfaceA"
$ = "UpdateSecurityContext"
condition:
any of them
}

Day 86 - AcidBox - SSP DLL Strings - PE Meta Features Part 5

I think it’s worth pointing out successful rule attempts, as well as failures. I wanted to see if I could write a rule based on the following information from the Palo Alto blog:

All of the AcidBox samples contain gaps between the single exported function entries…

Every AcidBox sample has a NumberOfFunctions value in the export directory that is bigger than the NumberOfNames value. This isn’t something unusual, as not every exported function has to have a name too. Unnamed functions can be also called by their ordinal values. What is uncommon, however, is that the function entries which are unnamed are also zeroed out, thus not used.

By looking at the information from the PE module, the following export details are parsed out:

export_details
[0]
offset = 28244
name = "InitSecurityInterfaceA"
forward_name = YR_UNDEFINED
ordinal = 1
[1]
offset = 0
name = YR_UNDEFINED
forward_name = YR_UNDEFINED
ordinal = 2
[2]
offset = 0
name = YR_UNDEFINED
forward_name = YR_UNDEFINED
ordinal = 3
[3]
offset = 0
name = YR_UNDEFINED
forward_name = YR_UNDEFINED
ordinal = 4
[4]
offset = 27964
name = "InitPhysicalInterfaceA"
forward_name = YR_UNDEFINED
ordinal = 5
[5]
offset = 0
name = YR_UNDEFINED
forward_name = YR_UNDEFINED
ordinal = 6
[6]
offset = 28408
name = "UpdateSecurityContext"
forward_name = YR_UNDEFINED
ordinal = 7
[7]
offset = 0
name = YR_UNDEFINED
forward_name = YR_UNDEFINED
ordinal = 8
[8]
offset = 28168
name = "SpLsaModeInitialize"
forward_name = YR_UNDEFINED
ordinal = 9

In many cases, the export name member is YR_UNDEFINED, which we can check using the defined keyword. These exports also seem to have their export set to 0; I’m not sure if this is a default for the pe module or not. As such I wrote the following rule looking for DLL with multiple, low ordinal exports with no name:

import "pe"
rule Heuristic_Multiple_Undefined_Low_Ordinal_Exported_Functions {
meta:
description = "Detects DLLs with at least 2 different exported functions that are undefined, and which have low ordinals"
note = "This returns a lot of results, do not use for threat hunting without extra heuristics"
condition:
for 2 export in pe.export_details : (
export.offset == 0 and
not defined export.name and
export.ordinal <= 10
)
}

Unfortunately, as Palo Alto points out, this is not uncommon! Turns out a lot of DLLs have empty exports, meaning you can’t rely on this alone. Still, the rule might be useful with some extra heuristics/context applied, but I wouldn’t recommend using it in general.

Day 87 - AcidBox - SSP DLL Code - Signaturing Crypto Routine - Part 1

We’ve written some rules for strings and meta features of the AcidBox SSP DLL. So let’s move on to code. Unfortunately, I think this starts to create a barrier to entry from a detection perspective, as a little bit of reverse engineering knowledge is usually required to make a start on this. However, I hope I can highlight some features that are worth looking at from a YARA perspective!

To analyse 003669761229d3e1db0f5a5b333ef62b3dffcc8e27c821ce9018362e0a2df7e9 I’m using Ghidra, which is free and open source.

So where should we start looking? Something I usually look for is custom cryptography routines, which can sometimes be useful for clustering samples together. FUN_180007fc8 appears to be loading a PE resource (which matches with what is described in the AcidBox blog). So by looking around, I can see that FUN_180013a14 appears to be some kind of cryptography routine (likely RSA, but we don’t necessarily need to know that for now) based on the fact that it has a for loop which contains an XOR.

AcidBox custom cryptography routine in Ghidra

Looking at the highlighted disassembly/decompiler view, I can see that there are some “nice” instructions to work with; that is, there are no fixed offsets (e.g. referencing string positions that may change throughout the samples), and the combination of registers/instructions used looks pretty unique! As such, I can use Ghidra’s Copy Special... option to copy out the Byte String of this code, and put it straight into a YARA rule.

rule AcidBox_SSP_DLL_Loader_Crypto_Routine_A {
meta:
description = "Detects AcidBox SSP DLL loaders, based on a unique cryptography routine"
author = "BitsOfBinary"
reference = "https://unit42.paloaltonetworks.com/acidbox-rare-malware/"
hash = "003669761229d3e1db0f5a5b333ef62b3dffcc8e27c821ce9018362e0a2df7e9"
strings:
// 180013a71 0f b6 04 32 MOVZX EAX ,byte ptr [param_2 + RSI *0x1 ]
// 180013a75 33 c8 XOR param_1 ,EAX
// 180013a77 88 0c 3a MOV byte ptr [param_2 + RDI *0x1 ],param_1
// 180013a7a 41 ff c0 INC param_3
// 180013a7d 44 89 44 MOV dword ptr [RSP + local_14 ],param_3
// 24 04
$ = {0f b6 04 32 33 c8 88 0c 3a 41 ff c0 44 89 44 24 04}
condition:
any of them
}

Note: I always find it useful to copy the code we’ve signatured into the rule itself as a comment. That way, anyone reading it can see what the bytes represent, rather than having to go disassemble them themselves.

Day 88 - AcidBox - SSP DLL Code - Signaturing Crypto Routine - Part 2

In the previous post’s example, I copied the code straight from the binary itself to the YARA rule. While, if done correctly, this is usually sufficient to write rules with, there may be some edits we can make to the copied code to make it possible to try and find even more related samples.

In particular, we are able to add wildcard operators to hex strings using ? characters, which we could use to mask bytes that may change between samples. This could be used for masking stack offsets that may change, changing the type of register used, or fully masking addresses that will likely change across variants.

While we could open the x86 manual and do this ourselves (which I still recommend trying at least once!), we can actually take advantage of a default Ghidra plugin to help us with this! That is, YaraGhidraGUIScript.java can come in very handy. If I select a block of code, and execute this plugin, we can see the following output: Default YaraGhidraGUIScript output for AcidBox crypto routine

As you can see from the default output, some instructions have already been masked, changing some default registers. So already, we have a slightly looser rule we can use:

rule AcidBox_SSP_DLL_Loader_Crypto_Routine_B {
meta:
description = "Detects AcidBox SSP DLL loaders, based on a unique cryptography routine"
author = "BitsOfBinary"
reference = "https://unit42.paloaltonetworks.com/acidbox-rare-malware/"
hash = "003669761229d3e1db0f5a5b333ef62b3dffcc8e27c821ce9018362e0a2df7e9"
strings:
// 180013a71 0f b6 04 32 MOVZX EAX ,byte ptr [param_2 + RSI *0x1 ]
// 180013a75 33 c8 XOR param_1 ,EAX
// 180013a77 88 0c 3a MOV byte ptr [param_2 + RDI *0x1 ],param_1
// 180013a7a 41 ff c0 INC param_3
// 180013a7d 44 89 44 MOV dword ptr [RSP + local_14 ],param_3
// 24 04
$ = {0f b6 04 32 33 c8 88 0c 3a 4? ff c0 4? 89 44 ?4 04}
condition:
any of them
}

We’ll discuss in the next post a bit more about this Ghidra script + masking code.

Day 89 - AcidBox - SSP DLL Code - Signaturing Crypto Routine - Part 3

Let’s take a look at the YaraGhidraGUIScript.java window again: YaraGhidraGUIScript window showing toggleable instruction bytes

Each instruction, along with its operands can be toggled to be masked. So for instance, if I decided that I didn’t think the register R8D would be consistent across variants, I could toggle that value by clicking on the relevant boxes containing that register.

There are also options in the top of the window, which allow you to:

  • Mask all non-instructions (data)
  • Mask all operands
  • Mask all scalars
  • Mask all addresses

It’s worth playing around with these to see what the corresponding output would look like. For instance, I personally wouldn’t want to mask all operands in this case, although in larger blocks of code that may be useful. But masking all addresses may be useful here, which will mask the operand dword ptr [RSP + 0x4]. Here is an example of some of the instructions I have masked: YaraGhidraGUIScript output with masked instructions

If I cut out the last 3 wildcards (as they are no longer really needed), I can get the following rule:

rule AcidBox_SSP_DLL_Loader_Crypto_Routine_C {
meta:
description = "Detects AcidBox SSP DLL loaders, based on a unique cryptography routine"
author = "BitsOfBinary"
reference = "https://unit42.paloaltonetworks.com/acidbox-rare-malware/"
hash = "003669761229d3e1db0f5a5b333ef62b3dffcc8e27c821ce9018362e0a2df7e9"
strings:
// 180013a71 0f b6 04 32 MOVZX EAX ,byte ptr [param_2 + RSI *0x1 ]
// 180013a75 33 c8 XOR param_1 ,EAX
// 180013a77 88 0c 3a MOV byte ptr [param_2 + RDI *0x1 ],param_1
// 180013a7a 41 ff c0 INC param_3
// 180013a7d 44 89 44 MOV dword ptr [RSP + local_14 ],param_3
// 24 04
$ = {0f b6 04 32 33 c8 88 0c 3a 4? ff c? 4? 89}
condition:
any of them
}

Overall, it is worth playing around with instruction masking to see how far you can go before you start getting false positives. The more you want to reverse engineer the sample, the more context you will get to help you decide what you can/can’t mask (e.g. in this case, most of the code is dealing with function parameters, which have been saved into specific registers, so the masking might not actually make that much of a difference).

Day 90 - AcidBox - SSP DLL Code - Error Return Codes - Part 1

Something I noticed when looking through the AcidBox code was that a lot of functions would return 4-byte codes when it appeared that functions had errors. For example, in the screenshot below, you can see highlighted one of these error codes which will be returned if the call to OpenMutexA fails: AcidBox SSP DLL unique 4-byte return codes in Ghidra

This got me thinking that these values may be of interest from a detection perspective. But the first challenge is, how do we collect them all?

I could go through each function individually and copy them out, but that would take a while. So intead, I wrote the following Ghidra script:

max_steps = 100000
counter = 0
ins = getFirstInstruction()
last_ins = getLastInstruction()
while counter < max_steps and ins != last_ins:
mne_str = ins.getMnemonicString()
if mne_str == "MOV":
num_ops = ins.getNumOperands()
if num_ops == 2:
reg = ins.getDefaultOperandRepresentation(0)
if reg == "EAX" or reg == "EBX":
val = ins.getDefaultOperandRepresentation(1)
if val.startswith("0x") and len(val) == 10:
print(val)
ins = getInstructionAfter(ins)
counter += 1

It’s pretty hacky, but what it will do is iterate through the sample, find all instances of MOV instructions, and if a 4-byte value is being moved into EAX or EBX (the ones I saw commonly being used), it will print out those instructions.

The returned results cannot be used immediately, as there are some values returned that will cause lots of false positive (e.g. 0xfffffffe), and they are all the wrong endianess to use in YARA strings. As such, I put together a CyberChef script where I have removed some results, swapped the endianess, and put them in a nice format to use in YARA, which you can find here.

I’ll use the output in the next post to start writing rules with.

Day 91 - AcidBox - SSP DLL Code - Error Return Codes - Part 2

There are 133 error return codes output by the script in the previous post. None of these codes on their own are good enough to write a rule with; if I run a rule looking for any of them over system32, I get thousands of results.

If I increase the condition to 10 of them, I still get hits from system32, suggesting maybe these codes are used in some legitimate files/those bytes are too common?

So for a first pass at a rule, we should make sure we look for a sufficient amount of the strings, and apply some extra modifiers to reduce the chances of getting false positives.

rule AcidBox_SSP_DLL_Loader_Unique_Return_Codes_A {
meta:
description = "Detects AcidBox SSP DLL loaders, based on unique return codes seen in functions"
author = "BitsOfBinary"
reference = "https://unit42.paloaltonetworks.com/acidbox-rare-malware/"
hash = "003669761229d3e1db0f5a5b333ef62b3dffcc8e27c821ce9018362e0a2df7e9"
strings:
$ = {06 04 00 a0}
$ = {01 04 00 a0}
$ = {02 04 00 a0}
$ = {0c 0c 00 a0}
$ = {02 0c 00 a0}
$ = {01 07 00 a0}
$ = {07 08 00 a0}
$ = {02 07 00 a0}
$ = {04 06 00 a0}
$ = {08 06 00 a0}
$ = {02 06 00 a0}
$ = {0c 08 00 a0}
$ = {06 08 00 a0}
$ = {04 08 00 a0}
$ = {07 10 03 a0}
$ = {09 10 03 a0}
$ = {11 10 03 a0}
$ = {02 10 03 a0}
$ = {04 04 08 a0}
$ = {07 04 08 a0}
$ = {02 03 00 a0}
$ = {02 04 08 a0}
$ = {04 01 08 a0}
$ = {06 01 08 a0}
$ = {0e 01 08 a0}
$ = {01 02 08 a0}
$ = {02 02 08 a0}
$ = {04 02 08 a0}
$ = {06 02 08 a0}
$ = {01 00 00 c0}
$ = {02 0a 08 a0}
$ = {02 06 03 a0}
$ = {04 06 03 a0}
$ = {10 06 03 a0}
$ = {0e 06 03 a0}
$ = {02 08 02 80}
$ = {06 08 02 80}
$ = {01 08 02 80}
$ = {04 08 02 80}
$ = {07 08 02 80}
$ = {71 80 07 80}
$ = {06 01 03 80}
$ = {02 01 03 80}
$ = {02 06 03 80}
$ = {01 06 03 80}
$ = {02 07 03 80}
$ = {06 07 03 80}
$ = {07 06 04 80}
$ = {04 06 04 80}
$ = {05 06 04 80}
$ = {02 06 04 80}
$ = {07 16 04 80}
$ = {04 16 04 80}
$ = {06 16 04 80}
$ = {02 16 04 80}
$ = {02 28 04 80}
$ = {07 28 04 80}
$ = {06 0b 04 80}
$ = {02 0b 04 80}
$ = {02 0c 04 80}
$ = {02 0d 04 80}
$ = {06 0d 04 80}
$ = {02 1c 04 80}
$ = {04 1c 04 80}
$ = {07 1c 04 80}
$ = {06 1c 04 80}
$ = {0c 1c 04 80}
$ = {06 1d 04 80}
$ = {09 22 04 80}
$ = {09 08 04 80}
$ = {09 09 04 80}
$ = {09 07 04 80}
$ = {02 22 04 80}
$ = {0c 01 04 80}
$ = {02 01 04 80}
$ = {02 10 04 80}
$ = {02 11 04 80}
$ = {07 11 04 80}
$ = {0a 11 04 80}
$ = {02 12 04 80}
$ = {0a 12 04 80}
$ = {07 12 04 80}
$ = {01 0f 04 80}
$ = {07 0f 04 80}
$ = {02 0f 04 80}
$ = {0a 0f 04 80}
$ = {0b 0f 04 80}
$ = {02 02 04 80}
$ = {07 04 04 80}
$ = {0c 04 04 80}
$ = {02 04 04 80}
$ = {02 14 04 80}
$ = {02 15 04 80}
$ = {0a 14 04 80}
$ = {07 15 04 80}
$ = {0c 15 04 80}
$ = {09 25 04 80}
$ = {02 25 04 80}
$ = {02 26 04 80}
$ = {06 27 04 80}
$ = {07 27 04 80}
$ = {09 27 04 80}
$ = {0c 27 04 80}
$ = {0a 27 04 80}
$ = {04 27 04 80}
$ = {02 27 04 80}
$ = {04 13 04 80}
$ = {0c 13 04 80}
$ = {06 13 04 80}
$ = {01 13 04 80}
$ = {02 13 04 80}
$ = {0c 21 04 80}
$ = {06 21 04 80}
$ = {05 21 04 80}
$ = {02 21 04 80}
$ = {06 17 04 80}
$ = {0c 17 04 80}
$ = {02 17 04 80}
$ = {02 05 05 80}
$ = {06 05 05 80}
$ = {06 07 05 80}
$ = {04 07 05 80}
$ = {02 07 05 80}
$ = {02 09 05 80}
$ = {06 09 05 80}
$ = {01 0b 07 80}
$ = {06 0b 07 80}
$ = {02 0b 07 80}
$ = {06 0c 07 80}
$ = {02 0c 07 80}
$ = {05 03 01 80}
$ = {02 03 01 80}
condition:
uint16(0) == 0x5A4D and filesize < 500KB and 80 of them
}

Day 92 - AcidBox - SSP DLL Code - Error Return Codes - Part 3

My first attempt to try and reduce the number of error return codes to search for, was to combine the heuristics of only looking for them in the .text section, and ensure that they don’t appear more than 3 times per sample. As such, the updated condition looks like this:

uint16(0) == 0x5A4D and filesize < 500KB and 30 of them and not for any of them : (
not $ in (pe.sections[0].raw_data_offset .. pe.sections[0].raw_data_offset + pe.sections[0].raw_data_size) and
# > 3
)

To break this rule down:

  • not for any of them : ( ... ) - this performs a for loop over every occurance of every string matched, and looks to see that the result is false via the not operator
  • not $ in ( ... ) - given we’re in a for loop, we can refer to the strings anonymously using just $
  • (pe.sections[0].raw_data_offset .. pe.sections[0].raw_data_offset + pe.sections[0].raw_data_size) - I’m assuming here that the .text section is the first section in the PE - and by doing this I can use this to construct a range to check the string in that will represent the whole .text section
  • # > 3 - again, using the fact that the strings are anonymous to see if they appear more than 3 times

With some testing, I found that there were reduced FPs with this lower count of strings, but that there will still some files being detected that I don’t think were related. So while it is an improvement in that the rule is a bit more loose, it isn’t quite ideal! Find the full rule below:

import "pe"
rule AcidBox_SSP_DLL_Loader_Unique_Return_Codes_B {
meta:
description = "Detects AcidBox SSP DLL loaders, based on unique return codes seen in functions"
author = "BitsOfBinary"
reference = "https://unit42.paloaltonetworks.com/acidbox-rare-malware/"
hash = "003669761229d3e1db0f5a5b333ef62b3dffcc8e27c821ce9018362e0a2df7e9"
strings:
$ = {06 04 00 a0}
$ = {01 04 00 a0}
$ = {02 04 00 a0}
$ = {0c 0c 00 a0}
$ = {02 0c 00 a0}
$ = {01 07 00 a0}
$ = {07 08 00 a0}
$ = {02 07 00 a0}
$ = {04 06 00 a0}
$ = {08 06 00 a0}
$ = {02 06 00 a0}
$ = {0c 08 00 a0}
$ = {06 08 00 a0}
$ = {04 08 00 a0}
$ = {07 10 03 a0}
$ = {09 10 03 a0}
$ = {11 10 03 a0}
$ = {02 10 03 a0}
$ = {04 04 08 a0}
$ = {07 04 08 a0}
$ = {02 03 00 a0}
$ = {02 04 08 a0}
$ = {04 01 08 a0}
$ = {06 01 08 a0}
$ = {0e 01 08 a0}
$ = {01 02 08 a0}
$ = {02 02 08 a0}
$ = {04 02 08 a0}
$ = {06 02 08 a0}
$ = {01 00 00 c0}
$ = {02 0a 08 a0}
$ = {02 06 03 a0}
$ = {04 06 03 a0}
$ = {10 06 03 a0}
$ = {0e 06 03 a0}
$ = {02 08 02 80}
$ = {06 08 02 80}
$ = {01 08 02 80}
$ = {04 08 02 80}
$ = {07 08 02 80}
$ = {71 80 07 80}
$ = {06 01 03 80}
$ = {02 01 03 80}
$ = {02 06 03 80}
$ = {01 06 03 80}
$ = {02 07 03 80}
$ = {06 07 03 80}
$ = {07 06 04 80}
$ = {04 06 04 80}
$ = {05 06 04 80}
$ = {02 06 04 80}
$ = {07 16 04 80}
$ = {04 16 04 80}
$ = {06 16 04 80}
$ = {02 16 04 80}
$ = {02 28 04 80}
$ = {07 28 04 80}
$ = {06 0b 04 80}
$ = {02 0b 04 80}
$ = {02 0c 04 80}
$ = {02 0d 04 80}
$ = {06 0d 04 80}
$ = {02 1c 04 80}
$ = {04 1c 04 80}
$ = {07 1c 04 80}
$ = {06 1c 04 80}
$ = {0c 1c 04 80}
$ = {06 1d 04 80}
$ = {09 22 04 80}
$ = {09 08 04 80}
$ = {09 09 04 80}
$ = {09 07 04 80}
$ = {02 22 04 80}
$ = {0c 01 04 80}
$ = {02 01 04 80}
$ = {02 10 04 80}
$ = {02 11 04 80}
$ = {07 11 04 80}
$ = {0a 11 04 80}
$ = {02 12 04 80}
$ = {0a 12 04 80}
$ = {07 12 04 80}
$ = {01 0f 04 80}
$ = {07 0f 04 80}
$ = {02 0f 04 80}
$ = {0a 0f 04 80}
$ = {0b 0f 04 80}
$ = {02 02 04 80}
$ = {07 04 04 80}
$ = {0c 04 04 80}
$ = {02 04 04 80}
$ = {02 14 04 80}
$ = {02 15 04 80}
$ = {0a 14 04 80}
$ = {07 15 04 80}
$ = {0c 15 04 80}
$ = {09 25 04 80}
$ = {02 25 04 80}
$ = {02 26 04 80}
$ = {06 27 04 80}
$ = {07 27 04 80}
$ = {09 27 04 80}
$ = {0c 27 04 80}
$ = {0a 27 04 80}
$ = {04 27 04 80}
$ = {02 27 04 80}
$ = {04 13 04 80}
$ = {0c 13 04 80}
$ = {06 13 04 80}
$ = {01 13 04 80}
$ = {02 13 04 80}
$ = {0c 21 04 80}
$ = {06 21 04 80}
$ = {05 21 04 80}
$ = {02 21 04 80}
$ = {06 17 04 80}
$ = {0c 17 04 80}
$ = {02 17 04 80}
$ = {02 05 05 80}
$ = {06 05 05 80}
$ = {06 07 05 80}
$ = {04 07 05 80}
$ = {02 07 05 80}
$ = {02 09 05 80}
$ = {06 09 05 80}
$ = {01 0b 07 80}
$ = {06 0b 07 80}
$ = {02 0b 07 80}
$ = {06 0c 07 80}
$ = {02 0c 07 80}
$ = {05 03 01 80}
$ = {02 03 01 80}
condition:
uint16(0) == 0x5A4D and filesize < 500KB and 30 of them and not for any of them : (
not $ in (pe.sections[0].raw_data_offset .. pe.sections[0].raw_data_offset + pe.sections[0].raw_data_size) and
# > 3
)
}

Day 93 - AcidBox - SSP DLL Code - Error Return Codes - Part 4

To use these error codes in a slightly different way, let’s consider what the script from part 1 of these posts was doing: it was looking for instances where 4-byte values were being loading into EAX or EBX (which are subsequently returned by a function).

Using this fact, we can rewrite our rules to only look for instances where these error codes are being loaded into either of these registers, e.g. $ = {(b8|bb) 06 04 00 a0}. I found that this approach meant that the overall number of strings required to be present could be significantly reduced!

rule AcidBox_SSP_DLL_Loader_Unique_Return_Codes_C {
meta:
description = "Detects AcidBox SSP DLL loaders, based on unique return codes seen in functions"
author = "BitsOfBinary"
reference = "https://unit42.paloaltonetworks.com/acidbox-rare-malware/"
hash = "003669761229d3e1db0f5a5b333ef62b3dffcc8e27c821ce9018362e0a2df7e9"
strings:
$ = {(b8|bb) 06 04 00 a0}
$ = {(b8|bb) 01 04 00 a0}
$ = {(b8|bb) 02 04 00 a0}
$ = {(b8|bb) 0c 0c 00 a0}
$ = {(b8|bb) 02 0c 00 a0}
$ = {(b8|bb) 01 07 00 a0}
$ = {(b8|bb) 07 08 00 a0}
$ = {(b8|bb) 02 07 00 a0}
$ = {(b8|bb) 04 06 00 a0}
$ = {(b8|bb) 08 06 00 a0}
$ = {(b8|bb) 02 06 00 a0}
$ = {(b8|bb) 0c 08 00 a0}
$ = {(b8|bb) 06 08 00 a0}
$ = {(b8|bb) 04 08 00 a0}
$ = {(b8|bb) 07 10 03 a0}
$ = {(b8|bb) 09 10 03 a0}
$ = {(b8|bb) 11 10 03 a0}
$ = {(b8|bb) 02 10 03 a0}
$ = {(b8|bb) 04 04 08 a0}
$ = {(b8|bb) 07 04 08 a0}
$ = {(b8|bb) 02 03 00 a0}
$ = {(b8|bb) 02 04 08 a0}
$ = {(b8|bb) 04 01 08 a0}
$ = {(b8|bb) 06 01 08 a0}
$ = {(b8|bb) 0e 01 08 a0}
$ = {(b8|bb) 01 02 08 a0}
$ = {(b8|bb) 02 02 08 a0}
$ = {(b8|bb) 04 02 08 a0}
$ = {(b8|bb) 06 02 08 a0}
$ = {(b8|bb) 01 00 00 c0}
$ = {(b8|bb) 02 0a 08 a0}
$ = {(b8|bb) 02 06 03 a0}
$ = {(b8|bb) 04 06 03 a0}
$ = {(b8|bb) 10 06 03 a0}
$ = {(b8|bb) 0e 06 03 a0}
$ = {(b8|bb) 02 08 02 80}
$ = {(b8|bb) 06 08 02 80}
$ = {(b8|bb) 01 08 02 80}
$ = {(b8|bb) 04 08 02 80}
$ = {(b8|bb) 07 08 02 80}
$ = {(b8|bb) 71 80 07 80}
$ = {(b8|bb) 06 01 03 80}
$ = {(b8|bb) 02 01 03 80}
$ = {(b8|bb) 02 06 03 80}
$ = {(b8|bb) 01 06 03 80}
$ = {(b8|bb) 02 07 03 80}
$ = {(b8|bb) 06 07 03 80}
$ = {(b8|bb) 07 06 04 80}
$ = {(b8|bb) 04 06 04 80}
$ = {(b8|bb) 05 06 04 80}
$ = {(b8|bb) 02 06 04 80}
$ = {(b8|bb) 07 16 04 80}
$ = {(b8|bb) 04 16 04 80}
$ = {(b8|bb) 06 16 04 80}
$ = {(b8|bb) 02 16 04 80}
$ = {(b8|bb) 02 28 04 80}
$ = {(b8|bb) 07 28 04 80}
$ = {(b8|bb) 06 0b 04 80}
$ = {(b8|bb) 02 0b 04 80}
$ = {(b8|bb) 02 0c 04 80}
$ = {(b8|bb) 02 0d 04 80}
$ = {(b8|bb) 06 0d 04 80}
$ = {(b8|bb) 02 1c 04 80}
$ = {(b8|bb) 04 1c 04 80}
$ = {(b8|bb) 07 1c 04 80}
$ = {(b8|bb) 06 1c 04 80}
$ = {(b8|bb) 0c 1c 04 80}
$ = {(b8|bb) 06 1d 04 80}
$ = {(b8|bb) 09 22 04 80}
$ = {(b8|bb) 09 08 04 80}
$ = {(b8|bb) 09 09 04 80}
$ = {(b8|bb) 09 07 04 80}
$ = {(b8|bb) 02 22 04 80}
$ = {(b8|bb) 0c 01 04 80}
$ = {(b8|bb) 02 01 04 80}
$ = {(b8|bb) 02 10 04 80}
$ = {(b8|bb) 02 11 04 80}
$ = {(b8|bb) 07 11 04 80}
$ = {(b8|bb) 0a 11 04 80}
$ = {(b8|bb) 02 12 04 80}
$ = {(b8|bb) 0a 12 04 80}
$ = {(b8|bb) 07 12 04 80}
$ = {(b8|bb) 01 0f 04 80}
$ = {(b8|bb) 07 0f 04 80}
$ = {(b8|bb) 02 0f 04 80}
$ = {(b8|bb) 0a 0f 04 80}
$ = {(b8|bb) 0b 0f 04 80}
$ = {(b8|bb) 02 02 04 80}
$ = {(b8|bb) 07 04 04 80}
$ = {(b8|bb) 0c 04 04 80}
$ = {(b8|bb) 02 04 04 80}
$ = {(b8|bb) 02 14 04 80}
$ = {(b8|bb) 02 15 04 80}
$ = {(b8|bb) 0a 14 04 80}
$ = {(b8|bb) 07 15 04 80}
$ = {(b8|bb) 0c 15 04 80}
$ = {(b8|bb) 09 25 04 80}
$ = {(b8|bb) 02 25 04 80}
$ = {(b8|bb) 02 26 04 80}
$ = {(b8|bb) 06 27 04 80}
$ = {(b8|bb) 07 27 04 80}
$ = {(b8|bb) 09 27 04 80}
$ = {(b8|bb) 0c 27 04 80}
$ = {(b8|bb) 0a 27 04 80}
$ = {(b8|bb) 04 27 04 80}
$ = {(b8|bb) 02 27 04 80}
$ = {(b8|bb) 04 13 04 80}
$ = {(b8|bb) 0c 13 04 80}
$ = {(b8|bb) 06 13 04 80}
$ = {(b8|bb) 01 13 04 80}
$ = {(b8|bb) 02 13 04 80}
$ = {(b8|bb) 0c 21 04 80}
$ = {(b8|bb) 06 21 04 80}
$ = {(b8|bb) 05 21 04 80}
$ = {(b8|bb) 02 21 04 80}
$ = {(b8|bb) 06 17 04 80}
$ = {(b8|bb) 0c 17 04 80}
$ = {(b8|bb) 02 17 04 80}
$ = {(b8|bb) 02 05 05 80}
$ = {(b8|bb) 06 05 05 80}
$ = {(b8|bb) 06 07 05 80}
$ = {(b8|bb) 04 07 05 80}
$ = {(b8|bb) 02 07 05 80}
$ = {(b8|bb) 02 09 05 80}
$ = {(b8|bb) 06 09 05 80}
$ = {(b8|bb) 01 0b 07 80}
$ = {(b8|bb) 06 0b 07 80}
$ = {(b8|bb) 02 0b 07 80}
$ = {(b8|bb) 06 0c 07 80}
$ = {(b8|bb) 02 0c 07 80}
$ = {(b8|bb) 05 03 01 80}
$ = {(b8|bb) 02 03 01 80}
condition:
uint16(0) == 0x5A4D and 10 of them
}

We could extend this further if we wanted, to include all possible registers that these values are being loaded into; but I’ll leave that up to you if you’d like to try that out.

Day 94 - AcidBox - Main Worker DLL Technique - SeLoadDriverPrivilege Stack String - Part 1

To change things up a bit, let’s look at the AcidBox main worker DLL referenced by Palo Alto: eb30a1822bd6f503f8151cb04bfd315a62fa67dbfe1f573e6fcfd74636ecedd5

A lot of our already written rules hit on this sample, including the format strings combo, crypto routine, and return codes. So we already have some good coverage! Instead of writing a YARA rule for strings, meta features, or code, let’s instead focus on a technique to signature.

The main worker DLL uses stack strings to obfuscate some of the important strings (which is similar to the loader, which explains why we weren’t seeing as many strings in plaintext). One in particular is the string SeLoadDriverPrivilege, which is being used to attempt to set a new privilege level for itself. The following blog has some explanations about why/how it can be used maliciously: https://www.tarlogic.com/blog/seloaddriverprivilege-privilege-escalation/

AcidBox main worker DLL stack string in Ghidra

If you’re looking at stack strings, I can recommend @notareverser’s Python script to generate variations of possible stack strings for a provided input: https://gist.github.com/notareverser/4f6b9c644d4fe517889b3fbb0b4271ca

If we input SeLoadDriverPrivilege into this script, we get the following rule:

rule stackstring_SeLoadDriverPrivilege
{
strings:
$smallStack = {c6(45|4424)??53 c6(45|4424)??65 c6(45|4424)??4c c6(45|4424)??6f c6(45|4424)??61 c6(45|4424)??64 c6(45|4424)??44 c6(45|4424)??72 c6(45|4424)??69 c6(45|4424)??76 c6(45|4424)??65 c6(45|4424)??72 c6(45|4424)??50 c6(45|4424)??72 c6(45|4424)??69 c6(45|4424)??76 c6(45|4424)??69 c6(45|4424)??6c c6(45|4424)??65 c6(45|4424)??67 c6(45|4424)??65}
$largeStack = {c7(45|85)[1-4]53000000 c7(45|85)[1-4]65000000 c7(45|85)[1-4]4c000000 c7(45|85)[1-4]6f000000 c7(45|85)[1-4]61000000 c7(45|85)[1-4]64000000 c7(45|85)[1-4]44000000 c7(45|85)[1-4]72000000 c7(45|85)[1-4]69000000 c7(45|85)[1-4]76000000 c7(45|85)[1-4]65000000 c7(45|85)[1-4]72000000 c7(45|85)[1-4]50000000 c7(45|85)[1-4]72000000 c7(45|85)[1-4]69000000 c7(45|85)[1-4]76000000 c7(45|85)[1-4]69000000 c7(45|85)[1-4]6c000000 c7(45|85)[1-4]65000000 c7(45|85)[1-4]67000000 c7(45|85)[1-4]65000000}
$register = {b?53000000 6689???? b?65000000 6689???? b?4c000000 6689???? b?6f000000 6689???? b?61000000 6689???? b?64000000 6689???? b?44000000 6689???? b?72000000 6689???? b?69000000 6689???? b?76000000 6689???? b?65000000 6689???? b?72000000 6689???? b?50000000 6689???? b?72000000 6689???? b?69000000 6689???? b?76000000 6689???? b?69000000 6689???? b?6c000000 6689???? b?65000000 6689???? b?67000000 6689???? b?65000000 6689????}
$dword = {c7(45|85)[1-4]6f4c6553 c7(45|85)[1-4]72446461 c7(45|85)[1-4]72657669 c7(45|85)[1-4]76697250 c7(45|85)[1-4]67656c69 [0-1]c6(45|85)[1-4]65}
$pushpop = {6a535? 6a65 6689????5? 6a4c 6689????5? 6a6f 6689????5? 6a61 6689????5? 6a64 6689????5? 6a44 6689????5? 6a72 6689????5? 6a69 6689????5? 6a76 6689????5? 6a65 6689????5? 6a72 6689????5? 6a50 6689????5? 6a72 6689????5? 6a69 6689????5? 6a76 6689????5? 6a69 6689????5? 6a6c 6689????5? 6a65 6689????5? 6a67 6689????5?}
$callOverString = {e81500000053654c6f616444726976657250726976696c6567655? }
condition:
any of them
}

Unforunately in this case, the stack string is being built up out of order, meaning this auto-generated rule won’t be able to pick it up. So let’s look in the next post about a way we can deal with this.

Day 95 - AcidBox - Main Worker DLL Technique - SeLoadDriverPrivilege Stack String - Part 2

Let’s look at the code that is loading the stack string:

1800097cf c7 44 24 MOV dword ptr [RSP + Stack [-0x21 ]],"eliv"
37 76 69
6c 65
1800097d7 c7 44 24 MOV dword ptr [RSP + local_2f[0] ],"aoLe"
29 65 4c
6f 61
1800097df 66 c7 44 MOV word ptr [RSP + local_1f +0x2 ],"eg"
24 3b 67 65
1800097e6 c7 44 24 MOV dword ptr [RSP + local_2f[5] ],"virD"
2e 44 72
69 76
1800097ee c7 44 24 MOV dword ptr [RSP + Stack [-0x25 ]],"irPr"
33 72 50
72 69
1800097f6 c6 44 24 MOV byte ptr [RSP + local_2f[4] ],'d'
2d 64
1800097fb c6 44 24 MOV byte ptr [RSP + Stack [-0x26 ]],'e'
32 65
180009800 c6 44 24 MOV byte ptr [RSP + local_30 ],'S'
28 53

As we can see, the different parts of the string are being loaded on to the stack out of order, and in variable amounts: either 1, 2, or 4 bytes at a time. As we can see, each set of instructions looks like this (note that we’re adding wildcards to the stack offsets):

  • 1-byte - C6 44 24 ?? AA
  • 2-byte - 66 C7 44 24 ?? AA BB
  • 4-byte - C7 44 24 ?? AA BB CC DD

So, if we want to write a YARA rule for this stack string, we will have to do it in an un-ordered way, and if we want to hunt for more samples we can’t necessarily assume that it will be in the same order we observe here. As such, we will need to generate all possible instructions for loading the characters onto the stack. The following Python code can do this for us, and format them as YARA strings:

import binascii
api_name = "SeLoadDriverPrivilege"
one_byte_strs = []
two_byte_strs = []
four_byte_strs = []
for c in api_name:
hex_str = f"$one_byte_mov_{c}_stack = {{C6 44 24 ?? {format(ord(c), 'x')}}}"
if hex_str not in one_byte_strs:
one_byte_strs.append(hex_str)
for i in range(0, len(api_name)-1):
chars = api_name[i:i+2]
two_bytes = binascii.hexlify(chars.encode(), ' ').decode()
hex_str = f"$two_byte_mov_{chars}_stack = {{66 C7 44 24 ?? {two_bytes}}}"
if hex_str not in two_byte_strs:
two_byte_strs.append(hex_str)
for i in range(0, len(api_name)-3):
chars = api_name[i:i+4]
four_bytes = binascii.hexlify(chars.encode(), ' ').decode()
hex_str = f"$four_byte_mov_{chars}_stack = {{C7 44 24 ?? {four_bytes}}}"
if hex_str not in four_byte_strs:
four_byte_strs.append(hex_str)
for string in one_byte_strs + two_byte_strs + four_byte_strs:
print(string)

We’ll start building YARA rules with these values in the next post.

Day 96 - AcidBox - Main Worker DLL Technique - SeLoadDriverPrivilege Stack String - Part 3

Using the strings generated from the script in the previous post, we can start with the following naive attempt:

rule Heuristic_Stack_String_SeLoadDriverPrivilege_A {
meta:
description = "Detects the stack string SeLoadDriverPrivilege being loaded in a combination of 1, 2, and 4 byte chunks, not necessarily in order"
strings:
$one_byte_mov_S_stack = {C6 44 24 ?? 53}
$one_byte_mov_e_stack = {C6 44 24 ?? 65}
$one_byte_mov_L_stack = {C6 44 24 ?? 4c}
$one_byte_mov_o_stack = {C6 44 24 ?? 6f}
$one_byte_mov_a_stack = {C6 44 24 ?? 61}
$one_byte_mov_d_stack = {C6 44 24 ?? 64}
$one_byte_mov_D_stack = {C6 44 24 ?? 44}
$one_byte_mov_r_stack = {C6 44 24 ?? 72}
$one_byte_mov_i_stack = {C6 44 24 ?? 69}
$one_byte_mov_v_stack = {C6 44 24 ?? 76}
$one_byte_mov_P_stack = {C6 44 24 ?? 50}
$one_byte_mov_l_stack = {C6 44 24 ?? 6c}
$one_byte_mov_g_stack = {C6 44 24 ?? 67}
$two_byte_mov_Se_stack = {66 C7 44 24 ?? 53 65}
$two_byte_mov_eL_stack = {66 C7 44 24 ?? 65 4c}
$two_byte_mov_Lo_stack = {66 C7 44 24 ?? 4c 6f}
$two_byte_mov_oa_stack = {66 C7 44 24 ?? 6f 61}
$two_byte_mov_ad_stack = {66 C7 44 24 ?? 61 64}
$two_byte_mov_dD_stack = {66 C7 44 24 ?? 64 44}
$two_byte_mov_Dr_stack = {66 C7 44 24 ?? 44 72}
$two_byte_mov_ri_stack = {66 C7 44 24 ?? 72 69}
$two_byte_mov_iv_stack = {66 C7 44 24 ?? 69 76}
$two_byte_mov_ve_stack = {66 C7 44 24 ?? 76 65}
$two_byte_mov_er_stack = {66 C7 44 24 ?? 65 72}
$two_byte_mov_rP_stack = {66 C7 44 24 ?? 72 50}
$two_byte_mov_Pr_stack = {66 C7 44 24 ?? 50 72}
$two_byte_mov_vi_stack = {66 C7 44 24 ?? 76 69}
$two_byte_mov_il_stack = {66 C7 44 24 ?? 69 6c}
$two_byte_mov_le_stack = {66 C7 44 24 ?? 6c 65}
$two_byte_mov_eg_stack = {66 C7 44 24 ?? 65 67}
$two_byte_mov_ge_stack = {66 C7 44 24 ?? 67 65}
$four_byte_mov_SeLo_stack = {C7 44 24 ?? 53 65 4c 6f}
$four_byte_mov_eLoa_stack = {C7 44 24 ?? 65 4c 6f 61}
$four_byte_mov_Load_stack = {C7 44 24 ?? 4c 6f 61 64}
$four_byte_mov_oadD_stack = {C7 44 24 ?? 6f 61 64 44}
$four_byte_mov_adDr_stack = {C7 44 24 ?? 61 64 44 72}
$four_byte_mov_dDri_stack = {C7 44 24 ?? 64 44 72 69}
$four_byte_mov_Driv_stack = {C7 44 24 ?? 44 72 69 76}
$four_byte_mov_rive_stack = {C7 44 24 ?? 72 69 76 65}
$four_byte_mov_iver_stack = {C7 44 24 ?? 69 76 65 72}
$four_byte_mov_verP_stack = {C7 44 24 ?? 76 65 72 50}
$four_byte_mov_erPr_stack = {C7 44 24 ?? 65 72 50 72}
$four_byte_mov_rPri_stack = {C7 44 24 ?? 72 50 72 69}
$four_byte_mov_Priv_stack = {C7 44 24 ?? 50 72 69 76}
$four_byte_mov_rivi_stack = {C7 44 24 ?? 72 69 76 69}
$four_byte_mov_ivil_stack = {C7 44 24 ?? 69 76 69 6c}
$four_byte_mov_vile_stack = {C7 44 24 ?? 76 69 6c 65}
$four_byte_mov_ileg_stack = {C7 44 24 ?? 69 6c 65 67}
$four_byte_mov_lege_stack = {C7 44 24 ?? 6c 65 67 65}
condition:
any of ($one_byte_*) and
any of ($two_byte_*) and
any of ($four_byte_*)
}

This is naive in the sense that it is looking for at least one of each type of stack loading (1, 2, and 4 byte), but it is looking for them anywhere in the file. While the 4 byte strings won’t be as common, the other ones (especially the 1 byte strings) will be a lot more common, meaning we might run into some false positives, and as such we cannot rely on any one type on its own at this stage. We’ll see if we can do any better in the next post.

Day 97 - AcidBox - Main Worker DLL Technique - SeLoadDriverPrivilege Stack String - Part 4

Instead of looking for each type of stack string loading anywhere in a scanned file, let’s be a bit more specific. In particular, how can we ensure that they are appearing in the same region as each other?

My first thought for this is to introduce a for loop as follows:

rule Heuristic_Stack_String_SeLoadDriverPrivilege_B {
meta:
description = "Detects the stack string SeLoadDriverPrivilege being loaded in a combination of 1, 2, and 4 byte chunks, not necessarily in order"
strings:
$one_byte_mov_S_stack = {C6 44 24 ?? 53}
$one_byte_mov_e_stack = {C6 44 24 ?? 65}
$one_byte_mov_L_stack = {C6 44 24 ?? 4c}
$one_byte_mov_o_stack = {C6 44 24 ?? 6f}
$one_byte_mov_a_stack = {C6 44 24 ?? 61}
$one_byte_mov_d_stack = {C6 44 24 ?? 64}
$one_byte_mov_D_stack = {C6 44 24 ?? 44}
$one_byte_mov_r_stack = {C6 44 24 ?? 72}
$one_byte_mov_i_stack = {C6 44 24 ?? 69}
$one_byte_mov_v_stack = {C6 44 24 ?? 76}
$one_byte_mov_P_stack = {C6 44 24 ?? 50}
$one_byte_mov_l_stack = {C6 44 24 ?? 6c}
$one_byte_mov_g_stack = {C6 44 24 ?? 67}
$two_byte_mov_Se_stack = {66 C7 44 24 ?? 53 65}
$two_byte_mov_eL_stack = {66 C7 44 24 ?? 65 4c}
$two_byte_mov_Lo_stack = {66 C7 44 24 ?? 4c 6f}
$two_byte_mov_oa_stack = {66 C7 44 24 ?? 6f 61}
$two_byte_mov_ad_stack = {66 C7 44 24 ?? 61 64}
$two_byte_mov_dD_stack = {66 C7 44 24 ?? 64 44}
$two_byte_mov_Dr_stack = {66 C7 44 24 ?? 44 72}
$two_byte_mov_ri_stack = {66 C7 44 24 ?? 72 69}
$two_byte_mov_iv_stack = {66 C7 44 24 ?? 69 76}
$two_byte_mov_ve_stack = {66 C7 44 24 ?? 76 65}
$two_byte_mov_er_stack = {66 C7 44 24 ?? 65 72}
$two_byte_mov_rP_stack = {66 C7 44 24 ?? 72 50}
$two_byte_mov_Pr_stack = {66 C7 44 24 ?? 50 72}
$two_byte_mov_vi_stack = {66 C7 44 24 ?? 76 69}
$two_byte_mov_il_stack = {66 C7 44 24 ?? 69 6c}
$two_byte_mov_le_stack = {66 C7 44 24 ?? 6c 65}
$two_byte_mov_eg_stack = {66 C7 44 24 ?? 65 67}
$two_byte_mov_ge_stack = {66 C7 44 24 ?? 67 65}
$four_byte_mov_SeLo_stack = {C7 44 24 ?? 53 65 4c 6f}
$four_byte_mov_eLoa_stack = {C7 44 24 ?? 65 4c 6f 61}
$four_byte_mov_Load_stack = {C7 44 24 ?? 4c 6f 61 64}
$four_byte_mov_oadD_stack = {C7 44 24 ?? 6f 61 64 44}
$four_byte_mov_adDr_stack = {C7 44 24 ?? 61 64 44 72}
$four_byte_mov_dDri_stack = {C7 44 24 ?? 64 44 72 69}
$four_byte_mov_Driv_stack = {C7 44 24 ?? 44 72 69 76}
$four_byte_mov_rive_stack = {C7 44 24 ?? 72 69 76 65}
$four_byte_mov_iver_stack = {C7 44 24 ?? 69 76 65 72}
$four_byte_mov_verP_stack = {C7 44 24 ?? 76 65 72 50}
$four_byte_mov_erPr_stack = {C7 44 24 ?? 65 72 50 72}
$four_byte_mov_rPri_stack = {C7 44 24 ?? 72 50 72 69}
$four_byte_mov_Priv_stack = {C7 44 24 ?? 50 72 69 76}
$four_byte_mov_rivi_stack = {C7 44 24 ?? 72 69 76 69}
$four_byte_mov_ivil_stack = {C7 44 24 ?? 69 76 69 6c}
$four_byte_mov_vile_stack = {C7 44 24 ?? 76 69 6c 65}
$four_byte_mov_ileg_stack = {C7 44 24 ?? 69 6c 65 67}
$four_byte_mov_lege_stack = {C7 44 24 ?? 6c 65 67 65}
condition:
for any of them : (
any of ($one_byte*) in (@ - 100 .. @ + 100) and
any of ($two_byte*) in (@ - 100 .. @ + 100) and
any of ($four_byte*) in (@ - 100 .. @ + 100)
)
}

Here, we are using the fact that as we’re iterating over anonymous strings (via any of them), we can reference each string’s offset via the @ operator. Further to this, we’re saying that for each type of stack string loading (1, 2, and 4 bytes), we want to make sure that one of each type of them will appear “close enough” to each other (i.e. via the any of .. in (@ - 100 .. @ + 100) check).

We could aim to make this rule stricter by changing the range check (e.g. (@ - 50 .. @ + 50)), or checking to see if there are multiple types of each stack string loading (e.g. 2 of them).

Day 98 - AcidBox - Main Worker DLL Technique - SeLoadDriverPrivilege Stack String - Part 5

To wrap up the discussion of this technique, let’s think about if there is a way we can ensure that we don’t have to look for every type of the stack string loading in the same sample. That is, maybe one variant will load this string using five 4-byte loads, and one 1-byte load, and not use the 2-byte load at all.

My thought for this approach is to again use a for loop, and iterate over one of the types (I use the 4-byte version in this case), and see if one of the other types occurs immediately afterwards. Given that the length of the 4-byte move instruction is 8-bytes, the rule looks like this:

rule Heuristic_Stack_String_SeLoadDriverPrivilege_C {
meta:
description = "Detects the stack string SeLoadDriverPrivilege being loaded in a combination of 1, 2, and 4 byte chunks, not necessarily in order"
strings:
$one_byte_mov_S_stack = {C6 44 24 ?? 53}
$one_byte_mov_e_stack = {C6 44 24 ?? 65}
$one_byte_mov_L_stack = {C6 44 24 ?? 4c}
$one_byte_mov_o_stack = {C6 44 24 ?? 6f}
$one_byte_mov_a_stack = {C6 44 24 ?? 61}
$one_byte_mov_d_stack = {C6 44 24 ?? 64}
$one_byte_mov_D_stack = {C6 44 24 ?? 44}
$one_byte_mov_r_stack = {C6 44 24 ?? 72}
$one_byte_mov_i_stack = {C6 44 24 ?? 69}
$one_byte_mov_v_stack = {C6 44 24 ?? 76}
$one_byte_mov_P_stack = {C6 44 24 ?? 50}
$one_byte_mov_l_stack = {C6 44 24 ?? 6c}
$one_byte_mov_g_stack = {C6 44 24 ?? 67}
$two_byte_mov_Se_stack = {66 C7 44 24 ?? 53 65}
$two_byte_mov_eL_stack = {66 C7 44 24 ?? 65 4c}
$two_byte_mov_Lo_stack = {66 C7 44 24 ?? 4c 6f}
$two_byte_mov_oa_stack = {66 C7 44 24 ?? 6f 61}
$two_byte_mov_ad_stack = {66 C7 44 24 ?? 61 64}
$two_byte_mov_dD_stack = {66 C7 44 24 ?? 64 44}
$two_byte_mov_Dr_stack = {66 C7 44 24 ?? 44 72}
$two_byte_mov_ri_stack = {66 C7 44 24 ?? 72 69}
$two_byte_mov_iv_stack = {66 C7 44 24 ?? 69 76}
$two_byte_mov_ve_stack = {66 C7 44 24 ?? 76 65}
$two_byte_mov_er_stack = {66 C7 44 24 ?? 65 72}
$two_byte_mov_rP_stack = {66 C7 44 24 ?? 72 50}
$two_byte_mov_Pr_stack = {66 C7 44 24 ?? 50 72}
$two_byte_mov_vi_stack = {66 C7 44 24 ?? 76 69}
$two_byte_mov_il_stack = {66 C7 44 24 ?? 69 6c}
$two_byte_mov_le_stack = {66 C7 44 24 ?? 6c 65}
$two_byte_mov_eg_stack = {66 C7 44 24 ?? 65 67}
$two_byte_mov_ge_stack = {66 C7 44 24 ?? 67 65}
$four_byte_mov_SeLo_stack = {C7 44 24 ?? 53 65 4c 6f}
$four_byte_mov_eLoa_stack = {C7 44 24 ?? 65 4c 6f 61}
$four_byte_mov_Load_stack = {C7 44 24 ?? 4c 6f 61 64}
$four_byte_mov_oadD_stack = {C7 44 24 ?? 6f 61 64 44}
$four_byte_mov_adDr_stack = {C7 44 24 ?? 61 64 44 72}
$four_byte_mov_dDri_stack = {C7 44 24 ?? 64 44 72 69}
$four_byte_mov_Driv_stack = {C7 44 24 ?? 44 72 69 76}
$four_byte_mov_rive_stack = {C7 44 24 ?? 72 69 76 65}
$four_byte_mov_iver_stack = {C7 44 24 ?? 69 76 65 72}
$four_byte_mov_verP_stack = {C7 44 24 ?? 76 65 72 50}
$four_byte_mov_erPr_stack = {C7 44 24 ?? 65 72 50 72}
$four_byte_mov_rPri_stack = {C7 44 24 ?? 72 50 72 69}
$four_byte_mov_Priv_stack = {C7 44 24 ?? 50 72 69 76}
$four_byte_mov_rivi_stack = {C7 44 24 ?? 72 69 76 69}
$four_byte_mov_ivil_stack = {C7 44 24 ?? 69 76 69 6c}
$four_byte_mov_vile_stack = {C7 44 24 ?? 76 69 6c 65}
$four_byte_mov_ileg_stack = {C7 44 24 ?? 69 6c 65 67}
$four_byte_mov_lege_stack = {C7 44 24 ?? 6c 65 67 65}
condition:
for any of ($four_byte_*) : (
any of ($one_byte_*, $two_byte_*) at @+8
)
}

Again, there are more ways to modify this rule, such as including another for loop for each other type, or doing combinations of those, etc. There are usually multiple ways to write these more heuristic rules, and these are just my interpretations!

Day 99 - AcidBox Wrapup

Despite spending many posts looking at AcidBox, I feel like there is still more that can be done! I haven’t looked at the kernel module, or focused on any meta features of the main worker DLL.

However, as I stated back at the start of the AcidBox analysis, I believe I have followed the approach I set out to do, which is as follows:

  • Accessibility - I’ve made my rule names and descriptions clear, while referencing the Palo Alto blog and hash values I used to write the rules with
  • Simplicity - I’ve stuck to a single idea per rule to try and keep the logic straightforward and understandable
  • Redundancy - by writing rules for strings, meta features, code, and techniques, we now have a collection of rules not just for multiple facets of AcidBox, but some heuristic rules that can be used to classify other samples as well

Private Rules

You may not like that each rulename itself is very descriptive; instead, maybe all you care about is having a rule that tells you “is this AcidBox?”. This could be done via private YARA rules, by taking each rule that we’ve written for AcidBox in these posts, making them private, and then referencing them in one main rule:

rule AcidBox {
condition:
any of (AcidBox*)
}

You could then decide how strong you want this condition to be. Maybe you want to be confident that it is indeed AcidBox by relying on it covering multiple facets; so you could increase the condition to 2 of them, or break it out further into checking specific combinations of rules (e.g. checking for error codes AND format strings, etc.).

I hope these posts have shown how you can tackle writing rules for a malware family!