Introduction

Could an attacker with limited prior knowledge of an organisation compromise its internet-facing assets and establish a foothold inside its internal network?

That was the objective of one of our recent red team engagements. The target had requested a full zero-knowledge red team against their organisation with the goal of compromising them from the outside. We achieved it by exploiting a publicly known ViewState Machine Key in an internet facing ASP.NET application. Exploitation of that vulnerability isn’t impressive by itself, but our operators devised a novel solution to exploit this vulnerability and gain an internal foothold without triggering a detection or alert on the target which was protected by a leading EDR product.

This post traces the attack path from initial reconnaissance to internal access, covering:

  1. How our CYNTEL platform supported reconnaissance and helped our operators identify the vulnerable application
  2. How we developed an improved, custom exploit beyond the usual technique, establishing command-and-control (C2) within the customerโ€™s internal network, all while avoiding SOC / EDR detection
  3. How AI aided us in this process, saving days of research & development time
  4. Practical mitigations and a defensive checklist for ASP.NET applications that use ViewState

We will keep it brief, and will not disclose the entire detail of the final exploit chain due to potential abuse. At the time of publishing, the technique evades all of the leading security products that we tested against.

A ViewState To a Kill

The attack path followed something like this:

Throughout the article and in the interest of confidentiality, we will address the organisation as $TARGET.

OSINT & reconnaissance always begins with our CYNTEL platform. It provides us information & intelligence on a number of things, some of which are relevant to this:

  1. Domains, Subdomains, IP addresses, ASN blocks
  2. Web technologies
  3. Organisation data & credentials exposed on the DarkWeb
  4. Critical and High risk findings that would be useful to an adversary looking to compromise a target organisation

The screenshot below gives an idea of what that looks like to the operators within Cyndicate Labs.

Now with all the intelligence goodies on $TARGET, our operators would usually undertake further active probing and manual assessments against the identified assets, focusing on areas of interest should nothing immediately be actionable. However in this instance, whilst a number of ASPX servers were identified, one of them was vulnerable to a known MachineKey issue1.

When exploited, it allows for arbitrary code execution through the deserialisation of the VIEWSTATE parameter contents. An excellent writeup of this issue was documented back in 2019 by Soroush Dalili2.

Going into the “Known ASP.NET Machine Key” finding, we retrieved the known full key-pair, which consists of a decryption key and validation key, together labelled as the Machine Key. We need this two create our own ViewState objects.

This vulnerability is probably familiar to a lot of readers; however, if you are no stranger to operating in mature environments you may be aware exploiting this without triggering an investigation or outright being prevented and blocked can be somewhat of a challenge.

It was at this stage we needed to setup a replica environment of our $TARGET to test and develop our exploit.

A positive about our $TARGET was even though the application was protected by a login page, of which we did not have credentials for, the login request used ViewState. Therefore we later confirm we could trigger the remote code execution by sending an invalid login request, with a malicious ViewState payload, resulting in unauthenticated remote code execution as an IIS APPPOOL user with SeImpersonatePrivilege.

Setting Up The Test Environment

Using Amazon Web Services (AWS), we deployed as close to a replica environment that we could from our reconnaissance. We needed to ensure we did at least the following:

  • Deploy a Windows IIS Server configured to run an ASP.NET ViewState enabled web application
  • Develop a minimal ViewState compatible application to trigger the deserialisation
  • Set the MachineKey values to the same that $TARGET was using
  • Ensure the Windows Server is protected by a modern EDR in order to build an evasive attack

We chose to deploy a Windows 2025 Server running the latest IIS and installed the same EDR product used by our client.

The web.config we configured looked like this, configured with the same known machine key that we had identified on the target.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <appSettings>
    <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
  </appSettings>
  <system.web>
    <machineKey validationKey="[redacted]" decryptionKey="[redacted]" validation="HMACSHA256" decryption="AES" compatibilityMode="Framework20SP2" />
    <pages enableViewState="true" enableViewStateMac="true" viewStateEncryptionMode="Never" />
  </system.web>
</configuration>

The ASP web application was a simple login page, that simply used ViewState so we can trigger our exploit in the same way $TARGET would when a login request is received. When a HTTP request is received by the application, a w3wp.exe process is initiated on the server.

It was also not possible at the time to figure out if the remote architecture was 32-bit or 64-bit, so we developed a working exploit for both architectures.

Developing a New Stealthy Exploit Chain

The most significant part of this engagement, and the reason for the blog post, was the research and the exploit technique that came out of it. The ViewState weakness provided the initial route to .NET code execution via deserialisation, but our challenge was to turn that capability into an internal foothold which when exploited, avoided triggering an alert in $TARGET EDR.

A common exploitation approach would be to use ysoserial.net3 to generate a deserialisation payload that launches a command or executable. In an IIS-hosted application, this results in a child process spawned by the IIS worker process, w3wp.exe. That approach establishes code execution, but also introduces process creation activity that defenders can easily detect.

Another approach would be to write an ASPX web shell, which we have previously documented in RTD0x1 โ€“ Writeable Web Root โ†’ Domain Admin via Custom CLR Assemblies. However, it’s possible that writing an ASPX web shell would have been restricted due to the web root not being writeable by the executing user.

We needed a stealthier way to exploit this which didn’t result in child process execution under the IIS worker process. Our plan was to execute a position-independent code object (PICO) through the ViewState deserialisation attack, and avoid some of the usual footprints that come with a stock ysoserial.net payload. It was also cooler to go down the PICO loading approach.

Standard ysoserial.net Approach

First, we demo the common approach below on our test server, using ysoserial.net to exploit the ViewState and simply execute a calc.exe process. When we attempted this on our test machine, it was obviously detected and raised a high-risk alert in the EDR dashboard.

The steps explained above are as following:

  1. The CMD at the top left generated the standard ysoserial.net payload, which executes calc.exe
  2. The Burp repeater tab sends the malicious ViewState, which has been generated with the publicly disclosed Machine Key
  3. The IIS 2026 machine on the right deserialises the ViewState and executes the calc.exe process

The problem with this approach as mentioned, is that the modern EDR on the endpoint will raise a high-risk alert in the dashboard to the SOC, resulting in an inevitable detection & response in a mature organisation, so for us, we needed to develop some thing stealthier.

Our Approach

We wanted to achieve the following:

  • No process creation at all
  • Send a position-independent code object (PICO) within the ViewState, or fetch remotely via Web Request (we did both in the end)
  • Execute the PICO in the running process (w3wp.exe)
  • PICO must perform required OPSEC, such as Module Stomping, Unwindable Stacks, etc.

We wanted our approach to use existing .NET functionality in already loaded assemblies when running an ASP.NET application. Kind of like living-off-the-land. This was due to the detections that we had seen in the dashboard were actually around loading of suspicious assemblies as well as child-process creation.

For this, we needed to find out what assemblies would already be loaded within a standard ASP.NET worker process when performing ViewState deserialisation, and avoid loading of other potentially suspicious assemblies, such as what may be done when using ysoserial.net.

If we open w3wp.exe and inspect its assemblies, by default it should have the following loaded (This can vary depending on what your application and ViewState is actually doing):

  • mscorlib.dll – Core types such as String, Int32, arrays, ArrayList, Hashtable, reflection/type resolution, and BinaryFormatter on .NET Framework
  • System.Web.dll – ObjectStateFormatter, LosFormatter, Pair, Triplet, Unit, event-validation state, etc.
  • System.dll – Things such as TypeDescriptor, TypeConverter, HybridDictionary, depending on the serialised values
  • System.Drawing.dll – If ViewState contains optimised Color/KnownColor values

This is where LLMs helped speed up the weaponisation process. We wanted to utilise the functionality already within those assemblies, and minimise the loading of suspicious types or libraries that could be a detection point for the EDR.

After much debugging, iterating, and prompting, the final process looked something like:

  1. Construct a ViewState containing a BinaryFormatter TypeConfuseDelegate object graph.
  2. The delegate is redirected to System.Windows.Markup.XamlReader.Parse rather than process creation.
  3. The XAML is a ResourceDictionary containing ObjectDataProvider instances that invoke framework methods as the dictionary is materialised.
  4. The XAML reconstructs the PICO. The PICO is encrypted and sent inside ViewState.
  5. Derive the AES key from the effective machineKey.validationKey, and decrypts the PICO.
  6. Reflectively invoke VirtualAlloc(), obtains private RW memory, and copies the PICO there.
  7. Invoke the PICO and execute it on a CLR-created background thread.

The final result of this research and testing gave us a new novel approach to exploiting ViewState deserialisation and one which does not get detected by any of the EDR products we tested against.

To test our exploit we needed a basic PICO, so we developed one based on Crystal Palace4. If that worked, we would have tested our premise and then could move on to executing a Shellcode from a C2 of our choice to continue the operation.

The test PICO simply printed a Debug message “Hello from PICO inside process %lu” that could be observed with DbgView.exe in our test machine. Observing the message would confirm our code object executed successfully.

Executing our exploit script proved the premise, the encrypted PICO bin file sent in the ViewState executed successfully, and went undetected on the test machine with the EDR configured with full protection.

Then observe the same printed Debug message, no child process (trust us!), originating from the w3wp.exe process PID 2192.

It wouldn’t be fair to not show the .NET loaded assemblies in the w3wp.exe process after successful exploitation using this documented approach:

Above are the highlighted loaded .NET assemblies that were loaded as a side-effect of this particular exploit, and detection could be built specifically on those, but there are also stealthier alternatives we developed to avoid the loading of WindowsBase and Presentation* libraries.

Whilst the test PICO used above did not do anything behavioural that would trigger detection anyway, it proves the allocating of memory, and executing the object code did go undetected. When executing a different C2 Shellcode in the future, you would still need to implement all of the security OPSEC required to evade EDR as your capability is being executed such as unwindable stacks, no floating threads etc.

Closing Remarks

We chose to go with loading of a native PICO instead of a managed assembly in order to progress the engagement faster, and obtain a callback with our C2 platform, but there are many other options available here. One of which was recently documented by Google where a threat actor deployed an in-memory Web Shell (BLUEBEAM / Godzilla)5.

Similar to the idea above, we are currently developing is a managed in-memory C2 which operates on client-initiated ViewState requests and responses. This would avoid the need to allocate private memory regions and load unmanaged code. We may leave that for another blog post.


ASP.NET ViewState Security Recommendations

The root-cause of this finding which ultimately leads to a successful compromise is the use of a publicly known ASP.NET Validation and Decryption key pair. Even still in 2026 we have identified this issue on two separate Red Team engagements which have led to full remote compromise. Below are some security recommendations around ASP.NET ViewState, and Machine Key handling / generation.

ViewState Security

  • Use a supported, fully patched .NET Framework runtime. Set compatibilityMode="Framework45" to use the newer ASP.NET cryptographic implementation
  • Always enable MAC validation and encryption. Set enableViewStateMac="true" and viewStateEncryptionMode="Always". Keep event validation enabled and review page directives and code for overrides
  • Use modern algorithms. Configure HMACSHA256 for validation and AES for encryption. Avoid legacy options such as MD5, SHA1, DES, and 3DES for new configurations
  • An example web.config may look like the following:
<configuration>
  <system.web>
    <machineKey
      compatibilityMode="Framework45"
      validation="HMACSHA256"
      decryption="AES"
      validationKey="REPLACE_WITH_GENERATED_VALIDATION_KEY"
      decryptionKey="REPLACE_WITH_GENERATED_DECRYPTION_KEY" />

    <pages
      enableViewStateMac="true"
      viewStateEncryptionMode="Always"
      enableEventValidation="true" />
  </system.web>
</configuration>
  • Bind ViewState to the session. Set ViewStateUserKey during Page_Init or OnInit, using an unpredictable value unique to the session. Apply this consistently through a shared base page. For applications with session state enabled
protected override void OnInit(EventArgs e)
{
    ViewStateUserKey = Session.SessionID;
    base.OnInit(e);
}

This helps prevent another sessionโ€™s ViewState from being reused in a CSRF attack.

Machine Key Security

  • Ensure the Decryption and Validation keys are rotated in Microsoft IIS. Generate fresh keys using IIS Manager โ†’ application โ†’ Machine Key โ†’ Generate Keys โ†’ Apply, then ensure the resulting configuration retains the settings
  • Check that your Machine Keys are not in already public sources, such as those defined in Blacklist3r6. Ensure to check all web.config also for <machineKey> declarations.
<system.web>
    <machineKey .../>
</system.web>

When developers are deploying ASP.NET applications, ensure that Machine Keys are not copied from public sources such as Blog Posts, GitHub, or any other online example sources. This is often the case in how this vulnerability arises, when keys are copied from example web.config files

Detections for Blue Team

  • Ensure parent-child process relationships involving w3wp.exe are closely monitored in your environment. It is probably malicious if your IIS worker process is spawning cmd.exe or anything else
  • Ascertain a baseline within your environment of what .NET assemblies are loaded in your w3wp.exe processes over a period of time. Some attack paths, like the one shown in the blog, do load other assemblies, that may be an anomalous signal within your environment
  • Monitor the Windows Application log for Event ID 1316 from ASP.NET 4.0.30319.0, or the equivalent source for the installed ASP.NET version. Look for event code 4009 with either of these messages:
    • Integrity check failed: Viewstate verification failed. Reason: The viewstate supplied failed integrity check. This may indicate an attack attempt using an incorrect key
    • Invalid ViewState: Viewstate verification failed. Reason: Viewstate was invalid. This indicates that the integrity check passed and deserialisation was attempted. The payload may have executed, but this event alone does not confirm successful execution
  • Enable Microsoft-Windows-DotNETRuntime loader events with LoaderKeyword 0x8, informational level
    • Event 154 is AssemblyLoad_V1
    • Event 152 is ModuleLoad_V2
    • Microsoft documents the fields and event IDs7
  • If using SysMon:
    • Event 3 and Event 22 for outbound network/DNS from w3wp.exe
    • Event 7 for WPF DLL/native-image loads in w3wp.exe
    • SysMon Event 7 and Event 3 are disabled by default and should be narrowly filtered because of volume8

References

  1. https://www.microsoft.com/en-us/security/blog/2025/02/06/code-injection-attacks-using-publicly-disclosed-asp-net-machine-keys/ โ†ฉ๏ธŽ
  2. https://soroush.me/blog/exploiting-deserialisation-in-asp-net-via-viewstate โ†ฉ๏ธŽ
  3. https://github.com/pwntester/ysoserial.net โ†ฉ๏ธŽ
  4. https://tradecraftgarden.org/crystalpalace.html โ†ฉ๏ธŽ
  5. https://cloud.google.com/blog/topics/threat-intelligence/knowledgedeliver-viewstate-deserialization-vulnerability โ†ฉ๏ธŽ
  6. https://github.com/NotSoSecure/Blacklist3r/blob/master/MachineKey/AspDotNetWrapper/AspDotNetWrapper/Resource/MachineKeys.txt โ†ฉ๏ธŽ
  7. https://learn.microsoft.com/en-us/dotnet/framework/performance/loader-etw-events โ†ฉ๏ธŽ
  8. https://learn.microsoft.com/en-us/sysinternals/downloads/sysmon#event-id-7-image-loaded โ†ฉ๏ธŽ