SHOW:
|
|
- or go back to the newest paste.
| 1 | - | /* Changelog |
| 1 | + | /* Pass finder for SHA256(SHA256(password)+salt)) |
| 2 | *Changelog | |
| 3 | * Version 1.00 | |
| 4 | * Initial version | |
| 5 | * Version 1.01 | |
| 6 | * Speeded up approximately 500 times. | |
| 7 | * Now instead of writing all passwords from dictionary and their hashes to result file | |
| 8 | - | * "Parole: password Hash: 5e884898da280410e88a656f8dc6292773603d0d6aabbdd625jd72nhkd1542d |
| 8 | + | |
| 9 | * e.g | |
| 10 | * User: [creeperdaddy] Pass: [123456] | |
| 11 | * Added status, shows amount of SHA256 operations, updates every tenth thousand operation. | |
| 12 | * Added Command line options -u [file with user name:salt:sha256] -p [dictionary] -r [result file] | |
| 13 | * Points out the problem, if no input files given. | |
| 14 | * Version 1.02 | |
| 15 | * Multi threading support (Up to 8 cores) | |
| 16 | * Added delimiter option | |
| 17 | - | * Pass finder for SHA256(SHA256(password)+salt)) |
| 17 | + | * Added skip option. |
| 18 | - | * Input |
| 18 | + | |
| 19 | - | * SHATEST.exe -u dbdump.txt -p twitter-banned.txt -r twitter-banned.txt.res |
| 19 | + | |
| 20 | - | * 1. File containing Username:Salt:SHA256 of password |
| 20 | + | * Usage: SHADEC.exe -u userfile [-d delimiter] {-p passfile|-P passfile} -1|2|4|8
|
| 21 | - | * e.g creeperdaddy:633d06d3d95c64ac:349b5849410e88a67ce4fbd938b9e6f8ba53bd9a5167d9787cbfa2eeb520a1d1 |
| 21 | + | * [-s skip_number] [-r resultfile [-o]] |
| 22 | - | * 2. Dictionary |
| 22 | + | * Pass finder for sha256(sha256(pass)+seed)) |
| 23 | - | * e.g twitter-banned.txt |
| 23 | + | * User file format is username<delimiter>seed<delimiter>hash_as_hex_string |
| 24 | - | * 3. Output file |
| 24 | + | * Default delimiter ':' (can be changed by -d) |
| 25 | * Default output to stdout (if -r not specified) | |
| 26 | * -1248 Limit core usage to 1/2/4/8. default - maximum available | |
| 27 | * -s skip first nums of pass (to continue) | |
| 28 | * -o overwrite output file (default - append) | |
| 29 | * -u and either -p or -P parameters are mandatory | |
| 30 | * -p loads pass into memory (program uses more memory) | |
| 31 | * -P keep pass file open in time of calculation | |
| 32 | * | |
| 33 | * FIPS-180-2 compliant SHA-256 implementation | |
| 34 | * | |
| 35 | * Copyright (C) 2001-2003 Christophe Devine | |
| 36 | * | |
| 37 | * This program is free software; you can redistribute it and/or modify | |
| 38 | * it under the terms of the GNU General Public License as published by | |
| 39 | * the Free Software Foundation; either version 2 of the License, or | |
| 40 | * (at your option) any later version. | |
| 41 | * | |
| 42 | * This program is distributed in the hope that it will be useful, | |
| 43 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 44 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 45 | * GNU General Public License for more details. | |
| 46 | * | |
| 47 | * You should have received a copy of the GNU General Public License | |
| 48 | * along with this program; if not, write to the Free Software | |
| 49 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 50 | */ | |
| 51 | ||
| 52 | #include <string.h> | |
| 53 | #include <unistd.h> | |
| 54 | #include <sys/types.h> | |
| 55 | #include <sys/stat.h> | |
| 56 | #include <stdlib.h> | |
| 57 | #include <stdio.h> | |
| 58 | #include <time.h> | |
| 59 | ||
| 60 | #include <omp.h> | |
| 61 | ||
| 62 | #include "sha256.h" | |
| 63 | ||
| 64 | #define GET_UINT32(n,b,i) \ | |
| 65 | { \
| |
| 66 | (n) = ( (uint32) (b)[(i) ] << 24 ) \ | |
| 67 | | ( (uint32) (b)[(i) + 1] << 16 ) \ | |
| 68 | | ( (uint32) (b)[(i) + 2] << 8 ) \ | |
| 69 | | ( (uint32) (b)[(i) + 3] ); \ | |
| 70 | } | |
| 71 | ||
| 72 | #define PUT_UINT32(n,b,i) \ | |
| 73 | { \
| |
| 74 | (b)[(i) ] = (uint8) ( (n) >> 24 ); \ | |
| 75 | (b)[(i) + 1] = (uint8) ( (n) >> 16 ); \ | |
| 76 | (b)[(i) + 2] = (uint8) ( (n) >> 8 ); \ | |
| 77 | (b)[(i) + 3] = (uint8) ( (n) ); \ | |
| 78 | } | |
| 79 | ||
| 80 | void sha256_starts( sha256_context *ctx ) | |
| 81 | {
| |
| 82 | ctx->total[0] = 0; | |
| 83 | ctx->total[1] = 0; | |
| 84 | ||
| 85 | ctx->state[0] = 0x6A09E667; | |
| 86 | ctx->state[1] = 0xBB67AE85; | |
| 87 | ctx->state[2] = 0x3C6EF372; | |
| 88 | ctx->state[3] = 0xA54FF53A; | |
| 89 | ctx->state[4] = 0x510E527F; | |
| 90 | ctx->state[5] = 0x9B05688C; | |
| 91 | ctx->state[6] = 0x1F83D9AB; | |
| 92 | ctx->state[7] = 0x5BE0CD19; | |
| 93 | } | |
| 94 | ||
| 95 | void sha256_process( sha256_context *ctx, uint8 data[64] ) | |
| 96 | {
| |
| 97 | uint32 temp1, temp2, W[64]; | |
| 98 | uint32 A, B, C, D, E, F, G, H; | |
| 99 | ||
| 100 | GET_UINT32( W[0], data, 0 ); | |
| 101 | GET_UINT32( W[1], data, 4 ); | |
| 102 | GET_UINT32( W[2], data, 8 ); | |
| 103 | GET_UINT32( W[3], data, 12 ); | |
| 104 | GET_UINT32( W[4], data, 16 ); | |
| 105 | GET_UINT32( W[5], data, 20 ); | |
| 106 | GET_UINT32( W[6], data, 24 ); | |
| 107 | GET_UINT32( W[7], data, 28 ); | |
| 108 | GET_UINT32( W[8], data, 32 ); | |
| 109 | GET_UINT32( W[9], data, 36 ); | |
| 110 | GET_UINT32( W[10], data, 40 ); | |
| 111 | GET_UINT32( W[11], data, 44 ); | |
| 112 | GET_UINT32( W[12], data, 48 ); | |
| 113 | GET_UINT32( W[13], data, 52 ); | |
| 114 | GET_UINT32( W[14], data, 56 ); | |
| 115 | GET_UINT32( W[15], data, 60 ); | |
| 116 | ||
| 117 | #define SHR(x,n) ((x & 0xFFFFFFFF) >> n) | |
| 118 | #define ROTR(x,n) (SHR(x,n) | (x << (32 - n))) | |
| 119 | ||
| 120 | #define S0(x) (ROTR(x, 7) ^ ROTR(x,18) ^ SHR(x, 3)) | |
| 121 | #define S1(x) (ROTR(x,17) ^ ROTR(x,19) ^ SHR(x,10)) | |
| 122 | ||
| 123 | #define S2(x) (ROTR(x, 2) ^ ROTR(x,13) ^ ROTR(x,22)) | |
| 124 | #define S3(x) (ROTR(x, 6) ^ ROTR(x,11) ^ ROTR(x,25)) | |
| 125 | ||
| 126 | #define F0(x,y,z) ((x & y) | (z & (x | y))) | |
| 127 | #define F1(x,y,z) (z ^ (x & (y ^ z))) | |
| 128 | ||
| 129 | #define R(t) \ | |
| 130 | ( \ | |
| 131 | W[t] = S1(W[t - 2]) + W[t - 7] + \ | |
| 132 | S0(W[t - 15]) + W[t - 16] \ | |
| 133 | ) | |
| 134 | ||
| 135 | #define P(a,b,c,d,e,f,g,h,x,K) \ | |
| 136 | { \
| |
| 137 | temp1 = h + S3(e) + F1(e,f,g) + K + x; \ | |
| 138 | temp2 = S2(a) + F0(a,b,c); \ | |
| 139 | d += temp1; h = temp1 + temp2; \ | |
| 140 | } | |
| 141 | ||
| 142 | A = ctx->state[0]; | |
| 143 | B = ctx->state[1]; | |
| 144 | C = ctx->state[2]; | |
| 145 | D = ctx->state[3]; | |
| 146 | E = ctx->state[4]; | |
| 147 | F = ctx->state[5]; | |
| 148 | G = ctx->state[6]; | |
| 149 | H = ctx->state[7]; | |
| 150 | ||
| 151 | P( A, B, C, D, E, F, G, H, W[ 0], 0x428A2F98 ); | |
| 152 | P( H, A, B, C, D, E, F, G, W[ 1], 0x71374491 ); | |
| 153 | P( G, H, A, B, C, D, E, F, W[ 2], 0xB5C0FBCF ); | |
| 154 | P( F, G, H, A, B, C, D, E, W[ 3], 0xE9B5DBA5 ); | |
| 155 | P( E, F, G, H, A, B, C, D, W[ 4], 0x3956C25B ); | |
| 156 | P( D, E, F, G, H, A, B, C, W[ 5], 0x59F111F1 ); | |
| 157 | P( C, D, E, F, G, H, A, B, W[ 6], 0x923F82A4 ); | |
| 158 | P( B, C, D, E, F, G, H, A, W[ 7], 0xAB1C5ED5 ); | |
| 159 | P( A, B, C, D, E, F, G, H, W[ 8], 0xD807AA98 ); | |
| 160 | P( H, A, B, C, D, E, F, G, W[ 9], 0x12835B01 ); | |
| 161 | P( G, H, A, B, C, D, E, F, W[10], 0x243185BE ); | |
| 162 | P( F, G, H, A, B, C, D, E, W[11], 0x550C7DC3 ); | |
| 163 | P( E, F, G, H, A, B, C, D, W[12], 0x72BE5D74 ); | |
| 164 | P( D, E, F, G, H, A, B, C, W[13], 0x80DEB1FE ); | |
| 165 | P( C, D, E, F, G, H, A, B, W[14], 0x9BDC06A7 ); | |
| 166 | P( B, C, D, E, F, G, H, A, W[15], 0xC19BF174 ); | |
| 167 | P( A, B, C, D, E, F, G, H, R(16), 0xE49B69C1 ); | |
| 168 | P( H, A, B, C, D, E, F, G, R(17), 0xEFBE4786 ); | |
| 169 | P( G, H, A, B, C, D, E, F, R(18), 0x0FC19DC6 ); | |
| 170 | P( F, G, H, A, B, C, D, E, R(19), 0x240CA1CC ); | |
| 171 | P( E, F, G, H, A, B, C, D, R(20), 0x2DE92C6F ); | |
| 172 | P( D, E, F, G, H, A, B, C, R(21), 0x4A7484AA ); | |
| 173 | P( C, D, E, F, G, H, A, B, R(22), 0x5CB0A9DC ); | |
| 174 | P( B, C, D, E, F, G, H, A, R(23), 0x76F988DA ); | |
| 175 | P( A, B, C, D, E, F, G, H, R(24), 0x983E5152 ); | |
| 176 | P( H, A, B, C, D, E, F, G, R(25), 0xA831C66D ); | |
| 177 | P( G, H, A, B, C, D, E, F, R(26), 0xB00327C8 ); | |
| 178 | P( F, G, H, A, B, C, D, E, R(27), 0xBF597FC7 ); | |
| 179 | P( E, F, G, H, A, B, C, D, R(28), 0xC6E00BF3 ); | |
| 180 | P( D, E, F, G, H, A, B, C, R(29), 0xD5A79147 ); | |
| 181 | P( C, D, E, F, G, H, A, B, R(30), 0x06CA6351 ); | |
| 182 | P( B, C, D, E, F, G, H, A, R(31), 0x14292967 ); | |
| 183 | P( A, B, C, D, E, F, G, H, R(32), 0x27B70A85 ); | |
| 184 | P( H, A, B, C, D, E, F, G, R(33), 0x2E1B2138 ); | |
| 185 | P( G, H, A, B, C, D, E, F, R(34), 0x4D2C6DFC ); | |
| 186 | P( F, G, H, A, B, C, D, E, R(35), 0x53380D13 ); | |
| 187 | P( E, F, G, H, A, B, C, D, R(36), 0x650A7354 ); | |
| 188 | P( D, E, F, G, H, A, B, C, R(37), 0x766A0ABB ); | |
| 189 | P( C, D, E, F, G, H, A, B, R(38), 0x81C2C92E ); | |
| 190 | P( B, C, D, E, F, G, H, A, R(39), 0x92722C85 ); | |
| 191 | P( A, B, C, D, E, F, G, H, R(40), 0xA2BFE8A1 ); | |
| 192 | P( H, A, B, C, D, E, F, G, R(41), 0xA81A664B ); | |
| 193 | P( G, H, A, B, C, D, E, F, R(42), 0xC24B8B70 ); | |
| 194 | P( F, G, H, A, B, C, D, E, R(43), 0xC76C51A3 ); | |
| 195 | P( E, F, G, H, A, B, C, D, R(44), 0xD192E819 ); | |
| 196 | P( D, E, F, G, H, A, B, C, R(45), 0xD6990624 ); | |
| 197 | P( C, D, E, F, G, H, A, B, R(46), 0xF40E3585 ); | |
| 198 | P( B, C, D, E, F, G, H, A, R(47), 0x106AA070 ); | |
| 199 | P( A, B, C, D, E, F, G, H, R(48), 0x19A4C116 ); | |
| 200 | P( H, A, B, C, D, E, F, G, R(49), 0x1E376C08 ); | |
| 201 | P( G, H, A, B, C, D, E, F, R(50), 0x2748774C ); | |
| 202 | P( F, G, H, A, B, C, D, E, R(51), 0x34B0BCB5 ); | |
| 203 | P( E, F, G, H, A, B, C, D, R(52), 0x391C0CB3 ); | |
| 204 | P( D, E, F, G, H, A, B, C, R(53), 0x4ED8AA4A ); | |
| 205 | P( C, D, E, F, G, H, A, B, R(54), 0x5B9CCA4F ); | |
| 206 | P( B, C, D, E, F, G, H, A, R(55), 0x682E6FF3 ); | |
| 207 | P( A, B, C, D, E, F, G, H, R(56), 0x748F82EE ); | |
| 208 | P( H, A, B, C, D, E, F, G, R(57), 0x78A5636F ); | |
| 209 | P( G, H, A, B, C, D, E, F, R(58), 0x84C87814 ); | |
| 210 | P( F, G, H, A, B, C, D, E, R(59), 0x8CC70208 ); | |
| 211 | P( E, F, G, H, A, B, C, D, R(60), 0x90BEFFFA ); | |
| 212 | P( D, E, F, G, H, A, B, C, R(61), 0xA4506CEB ); | |
| 213 | P( C, D, E, F, G, H, A, B, R(62), 0xBEF9A3F7 ); | |
| 214 | P( B, C, D, E, F, G, H, A, R(63), 0xC67178F2 ); | |
| 215 | ||
| 216 | ctx->state[0] += A; | |
| 217 | ctx->state[1] += B; | |
| 218 | ctx->state[2] += C; | |
| 219 | ctx->state[3] += D; | |
| 220 | ctx->state[4] += E; | |
| 221 | ctx->state[5] += F; | |
| 222 | ctx->state[6] += G; | |
| 223 | ctx->state[7] += H; | |
| 224 | } | |
| 225 | ||
| 226 | void sha256_update( sha256_context *ctx, uint8 *input, uint32 length ) | |
| 227 | {
| |
| 228 | uint32 left, fill; | |
| 229 | ||
| 230 | if( ! length ) return; | |
| 231 | ||
| 232 | left = ctx->total[0] & 0x3F; | |
| 233 | fill = 64 - left; | |
| 234 | ||
| 235 | ctx->total[0] += length; | |
| 236 | ctx->total[0] &= 0xFFFFFFFF; | |
| 237 | ||
| 238 | if( ctx->total[0] < length ) | |
| 239 | ctx->total[1]++; | |
| 240 | ||
| 241 | if( left && length >= fill ) | |
| 242 | {
| |
| 243 | memcpy( (void *) (ctx->buffer + left), | |
| 244 | (void *) input, fill ); | |
| 245 | sha256_process( ctx, ctx->buffer ); | |
| 246 | length -= fill; | |
| 247 | input += fill; | |
| 248 | left = 0; | |
| 249 | } | |
| 250 | ||
| 251 | while( length >= 64 ) | |
| 252 | {
| |
| 253 | sha256_process( ctx, input ); | |
| 254 | length -= 64; | |
| 255 | input += 64; | |
| 256 | } | |
| 257 | ||
| 258 | if( length ) | |
| 259 | {
| |
| 260 | memcpy( (void *) (ctx->buffer + left), | |
| 261 | (void *) input, length ); | |
| 262 | } | |
| 263 | } | |
| 264 | ||
| 265 | static uint8 sha256_padding[64] = | |
| 266 | {
| |
| 267 | 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 268 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 269 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
| 270 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | |
| 271 | }; | |
| 272 | ||
| 273 | void sha256_finish( sha256_context *ctx, uint8 digest[32] ) | |
| 274 | {
| |
| 275 | uint32 last, padn; | |
| 276 | uint32 high, low; | |
| 277 | uint8 msglen[8]; | |
| 278 | ||
| 279 | high = ( ctx->total[0] >> 29 ) | |
| 280 | | ( ctx->total[1] << 3 ); | |
| 281 | low = ( ctx->total[0] << 3 ); | |
| 282 | ||
| 283 | PUT_UINT32( high, msglen, 0 ); | |
| 284 | PUT_UINT32( low, msglen, 4 ); | |
| 285 | ||
| 286 | last = ctx->total[0] & 0x3F; | |
| 287 | padn = ( last < 56 ) ? ( 56 - last ) : ( 120 - last ); | |
| 288 | ||
| 289 | sha256_update( ctx, sha256_padding, padn ); | |
| 290 | sha256_update( ctx, msglen, 8 ); | |
| 291 | ||
| 292 | PUT_UINT32( ctx->state[0], digest, 0 ); | |
| 293 | - | /* |
| 293 | + | |
| 294 | - | * those are the standard FIPS-180-2 test vectors |
| 294 | + | |
| 295 | PUT_UINT32( ctx->state[3], digest, 12 ); | |
| 296 | - | /* |
| 296 | + | |
| 297 | - | static char *msg[] = |
| 297 | + | |
| 298 | PUT_UINT32( ctx->state[6], digest, 24 ); | |
| 299 | - | "abc", |
| 299 | + | |
| 300 | - | "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", |
| 300 | + | |
| 301 | - | NULL |
| 301 | + | |
| 302 | typedef struct ufilest {
| |
| 303 | char* uname; | |
| 304 | - | static char *val[] = |
| 304 | + | |
| 305 | char* hash; | |
| 306 | - | "ba7816bf8f01cfea414140de5dae2223" \ |
| 306 | + | char found; |
| 307 | - | "b00361a396177a9cb410ff61f20015ad", |
| 307 | + | |
| 308 | - | "248d6a61d20638b8e5c026930c3e6039" \ |
| 308 | + | |
| 309 | - | "a33ce45964ff2167f6ecedd419db06c1", |
| 309 | + | |
| 310 | - | "cdc76e5c9914fb9281a1c7e284d73e67" \ |
| 310 | + | |
| 311 | - | "f1809a48a497200e046d39ccc7112cd0" |
| 311 | + | |
| 312 | char* pass; | |
| 313 | - | */ |
| 313 | + | |
| 314 | struct pfilest *next; | |
| 315 | } pfilest; | |
| 316 | ||
| 317 | #define HELPTEXT "Usage: %s -u userfile [-d delimiter] {-p passfile|-P passfile} -1|2|4|8 [-s skip_number] [-r resultfile [-o]]\n" \
| |
| 318 | "\tPass finder for sha256(sha256(pass)+seed))\n" \ | |
| 319 | "\tUser file format is username<delimiter>seed<delimiter>hash_as_hex_string\n" \ | |
| 320 | "\tDefault delimiter \':\' (can be changed by -d)\n" \ | |
| 321 | "\tDefault output to stdout (if -r not specified)\n" \ | |
| 322 | "\t-1248 Limit core usage to 1/2/4/8. default - maximum available\n" \ | |
| 323 | "\t-s skip first nums of pass (to continue)\n" \ | |
| 324 | "\t-o overwrite output file (default - append)\n" \ | |
| 325 | "\t-u and either -p or -P parameters are mandatory\n" \ | |
| 326 | "\t-p loads pass into memory (program use more memory)\n" \ | |
| 327 | "\t-P keep pass file open in time of calculation\n" | |
| 328 | ||
| 329 | ||
| 330 | unsigned char ctox(char c){
| |
| 331 | unsigned char rc = 0; | |
| 332 | if( c >= '0' && c <= '9' ) rc = c - '0'; | |
| 333 | else if (c >= 'A' && c <= 'F') rc = c - 'A' + 10; | |
| 334 | else if (c >= 'a' && c <= 'f') rc = c - 'a' + 10; | |
| 335 | return rc; | |
| 336 | } | |
| 337 | ||
| 338 | unsigned char stox(char *s, unsigned char (*t)[32]){
| |
| 339 | int i; | |
| 340 | - | return 0; |
| 340 | + | |
| 341 | (*t)[i] = ctox(*(s+i*2))<<4 | ctox(*(s+i*2+1)); | |
| 342 | return 0; | |
| 343 | } | |
| 344 | ||
| 345 | void print_help(char *arg){
| |
| 346 | fprintf(stderr,HELPTEXT,arg); | |
| 347 | } | |
| 348 | ||
| 349 | int insert_u(char * buffer, struct ufilest ** cu, struct ufilest ** pu, char divider ){
| |
| 350 | - | perror("Malloc error for user file");
|
| 350 | + | |
| 351 | char *pt,*pb; | |
| 352 | size_t msize; | |
| 353 | msize = sizeof(struct ufilest); | |
| 354 | *cu = (struct ufilest *)malloc(msize); | |
| 355 | if ( ! *cu ) {
| |
| 356 | perror("Malloc error for user file");
| |
| 357 | // Delete structure | |
| 358 | return(255); | |
| 359 | } | |
| 360 | pb = buffer; | |
| 361 | pt = &tmp[0]; | |
| 362 | while( *pb && *pb != divider ) *(pt++) = *(pb++); *pt = '\0'; pb++; | |
| 363 | msize = (strlen(tmp)+1)*sizeof(char); | |
| 364 | (*cu)->uname = (char *) malloc(msize); | |
| 365 | strcpy((*cu)->uname,tmp); | |
| 366 | pt = &tmp[0]; | |
| 367 | while( *pb && *pb != divider ) *(pt++) = *(pb++); *pt = '\0'; pb++; | |
| 368 | msize = (strlen(tmp)+1)*sizeof(char); | |
| 369 | (*cu)->seed = (char *) malloc(msize); | |
| 370 | strcpy((*cu)->seed,tmp); | |
| 371 | pt = &tmp[0]; | |
| 372 | while( *pb && *pb != divider ) *(pt++) = *(pb++); *pt = '\0'; pb++; | |
| 373 | msize = (strlen(tmp)+1)*sizeof(char); | |
| 374 | (*cu)->hash = (char *) malloc(msize); | |
| 375 | strcpy((*cu)->hash,tmp); | |
| 376 | stox(tmp,&((*cu)->sha256)); | |
| 377 | (*cu)->found = 0; | |
| 378 | (*cu)->next = NULL; | |
| 379 | if( (*pu) ) (*pu)->next = *cu; | |
| 380 | return 0; | |
| 381 | } | |
| 382 | ||
| 383 | ||
| 384 | int insert_p(char * buffer, struct pfilest ** cp, struct pfilest ** pp ){
| |
| 385 | - | |
| 385 | + | |
| 386 | char tmp[1000]; | |
| 387 | char *pt,*pb; | |
| 388 | size_t msize; | |
| 389 | - | perror("Malloc error for user file");
|
| 389 | + | |
| 390 | unsigned char sha256[32]; | |
| 391 | ||
| 392 | ||
| 393 | msize = sizeof(struct pfilest); | |
| 394 | *cp = (struct pfilest *)malloc(msize); | |
| 395 | if ( ! *cp ) {
| |
| 396 | perror("Malloc error for user file");
| |
| 397 | // Delete structure | |
| 398 | return(255); | |
| 399 | - | |
| 399 | + | |
| 400 | pb = buffer; | |
| 401 | pt = &tmp[0]; | |
| 402 | while( *pb ) *(pt++) = *(pb++); *pt = '\0'; pb++; | |
| 403 | msize = (strlen(tmp)+1)*sizeof(char); | |
| 404 | (*cp)->pass = (char *) malloc(msize); | |
| 405 | strcpy((*cp)->pass,tmp); | |
| 406 | ||
| 407 | sha256_starts( &ct2 ); | |
| 408 | sha256_update( &ct2, (uint8 *) buffer, strlen(buffer) ); | |
| 409 | sha256_finish( &ct2, sha256 ); | |
| 410 | ||
| 411 | msize = 65*sizeof(char); | |
| 412 | (*cp)->hash = (char *) malloc(msize); | |
| 413 | - | void myprint(int redir, FILE * fu, char * buffer){
|
| 413 | + | |
| 414 | - | if( redir ) {
|
| 414 | + | |
| 415 | - | fprintf(fu,buffer); |
| 415 | + | |
| 416 | - | } else {
|
| 416 | + | |
| 417 | - | fprintf(stdout,buffer); |
| 417 | + | |
| 418 | } | |
| 419 | ||
| 420 | inline void myprint(int redir, FILE * fu, char * buffer){
| |
| 421 | if (redir == 1) fprintf(fu,buffer); | |
| 422 | else printf(buffer); | |
| 423 | } | |
| 424 | ||
| 425 | - | FILE *fu; |
| 425 | + | inline void print_progress(int thr,unsigned long * cnt2){
|
| 426 | - | int i, j, c; |
| 426 | + | switch(thr){
|
| 427 | - | char output[255]; |
| 427 | + | case 1: printf("Passwords: %09lu\r",*(cnt2)); break;
|
| 428 | case 2: printf("Passwords: %09lu %09lu\r",*(cnt2),*(cnt2+1)); break;
| |
| 429 | - | unsigned char buf[1000]; |
| 429 | + | case 4: printf("Passwords: %09lu %09lu %09lu %09lu\r",*(cnt2),*(cnt2+1),*(cnt2+2),*(cnt2+3)); break;
|
| 430 | - | unsigned char sha256sum[32]; |
| 430 | + | case 8: printf("Passwords: %09lu %09lu %09lu %09lu %09lu %09lu %09lu %09lu\r",*(cnt2),*(cnt2+1),*(cnt2+2),*(cnt2+3),*(cnt2+4),*(cnt2+5),*(cnt2+6),*(cnt2+7)); break;
|
| 431 | - | unsigned long cnt2; |
| 431 | + | |
| 432 | } | |
| 433 | - | char inputline[1000]; |
| 433 | + | |
| 434 | - | char separator = ':'; |
| 434 | + | void process_memory_pass(int tid,int numt,struct pfilest * sp,struct pfilest * cp,struct pfilest * pp,struct ufilest * su,struct ufilest * cu,struct ufilest * pu,unsigned long *cnt2, FILE *fu, int c){
|
| 435 | int i,j; | |
| 436 | char output[160],buf[160]; | |
| 437 | - | struct pfilest *cp = NULL, *pp = NULL, *sp = NULL; |
| 437 | + | unsigned char sha256sum[32]; |
| 438 | sha256_context ctx; | |
| 439 | - | int digit_optind = 0; |
| 439 | + | cp = sp; |
| 440 | while( cp ){
| |
| 441 | - | int this_option_optind; |
| 441 | + | cu = su; |
| 442 | ++(*(cnt2+tid)); | |
| 443 | - | while ( (c = getopt(argc, argv, "p:P:u:U:r:R:")) != -1) {
|
| 443 | + | if( tid == 0 || (*cnt2) % 1000 == 0 ){
|
| 444 | - | this_option_optind = optind ? optind : 1; |
| 444 | + | print_progress(numt,cnt2); |
| 445 | } | |
| 446 | while( cu ){
| |
| 447 | - | case 'P': |
| 447 | + | if( ! cu->found ){
|
| 448 | strcpy(buf,cp->hash); | |
| 449 | strcat(buf,cu->seed); | |
| 450 | sha256_starts( &ctx ); | |
| 451 | - | case 'R': |
| 451 | + | sha256_update( &ctx, (uint8 *) buf, strlen(buf) ); |
| 452 | sha256_finish( &ctx, sha256sum ); | |
| 453 | j = 1; | |
| 454 | for( i = 0; i < 32; i++ ) | |
| 455 | - | case 'U': |
| 455 | + | if( cu->sha256[i] != sha256sum[i] ) {
|
| 456 | j = 0; break; | |
| 457 | } | |
| 458 | if( j ){
| |
| 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]);
|
| 459 | + | sprintf(output,"User: [%s] Pass: [%s]\n",cu->uname,cp->pass); |
| 460 | myprint(c,fu,output); | |
| 461 | cu->found = 1; | |
| 462 | } | |
| 463 | } | |
| 464 | cu = cu->next; | |
| 465 | } | |
| 466 | - | if( argc < 3 ){
|
| 466 | + | cp = cp->next; |
| 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]);
|
| 467 | + | |
| 468 | - | exit(EXIT_FAILURE); |
| 468 | + | cp = sp; |
| 469 | while( cp ){
| |
| 470 | - | if ( access(popt,R_OK) ) { printf("RO access password file %s - denied of file doesn\'t exist\n",popt); exit(EXIT_FAILURE); }
|
| 470 | + | pp = cp; |
| 471 | - | if ( access(uopt,R_OK) ) { printf("RO access user file %s - denied of file doesn\'t exist\n",uopt); exit(EXIT_FAILURE); }
|
| 471 | + | cp = cp->next; |
| 472 | free(pp->hash); | |
| 473 | free(pp->pass); | |
| 474 | - | while (fgets(inputline, 1000, fu) != NULL) {
|
| 474 | + | free(pp); |
| 475 | - | i = strlen(inputline)-1; |
| 475 | + | |
| 476 | - | while( i && ( inputline[i] == '\n' || inputline[i] == '\r' ) ) inputline[i--] = '\0'; |
| 476 | + | |
| 477 | - | i = 0; |
| 477 | + | |
| 478 | ||
| 479 | - | insert_u(inputline,&cu,&pu,separator); |
| 479 | + | void process_disk_pass(int tid,int numt,int bst, char * inputline, struct ufilest * su,struct ufilest * cu,struct ufilest * pu,unsigned long *cnt2, FILE *fu, int c){
|
| 480 | int i,j; | |
| 481 | char cph[81],output[160]; | |
| 482 | unsigned char sha256sum[32]; | |
| 483 | - | |
| 483 | + | |
| 484 | - | printf("************ User list\n");
|
| 484 | + | |
| 485 | if( bst ){
| |
| 486 | i = strlen(inputline)-1; | |
| 487 | while( i && ( inputline[i] == '\n' || inputline[i] == '\r' ) ) inputline[i--] = '\0'; | |
| 488 | ++(*(cnt2+tid)); | |
| 489 | if( tid == 0 || (*cnt2) % 1000 == 0 ){
| |
| 490 | - | |
| 490 | + | print_progress(numt,cnt2); |
| 491 | } | |
| 492 | - | if( ! (fu = fopen(popt,"rt")) ){ perror("Can\'t open password file\n"); exit(EXIT_FAILURE); }
|
| 492 | + | sha256_starts( &ctx ); |
| 493 | - | while (fgets(inputline, 1000, fu) != NULL) {
|
| 493 | + | sha256_update( &ctx, (uint8 *) inputline, strlen(inputline) ); |
| 494 | - | i = strlen(inputline)-1; |
| 494 | + | sha256_finish( &ctx, sha256sum ); |
| 495 | - | while( i && ( inputline[i] == '\n' || inputline[i] == '\r' ) ) inputline[i--] = '\0'; |
| 495 | + | for( i = 0; i < 32; i++ ) sprintf( &cph[i*2], "%02x", sha256sum[i] ); |
| 496 | - | i = 0; |
| 496 | + | cph[64] = '\0'; |
| 497 | - | pp = cp; |
| 497 | + | cu = su; |
| 498 | - | insert_p(inputline,&cp,&pp); |
| 498 | + | |
| 499 | - | if( ! sp ) sp = cp; |
| 499 | + | if( ! cu->found ){
|
| 500 | strcpy(&cph[64],cu->seed); | |
| 501 | - | fclose(fu); fu = NULL; |
| 501 | + | sha256_starts( &ctx ); |
| 502 | sha256_update( &ctx, (uint8 *) cph, strlen(cph) ); | |
| 503 | - | printf("************ Pass list\n");
|
| 503 | + | sha256_finish( &ctx, sha256sum ); |
| 504 | j = 1; | |
| 505 | for( i = 0; i < 32; i++ ) | |
| 506 | if( cu->sha256[i] != sha256sum[i] ) {
| |
| 507 | j = 0; break; | |
| 508 | - | // } |
| 508 | + | } |
| 509 | if( j ){
| |
| 510 | sprintf(output,"User: [%s] Pass: [%s]\n",cu->uname,inputline); | |
| 511 | - | if( ! (fu = fopen(ropt,"w")) ) { perror("Can\'t open result file\n"); exit(EXIT_FAILURE); }
|
| 511 | + | myprint(c,fu,output); |
| 512 | cu->found = 1; | |
| 513 | - | c = fu ? 1 : 0; |
| 513 | + | } |
| 514 | } | |
| 515 | - | myprint(c,fu,"Start\n"); |
| 515 | + | cu = cu->next; |
| 516 | } | |
| 517 | - | cp = sp; |
| 517 | + | } |
| 518 | - | while( cp ){
|
| 518 | + | |
| 519 | } | |
| 520 | - | cu = su; |
| 520 | + | |
| 521 | ||
| 522 | - | strcpy(buf,cp->hash); |
| 522 | + | |
| 523 | - | strcat(buf,cu->seed); |
| 523 | + | |
| 524 | - | sha256_starts( &ctx ); |
| 524 | + | FILE *fu,*fp; |
| 525 | - | sha256_update( &ctx, (uint8 *) buf, strlen(buf) ); |
| 525 | + | int i, j, c ; |
| 526 | - | sha256_finish( &ctx, sha256sum ); |
| 526 | + | unsigned long cnt2,cnt2p[8],skipline = 0; |
| 527 | - | if( (++cnt2 % 10000) == 0 ) printf("%lu\r",cnt2);
|
| 527 | + | |
| 528 | - | j = 1; |
| 528 | + | |
| 529 | - | for( i = 0; i < 32; i++ ) |
| 529 | + | time_t stt,ent; |
| 530 | - | if( cu->sha256[i] != sha256sum[i] ) {
|
| 530 | + | |
| 531 | - | j = 0; break; |
| 531 | + | int tid,maxtid,maxpar = 8; |
| 532 | - | } |
| 532 | + | int overwrite = 0; |
| 533 | - | if( j ){
|
| 533 | + | |
| 534 | - | sprintf(output,"User: [%s] Pass: [%s]\n",cu->uname,cp->pass); |
| 534 | + | char inputline[8][1000]; |
| 535 | - | myprint(c,fu,output); |
| 535 | + | char separator = ':',bst[8]; |
| 536 | ||
| 537 | - | cu = cu->next; |
| 537 | + | |
| 538 | struct pfilest *cp[8], *pp[8], *sp[8]; | |
| 539 | - | cp = cp->next; |
| 539 | + | |
| 540 | int ptype = 0; | |
| 541 | char *ropt = 0, *popt = 0, *uopt = 0; | |
| 542 | ||
| 543 | - | cp = sp; |
| 543 | + | for(i = 0; i < 8; i++ ){ cp[i] = NULL; sp[i] = NULL; pp[i] = NULL; cnt2p[i] = 0; }
|
| 544 | - | while( cp ){
|
| 544 | + | |
| 545 | - | pp = cp; |
| 545 | + | while ( (c = getopt(argc, argv, "p:P:u:r:R:1248s:od:")) != -1) {
|
| 546 | - | cp = cp->next; |
| 546 | + | |
| 547 | - | free(pp->hash); |
| 547 | + | case '1': |
| 548 | - | free(pp->pass); |
| 548 | + | case '2': |
| 549 | - | free(pp); |
| 549 | + | case '4': |
| 550 | case '8': | |
| 551 | maxpar = c - '0'; | |
| 552 | break; | |
| 553 | case 'o': | |
| 554 | overwrite = 1; | |
| 555 | break; | |
| 556 | case 'p': | |
| 557 | popt = optarg; | |
| 558 | ptype = 1; | |
| 559 | break; | |
| 560 | case 'P': | |
| 561 | - | |
| 561 | + | |
| 562 | - | |
| 562 | + | ptype = 2; |
| 563 | - | if( c )fclose(fu); |
| 563 | + | |
| 564 | - | system("PAUSE");
|
| 564 | + | |
| 565 | case 'R': | |
| 566 | ropt = optarg; | |
| 567 | break; | |
| 568 | case 'u': | |
| 569 | uopt = optarg; | |
| 570 | break; | |
| 571 | case 's': | |
| 572 | skipline = atol(optarg); | |
| 573 | break; | |
| 574 | case 'd': | |
| 575 | separator = optarg[0]; | |
| 576 | break; | |
| 577 | case '?': | |
| 578 | print_help(argv[0]); | |
| 579 | return(0); | |
| 580 | break; | |
| 581 | default: | |
| 582 | printf ("?? getopt returned character code 0x%x ??\n", c);
| |
| 583 | } | |
| 584 | } | |
| 585 | if( argc < 3 || uopt == NULL || popt == NULL){
| |
| 586 | print_help(argv[0]); | |
| 587 | exit(EXIT_FAILURE); | |
| 588 | } | |
| 589 | ||
| 590 | maxtid = omp_get_max_threads(); | |
| 591 | printf("\nMaximum available threads detected: %2d\n",maxtid);
| |
| 592 | if( maxtid > 8 ) maxtid = 8; | |
| 593 | if( maxpar < maxtid ) maxtid = maxpar; | |
| 594 | omp_set_num_threads(maxtid); | |
| 595 | printf("Maximum number of threads for use: %2d\n",maxtid);
| |
| 596 | ||
| 597 | if ( access(popt,R_OK) ) { fprintf(stderr,"RO access password file %s - denied of file doesn\'t exist\n",popt); exit(EXIT_FAILURE); }
| |
| 598 | if ( access(uopt,R_OK) ) { fprintf(stderr,"RO access user file %s - denied of file doesn\'t exist\n",uopt); exit(EXIT_FAILURE); }
| |
| 599 | ||
| 600 | if( ! (fu = fopen(uopt,"rt")) ){ perror("Can\'t open user file\n"); exit(EXIT_FAILURE); }
| |
| 601 | cnt2 = 0; | |
| 602 | stt = time(NULL); | |
| 603 | while (fgets(inputline[0], 1000, fu) != NULL) {
| |
| 604 | i = strlen(inputline[0])-1; | |
| 605 | while( i && ( inputline[0][i] == '\n' || inputline[0][i] == '\r' ) ) inputline[0][i--] = '\0'; | |
| 606 | i = 0; if( (++cnt2 % 100) == 0 )printf("Users: %9ld\r",cnt2);
| |
| 607 | pu = cu; | |
| 608 | insert_u(inputline[0],&cu,&pu,separator); | |
| 609 | if( ! su ) su = cu; | |
| 610 | } | |
| 611 | fclose(fu); | |
| 612 | ent = time(NULL); | |
| 613 | printf("\nTotal %ld users (%ld seconds)\n",cnt2,ent-stt);
| |
| 614 | // cu = su; | |
| 615 | // while( cu ) {
| |
| 616 | // printf("User: %s Seed: %s Hash %s Hash2 %02x %02x\n",cu->uname,cu->seed,cu->hash,cu->sha256[0], cu->sha256[1]);
| |
| 617 | // cu = cu->next; | |
| 618 | // } | |
| 619 | ||
| 620 | ||
| 621 | if( ! (fp = fopen(popt,"rt")) ){ perror("Can\'t open password file\n"); exit(EXIT_FAILURE); }
| |
| 622 | ||
| 623 | if( ptype == 1 ){
| |
| 624 | cnt2 = 0; | |
| 625 | j = 0; | |
| 626 | stt = time(NULL); | |
| 627 | if( skipline > 0){
| |
| 628 | while( skipline >= ++cnt2 && fgets(inputline[0], 1000, fp) != NULL ); | |
| 629 | printf("First %ld paswords skipped\n",cnt2-1);
| |
| 630 | cnt2 = 0; | |
| 631 | } | |
| 632 | while (fgets(inputline[0], 1000, fp) != NULL) {
| |
| 633 | i = strlen(inputline[0])-1; | |
| 634 | while( i && ( inputline[0][i] == '\n' || inputline[0][i] == '\r' ) ) inputline[0][i--] = '\0'; | |
| 635 | if( (++cnt2 % 100) == 0 )printf("Passwords read: %9ld\r",cnt2);
| |
| 636 | pp[j] = cp[j]; | |
| 637 | insert_p(inputline[0],&cp[j],&pp[j]); | |
| 638 | if( ! sp[j] ) sp[j] = cp[j]; | |
| 639 | ++j; j %= 8; | |
| 640 | } | |
| 641 | fclose(fp); fp = NULL; | |
| 642 | ent = time(NULL); | |
| 643 | printf("\nTotal %ld passwords loaded (%ld seconds)\n",cnt2,ent-stt);
| |
| 644 | } | |
| 645 | ||
| 646 | // cp = sp; | |
| 647 | // while( cp ) {
| |
| 648 | // printf("Pass: %s Hash %s\n",cp->pass,cp->hash);
| |
| 649 | // cp = cp->next; | |
| 650 | // } | |
| 651 | ||
| 652 | if( ropt ){
| |
| 653 | if( overwrite ){
| |
| 654 | if( ! (fu = fopen(ropt,"w")) ) { perror("Can\'t open result file\n"); exit(EXIT_FAILURE); }
| |
| 655 | } else {
| |
| 656 | if( ! (fu = fopen(ropt,"a")) ) { perror("Can\'t open result file\n"); exit(EXIT_FAILURE); }
| |
| 657 | } | |
| 658 | } | |
| 659 | c = ropt ? 1 : 0; | |
| 660 | ||
| 661 | printf("Start processes\n");
| |
| 662 | cnt2 = 0; | |
| 663 | stt = time(NULL); | |
| 664 | if( ptype == 1 ){
| |
| 665 | #pragma omp parallel default(none) shared(sp,cp,pp,su,cu,pu,fu,c,cnt2p,maxtid) private (tid) | |
| 666 | {
| |
| 667 | tid = omp_get_thread_num(); | |
| 668 | #pragma omp sections | |
| 669 | {
| |
| 670 | #pragma omp section | |
| 671 | { process_memory_pass(tid,maxtid,sp[0],cp[0],pp[0],su,cu,pu,cnt2p,fu,c); }
| |
| 672 | #pragma omp section | |
| 673 | { process_memory_pass(tid,maxtid,sp[1],cp[1],pp[1],su,cu,pu,cnt2p,fu,c); }
| |
| 674 | #pragma omp section | |
| 675 | { process_memory_pass(tid,maxtid,sp[2],cp[2],pp[2],su,cu,pu,cnt2p,fu,c); }
| |
| 676 | #pragma omp section | |
| 677 | { process_memory_pass(tid,maxtid,sp[3],cp[3],pp[3],su,cu,pu,cnt2p,fu,c); }
| |
| 678 | #pragma omp section | |
| 679 | { process_memory_pass(tid,maxtid,sp[4],cp[4],pp[4],su,cu,pu,cnt2p,fu,c); }
| |
| 680 | #pragma omp section | |
| 681 | { process_memory_pass(tid,maxtid,sp[5],cp[5],pp[5],su,cu,pu,cnt2p,fu,c); }
| |
| 682 | #pragma omp section | |
| 683 | { process_memory_pass(tid,maxtid,sp[6],cp[6],pp[6],su,cu,pu,cnt2p,fu,c); }
| |
| 684 | #pragma omp section | |
| 685 | { process_memory_pass(tid,maxtid,sp[7],cp[7],pp[7],su,cu,pu,cnt2p,fu,c); }
| |
| 686 | } | |
| 687 | } | |
| 688 | } | |
| 689 | else if ( ptype == 2 ){
| |
| 690 | cnt2 = 0; | |
| 691 | if( skipline > 0){
| |
| 692 | while( skipline >= ++cnt2 && fgets(inputline[0], 1000, fp) != NULL ); | |
| 693 | printf("First %ld paswords skipped\n",cnt2-1);
| |
| 694 | cnt2 = 0; | |
| 695 | } | |
| 696 | while( feof(fp) == 0 ){
| |
| 697 | for( i = 0; i<8; i++ ) bst[i] = (int)fgets(inputline[i], 1000, fp); | |
| 698 | #pragma omp parallel default(none) shared(su,cu,pu,fu,c,cnt2p,maxtid,bst,inputline) private (tid) | |
| 699 | {
| |
| 700 | tid = omp_get_thread_num(); | |
| 701 | #pragma omp sections | |
| 702 | {
| |
| 703 | #pragma omp section | |
| 704 | { process_disk_pass(tid,maxtid,bst[0],inputline[0], su,cu,pu,cnt2p,fu,c); }
| |
| 705 | #pragma omp section | |
| 706 | { process_disk_pass(tid,maxtid,bst[1],inputline[1], su,cu,pu,cnt2p,fu,c); }
| |
| 707 | #pragma omp section | |
| 708 | { process_disk_pass(tid,maxtid,bst[2],inputline[2], su,cu,pu,cnt2p,fu,c); }
| |
| 709 | #pragma omp section | |
| 710 | { process_disk_pass(tid,maxtid,bst[3],inputline[3], su,cu,pu,cnt2p,fu,c); }
| |
| 711 | #pragma omp section | |
| 712 | { process_disk_pass(tid,maxtid,bst[4],inputline[4], su,cu,pu,cnt2p,fu,c); }
| |
| 713 | #pragma omp section | |
| 714 | { process_disk_pass(tid,maxtid,bst[5],inputline[5], su,cu,pu,cnt2p,fu,c); }
| |
| 715 | #pragma omp section | |
| 716 | { process_disk_pass(tid,maxtid,bst[6],inputline[6], su,cu,pu,cnt2p,fu,c); }
| |
| 717 | #pragma omp section | |
| 718 | { process_disk_pass(tid,maxtid,bst[7],inputline[7], su,cu,pu,cnt2p,fu,c); }
| |
| 719 | } | |
| 720 | } | |
| 721 | ||
| 722 | } | |
| 723 | fclose(fp); | |
| 724 | ||
| 725 | } | |
| 726 | ent = time(NULL); | |
| 727 | print_progress(maxtid,cnt2p); | |
| 728 | printf("\nTotal %ld passwords processed (%ld seconds)\n",cnt2p[0]+cnt2p[1]+cnt2p[2]+cnt2p[3]+cnt2p[4]+cnt2p[5]+cnt2p[6]+cnt2p[7]+cnt2,ent-stt);
| |
| 729 | ||
| 730 | cu = su; | |
| 731 | while( cu ){
| |
| 732 | pu = cu; | |
| 733 | cu = cu->next; | |
| 734 | free(pu->hash); | |
| 735 | free(pu->seed); | |
| 736 | free(pu->uname); | |
| 737 | free(pu); | |
| 738 | } | |
| 739 | ||
| 740 | printf("End process \n");
| |
| 741 | if( c )fclose(fu); | |
| 742 | // system("PAUSE");
| |
| 743 | return( 0 ); | |
| 744 | } |