Advertisement
illwill

potfile-import.py

Jan 17th, 2019
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. import PyMySQL
  4. import glob
  5. import re
  6. import base64
  7.  
  8. db = PyMySQL.connect("localhost","root","password123","dbname")#Open database connection - ip,user,password,dbname
  9. cursor = db.cursor()                    # prepare a cursor object using cursor() method
  10. d = glob.glob("./*.potfile")            # potfile as glob
  11. find = re.compile(r"([^:]*)")           # look for : as a delimter using regex
  12.  
  13. for i in d:                             # iterate through each potfile in directory
  14.     with open(i, "r") as f:             # open potfile glob
  15.         for x in f:                     # iterate through each line of potfile glob
  16.             x = x.strip()               # strip any whitespace
  17.             output = re.split(find,x)   # split using delimter
  18.             if len(output) > 3:         # make sure not a fucked up line
  19.                 sql = "UPDATE dbname SET pwd = '{}' WHERE hash = '{}'".format(output[3],output[1])
  20.                 print(sql)
  21.                 try:
  22.                     cursor.execute(sql) # Execute the SQL command
  23.                     db.commit()         # Commit your changes in the database
  24.                 except:
  25.                     db.rollback()       # Rollback in case there is any error
  26. db.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement