{"id":46,"date":"2009-03-17T12:56:19","date_gmt":"2009-03-17T18:56:19","guid":{"rendered":"http:\/\/jameskovacs.com\/2009\/03\/17\/Confusion+About+PowerShell+Script+Signing"},"modified":"2009-03-17T12:56:19","modified_gmt":"2009-03-17T18:56:19","slug":"confusion-about-powershell-script-signing","status":"publish","type":"post","link":"https:\/\/www.jameskovacs.com\/index.php\/2009\/03\/17\/confusion-about-powershell-script-signing\/","title":{"rendered":"Confusion about PowerShell Script Signing"},"content":{"rendered":"<p>I\u2019ve been having fun writing about my adventures in PowerShell. I would like to thank everyone for their encouragement and feedback. Something that I haven\u2019t explicitly stated \u2013 which should go without saying as this is a blog \u2013 is that I am not a PowerShell expert. This is one man\u2019s journey learning about PowerShell. I consider myself an expert on C#, .NET, and many other things, but as for PowerShell, I am a hacker. I learn enough to get the job done.<\/p>\n<p>Yes, I wrote <a href=\"http:\/\/code.google.com\/p\/psake\/\">psake<\/a>, which is a cool little PowerShell-based build tool, if I do say so myself. I wrote it in part to learn more about PowerShell and what was possible. (I surprised myself that I was able to write a task-based build system in a few hours with about 100 lines of PowerShell, ignoring comments.)<\/p>\n<p>If you\u2019re looking for PowerShell gospel, I would recommend checking out the <a href=\"http:\/\/blogs.msdn.com\/powershell\/default.aspx\">Windows PowerShell Blog<\/a> (the blog of Jeffrey Snover and the rest of the PowerShell team), <a href=\"http:\/\/www.amazon.com\/gp\/product\/1932394907?ie=UTF8&amp;tag=jamkovweb-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=1932394907\"><em>Windows PowerShell in Action<\/em><\/a> by Bruce Payette, the PowerScripting Podcast, or any of the myriad PowerShell MVP blogs. They are the experts. I\u2019m just a hacker having fun.<\/p>\n<p>With that disclaimer, I hope that by documenting my PowerShell learnings in public, I will help other developers learn PowerShell. I know that I am learning great things about PowerShell from my readers. In <a href=\"2009\/02\/01\/Getting-Started-With-PowerShell-Developer-Edition\">Getting Started with PowerShell &#8211; Developer Edition<\/a>, I lamented the lack of grep. My friend, <a href=\"http:\/\/www.tavaresstudios.com\/\">Chris Tavares<\/a> \u2013 known for his work on Unity and ASP.NET MVC &#8211; pointed out that Select-String can perform similar functions. Awesome! Then in <a href=\"2009\/02\/08\/PowerShell-Processes-And-Piping\">PowerShell, Processes, and Piping<\/a>, Jeffrey Snover himself pointed out that PowerShell supports KB, MB, and GB \u2013 with TB and PB in v2 \u2013 so that you can write:<\/p>\n<p>get-process | where { $_.PrivateMemorySize \u2013gt 200MB }<\/p>\n<p>rather than having to translate 200MB into 200*1024*1024 as I originally did. Fantastic!<\/p>\n<p>In <a href=\"2009\/03\/16\/Writing-Reusable-Scripts-With-PowerShell\">Writing Re-usable Scripts with PowerShell<\/a>, <a href=\"http:\/\/wekempf.spaces.live.com\/\">wekempf<\/a>, <a href=\"http:\/\/www.pseale.com\/blog\/\">Peter<\/a>, and <a href=\"http:\/\/www.josheinstein.com\/\">Josh<\/a> discussed the merits of setting your execution policy to Unrestricted. I corrected the post to use RemoteSigned, which means that downloaded PowerShell scripts have to be unblocked before running, but local scripts can run without requiring signing\/re-signing. Thanks, guys. I agree that RemoteSigned is a better option.<\/p>\n<p>Let\u2019s talk security for a second. I am careful about security. I run as a normal user on Vista and have a separate admin account. When setting up <a href=\"http:\/\/teamcity.codebetter.com\">teamcity.codebetter.com<\/a>, the build agent runs under a least privilege account, which is why we can\u2019t run NCover on the build server yet. (NCover currently requires admin privs, though Gnoso is working on fixing that in short order.) (Imagine if we did run builds as an Administrator or Local System. Someone could write a unit test that added a new user with admin privs to the box, log in remotely and start installing bots, malware, and other evil.) So I tend to be careful about security.<\/p>\n<p>Now for my real question\u2026 What is the threat model for PowerShell that requires script signing? Maybe I\u2019m being really dense here, but I don\u2019t get it. Let\u2019s say I want to do something really evil like formatting your hard drive. I create a PowerShell script with \u201cformat c:\u201d in it, exploit a security vulnerability to drop it onto your box, and exploit another security vulnerability to launch PowerShell to execute the script. (Or I name it the same as a common script, but earlier in your search path, and wait for you to execute it.) But you\u2019ve been anal-retentive about security and only allow signed scripts. So the script won\u2019t execute. Damn! Foiled again! But wait! Let me just rename it from foo.ps1 to foo.cmd or foo.bat and execute it from cmd.exe. If I can execute code on your computer, there are easier ways for me to do bad things than writing PowerShell scripts. Given that we can\u2019t require signing for *.cmd and *.bat files as this would horribly break legacy compatibility, what is the advantage of requiring PowerShell scripts to be signed by default? Dear readers, please enlighten me!<\/p>\n<p><strong>UPDATE:<\/strong> <a href=\"http:\/\/huddledmasses.org\/\">Joel \u201cJaykul\u201d Bennett<\/a> provided a good explanation in the comments. I would recommend reading:<\/p>\n<p><a title=\"http:\/\/blogs.msdn.com\/powershell\/archive\/2008\/09\/30\/powershell-s-security-guiding-principles.aspx\" href=\"http:\/\/blogs.msdn.com\/powershell\/archive\/2008\/09\/30\/powershell-s-security-guiding-principles.aspx\">http:\/\/blogs.msdn.com\/powershell\/archive\/2008\/09\/30\/powershell-s-security-guiding-principles.aspx<\/a><\/p>\n<p>as it exlains the PowerShell Team\u2019s design decision. The intention wasn\u2019t to force everyone to sign scripts, but to disable script execution for most users (as they won\u2019t use PowerShell), but allow PowerShell users to opt into RemoteSigned or Unrestricted as they so choose. Script signing is meant for administrators to set group policy and use signed scripts for administration (as one example use case of script signing).<\/p>\n<p>Thanks again, Joel! That was faster than sifting through the myriad posts on script signing trying to find the reasoning behind it. Once again, the advantages of learning as a community!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I\u2019ve been having fun writing about my adventures in PowerShell. I would like to thank everyone for their encouragement and feedback. Something that I haven\u2019t explicitly stated \u2013 which should go without saying as this is a blog \u2013 is that I am not a PowerShell expert. This is one man\u2019s journey learning about PowerShell. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-46","post","type-post","status-publish","format-standard","hentry","category-powershell"],"_links":{"self":[{"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/posts\/46","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/comments?post=46"}],"version-history":[{"count":0,"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/posts\/46\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/media?parent=46"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/categories?post=46"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jameskovacs.com\/index.php\/wp-json\/wp\/v2\/tags?post=46"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}