Echo Stdin to Powershell


By now most shops have a good selection of powershell rules, long command lines, netconn, keywords, obfuscation and so on so I am on the lookout for those that might not trigger anything.

A recent tweet from Clearsky included an Anyrun trace (always a good source for techniques) that showed cmd echoing commands to powershell without powershell showing the command line so I dug into it a bit. From the references you can see that it isn't new.


GBHackers had a good explanation -
"Powershell command that ends with Dash “-“ ,that will Execute the command by using standard input (Stdin) and only the dash will appear in powershell.exe’s command line arguments."

Cmd using echo


 "Powershell -"



Also note that while powershell is a child of cmd, it is not the one with the command arguments.

Testing showed that the "| powershell -" was not in the command lines from my EDR.


Detection
There are a couple of ways to go about detecting this. First would be just to look for "powershell -" as a child of cmd.exe, but analysis would be a little tricky with just that as an alert and it might be overlooked. It may be good to have this is a sig though because if you use "type file.txt | powershell -" you wont see command line arguments at all unless you catch them being created in the file.

The second would be to look for markers in a command line for the key elements "echo" and "IEX" which are likely to be present and negate the term "powershell".

Those signatures are pretty simple so I won't bother to show them here. The bottom line is that it a nice evasion but still detectable when you know to look for it.


References
https://twitter.com/ClearskySec/status/1142749953304997889
https://app.any.run/tasks/fc72665b-8555-499d-837f-8ca75e6fa51a/
https://twitter.com/danielhbohannon/status/796704888000512000
https://twitter.com/Ben0xA/status/966433613196808193
https://gbhackers.com/hackers-increasing-the-use-of-command-line-evasion-and-obfuscation-to-spread-advance-level-threats/

Comments

Popular posts from this blog

Misleading extensions Xls.exe Doc.exe Pdf.exe

Netconn from suspicious directories

Powershell DNS C2 Notes