[Osquery_manager] Prefetch artifact saved query #16067
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Windows Prefetch Artifact
The Windows Prefetch artifact provides critical forensic visibility into program execution history on Windows systems. Prefetch (.pf) files automatically track application launches, execution counts, timestamps, and file/directory access patterns, making them invaluable for detecting malicious program execution, lateral movement, and persistence mechanisms.
Read https://p.elstc.co/paste/otT8aNps#MwungD8BCsjzA5MFfHfXPQqUhCD+eVAXPGs65MQPBVA
Core Forensic Artifacts Coverage
Queries by Platform
🪟 Windows - Program Execution History and Forensic Intelligence
Description
Investigates Windows Prefetch artifacts to track program execution history across the system. Prefetch files (.pf) are automatically created by Windows to optimize application load times, but they also serve as a critical forensic data source. This query uses the native Osquery prefetch table to parse .pf files and extract execution intelligence including executable names, MD5 hashes, run counts, last execution timestamps, and accessed file/directory patterns. The query is filtered to executables run within the last 90 days to reduce noise while maintaining detection capabilities for recent threats. Results are capped at 1024 entries (matching Windows prefetch directory limit).
Detection Focus:
Result
Query returns comprehensive execution history including:
Platform
windowsInterval
3600seconds (1 hour)Query ID
prefetch_windows_elasticECS Field Mappings
process.name→filenamefile.name→filenameprocess.hash.md5→hashevent.created→last_execution_timeevent.sequence→run_countfile.size→sizehost.id→volume_serialfile.path→accessed_filesfile.directory→accessed_directoriesfile.path→prefetch_file_pathSQL Query
Implementation Notes
This query leverages Osquery's native
prefetchtable to parse Windows Prefetch artifacts directly, providing equivalent functionality to Velociraptor'sWindows.Forensics.Prefetchartifact. The 90-day time window (7,776,000 seconds) balances forensic depth with performance, focusing on recent execution activity most relevant for threat detection. The 1024 result limit aligns with Windows' maximum prefetch directory capacity, ensuring complete coverage of the prefetch cache.