No Description

sqlgen2.py 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import mysql.connector
  2. from random import randint
  3. import hashlib
  4. try:
  5. db = mysql.connector.connect(host="localhost",
  6. user="root",
  7. passwd="python1234",
  8. db="sqlinjection")
  9. cursor = db.cursor()
  10. delTable = "DROP TABLE IF EXISTS login;"
  11. cursor.execute(delTable)
  12. creTable = "CREATE TABLE login (username VARCHAR(20) NOT NULL, password VARCHAR(32) NOT NULL);"
  13. cursor.execute(creTable)
  14. # Crear una tabla de cuentas de usuarios con sus hashes de manera aleatoria con 50 usuarios
  15. for t in range(50):
  16. largoUser = randint(8, 16)
  17. username = ""
  18. for i in range(largoUser):
  19. randChar = randint(48, 126)
  20. if randChar == 92:
  21. randChar += 1
  22. username += str(unichr(randChar))
  23. largoPass = randint(8, 20)
  24. password = ""
  25. for j in range(largoUser):
  26. randChar = randint(48, 126)
  27. if randChar == 92:
  28. randChar += 1
  29. password += str(unichr(randChar))
  30. password = hashlib.md5(password).hexdigest()
  31. insDB = "insert into login (username, password) VALUES ('"
  32. insDB += username
  33. insDB += "' , '"
  34. insDB += password
  35. insDB += "');"
  36. cursor.execute(insDB)
  37. insUser = "insert into login (username, password) VALUES ('dbadmin','64387b4b69baef645c388a6c3b812c52');"
  38. cursor.execute(insUser)
  39. db.commit()
  40. cursor.close()
  41. db.close()
  42. except Exception as e:
  43. print e