Leaving No Safe Haven For Commandline Obfuscation (Part One)

The only thing I find more fascinating than digital anti-forensics, obfuscation and defence evasion is coming up with ways to thwart those techniques as they are employed by adversaries in the wild. This will be a few posts about ways to detect Windows command line obfuscation using Splunk, but I'm sure that the SPL I'm going to include here could be adapted to create detections for other SIEM tools like elastic or Sentinel with relative ease.

Think of this as a chance to look up a magician's sleeve for a little peek at the concealed dove.

If you are following along with ATT&CK I think this technique is best mapped to T1027, Obfuscated Files or Information.

One of the most basic command line obfuscation techniques I've seen in the wild is paired double quotes insertion. Take this for instance:


You can place pairs of arbitrarily positioned double quotes in your command line and as long as the number of quotes per command line is an even number and there are no more than two subsequent quotes, programs will generally accept this input without blinking.

If you had a SIEM alert that related to usage of "whoami" and it was based on that string appearing in the command line, you would miss that usage based on the obfuscation shown above.

If we want to look for quotes in Splunk we need to escape them, the SPL below gives us a quote count:

index=* sourcetype="wineventlog:security" EventCode=4688
| eval quoteCount=mvcount(split(Process_Command_Line,"\""))-1
| stats count by Account_Name, host, Process_Command_Line, quoteCount
| sort - quoteCount

Obviously set the index to wherever you are keeping your Windows logs and hopefully you are logging Process_Command_Line with EventID 4688, right?

The only way I might improve this SPL is to add a where clause, looking for a quoteCount greater than 2 for instance, which would help exclude relatively "normal" double quote usage such as around file paths or file names.

Your mileage will vary here, this might be better suited to threat hunting as opposed to an alert depending on your environment and what is and isn't benign behaviour in your world.

Next blog entry we will go a little deeper into other methods of Windows cli obfuscation and how we can detect it within Splunk.

Popular posts from this blog

Fastening the Seatbelt on.. Threat Hunting for Seatbelt

Capturing Pcap driver installations

Microsoft Defender, Find User Ignored Threats With Splunk