Skip to main content

Overview

The getenv 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

Usage Examples

Get All Environment Variables

Get Specific Variables

Example Output

Environment Variable Scope

Environment variables have different scopes:

Operational Use Cases

Scenario 1: Information Gathering

Scenario 2: Detect Security Tools

Look for:
  • AV installation paths
  • EDR agent directories
  • Security monitoring tools
  • Defensive software

Scenario 3: Credential Hunting

Look for:
  • Custom credential variables
  • API keys in environment
  • Database connection strings
  • Service account info

Scenario 4: Exfiltration Channel

Common Environment Variables

System Information

Paths

User Session

Remote vs Local Usage

Advantages:
  • No network traffic
  • No authentication required
  • Immediate results

Detection Considerations

  • WMI queries for Win32_Environment class
  • Event ID 5857: WMI activity
  • Sysmon Event ID 19-21: WMI operations
  • 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

Cause: Variable doesn’t existSolution:
  • Check variable name spelling
  • Variable may be user-specific
  • Run without name parameter to see all variables
Cause: Insufficient privilegesSolution:
  • Use username and password parameters
  • Verify admin rights on target
Cause: No matching variablesSolution:
  • Verify WMI service is running
  • Check variable scope (system vs user)
  • Try querying all variables first

setenv

Set environment variable values

delenv

Delete environment variables

query

Custom WMI queries

ps

List processes

Alternative Query