-
Notifications
You must be signed in to change notification settings - Fork 12
/
queryhashdb.py
90 lines (67 loc) · 2.73 KB
/
queryhashdb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python3
# coding=utf-8
# python version 3.7 by 6time
# 哈希查询sqlite3数据库
import sqlite3
import config1
def querystr(hash=str):
"""单个哈希查询"""
print('-' * 86)
print("{:^24}{:<12}{:^24}".format('password', 'encrypt', 'hash'))
print('-' * 86)
conn = sqlite3.connect(config1.db_name)
for i in range(1, len(config1.hashlist)):
# SELECT password FROM pwdhash WHERE md5='e10adc3949ba59abbe56e057f20f883e'
qy = "SELECT password FROM '%s' WHERE %s='%s'" % (config1.table, config1.hashlist[i], hash)
rows = conn.execute(qy)
for row in rows:
print("{:<24}{:<12}{}".format(row[0], config1.hashlist[i], hash))
conn.close()
def querylist(hash=[]):
"""从文件读取多个哈希查询"""
print('-' * 86)
print("{:^24}{:<12}{:^24}".format('password', 'encrypt', 'hash'))
print('-' * 86)
conn = sqlite3.connect(config1.db_name)
for h in hash:
for i in range(1, len(config1.hashlist)):
# SELECT password FROM pwdhash WHERE md5='e10adc3949ba59abbe56e057f20f883e'
qy = "SELECT password FROM '%s' WHERE %s='%s'" % (
config1.table, config1.hashlist[i], h)
rows = conn.execute(qy)
for row in rows:
print("{:<24}{:<12}{}".format(row[0], config1.hashlist[i], h))
conn.close()
def querypassword(pwd):
"""查询密码是否存在数据库中"""
print('-' * 86)
print("{:^24}{:<12}{:^24}".format('password', 'encrypt', 'hash'))
print('-' * 86)
conn = sqlite3.connect(config1.db_name)
qy = "SELECT * FROM '%s' WHERE password='%s'" % (config1.table, pwd)
rows = conn.execute(qy)
for row in rows:
for i in range(len(config1.hashlist)):
# for row in rows:
print("{:<24}{:<12}{}".format(pwd, config1.hashlist[i], row[i]))
conn.close()
def pwdlike(hash=str):
"""单个哈希模糊查询"""
print('-' * 86)
print("{:^24}{:<12}{:^24}".format('password', 'encrypt', 'hash'))
print('-' * 86)
conn = sqlite3.connect(config1.db_name)
for i in range(len(config1.hashlist)):
qy = "SELECT password FROM '{}' WHERE {} like '%{}%'".format(config1.table, config1.hashlist[i], hash)
rows = conn.execute(qy)
for row in rows:
print("{:<24}{:<12}{}".format(row[0], config1.hashlist[i], hash))
conn.close()
if __name__ == '__main__':
querystr('e10adc3949ba59abbe56e057f20f883e')
querystr('10470c3b4b1fed12c3baac014be15fac67c6e815')
querylist(['10470c3b4b1fed12c3baac014be15fac67c6e815',
'e10adc3949ba59abbe56e057f20f883e',
'6bb4837eb74329105ee4568dda7dc67ed2ca2ad9'])
querypassword('123456')
pwdlike('ba59abbe56')