Alberts00

SHADEC V1.01 | main.c

Jan 4th, 2013
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 17.31 KB | None | 0 0
  1. /* Changelog
  2.  * Version 1.00
  3.  * Initial version
  4.  * Version 1.01
  5.  * Speeded up approximately 500 times.
  6.  * Now instead of writing all passwords from dictionary and their hashes to result file
  7.  * e.g
  8.  * "Parole: password Hash: 5e884898da280410e88a656f8dc6292773603d0d6aabbdd625jd72nhkd1542d
  9.  * Writes just the user name and password of user, whose password has been found.
  10.  * e.g
  11.  * User: [creeperdaddy] Pass: [123456]
  12.  * Added status, shows amount of SHA256 operations, updates every tenth thousand operation.
  13.  * Added Command line options -u [file with user name:salt:sha256] -p [dictionary] -r [result file]
  14.  * Points out the problem, if no input files given.
  15.  *
  16.  *  
  17.  * Pass finder for SHA256(SHA256(password)+salt))
  18.  * Input
  19.  * SHATEST.exe -u dbdump.txt -p twitter-banned.txt -r twitter-banned.txt.res
  20.  * 1. File containing Username:Salt:SHA256 of password
  21.  * e.g creeperdaddy:633d06d3d95c64ac:349b5849410e88a67ce4fbd938b9e6f8ba53bd9a5167d9787cbfa2eeb520a1d1
  22.  * 2. Dictionary
  23.  * e.g twitter-banned.txt
  24.  * 3. Output file
  25.  *  
  26.   *  FIPS-180-2 compliant SHA-256 implementation
  27.  *
  28.  *  Copyright (C) 2001-2003  Christophe Devine
  29.  *
  30.  *  This program is free software; you can redistribute it and/or modify
  31.  *  it under the terms of the GNU General Public License as published by
  32.  *  the Free Software Foundation; either version 2 of the License, or
  33.  *  (at your option) any later version.
  34.  *
  35.  *  This program is distributed in the hope that it will be useful,
  36.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  37.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  38.  *  GNU General Public License for more details.
  39.  *
  40.  *  You should have received a copy of the GNU General Public License
  41.  *  along with this program; if not, write to the Free Software
  42.  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  43.  */
  44.  
  45. #include <string.h>
  46. #include <unistd.h>
  47. #include <sys/types.h>
  48. #include <sys/stat.h>
  49.  
  50. #include "sha256.h"
  51.  
  52. #define GET_UINT32(n,b,i)                       \
  53. {                                               \
  54.     (n) = ( (uint32) (b)[(i)    ] << 24 )       \
  55.         | ( (uint32) (b)[(i) + 1] << 16 )       \
  56.         | ( (uint32) (b)[(i) + 2] <<  8 )       \
  57.         | ( (uint32) (b)[(i) + 3]       );      \
  58. }
  59.  
  60. #define PUT_UINT32(n,b,i)                       \
  61. {                                               \
  62.     (b)[(i)    ] = (uint8) ( (n) >> 24 );       \
  63.     (b)[(i) + 1] = (uint8) ( (n) >> 16 );       \
  64.     (b)[(i) + 2] = (uint8) ( (n) >>  8 );       \
  65.     (b)[(i) + 3] = (uint8) ( (n)       );       \
  66. }
  67.  
  68. void sha256_starts( sha256_context *ctx )
  69. {
  70.     ctx->total[0] = 0;
  71.     ctx->total[1] = 0;
  72.  
  73.     ctx->state[0] = 0x6A09E667;
  74.     ctx->state[1] = 0xBB67AE85;
  75.     ctx->state[2] = 0x3C6EF372;
  76.     ctx->state[3] = 0xA54FF53A;
  77.     ctx->state[4] = 0x510E527F;
  78.     ctx->state[5] = 0x9B05688C;
  79.     ctx->state[6] = 0x1F83D9AB;
  80.     ctx->state[7] = 0x5BE0CD19;
  81. }
  82.  
  83. void sha256_process( sha256_context *ctx, uint8 data[64] )
  84. {
  85.     uint32 temp1, temp2, W[64];
  86.     uint32 A, B, C, D, E, F, G, H;
  87.  
  88.     GET_UINT32( W[0],  data,  0 );
  89.     GET_UINT32( W[1],  data,  4 );
  90.     GET_UINT32( W[2],  data,  8 );
  91.     GET_UINT32( W[3],  data, 12 );
  92.     GET_UINT32( W[4],  data, 16 );
  93.     GET_UINT32( W[5],  data, 20 );
  94.     GET_UINT32( W[6],  data, 24 );
  95.     GET_UINT32( W[7],  data, 28 );
  96.     GET_UINT32( W[8],  data, 32 );
  97.     GET_UINT32( W[9],  data, 36 );
  98.     GET_UINT32( W[10], data, 40 );
  99.     GET_UINT32( W[11], data, 44 );
  100.     GET_UINT32( W[12], data, 48 );
  101.     GET_UINT32( W[13], data, 52 );
  102.     GET_UINT32( W[14], data, 56 );
  103.     GET_UINT32( W[15], data, 60 );
  104.  
  105. #define  SHR(x,n) ((x & 0xFFFFFFFF) >> n)
  106. #define ROTR(x,n) (SHR(x,n) | (x << (32 - n)))
  107.  
  108. #define S0(x) (ROTR(x, 7) ^ ROTR(x,18) ^  SHR(x, 3))
  109. #define S1(x) (ROTR(x,17) ^ ROTR(x,19) ^  SHR(x,10))
  110.  
  111. #define S2(x) (ROTR(x, 2) ^ ROTR(x,13) ^ ROTR(x,22))
  112. #define S3(x) (ROTR(x, 6) ^ ROTR(x,11) ^ ROTR(x,25))
  113.  
  114. #define F0(x,y,z) ((x & y) | (z & (x | y)))
  115. #define F1(x,y,z) (z ^ (x & (y ^ z)))
  116.  
  117. #define R(t)                                    \
  118. (                                               \
  119.     W[t] = S1(W[t -  2]) + W[t -  7] +          \
  120.            S0(W[t - 15]) + W[t - 16]            \
  121. )
  122.  
  123. #define P(a,b,c,d,e,f,g,h,x,K)                  \
  124. {                                               \
  125.     temp1 = h + S3(e) + F1(e,f,g) + K + x;      \
  126.     temp2 = S2(a) + F0(a,b,c);                  \
  127.     d += temp1; h = temp1 + temp2;              \
  128. }
  129.  
  130.     A = ctx->state[0];
  131.     B = ctx->state[1];
  132.     C = ctx->state[2];
  133.     D = ctx->state[3];
  134.     E = ctx->state[4];
  135.     F = ctx->state[5];
  136.     G = ctx->state[6];
  137.     H = ctx->state[7];
  138.  
  139.     P( A, B, C, D, E, F, G, H, W[ 0], 0x428A2F98 );
  140.     P( H, A, B, C, D, E, F, G, W[ 1], 0x71374491 );
  141.     P( G, H, A, B, C, D, E, F, W[ 2], 0xB5C0FBCF );
  142.     P( F, G, H, A, B, C, D, E, W[ 3], 0xE9B5DBA5 );
  143.     P( E, F, G, H, A, B, C, D, W[ 4], 0x3956C25B );
  144.     P( D, E, F, G, H, A, B, C, W[ 5], 0x59F111F1 );
  145.     P( C, D, E, F, G, H, A, B, W[ 6], 0x923F82A4 );
  146.     P( B, C, D, E, F, G, H, A, W[ 7], 0xAB1C5ED5 );
  147.     P( A, B, C, D, E, F, G, H, W[ 8], 0xD807AA98 );
  148.     P( H, A, B, C, D, E, F, G, W[ 9], 0x12835B01 );
  149.     P( G, H, A, B, C, D, E, F, W[10], 0x243185BE );
  150.     P( F, G, H, A, B, C, D, E, W[11], 0x550C7DC3 );
  151.     P( E, F, G, H, A, B, C, D, W[12], 0x72BE5D74 );
  152.     P( D, E, F, G, H, A, B, C, W[13], 0x80DEB1FE );
  153.     P( C, D, E, F, G, H, A, B, W[14], 0x9BDC06A7 );
  154.     P( B, C, D, E, F, G, H, A, W[15], 0xC19BF174 );
  155.     P( A, B, C, D, E, F, G, H, R(16), 0xE49B69C1 );
  156.     P( H, A, B, C, D, E, F, G, R(17), 0xEFBE4786 );
  157.     P( G, H, A, B, C, D, E, F, R(18), 0x0FC19DC6 );
  158.     P( F, G, H, A, B, C, D, E, R(19), 0x240CA1CC );
  159.     P( E, F, G, H, A, B, C, D, R(20), 0x2DE92C6F );
  160.     P( D, E, F, G, H, A, B, C, R(21), 0x4A7484AA );
  161.     P( C, D, E, F, G, H, A, B, R(22), 0x5CB0A9DC );
  162.     P( B, C, D, E, F, G, H, A, R(23), 0x76F988DA );
  163.     P( A, B, C, D, E, F, G, H, R(24), 0x983E5152 );
  164.     P( H, A, B, C, D, E, F, G, R(25), 0xA831C66D );
  165.     P( G, H, A, B, C, D, E, F, R(26), 0xB00327C8 );
  166.     P( F, G, H, A, B, C, D, E, R(27), 0xBF597FC7 );
  167.     P( E, F, G, H, A, B, C, D, R(28), 0xC6E00BF3 );
  168.     P( D, E, F, G, H, A, B, C, R(29), 0xD5A79147 );
  169.     P( C, D, E, F, G, H, A, B, R(30), 0x06CA6351 );
  170.     P( B, C, D, E, F, G, H, A, R(31), 0x14292967 );
  171.     P( A, B, C, D, E, F, G, H, R(32), 0x27B70A85 );
  172.     P( H, A, B, C, D, E, F, G, R(33), 0x2E1B2138 );
  173.     P( G, H, A, B, C, D, E, F, R(34), 0x4D2C6DFC );
  174.     P( F, G, H, A, B, C, D, E, R(35), 0x53380D13 );
  175.     P( E, F, G, H, A, B, C, D, R(36), 0x650A7354 );
  176.     P( D, E, F, G, H, A, B, C, R(37), 0x766A0ABB );
  177.     P( C, D, E, F, G, H, A, B, R(38), 0x81C2C92E );
  178.     P( B, C, D, E, F, G, H, A, R(39), 0x92722C85 );
  179.     P( A, B, C, D, E, F, G, H, R(40), 0xA2BFE8A1 );
  180.     P( H, A, B, C, D, E, F, G, R(41), 0xA81A664B );
  181.     P( G, H, A, B, C, D, E, F, R(42), 0xC24B8B70 );
  182.     P( F, G, H, A, B, C, D, E, R(43), 0xC76C51A3 );
  183.     P( E, F, G, H, A, B, C, D, R(44), 0xD192E819 );
  184.     P( D, E, F, G, H, A, B, C, R(45), 0xD6990624 );
  185.     P( C, D, E, F, G, H, A, B, R(46), 0xF40E3585 );
  186.     P( B, C, D, E, F, G, H, A, R(47), 0x106AA070 );
  187.     P( A, B, C, D, E, F, G, H, R(48), 0x19A4C116 );
  188.     P( H, A, B, C, D, E, F, G, R(49), 0x1E376C08 );
  189.     P( G, H, A, B, C, D, E, F, R(50), 0x2748774C );
  190.     P( F, G, H, A, B, C, D, E, R(51), 0x34B0BCB5 );
  191.     P( E, F, G, H, A, B, C, D, R(52), 0x391C0CB3 );
  192.     P( D, E, F, G, H, A, B, C, R(53), 0x4ED8AA4A );
  193.     P( C, D, E, F, G, H, A, B, R(54), 0x5B9CCA4F );
  194.     P( B, C, D, E, F, G, H, A, R(55), 0x682E6FF3 );
  195.     P( A, B, C, D, E, F, G, H, R(56), 0x748F82EE );
  196.     P( H, A, B, C, D, E, F, G, R(57), 0x78A5636F );
  197.     P( G, H, A, B, C, D, E, F, R(58), 0x84C87814 );
  198.     P( F, G, H, A, B, C, D, E, R(59), 0x8CC70208 );
  199.     P( E, F, G, H, A, B, C, D, R(60), 0x90BEFFFA );
  200.     P( D, E, F, G, H, A, B, C, R(61), 0xA4506CEB );
  201.     P( C, D, E, F, G, H, A, B, R(62), 0xBEF9A3F7 );
  202.     P( B, C, D, E, F, G, H, A, R(63), 0xC67178F2 );
  203.  
  204.     ctx->state[0] += A;
  205.     ctx->state[1] += B;
  206.     ctx->state[2] += C;
  207.     ctx->state[3] += D;
  208.     ctx->state[4] += E;
  209.     ctx->state[5] += F;
  210.     ctx->state[6] += G;
  211.     ctx->state[7] += H;
  212. }
  213.  
  214. void sha256_update( sha256_context *ctx, uint8 *input, uint32 length )
  215. {
  216.     uint32 left, fill;
  217.  
  218.     if( ! length ) return;
  219.  
  220.     left = ctx->total[0] & 0x3F;
  221.     fill = 64 - left;
  222.  
  223.     ctx->total[0] += length;
  224.     ctx->total[0] &= 0xFFFFFFFF;
  225.  
  226.     if( ctx->total[0] < length )
  227.         ctx->total[1]++;
  228.  
  229.     if( left && length >= fill )
  230.     {
  231.         memcpy( (void *) (ctx->buffer + left),
  232.                 (void *) input, fill );
  233.         sha256_process( ctx, ctx->buffer );
  234.         length -= fill;
  235.         input  += fill;
  236.         left = 0;
  237.     }
  238.  
  239.     while( length >= 64 )
  240.     {
  241.         sha256_process( ctx, input );
  242.         length -= 64;
  243.         input  += 64;
  244.     }
  245.  
  246.     if( length )
  247.     {
  248.         memcpy( (void *) (ctx->buffer + left),
  249.                 (void *) input, length );
  250.     }
  251. }
  252.  
  253. static uint8 sha256_padding[64] =
  254. {
  255.  0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  256.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  257.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  258.     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  259. };
  260.  
  261. void sha256_finish( sha256_context *ctx, uint8 digest[32] )
  262. {
  263.     uint32 last, padn;
  264.     uint32 high, low;
  265.     uint8 msglen[8];
  266.  
  267.     high = ( ctx->total[0] >> 29 )
  268.          | ( ctx->total[1] <<  3 );
  269.     low  = ( ctx->total[0] <<  3 );
  270.  
  271.     PUT_UINT32( high, msglen, 0 );
  272.     PUT_UINT32( low,  msglen, 4 );
  273.  
  274.     last = ctx->total[0] & 0x3F;
  275.     padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last );
  276.  
  277.     sha256_update( ctx, sha256_padding, padn );
  278.     sha256_update( ctx, msglen, 8 );
  279.  
  280.     PUT_UINT32( ctx->state[0], digest,  0 );
  281.     PUT_UINT32( ctx->state[1], digest,  4 );
  282.     PUT_UINT32( ctx->state[2], digest,  8 );
  283.     PUT_UINT32( ctx->state[3], digest, 12 );
  284.     PUT_UINT32( ctx->state[4], digest, 16 );
  285.     PUT_UINT32( ctx->state[5], digest, 20 );
  286.     PUT_UINT32( ctx->state[6], digest, 24 );
  287.     PUT_UINT32( ctx->state[7], digest, 28 );
  288. }
  289.  
  290. #include <stdlib.h>
  291. #include <stdio.h>
  292.  
  293. /*
  294.  * those are the standard FIPS-180-2 test vectors
  295.  */
  296. /*
  297. static char *msg[] =
  298. {
  299.     "abc",
  300.     "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
  301.     NULL
  302. };
  303.  
  304. static char *val[] =
  305. {
  306.     "ba7816bf8f01cfea414140de5dae2223" \
  307.     "b00361a396177a9cb410ff61f20015ad",
  308.     "248d6a61d20638b8e5c026930c3e6039" \
  309.     "a33ce45964ff2167f6ecedd419db06c1",
  310.     "cdc76e5c9914fb9281a1c7e284d73e67" \
  311.     "f1809a48a497200e046d39ccc7112cd0"
  312. };
  313. */
  314. typedef struct ufilest {
  315.     char* uname;
  316.     char* seed;
  317.     char* hash;
  318.     unsigned char sha256[32];
  319.     struct ufilest *next;
  320. } ufilest;
  321.  
  322. typedef struct pfilest {
  323.     char* pass;
  324.     char* hash;
  325.     struct pfilest *next;
  326. } pfilest;
  327.  
  328. unsigned char ctox(char c){
  329.     unsigned char rc = 0;
  330.     if( c >= '0' && c <= '9' ) rc = c - '0';
  331.     else if (c >= 'A' && c <= 'F') rc = c - 'A' + 10;
  332.     else if (c >= 'a' && c <= 'f') rc = c - 'a' + 10;
  333.     return rc;
  334. }
  335.  
  336. unsigned char stox(char *s, unsigned char (*t)[32]){
  337.     int i;
  338.     for( i=0; i<32; i++)
  339.         (*t)[i] = ctox(*(s+i*2))<<4 | ctox(*(s+i*2+1));
  340.     return 0;  
  341. }
  342.  
  343. int insert_u(char * buffer, struct ufilest ** cu, struct ufilest ** pu, char divider ){
  344.     char tmp[1000];
  345.     char *pt,*pb;
  346.     size_t msize;
  347.     msize = sizeof(struct ufilest);
  348.     *cu = (struct ufilest *)malloc(msize);
  349.     if ( ! *cu ) {
  350.         perror("Malloc error for user file");
  351.         // Delete structure
  352.         return(255);
  353.     }
  354.     pb = buffer;
  355.     pt = &tmp[0];
  356.     while( *pb && *pb != divider ) *(pt++) = *(pb++); *pt = '\0'; pb++;
  357.     msize = (strlen(tmp)+1)*sizeof(char);
  358.     (*cu)->uname = (char *) malloc(msize);
  359.     strcpy((*cu)->uname,tmp);
  360.     pt = &tmp[0];
  361.     while( *pb && *pb != divider ) *(pt++) = *(pb++); *pt = '\0'; pb++;
  362.     msize = (strlen(tmp)+1)*sizeof(char);
  363.     (*cu)->seed = (char *) malloc(msize);
  364.     strcpy((*cu)->seed,tmp);
  365.     pt = &tmp[0];
  366.     while( *pb && *pb != divider ) *(pt++) = *(pb++); *pt = '\0'; pb++;
  367.     msize = (strlen(tmp)+1)*sizeof(char);
  368.     (*cu)->hash = (char *) malloc(msize);
  369.     strcpy((*cu)->hash,tmp);
  370.     stox(tmp,&((*cu)->sha256));
  371.     (*cu)->next = NULL;
  372.     if( (*pu) ) (*pu)->next = *cu;
  373.     return 0;
  374. }
  375.  
  376.  
  377. int insert_p(char * buffer, struct pfilest ** cp, struct pfilest ** pp ){
  378.     int i;
  379.     char tmp[1000];
  380.     char *pt,*pb;
  381.     size_t msize;
  382.     sha256_context ct2;
  383.     unsigned char sha256[32];
  384.  
  385.    
  386.     msize = sizeof(struct pfilest);
  387.     *cp = (struct pfilest *)malloc(msize);
  388.     if ( ! *cp ) {
  389.         perror("Malloc error for user file");
  390.         // Delete structure
  391.         return(255);
  392.     }
  393.     pb = buffer;
  394.     pt = &tmp[0];
  395.     while( *pb ) *(pt++) = *(pb++); *pt = '\0'; pb++;
  396.     msize = (strlen(tmp)+1)*sizeof(char);
  397.     (*cp)->pass = (char *) malloc(msize);
  398.     strcpy((*cp)->pass,tmp);
  399.    
  400.     sha256_starts( &ct2 );
  401.     sha256_update( &ct2, (uint8 *) buffer, strlen(buffer) );
  402.     sha256_finish( &ct2, sha256 );
  403.    
  404.     msize = 65*sizeof(char);
  405.     (*cp)->hash = (char *) malloc(msize);
  406.     for( i = 0; i < 32; i++ ) sprintf( (*cp)->hash + i * 2, "%02x", sha256[i] );
  407.     *((*cp)->hash + 65) = '\0';
  408.     (*cp)->next = NULL;
  409.     if( (*pp) ) (*pp)->next = *cp;
  410.     return 0;
  411. }
  412.  
  413. void myprint(int redir, FILE * fu, char * buffer){
  414.     if( redir ) {
  415.        fprintf(fu,buffer);
  416.     } else {
  417.        fprintf(stdout,buffer);  
  418.     }
  419. }
  420.  
  421.  
  422.  
  423. int main( int argc, char *argv[] )
  424. {
  425.     FILE *fu;
  426.     int i, j, c;
  427.     char output[255];
  428.     sha256_context ctx;
  429.     unsigned char buf[1000];
  430.     unsigned char sha256sum[32];
  431.     unsigned long cnt2;
  432.    
  433.     char inputline[1000];
  434.     char separator = ':';
  435.    
  436.     struct ufilest *cu = NULL, *pu = NULL, *su = NULL;
  437.     struct pfilest *cp = NULL, *pp = NULL, *sp = NULL;
  438.  
  439.     int digit_optind = 0;
  440.     char *ropt = 0, *popt = 0, *uopt = 0;
  441.     int this_option_optind;
  442.    
  443.     while ( (c = getopt(argc, argv, "p:P:u:U:r:R:")) != -1) {
  444.         this_option_optind = optind ? optind : 1;
  445.         switch (c) {
  446.         case 'p':
  447.         case 'P':  
  448.             popt = optarg;
  449.             break;
  450.         case 'r':
  451.         case 'R':  
  452.             ropt = optarg;
  453.             break;
  454.         case 'u':
  455.         case 'U':  
  456.             uopt = optarg;
  457.             break;
  458.         case '?':
  459.             printf("Usage: %s -u userfile -p passfile [-r resultfile]\n\tPass finder for sha256(sha256(pass)+seed))\n\tDefault output to stdout (if -r not specified)",argv[0]);
  460.             return(0);
  461.             break;
  462.         default:
  463.             printf ("?? getopt returned character code 0x%x ??\n", c);
  464.         }
  465.     }
  466.     if( argc < 3 ){
  467.         printf("Usage: %s -u userfile -p passfile [-r resultfile]\n\tPass finder for sha256(sha256(pass)+seed))\n\tDefault output to stdout (if -r not specified)",argv[0]);
  468.         exit(EXIT_FAILURE);
  469.     }
  470.     if ( access(popt,R_OK) ) { printf("RO access password file %s - denied of file doesn\'t exist\n",popt); exit(EXIT_FAILURE); }
  471.     if ( access(uopt,R_OK) ) { printf("RO access user file %s - denied of file doesn\'t exist\n",uopt); exit(EXIT_FAILURE); }
  472.    
  473.     if( ! (fu = fopen(uopt,"rt")) ){ perror("Can\'t open user file\n");     exit(EXIT_FAILURE); }
  474.     while (fgets(inputline, 1000, fu) != NULL) {
  475.         i = strlen(inputline)-1;
  476.         while( i && ( inputline[i] == '\n' || inputline[i] == '\r' ) ) inputline[i--] = '\0';
  477.         i = 0;
  478.         pu = cu;
  479.         insert_u(inputline,&cu,&pu,separator);
  480.         if( ! su ) su = cu;
  481.     }
  482.     fclose(fu);
  483.    
  484.     printf("************ User list\n");
  485. //  cu = su;
  486. //  while( cu ) {
  487. //    printf("User: %s Seed: %s Hash %s Hash2 %02x %02x\n",cu->uname,cu->seed,cu->hash,cu->sha256[0], cu->sha256[1]);
  488. //    cu = cu->next;
  489. //    }
  490.  
  491.    
  492.     if( ! (fu = fopen(popt,"rt")) ){ perror("Can\'t open password file\n");     exit(EXIT_FAILURE); }
  493.     while (fgets(inputline, 1000, fu) != NULL) {
  494.         i = strlen(inputline)-1;
  495.         while( i && ( inputline[i] == '\n' || inputline[i] == '\r' ) ) inputline[i--] = '\0';
  496.         i = 0;
  497.         pp = cp;
  498.         insert_p(inputline,&cp,&pp);
  499.         if( ! sp ) sp = cp;
  500.     }
  501.     fclose(fu); fu = NULL;
  502.    
  503.     printf("************ Pass list\n");
  504. //  cp = sp;
  505. //  while( cp ) {
  506. //    printf("Pass: %s Hash %s\n",cp->pass,cp->hash);
  507. //    cp = cp->next;
  508. //    }
  509.    
  510.     if( ropt ){
  511.         if( ! (fu = fopen(ropt,"w")) ) {  perror("Can\'t open result file\n");  exit(EXIT_FAILURE); }
  512.     }
  513.     c = fu ? 1 : 0;
  514.  
  515.     myprint(c,fu,"Start\n");
  516.     cnt2 = 0;
  517.     cp = sp;
  518.     while( cp ){
  519.        
  520.         cu = su;
  521.         while( cu ){
  522.             strcpy(buf,cp->hash);
  523.             strcat(buf,cu->seed);
  524.             sha256_starts( &ctx );
  525.             sha256_update( &ctx, (uint8 *) buf, strlen(buf) );
  526.             sha256_finish( &ctx, sha256sum );
  527.             if( (++cnt2 % 10000) == 0 ) printf("%lu\r",cnt2);
  528.             j = 1;
  529.             for( i = 0; i < 32; i++ )
  530.                if( cu->sha256[i] != sha256sum[i] ) {
  531.                   j = 0; break;
  532.                }
  533.             if( j ){
  534.                sprintf(output,"User: [%s] Pass: [%s]\n",cu->uname,cp->pass);
  535.                myprint(c,fu,output);
  536.             }
  537.             cu = cu->next;
  538.         }
  539.         cp = cp->next;
  540.     }
  541.  
  542.  
  543.     cp = sp;
  544.     while( cp ){
  545.         pp = cp;
  546.         cp = cp->next;
  547.         free(pp->hash);
  548.         free(pp->pass);
  549.         free(pp);
  550.     }
  551.    
  552.     cu = su;
  553.     while( cu ){
  554.         pu = cu;
  555.         cu = cu->next;
  556.         free(pu->hash);
  557.         free(pu->seed);
  558.         free(pu->uname);
  559.         free(pu);
  560.     }
  561.      
  562.        
  563.     if( c )fclose(fu);
  564.     system("PAUSE");
  565.     return( 0 );
  566. }
Advertisement
Add Comment
Please, Sign In to add comment