-
Notifications
You must be signed in to change notification settings - Fork 2k
/
dynamic_utils.c
174 lines (161 loc) · 3.94 KB
/
dynamic_utils.c
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
* This software was written by Jim Fougeron jfoug AT cox dot net
* in 2009-2012. No copyright is claimed, and the software is hereby
* placed in the public domain. In case this attempt to disclaim
* copyright and place the software in the public domain is deemed
* null and void, then the software is Copyright (c) 2009 Jim Fougeron
* and it is hereby released to the general public under the following
* terms:
*
* This software may be modified, redistributed, and used for any
* purpose, in source and binary forms, with or without modification.
*
* Generic MD5 hashes cracker
*
* Preloaded types dynamic_0 to dynamic_999 are 'reserved' types.
* They are loaded from this file. If someone tryes to build a 'custom'
* type in their john.ini file using one of those, john will abort
* the run.
*
* Renamed and changed from dynamic* to dynamic*. We handle MD5 and SHA1
* at the present time. More crypt types 'may' be added later.
* Added SHA2 (SHA224, SHA256, SHA384, SHA512), GOST, Whirlpool crypt types.
* Whirlpool use oSSSL if OPENSSL_VERSION_NUMBER >= 0x10000000, otherwise use sph_* code.
*/
#include <string.h>
#if AC_BUILT
#include "autoconfig.h"
#endif
#include "arch.h"
#if defined(SIMD_COEF_32) && !ARCH_LITTLE_ENDIAN
#undef SIMD_COEF_32
#undef SIMD_COEF_64
#undef SIMD_PARA_MD5
#undef SIMD_PARA_MD4
#undef SIMD_PARA_SHA1
#undef SIMD_PARA_SHA256
#undef SIMD_PARA_SHA512
#define BITS ARCH_BITS_STR
#endif
#if !FAST_FORMATS_OMP
#ifdef _OPENMP
#define FORCE_THREAD_MD5_body
#endif
#undef _OPENMP
#endif
#include "misc.h"
#include "common.h"
#include "formats.h"
#include "config.h"
#include "md5.h"
#include "dynamic.h"
#ifndef UNICODE_NO_OPTIONS
#include "options.h"
#endif
#ifndef DYNAMIC_DISABLED
void dynamic_DISPLAY_ALL_FORMATS()
{
int i;
for (i = 0; i < 1000; ++i)
{
char *sz = dynamic_PRELOAD_SIGNATURE(i);
char Type[14], *cp;
if (!sz)
break;
strnzcpy(Type, sz, sizeof(Type));
cp = strchr(Type, ':');
if (cp) *cp = 0;
printf("Format = %s%s type = %s\n", Type, strlen(Type)<10?" ":"", sz);
}
// The config has not been loaded, so we have to load it now, if we want to 'check'
// and show any user set md5-generic functions.
#if JOHN_SYSTEMWIDE
cfg_init(CFG_PRIVATE_FULL_NAME, 1);
#endif
cfg_init(CFG_FULL_NAME, 1);
for (i = 1000; i < 10000; ++i)
{
char *sz = dynamic_LOAD_PARSER_SIGNATURE(i);
if (sz && dynamic_IS_VALID(i, 0) == 1)
printf("UserFormat = dynamic_%d type = %s\n", i, sz);
}
}
// Only called at load time, so does not have to be overly optimal
static int ishexdigit(char c) {
if (c >= '0' && c <= '9')
return 1;
if (c >= 'a' && c <= 'f')
return 1;
if (c >= 'A' && c <= 'F')
return 1;
return 0;
}
// Was only called at load time, so did not have to be overly optimal and could
// leak memory.
// Now is also called as fallback by the RDP dynamic compiler format, so should
// avoid leaking memory, but in non-trivial cases still does.
char *dynamic_Demangle(char *Line, int *Len)
{
char *tmp, *cp, *cp2, digits[3];
if (!Line) {
if (Len)
*Len = 0;
return "";
}
if (!strchr(Line, '\\')) {
if (Len)
*Len = strlen(Line);
return Line;
}
tmp = str_alloc_copy(Line);
cp = tmp;
cp2 = Line;
while (*cp2)
{
if (*cp2 != '\\')
*cp++ = *cp2++;
else
{
++cp2;
if (*cp2 == '\\')
*cp++ = *cp2++;
else
{
unsigned val;
if (*cp2 != 'x') {
*cp++ = '\\';
continue;
}
++cp2;
if (!cp2[0]) {
*cp++ = '\\';
*cp++ = 'x';
continue;
}
digits[0] = *cp2++;
if (!cp2[0] || !ishexdigit(digits[0])) {
*cp++ = '\\';
*cp++ = 'x';
*cp++ = digits[0];
continue;
}
digits[1] = *cp2++;
if (!ishexdigit(digits[1])) {
*cp++ = '\\';
*cp++ = 'x';
*cp++ = digits[0];
*cp++ = digits[1];
continue;
}
digits[2] = 0;
val = (unsigned)strtol(digits, NULL, 16);
sprintf(cp, "%c", val);
++cp;
}
}
}
*cp = 0;
if (Len) *Len = cp-tmp;
return tmp;
}
#endif /* DYNAMIC_DISABLED */