The payload arrives folded twice, and static inspection sees only opaque text. base64 armor, an XOR fold that breaks the base64 alphabet, base64 armor again: the content is never at rest in cleartext. This file folds a benign payload end to end and runs it by decoding straight into a shell, then the defense measures the artifact instead of matching it, entropy triage flags the armor, a sandboxed safe-decode reveals the payload, the running decoded process is contained with evidence-first discipline, and a scheduled hunt makes the control durable.
MITRE ATT&CK T1140: adversaries decode or deobfuscate files or information at the moment of use, so the artifact at rest is armor, not content. This file folds a benign payload twice and runs it by decoding straight into a shell, so static inspection sees only opaque text. Then the defense: entropy triage flags the armor, a sandboxed safe-decode reveals the payload, the running decoded process is contained with evidence-first discipline, and a scheduled decode-hunt makes the control durable. Two actors: the attacker, who owns fold.py, note.folded, and unfold.sh; and the defender, who owns the entropy reads, the sandbox decode, the kill, and the scheduled hunt in the blue phase.
Why this technique. Every static control answers one question: what does this file contain. Hash blocklists, content signatures, grep, strings: all of them read the artifact at rest. Folding changes what is at rest. The bytes on disk are armor, layered transforms chosen so the original text never appears. The content exists in cleartext only inside the decode pipe, for a fraction of a second, between unfold.sh and sh. A scanner that reads the file sees the armor. The payload is never at rest in cleartext, so there is nothing at rest to match.
Why not ship it in cleartext. The obvious alternative is the naive dropper: a shell script on disk, executed directly. Break it on the concrete input: grep -l GHOSTLIGHT over the lab names /tmp/clear.sh instantly, strings would print its lines, any content rule keyed on the marker fires. The recording shows the measurement: grep -l finds the cleartext file and stays silent on note.folded. One artifact is found instantly; the other is invisible. That gap is what the folds buy.
Why not a single base64 layer. The next obvious alternative is one fold of base64, the classic decode-then-execute one-liner. Break it: base64 has a fixed 64-character alphabet, and defenders know it. A base64 blob is recognizable by its alphabet, and one base64 -d reverses it. The XOR fold breaks the alphabet: the middle layer is binary, not base64 text, so alphabet signatures do not match and a lone base64 -d of the middle layer yields garbage instead of the payload. The outer armor re-encodes to base64, so the stored artifact still looks like ordinary encoded text. Each fold defeats one cheap detector.
The mechanism, in one line. Obfuscation is transforming content to hide its meaning while keeping it recoverable. Encoding, here base64, is the binary-to-text armor that maps every 3 bytes to 4 text characters. A fold is one such transform applied in sequence. XOR with a key byte flips bits reversibly: applying the same XOR twice restores the original, so the decoder needs only the key, 0x5A here. Decode-then-execute is the pipeline that decodes standard input straight into an interpreter: ./unfold.sh note.folded | sh. The payload is cleartext only in the pipe between the two. Terms earned, no borrowing.
The concrete case, before the abstraction. In /tmp/gh018: fold.py reads payload.sh, 124 bytes, a benign stand-in that prints a marker and sleeps 600. base64 makes it text, XOR 0x5A breaks the alphabet, base64 armors it again: note.folded, 224 bytes. payload.sh is deleted; the delivered artifact is note.folded plus unfold.sh. unfold.sh reverses the folds, base64 -d, XOR 0x5A, base64 -d, to standard output. The attack is one pipeline: ./unfold.sh note.folded | sh. The marker prints, the sleeper starts, and the disk still holds only armor.
Scope. T1140 covers deobfuscation and decoding broadly: encoded payloads, encrypted blobs with embedded keys, packed binaries, runtime decoding. This file works the encoded-artifact case end to end: the two-fold packer, the decoder stub, the decode-into-shell execution, entropy triage, the sandboxed safe-decode, evidence-first containment, and the scheduled hunt. The payload is a benign stand-in that prints a marker and sleeps: it proves execution and touches nothing else. The lab runs in a disposable namespace because every blue-phase read targets the live decoded process.
Ubuntu 24.04.5 LTS, x86-64, in a disposable namespace used only for this lab. Runs as root: the lab folds its own payload, runs the decode pipeline, and every blue-phase read targets the live decoded process. Everything the lab touches lives inside /tmp/gh018, so cleanup is a single rm.
One disposable directory, built from scratch. cp brings in the lab files; chmod +x makes the scripts executable; python3 fold.py folds the payload (124 bytes in, 224 bytes of armor out); rm -f payload.sh deletes the cleartext so the lab holds only the delivered artifact; file confirms the disguise. Every file below is shown in full, each line glossed after it.
#!/bin/sh # Benign stand-in payload: proves execution, touches nothing. echo "GHOSTLIGHT folded payload executed" sleep 600
payload.sh, the benign stand-in, in full: the shebang picks the interpreter, the echo prints the marker that proves execution, sleep 600 keeps the decoded process alive long enough for the blue phase to find it. It touches nothing else. This is the file the attacker deletes after folding: it never ships.
#!/usr/bin/env python3
"""fold.py (attacker's packer): payload.sh -> base64 -> XOR 0x5A -> base64 -> note.folded.
Two folds. The inner base64 armor hides the text. The XOR breaks the
base64 alphabet so signature scanners see no base64. The outer base64
armor makes the result look like ordinary encoded text.
"""
import base64
with open('/tmp/gh018/payload.sh', 'rb') as f:
raw = f.read()
inner = base64.b64encode(raw)
xored = bytes(b ^ 0x5A for b in inner)
outer = base64.b64encode(xored)
with open('/tmp/gh018/note.folded', 'wb') as f:
f.write(outer + b'\n')
print('folded %d -> %d bytes' % (len(raw), len(outer)))
fold.py, the packer, in full: read payload.sh as bytes; base64.b64encode makes it text, the inner armor; the generator expression XORs every byte with 0x5A, breaking the base64 alphabet so the middle layer is binary, not text; base64.b64encode again, the outer armor, so the stored artifact looks like ordinary encoded text; write note.folded with a trailing newline; print the size change. Two folds, each defeating one cheap detector.
#!/bin/sh # unfold.sh (attacker's decoder stub): reverses the two folds. # Usage: ./unfold.sh note.folded base64 -d "$1" | python3 -c "import sys;d=sys.stdin.buffer.read();sys.stdout.buffer.write(bytes(b^0x5A for b in d))" | base64 -d
unfold.sh, the decoder stub, in full: one pipeline that reverses the folds. base64 -d strips the outer armor; the python3 one-liner XORs every byte with 0x5A again, which restores the inner armor, because applying the same XOR twice is the identity; the final base64 -d strips the inner armor. Decoded bytes go to standard output, which is what the attack pipes into sh.
#!/usr/bin/env python3
"""entropy.py (defender's triage): Shannon entropy per file in a directory.
Armored or encoded blobs score near the top of their alphabet's range;
ordinary scripts and text score lower. A triage signal, not a verdict:
the verdict comes from safely decoding the flagged file.
"""
import math
import os
import sys
from collections import Counter
def entropy(path):
with open(path, 'rb') as f:
data = f.read()
if not data:
return 0.0, 0
counts = Counter(data)
n = len(data)
return -sum(v / n * math.log2(v / n) for v in counts.values()), n
target = sys.argv[1] if len(sys.argv) > 1 else '.'
for root, _dirs, files in os.walk(target):
for name in sorted(files):
path = os.path.join(root, name)
try:
e, n = entropy(path)
except OSError:
continue
flag = ' <-- OPAQUE' if e > 5.0 else ''
print('%5.2f bits/byte %6d bytes %s%s' % (e, n, path, flag))
entropy.py, the defender’s triage, in full: walk the target directory; read each file as bytes; count byte frequencies; compute the Shannon entropy in bits per byte; flag anything above 5.0. Armored blobs score near the top of their alphabet’s range; ordinary scripts score lower. The flag is a triage signal, not a verdict: the verdict comes from safely decoding the flagged file.
#!/bin/sh
# decode-hunt.sh (defender's scheduled control): triage a directory for
# opaque files and attempt a SAFE decode of a COPY in a sandbox dir
# (D3FEND D3-FCDC: File Content Decompression Checking).
# It never executes what it finds. Run: ./decode-hunt.sh /srv/www
dir=${1:-/srv/www}
thresh=5.0
tmp=$(mktemp -d)
found=0
for f in "$dir"/*; do
[ -f "$f" ] || continue
e=$(python3 -c "import math,sys;from collections import Counter;d=open(sys.argv[1],'rb').read();c=Counter(d);n=len(d);print('%.2f'%(-sum(v/n*math.log2(v/n) for v in c.values())))" "$f")
if [ "$(python3 -c "print(int(float('$e') > $thresh))")" = 1 ]; then
found=1
echo "OPAQUE: $f ($e bits/byte)"
cp "$f" "$tmp/sample"
if base64 -d "$tmp/sample" > "$tmp/dec" 2>/dev/null; then
echo " outer layer is base64; decoded first bytes:"
head -c 48 "$tmp/dec" | od -A d -t x1 | head -3
else
echo " not plain base64; escalate to the sandbox"
fi
fi
done
if [ "$found" = 0 ]; then
echo "clean: no opaque files in $dir"
fi
rm -rf "$tmp"
decode-hunt.sh, the scheduled control, in full: for each file in the directory, compute its entropy with the same formula; above the 5.0 threshold, copy the file to a sandbox temp dir and try base64 -d on the copy; print the decoded first bytes, or escalate if it is not plain base64. It never executes what it finds. D3FEND D3-FCDC: File Content Decompression Checking names this shape: checking whether encoded sections decode.
The attacker confirms the delivered artifact, watches static inspection fail three ways, measures the cleartext alternative getting caught instantly, and runs the folded artifact by decoding it straight into a shell.
ls -l shows the lab: note.folded, the armor; unfold.sh, the decoder stub; fold.py, the packer; entropy.py and decode-hunt.sh, the defender’s tools, already staged for the blue phase. No payload.sh: it was deleted after folding. The cleartext never ships.
$ ls -l total 20 -rwxrwx--- 1 root root 1103 Sep 23 12:47 decode-hunt.sh -rwxrwx--- 1 root root 977 Sep 23 12:47 entropy.py -rwxrwx--- 1 root root 627 Sep 23 12:47 fold.py -rw-rw---- 1 root root 225 Sep 23 12:47 note.folded -rwxrwx--- 1 root root 235 Sep 23 12:47 unfold.sh
file says ASCII text: the armor wears a plain-text disguise. strings prints the armor lines, which say nothing. grep -c counts zero hits for the payload marker, and the fallback echo confirms it. Three independent static reads, all blind.
$ echo "--- static inspection:"; file note.folded; echo "--- strings:"; strings note.folded | head -4; echo "--- grep for the payload marker:"; grep -c GHOSTLIGHT note.folded || echo "(0 hits: the marker is nowhere in the artifact)" --- static inspection: note.folded: ASCII text --- strings: EyMfLAM3Ni8WaRQ1GTMXPQs3DC87DT4vExIUagMNbzEWDTYvExIYMj8NIiwDDQtsExIYIzhpADY5Ixg2Px0MMD4CCCo4aG4pExIILD4NFDUAAhc9ODdjajsdNi8AI24RAA0UNTgjGzMIajIKD2sIFwkPPhMMGRg3OGgiMQANCz05HRxvOB1jMgAZGDY/HQwwPgIINgAZExE5aCI2AAIbPRQwGy0ZPWdn --- grep for the payload marker: 0 (0 hits: the marker is nowhere in the artifact)
printf writes the cleartext twin of the payload to /tmp/clear.sh. grep -l over both files names the cleartext instantly and stays silent on note.folded: the measurement, concrete. rm -f removes the twin. One artifact is found instantly; the other is invisible. That gap is what the folds buy.
$ printf 'echo "GHOSTLIGHT folded payload executed"\nsleep 600\n' > /tmp/clear.sh && echo "--- the obvious alternative: ship it in cleartext ---" && grep -l GHOSTLIGHT /tmp/clear.sh note.folded; echo "(cleartext: found instantly. folded: invisible.)"; rm -f /tmp/clear.sh --- the obvious alternative: ship it in cleartext --- /tmp/clear.sh (cleartext: found instantly. folded: invisible.)
./unfold.sh note.folded | sh & backgrounds the decode-then-execute pipeline; the decoded bytes flow straight into the interpreter and are never a file. $! names the pipeline pid. The marker prints from red.out: the decoded payload ran. The disk still holds only armor.
$ echo "--- the attack: unfold and run ---"; ./unfold.sh note.folded | sh > red.out 2>&1 & RPID=$!; sleep 1; echo "--- the decoded payload ran:"; cat red.out; echo "pipeline pid: $RPID" --- the attack: unfold and run --- [1] 25 --- the decoded payload ran: GHOSTLIGHT folded payload executed pipeline pid: 25
Three echo lines, the attacker’s summary: the artifact on disk is opaque armor; the payload was cleartext only inside the pipe, for a fraction of a second; static inspection never saw it. The file listing is the wrong evidence to read, which is exactly what the blue phase exploits.
$ echo "stealth confirmed: the artifact on disk is opaque armor"; echo "the payload was cleartext only inside the pipe, for a fraction of a second"; echo "static inspection never saw it" stealth confirmed: the artifact on disk is opaque armor the payload was cleartext only inside the pipe, for a fraction of a second static inspection never saw it
The folded artifact decoded straight into a shell and executed; static inspection (file, strings, grep) saw nothing at any point; the payload was cleartext only inside the pipe. The attack works because every static control reads the artifact at rest, and the content is never at rest.
The defender does not trust the static reads. The defender measures the artifact with entropy triage, decodes a copy in a sandbox, and only then touches the running process: evidence first, kill second, sweep the schedulers, install the hunt.
Here is the trap: running grep over the lab, finding nothing, and concluding the box is clean. That is trusting the static reads the attacker just defeated. The detection starts with a measurement, not a match: entropy.
grep -l "folded payload" finds red.out, the execution log. It proves a payload ran; it says nothing about how. note.folded still gives up nothing. The log is the starting point, not the answer.
$ echo "--- the log proves something ran; the artifact hides the how:"; grep -l "folded payload" * 2>/dev/null; echo "(red.out is the execution log. note.folded still gives up nothing.)" --- the log proves something ran; the artifact hides the how: red.out (red.out is the execution log. note.folded still gives up nothing.)
python3 entropy.py walks the lab and measures every file. note.folded scores 5.35 bits per byte and is flagged OPAQUE; the scripts score lower and are not. Good versus bad, concrete: good is text a human can read; bad is armor no human can read, investigate now. The flag is triage, not a verdict: the verdict comes from decoding the flagged file.
$ echo "--- DETECTION: entropy triage ---"; python3 entropy.py /tmp/gh018 --- DETECTION: entropy triage --- 4.92 bits/byte 1103 bytes /tmp/gh018/decode-hunt.sh 4.59 bits/byte 977 bytes /tmp/gh018/entropy.py 4.96 bits/byte 627 bytes /tmp/gh018/fold.py 5.35 bits/byte 225 bytes /tmp/gh018/note.folded <-- OPAQUE 4.19 bits/byte 35 bytes /tmp/gh018/red.out 4.90 bits/byte 235 bytes /tmp/gh018/unfold.sh
file says ASCII text, again. The armor wears a plain-text disguise, and "text" is not "benign". This is why the triage measures instead of trusting the type: the type is the attacker’s costume.
$ echo "--- the innocent look:"; file note.folded; echo "(ASCII text: the armor wears a plain-text disguise)" --- the innocent look: note.folded: ASCII text (ASCII text: the armor wears a plain-text disguise)
mkdir -p /tmp/sandbox and cp move a COPY of the artifact into the sandbox; the original is evidence and is never decoded in place. ./unfold.sh on the copy writes decoded.sh; cat reveals the payload, in full, deterministically. Now the defender knows exactly what ran, before touching anything.
$ echo "--- DETECTION: safe decode of a COPY (never the original):"; mkdir -p /tmp/sandbox && cp note.folded /tmp/sandbox/ && ./unfold.sh /tmp/sandbox/note.folded > /tmp/sandbox/decoded.sh; echo "--- the revealed payload:"; cat /tmp/sandbox/decoded.sh --- DETECTION: safe decode of a COPY (never the original): --- the revealed payload: #!/bin/sh # Benign stand-in payload: proves execution, touches nothing. echo "GHOSTLIGHT folded payload executed" sleep 600
pgrep -f "[s]leep 600" finds the sleeper; the bracket trick keeps pgrep from matching the hunter’s own command line. ps -o pid,ppid,args shows the process and its parent. The pid, the ppid, and the command line go into evidence.txt BEFORE the kill, because the kill destroys the evidence. kill $P ends the decoded process; pgrep confirms it is gone. There is no file to delete: the payload lived in the pipe.
$ echo "--- MITIGATION: evidence before the kill:"; P=$(pgrep -f "[s]leep 600" | head -1); echo "sleeper pid: $P"; ps -o pid,ppid,args -p $P; { echo "pid: $P"; echo "ppid: $(ps -o ppid= -p $P)"; echo "cmdline: $(tr '\0' ' ' < /proc/$P/cmdline)"; } > evidence.txt 2>&1; echo "--- recorded:"; cat evidence.txt; echo "--- contain:"; kill $P; sleep 0.5; pgrep -f "[s]leep 600" >/dev/null && echo STILL-RUNNING || echo "(gone: the decoded process is dead)"
--- MITIGATION: evidence before the kill:
sleeper pid: 30
PID PPID COMMAND
30 25 sleep 600
--- recorded:
pid: 30
ppid: 25
cmdline: sleep 600
--- contain:
(gone: the decoded process is dead)
rm -f removes the folded artifact, the decoder stub, and the execution log. Then the persistence sweep: decode pipelines hide in schedulers, so the loop reads /etc/cron.d and /etc/cron.daily, and grep -rl "base64 -d" hunts decode pipelines in cron. Clean. ls -l shows what remains: the defender’s tools.
$ echo "--- remove the artifacts:"; rm -f note.folded unfold.sh red.out; echo "--- persistence sweep: decode pipelines hide in schedulers:"; for d in /etc/cron.d /etc/cron.daily; do echo "-- $d:"; ls $d 2>/dev/null || echo "(absent)"; done; grep -rl "base64 -d" /etc/cron.d/ 2>/dev/null || echo "(no decode pipelines in cron)"; ls -l --- remove the artifacts: --- persistence sweep: decode pipelines hide in schedulers: -- /etc/cron.d: e2scrub_all -- /etc/cron.daily: apt-compat dpkg (no decode pipelines in cron) total 16 -rwxrwx--- 1 root root 1103 Sep 23 12:47 decode-hunt.sh -rwxrwx--- 1 root root 977 Sep 23 12:47 entropy.py -rw-rw---- 1 root root 42 Sep 23 12:47 evidence.txt -rwxrwx--- 1 root root 627 Sep 23 12:47 fold.py
The durable control: a cron line runs decode-hunt.sh over the served directory every 15 minutes. The hunt flags opaque files, safe-decodes copies in a sandbox temp dir, and never executes what it finds. Run by hand against this lab, it reports clean: the artifacts are gone and the control is watching.
$ echo "--- PREVENTION: the scheduled hunt:"; printf '*/15 * * * * /tmp/gh018/decode-hunt.sh /srv/www\n' > hunt.cron && cat hunt.cron && echo "--- the hunt, right now, against this lab:" && ./decode-hunt.sh /tmp/gh018 --- PREVENTION: the scheduled hunt: */15 * * * * /tmp/gh018/decode-hunt.sh /srv/www --- the hunt, right now, against this lab: clean: no opaque files in /tmp/gh018
The summary, in the defender’s own words: entropy flagged the armor, the sandboxed decode revealed the payload, the kill was evidenced first, the schedulers swept clean. rm -rf /tmp/sandbox /tmp/gh018 removes the lab; ls confirms the directory is gone.
$ echo "detection verified: entropy flagged the armor, the sandboxed decode revealed the payload"; echo "mitigation verified: evidenced, killed, artifacts removed, schedulers swept"; echo "prevention verified: the hunt runs every 15 minutes and decodes only copies"; rm -rf /tmp/sandbox /tmp/gh018; ls /tmp | grep gh018 || echo "(lab gone)" detection verified: entropy flagged the armor, the sandboxed decode revealed the payload mitigation verified: evidenced, killed, artifacts removed, schedulers swept prevention verified: the hunt runs every 15 minutes and decodes only copies (lab gone)
Entropy triage flagged the armor at 5.35 bits per byte, the sandboxed safe-decode revealed the payload deterministically, the running decoded process was evidenced before the kill, the artifacts were removed, and the schedulers swept clean. The static reads still say nothing. The measurement does not agree.
Three moves, in order: reveal and contain, hunt on a schedule, shrink the decode surface. Each is one way, not the way.
Proven first against the live decoded process: safe-decode a COPY of the folded artifact in a sandbox to learn what ran; capture the pid, ppid, and command line into evidence.txt before touching anything; kill the decoded process; remove the artifact, the decoder stub, and the log; sweep the schedulers for decode pipelines. A real response then hunts the delivery vector: how note.folded arrived on the box is the incident’s open question.
$ echo "--- MITIGATION: evidence before the kill:"; P=$(pgrep -f "[s]leep 600" | head -1); echo "sleeper pid: $P"; ps -o pid,ppid,args -p $P; { echo "pid: $P"; echo "ppid: $(ps -o ppid= -p $P)"; echo "cmdline: $(tr '\0' ' ' < /proc/$P/cmdline)"; } > evidence.txt 2>&1; echo "--- recorded:"; cat evidence.txt; echo "--- contain:"; kill $P; sleep 0.5; pgrep -f "[s]leep 600" >/dev/null && echo STILL-RUNNING || echo "(gone: the decoded process is dead)"
--- MITIGATION: evidence before the kill:
sleeper pid: 30
PID PPID COMMAND
30 25 sleep 600
--- recorded:
pid: 30
ppid: 25
cmdline: sleep 600
--- contain:
(gone: the decoded process is dead)
Honest limit. The kill destroys the running decoded process, and the pipe’s transient cleartext is unrecoverable after it: evidence before kill is the whole discipline. The lab deletes the attacker’s artifact for cleanliness; a real incident preserves the original folded file and the sandbox copy for forensics instead of rm. A response that deletes first and preserves after has destroyed its own case.
The scheduled form of the phase-blue read: decode-hunt.sh walks the directory, flags files above 5.0 bits per byte, safe-decodes copies in a sandbox dir, and never executes. D3FEND D3-FCDC: File Content Decompression Checking is the discipline behind it: encoded sections are decoded and inspected as a matter of routine, not after an incident.
$ echo "--- PREVENTION: the scheduled hunt:"; printf '*/15 * * * * /tmp/gh018/decode-hunt.sh /srv/www\n' > hunt.cron && cat hunt.cron && echo "--- the hunt, right now, against this lab:" && ./decode-hunt.sh /tmp/gh018 --- PREVENTION: the scheduled hunt: */15 * * * * /tmp/gh018/decode-hunt.sh /srv/www --- the hunt, right now, against this lab: clean: no opaque files in /tmp/gh018
Honest limit. base64, xxd, and python3 are dual-use: they are in every legitimate stack, so flagging every decode drowns the team. The hunt keys on opaque FILES plus decode attempts, not the tools alone. The 5.0 threshold is a starting point, not a constant: compressed backups, encrypted stores, and media files also score high, so tune it against your own baseline or every backup window pages the team. And an attacker who decodes purely in memory, with no folded file on disk, defeats the file hunt entirely: that gap is answered by execve auditing of decode-then-interpreter chains, not by a tighter threshold.
Two demonstrations, same technique. First, the scheduled decode-hunt.sh engaged as the installed control: it flagged the rebuilt note.folded at 5.35 bits/byte with the outer layer’s base64-decoded first bytes on display; the T1140 technique then attempted execution against the defended baseline, the decoded process was found and killed before it could reach its objective, and the post-engagement sweep came back clean. Second, the attack ran on a box with no decode tooling: a bare PATH holding only sh and echo, where ./unfold.sh note.folded dies with “base64: not found”, rc 127. The attack needs its decoder, and the decoder is not there.
$ cp /home/hatch/workspace/goals/ghostlight-stealth-research-site/hidden_files/gh018-lab/payload.sh payload.sh && python3 fold.py payload.sh note.folded && echo "--- artifact:" && ls -l note.folded folded 124 -> 224 bytes --- artifact: -rw-rw---- 1 root root 225 Sep 23 12:57 note.folded
$ echo "--- defense baseline: the scheduled decode-hunt against this lab ---" && ./decode-hunt.sh /tmp/gh018 --- defense baseline: the scheduled decode-hunt against this lab --- OPAQUE: /tmp/gh018/note.folded (5.35 bits/byte) outer layer is base64; decoded first bytes: 0000000 13 23 1f 2c 03 37 36 2f 16 69 14 35 19 33 17 3d 0000016 0b 37 0c 2f 3b 0d 3e 2f 13 12 14 6a 03 0d 6f 31 0000032 16 0d 36 2f 13 12 18 32 3f 0d 22 2c 03 0d 0b 6c
$ ./unfold.sh note.folded | sh > red.out 2>&1 & echo $! > /tmp/gh018/rpid.txt; sleep 1; P=$(pgrep -f "[s]leep 600" | head -1); echo "live unfolded process found: PID $P"; kill -9 $P; wait $(cat /tmp/gh018/rpid.txt) 2>/dev/null; echo "killed: the decoded process never reached its objective" live unfolded process found: PID 9883 killed: the decoded process never reached its objective
$ rm -f payload.sh note.folded red.out rpid.txt && echo "--- post-engagement sweep ---" && ./decode-hunt.sh /tmp/gh018 --- post-engagement sweep --- clean: no opaque files in /tmp/gh018
$ mkdir -p /tmp/barebin && ln -sf /bin/sh /bin/echo /tmp/barebin/ && ls /tmp/barebin echo sh
$ echo "--- the attack, on a box with no decode tooling: ---" && PATH=/tmp/barebin ./unfold.sh note.folded; echo "rc=$?" --- the attack, on a box with no decode tooling: --- rc=127 ./unfold.sh: 4: python3: not found ./unfold.sh: 4: base64: not found ./unfold.sh: 4: base64: not found
Honest limit. Any interpreter is a decoder: python3, perl, even sh itself can unwrap simple folds, so removing base64 raises the bar, it does not remove decoding. A determined attacker ships their own decoder. The durable win is the hunt from step 2, which catches the artifact regardless of which decoder the attacker brought. Strip the tooling where it is genuinely unneeded; monitor everywhere else.
The payload was revealed by safe-decoding a copy, the running process was evidenced before the kill, the schedulers swept clean; the hunt runs every 15 minutes and decodes only copies; where decode tooling is not needed it is not installed, and the attack dies at the first fold. Every control names its bypass: the file hunt misses in-memory-only decoding, the threshold needs a local baseline, and no tool removal stops an interpreter.
When static inspection sees only armor, measure the file and decode a copy: the content is never at rest, so look at the moment of use.
IOC checklist: signs this technique was used
Reproducibility checklist
Sources
MITRE ATT&CK T1140: Deobfuscate/Decode Files or Information
MITRE ATT&CK T1027: Obfuscated Files or Information (the armor; T1140 is the unwrapping)
base64(1) (the armor tool)
D3FEND D3-FCDC: File Content Decompression Checking
The next file hands a locked-out user the key to a secret with one chmod.