You are browsing the archive for EDR.

Trivial Anti-BlueTeam trick for 32-bit systems

December 6, 2018 in Anti-*, Compromise Detection, EDR, Incident Response

I love evasion tricks of any sort. Sometimes they can be very elaborate, and sometimes… incredibly trivial, almost stupid really. Such is the trick I am describing below. It works on 32-bit Windows only, and that’s because it relies on a folder structure that is (exclusively) present on 64-bit systems.

If we look at logs from various process monitoring tools we can notice that they omit a very important info. They don’t tell us what is the architecture of the logging system. Unless it is somehow self-evident (e.g. ‘bitness’ is a part of a host naming convention) there is no way to tell whether the process is executed on a 32- or 64- box.

These 3 folders are present on 64-bit systems only:

  • c:\windows\syswow64\
  • c:\windows\sysnative\
  • c:\Program Files (x86)\

Nothing (apart from access rights) stops us from re-creating them on a 32-bit system.

Imagine seeing the following paths in the logs indicating that calc.exe or iexplore.exe was launched on a system:

  • c:\windows\syswow64\calc.exe – from a 64-bit system
  • c:\windows\syswow64\calc.exe – from a 32-bit system
  • c:\windows\sysnative\calc.exe – from a 64-bit system
  • c:\windows\sysnative\calc.exe – from a 32-bit system
  • c:\Program Files (x86)\Internet Explorer\iexplore.exe – from a 64-bit system
  • c:\Program Files (x86)\Internet Explorer\iexplore.exe – from a 32-bit system

For all logs from 32-bit systems it’s obvious that they are fake.
How can you tell the difference though if your logs don’t tell you the architecture of the system where they come from?

This opens up a lot of opportunities for an impersonation.

Threat hunting efforts that rely on full paths for analysis purposes (whitelisting, LFO, etc.) could be easily fooled to accidentally exclude, or include bad processes that are executed from locations that pretend to be ’64-bit legitimate’.
And since most of the orgs are mixed 32/64 environments, the logs from all systems will be inevitably clustered together, and detection rules will be applied to them as a whole.

Admittedly, a malicious svchost.exe executed from c:\windows\syswow64\svchost.exe is definitely less suspicious than one starting from %APPDATA%:

Now, could this be a bad process?

  • c:\Program Files (x86)\Windows Defender\MpCmdRun.exe

Propagate – yet another follow-up (hypothetical clipboard execution version)

November 19, 2018 in Anti-*, Code Injection, Compromise Detection, EDR, Incident Response, Malware Analysis, Sandboxing

I’ve been thinking of tricking the Windows Clipboard to execute code inside other processes for a while now. It perhaps sounds crazy, but I thought there may be _some_ way to do it. The below is just a pure speculation based on some cursory analysis of 2 popular Windows APIs.

So dunno if it works. Still, I will just jot it down here, and if anyone has time and mood to test it in practice — feel free to do so, and share the results.

Accessing clipboard via Windows API is very straightforward – refer to the MSDN for details. The only thing that matters is that data using typical data formats can be placed in a clipboard via SetClipboardData API. We could potentially use it to inject data to any process that deals with the clipboard, and somehow make it execute before the user changes the clipboard content? Possibly, who knows… Since I couldn’t come up with any trick to make it happen I looked at other clipboard functions. My attention was drawn to the concept of sharing non-standard clipboard data formats between processes. How does the clipboard works with these? The SetClipboardData is not enough – we need to use the OleSetClipboard API.

As far as I can tell, the implementation details of this API are not covered anywhere. At least I couldn’t find it. A very good high-level description of the OLE Clipboard can be found in the excerpts from the ‘Programming Windows with MFC’ book by Jeff Prosise that was published in 1999 (I don’t include links as the sites look dodgy). The Windows documentation simply says that the function ‘places a pointer to a specific data object onto the clipboard. This makes the data object accessible to the OleGetClipboard function.’.

This is a very curious statement. How can you place a pointer onto the clipboard?

I immediately started looking at these two APIs. It turns out that lots of applications use OleGetClipboard API to access the clipboard. If we use the OleSetClipboard and make it point to our IDataObject interface, some application will sooner or later retrieve the pointer in their own process space. It will then start calling the IDataObject methods to access the OLE Clipboard. Due to internal working of COM the interface pointer returned inside the remote process is not something we can directly control (as far as I can tell) and we can’t get a code execution this way.

Are there any other options?

I mentioned the internal working of OleSetClipboard and OleGetClipboard that are a bit of a mystery. And they are actually far more complex that I imagined. The simple bit is that Ole32 library that implements these functions registers a window class named ‘CLIPBRDWNDCLASS’. And surprise, surprise, when we run OleSetClipboard API the IDataObject data pointer we pass to this API… will be stored as a window property of this OLE clipboard window!

Sounds familiar?

Yup. You may recall the Propagate technique I described last year – it relies on a fact that certain windows properties can be modified by external programs. That is, if we can find the CLIPBRDWNDCLASS window, we can probably modify some of its clipboard-related properties?

After checking the code of the OleSetClipboard API we can quickly discover a number of interesting windows properties:

  • OLEClipPackgeOwner
  • OleClipProcessOwner
  • ClipboardDataObjectInterface
  • ClipboardRootDataObjectInterface
  • ClipboardDataObjectInterfaceMTA

If it has an ‘interface’ in the name, it is obviously _very_ interesting.

The ‘ClipboardDataObjectInterface’ property is where the IDataObject pointer is stored. What about the other two ‘interface’ properties? The ‘MTA’ in the name of one of them suggests ‘Multi Thread Apartment’, the ‘root’ one stores the source IDataObject – both seem to be used internally by CClipboardBroker::SetClipboard method only.

After browsing through the references to these properties I noticed that in some cases the pointer retrieved from the window is not being marshalled. As far as I can tell, such are the cases when:

  • the pointer retrieved via the GetProp API is used inside the same process that owns the CLIPBRDWNDCLASS window
  • when OleFlushClipboard is called
  • same thing happens when the OLE clipboard is destroyed. e.g. in reaction to CLIPBRDWNDCLASS window receiving a WM_DESTROYCLIPBOARD message.

I guess this part of code was written with an assumption that the message will never be received from an external application(?). The important bit is that during this clipboard destruction process, and before the RemoveProp API is called for all these ‘interface’ clipboard properties, the Release method of the IDataObject retrieved from the ClipboardDataObjectInterface (and other interfaces) will be called as well.

If the hypothesis is right,

  • changing the¬†CLIPBRDWNDCLASS window property ‘ClipboardDataObjectInterface’ to point to a controlled memory region storing pointer to a dummy IDataObject object pointing in return to a malicious code (with the callback registered under Release method); other ‘interface’ properties can be used too
  • then sending a WM_DESTROYCLIPBOARD message to the CLIPBRDWNDCLASS window

should end up with a code execution…