macOS-optimized scripts to preserve file modification timestamps while editing.
These scripts help you edit files while maintaining their original "Modified" date in Finder. This is useful when you need to preserve the appearance of when a file was last modified, even after editing it.
These scripts were developed for red teaming and security testing purposes. They enable security professionals to:
- Create Authentic Bait Files: Generate files that appear to have been created or modified at specific historical dates, making them more convincing for honeypots and deception operations
- Maintain Operational Security: Edit files during red team exercises without leaving obvious traces of recent modification timestamps
- Test Security Controls: Evaluate how security tools and analysts respond to files with manipulated timestamps
- Simulate Historical Artifacts: Create files that blend into existing file systems by matching modification dates of surrounding files
Ethical Use: These scripts are intended for authorized security testing, red team exercises, and legitimate security research only. Unauthorized use to deceive or harm is strictly prohibited.
The scripts work with any file type:
- Office documents (
.docx,.xlsx,.pptx, etc.) - Text files (
.txt,.md,.json, etc.) - Images, videos, PDFs
- Any file you can edit with applications
These scripts automatically detect macOS and use appropriate commands:
Monitors file changes and automatically restores timestamp after saving.
Captures the current timestamp before editing.
Restores the timestamp after editing.
./preserve_metadata.sh yourfile.extThis script will:
- Capture the current modification time
- Open the file in your default application
- Monitor for changes and automatically restore the timestamp when you save
# Step 1: Capture timestamp before editing
./capture_timestamp.sh yourfile.ext
# Step 2: Edit file normally, then save
# Step 3: Restore timestamp after editing
./restore_timestamp.sh yourfile.extIf you have a backup with the desired timestamp:
./restore_timestamp.sh yourfile.ext reference_file.ext-
Make the scripts executable:
chmod +x *.sh -
The scripts automatically detect macOS and use:
stat -f %m <file>- Get modification timetouch -mt <YYYYMMDDHHMM.SS> <file>- Set modification timeopen <file>- Open in default application
The scripts use macOS system tools to:
- Capture the original file modification time using
stat -f %m - Allow normal editing - file content updates normally
- Restore the original filesystem timestamp using
touch -mt
When using these scripts for red team operations:
-
Forensic Detection: Advanced forensic tools may detect timestamp manipulation through:
- File system journal analysis
- MAC (Modified, Accessed, Created) time inconsistencies
- Application-level metadata (e.g., Office document properties)
- File content hash changes without timestamp updates
-
Best Practices:
- Use reference files from the target environment when possible
- Test timestamp restoration on similar systems before operations
- Consider application-specific metadata that may reveal manipulation
- Document timestamp changes for post-operation analysis
- File Content Changes: File content updates normally - only filesystem timestamp is preserved
- File Permissions: Scripts need read/write access to files
- Monitoring Accuracy: Automated script monitors file size changes
- Application Internal Metadata: Some applications maintain internal metadata that cannot be preserved while saving changes
- Forensic Detection: These scripts only modify filesystem timestamps. Advanced forensic analysis may still detect manipulation
Ensure you have write permissions to the file and directory.
Ensure the scripts are executable: chmod +x *.sh
Check file permissions and ensure no other processes are accessing the file.
The open command may not work in all environments. Open files manually.
# Capture timestamp from a legitimate file in the target directory
./capture_timestamp.sh ~/Documents/legitimate_document.docx
# Create/edit your bait file, then restore using the captured timestamp
./restore_timestamp.sh bait_file.docx ~/Documents/legitimate_document.docx./preserve_metadata.sh report.xlsx
# Edit in Excel, save, timestamp automatically restored./capture_timestamp.sh thesis.docx
# Edit document...
./restore_timestamp.sh thesis.docxfor file in *.pdf; do
./capture_timestamp.sh "$file"
# Edit files...
./restore_timestamp.sh "$file"
doneThese scripts are provided as-is for educational and practical use.