{"id":8331,"date":"2007-03-06T22:26:00","date_gmt":"2007-03-06T22:26:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2007\/03\/06\/how-does-the-remotesigned-execution-policy-work\/"},"modified":"2019-02-18T13:16:49","modified_gmt":"2019-02-18T20:16:49","slug":"how-does-the-remotesigned-execution-policy-work","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/how-does-the-remotesigned-execution-policy-work\/","title":{"rendered":"How does the RemoteSigned execution policy work?"},"content":{"rendered":"<p class=\"MsoNormal\"><span>You might have wondered how the &#8220;RemoteSigned&#8221; execution policy protects us from running unsigned PowerShell scripts downloaded from the internet.&nbsp; We use <span>the URL Security Zones API related to <\/span><\/span><span lang=\"EN\">&#8220;Attachment Execution Service&#8221; (AES) introduced in Windows XP SP2 and Windows Server 2003 SP1. &nbsp;Internet Explorer and Outlook Express are among&nbsp;the applications that participate in the AES system, while FireFox, Microsoft Office Outlook and Live Messenger do not follow AES.<\/span><\/p>\n<p class=\"MsoNormal\"><span lang=\"EN\">&nbsp;<\/span><\/p>\n<p class=\"MsoNormal\"><span>AES-participating applications call the <a href=\"http:\/\/msdn.microsoft.com\/library\/default.asp?url=\/library\/en-us\/shellcc\/platform\/shell\/reference\/ifaces\/iattachmentexecute\/save.asp\"><span>Save<\/span><\/a> method of <a href=\"http:\/\/msdn.microsoft.com\/library\/default.asp?url=\/library\/en-us\/shellcc\/platform\/shell\/reference\/ifaces\/iattachmentexecute\/iattachmentexecute.asp\"><span>IAttachmentExecute<\/span><\/a> interface to add a Zone.Identifier alternate data stream to store the zone from which the file came. We then call <\/span><span><a href=\"http:\/\/msdn2.microsoft.com\/en-us\/library\/system.security.policy.zone.createfromurl.aspx\"><span>System.Security.Policy.Zone.CreateFromUrl<\/span><\/a><span> to determine which zone the file originated from. Here is the mapping between ZoneId and SecurityZone enum:<\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span>public<\/span><span> <span>enum<\/span> <span>SecurityZone<br \/><\/span>{<br \/><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>NoZone = -1,<br \/><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>MyComputer = 0,<br \/><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Intranet = 1,<br \/><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Trusted = 2,<br \/><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Internet = 3,<br \/><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <\/span>Untrusted = 4,<br \/>}<\/span><\/p>\n<p class=\"MsoNormal\"><span><\/span><span><\/span>&nbsp;<\/p>\n<p class=\"MsoNormal\"><span>If the file has a ZoneId &gt;= 3, PowerShell considers it remote. Furthermore, PowerShell considers Intranet as remote, if your computer is set up with the Internet Explorer Enhanced Security Configuration.<\/span><\/p>\n<p class=\"MsoNormal\"><span>Let&#8217;s do a little experiment.<\/span><\/p>\n<p class=\"MsoNormal\"><span>1)&nbsp;&nbsp;&nbsp; <\/span><span>Download a PowerShell script from the internet using Internet Explorer<br \/><b><span>&nbsp;<\/span><\/b><\/span><span class=\"MsoHyperlink\"><span><a href=\"http:\/\/www.reskit.net\/Monad\/samplescripts\/Get-WhoAmI.ps1\"><font color=\"#800080\">http:\/\/www.reskit.net\/Monad\/samplescripts\/Get-WhoAmI.ps1<\/font><\/a><\/span><\/span><\/p>\n<p class=\"MsoNormal\"><span>2)&nbsp;&nbsp;&nbsp; <\/span><span>Open the Zone.Identifier alternate data stream in notepad<\/span><\/p>\n<p class=\"CommandLine\"><font face=\"Courier New\" color=\"#1f497d\">notepad \u201cGet-WhoAmI.ps1:Zone.Identifier&#8221;<\/font><\/p>\n<p class=\"MsoNormal\"><span>You will get:<\/span><\/p>\n<p class=\"MsoNormal\"><span><img decoding=\"async\" src=\"http:\/\/farm1.static.flickr.com\/165\/413296121_a6b92f6b2e.jpg\"><\/span><span><\/span><\/p>\n<p class=\"MsoNormal\"><span>3)&nbsp;&nbsp;&nbsp; <\/span><span>Set ExecutionPolicy to RemoteSigned, and run this script<\/span><\/p>\n<p class=\"CommandLine\"><font face=\"Courier New\" color=\"#1f497d\">PS C:\\toolbox\\lads&gt; Set-ExecutionPolicy RemoteSigned<br \/>PS C:\\toolbox\\lads&gt; .\\Get-WhoAmI.ps1<br \/><\/font><span>File C:\\toolbox\\lads\\Get-WhoAmI.ps1 cannot be loaded. The file C:\\toolbox\\lads\\Get-WhoAmI.ps1 is not digitally signed. The script will not execute on the system. Please see &#8220;get-help about_signing&#8221; for more details..<br \/>At line:1 char:17<br \/>+ .\\Get-WhoAmI.ps1 &lt;&lt;&lt;&lt;<\/span><\/p>\n<p class=\"MsoNormal\"><span>4)&nbsp;&nbsp;&nbsp; <\/span><span>Change ZoneId to 2 in notepad, and rerun the script, now the script is considered local<\/span><\/p>\n<p class=\"CommandLine\"><font face=\"Courier New\" color=\"#1f497d\">PS C:\\toolbox\\lads&gt; .\\Get-WhoAmI.ps1<br \/>PS C:\\toolbox\\lads&gt;<\/font><\/p>\n<p class=\"MsoNormal\"><b><span>Links:<\/span><\/b><\/p>\n<ul>\n<li>\n<div class=\"MsoNormal\"><b><span><\/span><\/b><span>For more information about <\/span><span lang=\"EN\">Attachment Execution Service (AES), refer to <a href=\"http:\/\/community.bartdesmet.net\/blogs\/bart\/archive\/2005\/08\/19\/3485.aspx\"><span>http:\/\/community.bartdesmet.net\/blogs\/bart\/archive\/2005\/08\/19\/3485.aspx<\/span><\/a> <\/span><\/div>\n<\/li>\n<li>\n<div class=\"MsoNormal\"><span lang=\"EN\"><\/span><span>For more information about NTFS alternative data stream, refer to <a href=\"http:\/\/www.securityfocus.com\/infocus\/1822\"><span>http:\/\/www.securityfocus.com\/infocus\/<\/span><font color=\"#800080\"><span>1822<\/span><\/font><\/a> &nbsp;<\/span><\/div>\n<\/li>\n<\/ul>\n<p class=\"MsoNormal\"><span>Wei Wu [MSFT]<\/span><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You might have wondered how the &#8220;RemoteSigned&#8221; execution policy protects us from running unsigned PowerShell scripts downloaded from the internet.&nbsp; We use the URL Security Zones API related to &#8220;Attachment Execution Service&#8221; (AES) introduced in Windows XP SP2 and Windows Server 2003 SP1. &nbsp;Internet Explorer and Outlook Express are among&nbsp;the applications that participate in the [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-8331","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"acf":[],"blog_post_summary":"<p>You might have wondered how the &#8220;RemoteSigned&#8221; execution policy protects us from running unsigned PowerShell scripts downloaded from the internet.&nbsp; We use the URL Security Zones API related to &#8220;Attachment Execution Service&#8221; (AES) introduced in Windows XP SP2 and Windows Server 2003 SP1. &nbsp;Internet Explorer and Outlook Express are among&nbsp;the applications that participate in the [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/8331","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=8331"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/8331\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=8331"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=8331"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=8331"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}