Guest User

Untitled

a guest
Mar 20th, 2018
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. --Write an attack which will list all the usernames and their passwords.
  2.  
  3. UNION SELECT username, password FROM users
  4.  
  5. --Write an attack which will update the table so that every entry in the friends table has their userid set to 42.
  6.  
  7. SELECT name, phone, age FROM friends
  8. WHERE friendid = " + id + ";" OR friendid = 42;
  9.  
  10. --Write an attack which will drop both tables.
  11.  
  12. SELECT userid FROM users
  13. WHERE username='" + uname + "' AND password='" + passwd + "'; DROP TABLE users;
  14.  
  15. SELECT name, phone, age FROM friends
  16. WHERE friendid = " + id + ";"; DROP TABLE users
  17.  
  18. import hashlib
  19. from os import urandom
  20. from sqlalchemy import create_engine
  21. from sqlalchemy.ext.declarative import declarative_base
  22. from sqlalchemy import Column, Integer, String, VARCHAR
  23.  
  24. engine = create_engine('sqlite:///:memory:', echo=False) #change to true
  25. Base = declarative_base()
  26.  
  27.  
  28. class User_Details(Base):
  29. '''
  30. Store the user details in the database.
  31. Do not store the password in the database.
  32. **Instead** store the cryptographic hash of the password.
  33. Make sure that the password is salted, and that the salt is unique for each user.
  34. '''
  35. __tablename__ = 'user_details'
  36. id = Column(Integer, primary_key=True)
  37. username = Column(VARCHAR)
  38. hashed_password = Column(VARCHAR)
  39. salt = Column(VARCHAR)
  40.  
  41.  
  42. #password = hashlib.new('inputastring')
  43. h = hashlib.new('ripemd160')
  44. print(h)
  45.  
  46. def secure_password(string):
  47. #has the password using a cryptographic hash function.
  48. sha = hashlib.sha256()
  49. psswrd = sha.update(string)
  50. salt = urandom(len(psswrd))
  51. password = sha.update(psswrd+salt)
  52. return password, salt
  53.  
  54. from sqlalchemy.orm import sessionmaker
  55. Session = sessionmaker(bind=engine)
  56. Session.configure(bind=engine)
  57. session = Session()
  58.  
  59. session.add(User_Details(username="nh123", hashed_password=secure_password("password")[0],
  60. salt = secure_password("password")[1]))
Add Comment
Please, Sign In to add comment