-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiron-filings.js
119 lines (92 loc) · 3.04 KB
/
iron-filings.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
'use strict';
const fs = require('fs');
const Iron = require('iron');
const argOpts = { string: ['token','wordlist'], boolean: 'h' };
const argv = require('minimist')(process.argv.slice(2), argOpts);
function IronToken(tokenString) {
//const self = this;
const token = tokenString;
const tokenParts = token.split('*');
const encryptionSalt = tokenParts[2];
const integritySalt = tokenParts[6];
const TEN_YEARS_SECONDS = (60 * 60 * 24 * 365 * 10);
function base64DecodedLength(str) { return (new Buffer(str, 'base64')).length; }
const ironOptions = {
encryption: {
saltBits: base64DecodedLength(encryptionSalt),
algorithm: 'aes-256-cbc',
iterations: 1
},
integrity: {
saltBits: base64DecodedLength(integritySalt),
algorithm: 'sha256',
iterations: 1
},
ttl: 0,
timestampSkewSec: TEN_YEARS_SECONDS, // Accept expired tokens.
localtimeOffsetMsec: 0
};
function unseal (password, callback) {
return Iron.unseal(token, password, ironOptions, callback);
}
function passwordFound (result) {
console.log("");
console.log(`Unsealed Token: ${JSON.stringify(result.token)}`);
console.log(`Password Found! - '${result.password}'`);
console.log("");
}
this.guessPassword = function(guess) {
unseal(guess, function (err, unsealed) {
if (err === null) {
passwordFound({password: guess, token: unsealed});
}
});
};
}
IronToken.isValidToken = function (token) {
var parts = token.split('*');
return ((parts.length === 8)
&& (parts[0] === 'Fe26.2')
&& (parts[4] !== '')
&& (parts[7] !== ''));
};
IronToken.dictionaryAttack = function (token, dict) {
function tryWordlist (wordlist) {
var ironToken = new IronToken(token);
console.log("Starting Password Brute-Force...");
wordlist.forEach(ironToken.guessPassword);
}
function loadedDictionary (err, data) {
if(err === null) {
tryWordlist(data.split('\n'));
} else {
console.log("Failed to load dictionary file.");
}
}
if(!IronToken.isValidToken(token)) {
console.log("Invalid token. Iron tokens begin with 'Fe26.2*'.");
return -1;
}
const wordlistFilename = dict || 'wordlist.txt';
fs.readFile(wordlistFilename, 'utf8', loadedDictionary);
return 0;
};
if (require.main === module) {
if (argv.h) {
console.log(`Usage: process.args[0] process.args[1] [-h] --token <iron_token> [--wordlist]\n\n`);
process.exit(0);
}
if (!argv.token){
console.log("Error: No --token argument provided.");
process.exit(-1);
}
IronToken.dictionaryAttack(argv.token, argv.wordlist);
} else {
module.exports = {
dictionaryAttack: IronToken.dictionaryAttack,
isValidToken: IronToken.isValidToken
};
}
/* TEST TOKEN
Fe26.2**0cdd607945dd1dffb7da0b0bf5f1a7daa6218cbae14cac51dcbd91fb077aeb5b*aOZLCKLhCt0D5IU1qLTtYw*g0ilNDlQ3TsdFUqJCqAm9iL7Wa60H7eYcHL_5oP136TOJREkS3BzheDC1dlxz5oJ**05b8943049af490e913bbc3a2485bee2aaf7b823f4c41d0ff0b7c168371a3772*R8yscVdTBRMdsoVbdDiFmUL8zb-c3PQLGJn4Y8C-AqI
*/