Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 为什么PSGallery中的脚本没有区域标识符流?_Powershell_Nuget - Fatal编程技术网

Powershell 为什么PSGallery中的脚本没有区域标识符流?

Powershell 为什么PSGallery中的脚本没有区域标识符流?,powershell,nuget,Powershell,Nuget,NuGet存储库(如PSGallery)显然是一个远程系统。为什么从那里安装的脚本没有区域标识符流 PS C:\> Find-Script -Repository PSGallery -Name Test-RPC | Install-Script -Scope CurrentUser Untrusted repository You are installing the scripts from an untrusted repository. If you trust this rep

NuGet存储库(如PSGallery)显然是一个远程系统。为什么从那里安装的脚本没有区域标识符流

PS C:\> Find-Script -Repository PSGallery -Name Test-RPC | Install-Script -Scope CurrentUser

Untrusted repository
You are installing the scripts from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the
Set-PSRepository cmdlet. Are you sure you want to install the scripts from 'https://www.powershellgallery.com/api/v2'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): Y

PS C:\> Get-Item -Path $Env:USERPROFILE\Documents\WindowsPowerShell\Scripts\Test-RPC.ps1 -Stream *

PSPath        : Microsoft.PowerShell.Core\FileSystem::C:\Users\lit\Documents\WindowsPowerShell\Scripts\Test-RPC.ps1::$DATA
PSParentPath  : Microsoft.PowerShell.Core\FileSystem::C:\Users\lit\Documents\WindowsPowerShell\Scripts
PSChildName   : Test-RPC.ps1::$DATA
PSDrive       : C
PSProvider    : Microsoft.PowerShell.Core\FileSystem
PSIsContainer : False
FileName      : C:\Users\lit\Documents\WindowsPowerShell\Scripts\Test-RPC.ps1
Stream        : :$DATA
Length        : 7771
问题是:

如何确保具有RemoteSigned ExecutionPolicy的用户需要使用签名?PowerShell如何知道它是一个没有区域标识符流的远程文件

PS C:\> Find-Script -Repository PSGallery -Name Test-RPC | Install-Script -Scope CurrentUser

Untrusted repository
You are installing the scripts from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the
Set-PSRepository cmdlet. Are you sure you want to install the scripts from 'https://www.powershellgallery.com/api/v2'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): Y

PS C:\> Get-Item -Path $Env:USERPROFILE\Documents\WindowsPowerShell\Scripts\Test-RPC.ps1 -Stream *

PSPath        : Microsoft.PowerShell.Core\FileSystem::C:\Users\lit\Documents\WindowsPowerShell\Scripts\Test-RPC.ps1::$DATA
PSParentPath  : Microsoft.PowerShell.Core\FileSystem::C:\Users\lit\Documents\WindowsPowerShell\Scripts
PSChildName   : Test-RPC.ps1::$DATA
PSDrive       : C
PSProvider    : Microsoft.PowerShell.Core\FileSystem
PSIsContainer : False
FileName      : C:\Users\lit\Documents\WindowsPowerShell\Scripts\Test-RPC.ps1
Stream        : :$DATA
Length        : 7771

包提供程序,尤其是不受信任的包提供程序,是否有理由不创建区域标识符流?

继续我的评论

PS C:\> Find-Script -Repository PSGallery -Name Test-RPC | Install-Script -Scope CurrentUser

Untrusted repository
You are installing the scripts from an untrusted repository. If you trust this repository, change its InstallationPolicy value by running the
Set-PSRepository cmdlet. Are you sure you want to install the scripts from 'https://www.powershellgallery.com/api/v2'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): Y

PS C:\> Get-Item -Path $Env:USERPROFILE\Documents\WindowsPowerShell\Scripts\Test-RPC.ps1 -Stream *

PSPath        : Microsoft.PowerShell.Core\FileSystem::C:\Users\lit\Documents\WindowsPowerShell\Scripts\Test-RPC.ps1::$DATA
PSParentPath  : Microsoft.PowerShell.Core\FileSystem::C:\Users\lit\Documents\WindowsPowerShell\Scripts
PSChildName   : Test-RPC.ps1::$DATA
PSDrive       : C
PSProvider    : Microsoft.PowerShell.Core\FileSystem
PSIsContainer : False
FileName      : C:\Users\lit\Documents\WindowsPowerShell\Scripts\Test-RPC.ps1
Stream        : :$DATA
Length        : 7771
Clear-Host 

$Url          = 'https://www.powershellgallery.com/packages/Test-RPC/1.0/Content/Test-RPC.ps1'
$output       = 'C:\Temp\Test-RPC.ps1'
$ValidateFile = {
    Try {Get-Item -Path $output -Stream Zone.Identifier -ErrorAction Stop}
    Catch [System.Exception]
    {
        Write-Warning -Message 'Error'
        $PSItem.Exception.Message
    }
}


Remove-Item -Path $output -Force -ErrorAction SilentlyContinue

Invoke-WebRequest -Uri $url -OutFile $output

Remove-Item -Path $output -Force -ErrorAction SilentlyContinue

$wc = New-Object System.Net.WebClient
$wc.DownloadFile($url, $output)
& $ValidateFile

Remove-Item -Path $output -Force -ErrorAction SilentlyContinue
(New-Object System.Net.WebClient).DownloadFile($url, $output)
& $ValidateFile

Import-Module -Name BitsTransfer

Remove-Item -Path $output -Force -ErrorAction SilentlyContinue

Start-BitsTransfer -Source $url -Destination $output
& $ValidateFile

Remove-Item -Path $output -Force -ErrorAction SilentlyContinue
Start-BitsTransfer -Source $url -Destination $output -Asynchronous
& $ValidateFile
# Results
<#
WARNING: Error
Could not open the alternate data stream 'Zone.Identifier' of the file 'C:\Temp\Test-RPC.ps1'.
WARNING: Error
Could not open the alternate data stream 'Zone.Identifier' of the file 'C:\Temp\Test-RPC.ps1'.
WARNING: Error
Could not open the alternate data stream 'Zone.Identifier' of the file 'C:\Temp\Test-RPC.ps1'.

WARNING: Error
JobId                                DisplayName   TransferType JobState   OwnerAccount                      
-----                                -----------   ------------ --------   ------------                      
f5f04c93-4247-4095-8d9a-587b26d64d26 BITS Transfer Download     Connecting 570A5E12-BA93-4\WDAGUtilityAccount
Cannot find path 'C:\Temp\Test-RPC.ps1' because it does not exist.
#>
检查广告数据,注意互联网标签在那里。

使用cmd.exe中的real curl.exe下载

curl.exe -O https://curl.se/windows/dl-7.76.0/curl-7.76.0-win64-mingw.zip
检查广告数据,不互联网标签不在那里。

最后,关于这个

如何确保具有RemoteSigned的ExecutionPolicy的用户签名

根据MSFT的记录和公开声明,EP不是安全边界,也不是他们的设计。

远程签名执行策略:

•允许运行脚本

•要求所有从Internet下载的脚本必须 由指定为受信任的发布者进行数字签名***。 这包括通过电子邮件和即时消息接收的脚本 平台

•不需要对在本地计算机上编写的脚本进行数字签名 计算机

•可能允许从其他来源运行恶意脚本

它们用于防止意外的代码运行EP可以很容易地绕过,并且也有完整的文档/演示

绕过PowerShell执行策略的15种方法:

检测攻击性PowerShell攻击工具:

你可以打开ISE/VSCode中的任何脚本,等等,选择all,然后点击run,EP对此没有控制权。EP用于按名称、含义、控制台主机调用、计划任务等运行脚本

没有任何东西可以阻止用户打开脚本、删除sigblock、使用新名称保存脚本、运行脚本或创建空白脚本、从计时脚本复制内容、保存并运行脚本


PowerShell风险管理/安全控制/缓解是所有正常的网络/客户端功能,以及所有有关完整企业日志记录、审核和在发现/发现异常时的早期警报/效果响应的功能。

Windows决定ADS(基于浏览器的功能)
,而不是PowerShell。在PowerShell会话中,安装操作更像是本地复制操作,而不是web下载,尽管实际操作是从远程repo获取内容。通过
安装
,ADS与EP签名要求无关。在浏览器文件下载中,在几乎所有情况下,在使用文件之前都应该删除广告,否则当您尝试使用文件时,Windows会拒绝。测试理论,使用浏览器和保存脚本vs curl.exe/Invoke-WebRequest/Invoke-RestMethod vs the Install等,以获取以下信息:只有web浏览器才能创建带有Zone.Identifier的广告流。而且,即使他们这样做了,这也不是很有意义吗?广告只是一个来源指标。自它们存在以来,任何人在任何时候都可以轻易地将其移除。许多人只是不知道或不注意广告,直到邪恶的类型开始使用它们作为攻击载体,这被称为
隐写术
。人们可以在广告中嵌入我想要的任何内容,包括任何文件类型,尽管不再使用。无论文件类型如何,广告都应该被检查,并且经常被删除。几十年来,关于广告的文章(它们是什么&它们为什么存在)以及人们应该如何处理它们---