Overview
Thegetenv action retrieves environment variable values from local and remote systems by querying the Win32_Environment WMI class. It can retrieve all environment variables or specific variables by name.
Syntax
Parameters
| Parameter | Required | Description |
|---|---|---|
action | Yes | Must be getenv |
name | No | Variable name(s), comma-separated. If omitted, retrieves all |
computername | No | Target host(s), comma-separated. Defaults to localhost |
username | No | Username for authentication |
password | No | Password for authentication |
Usage Examples
Get All Environment Variables
Get Specific Variables
Example Output
Environment Variable Scope
Environment variables have different scopes:| Scope | UserName Value | Description |
|---|---|---|
| System | <SYSTEM> | System-wide variables |
| User | DOMAIN\username | User-specific variables |
| Volatile | Varies | Temporary session variables |
Operational Use Cases
Scenario 1: Information Gathering
Scenario 2: Detect Security Tools
- AV installation paths
- EDR agent directories
- Security monitoring tools
- Defensive software
Scenario 3: Credential Hunting
- Custom credential variables
- API keys in environment
- Database connection strings
- Service account info
Scenario 4: Exfiltration Channel
Common Environment Variables
System Information
| Variable | Description |
|---|---|
COMPUTERNAME | Computer name |
USERDOMAIN | User’s domain |
USERNAME | Current username |
OS | Operating system |
PROCESSOR_ARCHITECTURE | CPU architecture |
NUMBER_OF_PROCESSORS | Processor count |
Paths
| Variable | Description |
|---|---|
PATH | Executable search paths |
TEMP / TMP | Temporary directory |
APPDATA | Application data directory |
LOCALAPPDATA | Local application data |
USERPROFILE | User profile directory |
PROGRAMFILES | Program Files directory |
SystemRoot | Windows directory |
User Session
| Variable | Description |
|---|---|
SESSIONNAME | Session name (Console, RDP) |
LOGONSERVER | Domain controller used for logon |
USERDNSDOMAIN | User’s DNS domain |
Remote vs Local Usage
- Local Query
- Remote Query
- No network traffic
- No authentication required
- Immediate results
Detection Considerations
WMI Detection
WMI Detection
- WMI queries for
Win32_Environmentclass - Event ID 5857: WMI activity
- Sysmon Event ID 19-21: WMI operations
Unusual Queries
Unusual Queries
- Environment variable enumeration from unusual sources
- Bulk environment queries across systems
- Queries for sensitive variables
Best Practices
Operational Security
- Limit query frequency
- Blend with legitimate admin activity
- Use specific variable names when possible
- Avoid bulk enumeration
Data Analysis
- Filter system variables
- Focus on user-specific values
- Look for credentials in variables
- Identify security tool paths
Troubleshooting
Variable Not Found
Variable Not Found
Cause: Variable doesn’t existSolution:
- Check variable name spelling
- Variable may be user-specific
- Run without
nameparameter to see all variables
Access Denied
Access Denied
Cause: Insufficient privilegesSolution:
- Use
usernameandpasswordparameters - Verify admin rights on target
Empty Results
Empty Results
Cause: No matching variablesSolution:
- Verify WMI service is running
- Check variable scope (system vs user)
- Try querying all variables first
Related Actions
setenv
Set environment variable values
delenv
Delete environment variables
query
Custom WMI queries
ps
List processes
Alternative Query
Custom WMI Query
Custom WMI Query