On a recent CTF machine, I had to exploit the Windows 11 ThemeBleed vulnerability (https://github.com/gabe-k/themebleed) for which at that time only one PoC existed that only ran under Windows. This was a pain for me because I hadn’t installed the required VPN on Windows.
And as I’m interested in learning new stuff, I decided to dive into this. It can’t be too hard, right?
TL;DR
https://github.com/Jnnshschl/CVE-2023-38146/
|
|
How it works
I started off by thinking about the Impacket-SMBServer. I use it quite frequently in CTF’s, and it runs under Linux. It seems like the right choice! The first step was to get an idea of how this SMBServer works.
https://github.com/fortra/impacket/blob/master/examples/smbserver.py was my starting point. I quickly decided to build a subclass of SimpleSMBServer
as it contains everything needed to get a server up and running.
The original PoC shows us how to do it. When the ShareAccess
type is 5
we need to send the malicious DLL file.
|
|
To achieve this using the Impacket-SMBServer class, I had to dig through its command handlers located in this file: https://github.com/fortra/impacket/blob/master/impacket/smbserver.py#L4098
|
|
Which led me to this function that gets called every time a file is accessed via SMB. It opens the file too, which is great, as this is the point we need to intercept the server and feed the malicious DLL file to our Windows client.
|
|
I simply copied the whole function into my custom SMBServer
class. I still needed to replace the original handler in the __smb2Commands
. In Python, class properties starting with “__” cannot be modified directly. Instead, you have to access the variable in a really weird way:
|
|
self.tbSmb2Create
was my custom handler function, which, in its current state, is only a pasted version of the Impacket function. I started by inspecting the smb2Create
with various debug logs and tried to discover a way to get the ShareAccess
type of the client. It turned out to be as simple as writing:
|
|
-> In case you wonder what ShareAccess is: https://github.com/TalAloni/SMBLibrary/blob/master/SMBLibrary/NTFileStore/Enums/NtCreateFile/ShareAccess.cs
So the only thing left to do was replace the requested file with the malicious one. The point at which the server built the filename sounded very promising to me:
|
|
I came up with the following code, placed right beneath the filename building:
|
|
And yes, it worked; that was easy!