Leaving No Safe Haven For Commandline Obfuscation (The Second Part)

 


In part one of these blog entries on command line obfuscation in Windows (which you can find here, if you haven't read it), we covered some real basic SPL for detecting the usage of double quotes to potentially circumvent SIEM detections.

One of the things I forgot to mention then is that counting specific characters in fields has a lot of potential uses within Splunk searches if you are prepared to think outside the box a little.

For instance let's say you were looking at Apache web logs and you were wanting to find instances of directory (or path) traversal, someone appending something like "../../../../../../../../../../../../etc/passwd%00" to a url to try to get at your valuable files, you could modify the SPL as follows:

 

index=apache sourcetype=access_combined

| eval traversalCount=mvcount(split(uri,"."))-1

| where traversalCount >=4

| stats values(uri) BY traversalCount clientip status

 

This would give you any instances of uris containing 4 or more periods, mess with the threshold attached to there where as needed. You can use that basic SPL for all kinds of tricks if you think about it.

Anyway, that's a tangent, back to command line obfuscation.

In terms of Windows command line character insertion obfuscation only certain characters work, so we can gather what these characters are and search for them. Our full list will be carets, colons, semi-colons, pipes, back and forward slashes, our aforementioned double quotes and finally the humble parentheses (opening and closing).

What you can end up with are EventID 4688 events that look something like this:

 



Now for a little SPL magic:

 

index=* sourcetype="wineventlog:security" EventCode=4688
| eval cliLength=len(Process_Command_Line)
| rex field=Process_Command_Line max_match=0 "(?<special>[\"\\\/\(\)\;\|\^])"
| eval specialCount=mvcount(special)
| where specialCount > (cliLength / 2)
| table cliLength specialCount Process_Command_Line
 

So what are we doing? We are getting the length of the command line (itself a good potential way to find the padding that character insertion causes), then counting our potential character insertions via rex and an eval and finally looking for where the count of those characters is more than half of the total actual characters in the command line.

As always feel free to alter the "where" or remove it altogether, there are a lot of potential tweaks you could make to the above SPL.

Check out Invoke-Dosfuscation on github if you want to learn more about this topic, the repo includes samples of Windows logs that you can ingest into the SIEM of your choice to test out your own potential hunts.

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