How to Build a Timestomping Utility: Windows Native APIs, NTFS Metadata & Forensic Evasion
Title: How to Build a Timestomping Utility: Windows Native APIs, NTFS Metadata & Forensic Evasion
Description: Learn how file timestamps work in Windows, how they can be modified using Native APIs, and why forensic examiners need multiple data sources to catch manipulation.
Tags: #windows #cybersecurity #ntfs #native-api #forensics #c #malware-analysis #windows-internals
Reading Time: 8 min
Difficulty: Intermediate
π― Introduction
Ever wondered how malware hides its tracks on Windows systems? One of the most overlookedβyet powerfulβtechniques is timestomping: modifying file creation, modification, and access timestamps to appear innocuous.
In this post, I'll walk you through:
β
How Windows stores file timestamps
β
Why investigators rely on them
β
How to build a timestomping utility from scratch
β
Why timestomping alone is insufficient for evasion
β
How forensic examiners can detect manipulation
I've built a working timestomper in C using Windows Native APIsβlet's dissect it.
π The Problem: File Timestamps in Forensics
When an investigator reconstructs a timeline of events on a compromised system, they often start with file metadata.
Standard questions during incident response:
- When was this executable created?
- When was this configuration file last modified?
- What files were accessed around the time of the breach?
All of this relies on three critical timestamps:
| Timestamp | Meaning | Example |
|---|---|---|
| Creation Time | When the file was first written to disk | 2026-07-10 10:13 PM |
| Last Write Time | When the file contents changed | 2026-07-10 10:15 PM |
| Last Access Time | When the file was opened | 2026-07-10 3:00 PM |
If an attacker can modify these timestamps, they can:
- π΅οΈ Hide when malware was executed
- π Impersonate legitimate system files
- π Obfuscate the attack timeline
- πͺ Evade automated detection systems
βοΈ Understanding Windows File Timestamps
Where Are Timestamps Stored?
Windows stores file timestamps in the NTFS MFT (Master File Table). Every file has an associated entry containing:
FILE_BASIC_INFORMATION
βββ CreationTime
βββ LastAccessTime
βββ LastWriteTime
βββ ChangeTime
βββ FileAttributes
How Can We Access Them?
There are two ways to read/modify timestamps:
1. Win32 APIs (High-Level)
GetFileTime() // Read timestamps
SetFileTime() // Write timestamps (limited)
2. Native APIs (Low-Level)
NtQueryInformationFile() // Query file info directly from kernel
NtSetInformationFile() // Modify file info at kernel level
The Native API approach is more powerful because:
- Win32 may enforce restrictions or validation
- Native APIs interact directly with NTFS structures
- Developers can bypass certain access checks
π§ Building the Timestomper
Let's break down the implementation. Full source code: github.com/zainsial866/timestomper
Step 1: Define the Structures
typedef struct _FILE_BASIC_INFORMATION {
LARGE_INTEGER CreationTime;
LARGE_INTEGER LastAccessTime;
LARGE_INTEGER LastWriteTime;
LARGE_INTEGER ChangeTime;
ULONG FileAttributes;
} FILE_BASIC_INFORMATION;
The LARGE_INTEGER format stores time as 100-nanosecond intervals since January 1, 1601 (Windows FILETIME).
Step 2: Dynamically Resolve Native APIs
Instead of static linking, we resolve the APIs at runtime:
NtQueryInformationFile_t pNtQueryInformationFile =
(NtQueryInformationFile_t)GetProcAddress(
GetModuleHandleA("ntdll.dll"),
"NtQueryInformationFile"
);
if (pNtQueryInformationFile == NULL) {
printf("[!] Could not resolve NtQueryInformationFile\n");
return FALSE;
}
Why?
- Undocumented APIs aren't in import libraries
- Dynamic resolution makes the tool more portable
- Demonstrates runtime API patching techniques
Step 3: Open Source & Destination Files
HANDLE fileSrc = CreateFile(
srcfile,
GENERIC_READ, // Source needs read access
0, NULL, OPEN_EXISTING, 0, NULL
);
HANDLE fileDst = CreateFile(
dstfile,
GENERIC_READ | GENERIC_WRITE | FILE_WRITE_ATTRIBUTES, // Dst needs write
0, NULL, OPEN_EXISTING, 0, NULL
);
Step 4: Query the Source File's Timestamps
IO_STATUS_BLOCK ioStat;
FILE_BASIC_INFORMATION src_fbi;
pNtQueryInformationFile(
fileSrc, // File handle
&ioStat, // Status block
&src_fbi, // Output buffer
sizeof(FILE_BASIC_INFORMATION), // Buffer size
FileBasicInformation // Information class
);
Step 5: Copy Timestamps
FILE_BASIC_INFORMATION dst_fbi;
// Get destination file's current metadata
pNtQueryInformationFile(fileDst, &ioStat, &dst_fbi,
sizeof(FILE_BASIC_INFORMATION), FileBasicInformation);
// Replace timestamps
dst_fbi.LastWriteTime = src_fbi.LastWriteTime;
dst_fbi.LastAccessTime = src_fbi.LastAccessTime;
dst_fbi.ChangeTime = src_fbi.ChangeTime;
dst_fbi.CreationTime = src_fbi.CreationTime;
Step 6: Write Modified Metadata Back
pNtSetInformationFile(
fileDst, // File handle
&ioStat, // Status block
&dst_fbi, // Modified structure
sizeof(FILE_BASIC_INFORMATION), // Buffer size
FileBasicInformation // Information class
);
π¬ How It Works (Flow)
βββββββββββββββββββββββββββββββββββββββββββββββββββ
β SOURCE FILE DESTINATION FILE β
β (kernel32.dll) (malware.exe) β
βββββββββββββββ¬βββββββββββββββββββββββ¬βββββββββββββ
β β
β β
ββββββββββββββββ ββββββββββββββββ
β Query β β Query β
β Timestamps β β Timestamps β
ββββββββ¬ββββββββ ββββββββ¬ββββββββ
β β
β β
ββββββββββββββββ ββββββββββββββββ
β CreationTime β β CreationTime β
β LastAccess β β LastAccess β
β LastWrite β β LastWrite β
ββββββββ¬ββββββββ ββββββββ¬ββββββββ
β β
βββββββββββ¬ββββββββββββ
β
COPY TIMESTAMPS
β
ββββββββββββββββ
β SetFileInfo β
β Write Back β
ββββββββ¬ββββββββ
β
β
SUCCESS
π Real-World Lab Results
I tested this on Windows 10/11. Here's what happens:
Before Timestomping:
C:\> dir /tc test.txt
07/10/2026 10:13 PM
C:\> dir /tw test.txt
07/10/2026 10:15 PM
After timestomping (using kernel32.dll as source):
C:\> dir /tc test.txt
04/30/2026 10:30 PM
C:\> dir /tw test.txt
04/30/2026 10:30 PM
The file now appears to have been created and modified in Aprilβmonths agoβeven though we modified it today.
π¨ Why Timestomping Alone Doesn't Work
Here's the critical part: timestomping is easily detected by forensic examiners.
Why Timestamps Can't Be Trusted Alone
-
Creation Time < Last Write Time
- If a file's creation time is after its last write time, something is wrong
- Legitimate behavior: Creation β€ Last Write (always)
-
The NTFS USN Journal
- NTFS maintains a Change Journal recording all file modifications
- This journal is harder to modify than file timestamps
- Forensic examiners cross-reference timestamps with USN entries
-
Event Logs
- Windows logs application behavior in
Event Viewer - A process execution is recorded regardless of file timestamps
- Malware execution can be tied to specific processes
- Windows logs application behavior in
-
Link Files & Prefetch
- Windows creates
.lnkfiles with accurate timestamps - Prefetch files (
C:\Windows\Prefetch\) log application execution - These are harder to modify than file times
- Windows creates
-
MFT Analysis
- The Master File Table stores multiple timestamp variations
- Some entries are resistant to modification
- Examiners compare MFT entries with user-visible timestamps
How Forensic Examiners Detect Timestomping
Timeline:
βββ File timestamps: April 30
βββ USN Journal: July 10 β
MISMATCH
βββ Windows Event Log: July 10 β
MISMATCH
βββ Prefetch: July 10 β
MISMATCH
βββ MFT Record: July 10 β
MISMATCH
CONCLUSION: Timestamps are forged
π‘οΈ Forensic Recommendations
If you're on the defense side, here's how to strengthen your detection:
- Collect Multiple Data Sources
β
File timestamps
β
USN Journal
β
Windows Event Logs
β
Prefetch files
β
Link files
β
MFT analysis
β
Application logs
-
Monitor File Modifications
- Use File Integrity Monitoring (FIM) tools
- Alert on suspicious timestamp changes
- Correlate with process execution logs
-
Hardening
- Implement filesystem auditing
- Enable USN Journal on critical partitions
- Use WDAC (Windows Defender Application Control) to restrict executable creation
- Monitor
ntdll.dllfunction calls (suspicious if processes callNtSetInformationFile)
π Technical Concepts You'll Learn
By studying this code, you'll understand:
β Windows Internals
- NTFS file system structures
- Master File Table (MFT)
- File timestamps and their representations
β Native APIs
- How Win32 abstracts the kernel
- Undocumented API usage
- Dynamic API resolution
β Forensics & Incident Response
- Timeline reconstruction
- Artifact correlation
- Evidence integrity checks
β Malware Analysis
- Common evasion techniques
- Timestamp manipulation detection
- Attribution challenges
π Resources & Further Reading
Windows Internals:
Forensics:
NTFS Deep Dive:
Malware Analysis:
π¦ Full Repository
Check out the complete working code:
GitHub: zainsial866/timestomper
What's included:
- β Complete C source code
- β Detailed README with examples
- β Lab notes documenting behavior
- β Header files with structure definitions
- β Compilation instructions
βοΈ Legal & Ethical Note
This tool is for educational purposes and authorized security research only.
Modifying file timestamps without authorization may violate:
- π Computer Fraud & Abuse Act (CFAA)
- π Evidence tampering laws
- π Your organization's security policy
Always get explicit authorization before testing on any system.
π― Conclusion
Timestomping is a powerful technique that demonstrates:
- How easily file metadata can be modified
- Why forensic investigators use multiple data sources
- The importance of understanding Windows internals
- How attackers hide their footprints
But it's also a reminder that no single artifact tells the whole story. Modern incident response requires correlation across logs, events, and file system metadata.
If you're building a SOC, hunting for threats, or just curious about Windows internalsβunderstanding timestomping is critical.
Have thoughts on forensics, Windows internals, or cybersecurity? Drop a comment below. π
Want to see more deep dives like this? Follow for more technical content on offensive security, Windows research, and malware analysis.
About the Author
I'm a cybersecurity student at SS-CASE-IT focusing on offensive security, Windows internals, and tool development. I post technical content on GitHub and maintain a blog covering CTF writeups, security research, and system internals.
Connect with me:
Last updated: July 2026
Top comments (0)