GH-017 T1620 PHASE RED INSIDE

The Unwritten File

The payload executes, but it was never a file on disk. memfd_create makes an anonymous memory file, the loader copies the ELF into it and runs it with fexecve, then unlinks even the staging copy it read from. This file runs that loading end to end, then detects the fileless process from the exe link that resolves to anonymous memory, contains it with evidence-first discipline, and demonstrates the seccomp gate that makes the loader fail closed.

TechniqueReflective Code Loading (T1620)
Target OSUbuntu 24.04.5 LTS
Toolchainbash, gcc, coreutils
LevelAdvanced
Time30 min

OBJECTIVES

  1. Load an ELF into anonymous memory with memfd_create and execute it with fexecve, leaving no file on disk
  2. Detect the fileless process from /proc/PID/exe and the memfd mappings, capture the evidence, contain it
  3. Scan /proc for memfd-backed executables on a schedule, gate memfd_create behind seccomp for sandboxed workloads
  4. Take the IOC checklist and the one-sentence lesson
01

Intel Brief

CONTEXT

MITRE ATT&CK T1620: adversaries load code into memory and execute it without the code ever existing as a file on the filesystem, defeating every control that starts from the file inventory: blocklists, quarantine, integrity monitors. This file runs the Linux memfd_create variant end to end, then detects it from the one place the kernel cannot hide: the process's own executable mapping. Two actors: the attacker, who owns the loader, the payload bytes, and the anonymous file; and the defender, who owns the /proc reads, the scanner, the kill, and the seccomp gate in the blue phase.

Why this technique. Every file-based control answers the same question: what is on this disk. A hash blocklist, a quarantine, an integrity monitor, a forensic image: all of them enumerate files. Reflective code loading changes the question by removing the file. The payload arrives as bytes (over the network, inside another process, it does not matter for this file), lands in anonymous memory, and executes. There is no path to blocklist, no file to quarantine, no directory entry for the monitor to hash. The defender who starts from the file inventory finds nothing, because there is nothing to find there. The detection has to move up a layer, from what is on the disk to what is executing.

Why not run it from disk and delete it. The obvious alternative is the naive fileless: write the payload to /tmp, execute it, delete the file. Break it on the concrete input: between the write and the delete, the file exists with a directory entry, visible to any sweep, any integrity monitor, any forensic image taken in that window. And the delete itself leaves the directory-mtime scar: the parent directory's timestamp moves when the entry is removed. memfd_create never creates a directory entry at all. There is no window where the file exists, and no scar where it was removed, because nothing was ever written to the filesystem.

Why not hide inside a host process. The other obvious alternatives are the earlier techniques: the LD_PRELOAD rootkit, which hides files by intercepting libc directory reads, and ptrace injection, which runs the payload inside a living host process. Break them: both need a living host process to infect, and both leave their own artifacts, the preload library on disk, the injector's trace. The memfd payload is self-contained. It needs exactly one thing from the operating system, the anonymous file, and the dropper's single memfd_create call provides it. Fewer dependencies, fewer artifacts, a smaller surface for the defender to grip.

Why not pipe it into a shell. The third alternative is curl | sh: fetch the script, pipe it to the interpreter, never write it down. Break it: the interpreter is a real file with a real exe link. Only the script is remote; the thing doing the executing is /bin/sh, sitting on disk, hashed and inventoried like everything else. The memfd construction goes one layer deeper: not just the script but the EXECUTED IMAGE is anonymous. /proc/PID/exe does not resolve to a path at all.

The mechanism, in one line. An anonymous file is a file with no directory entry: it exists only as long as something holds it open, reachable solely through its file descriptor. A file descriptor is the kernel's handle for an open file: the small integer a process passes to read, write, and execute. memfd_create is the syscall that makes an anonymous memory-backed file and returns its descriptor. fexecve executes the program held open on a file descriptor, replacing the calling process. Reflective code loading is running code that was loaded into memory without ever existing as a filesystem file. Terms earned, no borrowing.

The concrete case, before the abstraction. In /tmp/gh017: payload.c prints a marker and sleeps, compiled to the payload ELF. loader.c calls memfd_create("ghost-payload", MFD_CLOEXEC), copies the ELF bytes into the descriptor, unlinks the disk copy it read from, and calls fexecve on the descriptor. After: ls shows no payload file, ps shows the process under its argv[0] name, and readlink /proc/PID/exe prints /memfd:ghost-payload (deleted). One syscall, one anonymous file, one exe link that resolves to memory instead of a path.

Scope. T1620 covers reflective loading broadly: memfd_create on Linux, anonymous mappings with PROT_EXEC, process hollowing and injection on other platforms. This file works the Linux memfd_create case end to end: the loader, the unlink, the fexecve, the /proc detection, the evidence-first containment, the whole-host scanner, and the seccomp gate. 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 the technique's whole point is leaving no filesystem trace; the /proc reads are the defender's independent observation path.

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 compiles its own loader, payload, scanner, and seccomp gate inside /tmp/gh017, and every blue-phase read targets the live fileless process. Everything the lab touches lives inside /tmp/gh017, so cleanup is a single rm.

1

Build the lab

One disposable directory, built from scratch. rm -rf /tmp/gh017 clears any earlier take; mkdir -p makes the lab. Four sources go in through heredocs. payload.c is the benign stand-in: it prints "GHOSTLIGHT reflective payload executed (pid N)", flushes, and sleeps 600. It proves execution and touches nothing else. loader.c is the dropper: memfd_create with MFD_CLOEXEC, copy the ELF bytes from the staging path into the descriptor, close and unlink the staging copy, then fexecve the descriptor with argv[0] set to "ghost-payload". The executed program was never a file at exec time. scan.sh is the detector: it walks /proc/[0-9]*, readlinks each exe, and flags any that resolve to /memfd:*. gate.c is the prevention: a raw-BPF seccomp filter that returns EPERM for the memfd_create syscall number and allows everything else, installed with NO_NEW_PRIVS before execing its target. gcc -O2 builds all three binaries; the final ls -l proves the lab built.

bash
$ rm -rf /tmp/gh017 && mkdir -p /tmp/gh017 && cd /tmp/gh017 && cat > payload.c <<'EOF'
#include <stdio.h>
#include <unistd.h>
/* Benign stand-in: proves execution, touches nothing. */
int main(void) {
    printf("GHOSTLIGHT reflective payload executed (pid %d)\n", getpid());
    fflush(stdout);
    sleep(600);
    return 0;
}
EOF
cat > loader.c <<'EOF'
#define _GNU_SOURCE
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
/* Dropper: anonymous file, copy the ELF in, unlink the staging copy,
   execute from the descriptor. The payload is never a file at exec time. */
int main(int argc, char **argv, char **envp) {
    if (argc < 2) { fprintf(stderr, "usage: %s <payload-elf>\n", argv[0]); return 2; }
    int mfd = memfd_create("ghost-payload", MFD_CLOEXEC);
    if (mfd < 0) { perror("memfd_create"); return 1; }
    int pfd = open(argv[1], O_RDONLY);
    if (pfd < 0) { perror("open payload"); return 1; }
    char buf[65536]; ssize_t n;
    while ((n = read(pfd, buf, sizeof buf)) > 0)
        if (write(mfd, buf, n) != n) { perror("write"); return 1; }
    close(pfd);
    unlink(argv[1]);
    char *args[] = { "ghost-payload", NULL };
    fexecve(mfd, args, envp);
    perror("fexecve");
    return 1;
}
EOF
cat > scan.sh <<'EOF'
#!/bin/sh
# memfd-scan: flag processes whose executable is anonymous memory.
# Good: every exe resolves to a real path. Bad: exe is /memfd:*.
found=0
for d in /proc/[0-9]*; do
    exe=$(readlink "$d/exe" 2>/dev/null) || continue
    case "$exe" in
        /memfd:*)
            pid=${d#/proc/}
            cmd=$(tr '\0' ' ' < "$d/cmdline" 2>/dev/null)
            echo "SUSPECT pid=$pid exe='$exe' cmd='$cmd'"
            found=1 ;;
    esac
done
[ "$found" -eq 0 ] && echo "clean: no memfd-backed executables"
EOF
cat > gate.c <<'EOF'
#define _GNU_SOURCE
#include <linux/seccomp.h>
#include <linux/filter.h>
#include <linux/audit.h>
#include <sys/prctl.h>
#include <sys/syscall.h>
#include <stddef.h>
#include <errno.h>
#include <unistd.h>
#include <stdio.h>
/* Prevention gate: memfd_create -> EPERM, everything else allowed. */
static struct sock_filter f[] = {
    BPF_STMT(BPF_LD | BPF_W | BPF_ABS, offsetof(struct seccomp_data, nr)),
    BPF_JUMP(BPF_JMP | BPF_JEQ | BPF_K, __NR_memfd_create, 0, 1),
    BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ERRNO | EPERM),
    BPF_STMT(BPF_RET | BPF_K, SECCOMP_RET_ALLOW),
};
static struct sock_fprog p = { .len = sizeof(f)/sizeof(f[0]), .filter = f };
int main(int argc, char **argv) {
    if (argc < 2) { fprintf(stderr, "usage: %s <prog> [args]\n", argv[0]); return 2; }
    if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0)) { perror("no_new_privs"); return 1; }
    if (syscall(__NR_seccomp, SECCOMP_SET_MODE_FILTER, 0, &p)) { perror("seccomp"); return 1; }
    execvp(argv[1], argv + 1);
    perror("execvp");
    return 1;
}
EOF
gcc -O2 -o payload payload.c && gcc -O2 -o loader loader.c && gcc -O2 -o gate gate.c && chmod +x scan.sh && echo "lab built: /tmp/gh017"; ls -l /tmp/gh017
lab built: /tmp/gh017
total 68
-rwxrwx--- 1 root root 16336 Sep 23 00:15 gate
-rw-rw---- 1 root root  1030 Sep 23 00:15 gate.c
-rwxrwx--- 1 root root 16440 Sep 23 00:15 loader
-rw-rw---- 1 root root   889 Sep 23 00:15 loader.c
-rwxrwx--- 1 root root 16144 Sep 23 00:15 payload
-rw-rw---- 1 root root   241 Sep 23 00:15 payload.c
-rwxrwx--- 1 root root   511 Sep 23 00:15 scan.sh
2

The obvious alternative, broken on a concrete input

Before the real attack, watch the naive version fail. cp payload runme puts the payload on disk under a new name; ./runme & backgrounds it; the marker prints. Then the failure, concrete: ls -l /tmp/gh017/runme shows the file, 16144 bytes, sitting there for any sweep, any integrity monitor, any forensic image to find. kill stops it, rm removes it. Disk execution leaves a directory entry between the write and the delete, and the delete leaves the mtime scar. That is the failure the memfd construction exists to fix.

bash
$ echo "--- the obvious alternative: run it from disk ---"; cp payload runme && ./runme > runme.out 2>&1 & RPID=$!; sleep 1; cat runme.out; echo "--- the failure: the file is right there for any sweep ---"; ls -l /tmp/gh017/runme; kill $RPID 2>/dev/null; rm -f runme runme.out; echo "(disk execution leaves a directory entry; that is what we fix next)"
--- the obvious alternative: run it from disk ---
[1] 27
GHOSTLIGHT reflective payload executed (pid 30)
--- the failure: the file is right there for any sweep ---
-rwxrwx--- 1 root root 16144 Sep 23 00:15 /tmp/gh017/runme
(disk execution leaves a directory entry; that is what we fix next)
03

Phase Red: run the unwritten

ATTACK

The loader runs the payload from anonymous memory, unlinks its own staging copy, and the exe link resolves to memory instead of a path.

Real screen recording 343.4s
What you are watching: A payload is executed from anonymous memory with no file on disk. The staging copy is unlinked by the loader itself. Every command below is copy-pasteable.
1

The attack

./loader ./payload & backgrounds the dropper; fexecve replaces it with the payload, so the background job IS the payload now, and $! names its pid directly. The marker prints: the code is running. Then the inventory: ls /tmp/gh017/payload fails, no such file, because the loader unlinked its own staging copy after copying the bytes into the memfd. And the tell the attacker cannot remove: readlink /proc/$LPID/exe prints /memfd:ghost-payload (deleted). The executable is anonymous memory. The process table shows a name; the name resolves to nowhere on disk.

bash
$ echo "--- the attack: execute from anonymous memory ---"; ./loader ./payload > payload.out 2>&1 & LPID=$!; sleep 1; echo "--- the payload ran:"; cat payload.out; echo "--- the staging copy:"; ls /tmp/gh017/payload 2>&1 || echo '(gone: the loader unlinked it)'; echo "payload pid: $LPID (fexecve replaced the loader in place)"; echo "--- what the executable resolves to:"; readlink /proc/$LPID/exe
--- the attack: execute from anonymous memory ---
[1] 34
--- the payload ran:
GHOSTLIGHT reflective payload executed (pid 34)
--- the staging copy:
ls: cannot access '/tmp/gh017/payload': No such file or directory
(gone: the loader unlinked it)
payload pid: 34 (fexecve replaced the loader in place)
--- what the executable resolves to:
/memfd:ghost-payload (deleted)
2

Stealth confirmed

Three echo lines, the attacker's summary: the code runs, but it was never a file; no directory entry existed at exec time, so no inventory can list it; the process table shows a name, but the name resolves to anonymous memory. The file listing is the wrong evidence to read, which is exactly what the blue phase exploits.

bash
$ echo "stealth confirmed: the code runs, but it was never a file"; echo "no directory entry existed at exec time, so no inventory can list it"; echo "the process table shows a name; the name resolves to anonymous memory"
stealth confirmed: the code runs, but it was never a file
no directory entry existed at exec time, so no inventory can list it
the process table shows a name; the name resolves to anonymous memory
Stealth confirmed

The payload executed from a memfd_create anonymous file via fexecve, the loader unlinked its own staging copy, and no file on disk corresponds to the running code: the file inventory is empty. The attack works because every file-based control enumerates files, and there is no file.

04

Phase Blue: read the exe link

DEFENSE

The defender does not trust the file listing. The defender reads the process's own executable mapping: scan the whole host for anonymous executables, drill into the exe link and the mappings by hand, learn the CLOEXEC lesson from the descriptors, then record the evidence before containing.

Here is the trap: running ps, seeing the process, running ls, finding no file, and concluding the process must be legitimate because there is nothing to quarantine. That is trusting the file inventory the attacker just bypassed. The detection is the exe link: readlink /proc/PID/exe while the process is still running.

Real screen recording 193.1s
What you are watching: The defender detects the fileless process from its exe link and memory mappings, captures the evidence, contains it, and demonstrates the seccomp gate that makes the loader fail closed. Every command below is copy-pasteable.
1

DETECTION: the naive view

ps -ef | grep ghost-payload shows the process running: the naive view. ls -l /tmp/gh017 shows the lab files and no payload: the file inventory says there is nothing to quarantine. Stopping here is the attacker's win, and it is exactly where file-based tooling stops. The independent path starts in the next step.

bash
$ echo "--- DETECTION: the naive view first ---"; ps -ef | grep -x '.*ghost-payload.*' | grep -v grep || pgrep -ax ghost-payload; echo "--- the file inventory:"; ls -l /tmp/gh017; echo "(no payload file. Stopping here is the attacker's win.)"
--- DETECTION: the naive view first ---
root          34       1  0 00:15 ?        00:00:00 ghost-payload
--- the file inventory:
total 56
-rwxrwx--- 1 root root 16336 Sep 23 00:15 gate
-rw-rw---- 1 root root  1030 Sep 23 00:15 gate.c
-rwxrwx--- 1 root root 16440 Sep 23 00:15 loader
-rw-rw---- 1 root root   889 Sep 23 00:15 loader.c
-rw-rw---- 1 root root   241 Sep 23 00:15 payload.c
-rw-rw---- 1 root root    48 Sep 23 00:15 payload.out
-rwxrwx--- 1 root root   511 Sep 23 00:15 scan.sh
(no payload file. Stopping here is the attacker's win.)
2

DETECTION: the whole-host scanner

/tmp/gh017/scan.sh walks every numeric /proc entry, readlinks each exe, and flags any resolving to /memfd:*. One command, the whole host, no trust in the file inventory. The output names the suspect PID, the anonymous exe, and the command line. The pid it reports is the handle every following step drills into.

bash
$ echo "--- DETECTION: the whole-host scanner ---"; /tmp/gh017/scan.sh; echo "(one command, every process, no trust in the file inventory)"
--- DETECTION: the whole-host scanner ---
SUSPECT pid=34 exe='/memfd:ghost-payload (deleted)' cmd='ghost-payload '
(one command, every process, no trust in the file inventory)
3

DETECTION: the independent path, by hand

The pid comes from the scanner's output; the verification is manual. readlink /proc/$P/exe prints /memfd:ghost-payload (deleted): the executable is anonymous memory, and that is the tell. grep -c memfd /proc/$P/maps counts the anonymous mappings; the head shows them, including one r-xp line, an executable mapping with no file behind it. Good versus bad, concrete: good is the exe link resolving to a real path; bad is the exe link resolving to /memfd:*, which means fileless execution, investigate now. The kernel cannot lie about what it is executing, even when the filesystem has nothing to say.

bash
$ echo "--- DETECTION: the independent path ---"; P=$(/tmp/gh017/scan.sh | awk '/^SUSPECT/ {print $2}' | cut -d= -f2 | head -1); echo "payload pid: $P (found by the scanner)"; echo "--- the exe link:"; readlink /proc/$P/exe; echo "--- memfd mappings (one is executable):"; grep -c memfd /proc/$P/maps; grep memfd /proc/$P/maps | head -3; echo "good: exe resolves to a real path"; echo "bad: exe resolves to /memfd:* -> fileless execution, investigate"
--- DETECTION: the independent path ---
payload pid: 34 (found by the scanner)
--- the exe link:
/memfd:ghost-payload (deleted)
--- memfd mappings (one is executable):
5
5ed091ba9000-5ed091baa000 r--p 00000000 00:01 1336                       /memfd:ghost-payload (deleted)
5ed091baa000-5ed091bab000 r-xp 00001000 00:01 1336                       /memfd:ghost-payload (deleted)
5ed091bab000-5ed091bac000 r--p 00002000 00:01 1336                       /memfd:ghost-payload (deleted)
good: exe resolves to a real path
bad: exe resolves to /memfd:* -> fileless execution, investigate
4

DETECTION: the CLOEXEC lesson

ls -l /proc/$P/fd shows stdin, stdout, stderr, and no memfd descriptor. The loader passed MFD_CLOEXEC, so the kernel closed the anonymous file's descriptor at exec: the attacker hid the handle. A detector that only watches for memfd file descriptors misses the CLOEXEC variant entirely. The exe link and the mappings do not depend on the descriptor surviving, which is why the independent path reads them and not the fd table. Defense in depth starts with knowing which observation the attacker already defeated.

bash
$ echo "--- the CLOEXEC lesson: check the descriptors ---"; P=$(/tmp/gh017/scan.sh | awk '/^SUSPECT/ {print $2}' | cut -d= -f2 | head -1); ls -l /proc/$P/fd; echo "(no memfd descriptor: MFD_CLOEXEC closed it at exec)"; echo "the attacker hid the descriptor; the exe link still tells the truth"
--- the CLOEXEC lesson: check the descriptors ---
total 0
lr-x------ 1 root root 64 Sep 23 00:15 0 -> /dev/null
l-wx------ 1 root root 64 Sep 23 00:15 1 -> /tmp/gh017/payload.out
l-wx------ 1 root root 64 Sep 23 00:15 2 -> /tmp/gh017/payload.out
(no memfd descriptor: MFD_CLOEXEC closed it at exec)
the attacker hid the descriptor; the exe link still tells the truth
5

MITIGATION: evidence first, then contain

The exe link, the memfd mappings, the command line, and the fd listing go into evidence.txt BEFORE anything is touched: killing the process destroys the memfd with it, and the anonymous contents are unrecoverable after that, so the capture comes first. Then kill $P: the memfd dies with the process, there is no file to delete, containment is the kill plus the sweep. /tmp/gh017/scan.sh reports clean: no memfd-backed executables remain. The scanner already covered every process, so the sweep is done.

bash
$ echo "--- MITIGATION: record the evidence BEFORE touching anything ---"; P=$(/tmp/gh017/scan.sh | awk '/^SUSPECT/ {print $2}' | cut -d= -f2 | head -1); { echo "exe: $(readlink /proc/$P/exe)"; echo '--- maps:'; grep memfd /proc/$P/maps; echo '--- cmdline:'; tr '\0' ' ' < /proc/$P/cmdline; echo; echo '--- fd:'; ls -l /proc/$P/fd; } > /tmp/gh017/evidence.txt 2>&1; cat /tmp/gh017/evidence.txt; echo "--- contain: kill it; the memfd dies with the process ---"; kill $P; sleep 0.5; /tmp/gh017/scan.sh
--- MITIGATION: record the evidence BEFORE touching anything ---
exe: /memfd:ghost-payload (deleted)
--- maps:
5ed091ba9000-5ed091baa000 r--p 00000000 00:01 1336                       /memfd:ghost-payload (deleted)
5ed091baa000-5ed091bab000 r-xp 00001000 00:01 1336                       /memfd:ghost-payload (deleted)
5ed091bab000-5ed091bac000 r--p 00002000 00:01 1336                       /memfd:ghost-payload (deleted)
5ed091bac000-5ed091bad000 r--p 00002000 00:01 1336                       /memfd:ghost-payload (deleted)
5ed091bad000-5ed091bae000 rw-p 00003000 00:01 1336                       /memfd:ghost-payload (deleted)
--- cmdline:
ghost-payload
--- fd:
total 0
lr-x------ 1 root root 64 Sep 23 00:15 0 -> /dev/null
l-wx------ 1 root root 64 Sep 23 00:15 1 -> /tmp/gh017/payload.out
l-wx------ 1 root root 64 Sep 23 00:15 2 -> /tmp/gh017/payload.out
--- contain: kill it; the memfd dies with the process ---
clean: no memfd-backed executables
6

MITIGATION: the dropper was always a file

rm -f removes the loader and payload binaries from disk; ls -l confirms what remains. The honest note, stated plainly: only the payload was fileless. The dropper was always a file, and incident response still hunts how the dropper arrived on the box: the delivery vector is out of this file's scope, but the response is not complete until it is answered. Fileless execution hides the payload, never the delivery.

bash
$ echo "--- MITIGATION: the dropper was always a file ---"; rm -f /tmp/gh017/loader /tmp/gh017/payload; ls -l /tmp/gh017; echo "(only the payload was fileless; incident response still hunts how the dropper arrived)"
--- MITIGATION: the dropper was always a file ---
total 40
-rw-rw---- 1 root root   798 Sep 23 00:15 evidence.txt
-rwxrwx--- 1 root root 16336 Sep 23 00:15 gate
-rw-rw---- 1 root root  1030 Sep 23 00:15 gate.c
-rw-rw---- 1 root root   889 Sep 23 00:15 loader.c
-rw-rw---- 1 root root   241 Sep 23 00:15 payload.c
-rw-rw---- 1 root root    48 Sep 23 00:15 payload.out
-rwxrwx--- 1 root root   511 Sep 23 00:15 scan.sh
(only the payload was fileless; incident response still hunts how the dropper arrived)
7

PREVENTION: the seccomp gate

The dropper is rebuilt, then run under the gate: ./gate ./loader ./payload. The loader's memfd_create returns EPERM, "Operation not permitted", and the loader exits 1 before it can do anything: no anonymous file, no execution, and the staging copy survives on disk because the loader died before unlinking it. Under the gate the attack fails closed. D3FEND D3-PSEP: Process Segment Execution Prevention names this shape: preventing execution from memory regions outside the legitimate code segment, enforced here at the syscall that creates the anonymous region.

bash
$ echo "--- PREVENTION: the seccomp gate ---"; echo "(rebuild the dropper, then run it under the gate)"; cd /tmp/gh017 && gcc -O2 -o loader loader.c && gcc -O2 -o payload payload.c && ./gate ./loader ./payload; echo "loader rc=$?"; echo "--- the staging copy survives: the loader died before it could unlink ---"; ls -l /tmp/gh017/payload; echo "(under the gate the attack fails closed: no anonymous file, no execution)"
--- PREVENTION: the seccomp gate ---
(rebuild the dropper, then run it under the gate)
memfd_create: Operation not permitted
loader rc=1
--- the staging copy survives: the loader died before it could unlink ---
-rwxrwx--- 1 root root 16144 Sep 23 00:15 /tmp/gh017/payload
(under the gate the attack fails closed: no anonymous file, no execution)
8

Verdict and cleanup

The summary, in the defender's own words: the listing said clean, the exe link said anonymous memory. The evidence was captured before the kill, the scanner is the scheduled check, the seccomp gate denies memfd_create and the attack fails closed. rm -rf /tmp/gh017 removes the lab; ls confirms the directory is gone.

bash
$ echo "detection verified: the listing said clean, the exe link said anonymous memory"; echo "the evidence was captured before the kill, the scanner is the scheduled check"; echo "the seccomp gate denies memfd_create, and the attack fails closed"; rm -rf /tmp/gh017; ls /tmp | grep gh017 || echo "lab gone"
detection verified: the listing said clean, the exe link said anonymous memory
the evidence was captured before the kill, the scanner is the scheduled check
the seccomp gate denies memfd_create, and the attack fails closed
lab gone
Detection verified

The file listing said clean and the exe link said anonymous memory, and the exe link was right: /memfd:ghost-payload (deleted), with executable anonymous mappings to match. The evidence was captured before the kill, the whole-host scanner confirmed the containment, and the seccomp gate made the rebuilt dropper fail closed with EPERM. The CLOEXEC variant hides the descriptor; it cannot hide the execution.

05

Countermeasures

DEFENSE

Three moves, in order: capture and contain, scan the host on a schedule, gate the syscall for sandboxed workloads. Each is one way, not the way.

1

Mitigate: capture, kill, sweep, remove the dropper

Proven first against the live fileless process: capture the exe link, the memfd mappings, the command line, and the fd listing into evidence.txt before touching anything, kill the process (the memfd dies with it; there is no file to delete), re-run the /proc scanner to confirm clean across every process, and remove the dropper binary from disk. A real response then hunts the delivery vector: how the dropper arrived is the incident's open question.

bash
$ echo "--- MITIGATION: record the evidence BEFORE touching anything ---"; P=$(/tmp/gh017/scan.sh | awk '/^SUSPECT/ {print $2}' | cut -d= -f2 | head -1); { echo "exe: $(readlink /proc/$P/exe)"; echo '--- maps:'; grep memfd /proc/$P/maps; echo '--- cmdline:'; tr '\0' ' ' < /proc/$P/cmdline; echo; echo '--- fd:'; ls -l /proc/$P/fd; } > /tmp/gh017/evidence.txt 2>&1; cat /tmp/gh017/evidence.txt; echo "--- contain: kill it; the memfd dies with the process ---"; kill $P; sleep 0.5; /tmp/gh017/scan.sh
--- MITIGATION: record the evidence BEFORE touching anything ---
exe: /memfd:ghost-payload (deleted)
--- maps:
5ed091ba9000-5ed091baa000 r--p 00000000 00:01 1336                       /memfd:ghost-payload (deleted)
5ed091baa000-5ed091bab000 r-xp 00001000 00:01 1336                       /memfd:ghost-payload (deleted)
5ed091bab000-5ed091bac000 r--p 00002000 00:01 1336                       /memfd:ghost-payload (deleted)
5ed091bac000-5ed091bad000 r--p 00002000 00:01 1336                       /memfd:ghost-payload (deleted)
5ed091bad000-5ed091bae000 rw-p 00003000 00:01 1336                       /memfd:ghost-payload (deleted)
--- cmdline:
ghost-payload
--- fd:
total 0
lr-x------ 1 root root 64 Sep 23 00:15 0 -> /dev/null
l-wx------ 1 root root 64 Sep 23 00:15 1 -> /tmp/gh017/payload.out
l-wx------ 1 root root 64 Sep 23 00:15 2 -> /tmp/gh017/payload.out
--- contain: kill it; the memfd dies with the process ---
clean: no memfd-backed executables

Honest limit. Killing the process destroys the memfd and with it any in-memory forensic artifact: the evidence.txt capture comes before the kill for exactly that reason, and the capture is treated as the record. The memfd's former contents are unrecoverable after the kill; there is no file to carve. The loader binary and the evidence capture ARE the artifacts. A response that kills first and captures after has destroyed its own evidence.

2

Monitor: scan /proc for memfd-backed executables on a schedule

The scheduled form of the phase-blue read: the scanner walks /proc, readlinks every exe, and flags any resolving to /memfd:*. The tell is any memfd-backed executable on a production host. D3FEND D3-PCSV: Process Code Segment Verification is the discipline behind it: the code segment is verified against a source of truth, and here the truth is that every executable must resolve to a real path.

bash
$ echo "--- DETECTION: the whole-host scanner ---"; /tmp/gh017/scan.sh; echo "(one command, every process, no trust in the file inventory)"
--- DETECTION: the whole-host scanner ---
SUSPECT pid=34 exe='/memfd:ghost-payload (deleted)' cmd='ghost-payload '
(one command, every process, no trust in the file inventory)

Honest limit. The scanner sees only its own PID namespace: run it host-wide, not inside a container, or the fileless process in another namespace is invisible to it. Legitimate software (browsers, language runtimes) uses memfd and must be allowlisted by exact name, and every allowlist entry is a name the attacker will try to wear. The poll interval sets the detection floor: a payload that runs and exits between polls is missed. Where available, pair the scanner with syscall auditing of memfd_create itself (auditctl -a always,exit -F arch=b64 -S memfd_create -k memfd-exec): stated with its exact syntax and its dependency, not demonstrated, because the audit subsystem is disabled in this lab and in many containers.

3

Prevent: deny memfd_create to the sandboxed workload

The durable form: a seccomp-BPF gate that returns EPERM for memfd_create, applied where the untrusted code runs. Demonstrated above: under the gate the loader fails closed before it can create the anonymous file. In production the gate lives in the container runtime's seccomp profile or the unit's SystemCallFilter=~memfd_create, not in a wrapper binary.

bash
$ echo "--- PREVENTION: the seccomp gate ---"; echo "(rebuild the dropper, then run it under the gate)"; cd /tmp/gh017 && gcc -O2 -o loader loader.c && gcc -O2 -o payload payload.c && ./gate ./loader ./payload; echo "loader rc=$?"; echo "--- the staging copy survives: the loader died before it could unlink ---"; ls -l /tmp/gh017/payload; echo "(under the gate the attack fails closed: no anonymous file, no execution)"
--- PREVENTION: the seccomp gate ---
(rebuild the dropper, then run it under the gate)
memfd_create: Operation not permitted
loader rc=1
--- the staging copy survives: the loader died before it could unlink ---
-rwxrwx--- 1 root root 16144 Sep 23 00:15 /tmp/gh017/payload
(under the gate the attack fails closed: no anonymous file, no execution)

Honest limit. The gate is per-process policy: it stops only the workloads it is applied to, and an attacker who controls the policy controls the gate. Blocking the syscall can break legitimate software that uses anonymous files, so the profile must be built from the workload's actual syscall set, not copied blindly. And it stops the memfd variant, not reflective loading by other primitives: anonymous PROT_EXEC mappings do not need memfd_create. Defense in depth, not a silver bullet.

Countermeasures verified

The fileless process was detected from its exe link, captured, and contained with the scanner confirming clean; the scanner is the scheduled check with the namespace and allowlist limits stated; the seccomp gate denies memfd_create and the rebuilt dropper failed closed. The file listing still says nothing ran. The exe link does not agree.

06

Debrief

TAKEAWAY

When the file listing says nothing ran, read the exe link: code that was never a file still has to execute from somewhere.

IOC checklist: signs this technique was used

  • A process whose /proc/PID/exe resolves to /memfd:* (deleted) instead of a path
  • Anonymous executable mappings (r-xp) in /proc/PID/maps with a memfd tag and no file
  • A process name with no corresponding file anywhere on the filesystem
  • A dropper binary whose recent execution left no payload artifact behind
  • Audit events for the memfd_create syscall from an unexpected process, where auditing is enabled

Reproducibility checklist

  • Verified on Ubuntu 24.04.5 LTS, x86-64, on 2026-09-22
  • Both recordings are real executions on that platform, not simulations
  • Runs as root in a disposable namespace (the lab compiles its own loader, payload, scanner, and gate; the assumed breach: something on the box delivered the dropper)
  • Cleanup: rm -rf /tmp/gh017; verify with ls /tmp

Sources

MITRE ATT&CK T1620: Reflective Code Loading
memfd_create(2) (the anonymous file)
execve(2) (fexecve: execute from a descriptor)
seccomp(2) (the prevention gate)
proc(5) (the exe link, the maps, the fd table)
D3FEND D3-PCSV: Process Code Segment Verification
D3FEND D3-PSEP: Process Segment Execution Prevention

Legitimate uses

memfd_create is dual-use: the same anonymous file the loader abuses is ordinary infrastructure elsewhere. systemd wraps it for sealed, non-executable anonymous files (memfd-util.c); QEMU backs guest RAM with it to share memory with vhost-user daemons (memory-backend-memfd); Wayland's wl_shm software-rendering path is typically memfd-backed (wl_shm mechanism). The blue phase above targets the malicious pattern, an executable whose exe link resolves to anonymous memory, not the syscall itself, which is why the seccomp gate belongs on the sandboxed workload, not the whole host.

Next file

GH-018 The Folded Letter

The next file unwraps code that arrives folded.