Advanced Powershell Hunting with the Splunk Decrypt App


If you already have powershell event logs in Splunk and want to decode the base64, this may help.

This tutorial builds on the work of others with some new cleverness to provide an efficient decoding of powershell commands for threat hunting.

After adding the Splunk Decrypt addon #2655 to decode powershell encoded scripts I ran into a problem. Namely that the app decodes the powershell fine but removing the null padding (seen as periods) took me a while to figure out.

TL;DR  Here is the sig


There is a bit going on here:
  • I had to play with the search line a bit to capture different variations from -e all the way to -encodedcommand without false positives. The NOT filter helps with that. This is also a good place to filter noisy known good powershell from your environment.
  • The rex command is modified from the .conf2016 presentation from Bechtel. Base64 encoding can contain /+ so the \w becomes [\w/+]. I also had to play with the lengths a bit to capture as much as possible but stay within a mod 4 boundary. Note it is possible to work around that with some extra evals. If the length mod 4 is not 0 then the decrypt app fails to decode.
  • The decrypt method has been changed to output hex instead of base64. Just chain the atob (b64decode) to hex. This gives me the ability to strip out the nulls.
  • Rex regex "s/([0-9A-Fa-f]{2})00/%\1/g" to strip the nulls and prepend the % to the hex which the urldecode will need.
  • Eval urldecode converts the hex to ascii and avoids all the periods that decrypt emits using just base64 decode.
  • The regex is where I filter known goods. It will be a bit longer in production but not crazy long.
  • Table or Stats it up

This search is fast enough to go back all time so it can be a great review for historical events. Note that this is a profiling search where I filter out the false positives to view all the new unknowns. Set aside some time for your team when you first run this for all time, you may be surprised how much you can see.

Happy Hunting



References:

https://splunkbase.splunk.com/app/2655/#/details

https://www.splunk.com/en_us/blog/security/hellsbells-lets-hunt-powershells.html

https://conf.splunk.com/files/2016/slides/powershell-power-hell-hunting-for-malicious-use-of-powershell-with-splunk.pdf

https://answers.splunk.com/answers/151846/how-to-convert-hex-to-ascii-in-splunk.html

Comments

Post a Comment

Popular posts from this blog

Misleading extensions Xls.exe Doc.exe Pdf.exe

Netconn from suspicious directories

Powershell DNS C2 Notes