-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathcracked_pwd_db.js
176 lines (150 loc) · 4.99 KB
/
cracked_pwd_db.js
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
// To check bloom filter.
// 50GB at the server
var BLOOMFILTER_SIZE = Math.pow(2, 30) * 50;
// Total bloomfilter bits in those 50GB
var TOTAL_BITS = (BLOOMFILTER_SIZE * 8);
// File size in bytes (10K)
var FILE_SIZE = Math.pow(2, 20) * 100;
// Bloomfilter bits in each file
var BITS_PER_FILE = FILE_SIZE * 8;
// Total files in each directory
var FILES_PER_DIR = 32;
// Total directories
var TOT_DIR = 16;
var BF_SUBDIR = "bloomfilters";
var bit_set_array = [
128,
64,
32,
16,
8,
4,
2,
1,
];
// Returns 10 hash values from 10 hash-functions
// Check: http://www.eecs.harvard.edu/~kirsch/pubs/bbbf/rsa.pdf
function get_hashed_value(pwd) {
var h1 = CryptoJS.SHA1(pwd).toString();
var h2 = sjcl.codec.hex.fromBits(sjcl.hash.sha256.hash(pwd));
var hashes = [];
for (var i = 0; i < 10; i++) {
var curr_hash = sjcl.codec.hex.fromBits(sjcl.hash.sha256.hash(h1 + i + h2));
hashes.push(curr_hash);
}
return hashes;
}
function get_bit_positions(hashes) {
var hash_bitpos = {};
var check_bits = {};
for (var i = 0; i < 10; i++) {
var hbn = BigNumber(hashes[i], 16);
var hbn_mod = hbn.mod(TOTAL_BITS);
var bit_number = parseInt(hbn_mod.valueOf());
var file_number = Math.ceil((bit_number + 1.0) / BITS_PER_FILE) - 1;
var bit_position = bit_number % BITS_PER_FILE;
var dir_number = Math.ceil((file_number + 1.0) / FILES_PER_DIR) - 1;
var byte_number = Math.ceil((bit_position + 1.0)/ 8) - 1;
var bitpos_inside_byte = bit_position % 8;
hash_bitpos[hashes[i]] = {
"fname": file_number.toString(),
"dname": dir_number.toString(),
"bitpos": bit_position,
"byte_number" : byte_number,
"bitpos_inside_byte" : bitpos_inside_byte,
"checked" : false,
"present" : false
}
check_bits[i] = bit_number;
}
return check_bits;
// return hash_bitpos;
}
function is_bit_set(bytenum, bitinbyte, arrbuf) {
var arrbuf_view8 = new Uint8Array(arrbuf);
var rc = search_in_arrayBuffer("<bits>", arrbuf);
var databyte = arrbuf_view8[bytenum + rc[1]];
if ((bit_set_array[bitinbyte] & databyte) != 0) {
return true;
}
return false;
}
function check_if_pwd_in_cracked_pwd_db(pwd, cb) {
var hashes = get_hashed_value(pwd);
var bitpos = get_bit_positions(hashes);
$.post(server_url + "check_cracked_pwd_db",
JSON.stringify(bitpos),
function(data) {
if (data.split(' ')[0] == 'Success') {
var temp = data.split(' ');
temp.shift();
result = temp.join(' ');
console.log("APPU DEBUG: Is password cracked: " + result);
cb(result);
}
else if (data.split(' ')[0] == 'Failed') {
var temp = data.split(' ');
temp.shift();
reason = temp.join(' ');
console.log("APPU DEBUG: Checking cracked pwd db failed for reason: " + reason);
cb("failed");
}
else {
console.log("APPU DEBUG: Checking cracked pwd db failed: Unknown Reason");
cb("failed");
}
})
.error(function(bitpos) {
return function(data, status) {
print_appu_error("Appu Error: Could not check cracked pwd db for bitpos: "
+ JSON.stringify(bitpos));
cb("failed");
}
} (bitpos));
// for (var i = 0; i < hashes.length; i++) {
// bitpos[hashes[i]]["is_downloaded"] = false;
// download_file(bitpos[hashes[i]]["fname"] + ".base64", "pwdbf",
// bitpos[hashes[i]]["dname"], (function(hash_index, bitpos, hashes, pwd) {
// return function(unzip_buf, version) {
// var are_all_downloaded = true;
// bitpos[hashes[hash_index]]["is_downloaded"] = true;
// bitpos[hashes[hash_index]]["unzip"] = unzip_buf;
// bitpos[hashes[hash_index]]["version"] = version;
// for (var j = 0; j < hashes.length; j++) {
// if (bitpos[hashes[j]]["is_downloaded"] == undefined ||
// bitpos[hashes[j]]["is_downloaded"] == false) {
// are_all_downloaded = false;
// break;
// }
// }
// if (are_all_downloaded == true) {
// var are_all_bits_set = true;
// for (var j = 0; j < hashes.length; j++) {
// if (bitpos[hashes[j]]["version"] == undefined &&
// bitpos[hashes[j]]["unzip"] == undefined) {
// are_all_bits_set = false;
// break;
// }
// if (bitpos[hashes[j]]["version"] == "0.0.0") {
// are_all_bits_set = false;
// break;
// }
// var rc = is_bit_set(bitpos[hashes[j]]["byte_number"],
// bitpos[hashes[j]]["bitpos_inside_byte"],
// bitpos[hashes[j]]["unzip"]);
// if (rc == false) {
// are_all_bits_set = false;
// break;
// }
// }
// if (are_all_bits_set == true) {
// console.log("APPU DEBUG: Password IS cracked: " + pwd);
// }
// else {
// console.log("APPU DEBUG: Password is NOT cracked: " + pwd);
// }
// }
// }
// }(i, bitpos, hashes, pwd)), true);
// }
}