| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
#include <stdio.h> |
| 33 |
#include <string.h> |
| 34 |
#include <stdlib.h> |
| 35 |
#include <unistd.h> |
| 36 |
#include <openssl/md4.h> |
| 37 |
|
| 38 |
#ifndef WIN32 |
| 39 |
#include <netinet/in.h> |
| 40 |
#else |
| 41 |
#include <winsock.h> |
| 42 |
#endif |
| 43 |
|
| 44 |
#include "original.h" |
| 45 |
#include "misc.h" |
| 46 |
#include "hash.h" |
| 47 |
|
| 48 |
int resolve_nt_hash(char p1[], char p2[], char h[], unsigned char pw[], |
| 49 |
int insist) { |
| 50 |
|
| 51 |
unsigned int i,j, combinations; |
| 52 |
unsigned int l, max = 0; |
| 53 |
unsigned char md4[17],*p, orig[15]={0}; |
| 54 |
|
| 55 |
static unsigned char is_multi[256]={ |
| 56 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 57 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 58 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 59 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 60 |
1, 8, 2, 2, 2, 8, 2, 2, 2, 8, 2, 2, 2, 2, 2, 8, |
| 61 |
2, 2, 2, 2, 2, 8, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, |
| 62 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 63 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 64 |
|
| 65 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 66 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 67 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 68 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 69 |
1, 1, 1, 1, 2, 1, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, |
| 70 |
1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, |
| 71 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, |
| 72 |
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}; |
| 73 |
|
| 74 |
static unsigned char multi_char[256][12]= { |
| 75 |
{0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, |
| 76 |
{0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, |
| 77 |
{0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, |
| 78 |
{0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, |
| 79 |
{0}, {'A','a',0xe0,0xe2,0xc0,0xc2,0xe3,0xc3}, "Bb", "Cc", "Dd", |
| 80 |
{'E','e',0xc8,0xe8,0xca,0xea,0xeb,0xcb}, "Ff", "Gg", "Hh", {'I','i',0xee,0xef,0xce,0xcf,0xed,0xcd}, |
| 81 |
"Jj", "Kk", "Ll", "Mm", "Nn", {'O','o',0xf4,0xd4,0xf3,0xf5,0xd3,0xd5}, |
| 82 |
"Pp", "Qq", "Rr", "Ss", "Tt", {'U','u',0xf9,0xfb,0xd9,0xdb,0xfa,0xda}, "Vv", |
| 83 |
"Ww", "Xx", "Yy", "Zz", {0}, {0}, {0}, {0}, {0}, |
| 84 |
{0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, |
| 85 |
{0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, |
| 86 |
|
| 87 |
{0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, |
| 88 |
{0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, |
| 89 |
{0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, |
| 90 |
{0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, |
| 91 |
{0}, {0}, {0}, {0}, {0xc4,0xe4}, {0}, {0}, {0xe7,0xc7}, {0}, {0xc9,0xe9}, {0}, {0}, {0}, {0}, {0}, {0}, |
| 92 |
{0}, {0xd1,0xf1}, {0}, {0}, {0}, {0}, {0xd6,0xf6}, {0}, {0}, {0}, {0}, {0}, {0xdc,0xfc}, {0}, {0}, {0xdf}, |
| 93 |
{0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, |
| 94 |
{0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}} ; |
| 95 |
|
| 96 |
static int max_multi=8; |
| 97 |
|
| 98 |
memset(pw, 0, 16); |
| 99 |
strcpy((char*)pw,p1); |
| 100 |
strcpy((char*)(pw+7),p2); |
| 101 |
|
| 102 |
l=strlen((char*)pw); |
| 103 |
|
| 104 |
p = (unsigned char *)pw; |
| 105 |
for (i=0; i<l; i++) |
| 106 |
if (p[i]>=128) |
| 107 |
switch(p[i]){ |
| 108 |
case 0x8e: p[i]=0xc4;break; |
| 109 |
case 0x99: p[i]=0xd6;break; |
| 110 |
case 0x9a: p[i]=0xdc;break; |
| 111 |
case 0xe1: p[i]=0xdf;break; |
| 112 |
case 0xa5: p[i]=0xd1;break; |
| 113 |
case 0x90: p[i]=0xc9;break; |
| 114 |
case 0x80: p[i]=0xc7;break; |
| 115 |
} |
| 116 |
|
| 117 |
strcpy((char*)orig, (char*)pw); |
| 118 |
combinations=1; |
| 119 |
|
| 120 |
for (i=0; i<l; i++) |
| 121 |
combinations *=is_multi[pw[i]]; |
| 122 |
|
| 123 |
if (!insist) { |
| 124 |
max = max_multi; |
| 125 |
while (combinations > RESOLVE_MAX_COMBINATIONS) { |
| 126 |
max--; |
| 127 |
combinations = 1; |
| 128 |
for (i=0; i<l; i++) |
| 129 |
combinations *= MY_MIN(is_multi[pw[i]],max); |
| 130 |
} |
| 131 |
} |
| 132 |
|
| 133 |
for (i=0; i<combinations; i++) { |
| 134 |
int c,m; |
| 135 |
c=i; |
| 136 |
|
| 137 |
for (j=0; j<l; j++) { |
| 138 |
m = MY_MIN(is_multi[orig[j]],max); |
| 139 |
pw[j]=((m>1) ? multi_char[orig[j]][c%m]:orig[j]); |
| 140 |
c/=m; |
| 141 |
} |
| 142 |
md4[16]=0; |
| 143 |
make_nthash((char*)pw, (char*)md4); |
| 144 |
|
| 145 |
if (!memcmp(md4,h,16)) |
| 146 |
return 1; |
| 147 |
} |
| 148 |
|
| 149 |
memset(pw, 0, 16); |
| 150 |
return 0; |
| 151 |
} |
| 152 |
|
| 153 |
void make_nthash(char *pw, char *out) { |
| 154 |
uchar_t *pwd = (uchar_t*)pw; |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
uint16_t unipwd[128] = {0}; |
| 159 |
int len = strlen(pw); |
| 160 |
int i; |
| 161 |
|
| 162 |
for (i=0; i<len; ++i) |
| 163 |
unipwd[i] = htons(pwd[i] << 8); |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
MD4_CTX ctx; |
| 168 |
|
| 169 |
MD4_Init(&ctx); |
| 170 |
MD4_Update(&ctx, unipwd, len * sizeof(uint16_t)); |
| 171 |
MD4_Final((uchar_t*)out, &ctx); |
| 172 |
} |