forked from hashcrackq/Crackq
/
crackqcli.py
executable file
·214 lines (185 loc) · 7.03 KB
/
crackqcli.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/usr/bin/env python
#
# support@hashcrack.org
import json
import sys
import getopt
import os
import zlib
import base64
import re
from urllib2 import Request, urlopen, URLError, HTTPError
from thirdparty.termcolor import cprint
from thirdparty.pdf2john import PdfParser
SERVER = 'https://hashcrack.org'
CONFIG_PATH = None
ENDPOINTS = {
'user_email' : '/crackq/v0.1/user_email',
'submit' : '/crackq/v0.1/submit',
'client_ver' : '/crackq/v0.1/client_ver'
}
API_KEY = None
MYVER = '0.3.2'
HASH_TYPES = ['wpa', 'descrypt', 'md5crypt', 'md5', 'ntlm', 'sha1', 'pdf', 'phpass']
def banner():
cprint('Crackq client %s' % MYVER, 'green')
cprint('support@hashcrack.org\n', 'green')
def usage(argv0):
sys.stdout.write('%s [-t|--type hash_type] [hash|file_path]\n' % argv0)
sys.stdout.write('-t --type see supported hash types below\n')
sys.stdout.write('-h --help help\n\n')
sys.stdout.write('Supported hash types:\n')
sys.stdout.write('md5 Unsalted MD5 hashes\n')
sys.stdout.write('ntlm Windows NTLM hashes\n')
sys.stdout.write('sha1 Unsalted SHA1 hashes\n')
sys.stdout.write('wpa WPA/WPA2 handshakes\n')
sys.stdout.write('md5crypt MD5CRYPT / FreeBSD MD5 / Cisco IOS MD5 / MD5(Unix)\n')
sys.stdout.write('descrypt DESCRYPT / DES(Unix)\n')
sys.stdout.write('pdf PDF 1.4 - 1.6\n')
sys.stdout.write('phpass phpass (Wordpress, Joomla and phpBB3)\n')
def validate_hash(_hash, _hash_type):
if _hash_type == 'descrypt':
if re.match('^[\./0-9A-Za-z]{13,13}$', _hash) is None:
return False
elif _hash_type == 'md5crypt':
if re.match('^\$1\$[\./0-9A-Za-z]{0,8}\$[\./0-9A-Za-z]{22,22}$', _hash) is None:
return False
elif _hash_type == 'phpass':
if re.match('^\$[PH]\$[0-9A-Z][./0-9A-Za-z]{30,30}$', _hash) is None:
return False
elif _hash_type == 'sha1':
if len(_hash) != 40:
sys.stdout.write('[-] ERROR: Invalid hash\n')
return False
try:
int(_hash, 16)
except ValueError:
sys.stdout.write('[-] ERROR: The hash is not in hex\n')
return False
else:
if len(_hash) != 32:
sys.stdout.write('[-] ERROR: Invalid hash\n')
return False
try:
int(_hash, 16)
except ValueError:
sys.stdout.write('[-] ERROR: The hash is not in hex\n')
return False
return True
def save_config():
global API_KEY
global CONFIG_PATH
sys.stdout.write('Enter your API key: ')
key = sys.stdin.readline().strip()
try:
conf = open(CONFIG_PATH, 'w')
except IOError:
sys.stdout.write('[-] ERROR: Cannot write to %s\n' % CONFIG_PATH)
sys.exit(-1)
conf.write('key:%s\n' % key)
API_KEY = key
def load_config():
global API_KEY
global CONFIG_PATH
if os.name == 'nt':
CONFIG_PATH = os.getenv('APPDATA') + '\Crackq.cfg'
elif os.name == 'posix':
CONFIG_PATH = os.getenv("HOME") + '/.crackq'
else:
sys.stdout.write('[-] ERROR: Unsupported OS\n')
sys.exit(-1)
try:
conf = open(CONFIG_PATH, 'r')
for l in conf.readlines():
k, v = l.split(':')
if k == 'key':
API_KEY = v.strip()
if not API_KEY:
sys.stdout.write('[-] ERROR: API KEY NOT FOUND\n')
sys.exit(-1)
except IOError:
save_config()
if __name__ == '__main__':
_type = None
banner()
try:
optlist, args = getopt.getopt(sys.argv[1:], 't:huq:', ['type=', 'help', 'update'])
except getopt.GetoptError as err:
print str(err)
usage(sys.argv[0])
sys.exit(-1)
for o, a in optlist:
if o in ('-h', '--help'):
usage(sys.argv[0])
sys.exit(0)
if o in ('-u', '--update'):
os.system('git pull')
sys.exit(0)
if o in ('-t', '--type'):
_type = a
try:
# check for updates
sys.stdout.write('[+] Checking the current client version...\n')
if urlopen(SERVER + ENDPOINTS['client_ver']).read() != MYVER:
cprint('[-] WARNING: NEW CLIENT VERSION IS AVAILABLE. PLEASE UPDATE.', 'red')
sys.exit(-1)
if len(args) != 1:
usage(sys.argv[0])
sys.exit(-1)
_content = args[0]
if not _type or _type not in HASH_TYPES:
sys.stdout.write('[-] ERROR: INVALID HASH TYPE\n')
sys.exit(-1)
if (_type != 'wpa' and _type != 'pdf') and not validate_hash(_content, _type):
sys.stdout.write('[-] ERROR: INVALID HASH FORMAT\n')
sys.exit(-1)
load_config()
headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
data = {'key': API_KEY}
sys.stdout.write('[+] Retrieving email...\n')
req = Request(SERVER + ENDPOINTS['user_email'])
req.add_header('Content-Type', 'application/json')
res = urlopen(req, json.dumps(data))
data = json.load(res)
sys.stdout.write('[+] Results will be emailed to: %s\n' % data['email'])
sys.stdout.write('[+] Submissions left: %s\n' % data['privq_limit'])
if (data['privq_limit'] > 0):
sys.stdout.write('[+] Sending to the queue...\n')
else:
sys.stdout.write('[-] ERROR: NO QUEUE SUBMISSIONS LEFT. PURCHASE SUBMISSION QUOTA AT https://hashcrack.org/crackq_buy\n')
sys.exit(-1)
if _type == 'wpa':
try:
f = open(_content, 'r')
except IOError:
sys.stdout.write('[-] ERROR: Cannot find %s\n' % _content)
sys.exit(-1)
_raw = f.read()
if _type == 'wpa' and len(_raw) != 392:
sys.stdout.write('[-] ERROR: hccap file is invalid or multiple essids detected\n')
sys.exit(-1)
_content = base64.b64encode(zlib.compress(_raw))
f.close()
if _type == 'pdf':
parser = PdfParser(_content)
if not parser.supported():
print 'This PDF format is not supported'
sys.exit(-1)
try:
pdf_hash = parser.parse()
except RuntimeError:
e = sys.exc_info()[1]
sys.stderr.write("%s : %s\n" % (filename, str(e)))
sys.exit(-1)
_content = pdf_hash
data = {'key': API_KEY, 'content': _content, 'type': _type, 'q': 'privq'}
req = Request(SERVER + ENDPOINTS['submit'])
req.add_header('Content-Type', 'application/json')
res = urlopen(req, json.dumps(data))
sys.stdout.write('[+] Done\n')
except HTTPError as e:
sys.stdout.write('[-] ERROR: HTTP %d - %s\n' % (e.code, json.load(e)['msg']))
sys.exit(-1)
except URLError as e:
cprint('[-] ERROR: UNREACHABLE - %s' % e.reason, 'red')
sys.exit(-1)