GH-018 T1140 PHASE RED INSIDE

The Folded Letter

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.

TechniqueDeobfuscate/Decode Files or Information (T1140)
Target OSUbuntu 24.04.5 LTS
Toolchainbash, python3, coreutils
LevelIntermediate
Time25 min

OBJECTIVES

  1. Fold a benign payload twice (base64 armor, XOR, base64 armor) and run it by decoding straight into a shell, leaving only opaque text on disk
  2. Flag the opaque artifact with entropy triage, reveal the payload with a sandboxed safe-decode, capture evidence and contain the running decoded process
  3. Hunt opaque files on a schedule with safe-decode triage, sweep schedulers for decode pipelines, and state every control's bypass honestly
  4. Take the IOC checklist and the one-sentence lesson
01

Intel Brief

CONTEXT

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.

02

Target Environment

LOADOUT

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.

1

Build the lab

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.

payload.sh
#!/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.

fold.py
#!/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.

unfold.sh
#!/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.

entropy.py
#!/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.

decode-hunt.sh
#!/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.

03

Phase Red: run the folded letter

ATTACK

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.

Real screen recording 89.2s
What you are watching: A payload folded twice is decoded straight into a shell. Static inspection of the artifact finds nothing. Every command below is copy-pasteable.
1

The delivered artifact

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.

bash
$ 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
2

Static inspection sees nothing

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.

bash
$ 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)
3

The obvious alternative, broken on a concrete input

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.

bash
$ 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.)
4

The attack: unfold and run

./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.

bash
$ 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
5

Stealth confirmed

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.

bash
$ 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
Stealth confirmed

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.

04

Phase Blue: measure, then decode a copy

DEFENSE

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.

Real screen recording 193.2s
What you are watching: The defender flags the opaque artifact with entropy triage, reveals the payload by safely decoding a copy, captures evidence, contains the running process, and installs the scheduled hunt. Every command below is copy-pasteable.
1

DETECTION: the log proves something ran

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.

bash
$ 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.)
2

DETECTION: entropy triage

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.

bash
$ 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
3

DETECTION: the innocent look

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.

bash
$ 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)
4

DETECTION: safe decode of a copy

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.

bash
$ 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
5

MITIGATION: evidence before the kill

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.

bash
$ 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)
6

MITIGATION: remove the artifacts, sweep the schedulers

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.

bash
$ 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
7

PREVENTION: the scheduled hunt

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.

bash
$ 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
8

Verdict and cleanup

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.

bash
$ 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)
Detection verified

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.

05

Countermeasures

DEFENSE

Three moves, in order: reveal and contain, hunt on a schedule, shrink the decode surface. Each is one way, not the way.

1

Mitigate: reveal, capture, kill, sweep

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.

bash
$ 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.

2

Monitor: hunt opaque files on a schedule

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.

bash
$ 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.

3

Prevent: the hunt as a control, and no decoder, no decode

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.

bash
$ 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
bash
$ 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
bash
$ ./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
bash
$ 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
bash
$ mkdir -p /tmp/barebin && ln -sf /bin/sh /bin/echo /tmp/barebin/ && ls /tmp/barebin
echo
sh
bash
$ 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.

Countermeasures verified

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.

06

Debrief

TAKEAWAY

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

  • A file with high Shannon entropy (near the top of its alphabet’s range) that no human can read, especially newly arrived
  • Opaque text blobs: base64 blocks, hex dumps, long encoded strings in files that should be readable
  • Decode-then-interpreter pipelines in process trees or shell history: base64 -d piped into sh, xxd -r piped into sh
  • A payload marker that appears in logs but in no cleartext file on disk
  • Decoder tooling (base64, xxd, openssl enc, python3 one-liners) invoked with decode flags at odd hours or from odd parents

Reproducibility checklist

  • Verified on Ubuntu 24.04.5 LTS, x86-64, on 2026-09-23
  • Both recordings are real executions on that platform, not simulations
  • Runs as root in a disposable namespace (the lab folds its own payload; the assumed breach: something on the box delivered the folded artifact)
  • Cleanup: rm -rf /tmp/gh018 /tmp/sandbox; verify with ls /tmp

Sources

Next file

GH-019 The Open Door

The next file hands a locked-out user the key to a secret with one chmod.