By Waseem Akram on 10/15/2024
Today we’re gonna see an effective technique to mantain access in Windows systems during red team operations just by modifying a registry key...
Today we’re gonna see an effective technique to mantain access in Windows systems during red team operations just by modifying a registry key which interacts with the Recycle Bin. I don’t know if any APT group uses this technique but I read about it in a vxunderground paper (see here) and I thought it may be interesting to try in Golang so let’s see how it works.
In Windows there are some folders which have have uniques CLSID values like the ones for the “Recycle Bin” {645ff040-5081-101b-9f08-00aa002f954e} or the “My Documents” {450d8fba-ad25-11d0-98a8-0800361b1103}
All of this may sound familiar to you if you’ve ever tried the fodhelper.exe UAC bypass in which the registry HKCU is modified to execute commands as administrator without any confirmation.
First of all we must import the necessary packages. In this case we’ll use the official Golang package to interact with registry keys
This code is written in the Go programming language. Let's break it down step by step.
Every Go program starts with a package declaration. The main
package is used for executable programs, and it tells the Go compiler that this is an executable program rather than a shared library.
The import
keyword is used to include external packages in our program. In this case, we are importing three packages: fmt
, log
, and golang.org/x/sys/windows/registry
.
fmt
package provides functions for formatting and printing output.log
package provides functions for logging messages.golang.org/x/sys/windows/registry
package provides functions for interacting with the Windows registry.We have to open the CLSID registry key
This section of code attempts to open a specific key in the Windows registry.
registry.OpenKey
is a function that takes three arguments:
registry.LOCAL_MACHINE
: This specifies the part of the registry we are accessing (the local machine's registry)."SOFTWARE\\Classes\\CLSID\\{645FF040-5081-101B-9F08-00AA002F954E}\\shell"
: This is the path to the specific registry key we want to open. It is formatted as a string and uses double backslashes (\\
) to escape the backslash character.registry.WRITE
: This specifies the permissions we want to have on the key. In this case, we want to write to it.After attempting to open the registry key, we check if there was an error
defer
is a keyword that schedules the Close
method to be called when the surrounding function (not shown here) exits.Then we create the new registry where our malicious commands will be
This section of code creates a new registry key.
registry.CreateKey
is a function that takes three arguments:
bin_key
: This is the parent key we opened earlier. The new key will be created under this key."open\\command"
: This is the name of the new registry subkey we want to create. It is formatted as a string and uses double backslashes (\) to escape the backslash character.registry.ALL_ACCESS
: This specifies the permissions for the new key. In this case, it grants all possible access rights.And finally we set the value, in our case it’s a simple notepad but you could be creative to combine it with other things like UAC bypass and more
Let’s add more output and the final code should be something like this:
Now we compile our payload and transfer it to our Windows testing machine
I haven’t read anywhere if this operation can be done without administrator privileges but testing in my Windows it always returned “Access denied”
Be careful with your payload because testing with cmd.exe and notepad, I created an infinite loop and I had to restart my PC
As you can see after clicking the recycle bin icon a notepad.exe appears
Now if we search the parent process id (PPID) of the notepad.exe we see that it’s executed under explorer.exe process
To revert our modifications you can simply execute this powershell command Remove-Item -Path "HKLM:\SOFTWARE\Classes\CLSID\{645FF040-5081-101B-9F08-00AA002F954E}\shell\open" -Recurse -Force
and it should work for you
This persistence technique can be useful for red teamers as it’s stealthy and everyone use the recycle bin to delete files so the payload would be executed whenever a user access to it. But the registry key can be monitored to prevent this so blue teamers should have this technique in mind
This course is designed to be hands-on and beginner-friendly, so even if you’re new to the world of network security, you’ll be able to follow along with ease. By the end, you'll have a
Read MoreToday we’re going to see how real malware protect themselves from being analyzed using a technique called Api Hashing. First of all we should...
Read MoreToday we’ll dump LSASS.EXE process memory to obtain credentials and we also will be using some evasion techniques. During red team...
Read MoreToday we’ll learn an advanced shellcode injection technique used by Lazarus group which uses UuidFromStringA API call. In this technique, the malware..
Read MoreInstahack is a security tool officially designed to test the password strength of Instagram accounts using termux and kali with a brute force attack...
Read MoreToday we’re gonna see a simple malware development technique, Shellcode injection via CreateRemoteThread in Golang...
Read More