File Timestamps (mtime, ctime, atime)

File Timestamps (mtime, ctime, atime)

One-liner: Metadata timestamps on Unix/Linux files that record when content was modified, metadata was changed, and when the file was last accessedβ€”critical for forensic timeline analysis.

🎯 What Is It?

Unix-based systems maintain three primary timestamps for every file and directory:

Timestamp Full Name What It Records
mtime Modify Time Last time file contents were modified
ctime Change Time Last time file metadata was changed (permissions, ownership, filename)
atime Access Time Last time file was accessed/read

πŸ€” Why It Matters

πŸ”¬ How It Works

Core Principles

  1. Every file operation updates specific timestamps
  2. Timestamps are stored in the inode (filesystem metadata structure)
  3. Reading a file updates atime (unless mounted with noatime)
  4. Modifying content updates both mtime and ctime
  5. Changing permissions/ownership updates only ctime

Technical Deep-Dive

Viewing Timestamps

# View mtime (default ls behavior)
ls -l /var/www/html/assets/reverse.elf

# View ctime (change time)
ls -lc /var/www/html/assets/reverse.elf

# View atime (access time)
ls -lu /var/www/html/assets/reverse.elf

# View all three timestamps at once
stat /var/www/html/assets/reverse.elf

Timestamp Behavior Examples

Action mtime ctime atime
Create new file βœ… βœ… βœ…
Edit file content βœ… βœ… -
chmod (change permissions) - βœ… -
chown (change owner) - βœ… -
Rename/move file - βœ… -
Read file (cat, less) - - βœ…
Copy file (creates new inode) βœ… (new) βœ… (new) βœ… (new)

stat Command Output

$ stat /var/www/html/assets/reverse.elf
  File: /var/www/html/assets/reverse.elf
  Size: 250       	Blocks: 8          IO Block: 4096   regular file
Device: ca01h/51713d	Inode: 526643      Links: 1
Access: (0755/-rwxr-xr-x)  Uid: (   33/www-data)   Gid: (   33/www-data)
Access: 2024-02-13 02:31:29.256000000 +0000  # atime
Modify: 2024-02-13 00:26:28.000000000 +0000  # mtime
Change: 2024-02-13 00:34:50.679215113 +0000  # ctime
 Birth: -

πŸ›‘οΈ Detection & Prevention

How to Detect

Find Recently Modified Files

# Files modified in last 24 hours
find / -type f -mtime -1 2>/dev/null

# Files with ctime changed in last 5 minutes
find / -type f -cmin -5 2>/dev/null

# Files accessed in last hour
find / -type f -amin -60 2>/dev/null

Forensic Investigation Pattern

# 1. Identify suspicious binary
ls -l /var/tmp/bash

# 2. Check all timestamps
stat /var/tmp/bash

# 3. Compare to known-good binary
md5sum /var/tmp/bash /bin/bash

# 4. Check what else was modified around that time
find / -type f -newermt "2024-02-13 00:30" ! -newermt "2024-02-13 00:40" 2>/dev/null

How to Prevent / Mitigate

πŸ“Š Types/Categories

Scenario Key Timestamp Why It Matters
Malware dropped mtime = when created Initial compromise timeline
Config tampering mtime + ctime When attacker modified settings
Backdoor account creation ctime on /etc/passwd When user was added
Log deletion ctime (if deleted) or mtime (if truncated) Evidence of anti-forensics
Evidence of access atime (unreliable in live systems) What files attacker viewed

🎀 Interview Angles

Common Questions

STAR Story

Situation: Investigating a compromised web server where attacker uploaded a malicious binary.
Task: Establish timeline of the attack and identify all affected files.
Action: Used stat on suspicious binary to get mtime (file creation time). Ran find / -newermt to identify all files modified within Β±10 minutes of that timestamp. Cross-referenced with web server logs showing initial exploit. Discovered attacker modified /etc/passwd (ctime), uploaded reverse shell (mtime), and accessed multiple config files (atime before imaging).
Result: Built complete timeline showing: initial exploit (10:26), binary upload (10:26), privilege escalation (10:34), persistence via SSH key (10:34). Timeline matched log evidence and enabled us to scope the full extent of compromise.

βœ… Best Practices

❌ Common Misconceptions

πŸ“š References