簡體   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