# GuLoader Script Deobfuscation

### Stage 1 - VBS

To obtain the second-stage PowerShell script, some manual work is required. Fortunately, breaking down the first stage is relatively straightforward, allowing us to extract the embedded PowerShell script.

GuLoader utilizes `wscript` for interaction with the operating system. The initial step involves locating the variable used to call `wscript`, typically identified by searching for the string "WScript".

<figure><img src="https://3892796155-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZt3ly4wOcBID8vwUbybj%2Fuploads%2FvuOfmZAGYdTCe0kgGQcS%2FWScript_Shell_Variable.PNG?alt=media&#x26;token=14448758-cfe5-4120-9fc2-ded00b992afa" alt=""><figcaption></figcaption></figure>

Once the variable name is identified, another search helps pinpoint where it's utilized. This search should lead to a line resembling the following:

<figure><img src="https://3892796155-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZt3ly4wOcBID8vwUbybj%2Fuploads%2FY5tpkCVENSgJqOzFUuXv%2FWScript_Shell_Run_Original.PNG?alt=media&#x26;token=081e6ab1-d922-48d5-8288-85d5c7da1d16" alt=""><figcaption></figcaption></figure>

By modifying this line to output its contents to the command line, we can extract the second-stage script.

<figure><img src="https://3892796155-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZt3ly4wOcBID8vwUbybj%2Fuploads%2FBEh3bLqXvidavHWAh7FC%2FWScript_Shell_Run_Edited.PNG?alt=media&#x26;token=00b08241-3ea7-471a-a11e-d14265a9e564" alt=""><figcaption></figcaption></figure>

Running the modified first stage using `cscript` from PowerShell enables dumping of the second stage directly to the command line.

<figure><img src="https://3892796155-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZt3ly4wOcBID8vwUbybj%2Fuploads%2FCdKRVFZXXagCAFv8LC02%2FStage_2_Dumped.PNG?alt=media&#x26;token=6fa11aa8-0d4f-4d44-8618-24c0e4df066a" alt=""><figcaption></figcaption></figure>

### Stage 2 - PowerShell

After dumping the PowerShell payload, the next step is to determine the substring integer needed for the deobfuscation script. This is typically straightforward; at the beginning of the PowerShell script, there's usually a function defined. Inside this function, there's a for loop initialized with a non-zero number, which serves as the substring value for deobfuscating a passed string. In the sample, this number is set to seven.

<figure><img src="https://3892796155-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZt3ly4wOcBID8vwUbybj%2Fuploads%2FmmjY40qrHo3TYwD2iD3Q%2FSubstring_Variable.PNG?alt=media&#x26;token=24f2146e-eb9a-49a5-bb82-3d70fb645a91" alt=""><figcaption></figcaption></figure>

Once the substring value has been determined it can be configured in the python deobfuscation script.

<figure><img src="https://3892796155-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZt3ly4wOcBID8vwUbybj%2Fuploads%2FNbHHogJrqmxXgOhwaNpH%2FPython_Script_Variable_Definitions.PNG?alt=media&#x26;token=f3600375-6250-488f-893d-363a8249fa4b" alt=""><figcaption></figcaption></figure>

Running the python script drops a deobfuscated version of the PowerShell script in the current working directory.

<figure><img src="https://3892796155-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZt3ly4wOcBID8vwUbybj%2Fuploads%2FpiWAAPBec9LFyuB4EEme%2FDeobfuscated_PowerShell_Script.PNG?alt=media&#x26;token=04ba9977-c436-4d71-a166-97dd42fdf3fc" alt=""><figcaption></figcaption></figure>

### Background information

<table><thead><tr><th width="139">Algorithm</th><th>Value</th></tr></thead><tbody><tr><td>MD5</td><td>a4163c297e14cd940d72f601f04cabbc</td></tr><tr><td>SHA-1</td><td>7be322a6b0571912ded2402cd3ac0b2312fb9c1c</td></tr><tr><td>SHA-256</td><td>c31703fe238a825c2f0edabb1cf130de04f78702c81608f0fa9cc2267e8b44a8</td></tr></tbody></table>

{% embed url="<https://bazaar.abuse.ch/sample/c31703fe238a825c2f0edabb1cf130de04f78702c81608f0fa9cc2267e8b44a8>" %}
Link to sample
{% endembed %}
