mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 05:43:48 -07:00
refactor bruteforce headers and namespace
This commit is contained in:
parent
82886e2036
commit
bad5c1ea61
4 changed files with 47 additions and 41 deletions
|
@ -28,22 +28,22 @@ uint8_t charset_uppercase[] = {
|
|||
'X', 'Y', 'Z'
|
||||
};
|
||||
|
||||
void bf_generator_init(generator_context_t *ctx, uint8_t mode) {
|
||||
void bf_generator_init(generator_context_t *ctx, uint8_t mode, uint8_t key_size) {
|
||||
memset(ctx, 0, sizeof(generator_context_t));
|
||||
ctx->mode = mode;
|
||||
}
|
||||
|
||||
int bf_generator_set_charset(generator_context_t *ctx, uint8_t charsets) {
|
||||
if (ctx->mode != BRUTEFORCE_MODE_CHARSET) {
|
||||
if (ctx->mode != BF_MODE_CHARSET) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (charsets & CHARSET_DIGITS) {
|
||||
if (charsets & BF_CHARSET_DIGITS) {
|
||||
memcpy(ctx->charset, charset_digits, sizeof(charset_digits));
|
||||
ctx->charset_length += sizeof(charset_digits);
|
||||
}
|
||||
|
||||
if (charsets & CHARSET_UPPERCASE) {
|
||||
if (charsets & BF_CHARSET_UPPERCASE) {
|
||||
memcpy(ctx->charset + ctx->charset_length, charset_uppercase, sizeof(charset_uppercase));
|
||||
ctx->charset_length += sizeof(charset_uppercase);
|
||||
}
|
||||
|
@ -54,19 +54,19 @@ int bf_generator_set_charset(generator_context_t *ctx, uint8_t charsets) {
|
|||
int bf_generate32(generator_context_t *ctx) {
|
||||
|
||||
switch (ctx->mode) {
|
||||
case BRUTEFORCE_MODE_RANGE:
|
||||
case BF_MODE_RANGE:
|
||||
return _bf_generate_mode_range32(ctx);
|
||||
case BRUTEFORCE_MODE_CHARSET:
|
||||
case BF_MODE_CHARSET:
|
||||
return _bf_generate_mode_charset32(ctx);
|
||||
}
|
||||
|
||||
return GENERATOR_ERROR;
|
||||
return BF_GENERATOR_ERROR;
|
||||
}
|
||||
|
||||
int _bf_generate_mode_range32(generator_context_t *ctx) {
|
||||
|
||||
if (ctx->current_key32 >= ctx->range_high) {
|
||||
return GENERATOR_END;
|
||||
return BF_GENERATOR_END;
|
||||
}
|
||||
|
||||
// we use flag1 as indicator if value of range_low was already emitted
|
||||
|
@ -74,17 +74,17 @@ int _bf_generate_mode_range32(generator_context_t *ctx) {
|
|||
if (ctx->current_key32 <= ctx->range_low && ctx->flag1 == false) {
|
||||
ctx->current_key32 = ctx->range_low;
|
||||
ctx->pos[0] = true;
|
||||
return GENERATOR_NEXT;
|
||||
return BF_GENERATOR_NEXT;
|
||||
}
|
||||
|
||||
ctx->current_key32++;
|
||||
return GENERATOR_NEXT;
|
||||
return BF_GENERATOR_NEXT;
|
||||
}
|
||||
|
||||
int _bf_generate_mode_charset32(generator_context_t *ctx) {
|
||||
|
||||
if (ctx->flag1)
|
||||
return GENERATOR_END;
|
||||
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]];
|
||||
|
@ -94,7 +94,7 @@ int _bf_generate_mode_charset32(generator_context_t *ctx) {
|
|||
// set flag1 to emit value last time and end generation
|
||||
ctx->flag1 = true;
|
||||
|
||||
return GENERATOR_NEXT;
|
||||
return BF_GENERATOR_NEXT;
|
||||
}
|
||||
|
||||
// increments values in array with carryover using modulo limit for each byte
|
||||
|
|
|
@ -22,28 +22,33 @@
|
|||
#include "common.h"
|
||||
|
||||
typedef uint8_t bruteforce_mode_t;
|
||||
|
||||
#define BF_KEY_SIZE_32 4
|
||||
#define BF_KEY_SIZE_48 6
|
||||
|
||||
// bruteforcing all keys sequentially between X and Y
|
||||
#define BRUTEFORCE_MODE_RANGE 1
|
||||
#define BF_MODE_RANGE 1
|
||||
|
||||
// try keys based on limited charset/passphrases
|
||||
// some payment systems use user-provided passphrase as system key
|
||||
#define BRUTEFORCE_MODE_CHARSET 2
|
||||
#define BF_MODE_CHARSET 2
|
||||
|
||||
// "smart" mode - try some predictable patterns
|
||||
#define BRUTEFORCE_MODE_SMART 3
|
||||
#define BF_MODE_SMART 3
|
||||
|
||||
|
||||
typedef uint8_t bruteforce_charset_t;
|
||||
// bit flags - can be used together using logical OR
|
||||
#define CHARSET_DIGITS 1
|
||||
#define CHARSET_UPPERCASE 2
|
||||
#define BF_CHARSET_DIGITS 1
|
||||
#define BF_CHARSET_UPPERCASE 2
|
||||
|
||||
#define GENERATOR_END 0
|
||||
#define GENERATOR_NEXT 1
|
||||
#define GENERATOR_ERROR 2
|
||||
#define BF_GENERATOR_END 0
|
||||
#define BF_GENERATOR_NEXT 1
|
||||
#define BF_GENERATOR_ERROR 2
|
||||
|
||||
#define BF_CHARSET_DIGITS_SIZE 10
|
||||
#define BF_CHARSET_UPPERCASE_SIZE 25
|
||||
|
||||
#define CHARSET_DIGITS_SIZE 10
|
||||
#define CHARSET_UPPERCASE_SIZE 25
|
||||
|
||||
extern uint8_t charset_digits[];
|
||||
extern uint8_t charset_uppercase[];
|
||||
|
@ -53,12 +58,13 @@ typedef struct {
|
|||
// position of each of 4 bytes in 32 bit key in charset mode
|
||||
// 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[4];
|
||||
uint8_t pos[6]; // max supported key is now 48 bit
|
||||
uint8_t key_length; // bytes
|
||||
uint32_t current_key32;
|
||||
uint8_t mode;
|
||||
uint8_t charset[
|
||||
CHARSET_DIGITS_SIZE
|
||||
+ CHARSET_UPPERCASE_SIZE
|
||||
BF_CHARSET_DIGITS_SIZE
|
||||
+ BF_CHARSET_UPPERCASE_SIZE
|
||||
];
|
||||
uint8_t charset_length;
|
||||
|
||||
|
@ -69,7 +75,7 @@ typedef struct {
|
|||
|
||||
} generator_context_t;
|
||||
|
||||
void bf_generator_init(generator_context_t *ctx, uint8_t mode);
|
||||
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue