Advertisement
teslariu

inyección SQL

Aug 24th, 2023 (edited)
1,285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.95 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #
  4. # Motores de bases de datos:
  5. # MySQl, MariaDB, PostreSQL, SQLite (free software)  
  6. # SQLServer Oracle
  7.  
  8. # Python tiene una DB-API
  9.  
  10. # sqlite es el único con soporte integrado en Python: import sqlite3
  11. """
  12. MySQL: mysql-connector-python, PyMySQL
  13. PostgreSQL: psycopg, pg8000
  14. SQLite: sqlite3
  15. SQL Server: pymssql, pyodbc
  16. Oracle: cx_Oracle
  17. """
  18.  
  19. import sqlite3
  20.  
  21. # Me conecto a una bbdd. Si no existe, la crea
  22. conn = sqlite3.connect("database.sqlite")
  23.  
  24. # Para hacer consultas, necesito crear un cursor
  25. cursor = conn.cursor()
  26.  
  27. nombre = input("Ingrese un nombre: ")
  28. edad = int(input("Ingrese la edad: "))
  29.  
  30.  
  31. cursor.executescript(f"INSERT INTO personas VALUES('{nombre}',{edad})")
  32. conn.commit()
  33.  
  34. # ataque SQL Injection Borrado de tabla personas
  35. # >> Nombre: Ale',14); DELETE FROM personas; --
  36. # >> Edad: 1256
  37. #
  38. # INSERT INTO personas VALUES('Ale',14); DELETE FROM personas;--',1256)
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement