快速识别常见 Windows 漏洞和配置问题,这些问题不一定在公共安全标准中被涵盖,并收集用于利用和后渗透任务的有用信息。
[!重要] 使用此工具时需要注意的一个主要方面是,所有访问控制检查都是在当前用户的上下文中完成的。因此,如果以管理员权限运行,为了避免产生错误的发现,会跳过许多漏洞检查。
在此处下载脚本:PrivescCheck.ps1
[!提示] 上面的链接也可以直接在 PowerShell 终端中使用
(New-Object Net.WebClient).DownloadString(...)直接使用。
是否存在明显的本地提权方式?
powershell -ep bypass -c ". .\PrivescCheck.ps1; Invoke-PrivescCheck"
是否可以利用额外信息进行后渗透或发现第三方软件中的漏洞?
powershell -ep bypass -c ". .\PrivescCheck.ps1; Invoke-PrivescCheck -Extended -Report PrivescCheck_$($env:COMPUTERNAME) -Format TXT,HTML"
是否存在公共安全标准未涵盖的配置问题?
powershell -ep bypass -c ". .\PrivescCheck.ps1; Invoke-PrivescCheck -Extended -Audit -Report PrivescCheck_$($env:COMPUTERNAME) -Format TXT,HTML,CSV,XML"
Invoke-PrivescCheck [-Extended] [-Audit] [-Experimental] [-Report <PREFIX>]
[-Format <FORMAT>[,...]] [-Risky] [-Silent] [-Force]
-Extended
Include all "extended" checks in the scan (see README).
-Audit
Include all "audit" checks in the scan.
-Experimental
Include all "experimental" checks in the scan. Use only if you know
what you are doing.
-Report <PREFIX>
Generate at least one report file. The output filename will be
"PREFIX.txt" by default. The extension is automatically appended
based on the report format (see "-Format <FORMAT>[,...]").
-Format <FORMAT>[,...]
Specify the format of the output report file(s). If not set, the
default value is "TXT". Supported formats are: "TXT", "HTML", "CSV",
and "XML".
-Risky
Include checks marked as "risky", i.e. checks that are likely to
trigger a blocking action by an endpoint protection solution. Use with
caution.
-Silent
Suppress terminal output. This can be useful if you want to run the
script as part of a batch file, in a scheduled task for instance.
-Force
Force execution and ignore warnings. Typically, the script stops if
it is executed with administrator privileges. Use this option to
execute it anyway.
-Format TXT)使用选项 -Report <PREFIX>(搭配 -Format TXT)指定要生成原始文本报告。输出内容类似于终端中看到的内容,但仅包含 ASCII 字符,以便与所有文本编辑器保持更好的(向后)兼容性。

-Format HTML)使用选项 -Report <PREFIX> 搭配 -Format HTML 指定要生成HTML 报告。输出文件可以在网页浏览器中打开。它比原始文本报告更便于数据可视化。此外,它还提供了排序和筛选功能!

-Format CSV)和 XML(-Format XML)使用选项 -Report <PREFIX> 搭配 -Format CSV 或 -Format XML 指定要生成CSV 或 XML 报告。输出文件旨在便于自动化报告工具解析结果。
[!注意] 尽管输出格式尚未被文档化,但您可以通过分析已生成文件的结构轻松弄清楚。您可以使用每个检查的
Id值来唯一标识它们。
类型为 Base 的检查将始终执行,除非脚本以管理员身份运行。它们主要用于识别提权漏洞或其他重要问题。
-Extended)类型为 Extended 的检查仅在命令行中指定了 -Extended 选项时才会执行。它们主要用于提供可能对漏洞利用开发或后渗透有用的额外信息。
-Audit)类型为 Audit 的检查仅在命令行中指定了 -Audit 选项时才会执行。它们主要用于提供与配置审计相关的信息。
默认情况下,当启动新的 powershell.exe 进程时,PowerShell 执行策略在客户端设置为 Restricted,在服务器上设置为 RemoteSigned。这些策略会阻止(未签名)脚本的执行,但可以通过以下方式在当前作用域内覆盖。
Set-ExecutionPolicy Bypass -Scope Process -Force
. .\PrivescCheck.ps1
然而,当通过 GPO 强制执行执行策略时,此技巧无效。在这种情况下,启动新的 PowerShell 会话后,您可以按如下方式加载脚本。
Get-Content .\PrivescCheck.ps1 | Out-String | Invoke-Expression
一种绕过约束语言模式的常见方法是使用 PSv2,因为它不实现此保护。因此,大量开发工作用于维护这种向后兼容性。
[!注意] 尽管 PowerShell 版本 2
在 Windows 的最新版本上仍默认启用(从 Windows 中移除 PowerShell 2.0),但如果没有 .Net 框架 2.0 版本,它无法运行,而该框架需要手动安装。
如果您在 Meterpreter 会话中运行此脚本,您很可能会遇到“超时”错误。这是因为 Metasploit 使用默认的超时值为 15 秒,这不足以完成脚本的典型执行。
meterpreter > load powershell
Loading extension powershell...Success.
meterpreter > powershell_import /local/path/to/PrivescCheck.ps1
[+] File successfully imported. No result was returned.
meterpreter > powershell_execute "Invoke-PrivescCheck"
[-] Error running command powershell_execute: Rex::TimeoutError Operation timed out.
可以通过 sessions 命令的 -t 选项(文档)设置不同的超时时间。在以下示例中,为 ID 为 1 的会话设置了 2 分钟的超时时间,但您可能希望设置更高的值。
msf6 exploit(multi/handler) > sessions -t 120 -i 1
[*] Starting interaction with 1...
meterpreter > powershell_execute "Invoke-PrivescCheck"