Advertisement
teslariu

base con inyeccion

Feb 22nd, 2022
847
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.88 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # inyección de código
  5.  
  6. # Nombre: Carlos', 30); DELETE FROM personas; --
  7. # Edad: 30
  8.  
  9. import sqlite3
  10.  
  11. conn = sqlite3.connect("base.sqlite")
  12. cursor = conn.cursor()
  13.  
  14. nombre = input("Ingrese un nombre: ")
  15. edad = int(input("Ingrese una edad: "))
  16.  
  17. """
  18. ## forma correcta SEGURA, EVITA INYECCION DE CODIGO SQL
  19. try:
  20.     cursor.execute("INSERT INTO personas VALUES(?,?)",(nombre,edad))
  21. except sqlite3.OperationalError:
  22.         print("La consulta no se ejecutó correctamente")
  23. conn.commit()
  24. print("Todo OK")
  25. """
  26.  
  27. ## forma insegura
  28. try:
  29.     cursor.executescript(f"INSERT INTO personas VALUES('{nombre}',{edad})")
  30. except sqlite3.OperationalError:
  31.         print("La consulta no se ejecutó correctamente")
  32. print("Todo OK")
  33. conn.commit()
  34.  
  35. # inyeccion:
  36. # "INSERT INTO personas VALUES('Carlos', 30); DELETE FROM personas; --',11)"
  37.  
  38.  
  39.  
  40.  
  41. conn.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement