Thursday, January 5, 2017

PowerShell is Not Special - An Offensive PowerShell Retrospective

“PowerShell is not special.”

During Jared Haight’s excellent DerbyCon presentation, he uttered this blasphemous sentence. As someone who has invested the last five years of his life learning and mastering PowerShell, at a surface level, it was easy to dismiss such a claim. However, I’ve done a lot of introspection about my investment in offensive PowerShell and the more I thought about it, the more I began to realize that PowerShell really isn’t that special! Before you bring out the torches and pitchforks, allow me apply context.

My first exposure to PowerShell was from Dave Kennedy and Josh Kelley during their DEF CON presentation – PowerShell OMFG. Initially, I considered PowerShell to be amusing from a security perspective. I was just getting my start in infosec, however, and I had a lot of other things that I needed to focus on. Not long after that talk, Chris Campbell (@obscuresec) then took a keen interest in PowerShell and heavily advocated that we start using it on our team. My obsession for PowerShell wasn’t solidified until I realized that it could be used as a shellcode runner. When I realized that there really wasn’t anything PowerShell couldn’t do, my interest in and promotion of offensive PowerShell was truly realized.

For years, I did my part in developing unique offensive capabilities in PowerShell to the approval of many in the community and to the disappointment of defenders and employees of Microsoft. At the time, their disappointment and frustration was justified to an extent. When I started writing offensive PowerShell code, v3 hadn’t been released so the level of detection was laughable. Fast forward to now – PowerShell v5 (which is available downlevel to Windows 7). I challenge anyone to identify a single language – scripting, interpreted, compiled, or otherwise that has better logging than PowerShell v5. Additionally, if defenders choose to employ whitelisting to enforce trusted PowerShell code, both AppLocker and Device Guard do what many still (mistakenly) believe the execution policy was intended to do – actually perform signature enforcement of PowerShell code.

While PowerShell has become extremely popular amongst pentesters, red-teamer, criminals, and state-sponsored actors, let’s not forget that we’re still getting compromised by compiled payloads every... freaking... day. PowerShell really is just a means to an end in achieving an attacker’s objective - now at the cost of generating significant noise with the logging offered by PowerShell v5. PowerShell obviously offers many distinct advantages for attackers that I highlighted years ago but defenders and security vendors are slowly but surely catching up with detecting PowerShell attacks. Additionally, with the introduction of AMSI, for all of its flaws, we now have AV engines that can scan arbitrary buffers in memory.

So in the context of offense, this is why I say that PowerShell really isn’t special. Defenders truly are armed with the tools they need to detect and mitigate against PowerShell attacks. So the next time you find yourself worrying about PowerShell attacks, make sure you’re worrying equally, if not more about every other kind of payload that could execute on your system. Don’t be naïve, however, and write PowerShell off as a “solved problem.” There will always continue to be innovative bypass/evasion research in the PowerShell space. Let’s continue to bring this to the public’s attention and the community will continue to benefit from the fruits of offensive and defensive research.

References for securing/monitoring PowerShell:

5 comments:

  1. Using PowerShell for pentesting came as pleasant surprise to me after I took a crash course in it to fix some issues we were having with Office365. I looked at Metasploit many years ago but never really got into it and picking up Ruby never really appealed to me (C# dev is my day job). However after seeing Powersploit on GitHub, I plan on doing some basic pentesting with it this year.

    ReplyDelete
    Replies
    1. Tony,

      I'm glad you've been using PowerShell for security!

      Cheers,
      Matt

      Delete
  2. How many organisations do you know of that are:
    (1) logging powershell commands
    (2) actively reviewing those logs

    I would hazard a guess that it's 0. That's why attackers are using powershell.....

    ReplyDelete
    Replies
    1. I'm going to hazard a guess that you're not a defender and that you have yet to be caught running PowerShell in an environment. I can say that a large amount of our customers are both configuring and monitoring PowerShell logs to the point that we've recognized a need to diversify our tradecraft to an extent. No where in this post did I mention that PowerShell attacks would decrease. Quite the contrary. When I was reversing malware full time, we saw a massive increase in PowerShell malware (a lot of which included rips of my code). The point of this article is to reiterate that defenders are empowered with tools to detect malicious PowerShell should they choose to employ them. I figured many would appreciate hearing this from someone who has spent years writing offensive PowerShell code.

      Delete
  3. I'm glad to see this writeup by you since I share the same thoughts. spot on.

    ReplyDelete