2014-12-31 18:35:43 +08:00
|
|
|
#include <stdio.h>
|
|
|
|
#include "cipherutils.h"
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include "elite_crack.h"
|
|
|
|
|
2017-08-18 16:23:46 +08:00
|
|
|
void calc_score(uint8_t* csn, uint8_t* k) {
|
2014-12-31 18:35:43 +08:00
|
|
|
uint8_t score =0 ;
|
|
|
|
uint8_t i;
|
|
|
|
uint8_t goodvals[16] = {0};
|
|
|
|
uint8_t uniq_vals[8] = {0};
|
|
|
|
memset(goodvals, 0x00, 16);
|
|
|
|
memset(uniq_vals, 0x00, 8);
|
|
|
|
uint8_t badval = 0;
|
|
|
|
int badscore =0;
|
2017-08-18 16:23:46 +08:00
|
|
|
for ( i=0; i < 8 ; i++) {
|
|
|
|
if (k[i] == 0x01) continue;
|
|
|
|
if (k[i] == 0x00) continue;
|
|
|
|
if (k[i] == 0x45) continue;
|
|
|
|
if (k[i] < 16){
|
2014-12-31 18:35:43 +08:00
|
|
|
goodvals[k[i]] = 1;
|
|
|
|
}
|
|
|
|
// if(k[i] ==9 || k[i]==2){
|
|
|
|
// goodvals[k[i]] = 1;
|
|
|
|
// }
|
|
|
|
|
2017-08-18 16:23:46 +08:00
|
|
|
else if (k[i]>=16){
|
2014-12-31 18:35:43 +08:00
|
|
|
badscore++;
|
|
|
|
badval = k[i];
|
|
|
|
}
|
|
|
|
}
|
2017-08-18 16:23:46 +08:00
|
|
|
for (i =0; i < 16; i++) {
|
|
|
|
if (goodvals[i]) {
|
2014-12-31 18:35:43 +08:00
|
|
|
uniq_vals[score] = i;
|
|
|
|
score +=1;
|
|
|
|
}
|
|
|
|
}
|
2017-08-18 16:23:46 +08:00
|
|
|
|
|
|
|
if (score >=2 && badscore < 2) {
|
2014-12-31 18:35:43 +08:00
|
|
|
printf("CSN\t%02x%02x%02x%02x%02x%02x%02x%02x\t%02x %02x %02x %02x %02x %02x %02x %02x\t"
|
|
|
|
,csn[0],csn[1],csn[2],csn[3],csn[4],csn[5],csn[6],csn[7]
|
|
|
|
,k[0],k[1],k[2],k[3],k[4],k[5],k[6],k[7]
|
|
|
|
);
|
2017-08-18 16:23:46 +08:00
|
|
|
|
|
|
|
for (i=0 ; i < score; i++) {
|
2014-12-31 18:35:43 +08:00
|
|
|
printf("%d,", uniq_vals[i]);
|
|
|
|
}
|
|
|
|
printf("\tbadscore: %d (%02x)", badscore, badval);
|
|
|
|
printf("\r\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-18 16:23:46 +08:00
|
|
|
void brute_hash1(void){
|
|
|
|
uint16_t a,b,c,d;
|
2014-12-31 18:35:43 +08:00
|
|
|
uint8_t csn[8] = {0,0,0,0,0xf7,0xff,0x12,0xe0};
|
|
|
|
uint8_t k[8]= {0,0,0,0,0,0,0,0};
|
2017-08-18 16:23:46 +08:00
|
|
|
uint8_t testcsn[8] = {0x00,0x0d,0x0f,0xfd,0xf7,0xff,0x12,0xe0} ;
|
|
|
|
uint8_t testkey[8] = {0x05 ,0x01 ,0x00 ,0x10 ,0x45 ,0x08 ,0x45,0x56} ;
|
2014-12-31 18:35:43 +08:00
|
|
|
calc_score(testcsn,testkey);
|
|
|
|
printf("Brute forcing hashones\n");
|
|
|
|
//exit(1);
|
2017-08-18 16:23:46 +08:00
|
|
|
|
|
|
|
for (a=0; a < 256; a++) {
|
2014-12-31 18:35:43 +08:00
|
|
|
//if(a > 0)printf("%d/256 done...\n", a);
|
2017-08-18 16:23:46 +08:00
|
|
|
for (b=0; b < 256; b++)
|
|
|
|
for (c=0; c < 256; c++)
|
|
|
|
for (d=0; d < 256; d++) {
|
2014-12-31 18:35:43 +08:00
|
|
|
csn[0] = a;
|
|
|
|
csn[1] = b;
|
|
|
|
csn[2] = c;
|
|
|
|
csn[3] = d;
|
|
|
|
csn[4] = 0xf7;
|
|
|
|
csn[5] = 0xff;
|
|
|
|
csn[6] = 0x12;
|
|
|
|
csn[7] = 0xe0;
|
|
|
|
hash1(csn, k);
|
|
|
|
calc_score(csn,k);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|