GH-012 T1036.005 PHASE RED INSIDE

The Exact Address

A scheduler runs /tmp/gh012/bin/report every few seconds because the path is trusted. This file swaps the bytes at that path for a twin with the same name, the same job, and one quiet extra. The name checks out, the location checks out, the visible behavior checks out. Only the bytes changed, and the defender hashes the bytes.

TechniqueMasquerading: Match Legitimate Name or Location (T1036.005)
Target OSUbuntu 24.04.5 LTS
Toolchainbash, coreutils
LevelBeginner
Time20 min

OBJECTIVES

  1. Swap a scheduled utility for a same-named twin and watch the marker prove it ran
  2. Catch the swap with a hash baseline and scope what ran trojaned
  3. Restore from known-good, then lock the directory read-only
  4. Take the IOC checklist and the one-sentence lesson
01

Intel Brief

CONTEXT

MITRE ATT&CK T1036.005: adversaries match the name or location of a legitimate resource so the hostile file inherits the trust of the real one. This file swaps one scheduled utility for a same-named twin at the exact same path, and shows the one check that sees through it.

Why this technique. Schedulers, init scripts, and installers address their helpers by absolute path. The operating system resolves that path fresh on every run and never asks whether the bytes at the end of it are the bytes that were installed. That gap is the whole technique. The defender's inventory says the utility lives at its path, and it does, so every check that stops at the path passes. The attack is not on the name or the schedule; it is on the assumption that a trusted path ends at trusted bytes.

Why not just hide the payload. That is the obvious move, and this file breaks it on the concrete case: the scheduler runs /tmp/gh012/bin/report because the path is written into its loop. A payload hidden anywhere else never executes; the scheduler keeps running the real utility and the attack does nothing. Hiding answers the question "where is the file", and the scheduler never asks that question. It asks "what is at this address", and the attacker makes sure the answer is the twin.

Why not rename a legitimate utility. That is the neighboring sub-technique, T1036.003, and it breaks on the concrete input too: ls /tmp/gh012/bin/ would show the wrong name, and any admin auditing the directory would see it. The .005 case shows the RIGHT name at the RIGHT path, so even the careful admin sees nothing to question. The two sub-techniques hide different things: one borrows a name for a foreign file, the other keeps the name and swaps the contents.

The mechanism, in one line. Masquerading is borrowing the trust of a legitimate identity. The resource name is the filename; the location is the directory path. Together they form the address the system trusts. A hash is a short fingerprint of a file's bytes: change one byte and the fingerprint changes completely. The twin keeps the address and changes the bytes, so every name-based check passes and only the hash-based check fails. That is the entire detection in one operation: hash the bytes, not the name.

The concrete case, before the abstraction. The utility does one thing: append one timestamped line to its log. The scheduler runs it every three seconds. The twin does the same thing, then touches a marker file. Same name, same path, same visible job, one quiet extra.

Scope. T1036.005 covers matching legitimate names or locations broadly: lookalike filenames in system directories, hostile files dropped where installers look, service binaries replaced in place. This file works the exact-name, exact-location replacement of a scheduled utility end to end: the swap, and the hash check that catches it.

02

Target Environment

LOADOUT

Ubuntu 24.04.5 LTS, x86-64, in a disposable VM used only for this lab. The swap needs write access to the utility's directory, the assumed breach; the read-only mount demo needs root. Run it on a throwaway box anyway, because you are about to practice replacing system files.

1

Build the lab

One disposable directory. bin/ holds the utility, var/ its log, baseline/ the known-good copy and the manifest. Everything the lab touches lives inside it, so cleanup is a single rm.

bash
$ rm -rf /tmp/gh012; mkdir -p /tmp/gh012/bin /tmp/gh012/var /tmp/gh012/baseline && echo "lab built: /tmp/gh012"
lab built: /tmp/gh012
2

The utility: four lines

Line by line. #!/bin/sh runs the script under the system shell. The comment lines are notes; the shell ignores them. echo "$(date -u +%FT%TZ) report ok" >> /tmp/gh012/var/report.log builds one timestamped line, date -u in UTC, +%FT%TZ in ISO 8601 form, and appends it to the log; the double >> appends, it never truncates. chmod +x makes the file executable, so the scheduler can run it by path.

sh: utility
$ cat > /tmp/gh012/bin/report <<'EOF'
#!/bin/sh
# GH-012 lab utility: a scheduled-task stand-in. Appends one
# timestamped line to the report log. Benign by design.
echo "$(date -u +%FT%TZ) report ok" >> /tmp/gh012/var/report.log
EOF
chmod +x /tmp/gh012/bin/report && cat /tmp/gh012/bin/report
#!/bin/sh
# GH-012 lab utility: a scheduled-task stand-in. Appends one
# timestamped line to the report log. Benign by design.
echo "$(date -u +%FT%TZ) report ok" >> /tmp/gh012/var/report.log
3

The baseline and the scheduler

Two load-bearing moves before anything hostile exists. cp bin/report baseline/report takes the known-good copy: this is the source of truth everything later is measured against. sha256sum bin/report > baseline.sha256 writes the manifest, a fingerprint of the installed bytes. Then the scheduler: (while true; do /tmp/gh012/bin/report; sleep 3; done) & runs the utility by its absolute path every three seconds, the shape of a cron job. $! is the background loop's pid; the page keeps it in SCHED to stop it later.

bash
$ cp /tmp/gh012/bin/report /tmp/gh012/baseline/report && (cd /tmp/gh012 && sha256sum bin/report > baseline.sha256) && cat /tmp/gh012/baseline.sha256
39c4b33b03d266f613f04dca8f3b2181e3edc1eed77d375771db3f77fa4c6317  bin/report
$ (while true; do /tmp/gh012/bin/report; sleep 3; done) & SCHED=$!; echo "scheduler pid=$SCHED"; sleep 4
[1] 13
scheduler pid=13
03

Phase Red: take the address

ATTACK

The swap, live: first the utility proves itself, then the twin takes its address. The marker file is the witness. Watch what the outside view shows, and what it does not.

Real screen recording 138.9s
What you are watching: A scheduled utility runs from its trusted path, then a same-named twin takes its place. The log keeps growing; the marker says the twin ran. Every command below is copy-pasteable.
1

Normal operation

Baseline first: the log grows one line per scheduler run, and the hash matches the install-time manifest. This is the healthy system the attack will be measured against.

bash
$ tail -3 /tmp/gh012/var/report.log; (cd /tmp/gh012 && sha256sum -c baseline.sha256)
2026-09-19T23:25:19Z report ok
2026-09-19T23:25:22Z report ok
bin/report: OK
2

The swap

The attacker overwrites the utility at its exact path. Same filename, same directory, same permissions. Nothing about the address changed; only the bytes did. The twin does the original job, then touches its marker.

bash
$ cat > /tmp/gh012/bin/report <<'EOF'
#!/bin/sh
# Trojaned twin: same name, same location, same visible job,
# plus one quiet marker. This is the T1036.005 case.
echo "$(date -u +%FT%TZ) report ok" >> /tmp/gh012/var/report.log
touch /tmp/gh012/.pwned
EOF
chmod +x /tmp/gh012/bin/report && echo "swapped: same name, same path"
swapped: same name, same path
3

The twin runs

The scheduler never noticed. It runs the path, and the path now serves the twin. The log kept growing in the same format, so nothing looks broken; the marker is the only new fact, and only the attacker knows to look for it.

bash
$ sleep 4; ls /tmp/gh012/bin/; test -e /tmp/gh012/.pwned && echo "marker present: the twin ran"; tail -2 /tmp/gh012/var/report.log
report
marker present: the twin ran
2026-09-19T23:25:22Z report ok
2026-09-19T23:25:25Z report ok
4

The outside view

Everything an admin checks without hashing: the directory listing shows the right name, the log is still growing, the scheduler is still running. The address is exactly where it should be.

bash
$ echo "--- the outside view ---"; ls -l /tmp/gh012/bin/; echo "log lines: $(wc -l < /tmp/gh012/var/report.log) (still growing)"; test -e /tmp/gh012/.pwned && echo "marker: the twin ran at this address"
--- the outside view ---
total 4
-rwxrwx--- 1 root root 213 Sep 19 23:25 report
log lines: 3 (still growing)
marker: the twin ran at this address
Stealth confirmed

The name is right, the location is right, the behavior is right. An admin listing the directory, watching the log, or confirming the scheduler is alive sees a healthy system. The check that stops at the path cannot fail, because the path is exactly where it should be. Only the bytes changed, and nobody hashed them.

04

Phase Blue: hash the bytes

DEFENSE

The defender stops reading the name and starts reading the bytes. One hash check against the install-time manifest, then the window, then the restore.

Here is the trap: listing the directory, reading the log, confirming the scheduler is alive, and calling it healthy. All three check the address. The address is the one thing the attacker did not change. Verification means comparing the bytes to the source of truth.

Real screen recording 127.6s
What you are watching: The directory looks right and the log looks right, so the defender hashes the binary against its install-time manifest. The hash fails, the diff names the extra, the window gets scoped, and the known-good bytes go back. Every command below is copy-pasteable.
1

The first look

The defender arrives and sees what the attacker wants seen: the right name, a growing log. Looking is not verifying.

bash
$ ls -l /tmp/gh012/bin/; tail -2 /tmp/gh012/var/report.log
total 4
-rwxrwx--- 1 root root 213 Sep 19 23:25 report
2026-09-19T23:25:22Z report ok
2026-09-19T23:25:25Z report ok
2

The tell

The manifest was recorded at install time, before anything hostile existed. sha256sum -c re-hashes the file and compares. FAILED means the bytes at the trusted path are not the installed bytes. Good versus bad, concrete: good is OK with an mtime older than the last authorized change; bad is FAILED on any path a scheduler executes. The name told the truth about the address; the hash tells the truth about the bytes.

bash
$ (cd /tmp/gh012 && sha256sum -c baseline.sha256)
bin/report: FAILED
sha256sum: WARNING: 1 computed checksum did NOT match
3

Confirm the change

diff against the known-good copy names the twin's added lines; stat shows the new mtime and size. The mtime is the start of the incident window: everything the scheduler ran after that moment ran trojaned.

bash
$ diff /tmp/gh012/baseline/report /tmp/gh012/bin/report; stat -c 'mtime=%y size=%s name=%n' /tmp/gh012/bin/report
2,3c2,3
< # GH-012 lab utility: a scheduled-task stand-in. Appends one
< # timestamped line to the report log. Benign by design.
---
> # Trojaned twin: same name, same location, same visible job,
> # plus one quiet marker. This is the T1036.005 case.
4a5
> touch /tmp/gh012/.pwned
mtime=2026-09-19 23:25:23.652158141 +0000 size=213 name=/tmp/gh012/bin/report
4

Scope the window

The binary's mtime says when the swap landed; the marker's mtime says when the twin first ran. The find -newer sweep lists every file changed since the baseline was recorded, excluding var/ whose log legitimately grows: the swapped binary and the marker, nothing else. That is the full extent of the change on this box. Note what mitigation is not: deleting the trojan leaves the scheduler with no utility, and the window's log lines still need review.

bash
$ echo "binary mtime:  $(stat -c %y /tmp/gh012/bin/report)"; echo "marker mtime:  $(stat -c %y /tmp/gh012/.pwned)"; find /tmp/gh012 -newer /tmp/gh012/baseline.sha256 -not -path '/tmp/gh012/var/*' | sort
binary mtime:  2026-09-19 23:25:23.652158141 +0000
marker mtime:  2026-09-19 23:25:25.651158133 +0000
/tmp/gh012
/tmp/gh012/.pwned
/tmp/gh012/bin/report
/tmp/gh012/var
5

Stop, restore, restart

Kill the scheduler by the pid kept in SCHED, and confirm it is gone before touching files. Restore the binary from the known-good copy, then re-verify: OK. Remove the attacker's marker. Restart the scheduler and watch one clean cycle: the log grows, the hash holds. The utility is back at its address, and this time the bytes match the manifest.

bash
$ kill $SCHED; sleep 0.5; kill -0 $SCHED 2>/dev/null || echo "scheduler stopped"
scheduler stopped
$ cp /tmp/gh012/baseline/report /tmp/gh012/bin/report && rm -f /tmp/gh012/.pwned && (cd /tmp/gh012 && sha256sum -c baseline.sha256) && echo "marker removed, binary restored"
bin/report: OK
marker removed, binary restored
$ (while true; do /tmp/gh012/bin/report; sleep 3; done) & SCHED=$!; sleep 4; tail -1 /tmp/gh012/var/report.log; (cd /tmp/gh012 && sha256sum -c baseline.sha256)
[1] 48
2026-09-19T23:25:31Z report ok
bin/report: OK
Detection verified

One hash check found the swap; one diff named the extra; the mtimes drew the window. The defender never needed to suspect the name, because the name was never the lie. Hash the bytes, not the name, and the twin has nowhere to stand.

6

Lock the address

Prevention makes the swap impossible instead of detectable. Bind-mounting bin/ read-only means even a writer with directory access gets Read-only file system. The attempt fails in the open, on the record.

bash
$ mount --bind /tmp/gh012/bin /tmp/gh012/bin && mount -o remount,ro --bind /tmp/gh012/bin && echo "bin/ is now read-only" && (echo evil > /tmp/gh012/bin/report && echo "WRITE SUCCEEDED (bad)" || echo "write blocked: Read-only file system")
bin/ is now read-only
bash: /tmp/gh012/bin/report: Read-only file system
write blocked: Read-only file system
7

Cleanup

Unmount the bind, stop the scheduler, remove the lab. The bind mount dies with the lab's namespace regardless; the unmount keeps the rm honest.

bash
$ umount /tmp/gh012/bin && kill $SCHED 2>/dev/null; sleep 0.5; rm -rf /tmp/gh012; ls /tmp/gh012 2>/dev/null || echo "lab directory gone"
lab directory gone
05

Countermeasures

DEFENSE

Three moves, in order: put the known-good bytes back, watch the bytes on a schedule, make the bytes unwritable. Each is one way, not the way.

1

Mitigate: stop, restore, scope

Stop the scheduler by pid and confirm it is gone. Restore the binary from the known-good copy and re-verify the hash. Remove the attacker's artifacts. Scope the window from the binary's mtime and review what ran inside it. D3FEND names the restore Restore File (D3-RF): restoring a file for an entity to access.

bash
$ kill $SCHED; sleep 0.5; kill -0 $SCHED 2>/dev/null || echo "scheduler stopped"
scheduler stopped
$ cp /tmp/gh012/baseline/report /tmp/gh012/bin/report && rm -f /tmp/gh012/.pwned && (cd /tmp/gh012 && sha256sum -c baseline.sha256) && echo "marker removed, binary restored"
bin/report: OK
marker removed, binary restored

Honest limit. Restoring the binary does not undo what the twin did while it ran. The restore fixes the address; the window scoping decides whether the twin's extra did anything worse than touching a marker. On this box the extra was one file; on a real box the diff names the extra and the window names the exposure. A restore without scoping is a cleanup, not an incident response.

2

Monitor: hash the bytes on a schedule

The install-time manifest plus a scheduled sha256sum -c is the hand-rolled form of file integrity monitoring. Record the manifest at install time, store it where the attacker cannot rewrite it, and check it on a timer; the find -newer sweep catches anything the manifest does not cover. D3FEND's grounded set for this sub-technique: File Integrity Monitoring (D3-FIM), detecting any suspicious changes to files; Service Binary Verification (D3-SBV), comparing service binaries to a source of truth, the exact scheduled-binary case; File Hashing (D3-FH), hash comparisons; and File Creation Analysis (D3-FCA), analyzing file-create syscalls, modeled for .005 specifically, the auditd watch on the utility's directory.

bash
$ (cd /tmp/gh012 && sha256sum -c baseline.sha256)
bin/report: FAILED
sha256sum: WARNING: 1 computed checksum did NOT match
$ echo "binary mtime:  $(stat -c %y /tmp/gh012/bin/report)"; echo "marker mtime:  $(stat -c %y /tmp/gh012/.pwned)"; find /tmp/gh012 -newer /tmp/gh012/baseline.sha256 -not -path '/tmp/gh012/var/*' | sort
binary mtime:  2026-09-19 23:25:23.652158141 +0000
marker mtime:  2026-09-19 23:25:25.651158133 +0000
/tmp/gh012
/tmp/gh012/.pwned
/tmp/gh012/bin/report
/tmp/gh012/var

Honest limit. A baseline recorded after the compromise verifies the trojan. The manifest is only a source of truth if it predates the attacker and lives somewhere the attacker cannot rewrite; a manifest sitting in the same writable directory is a speed bump, not a control. Hashing also says nothing about a trojan installed before the first baseline, which is why install media and package signatures exist.

3

Prevent: make the swap impossible

Mount the utility directory read-only, demonstrated above: the write fails with Read-only file system. Keep the scheduler's files owned by root and writable only by root, so a compromised service account cannot swap them (Local File Permissions, D3-LFP). Keep admin utilities in packaged paths and verify with debsums, the packaged form of the manifest check.

bash
$ mount --bind /tmp/gh012/bin /tmp/gh012/bin && mount -o remount,ro --bind /tmp/gh012/bin && echo "bin/ is now read-only" && (echo evil > /tmp/gh012/bin/report && echo "WRITE SUCCEEDED (bad)" || echo "write blocked: Read-only file system")
bin/ is now read-only
bash: /tmp/gh012/bin/report: Read-only file system
write blocked: Read-only file system

Honest limit. Read-only does not stop root: remounting read-write is one command for anyone with privilege, as the cleanup step demonstrates. Permissions do not stop a root compromise either; they raise the price from "any writer" to "root". The per-file form is chattr +i, with the same root caveat; the lab's throwaway tmpfs refuses the flag, so this page demonstrates the mount form, which the lab can actually run.

Countermeasures verified

The twin was stopped by pid, the known-good bytes restored and re-verified, the window scoped to two files, and the directory locked read-only with the swap visibly failing. Detection hashes the bytes; prevention makes the bytes unwritable. Neither trusts the name.

06

Debrief

TAKEAWAY

A trusted path says nothing about the bytes at the end of it: verify the bytes, not the name.

IOC checklist: signs this technique was used

  • A scheduled-task binary whose sha256 no longer matches its install-time manifest
  • An executable on a scheduler-run path whose mtime is newer than its last authorized change
  • A utility that does its old job plus an unexplained extra, found by diffing against the known-good copy
  • Marker-style artifacts, files touched in /tmp, paired with a recently replaced utility
  • A find -newer sweep showing utility files changed outside a maintenance window

Reproducibility checklist

  • Verified on Ubuntu 24.04.5 LTS, x86-64, on 2026-09-19
  • Both recordings are real executions on that platform, not simulations
  • The swap needs write access to the utility's directory (the assumed breach); the read-only mount demo needs root
  • Cleanup: unmount the bind (umount /tmp/gh012/bin), kill the scheduler pid, then rm -rf /tmp/gh012; the bind mount dies with the lab's namespace regardless

Sources

MITRE ATT&CK T1036.005: Match Legitimate Resource Name or Location
sha256sum(1) (the manifest check)
stat(1) (mtimes that draw the incident window)
mount(8) (the read-only bind)
MITRE D3FEND: D3-FIM, D3-SBV, D3-FH, D3-RF, D3-LFP (each modeled against T1036.005 in the technique mapping)

Next file

GH-013 The Secret Knock

A port that stays closed until it hears the right knock. The next file runs the sequence, and shows what the firewall never logged.