mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-14 18:48:13 -07:00
make bruteforce code key length independent
This commit is contained in:
parent
bad5c1ea61
commit
ec31ec2141
3 changed files with 40 additions and 21 deletions
|
@ -646,8 +646,8 @@ static bool brute(em4x50_data_t *etd, uint32_t *pwd) {
|
|||
if (etd->bruteforce_mode == BF_MODE_CHARSET)
|
||||
bf_generator_set_charset(&ctx, etd->bruteforce_charset);
|
||||
|
||||
while ((generator_ret = bf_generate32(&ctx)) == BF_GENERATOR_NEXT) {
|
||||
*pwd = ctx.current_key32;
|
||||
while ((generator_ret = bf_generate(&ctx)) == BF_GENERATOR_NEXT) {
|
||||
*pwd = bf_get_key32(&ctx);
|
||||
|
||||
WDT_HIT();
|
||||
|
||||
|
|
|
@ -51,46 +51,56 @@ int bf_generator_set_charset(generator_context_t *ctx, uint8_t charsets) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int bf_generate32(generator_context_t *ctx) {
|
||||
int bf_generate(generator_context_t *ctx) {
|
||||
|
||||
switch (ctx->mode) {
|
||||
case BF_MODE_RANGE:
|
||||
return _bf_generate_mode_range32(ctx);
|
||||
return _bf_generate_mode_range(ctx);
|
||||
case BF_MODE_CHARSET:
|
||||
return _bf_generate_mode_charset32(ctx);
|
||||
return _bf_generate_mode_charset(ctx);
|
||||
}
|
||||
|
||||
return BF_GENERATOR_ERROR;
|
||||
}
|
||||
|
||||
int _bf_generate_mode_range32(generator_context_t *ctx) {
|
||||
int _bf_generate_mode_range(generator_context_t *ctx) {
|
||||
|
||||
if (ctx->current_key32 >= ctx->range_high) {
|
||||
if (ctx->key_length != BF_KEY_SIZE_32 && ctx->key_length != BF_KEY_SIZE_48)
|
||||
return BF_GENERATOR_ERROR;
|
||||
|
||||
if (ctx->current_key >= ctx->range_high) {
|
||||
return BF_GENERATOR_END;
|
||||
}
|
||||
|
||||
// we use flag1 as indicator if value of range_low was already emitted
|
||||
// so the range generated is <range_low, range_high>
|
||||
if (ctx->current_key32 <= ctx->range_low && ctx->flag1 == false) {
|
||||
ctx->current_key32 = ctx->range_low;
|
||||
ctx->pos[0] = true;
|
||||
if (ctx->current_key <= ctx->range_low && ctx->flag1 == false) {
|
||||
ctx->current_key = ctx->range_low;
|
||||
ctx->flag1 = true;
|
||||
return BF_GENERATOR_NEXT;
|
||||
}
|
||||
|
||||
ctx->current_key32++;
|
||||
ctx->current_key++;
|
||||
return BF_GENERATOR_NEXT;
|
||||
}
|
||||
|
||||
int _bf_generate_mode_charset32(generator_context_t *ctx) {
|
||||
int _bf_generate_mode_charset(generator_context_t *ctx) {
|
||||
|
||||
if (ctx->key_length != BF_KEY_SIZE_32 && ctx->key_length != BF_KEY_SIZE_48)
|
||||
return BF_GENERATOR_ERROR;
|
||||
|
||||
if (ctx->flag1)
|
||||
return BF_GENERATOR_END;
|
||||
|
||||
ctx->current_key32 = ctx->charset[ctx->pos[0]] << 24 | ctx->charset[ctx->pos[1]] << 16 |
|
||||
ctx->charset[ctx->pos[2]] << 8 | ctx->charset[ctx->pos[3]];
|
||||
uint8_t key_byte = 0;
|
||||
|
||||
for (key_byte = 0; key_byte < ctx->key_length;key_byte++){
|
||||
ctx->current_key |= ctx->charset[ctx->pos[key_byte]] << ((ctx->key_length - key_byte) - 1 * 8);
|
||||
}
|
||||
|
||||
|
||||
if (bf_array_increment(ctx->pos, 4, ctx->charset_length) == -1)
|
||||
|
||||
if (bf_array_increment(ctx->pos, ctx->key_length, ctx->charset_length) == -1)
|
||||
// set flag1 to emit value last time and end generation
|
||||
ctx->flag1 = true;
|
||||
|
||||
|
@ -127,3 +137,8 @@ int bf_array_increment(uint8_t *data, uint8_t data_len, uint8_t modulo) {
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// get current key casted to 32 bit
|
||||
uint32_t bf_get_key32(generator_context_t *ctx){
|
||||
return ctx->current_key & 0xFFFFFFFF;
|
||||
}
|
|
@ -55,12 +55,13 @@ extern uint8_t charset_uppercase[];
|
|||
|
||||
// structure to hold key generator temporary data
|
||||
typedef struct {
|
||||
// position of each of 4 bytes in 32 bit key in charset mode
|
||||
// position of each of bytes in charset mode - used to iterate over alphabets
|
||||
// add more bytes to support larger keys
|
||||
// pos[0] is most significant byte - all maths avoid relying on little/big endian memory layout
|
||||
uint8_t pos[6]; // max supported key is now 48 bit
|
||||
|
||||
uint8_t key_length; // bytes
|
||||
uint32_t current_key32;
|
||||
uint64_t current_key; // Use 64 bit and truncate when needed.
|
||||
uint8_t mode;
|
||||
uint8_t charset[
|
||||
BF_CHARSET_DIGITS_SIZE
|
||||
|
@ -77,9 +78,12 @@ typedef struct {
|
|||
|
||||
void bf_generator_init(generator_context_t *ctx, uint8_t mode, uint8_t key_size);
|
||||
int bf_generator_set_charset(generator_context_t *ctx, uint8_t charsets);
|
||||
int bf_generate32(generator_context_t *ctx);
|
||||
int _bf_generate_mode_range32(generator_context_t *ctx);
|
||||
int _bf_generate_mode_charset32(generator_context_t *ctx);
|
||||
int _bf_generate_mode_smart32(generator_context_t *ctx);
|
||||
int bf_generate(generator_context_t *ctx);
|
||||
int _bf_generate_mode_range(generator_context_t *ctx);
|
||||
int _bf_generate_mode_charset(generator_context_t *ctx);
|
||||
int _bf_generate_mode_smart(generator_context_t *ctx);
|
||||
int bf_array_increment(uint8_t *data, uint8_t data_len, uint8_t modulo);
|
||||
uint32_t bf_get_key32(generator_context_t *ctx);
|
||||
uint32_t bf_get_key48(generator_context_t *ctx);
|
||||
|
||||
#endif // BRUTEFORCE_H__
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue