Advertisement
teslariu

sql injection

Sep 6th, 2023
1,216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. #usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4.  
  5. # ejemplo de sql injection
  6. # >> Ingrese un nombre: Leticia',55);DELETE FROM personas;--
  7. # >> Ingrese una edad:55
  8.  
  9. # Como queda la consulta cursor.execute(f"INSERT INTO personas VALUES(?,?)",(nombre,edad))
  10. # "INSERT INTO personas VALUES('Leticia',55);DELETE FROM personas;--,55)"
  11. #
  12. # Descompongo la consulta
  13. #   INSERT INTO personas VALUES('Leticia',55);
  14. #   DELETE FROM personas;
  15. #   --,55)
  16.  
  17. import sqlite3
  18.  
  19. conn = sqlite3.connect("mibase.sqlite")
  20. cursor = conn.cursor()
  21.  
  22.  
  23. nombre = input("Ingrese un nombre: ")
  24. edad = int(input("Ingrese una edad: "))
  25.  
  26. cursor.executescript(f"INSERT INTO personas VALUES('{nombre}',{edad})")
  27.    
  28. conn.commit()
  29.  
  30. cursor.execute("SELECT * FROM personas")
  31. datos = cursor.fetchall()
  32. print(datos)
  33.  
  34. # cerrar la base
  35. conn.close()
  36.  
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement