-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
72 lines (57 loc) · 2.1 KB
/
index.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
const fs = require("fs");
const crypto = require('crypto');
function toUTF16LE(msg) {
// https://www.howtobuildsoftware.com/index.php/how-do/cccl/javascript-php-encoding-utf-8-utf-16-utf-8-to-utf-16le-javascript
var byteArray = new Uint8Array(msg.length * 2);
for (var i = 0; i < msg.length; i++) {
byteArray[i * 2] = msg.charCodeAt(i) // & 0xff;
byteArray[i * 2 + 1] = msg.charCodeAt(i) >> 8 // & 0xff;
}
return byteArray
}
function ntlm(msg) {
let hash = crypto.createHash('md4');
hash.update(toUTF16LE(msg))
return hash.digest("hex")
}
function hmac_md5(password, msg) {
let hash = crypto.createHmac('md5', password);
hash.update(msg)
return hash.digest("hex")
}
function ntlmv2(password, user, domain) {
return hmac_md5(Buffer.from(ntlm(password), "hex"), toUTF16LE(user.toUpperCase() + domain))
}
function netntlmv2(password, user, domain, proofStr, blob) {
var ntlmv2_buffer = Buffer.from(ntlmv2(password, user, domain), "hex")
var blockToHmac = Buffer.from(proofStr + blob, "hex")
var hashedBlock = hmac_md5(ntlmv2_buffer, blockToHmac)
return hashedBlock
}
function isEmptyPassword(formattedHash) {
const passwordToTry = "";
let splitted = formattedHash.split(":");
let generatedHash = "";
if (splitted.length < 6) return false
let user = splitted[0],
domain = splitted[2],
challenge = splitted[3],
targetHash = splitted[4],
blob = splitted[5]
if (targetHash.length == 32)
generatedHash = netntlmv2(passwordToTry, user, domain, challenge, blob);
// TODO: Support NetNTLMv1 (See "http://davenport.sourceforge.net/ntlm.html#theNtlmResponse")
return generatedHash.toUpperCase() === targetHash.toUpperCase()
}
let readStream = fs.createReadStream("hashes.txt");
var currentData = "";
readStream.on("data", (buffer) => currentData += buffer);
readStream.on("end", () => {
console.error("List of accounts with an empty password is being written to STDOUT, separated by a newline ('\\n')")
var splitted = currentData.split(/\r\n|\n/g);
for (let part of splitted) {
if (isEmptyPassword(part)) {
console.log(part.split(":")[0]);
}
}
});