渗透基础——Exchange Autodiscover 的使用

发布于 2024-11-28 14:18:22 字数 11617 浏览 23 评论 0

0x00 前言

Autodiscover 是 Exchange 的一个服务,用来简化客户端应用程序的配置流程。用户只需要输入自己的电子邮件地址和密码,就能够通过 Autodiscover 服务获取运行客户端应用程序所需的配置信息。

在渗透测试中,当我们获得了一个邮件用户的凭据,能够通过 Autodiscover 服务挖掘出更多有价值的信息。

本文将要介绍通过 Autodiscover 服务读取配置信息的方法,开源实现代码,分享利用思路。

0x01 简介

本文将要介绍以下内容:

  • 通过 Autodiscover 进行口令爆破的方法
  • 通过 Autodiscover 读取配置信息的方法
  • 通过 Autodiscover 访问 Exchange 邮件资源的方法

0x02 通过 Autodiscover 进行口令爆破的方法

对应的 URL: https://<domain>/autodiscover/autodiscover.xml

验证方式:NTLM Over HTTP Protocol(分别支持明文和 NTLM hash 登录)

登录失败返回 401

登录成功返回 200,内容示例:

<?xml version="1.0" encoding="utf-8"?>
<Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006">
  <Response>
    <Error Time="01:37:11.6638388" Id="2403276782">
      <ErrorCode>600</ErrorCode>
      <Message>Invalid Request</Message>
      <DebugData />
    </Error>
  </Response>
</Autodiscover>

我们可以看到,Autodiscover 的验证流程同 EWS 基本相同,所以在代码实现上也可以参照之前的代码 checkEWS.py

这里不再重复介绍,具体细节可参考之前的文章《渗透技巧——Pass the Hash with Exchange Web Service》

实现代码可参照 checkAutodiscover.py 中的 checkautodiscover 功能

0x03 通过 Autodiscover 读取配置信息的方法

直接通过浏览器访问 https://<domain>/autodiscover/autodiscover.xml

无法获得配置信息,浏览器返回的内容示例:

<?xml version="1.0" encoding="utf-8"?>
<Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/responseschema/2006">
  <Response>
    <Error Time="01:37:11.6638388" Id="2403276782">
      <ErrorCode>600</ErrorCode>
      <Message>Invalid Request</Message>
      <DebugData />
    </Error>
  </Response>
</Autodiscover>

如下图

Alt text

为了能够读取配置信息,我们需要以下操作:

1.发送 GET 包,Header 中加入 NTML 认证信息,示例: Authorization: NTLM xxxxxxxxxxx

URL 为 /autodiscover/autodiscover.xml

指定编码格式为 gzip,格式如下:

Accept-Encoding: gzip

2.接收返回结果

提示 401 Unauthorized

3.发送 POST 包

在 Header 中完成 NTML 认证,同时 Header 还需要额外添加以下信息(X-Anchormailbox),指定当前用户的邮箱地址,示例: X-Anchormailbox: test1@test.com

POST 的内容格式如下:

<?xml version="1.0" encoding="utf-8"?><Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006">
<Request><EMailAddress>{EMailAddress}</EMailAddress>
<AcceptableResponseSchema>http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a</AcceptableResponseSchema>
</Request></Autodiscover>

其中, {EMailAddress} 为当前用户的邮箱地址

完整数据包示例:

POST /autodiscover/autodiscover.xml HTTP/1.1
Host: 192.168.1.1
Content-Length: 351
Authorization: NTLM TlRMTVNTUAADAAAAGAAYAHYAAACuAK4AjgAAABYAFgBAAAAACgAKAFYAAAAWABYAYAAAAAAAAAA8AQAABQKIoDEAOQAyAC4AMQA4ADgALgAxAC4AMQB0AGUAcwB0ADEAMQA5ADIALgAxADYAOAAuADEALgAxABlZOdtFpFcfJQY7ysotO0RJVlczdGVrae1Bq6PIhSQWZ5F4VJTTyL8BAQAAAAAAAOiYz4Q0XtYBSVZXM3Rla2kAAAAAAgAIAFQARQBTAFQAAQAGAEQAQwAxAAQAEABAAGUAcwB0AC5AYwBvAG0AAwAYAGQAYwAxAC5AdABlAHMAdAAuAGMAbwBtAAUAEAB0AGUAcwB0AC4AYwBvAG0ABwAIAOiYz3Q0XtYBCQAQAGMAaQBmAHMALwBEAEMAMQAAAAAAAAAAAA==
Content-type: text/xml
X-Anchormailbox: test1@test.com
X-Mapihttpcapability: 1
Accept-Encoding: gzip

<?xml version="1.0" encoding="utf-8"?><Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006">
<Request><EMailAddress>test1@test.com</EMailAddress>
<AcceptableResponseSchema>http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a</AcceptableResponseSchema>
</Request></Autodiscover>

4.接收返回结果

提示 200 OK

返回的 Body 内容为 gzip 压缩格式,需要进行解码

不同版本的 Exchange 获得的内容有所不同,部分通用的内容如下:

  • DisplayName
  • LegacyDN
  • AutoDiscoverSMTPAddress

其中值得注意的是 AD ,代表域控制器的计算机名,在 Exchange 2013 及更老的版本能够获得 AD 的信息,Exchange2016 无法获取

以上的实现代码可参照 checkAutodiscover.py 中的 checkautodiscover 功能

在之前的文章《渗透技巧——通过 Exchange ActiveSync 访问内部文件共享》介绍了通过 Exchange ActiveSync 访问域内共享目录 SYSVOL 的方法,这里的路径需要指定域控制器的计算机名

正确的写法:

\\dc1\SYSVOL\test.com\Policies\{6AC1786C-016F-11D2-945F-00C04fB984F9}\GPT.INI

错误的写法:

\\test.com\SYSVOL\test.com\Policies\{6AC1786C-016F-11D2-945F-00C04fB984F9}\GPT.INI

将以上两点进行结合,就能够完整的实现读取域内共享目录 SYSVOL 的文件

为了能够支持 Exchange2016,这里介绍一种更为通用(支持所有版本)获取域控制器计算机名的方法:通过 EWS 读取当前用户的配置信息,进而获得域控制器的计算机名

参考资料:https://docs.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-get-user-settings-from-exchange-by-using-autodiscover

这里需要注意请求的 url 为 /autodiscover/autodiscover.svc ,而不是 /EWS/Exchange.asmx

发送的 SOAP 格式示例:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:a="http://schemas.microsoft.com/exchange/2010/Autodiscover" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <a:RequestedServerVersion>Exchange2013_SP1</a:RequestedServerVersion>
    <wsa:Action>http://schemas.microsoft.com/exchange/2010/Autodiscover/Autodiscover/GetUserSettings</wsa:Action>
    <wsa:To>https://{domain}/autodiscover/autodiscover.svc</wsa:To>
  </soap:Header>
  <soap:Body>
    <a:GetUserSettingsRequestMessage xmlns:a="http://schemas.microsoft.com/exchange/2010/Autodiscover">
      <a:Request>
        <a:Users>
          <a:User>
            <a:Mailbox>{mail}</a:Mailbox>
          </a:User>
        </a:Users>
        <a:RequestedSettings>
          <a:Setting>UserDisplayName</a:Setting>
          <a:Setting>UserDN</a:Setting>
          <a:Setting>UserDeploymentId</a:Setting>
          <a:Setting>InternalMailboxServer</a:Setting>
          <a:Setting>MailboxDN</a:Setting>
          <a:Setting>PublicFolderServer</a:Setting>
          <a:Setting>ActiveDirectoryServer</a:Setting>
          <a:Setting>ExternalMailboxServer</a:Setting>
          <a:Setting>EcpDeliveryReportUrlFragment</a:Setting>
          <a:Setting>EcpPublishingUrlFragment</a:Setting>
          <a:Setting>EcpTextMessagingUrlFragment</a:Setting>
          <a:Setting>ExternalEwsUrl</a:Setting>
          <a:Setting>CasVersion</a:Setting>
          <a:Setting>EwsSupportedSchemas</a:Setting>
          <a:Setting>GroupingInformation</a:Setting>
        </a:RequestedSettings>
      </a:Request>
    </a:GetUserSettingsRequestMessage>
  </soap:Body>
</soap:Envelope>

这里需要注意 {domain} 必须为域名,不能是 IP

返回的结果中, ActiveDirectoryServer 表示域控制器的计算机名,如下图

Alt text

实现代码可参照 checkAutodiscover.py 中的 getusersetting 功能

0x04 通过 Autodiscover 访问 Exchange 邮件资源的方法

通过 Autodiscover 完成身份认证以后,可以使用 MAPI OVER HTTP 访问 Exchange 邮件资源

注:

MAPI OVER HTTP 是 Outlook 同 Exchange2016 之间默认的通信协议

MAPI OVER HTTP 是 Exchange Server 2013 Service Pack 1 (SP1) 中实现的新传输协议,用来替代 RPC OVER HTTP(也称作 Outlook Anywhere)

Exchange2013 默认没有启用 MAPI OVER HTTP,Outlook 同 Exchange 之间的通信协议使用 RPC OVER HTTP

MAPI OVER HTTP 的资料可参考:

ruler 也支持 MAPI OVER HTTP 的部分功能,可以作为参考

1.执行命令

流程:

  1. connect
  2. execute
  3. disconnect

2.通过 Offline Address Book (OAB) 读取 GlobalAddressList

使用 checkAutodiscover.py

(1) 通过 Autodiscover 获得 OABUrl

命令示例:

python checkAutodiscover.py 192.168.1.1 443 plaintext test1@test.com DomainUser123! checkautodiscover

结果如下图

Alt text

获得 OABUrl 为 https://dc1.test.com/OAB/9e3fa457-ebf1-40e4-b265-21d09a62872b/

(2) 访问 OABUrl,从中找到 Default Global Address 对应的 lzx 文件名

命令示例:

python checkAutodiscover.py 192.168.1.1 443 plaintext test1@test.com DomainUser123! checkoab

结果如下图

Alt text

获得 Default Global Address 为 4667c322-5c08-4cda-844a-253ff36b4a6a-data-5.lzx

(3) 下载 lxz 文件

命令示例:

python checkAutodiscover.py 192.168.1.1 443 plaintext test1@test.com DomainUser123! downloadlzx

结果如下图

Alt text

(4) 对 lxz 文件进行解码

使用工具 oabextract

下载后需要进行安装

编译好可在 Kali 下直接使用的版本下载地址: http://x2100.icecube.wisc.edu/downloads/python/python2.6.Linux-x86_64.gcc-4.4.4/bin/oabextract

将 lzx 文件转换为 oab 文件的命令示例:

oabextract 4667c322-5c08-4cda-844a-253ff36b4a6a-data-5.lzx gal.oab

提取出 GAL 的命令示例:

strings gal.oab|grep SMTP

结果如图

Alt text

0x05 小结

本文介绍了通过 Autodiscover 进行口令爆破、读取配置信息和访问 Exchange 邮件资源的方法,开源实现代码,分享利用思路。

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

关于作者

文章
评论
26 人气
更多

推荐作者

陈独秀

文章 0 评论 0

最后的乘客

文章 0 评论 0

Jerry111

文章 0 评论 0

守护在此方

文章 0 评论 0

相思碎

文章 0 评论 0

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文