Introducing Aladdin - Nettitude Labs

Introducing Aladdin, a new tool and technique for red teamers to bypass misconfigured Windows Defender Application Control (WDAC) and AppLocker. Aladdin exploits a deserialisation issue over .NET remoting in order to execute code inside , bypassing a 2019 patch released by Microsoft in .NET Framework version 4.8.addinprocess.exe

Download Aladdin

Introducing Aladdin - Nettitude Labs GitHub:

A travel to the magic land of .NET deserialization

Once upon a time, in the mysterious land of cybersecurity, there was a red teamer named Aladdin. Aladdin was frustrated, since most of the payloads that he was using at the time were not able to run on a system with application control lists enabled, and those powerful EDR creatures that the evil Blue Lord had created were killing all his beacons.

One day, while out on a mission, Aladdin stumbled upon a strange magic lantern. As he picked it up, a genie appeared before him and granted him three wishes. Without hesitation, Aladdin thought of his first wish.

“I wish I could find a payload that would be able to execute on a WDAC enabled Windows 10 system”.

The genie granted his wish and disappeared, leaving Aladdin with the magic lantern at hand. Excited to test out his new power, Aladdin set to research existing techniques for bypassing WDAC / AppLocker. While consulting the majestic oracle named Google, he came across an article from the magician James Forshaw named “DG on Windows 10 S: Executing Arbitrary Code”. The article was written in 2017 and went into great detail about the Microsoft .NET process , residing in every Windows workstation (with Microsoft .NET installed). Add-ins are effectively a form of plugin model that the .NET Framework provides, enabling developers to create plugins for their applications. The model achieves this by constructing a communication pipeline between the host and the add-in.addinprocess.exe

As discovered by the magician, the process once launched would use the method ChannelServices.RegisterChannel to register a .NET remoting channel, a topic he was quite familiar with exploiting. The topic was also covered by other magicians more recently. Besides creating a .NET remoting channel, the magician identified that the process would use the BinaryFormatter Class to deserialize input in binary format, while setting the TypeFilterLevel to Full.

Microsoft clearly state that BinaryFormatter cannot be made secure.

Introducing Aladdin - Nettitude Labs

According to Microsoft, “.NET Framework remoting provides two levels of automatic deserialization, Low and Full. The Full deserialization level supports automatic deserialization of all types that remoting supports in all situations”. When decompiled, uses .addinprocess.exeTypeFilterLevel.Full

Introducing Aladdin - Nettitude Labs

This effectively meant that any data passed to the .NET Remoting channel would be deserialized, without worrying about any security controls that the deserialization level for .NET Framework remoting would enforce.Low

Aladdin, following the magician’s steps, identified that in order to launch the , the argument of /guid:[GUID] and the argument of /pid:[existing PID] should be provided.addinprocess.exe

The /guid argument was user controlled and was being used as the IPC channel name. The /pid argument referred to the process identifier of an already running process, that  would wait until exit.addinprocess.exe

Introducing Aladdin - Nettitude Labs

After reading through the article multiple times, Aladdin set out to create a new WDAC enabled Windows 10 system in order to test the original proof of concept. Useful resources for creating such a policy were that of WDACTools from Matt Graeber and Building a windows defender application control lab from FortyNorth.

The POC effectively was creating a correctly formatted set of bytes, based on the .NET remoting protocol, followed by the serialized provided assembly and the IPC endpoint

Introducing Aladdin - Nettitude Labs

The output of the POC was a binary array being placed in a template JScript SCT payload.

Introducing Aladdin - Nettitude Labs

Aladdin went ahead and tried out the generated SCT payload, but to no avail.

Introducing Aladdin - Nettitude Labs

Unfulfilled, he sought further consultation from the great oracle Google, which revealed that the giant Microsoft had already put out some magic defences that stopped this powerful attack.

Introducing Aladdin - Nettitude Labs

As he began poking and prodding at the patch, the magic lantern glowed brightly, reminding him that he had two additional wishes.

Introducing Aladdin - Nettitude Labs

Aladdin decided to use his second wish.

“I wish I could find a bypass for the patch applied by the great giant”

The genie again granted his wish and disappeared, leaving Aladdin with the magic lantern at hand and a blog post from the mage Nick Landers – Re-Animating ActivitySurrogateSelector.

Reading the article initially, Aladdin was feeling that he was reading some arcane powerful knowledge that he could not understand, but with every additional read, it became increasingly evident that the patch, besides adding a type check in the GetObjectData function looking for object types of or , also introduced a new function named DisableActivitySurrogateSelectorTypeCheck.ActivityBindDependencyObject

Introducing Aladdin - Nettitude Labs

The function was effectively responsible for checking a flag via ConfigurationManager.AppSettings, which in turn was a property that allowed the programmatic reading / writing of the of an application.AppSettingsSection

One of the great things that the mage Nick Landers discovered was the following C# code that disabled the type check:


And a new commit was made to the powerful project YSoSerial.Net.

Aladdin immediately started thinking on how to incorporate this bypass into the original POC, and after a few moments / hours / days (time is relative) of tinkering, managed to:

  1. Create a gadget that disables the using the project ().ActivitySurrogateSelectorpayload1.bin
  2. Modify the original POC of James Forshaw by first setting to true.DisableActivitySurrogateSelectorTypeCheck
  3. Generate a simple payload that would pop a message box using the POC of James Forshaw ().payload2.bin
  4. Spawn Addinprocess in his test VM with the correct arguments. Once spawned, the created a new named pipe under , where .NET remoting was listening.addinprocess.exe\\.\pipe\32a91b0f-30cd-4c75-be79-ccbd6345de11
  5. Send the first binary payload to the newly created pipe from cmd, to disable ActivitySurrogateSelector (type payload1.bin > \\.\pipe\32a91b0f-30cd-4c75-be79-ccbd6345de11)
  6. Send the second binary payload to the named pipe, to trigger the deserialization code execution ().type payload2.bin > \\.\pipe\32a91b0f-30cd-4c75-be79-ccbd6345de11
  7. Stare at his screen.
Introducing Aladdin - Nettitude Labs

The genie had granted his wish, and he was able to execute an arbitrary C# assembly via deserialization inside the Microsoft signed process .addinprocess.exe

The original POC also provided an SCT template that executes the attack via JScript, using . This object is useful since it allows writing to a named pipe although the scriptlet hosting environment is severely limited to which COM objects can be created, in a WDAC enabled system.Scripting.FileSystemObject

Without losing any time, Aladdin proceeded to create a tool that given a C# assembly DLL, would generate a serialized payload incorporating the bypass and the .NET Remoting bytes needed to communicate over the named pipe. Using the provided SCT template as a base, Aladdin also created templates for HTA / VBS / CHM / VBA allowing the execution of the payload from these old trusty vectors.BinaryFormatter

Introducing Aladdin - Nettitude Labs

Happy that everything was working, and his payloads were not being caught, Aladdin became immediately worried that this technique could be abused for evil purposes and as such he went ahead and researched what could be done in order to prevent it.

The big giant Microsoft goes into great lengths detailing the risks of deserialization vulnerabilities and includes advice on blocking the executable via their recommended block rules. These rules could also be applied via a supplemental WDAC policy or via a third-party application control software.BinaryFormatteraddinprocess.exe

If prevention controls cannot be applied, then process creation visibility could help detecting the execution of process (which in most environments should not be that common).

Introducing Aladdin - Nettitude Labs

While finalizing the code, Aladdin saw the magic lantern glowing again, reminding him that he had a third and final wish. Without much hesitation Aladdin decided to use his last wish:

“I wish I could write an article about this tool”

Download Aladdin

Introducing Aladdin - Nettitude Labs GitHub:


原文始发于nettitude:Introducing Aladdin - Nettitude Labs

版权声明:admin 发表于 2023年3月2日 上午8:58。
转载请注明:Introducing Aladdin - Nettitude Labs | CTF导航