Part 2: From Byovdll To Arbitrary Code Execution In Lsass
The report details a use-after-free vulnerability in the KeyIso service's RPC procedure SrvCryptFreeKey, where a race condition allows an attacker to control a freed Key object and redirect execution to an arbitrary address. The author explores exploitation strategies, including coercing LSASS to open a handle to the attacker's process and using NdrServerCallAll to call DuplicateHandle, but ultimately fails to duplicate a protected process handle into an unprotected process due to access restrictions.
blog.scrt.ch
Published on blog.scrt.ch
In the previous part, I showed how a technique called “Bring Your Own Vulnerable DLL” (BYOVDLL) could be used to reintroduce known vulnerabilities in LSASS, even when it’s protected. In this second part, I’m going to discuss the strategies I considered and explored to improve my proof-of-concept, and hopefully achieve…
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely a race condition in the KeyIso service's SrvCryptFreeKey RPC procedure where a Key object is freed and then reused without proper synchronization, allowing an attacker to control the freed memory.
Impact
The exploit could allow arbitrary code execution in LSASS, but the final step of duplicating a handle to a non-protected process was blocked by access restrictions, preventing full compromise.
What the attacker needed
Ability to trigger the vulnerable RPC procedure; win the race condition; LSASS must be running
How it was found
- Configure registry keys for Image File Execution Options and SilentProcessExit for LSASS.
- Replace the address of OutputDebugStringW with RtlReportSilentProcessExit and set the first parameter to (HANDLE)-1.
- Invoke SspirConnectRpc via RPC to coerce LSASS to open a handle to the client process.
- Use NdrServerCallAll with crafted RPC_MESSAGE structures to call DuplicateHandle within LSASS.
- Attempt to duplicate a handle from LSASS to the attacker's process, which fails with access denied.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
This report describes a use-after-free bug, which is like a hotel room that is checked out but the key still works. An attacker can quickly slip into the freed memory space with their own data before the program uses it again, potentially taking control of the program. The author tries to exploit this in a protected Windows process but faces several security barriers.
What is Race condition?
Parallel requests reach a state the code assumed could not happen: a coupon used twice, a limit overrun, a check skipped.