[Osquery_manager] LNK artifacts saved query #16059
Open
+179
−8
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.
LNK Files Artifact (Windows)
Windows LNK (shortcut) files are critical forensic artifacts for detecting persistence mechanisms, user activity tracking, and malware execution. Attackers frequently abuse LNK files placed in Startup folders to achieve persistence, or craft malicious shortcuts that execute LOLBins with obfuscated payloads.
Why Two Separate Queries?
This PR introduces two complementary LNK detection queries to address a known osquery limitation:
lnk_forensics_windows_elasticlnk_yara_detection_windows_elasticThe osquery
shortcut_target_pathBugDuring development, we discovered that osquery's
shortcut_target_pathfield (and related shortcut metadata fields) always returns empty despite being documented as available since osquery 5.11.0. This affects:shortcut_target_pathshortcut_target_typeshortcut_target_locationshortcut_start_inshortcut_runshortcut_commentIssue filed: osquery/osquery#8725
Solution: Dual-Query Approach
Forensics Query (
lnk_forensics_windows_elastic): Provides comprehensive LNK file enumeration with location-based detection, file metadata, and hash enrichment. The shortcut-related ECS fields are mapped but may return empty until osquery fixes the underlying bug.YARA Query (
lnk_yara_detection_windows_elastic): Bypasses theshortcut_target_pathlimitation entirely by scanning the raw LNK binary content with YARA rules. This provides immediate detection capability for malicious LNK patterns.Core Forensic Artifacts Coverage
Queries by Platform
🪟 Windows - LNK Forensics (Metadata-Based Enumeration)
Description
Comprehensive Windows LNK shortcut file forensics across all critical locations: user/system Startup folders (persistence), Desktop folders, Recent Items (user activity), Quick Launch, SendTo menu, and Start Menu Programs. Enriched with hash values for LNK files themselves. Uses the
userstable to dynamically enumerate all user directories.Detection Focus:
Locations Covered:
%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup)C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup)Known Limitation:
shortcut_target_pathand dependent fields may return empty due to osquery parsing issue. Uselnk_yara_detection_windows_elasticfor content-based detection that bypasses this limitation.Result:

Platform
windowsInterval
3600seconds (1 hour)Query ID
lnk_forensics_windows_elasticECS Field Mappings
file.path→pathfile.name→filenamefile.directory→directoryfile.size→sizefile.created→btimefile.mtime→mtimefile.accessed→atimefile.ctime→ctimefile.type→typefile.hash.md5→md5file.hash.sha1→sha1file.hash.sha256→sha256file.extension→extensionfile.code_signature.subject_name→authenticode_subjectfile.code_signature.issuer→authenticode_issuerfile.code_signature.status→authenticode_resultprocess.executable→shortcut_target_path(may be empty)process.command_line→combined_command(may be empty)user.id→shellbags_sid(may be empty)registry.path→shellbags_source(may be empty)MITRE ATT&CK Coverage
SQL Query
🪟 Windows - LNK YARA Detection (Content-Based Scanning)
Description
YARA-based content detection of suspicious Windows LNK shortcut files. Scans LNK binary content directly for malicious patterns, bypassing osquery's
shortcut_target_pathparsing issues. Returns only files matching suspicious patterns.Detection Focus:
Technical Notes:
Result:

Platform
windowsInterval
3600seconds (1 hour)Query ID
lnk_yara_detection_windows_elasticECS Field Mappings
file.path→pathrule.name→matchesthreat.indicator.matched.atomic→stringsfile.hash.md5→md5file.hash.sha256→sha256threat.indicator.type→"file"(static value)event.category→"malware"(static value)event.type→"indicator"(static value)file.directory→location_typeMITRE ATT&CK Coverage
SQL Query
Testing Results
Both queries were validated on Windows 10/11 with test LNK files:
Related Links
shortcut_target_pathbug:shortcut_target_pathand related columns always empty infiletable on Windows osquery/osquery#8725This PR was AI assisted with Claude Code