Advertisement
teslariu

inyeccion sql

Nov 27th, 2021
1,074
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. """
  4. Ejemplo de SQL Injection
  5. """
  6.  
  7. import sqlite3
  8.  
  9. # abrir una db, si no existe la crea
  10. conn = sqlite3.connect("database.sqlite")
  11.  
  12. # Para crear una tabla, agregar datos, etc debo hacer una consulta SQL
  13. # Para ejecutar una consulta necesito un cursor
  14. cursor = conn.cursor()
  15.  
  16. # pido los datos:
  17. nombre = input("Ingrese el nombre: ")
  18. edad = int(input("Ingrese la edad: "))
  19.  
  20.  
  21. # inserto los datos
  22. cursor.executescript(f"INSERT INTO personas VALUES('{nombre}',{edad})")
  23. conn.commit()
  24.  
  25. print("Datos guardados")
  26.  
  27.  
  28. # se cierra la base
  29. conn.close()
  30.  
  31. """
  32. nombre: Carlos',30); DELETE FROM personas; --
  33. Edad: 30
  34. Códigoo de la inyección:
  35. "INSERT INTO personas VALUES('Carlos',30); DELETE FROM personas; --',30)"
  36. """
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement