A filename is the only part of a file most people ever read. This file plants a benign canary in a script named quarterly-report.pdf.sh, watches the listing read it as a document while the kernel executes the bytes as a script, then the defense asks the bytes with file, hunts the mismatch with one command, captures evidence before closing the execution path, and installs the sweep that flags the next double extension.
MITRE ATT&CK T1036.007: adversaries deceive by giving a hostile file a double extension, so the name claims one type while the bytes are another. This file names a benign shell script quarterly-report.pdf.sh, watches a directory listing read it as a document, watches file(1) read the bytes and say script, and runs the script to prove the kernel executes the bytes, not the name. Then the defense: ask the bytes, hunt the name/bytes mismatch across the tree with one command, capture evidence before stripping the execute bit, and install the scheduled sweep that flags the next plant. Two actors: the attacker, who owns the deceptive name and the execution; and the defender, who owns the file reads, the mismatch hunt, the evidence-first mitigation, and the sweep in the blue phase.
Why this technique. People read names left to right and stop at the first familiar extension. The kernel does not read names at all: it resolves execution from the file's bytes, starting with the shebang line. A name that claims PDF on a file whose bytes say shell script deceives exactly the reader who never checks the bytes, which is most readers, most of the time. The hiding place is not a tool bug; it is the gap between human reading order and kernel execution order.
Why not the honest name. The obvious alternative is notes.sh: same 37 bytes, one truthful extension. Break it on the concrete input: file says POSIX shell script, cat shows the script body, the name says script. Name, bytes, and content all agree, so there is no divergence for a deception to live in. The recording shows the measurement: the honest name leaves anyone reading the listing fully informed before anything runs. The double extension fixes exactly that failure: it makes the name disagree with the bytes, and the disagreement is what the eye skips.
The mechanism, in one line. A file extension is the suffix after the last dot, a naming convention, not a property of the file: nothing in the bytes changes when the name changes. Magic bytes are the file's first bytes, which file(1) reads to identify the real type. The shebang is the #! first line, which tells the kernel which interpreter runs the file. The double extension exploits the reader, not the kernel: the eye lands on "quarterly-report.pdf" and stops, while the kernel reads #!/bin/sh and executes. Terms earned, no borrowing.
The concrete case, before the abstraction. In /tmp/gh022: quarterly-report.pdf.sh, 37 bytes. ls -1 prints two names, and the attacker's name reads as a PDF report. file quarterly-report.pdf.sh: POSIX shell script, ASCII text executable. ./quarterly-report.pdf.sh prints GHOSTLIGHT-CANARY-022. Named as a document, ran as code. That gap, between what the name claims and what the bytes are, is the whole technique.
Scope. T1036 covers masquerading broadly: matching legitimate names or locations, right-to-left override, fake icons, double extensions, faked magic bytes. This file works the double-extension case end to end: the plant, the listing deception, the bytes check, the mismatch hunt, the evidence-first mitigation, and the scheduled sweep. The canary is a benign token: it proves execution and touches nothing else. The lab runs in a disposable namespace under /tmp because the blue phase plants, strips, and sweeps for real.
Ubuntu 24.04.5 LTS, x86-64, in a disposable namespace used only for this lab. Runs as root: the lab plants its own files, and every blue-phase read targets the live lab. Everything the lab touches lives inside /tmp/gh022, so cleanup is a single rm. file(1) ships in the file package; everything else is coreutils.
One disposable directory, built from scratch. The attacker's file and the honest control are written in full below, each line glossed after it. rm -rf /tmp/gh022 starts clean; mkdir -p and cd set up the lab. printf writes each script: the shebang line plus echo GHOSTLIGHT-CANARY-022; \n is printf's newline escape, which is why each file lands as two lines. chmod +x makes both executable; ls -l shows the lab.
#!/bin/sh echo GHOSTLIGHT-CANARY-022
#!/bin/sh: the shebang, the #! first line that tells the kernel to run this file with /bin/sh. echo GHOSTLIGHT-CANARY-022: prints the benign canary, a token that proves the file executed and does nothing else. Thirty-seven bytes, identical in both files: the only difference between the attacker's file and the control is the name.
The attacker names a script like a document, watches the listing agree, and runs the bytes.
rm -rf /tmp/gh022 starts clean; mkdir -p and cd set up the lab directory. printf writes both scripts, the shebang plus the canary echo; chmod +x makes both executable; ls -l shows the lab: two 37-byte scripts. Everything the page shows is built here.
$ rm -rf /tmp/gh022; mkdir -p /tmp/gh022; cd /tmp/gh022 printf '#!/bin/sh\necho GHOSTLIGHT-CANARY-022\n' > quarterly-report.pdf.sh printf '#!/bin/sh\necho GHOSTLIGHT-CANARY-022\n' > notes.sh chmod +x quarterly-report.pdf.sh notes.sh ls -l total 8 -rwxrwx--- 1 root root 37 Sep 25 12:34 notes.sh -rwxrwx--- 1 root root 37 Sep 25 12:34 quarterly-report.pdf.sh
file notes.sh: POSIX shell script, ASCII text executable. cat notes.sh: the shebang and the echo, the script body in plain sight. The name says script, the bytes say script, the content is a script. There is no name/bytes divergence here, so the stealth property is absent: anyone reading the listing sees a script before running it.
$ file notes.sh cat notes.sh notes.sh: POSIX shell script, ASCII text executable #!/bin/sh echo GHOSTLIGHT-CANARY-022
ls -1: two names, one column. Read left to right, the eye lands on "quarterly-report.pdf" and stops: the trailing ".sh" is three characters at the end of a twenty-three-character name. Nothing in the listing marks the file as code.
$ ls -1 notes.sh quarterly-report.pdf.sh
file quarterly-report.pdf.sh: POSIX shell script, ASCII text executable. The name claims PDF; the bytes say script. This is the divergence the honest name lacked.
$ file quarterly-report.pdf.sh quarterly-report.pdf.sh: POSIX shell script, ASCII text executable
./quarterly-report.pdf.sh prints GHOSTLIGHT-CANARY-022. The kernel read the shebang and ran the script. It ran as code while dressed as a document.
$ ./quarterly-report.pdf.sh GHOSTLIGHT-CANARY-022
One echo line, the attacker's summary: ran as code, named as document. The deception lived entirely in the name; no byte was hidden, no privilege was touched.
$ echo 'stealth confirmed: ran as code, named as document' stealth confirmed: ran as code, named as document
The script ran as code under a document's name. ls read the name left to right and stopped at .pdf; file read the bytes and said shell script; the kernel executed the shebang. The deception lived entirely in the name: no byte was hidden, no privilege was touched.
The defender does not trust the name. The defender reads the bytes, hunts the mismatch across the tree, captures evidence before closing the execution path, and installs the sweep that flags the next plant.
Here is the trap: reading the listing, seeing a PDF report, and moving on. That is trusting the name the attacker chose. The detection starts by asking the bytes, which the attacker did not choose.
cd /tmp/gh022 && ls -l: a clean lab, two 37-byte scripts, nothing hidden. Stopping here is the attacker's win: the listing was never checking the bytes, so a clean listing proves nothing.
$ cd /tmp/gh022 && ls -l total 8 -rwxrwx--- 1 root root 37 Sep 25 12:34 notes.sh -rwxrwx--- 1 root root 37 Sep 25 12:34 quarterly-report.pdf.sh
file quarterly-report.pdf.sh reveals the shell script behind the PDF name. The name is a claim; the bytes are evidence. No prior knowledge of the trick is needed: file reads the bytes, not the name.
$ file quarterly-report.pdf.sh quarterly-report.pdf.sh: POSIX shell script, ASCII text executable
ls -1 | grep -E '\..*\.' flags every name carrying two or more dots and passes over notes.sh, the single-dot control. One command, the whole directory. The tell, concrete: good is a name with one truthful extension; bad is a name whose extensions disagree with the bytes.
$ ls -1 | grep -E '\..*\.' quarterly-report.pdf.sh
command -v auditctl answers /usr/sbin/auditctl: the audit tools are present in this lab. The rule for a real host is stated with its dependency, not demonstrated: auditctl -a always,exit -F arch=b64 -S execve -k execs records what actually executed regardless of the name, but it needs the audit subsystem enabled and its rules loaded. Where it runs, the good-versus-bad is concrete: good is an execve of a known deployment path; bad is an execve whose path contradicts the name the user saw.
$ command -v auditctl || echo 'no auditd in this lab' /usr/sbin/auditctl
mkdir -p evidence && sha256sum quarterly-report.pdf.sh | tee evidence/hash.txt && cp quarterly-report.pdf.sh evidence/ captures the hash and the file BEFORE the strip, because closing the execution path comes next. chmod -x quarterly-report.pdf.sh strips the execute bit. Verify: ./quarterly-report.pdf.sh fails with Permission denied, rc 126, recorded honestly. The execution path is closed; the evidence is preserved. Scope: the mismatch hunt covered the directory.
$ mkdir -p evidence && sha256sum quarterly-report.pdf.sh | tee evidence/hash.txt && cp quarterly-report.pdf.sh evidence/ chmod -x quarterly-report.pdf.sh ./quarterly-report.pdf.sh eb4f11ff28e29dd873ab052d324811c77d44c625e0bb03302c31f4b213482a30 quarterly-report.pdf.sh bash: ./quarterly-report.pdf.sh: Permission denied
The heredoc writes sweep.sh: ls -1 "${1:-.}" lists the target directory, defaulting to the current one, and grep -E '\..*\.' keeps only the names carrying two or more dots. chmod +x; ./sweep.sh . flags quarterly-report.pdf.sh. Honest note, shown live: the attacker's file lost its +x but keeps its name, so it still flags. The name is still deceptive; the execution is closed. The sweep watches names, not permissions.
$ cat > sweep.sh <<'EOF'
#!/bin/sh
# mismatch-sweep: flag names carrying two or more extensions.
# Run on arrival and download trees; any hit gets file(1) before it gets executed.
ls -1 "${1:-.}" | grep -E '\..*\.'
EOF
chmod +x sweep.sh
./sweep.sh .
quarterly-report.pdf.sh
printf plants a NEW arrival, invoice.pdf.sh, and chmod +x arms it. ./sweep.sh . flags both deceptive names. The next plant is caught by the sweep, demonstrated live against this lab. Honest limit: this catches the naive double extension, not T1036.008 (faked magic bytes) or a single-extension lie; the poll interval sets the detection floor.
$ printf '#!/bin/sh\necho GHOSTLIGHT-CANARY-022\n' > invoice.pdf.sh && chmod +x invoice.pdf.sh ./sweep.sh . invoice.pdf.sh quarterly-report.pdf.sh
The summary, in the defender's own words: the name is a claim, the bytes are evidence. rm -rf /tmp/gh022 removes the lab.
$ echo 'detection verified: the name is a claim, the bytes are evidence' cd /tmp && rm -rf /tmp/gh022 && ls /tmp detection verified: the name is a claim, the bytes are evidence
file exposed the shell script behind the PDF name; the one-line mismatch hunt flagged every two-dot name in the tree; evidence was hashed and copied before the execute bit was stripped; the stripped file failed with Permission denied; the sweep flagged the decommissioned plant and a newly planted arrival. The name is a claim; the bytes are evidence.
Three moves, in order: close execution with evidence first, sweep on a schedule, enforce an execution policy. Each is one way, not the way.
Proven first against the live plant: sha256sum | tee and cp capture the hash and the file into evidence/ BEFORE the strip; chmod -x closes the execution path; the failed re-execution (Permission denied, rc 126) and the mismatch hunt confirm scope. A real response then hunts the delivery vector: how the file arrived is the incident's open question.
$ mkdir -p evidence && sha256sum quarterly-report.pdf.sh | tee evidence/hash.txt && cp quarterly-report.pdf.sh evidence/ chmod -x quarterly-report.pdf.sh ./quarterly-report.pdf.sh eb4f11ff28e29dd873ab052d324811c77d44c625e0bb03302c31f4b213482a30 quarterly-report.pdf.sh bash: ./quarterly-report.pdf.sh: Permission denied
Honest limit. Closing execution is not the same as understanding arrival: a second copy elsewhere with +x still runs, which is why the hunt covers the whole tree. chmod -x needs write permission on the file. The lab removes the tree for cleanliness; a real incident preserves evidence/ and the original file for forensics instead.
The scheduled form of the phase-blue read: sweep.sh runs the one-liner over arrival and download trees, and the tell is any name carrying two or more extensions with an executable last one. Plus the execve auditd rule, stated with its dependency: it needs the audit subsystem enabled and its rules loaded, which this lab has (auditctl is present) but many containers lack. D3FEND D3-FMBV: File Magic Byte Verification is the production form of "ask the bytes".
$ ls -1 "${1:-.}" | grep -E '\..*\.'
quarterly-report.pdf.sh
Honest limit. The sweep catches the naive double extension only; magic bytes can be faked too (T1036.008 Masquerade File Type), and a single-extension lie needs the file check, not the name check. The poll interval sets the detection floor: a file that lands and is removed between sweeps leaves no name behind, only the audit log, if auditd was watching.
The demonstrated sweep detects; only an execution policy prevents. D3FEND D3-EAL: Executable Allowlisting is the durable control; in its production form it needs fleet control. Mail and gateway stripping of double extensions is the chokepoint form, stated with its dependency on the mail and gateway stack. Honest note, repeated because it matters: the sweep detects; only the execution policy prevents.
Honest limit. Allowlisting is the strongest control here and the heaviest to operate: every legitimate script needs a rule, and the rule set needs ownership. Gateway stripping only covers the mail and download paths it sits on; a file arriving by USB or a shared drive never passes the chokepoint.
The payload was hashed and copied before the strip, the strip closed execution (Permission denied on re-run), the scheduled sweep names its tell and flagged a newly planted arrival live, and the prevention control is stated with its dependency. Every control names its bypass: the sweep sees names, not bytes; the poll interval sets the floor; allowlisting needs fleet control; and only an execution policy prevents.
The name is a claim the eye reads left to right; the bytes are evidence the kernel executes. Ask the bytes before you run the name.
IOC checklist: signs this technique was used
Reproducibility checklist
Sources
The next file looks for a user the user list does not show.