PowerShell 执行策略被 powershell.exe 参数破坏

2024-01-04

在 PowerShell 中,除了尝试控制哪些脚本文件可以运行之外,限制性执行策略还有其他优点吗?

默认情况下,不允许运行 PowerShell 脚本,但似乎如果恶意方想要运行 PowerShell 脚本,他们可以使用 BAT 文件引导进入该脚本,该 BAT 文件调用 PowerShell,并将 -ExecutionPolicy 参数设置为“绕过”。

我是否遗漏了什么,或者这是否破坏了执行策略机制?为什么要签署脚本(其中看起来很麻烦 http://blogs.technet.com/b/heyscriptingguy/archive/2010/06/17/hey-scripting-guy-how-can-i-sign-windows-powershell-scripts-with-an-enterprise-windows-pki-part-2-of-2.aspx)什么时候你可以减少执行策略的限制?

下面是我编写的 BAT 脚本,它创建一个未签名的 .ps1 文件并运行它。它在执行策略为的机器上运行受限制的,这应该禁止脚本。UAC http://en.wikipedia.org/wiki/User_Account_Control已打开且不显示海拔提示。它甚至可以拨出互联网并获取最新的头条新闻“嘿,脚本专家!” http://blogs.technet.com/b/heyscriptingguy/ blog.

echo write-host "`r`nPowershell code running on $(hostname).`r`n`r`nHere's the latest headline from the 'Hey, Scripting Guy!' blog: '$(([xml](New-Object Net.WebClient).DownloadString("http://blogs.technet.com/b/heyscriptingguy/atom.aspx")).feed.entry[0].title)'.`r`n`r`nPress Enter to close.`r`n"; read-host > script.ps1
powershell -ExecutionPolicy bypass -Command .\script.ps1

执行策略将防止某人修改由其他人运行的现有脚本,或作为自动化进程(例如计划任务)。从安全角度来看,使用该 .bat 文件与将代码编译到 .exe 中执行相同操作没有什么不同。

此外,-ExecutionPolicy 参数在以下情况下不起作用:执行策略是通过本地/组策略设置的 http://www.techrepublic.com/blog/the-enterprise-cloud/set-the-powershell-execution-policy-via-group-policy/在机器上(根据 Ansgar 对问题的评论)。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

PowerShell 执行策略被 powershell.exe 参数破坏 的相关文章

随机推荐