批处理之家's Archiver

victorwoo 发表于 2014-10-27 11:04

PowerShell 技能连载 - 控制可执行文件的执行

原始链接:[url=http://blog.vichamp.com/powershell/tip/2014/10/23/controlling-execution-of-executables/]PowerShell 技能连载 - 控制可执行文件的执行[/url]
发表日期:2014-10-23
[hr]
[i]适用于 PowerShell 所有版本[/i]

PowerShell 将所有可执行程序(扩展名为 EXE 的文件)视为普通的命令。您甚至可以限制 PowerShell 不能执行任何可执行程序或只能执行白名单内的程序。

缺省的设置是允许任何 EXE 执行:[code]
PS> $ExecutionContext.SessionState.Applications
*
[/code]该设置为仅允许 `ping.exe` 和 `regedit.exe` 执行:[code]
$ExecutionContext.SessionState.Applications.Clear()
$ExecutionContext.SessionState.Applications.Add('ping.exe')
$ExecutionContext.SessionState.Applications.Add('regedit.exe')
[/code]以下是结果:[code]
PS> $ExecutionContext.SessionState.Applications
ping.exe
regedit.exe
[/code]显然地,您可以轻松地将设置恢复到缺省状态:[code]
PS> $ExecutionContext.SessionState.Applications.Add('*')

PS> explorer

PS>
[/code]所以,该设置可以使执行 EXE 程序变得更困难(或者说防止不小心运行了不该运行的 EXE)。若真要将它作为安全策略,您还需要关闭所谓的“语言模式”。

当语言模式关闭时,您无法直接存取 .NET 对象。这意味着您无法在当前的 PowerShell 会话中回退该操作。我们将在明天详细介绍语言模式设置。


本文国际来源:[url=http://powershell.com/cs/blogs/tips/archive/2014/10/23/controlling-execution-of-executables.aspx]Controlling Execution of Executables[/url]

页: [1]

Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.