// question

A Windows system shows a cmd.exe process spawn that appears to have been used for environment discovery. Review the process creation records to identify the exact command the adversary ran to enumerate environment variables.

Reference KQL answer and model-by-model comparison.

f400d1c0-1804-4ff8-b069-ef5ddd2adbf3
question id
17/23
models correct
1
valid answer
74%
success rate
// reference answer

Human-validated correct answer for this question.

set
// model comparison
ModelAnswerKQL queryStatusTriesTimeCost
gemini-2.5-flash-preview-04-17
set
DeviceProcessEvents
| where ActionType == "ProcessCreated"
| where FileName =~ "cmd.exe"
| where ProcessCommandLine contains "/c set"
| project Timestamp, DeviceName, AccountName, InitiatingProcessCommandLine, ProcessCommandLine
pass347.24s0.0237
gpt-35-turbo
no answer
no query generatedfail50.00s0.0107
gpt-4-turbo-2024-04-09
set comspec=%windir%\System32\calc.exe & cscript %windir%\System32\manage-bde.wsf
DeviceProcessEvents
| where FileName == 'cmd.exe'
| where ProcessCommandLine contains 'set' or ProcessCommandLine contains 'env' or ProcessCommandLine contains 'echo'
| project DeviceName, DeviceId, ProcessCommandLine, ProcessCreationTime
| order by ProcessCreationTime desc
pass226.05s0.1400
gpt-4.1
set comspec=%windir%\System32\cmd.exe
DeviceProcessEvents
| where FileName =~ "cmd.exe"
| where ActionType has_any ("ProcessCreated", "CreateProcess")
| where ProcessCommandLine matches regex @"(?i)set(\s|$)" 
       or ProcessCommandLine matches regex @"(?i)echo\s+%[A-Z_]+%" 
       or ProcessCommandLine matches regex @"(?i)for.*%[A-Z_]+%"
       or ProcessCommandLine matches regex @"%[A-Za-z0-9_]+%"
| project TimeGenerated, DeviceName, AccountName, FileName, ProcessCommandLine, InitiatingProcessAccountName, InitiatingProcessCommandLine
| order by TimeGenerated desc
pass534.90s0.0987
gpt-4.1-finetuned
"cmd.exe" /c set "SYSTEMROOT=C:\Windows\Temp" && cmd /c desktopimgdownldr.exe /lockscreenurl:https://raw.githubusercontent.com/redcanaryco/atomic-red-team/master/atomics/T1197/T1197.md /eventName:desktopimgdownldr
DeviceProcessEvents
| where FileName =~ "cmd.exe" and (ProcessCommandLine  has "set" )
pass114.32s0.0269
gpt-4.1-mini
set comspec=%windir%\System32\cmd.exe
DeviceProcessEvents
| where FileName == "cmd.exe"
| where ProcessCommandLine has_any ("set ", "echo %", "env")
| project DeviceName, ProcessCreationTime, ProcessCommandLine
| order by ProcessCreationTime desc
pass14.31s0.0025
gpt-4.1-nano
reg query HKLM\SYSTEM\CurrentControlSet\Control\TimeZoneInformation /v TimeZoneKeyName
DeviceProcessEvents
| where FileName =~ "cmd.exe" 
| where ProcessCommandLine contains "set" or ProcessCommandLine contains "env"
| project ProcessId, ProcessCreationTime, ProcessCommandLine, InitiatingProcessId, InitiatingProcessParentFileName, DeviceName, FileName
pass12.86s0.0009
gpt-4o
"cmd.exe" /c set comspec=%windir%\System32\cmd.exe
DeviceProcessEvents
| where FileName == "cmd.exe"
| where tolower(ProcessCommandLine) contains "set"
| project TimeGenerated, DeviceName, AccountName, AccountDomain, FileName, ProcessCommandLine
pass13.40s0.0218
gpt-5-high
set
let envVarToken = @"(?i)%[A-Z_][A-Z0-9_]*%";
DeviceProcessEvents
| where ActionType == "ProcessCreated"
| where FileName =~ "cmd.exe"
| extend cmd = tostring(ProcessCommandLine)
| where 
  // set listing (no assignment)
  (cmd matches regex @"(?i)\b(?:/c|/k)?\s*set(\s|$|\|)" and not(cmd matches regex @"(?i)\bset\s+/(?:a|p)\b") and not(cmd matches regex @"(?i)\bset\s+[A-Z_][A-Z0-9_]*\s*="))
  or cmd matches regex @"(?i)\bfor\s+/f.*\('set'\)"   // for /f ... in ('set')
  or cmd matches regex @"(?i)\bset\s*\|\s*findstr\b"   // set piped to findstr
  or cmd matches regex strcat(@"(?i)\becho\s+", envVarToken)  // echo %VAR%
| extend EnumMethod = case(
    cmd matches regex @"(?i)\bfor\s+/f.*\('set'\)", "for /f in ('set')",
    cmd matches regex @"(?i)\bset\s*\|\s*findstr\b", "set | findstr",
    cmd matches regex @"(?i)\becho\s+%[A-Z_][A-Z0-9_]*%", "echo %VAR%",
    cmd matches regex @"(?i)\bset(\s|$|\|)", "set listing",
    "unknown")
| project TimeGenerated, DeviceName, AccountDomain, AccountName, FileName, ProcessCommandLine, EnumMethod, InitiatingProcessFileName, InitiatingProcessParentFileName, InitiatingProcessCommandLine, ProcessId, InitiatingProcessId, LogonId, InitiatingProcessLogonId, MachineGroup
| order by TimeGenerated desc
pass195.99s0.0600
gpt-5-mini-high
set
(
    DeviceProcessEvents
    | extend SourceTable = "DeviceProcessEvents", CmdLine = tostring(ProcessCommandLine), EventTime = ProcessCreationTime
)
| union (
    DeviceEvents
    | extend SourceTable = "DeviceEvents", CmdLine = tostring(coalesce(ProcessCommandLine, InitiatingProcessCommandLine, tostring(AdditionalFields.CommandLine))), EventTime = coalesce(ProcessCreationTime, TimeGenerated)
)
| where tolower(FileName) == "cmd.exe" or tolower(InitiatingProcessFileName) == "cmd.exe" or tolower(CmdLine) contains "cmd.exe"
| where isnotempty(CmdLine)
// Look for common environment-enumeration commands: 'set', 'setx', or 'echo %VAR%'
| where CmdLine matches regex @"(?i)\b(set|setx)\b" or CmdLine matches regex @"(?i)echo\s+%[A-Za-z0-9_]+%"
| project EventTime, SourceTable, DeviceName, AccountDomain, AccountName, FileName, ProcessId, CmdLine, InitiatingProcessFileName, InitiatingProcessCommandLine, InitiatingProcessId, ReportId
| sort by EventTime desc
| take 200
pass132.84s0.0097
gpt-5-mini-low
no answer
no query generatedfail50.00s0.0268
gpt-5-mini-medium
no answer
no query generatedfail50.00s0.0148
gpt-5-nano-high
"cmd.exe" /c set comspec=%windir%\System32\cmd.exe
DeviceProcessEvents
| where (FileName == "cmd.exe" or InitiatingProcessFileName == "cmd.exe" or ProcessCommandLine contains "cmd.exe" or InitiatingProcessCommandLine contains "cmd.exe")
| extend CmdLine = coalesce(ProcessCommandLine, InitiatingProcessCommandLine)
| extend CmdLineLC = tolower(CmdLine)
| where CmdLineLC contains " set " or CmdLineLC contains " /c set" or CmdLineLC contains " /k set"
| project TimeGenerated, DeviceName, DeviceId, CmdLine, InitiatingProcessFileName, InitiatingProcessId, InitiatingProcessCreationTime
| order by TimeGenerated desc
pass141.03s0.0026
gpt-5-nano-medium
cmd.exe /c set comspec=%windir%\System32\cmd.exe
let TimeRange = 24h;
DeviceProcessEvents
| where tolower(FileName) == "cmd.exe" or tolower(InitiatingProcessFileName) == "cmd.exe" or tolower(ProcessCommandLine) contains "cmd.exe"
| where ProcessCreationTime >= ago(TimeRange)
| where ProcessCommandLine contains "set"
| project TimeCreated = ProcessCreationTime, DeviceName, DeviceId, ProcessId, InitiatingProcessId, CommandLine = ProcessCommandLine, InitiatingProcessCommandLine, InitiatingProcessFileName, InitiatingProcessAccountName, InitiatingProcessAccountDomain, InitiatingProcessCreationTime
| sort by TimeCreated desc
pass135.06s0.0036
grok-3-beta
set
DeviceProcessEvents
| where FileName =~ "cmd.exe"
| where ProcessCommandLine contains "set" or ProcessCommandLine contains "env" or ProcessCommandLine contains "printenv"
| project DeviceName, AccountName, ProcessCreationTime, ProcessCommandLine, InitiatingProcessFileName, InitiatingProcessCommandLine
| order by ProcessCreationTime desc
pass112.86s0.0365
grok-3-mini-beta
"cmd.exe" /c set comspec=%windir%\System32\cmd.exe
DeviceProcessEvents
| where FileName == 'cmd.exe'
| where ProcessCommandLine contains 'set'
| project TimeGenerated, DeviceName, ProcessCommandLine, AccountName
| order by TimeGenerated desc
| limit 100
pass119.05s0.0023
o1-high
no answer
no query generatedfail50.00s1.6474
o1-low
no answer
no query generatedfail50.00s1.5992
o3-high
set
// --- cmd.exe used for environment variable discovery ---------------------------------
DeviceProcessEvents
| where ActionType == "ProcessCreated"                      // new process start
| where FileName =~ "cmd.exe"                               // only CMD shells
// --------------------------------------------------------------------
// Identify typical env-var enumeration syntaxes issued from cmd.exe
//    –  "cmd /c set" (dump all variables)
//    –  "set <filter>"  (filtered dump)
//    –  "wmic environment get …" (WMIC technique)
//    –  "echo %VAR%"   (echo individual variable)
// --------------------------------------------------------------------
| where ProcessCommandLine matches regex @"(?i)(/c\s+)?set(\s|$|>|&)|wmic\s+environment|echo\s+%[A-Z0-9_]+%"
| project TimeGenerated,
          DeviceName,
          AccountDomain,
          AccountName,
          ProcessCommandLine,
          FolderPath,
          InitiatingProcessParentFileName,
          InitiatingProcessCommandLine,
          ReportId,
          SHA256
| order by TimeGenerated asc
pass5779.89s0.1242
o3-mini-high
set
DeviceProcessEvents
| where FileName =~ "cmd.exe"
| where ProcessCommandLine has "/c set" or ProcessCommandLine has "set"
| project TimeGenerated, DeviceName, FileName, ProcessCommandLine, FolderPath, InitiatingProcessCommandLine
| order by TimeGenerated desc
pass120.60s0.0173
o3-mini-low
set
DeviceProcessEvents
| where FileName =~ "cmd.exe"
| where ProcessCommandLine contains_cs "set"
| project TimeGenerated, DeviceName, AccountName, ProcessId, ProcessCommandLine, InitiatingProcessCommandLine, FolderPath
| order by TimeGenerated desc
pass144.32s0.0204
o4-mini-high
cmd.exe /c set comspec=%windir%\System32\cmd.exe
DeviceProcessEvents
| where FileName =~ "cmd.exe"
| where ProcessCommandLine has "/c set"
| project TimeGenerated, DeviceName, InitiatingProcessAccountName, InitiatingProcessAccountDomain, ProcessCommandLine
| sort by TimeGenerated desc
pass148.11s0.0086
o4-mini-low
no answer
no query generatedfail50.00s0.0346