Summary
Lists files and directories in a specified path, including file permissions, timestamps, and extended attributes. Supports both local and UNC paths with concurrent file processing and chunked responses.- Needs Admin: False
- Version: 3
- Author: @djhohnstein
Arguments
- path (String) - Directory or file path to list (defaults to current directory). Supports UNC paths like
\\DC01\C$
Usage
Detailed Summary
Agent Execution Flow
1. Parameter Processing
- Deserializes path and optional host parameters
- Handles localhost aliases (localhost, 127.0.0.1, COMPUTERNAME)
- Constructs UNC path when host specified
2. Path Resolution
- Builds UNC path format for remote hosts
- Uses
TryGetExactPathfor case-sensitive path resolution - Defaults to current directory if no path specified
3. Host Detection
- Automatically detects host from current working directory
- Extracts hostname from UNC paths
- Falls back to local computer name
4. File vs Directory Handling
Single File Processing
- Creates
FileInfoobject for single file - Extracts file metadata and permissions
- Sets
IsFileflag in response
Directory Processing
- Enumerates subdirectories and files separately
- Uses parallel processing with degree of parallelism = 2
- Processes directories and files concurrently
5. Permission Extraction
- Retrieves file security descriptor using
GetAccessControl - Extracts Access Control Entries (ACEs)
- Converts to
NTAccountformat for readable names - Handles both files and directories
6. Chunked Response Processing
- Uses concurrent queue for thread-safe file collection
- Triggers chunk events when reaching size threshold (10 files)
- Sends intermediate responses for large directories
Data Structures
FileInformation
ACE (Access Control Entry)
FileBrowser Response
Concurrent Processing
- Parallel Directory Processing: Processes subdirectories using
Parallel.ForEach - Parallel File Processing: Processes files concurrently with cancellation support
- Chunked Responses: Sends intermediate results for large directories
- Thread Safety: Uses
ConcurrentQueuefor thread-safe file collection
Error Handling
- Catches permission denied exceptions gracefully
- Provides detailed error messages with stack traces
- Continues processing remaining files on individual failures
APIs Used
MITRE ATT&CK Mapping
- T1083 - File and Directory Discovery
- T1106 - Native API
Security Considerations
- Information Disclosure: Reveals file system structure and permissions
- Access Patterns: Creates predictable file access patterns
- Performance Impact: Large directories may cause system load
- Detection Vectors: File enumeration may trigger security monitoring
Limitations
- Requires read permissions on target directories
- Large directories may cause performance impact
- UNC paths require network connectivity and credentials
- Some system directories may be restricted
- Parallel processing limited to degree of parallelism = 2
Error Conditions
- Access Denied: Insufficient permissions for path or individual files
- Path Not Found: Specified path doesn’t exist
- Network Unreachable: UNC path host not accessible
- Invalid Path: Malformed or invalid path format
- Cancellation: Operation cancelled during processing