Skip to content
SlateGitOrgPublic

About

An NTFS timestomping detector that parses $MFT and $UsnJrnl from scratch and needs corroborating indicators to call a file stomped, so copies, archive extracts and installers stop raising alarms.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

stompwise

CI

stompwise

stompwise is an NTFS timestomping detector written in Python with only the standard library. It parses $MFT FILE records and a $UsnJrnl:$J extract from scratch, runs five timestamp indicators, and calls a file stomped only when a backdated time in the MFT is corroborated by a later timestamp change in the USN journal. Copies, archive extracts and installer output, which trip the textbook check, come out as explained. The data in this repository is synthetic: a seeded volume simulator plants known stomps so the detector can be scored.

The problem

Attackers reset the $STANDARD_INFORMATION (SI) timestamps of dropped tools so they blend in with system files. The textbook check, SI creation earlier than $FILE_NAME (FN) creation, is noisy and beatable. Archive extraction and installers produce the same pattern legitimately, and a "double stomp" (stomp, then move the file so NTFS copies the SI times into FN) removes the SI/FN gap altogether. Responders end up either ignoring the check or chasing dozens of benign files. On the simulated volume below, the textbook check alone fires on 59 files and only 4 of them are planted stomps.

How it works

flowchart LR
    MFT["$MFT image"] --> REC["Record parser<br/>fixups applied and verified"]
    J["$J extract"] --> USN["USN_RECORD_V2 parser"]
    REC --> EVID["Per-file timestamp evidence<br/>SI, FN, USN times"]
    USN --> EVID
    EVID --> IND["Indicators I1-I5"]
    EVID --> BEN["Benign explainers<br/>copy, archive, installer"]
    IND --> RULE["Corroboration rule"]
    BEN --> RULE
    RULE --> OUT["Verdict with evidence<br/>stomped, suspicious, explained, clean"]
Loading

Indicators return fired, not fired or not applicable (for example when the USN records for a file have rolled off) together with their evidence.

Id Indicator Kind
I1 SI creation earlier than FN creation backdating
I2 SI times all whole seconds while FN times are not weak
I3 a BASIC_INFO_CHANGE close record after the FILE_CREATE close record journal
I4 SI creation earlier than the FILE_CREATE USN time backdating
I5 MFT entry allocated after neighbours whose SI creation is much later weak

Verdict rule:

  • stomped: I3 plus I1 or I4.
  • explained: a benign explainer matches and I3 did not fire.
  • suspicious: I1 or I4 without I3 and without an explainer, or I3 alone.
  • clean: none of I1, I3, I4.
  • I2 and I5 add supporting evidence that orders suspicious findings but never decide a verdict.

I3 is the signal that separates a timestomping tool from an extractor or installer: those set times on the handle that created the file, so the change lands in the create close record, while a stomping tool opens the file again and produces a later close record.

Quick start

python3 -m venv .venv
.venv/bin/pip install -e ".[dev]"
.venv/bin/stompwise demo                       # simulate a volume, scan it, score it
.venv/bin/stompwise scan --mft .tmp/stompwise-demo/mft.bin --usn .tmp/stompwise-demo/journal.bin
.venv/bin/stompwise file "\\Users\\Public\\Libraries\\rcl.exe" \
    --mft .tmp/stompwise-demo/mft.bin --usn .tmp/stompwise-demo/journal.bin
.venv/bin/stompwise eval --truth .tmp/stompwise-demo/truth.json
.venv/bin/pytest

scan and file take any $MFT image and $J extract (leading sparse zeros are skipped). eval needs the truth.json that the simulator writes.

Example output

Output of stompwise demo (seed 134; the file table of the last command is shortened with ...).

$ stompwise scan
files analysed: 2938   journal records: 521   torn records: 1   deleted records skipped: 0
verdicts: stomped 5, suspicious 1, explained 95, clean 2837

verdict     path                                     record  fired           support  why
----------  ---------------------------------------  ------  --------------  -------  -------------------------------------------------
stomped     \Windows\System32\netprofm2.dll            2955  I2 I3 I4 I5           2  I3 corroborates backdating (I4)
stomped     \Windows\System32\wsvc32.exe               2810  I1 I2 I3 I4 I5        2  I3 corroborates backdating (I1 and I4)
stomped     \ProgramData\Microsoft\updsvc.exe          2937  I1 I3 I4 I5           1  I3 corroborates backdating (I1 and I4)
stomped     \Users\Public\Libraries\rcl.exe            2951  I1 I3 I4 I5           1  I3 corroborates backdating (I1 and I4)
stomped     \Windows\System32\drivers\usbstor64.sys    2887  I3 I4 I5              1  I3 corroborates backdating (I4)
suspicious  \ProgramData\Microsoft\mscorsvw32.exe      2754  I1 I2 I5              2  I1 without a later journal change or an explainer
torn record 2843: sector 1 ends in c14d, expected update sequence number c04d

$ stompwise eval
files: 2938   planted stomps: 6

indicator / verdict                                    fired  tp  fp  precision  recall
-----------------------------------------------------  -----  --  --  ---------  ------
I1 SI created before FN created                           59   4  55      0.068     4/6
I2 SI times whole seconds, FN times not                   58   3  55      0.052     3/6
I3 BASIC_INFO_CHANGE after the create close                5   5   0      1.000     5/6
I4 SI created before FILE_CREATE USN time                 60   5  55      0.083     5/6
I5 MFT entry allocated after later-created neighbours     30   6  24      0.200     6/6
verdict: stomped                                           5   5   0      1.000     5/6
verdict: stomped or suspicious                             6   6   0      1.000     6/6

verdict by planted category
category          stomped  suspicious  explained  clean
----------------  -------  ----------  ---------  -----
baseline                0           0          0   2835
copy                    0           0         40      0
extracted               0           0         25      0
installer               0           0         30      0
orphan                  0           0          0      2
stomp_double            2           0          0      0
stomp_rolled_off        0           1          0      0
stomp_single            3           0          0      0

$ stompwise file \Windows\System32\drivers\usbstor64.sys
\Windows\System32\drivers\usbstor64.sys  (record 2887, sequence 1)
verdict: stomped  (I3 corroborates backdating (I4))

source                 field                                   time (UTC)
---------------------  --------------------------------------  ----------------------------
$STANDARD_INFORMATION  created                                 2021-11-09T13:20:05.6054417Z
$STANDARD_INFORMATION  modified                                2021-11-09T13:20:05.6054417Z
$STANDARD_INFORMATION  mft_modified                            2025-08-30T02:44:19.5174170Z
$STANDARD_INFORMATION  accessed                                2021-11-09T13:20:05.6054417Z
$FILE_NAME (Win32)     created                                 2021-11-09T13:20:05.6054417Z
$FILE_NAME (Win32)     modified                                2021-11-09T13:20:05.6054417Z
$FILE_NAME (Win32)     mft_modified                            2025-08-30T02:44:19.5174170Z
$FILE_NAME (Win32)     accessed                                2021-11-09T13:20:05.6054417Z
...
$J usn=90120           DATA_EXTEND|FILE_CREATE|CLOSE [a1.exe]  2025-08-30T02:41:18.3056822Z
$J usn=90192           BASIC_INFO_CHANGE|CLOSE [a1.exe]        2025-08-30T02:43:18.5283834Z
$J usn=90264           RENAME_OLD_NAME [a1.exe]                2025-08-30T02:44:19.5174170Z
$J usn=90336           RENAME_NEW_NAME|CLOSE [usbstor64.sys]   2025-08-30T02:44:20.2435384Z

I1 not fired: SI created 2021-11-09T13:20:05.6054417Z is not before FN 2021-11-09T13:20:05.6054417Z
I2 not fired: SI and FN sub-second precision are consistent
I3 fired: BASIC_INFO_CHANGE close at usn 90192 (2025-08-30T02:43:18.5283834Z) follows the FILE_CREATE close at usn 90120 (2025-08-30T02:41:18.3056822Z)
I4 fired: SI created 2021-11-09T13:20:05.6054417Z is 1389d 13:21:12 before FILE_CREATE at 2025-08-30T02:41:18.3056822Z
I5 fired: median SI created of the 5 earlier entries is 1386d 11:43:59 after this file's SI created 2021-11-09T13:20:05.6054417Z

The double-stomped file shows why I1 alone misses it: SI and FN agree, because the rename copied the stomped times into FN. The journal still holds the create close record, a later BASIC_INFO_CHANGE close record, and the rename.

The honest limit is the rolled-off stomp (mscorsvw32.exe): its journal records are gone, I3 and I4 are not applicable, and only I1 can fire, so it is reported as suspicious, never stomped.

deleted records skipped: 0 counts unused $MFT entries. The simulator plants four deleted records, but later files reuse all four entries, so none remain unused; the reuse is what the sequence-number matching test exercises.

Design decisions

  • Corroboration over a single indicator. stomped needs a backdated MFT time and a later journal change. This costs recall when the journal has rolled off (5 of 6 planted stomps), and buys a precision of 1.0 on the simulated volume.
  • Journal references match on record number and sequence number. Entries freed and reused would otherwise inherit a deleted file's later attribute change. A test reuses four entries on purpose.
  • Fixups are verified, not assumed. A record whose sector tails do not match its update sequence number is reported as torn and none of its attributes are used.
  • Exact FILETIME arithmetic. Times are integer 100 ns ticks with a civil-calendar conversion done on integers, so values keep their full precision and cover the NTFS range up to year 30828; the local time zone is never consulted.
  • Heuristic thresholds. The explainer thresholds (10 s archive window, at least 2 siblings, 1 day minimum age, 600 s installer window) are heuristics chosen on the simulated volume, not values measured on real systems; tune them for real evidence.
  • Weak indicators order, never decide. I2 and I5 are cheap to trip innocently, so they only rank suspicious findings.
  • Explainers never hide an indicator. A file is explained only when a pattern (copy, archive extraction, installer directory) matches and I3 did not fire; the indicator results stay in the evidence.

Known limitations

  • I3 assumes extractors, installers and CopyFile set times on the creating handle. The simulated volume contains no benign file with a later BASIC_INFO_CHANGE, so I3 precision of 1.000 holds by construction. On real volumes attrib, sync clients, antivirus and restore tools can change times through a later handle; such a file with backdated times would be called stomped.
  • Extension records (base record not 0) are dropped and $ATTRIBUTE_LIST is not read, so a file whose $STANDARD_INFORMATION or $FILE_NAME lives in an extension record is not analysed.
  • Only USN_RECORD_V2 is supported. A V3 or V4 record in the journal extract aborts the scan with an error (exit 2) instead of being skipped.
  • A record with a bad signature is listed with the torn records but is reported as an unreadable record, and its flags are not used.

Testing

.venv/bin/pytest

68 tests pass. They cover a hand-built five-record fixture with hand-computed times (including FILETIME 134066832671234567 as 2025-11-03T22:41:07.1234567Z), fixup application and torn records, path reconstruction and orphans, the USN parser, each indicator and the verdict table, the full simulated volume (all 95 benign files, 5 journal-covered stomps, the rolled-off stomp), the eval figures, the CLI, and hypothesis round trips of FILETIME across the NTFS range.

Project layout

src/stompwise/
  filetime.py    exact FILETIME arithmetic
  mft.py         FILE record parser, fixups, attribute walker
  records.py     byte writers (inverse of the parsers) for tests and the simulator
  paths.py       path reconstruction with parent sequence checks
  usn.py         USN_RECORD_V2 parser
  indicators.py  I1-I5
  benign.py      copy, archive and installer explainers
  verdict.py     corroboration rule
  analysis.py    runs everything over an $MFT and $J pair
  evaluate.py    precision and recall against ground truth
  report.py      text tables
  synth.py       seeded volume-history simulator
  cli.py         scan, file, eval, demo
tests/           pytest suite and fixtures/ (five-record $MFT, small $J)

License

MIT. See LICENSE.

About

An NTFS timestomping detector that parses $MFT and $UsnJrnl from scratch and needs corroborating indicators to call a file stomped, so copies, archive extracts and installers stop raising alarms.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages