Guest User

sec_tube_ks_crack

a guest
Jun 7th, 2012
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.40 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6. #include <fcntl.h>
  7.  
  8. unsigned char text[] =
  9. "\x8b\x12\xe8\x19\xa3\xcd\x91\x17\x76\xed\xf7\xc3\xcd\x5c\x5e\x0f"
  10. "\x1c\xc1\x07\x42\xf2\xdc\x99\x8a\x35\x38\xe5\xa3\xb0\xb6\xaf\x3c"
  11. "\x84\x12\xc3\xb2\xa8\xcd\xf7\x89\xfa\xe2\xe4\xf2\x44\x50\x40\x11"
  12. "\xfd\xc4\x67\x02\x8a\xee\x51\x63\x2c\xd0\x47\x68\x27\xa7\xbb\x8b"
  13. "\xcc\x2d\x0c\x41\xb6\x2b\x12\x13\x5f\x3c\xc2\x63\x06\x21\x6d\x11"
  14. "\x84\xba\x1c\x97\x55\x3f\x79\x24\xdd\x15\x3a\xda\x3b\xc3\xc6\x9b"
  15. "\xa8\xa2\x1c\x77\x93\x1f\xe9\x67\x7d\xbc\xb9\x16\x62\x5d\x58\xb5"
  16. "\xee\x9a\xe9\x61\x5b\x01\xf7\x38\x11\x17\x8b\xfd\x8a\xb5\xb6\x9a";
  17.  
  18. unsigned char cipher[] =
  19. "\x70\xca\xef\x5c\x0b\x09\x6c\x6d\x2e\x0b\xbe\xd6\xb1\xc5\x10\xfd\x25"
  20. "\x36\xbd\x6d\xbb\x76\x5d\x27\x7e\x47\x1e\x9b\x0e\x89\x29\x88\x03\x8b"
  21. "\xf6\x2b\x26\x6f\x3f\xbb\x09\x35\xf0\x50\xc7\xae\xc0\x46\xce\xdc\xce"
  22. "\xa8\x52\x07\x3b\xca\x42\xb3\xb9\x71\xca\x68\x98\xc8\xec\x84\x5d\x24"
  23. "\xb0\x9b\x71\x2b\x2b\x4f\x09\x1a\xbb\x43\xbc\xa4\x56\x28\x15\xd6\x85"
  24. "\xe4\xc6\x00\x70\x7f\x13\xb8\xf2\xca\xa2\xc3\x3e\xf0\x7f\x78\x5e\xe1"
  25. "\x2a\xc4\xa0\x6c\xd8\x8d\xc0\xd1\xc8\xbf\x15\xa7\x55\x18\xc3\xdb\x59"
  26. "\x3d\x2b\x28\x69\xab\x6c\x86\xa5\xe8\x96\x4d\x6d\x1b\x1f\x67\xe4\x1c";
  27.  
  28. unsigned char iv[]="\x3a\x6f\x63";
  29.  
  30. unsigned char *find_ks(void);
  31. unsigned char *wep(unsigned char *pass);
  32. unsigned char *rc4(unsigned char *password);
  33.  
  34. int main(int argc, char *argv[])
  35. {
  36.     unsigned char   *keystream;
  37.     unsigned char   *new_ks;
  38.     unsigned char   pass[6];
  39.     FILE        *fs;
  40.     register int    i;
  41.    
  42.     if ( argc == 1 )
  43.     {
  44.         fprintf(stderr, "Usage: %s passlist.txt\n", argv[0]);
  45.         return -1;
  46.     }
  47.     keystream = find_ks();
  48.    
  49.     if (( fs = fopen(argv[1], "rb")) == NULL )
  50.     {
  51.         fprintf(stderr, "fopen()\n");
  52.         return -1;
  53.     }
  54.    
  55.     for (;;)
  56.     {
  57.        
  58.         memset(pass, '\0', 6);
  59.         if ( fgets(pass, 6, fs) == NULL )
  60.             break;
  61.        
  62.         printf("trying \"%s\"\n", pass);
  63.         new_ks = wep(pass);
  64.         if ( strncmp(new_ks, keystream, 128) == 0 )
  65.         {
  66.             printf("pass: %s\n", pass);
  67.             free(new_ks);
  68.             break;
  69.         }
  70.         free(new_ks);
  71.     }
  72.     fclose(fs);
  73.     free(keystream);
  74.     return 0;
  75. }
  76.  
  77. unsigned char *find_ks(void)
  78. {
  79.     register int    i;
  80.     unsigned char   *keystream = (unsigned char *)malloc(129 * sizeof(char));
  81.    
  82.     for ( i = 0; i < 128; i++ )
  83.     {  
  84.         keystream[i] = text[i] ^ cipher[i];
  85.     }
  86.    
  87.     return keystream;
  88. }
  89.  
  90. unsigned char *wep(unsigned char *pass)
  91. {
  92.     //unsigned char   *password = "\x3a\x6f\x63\x74\x75\x64\x65\x73";
  93.     unsigned char   *password; 
  94.     unsigned char   *new_ks;
  95.  
  96.     password = (unsigned char *)malloc(9 * sizeof(char));
  97.     memset(password, '\0', 9);
  98.     memcpy(password, iv, 3);
  99.     memcpy(password+3, pass, 5);   
  100.  
  101.     new_ks = rc4(password);
  102.     free(password);
  103.    
  104.     return new_ks;
  105. }
  106.  
  107. unsigned char *rc4(unsigned char *password)
  108. {
  109.     register int    i, j, k;
  110.     unsigned char       s[256];
  111.     unsigned char           *new_ks;
  112.     unsigned char       temp;
  113.    
  114.     new_ks = (unsigned char *)malloc(129*sizeof(char));
  115.     memset(new_ks, '\0', 129);
  116.     printf("keystream: ");
  117.     //KSA
  118.     j = 0;
  119.     for ( i = 0; i < 256; i++ )
  120.     {
  121.         s[i] = i;
  122.     }
  123.    
  124.     for ( i = 0; i < 256; i++ )
  125.     {
  126.         j = (j + s[i] + password[ i % 8])%256;
  127.         temp = s[i];
  128.         s[i] = s[j];
  129.         s[j] = temp;
  130.     }
  131.     //PRGA
  132.     i = 0;
  133.     j = 0;
  134.     for ( k = 0; k < 128; k++ )
  135.     {
  136.         i = (i + 1)%256;
  137.         j = (j+s[i])%256;
  138.         temp = s[i];
  139.         s[i] = s[j];
  140.         s[j] = temp;
  141.         new_ks[k] = s[(s[i]+s[j])%256];
  142.     }
  143.     return new_ks;
  144. }
Add Comment
Please, Sign In to add comment