Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions argsParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default class ArgsParser {
constructor () {
this.args = yargs(hideBin(process.argv))
.usage(
'Usage: jwt-cracker -t <token> [-a <alphabet>] [--max <maxLength>]'
'Usage: jwt-cracker -t <token> [-a <alphabet>] [--min <minLength>] [--max <maxLength>]'
)
.option('t', {
alias: 'token',
Expand All @@ -20,10 +20,20 @@ export default class ArgsParser {
describe: 'Alphabet to use for the brute force',
default: Constants.DEFAULT_ALPHABET
})
.option('min', {
describe: 'Minimum length of the secret. Note: 1<= min',
default: Constants.DEFAULT_MIN_SECRET_LENGTH
})
.option('max', {
describe: 'Maximum length of the secret',
describe: 'Maximum length of the secret. Note: min <= max',
default: Constants.DEFAULT_MAX_SECRET_LENGTH
})
.check(argv => {
if (argv.min < 1 || argv.max < argv.min) {
throw new Error('Invalid min or max arguments. Remember: 1<= min <= max')
}
return true
})
.help()
.alias('h', 'help').argv
}
Expand All @@ -36,6 +46,10 @@ export default class ArgsParser {
return this.args.alphabet
}

get minLength () {
return this.args.min
}

get maxLength () {
return this.args.max
}
Expand Down
4 changes: 4 additions & 0 deletions constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ export default class Constants {
return 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
}

static get DEFAULT_MIN_SECRET_LENGTH () {
return 1
}

static get DEFAULT_MAX_SECRET_LENGTH () {
return 12
}
Expand Down
13 changes: 8 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const args = new ArgsParser()

const token = args.token
const alphabet = args.alphabet
const minLength = args.minLength
const maxLength = args.maxLength

const validToken = JWTValidator.validateToken(token)
Expand Down Expand Up @@ -43,11 +44,13 @@ let chunk = []

variationsStream(alphabet, maxLength)
.on('data', function (comb) {
chunk.push(comb)
if (chunk.length >= chunkSize) {
// save chunk and reset it
forkChunk(chunk)
chunk = []
if (comb.length >= minLength) {
chunk.push(comb)
if (chunk.length >= chunkSize) {
// save chunk and reset it
forkChunk(chunk)
chunk = []
}
}
})
.on('end', function () {
Expand Down
Loading