File and Directory Discovery
| Technique | File and Directory Discovery (T1083) |
| Tactic | Discovery |
| Platforms | ESXi, Linux, macOS, Network Devices, Windows |
Overview
File and Directory Discovery (T1083) refers to adversaries actively enumerating the file system — listing directories, searching for specific file types, and mapping out where sensitive data lives on a host or network share. Attackers use this information to locate credentials, configuration files, backups, intellectual property, and staging areas before pivoting to their actual objective.
Because file enumeration is a near-universal step in both targeted intrusions and commodity malware campaigns, detecting it early gives defenders a high-value chokepoint — one of the few opportunities to catch an attacker before they’ve achieved their actual goal. Missing this technique means missing critical pre-exfiltration and pre-lateral-movement signals.
Attacker Perspective
Attackers enumerate files and directories immediately after gaining initial access to understand the environment, validate they’re on the right target, and identify where their most valuable data resides.
- Credential harvesting setup: Threat actors run
dir /s /b C:\Users\*\AppData\Roaming\Microsoft\Credentials\*orfind / -name "*.kdbx" 2>/dev/nullto locate password databases, browser credential stores, and SSH keys before running dedicated dumping tools. - Ransomware pre-encryption staging: Ransomware families like LockBit use
tree /F /A C:\or custom file-walker binaries to build a complete file inventory, then filter for high-value extensions (e.g.,.docx,.sql,.bak) to prioritize encryption targets. - Data exfiltration targeting: APT groups use PowerShell such as
Get-ChildItem -Recurse -Include *.pdf,*.xlsx -Path C:\Usersor Linuxlocate -i "confidential"to find documents matching keyword patterns before staging them for exfiltration. - Network device reconnaissance: Adversaries with access to Cisco or similar devices run
dir flash:,show nvram, ordir all-filesystemsto enumerate configuration files and firmware images that could reveal credentials or architecture details.
This technique is attractive because it uses built-in OS tools that generate minimal noise, blends naturally with legitimate admin activity, and provides the attacker with a precise roadmap of the environment at essentially zero cost.
Detection Strategy
Required Telemetry
- Windows — Process Creation (Event ID 4688): Enable via GPO:
Computer Configuration → Windows Settings → Security Settings → Advanced Audit Policy → Detailed Tracking → Audit Process Creation = Success. Also enable command-line logging:HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System\Audit → ProcessCreationIncludeCmdLine_Enabled = 1. Without command-line capture, you will only see the process name and miss the actual discovery commands. - Windows — Sysmon Event ID 1 (Process Create): Deploy Sysmon with a configuration that captures
CommandLine,ParentImage,User,Hashes, andCurrentDirectory. Sysmon provides richer data than native 4688 and is the preferred source where available. Minimum Sysmon config should include rules fordir,tree,find,where, and PowerShell discovery cmdlets. - Windows — PowerShell Script Block Logging (Event ID 4104): Enable via GPO:
Computer Configuration → Administrative Templates → Windows Components → Windows PowerShell → Turn on PowerShell Script Block Logging = Enabled, or set registry keyHKLM\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging → EnableScriptBlockLogging = 1. This captures the actual content of PowerShell commands includingGet-ChildItemandInvoke-Expressionwrappers that would otherwise be obfuscated. - Windows — PowerShell Module Logging (Event ID 4103): Enable via GPO alongside Script Block Logging:
Turn on Module Logging = Enabled, then set*in the module names list to capture all modules. This catches pipeline execution details that 4104 may miss. - Linux — auditd Process Execution Rules: Add the following rules to
/etc/audit/rules.d/discovery.rules:
-a always,exit -F arch=b64 -S execve -F exe=/usr/bin/find -k file_discovery,
-a always,exit -F arch=b64 -S execve -F exe=/usr/bin/ls -k file_discovery,
-a always,exit -F arch=b64 -S execve -F exe=/usr/bin/locate -k file_discovery,
-a always,exit -F arch=b64 -S execve -F exe=/usr/bin/tree -k file_discovery.
These generateEXECVEandPROCTITLEaudit records with full arguments. Restart auditd after changes:service auditd restart. - Linux — auditd with ausearch/aureport or forwarded to SIEM via auditbeat/Filebeat: If using Elastic, deploy Auditbeat with the
auditdmodule enabled. If using Splunk, use the Splunk Add-on for Unix and Linux which reads/var/log/audit/audit.log. Ensure log forwarding is configured so records tagged withkey=file_discoveryreach the SIEM. - macOS — Endpoint Security Framework / Unified Log: Use an EDR agent (CrowdStrike, SentinelOne, Microsoft Defender for Endpoint) that hooks the Endpoint Security Framework to capture
es_event_exec_tevents, which provide process arguments for commands likels,find, andmdfind. Alternatively, enable OpenBSM auditing: setlo,exflags in/etc/security/audit_controlto capture exec events, then restart the audit daemon withaudit -s. - ESXi — Shell and API Logging: Enable ESXi Shell and SSH logging by configuring syslog to forward to your SIEM: set
Syslog.global.logHostvia vSphere or esxcli. Shell commands executed via the ESXi shell generate entries in/var/log/shell.log; ensure this file is included in the syslog forwarding configuration. - EDR Telemetry (cross-platform): If you have CrowdStrike Falcon, Microsoft Defender for Endpoint, or SentinelOne deployed, these provide pre-normalized process execution events with parent/child relationships and command lines. This is the highest-fidelity source and should be the primary detection layer where available, supplementing or replacing native OS log sources.
- Network Device CLI Logging: Enable
archive log configandloggingon Cisco IOS/IOS-XE devices and forward syslog to your SIEM. Commands likedir,show flash, anddir all-filesystemswill appear in the command authorization log if AAA command accounting is configured:aaa accounting commands 15 default start-stop group tacacs+.
Key Indicators
- Windows CMD discovery bursts: In Event ID 4688 or Sysmon Event ID 1, look for
Imageending incmd.exeortree.comwithCommandLinecontaining patterns likedir /s,dir /b,tree /F, orwhere /r. Especially suspicious whenParentImageis a non-standard parent such asmshta.exe,wscript.exe,cscript.exe,rundll32.exe, or any Office application. - PowerShell file enumeration: In Event ID 4104 (Script Block Log), look for
ScriptBlockTextcontainingGet-ChildItemor its aliasgcicombined with flags like-Recurse,-Include, or-Filtertargeting sensitive paths such asC:\Users,C:\Windows\System32\config,ADMIN$, or\\UNC paths. Example pattern:Get-ChildItem -Recurse -Include *.config,*.xml,*.kdbx. - Linux rapid find/locate execution: In auditd records with
key=file_discovery, look forEXECVErecords wherea0=findwith arguments targeting sensitive paths:/etc/passwd,/home/,/root/,/var/backups/,/.ssh/, or searching for extensions like-name "*.pem",-name "*.key",-name "id_rsa". Also flaglocate -i passwordorlocate .ssh. - Unusual process spawning discovery tools: In Sysmon Event ID 1 or EDR telemetry, flag when
find.exe(Windows),tree.com, orwhere.exeis spawned by unexpected parents:ParentImagein (powershell.exe,python.exe,java.exe,node.exe,nginx.exe,apache.exe). These suggest web shell or scripting-engine-based post-exploitation. - High-volume file enumeration in short window: In any process execution log, look for the same
UserorProcessIdgenerating more than 20 file/directory listing commands within a 60-second window. This pattern is characteristic of automated post-exploitation frameworks like Cobalt Strike, Metasploit, or custom C2 agents running file walker modules. - Sensitive directory targeting: In any log source, flag enumeration commands that explicitly reference high-value paths:
C:\Windows\NTDS\,C:\Windows\System32\config\,/etc/shadow,/etc/sudoers,~/.ssh/,/var/lib/,\\ADMIN$,\\C$,\\SYSVOL, or\\NETLOGON. - macOS mdfind/spotlight abuse: In EDR or Unified Log, look for
mdfindinvocations with queries targeting credential-related terms:mdfind -name ".pem",mdfind kMDItemDisplayName = "*password*", ormdfind -onlyin /Users kind:documentspawned from a non-GUI process. - Network device file enumeration: In syslog from network devices, look for AAA command accounting entries containing
dir flash:,dir nvram:,show flash, ordir all-filesystemsfrom user accounts that do not normally access device CLIs interactively, or from source IPs not in your approved management network.
Detection Logic
Rule 1 (Broad — High Sensitivity): Windows File Discovery via Built-in CLI Tools
IF process.name IN ("cmd.exe", "powershell.exe", "pwsh.exe")
AND process.command_line MATCHES ("dir /s", "dir /b", "tree /F", "where /r", "Get-ChildItem.*-Recurse", "gci.*-Recurse")
AND NOT process.parent.name IN ("explorer.exe", "svchost.exe")
AND NOT user.name IN [known_admin_service_accounts]
THEN alert(severity=LOW, rule="T1083 - File Discovery via CLI")
This broad rule catches the majority of interactive and scripted file enumeration on Windows. Expect moderate-to-high volume (10–50 alerts/day in a typical enterprise) and use it primarily as a hunting baseline. The exclusion of explorer.exe parents removes most user-initiated GUI file browsing.
Rule 2 (Medium — Balanced): File Discovery from Anomalous Parent Process
IF process.name IN ("cmd.exe", "powershell.exe", "find.exe", "where.exe", "tree.com", "ls", "find", "locate")
AND process.command_line MATCHES ("dir /s", "/s /b", "-Recurse", "find / ", "find /home", "find /etc", "locate *.key", "locate *.pem")
AND process.parent.name IN ("mshta.exe", "wscript.exe", "cscript.exe", "rundll32.exe", "regsvr32.exe", "python.exe", "python3", "java.exe", "node.exe", "WINWORD.EXE", "EXCEL.EXE", "nginx", "apache2", "httpd")
THEN alert(severity=HIGH, rule="T1083 - File Discovery from Suspicious Parent")
This rule targets a high-confidence pattern: discovery tools being called from script interpreters, Office applications, or web server processes — all classic indicators of initial access exploitation or web shell activity. Expect low volume (0–5 alerts/day) with high fidelity.
Rule 3 (Targeted — High Precision): Enumeration of Sensitive System Paths
IF process.command_line MATCHES (
"C:\\Windows\\NTDS", "System32\\config", "/etc/shadow", "/etc/passwd",
"\\.ssh", "id_rsa", "*.kdbx", "*.pfx", "*.key", "ADMIN$", "\\SYSVOL",
"\\NETLOGON", "/var/backups", "/root/.bash_history"
)
AND process.name IN ("cmd.exe", "powershell.exe", "find.exe", "find", "locate", "mdfind", "grep")
AND NOT process.name = "antivirus_scanner.exe"
AND NOT user.name IN [known_security_scanning_accounts]
THEN alert(severity=CRITICAL, rule="T1083 - Sensitive Path Enumeration")
This rule is narrowly scoped to file system searches that directly target credential stores, SSH keys, AD databases, and certificate files. Any hit here warrants immediate investigation. Expected volume: 0–2 alerts/day with very high true-positive rate. Tune out known vulnerability scanners and DLP agents by their process or user names.
Rule 4 (Behavioral — Burst Detection): High-Frequency File Enumeration in Short Window
IF COUNT(process.name IN ("dir", "ls", "find", "tree", "Get-ChildItem", "locate"))
WHERE user.name = same_user AND host.name = same_host
WITHIN 60 seconds > 15
AND NOT user.name IN [backup_service_accounts, software_deployment_accounts]
THEN alert(severity=MEDIUM, rule="T1083 - High-Frequency File Discovery Burst")
This rule catches automated file walkers embedded in post-exploitation frameworks that rapidly enumerate multiple directories in sequence. A human typing commands rarely exceeds 15 discovery commands per minute. Tune the threshold based on your environment’s baseline; backup software and software deployment tools (SCCM, Ansible) may legitimately exceed this threshold and should be excluded by service account name.
Tuning Guidance
- IT Administration and Helpdesk Scripts: Legitimate sysadmin scripts frequently use
dir /s,Get-ChildItem -Recurse, andfindfor software inventory, log collection, and troubleshooting. Exclude by addinguser.name IN [known_admin_accounts]ANDprocess.parent.name IN ("psexec.exe", "schtasks.exe", "wsmprovhost.exe")only when the source host is an identified management workstation (host.name IN [admin_jump_hosts]). - Backup and Archiving Software: Agents like Veeam, Backup Exec, Commvault, and Windows Backup enumerate the file system constantly as part of normal operation. Identify their service account names (e.g.,
svc_veeam,svc_backup) and excludeuser.name IN [backup_service_accounts]or exclude byprocess.parent.name IN ("VeeamAgent.exe", "BackupExecAgentAccelerator.exe"). - Antivirus and EDR Scanners: Security products perform their own file system traversal. Exclude by process name or hash: add
AND NOT process.parent.name IN ("MsMpEng.exe", "SentinelAgent.exe", "CSFalconService.exe", "cylancesvc.exe")to rules where these generate noise. - Software Deployment Tools: SCCM, Ansible, Puppet, Chef, and similar tools run discovery commands during inventory collection. Exclude
process.parent.name IN ("ccmexec.exe", "ansible", "puppet", "chef-client")or the associated service accounts. - Developer Workstations: Developers routinely run
find,ls -la,Get-ChildItem, and similar commands in terminals. Consider scoping your detection rules to server assets and excluding endpoints tagged as developer workstations (host.tags NOT CONTAINS "developer") from the broadest rules while keeping sensitive-path rules enabled everywhere. - CI/CD Pipelines: Build agents (Jenkins, GitHub Actions runners, Azure DevOps agents) frequently traverse file systems as part of build and test steps. Identify their host names or service accounts and create an explicit allowlist exclusion for these sources.
When the Alert Fires: Investigation Steps
- Verify the alert is real: Pull the raw event from the source log (Sysmon Event ID 1, auditd EXECVE record, or EDR telemetry) and confirm the
CommandLine,ProcessId,User, andTimestampfields are populated and match the alert. Do not rely solely on the SIEM alert summary — inspect the raw log to rule out parsing errors or false field extractions. - Identify the affected host and user: Confirm the hostname, IP address, and OS version from your asset inventory, and determine whether the account that executed the command is a standard user, service account, or privileged account. Flag immediately if the user has Domain Admin, local Administrator, or root privileges, as the blast radius is substantially larger.
- Pull the full process chain: In your EDR console or SIEM, query for all processes with the same
ProcessGuid(Sysmon) orSessionIdand trace the full parent-child chain back to the originating process. Look specifically for whether the chain originates from a browser, Office document, web server, or remote access tool — this determines whether you are dealing with exploitation, phishing, or insider threat. - Identify what was targeted: Review the exact
CommandLinearguments to determine which paths and file types were enumerated. Cross-reference the targeted paths against your data classification inventory — enumeration of paths containing credentials, source code, PII, or financial data significantly escalates severity and should trigger immediate escalation to Tier 2. - Check for network connections and files written to disk: In Sysmon Event ID 3 (Network Connection) and Event ID 11 (File Create), or equivalent EDR events, look for outbound connections or new files created by the same process or user within 10 minutes of the discovery activity. Enumeration followed by an outbound connection or a new compressed archive (
.zip,.7z,.tar.gz) is a strong indicator of active exfiltration staging. - Look for lateral movement from this host: Query your SIEM for Event ID 4624 (Logon) with
LogonType = 3(network) originating from this host, SMB connections (port 445) in NetFlow or firewall logs, and WMI or WinRM execution events (Sysmon Event ID 1 withparent = WmiPrvSE.exeorwsmprovhost.exe) within the 2-hour window following the discovery activity. If other hosts are involved, scope them into the investigation immediately. - Escalation decision: Treat the alert as a confirmed incident requiring escalation if any of the following are true: the process chain originates from an exploitation vector (browser, Office, web shell); sensitive credential or AD-related paths were targeted; network connections followed the discovery activity; or the user account is privileged and the activity falls outside documented maintenance windows. Treat it as benign and close after documenting if the process chain is entirely consistent with a known admin or backup tool, the user has a documented ticket or change record, and no sensitive paths or follow-on activity were observed.
Response Playbook
Containment
- Isolate the host (leave it powered on): Use your EDR console (CrowdStrike Network Containment, Microsoft Defender for Endpoint Device Isolation, or SentinelOne Network Quarantine) to isolate the host from the network immediately while preserving it for forensic memory capture. Do not power off — volatile memory may contain active C2 connections, encryption keys, or injected shellcode.
- Disable the affected user account: In Active Directory, run
Disable-ADAccount -Identity [username]or use the Azure AD portal to disable the account. If the account is a service account, coordinate with the application owner before disabling, but prioritize containment if active compromise is confirmed. - Kill the identified malicious process: If the process is still running, use your EDR to terminate it by
ProcessId. Document the PID, process name, hash, and parent before terminating. Do not simply close a terminal window on the host — use the EDR to ensure the kill is logged and complete. - Block identified C2 IPs and domains: If outbound network connections were identified in step 5 of the investigation, immediately submit the IPs and domains to your firewall team or SOAR playbook for blocking at the perimeter firewall and internal DNS sinkhole. Also add them to your proxy block list if one exists.
- Revoke active sessions and tokens: Invalidate all active Kerberos tickets for the affected account using
klist purgeon the host, or force a ticket invalidation viaSet-ADUser -Identity [username] -Replace @{msDS-SupportedEncryptionTypes=0}followed by a password reset. For cloud-integrated environments, revoke OAuth tokens and Azure AD refresh tokens via the Microsoft Entra portal orRevoke-AzureADUserAllRefreshToken.
Eradication
- Remove identified persistence mechanisms: Check for new scheduled tasks (Event ID 4698), registry run keys (
HKCU\Software\Microsoft\Windows\CurrentVersion\Run,HKLM\Software\Microsoft\Windows\CurrentVersion\Run), new services (Event ID 7045), and WMI subscriptions (Get-WMIObject -Namespace root\subscription -Class __EventFilter). Remove any entries not present in your approved baseline. - Search for and delete dropped payloads: Use your EDR’s file search capability or query Sysmon Event ID 11 (File Create) for any new executables, scripts, or archives created by the malicious process or user in the hours surrounding the incident. Pay particular attention to
%TEMP%,%APPDATA%,C:\ProgramData\,/tmp/, and/var/tmp/. Delete confirmed malicious files and submit hashes to your threat intelligence platform. - Reset credentials for all involved accounts: Force a password reset for the affected user account and any service accounts whose credentials may have been visible in the enumerated files. If the attacker accessed
C:\Windows\System32\config\or the NTDS database path, treat the entire domain as potentially compromised and initiate a full Kerberoastable account and krbtgt password reset. - Check lateral movement targets for backdoors: For every host identified in investigation step 6, run the same persistence checks (scheduled tasks, registry run keys, new services, WMI subscriptions) and look for the same file hashes and process names found on the initially compromised host. Do not assume a clean bill of health without active verification.
- Rotate secrets and API keys that may have been exposed: If the enumerated paths included cloud credential files (
~/.aws/credentials,~/.azure/,gcloudconfig directories,.envfiles, or application configuration files with embedded secrets), rotate those credentials immediately in the respective cloud console and audit CloudTrail/Azure Activity Log/GCP Audit Log for any use of those credentials from unexpected IPs or time windows.
Recovery
- Verify the host is clean before reconnecting: Before removing network isolation, run a full AV/EDR scan, review all persistence locations one final time, and confirm no unexpected listening ports or scheduled tasks remain. If confidence in the host’s integrity is below 90%, re-image from a known-good baseline rather than attempting to clean in place — the cost of re-imaging is always lower than the cost of a second breach from an overlooked backdoor.
- Re-enable the user account only after confirming no persistence remains: Coordinate with the user’s manager and confirm the account is clean, the password has been reset, and MFA has been re-enrolled before
Stay Ahead
Get daily threat intelligence and detection playbooks.
Free. No account. No email. Follow in Feedly, Inoreader, or any RSS reader.