繁体   English   中英

Powershell执行策略remotesigned矛盾?

[英]Powershell execution policy remotesigned contradiction?

请查看以下URL: URL

现在,它说明了有关已下载脚本的以下内容:

“运行脚本,这些脚本是从Internet下载的且未经签名的,如果脚本已被解除阻止,例如使用Unblock-File cmdlet。”

我刚刚从technet画廊(PS2EXE)下载了一个脚本,而无需使用Unblock_file cmdlet,就可以运行其中包含的测试脚本。 到底是怎么回事? 我是不是误会了微软在告诉我的内容,还是这是一个小故障?

help unblock-file

在内部,Unblock-File cmdlet删除Zone.Identifier备用数据流,该数据流的值为“ 3”表示它是从Internet下载的。

文件“远程”或“来自Internet”的想法是本地计算机文件系统上的数据,该数据必须由下载文件的工具放置在该文件系统中,下载过程中不包含在文件中。

如果您通过Internet Explorer(例如FireFox,Invoke-WebRequest)下载了文件,这些文件将添加它。 如果您下载其他内容,则该工具可能不会添加此替代流。

查看其行为:

# Show folder is empty
PS C:\temp\> Get-ChildItem


# Make a test script which prints Hello World, and run it
PS C:\temp\> "'Hello World'" | Set-Content -Path .\test.ps1
PS C:\temp\> .\test.ps1
Hello World


# Show the file exists
PS C:\temp\> Get-ChildItem

    Directory: C:\temp\

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       01/08/2018     22:07             15 test.ps1


# Add the Zone Identifier alternate data stream
PS C:\temp\> "[ZoneTransfer]`nZoneId=3" | Set-Content -Path 'test.ps1' -Stream 'Zone.Identifier'


# Show that it doesn't appear in a normal directory listing:
PS C:\temp\> Get-ChildItem

    Directory: C:\temp\

Mode                LastWriteTime         Length Name
----                -------------         ------ ----
-a----       01/08/2018     22:08             15 test.ps1



# Show how it blocks the file from running
PS C:\temp\> .\test.ps1
.\test.ps1 : File C:\temp\test.ps1 cannot be loaded. The file C:\temp\test.ps1 is not digitally signed. You cannot
run this script on the current system. For more information about running scripts and setting execution policy, see
about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ .\test.ps1
+ ~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess


# Show file content
PS C:\temp\> Get-Content -Path .\test.ps1
'Hello World'


# Show alternate data stream content
PS C:\temp\> Get-Content -Path .\test.ps1 -Stream 'Zone.Identifier'
[ZoneTransfer]
ZoneId=3


# Unblock-File removes this alternate stream
PS C:\temp\> Unblock-File .\test.ps1


# Script runs again
PS C:\temp\> .\test.ps1
Hello World

因此,主要的问题是,如果您运行Get-Content file.ps1:Zone.Identifier并看到ZoneId为3 并且仍然可以运行脚本, 并且 Get-ExecutionPolicy为RemoteSigned,那么您将遇到一些奇怪的情况。

但是我的猜测是下载工具没有添加此数据,因此该文件看起来就像是本地创建的文件。

NB。 RemoteSigned并非旨在成为一项安全功能,它旨在成为“在阅读脚本并故意选择运行它们之前,帮助防止意外运行的脚本的检查”,例如“您确定吗?” 框,而不是密码提示。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM