xref: /titanic_41/usr/src/lib/pam_modules/authtok_check/fascist.c (revision 8c74a1f9477c04aa8539a84a49aa2bf629c7a14d)
1 /*
2  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 #pragma ident	"%Z%%M%	%I%	%E% SMI"
7 
8 /*
9  * This program is copyright Alec Muffett 1993. The author disclaims all
10  * responsibility or liability with respect to it's usage or its effect
11  * upon hardware or computer systems, and maintains copyright as set out
12  * in the "LICENCE" document which accompanies distributions of Crack v4.0
13  * and upwards.
14  */
15 
16 #include "packer.h"
17 
18 
19 static char *r_destructors[] = {
20 	":",			/* noop - must do this to test raw word. */
21 	"[",			/* trimming leading/trailing junk */
22 	"]",
23 	"[[",
24 	"]]",
25 	"[[[",
26 	"]]]",
27 
28 	"/?p@?p",		/* purging out punctuation/symbols/junk */
29 	"/?s@?s",
30 	"/?X@?X",
31 	/* attempt reverse engineering of password strings */
32 	"/$s$s",
33 	"/$s$s/0s0o",
34 	"/$s$s/0s0o/2s2a",
35 	"/$s$s/0s0o/2s2a/3s3e",
36 	"/$s$s/0s0o/2s2a/3s3e/5s5s",
37 	"/$s$s/0s0o/2s2a/3s3e/5s5s/1s1i",
38 	"/$s$s/0s0o/2s2a/3s3e/5s5s/1s1l",
39 	"/$s$s/0s0o/2s2a/3s3e/5s5s/1s1i/4s4a",
40 	"/$s$s/0s0o/2s2a/3s3e/5s5s/1s1i/4s4h",
41 	"/$s$s/0s0o/2s2a/3s3e/5s5s/1s1l/4s4a",
42 	"/$s$s/0s0o/2s2a/3s3e/5s5s/1s1l/4s4h",
43 	"/$s$s/0s0o/2s2a/3s3e/5s5s/4s4a",
44 	"/$s$s/0s0o/2s2a/3s3e/5s5s/4s4h",
45 	"/$s$s/0s0o/2s2a/3s3e/5s5s/4s4a",
46 	"/$s$s/0s0o/2s2a/3s3e/5s5s/4s4h",
47 	"/$s$s/0s0o/2s2a/3s3e/1s1i",
48 	"/$s$s/0s0o/2s2a/3s3e/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o/4s4h",
119 	"/$s$s/0s0o/4s4a",
120 	"/$s$s/0s0o/4s4h",
121 	"/$s$s/2s2a",
122 	"/$s$s/2s2a/3s3e",
123 	"/$s$s/2s2a/3s3e/5s5s",
124 	"/$s$s/2s2a/3s3e/5s5s/1s1i",
125 	"/$s$s/2s2a/3s3e/5s5s/1s1l",
126 	"/$s$s/2s2a/3s3e/5s5s/1s1i/4s4a",
127 	"/$s$s/2s2a/3s3e/5s5s/1s1i/4s4h",
128 	"/$s$s/2s2a/3s3e/5s5s/1s1l/4s4a",
129 	"/$s$s/2s2a/3s3e/5s5s/1s1l/4s4h",
130 	"/$s$s/2s2a/3s3e/5s5s/4s4a",
131 	"/$s$s/2s2a/3s3e/5s5s/4s4h",
132 	"/$s$s/2s2a/3s3e/5s5s/4s4a",
133 	"/$s$s/2s2a/3s3e/5s5s/4s4h",
134 	"/$s$s/2s2a/3s3e/1s1i",
135 	"/$s$s/2s2a/3s3e/1s1l",
136 	"/$s$s/2s2a/3s3e/1s1i/4s4a",
137 	"/$s$s/2s2a/3s3e/1s1i/4s4h",
138 	"/$s$s/2s2a/3s3e/1s1l/4s4a",
139 	"/$s$s/2s2a/3s3e/1s1l/4s4h",
140 	"/$s$s/2s2a/3s3e/4s4a",
141 	"/$s$s/2s2a/3s3e/4s4h",
142 	"/$s$s/2s2a/3s3e/4s4a",
143 	"/$s$s/2s2a/3s3e/4s4h",
144 	"/$s$s/2s2a/5s5s",
145 	"/$s$s/2s2a/5s5s/1s1i",
146 	"/$s$s/2s2a/5s5s/1s1l",
147 	"/$s$s/2s2a/5s5s/1s1i/4s4a",
148 	"/$s$s/2s2a/5s5s/1s1i/4s4h",
149 	"/$s$s/2s2a/5s5s/1s1l/4s4a",
150 	"/$s$s/2s2a/5s5s/1s1l/4s4h",
151 	"/$s$s/2s2a/5s5s/4s4a",
152 	"/$s$s/2s2a/5s5s/4s4h",
153 	"/$s$s/2s2a/5s5s/4s4a",
154 	"/$s$s/2s2a/5s5s/4s4h",
155 	"/$s$s/2s2a/1s1i",
156 	"/$s$s/2s2a/1s1l",
157 	"/$s$s/2s2a/1s1i/4s4a",
158 	"/$s$s/2s2a/1s1i/4s4h",
159 	"/$s$s/2s2a/1s1l/4s4a",
160 	"/$s$s/2s2a/1s1l/4s4h",
161 	"/$s$s/2s2a/4s4a",
162 	"/$s$s/2s2a/4s4h",
163 	"/$s$s/2s2a/4s4a",
164 	"/$s$s/2s2a/4s4h",
165 	"/$s$s/3s3e",
166 	"/$s$s/3s3e/5s5s",
167 	"/$s$s/3s3e/5s5s/1s1i",
168 	"/$s$s/3s3e/5s5s/1s1l",
169 	"/$s$s/3s3e/5s5s/1s1i/4s4a",
170 	"/$s$s/3s3e/5s5s/1s1i/4s4h",
171 	"/$s$s/3s3e/5s5s/1s1l/4s4a",
172 	"/$s$s/3s3e/5s5s/1s1l/4s4h",
173 	"/$s$s/3s3e/5s5s/4s4a",
174 	"/$s$s/3s3e/5s5s/4s4h",
175 	"/$s$s/3s3e/5s5s/4s4a",
176 	"/$s$s/3s3e/5s5s/4s4h",
177 	"/$s$s/3s3e/1s1i",
178 	"/$s$s/3s3e/1s1l",
179 	"/$s$s/3s3e/1s1i/4s4a",
180 	"/$s$s/3s3e/1s1i/4s4h",
181 	"/$s$s/3s3e/1s1l/4s4a",
182 	"/$s$s/3s3e/1s1l/4s4h",
183 	"/$s$s/3s3e/4s4a",
184 	"/$s$s/3s3e/4s4h",
185 	"/$s$s/3s3e/4s4a",
186 	"/$s$s/3s3e/4s4h",
187 	"/$s$s/5s5s",
188 	"/$s$s/5s5s/1s1i",
189 	"/$s$s/5s5s/1s1l",
190 	"/$s$s/5s5s/1s1i/4s4a",
191 	"/$s$s/5s5s/1s1i/4s4h",
192 	"/$s$s/5s5s/1s1l/4s4a",
193 	"/$s$s/5s5s/1s1l/4s4h",
194 	"/$s$s/5s5s/4s4a",
195 	"/$s$s/5s5s/4s4h",
196 	"/$s$s/5s5s/4s4a",
197 	"/$s$s/5s5s/4s4h",
198 	"/$s$s/1s1i",
199 	"/$s$s/1s1l",
200 	"/$s$s/1s1i/4s4a",
201 	"/$s$s/1s1i/4s4h",
202 	"/$s$s/1s1l/4s4a",
203 	"/$s$s/1s1l/4s4h",
204 	"/$s$s/4s4a",
205 	"/$s$s/4s4h",
206 	"/$s$s/4s4a",
207 	"/$s$s/4s4h",
208 	"/0s0o",
209 	"/0s0o/2s2a",
210 	"/0s0o/2s2a/3s3e",
211 	"/0s0o/2s2a/3s3e/5s5s",
212 	"/0s0o/2s2a/3s3e/5s5s/1s1i",
213 	"/0s0o/2s2a/3s3e/5s5s/1s1l",
214 	"/0s0o/2s2a/3s3e/5s5s/1s1i/4s4a",
215 	"/0s0o/2s2a/3s3e/5s5s/1s1i/4s4h",
216 	"/0s0o/2s2a/3s3e/5s5s/1s1l/4s4a",
217 	"/0s0o/2s2a/3s3e/5s5s/1s1l/4s4h",
218 	"/0s0o/2s2a/3s3e/5s5s/4s4a",
219 	"/0s0o/2s2a/3s3e/5s5s/4s4h",
220 	"/0s0o/2s2a/3s3e/5s5s/4s4a",
221 	"/0s0o/2s2a/3s3e/5s5s/4s4h",
222 	"/0s0o/2s2a/3s3e/1s1i",
223 	"/0s0o/2s2a/3s3e/1s1l",
224 	"/0s0o/2s2a/3s3e/1s1i/4s4a",
225 	"/0s0o/2s2a/3s3e/1s1i/4s4h",
226 	"/0s0o/2s2a/3s3e/1s1l/4s4a",
227 	"/0s0o/2s2a/3s3e/1s1l/4s4h",
228 	"/0s0o/2s2a/3s3e/4s4a",
229 	"/0s0o/2s2a/3s3e/4s4h",
230 	"/0s0o/2s2a/3s3e/4s4a",
231 	"/0s0o/2s2a/3s3e/4s4h",
232 	"/0s0o/2s2a/5s5s",
233 	"/0s0o/2s2a/5s5s/1s1i",
234 	"/0s0o/2s2a/5s5s/1s1l",
235 	"/0s0o/2s2a/5s5s/1s1i/4s4a",
236 	"/0s0o/2s2a/5s5s/1s1i/4s4h",
237 	"/0s0o/2s2a/5s5s/1s1l/4s4a",
238 	"/0s0o/2s2a/5s5s/1s1l/4s4h",
239 	"/0s0o/2s2a/5s5s/4s4a",
240 	"/0s0o/2s2a/5s5s/4s4h",
241 	"/0s0o/2s2a/5s5s/4s4a",
242 	"/0s0o/2s2a/5s5s/4s4h",
243 	"/0s0o/2s2a/1s1i",
244 	"/0s0o/2s2a/1s1l",
245 	"/0s0o/2s2a/1s1i/4s4a",
246 	"/0s0o/2s2a/1s1i/4s4h",
247 	"/0s0o/2s2a/1s1l/4s4a",
248 	"/0s0o/2s2a/1s1l/4s4h",
249 	"/0s0o/2s2a/4s4a",
250 	"/0s0o/2s2a/4s4h",
251 	"/0s0o/2s2a/4s4a",
252 	"/0s0o/2s2a/4s4h",
253 	"/0s0o/3s3e",
254 	"/0s0o/3s3e/5s5s",
255 	"/0s0o/3s3e/5s5s/1s1i",
256 	"/0s0o/3s3e/5s5s/1s1l",
257 	"/0s0o/3s3e/5s5s/1s1i/4s4a",
258 	"/0s0o/3s3e/5s5s/1s1i/4s4h",
259 	"/0s0o/3s3e/5s5s/1s1l/4s4a",
260 	"/0s0o/3s3e/5s5s/1s1l/4s4h",
261 	"/0s0o/3s3e/5s5s/4s4a",
262 	"/0s0o/3s3e/5s5s/4s4h",
263 	"/0s0o/3s3e/5s5s/4s4a",
264 	"/0s0o/3s3e/5s5s/4s4h",
265 	"/0s0o/3s3e/1s1i",
266 	"/0s0o/3s3e/1s1l",
267 	"/0s0o/3s3e/1s1i/4s4a",
268 	"/0s0o/3s3e/1s1i/4s4h",
269 	"/0s0o/3s3e/1s1l/4s4a",
270 	"/0s0o/3s3e/1s1l/4s4h",
271 	"/0s0o/3s3e/4s4a",
272 	"/0s0o/3s3e/4s4h",
273 	"/0s0o/3s3e/4s4a",
274 	"/0s0o/3s3e/4s4h",
275 	"/0s0o/5s5s",
276 	"/0s0o/5s5s/1s1i",
277 	"/0s0o/5s5s/1s1l",
278 	"/0s0o/5s5s/1s1i/4s4a",
279 	"/0s0o/5s5s/1s1i/4s4h",
280 	"/0s0o/5s5s/1s1l/4s4a",
281 	"/0s0o/5s5s/1s1l/4s4h",
282 	"/0s0o/5s5s/4s4a",
283 	"/0s0o/5s5s/4s4h",
284 	"/0s0o/5s5s/4s4a",
285 	"/0s0o/5s5s/4s4h",
286 	"/0s0o/1s1i",
287 	"/0s0o/1s1l",
288 	"/0s0o/1s1i/4s4a",
289 	"/0s0o/1s1i/4s4h",
290 	"/0s0o/1s1l/4s4a",
291 	"/0s0o/1s1l/4s4h",
292 	"/0s0o/4s4a",
293 	"/0s0o/4s4h",
294 	"/0s0o/4s4a",
295 	"/0s0o/4s4h",
296 	"/2s2a",
297 	"/2s2a/3s3e",
298 	"/2s2a/3s3e/5s5s",
299 	"/2s2a/3s3e/5s5s/1s1i",
300 	"/2s2a/3s3e/5s5s/1s1l",
301 	"/2s2a/3s3e/5s5s/1s1i/4s4a",
302 	"/2s2a/3s3e/5s5s/1s1i/4s4h",
303 	"/2s2a/3s3e/5s5s/1s1l/4s4a",
304 	"/2s2a/3s3e/5s5s/1s1l/4s4h",
305 	"/2s2a/3s3e/5s5s/4s4a",
306 	"/2s2a/3s3e/5s5s/4s4h",
307 	"/2s2a/3s3e/5s5s/4s4a",
308 	"/2s2a/3s3e/5s5s/4s4h",
309 	"/2s2a/3s3e/1s1i",
310 	"/2s2a/3s3e/1s1l",
311 	"/2s2a/3s3e/1s1i/4s4a",
312 	"/2s2a/3s3e/1s1i/4s4h",
313 	"/2s2a/3s3e/1s1l/4s4a",
314 	"/2s2a/3s3e/1s1l/4s4h",
315 	"/2s2a/3s3e/4s4a",
316 	"/2s2a/3s3e/4s4h",
317 	"/2s2a/3s3e/4s4a",
318 	"/2s2a/3s3e/4s4h",
319 	"/2s2a/5s5s",
320 	"/2s2a/5s5s/1s1i",
321 	"/2s2a/5s5s/1s1l",
322 	"/2s2a/5s5s/1s1i/4s4a",
323 	"/2s2a/5s5s/1s1i/4s4h",
324 	"/2s2a/5s5s/1s1l/4s4a",
325 	"/2s2a/5s5s/1s1l/4s4h",
326 	"/2s2a/5s5s/4s4a",
327 	"/2s2a/5s5s/4s4h",
328 	"/2s2a/5s5s/4s4a",
329 	"/2s2a/5s5s/4s4h",
330 	"/2s2a/1s1i",
331 	"/2s2a/1s1l",
332 	"/2s2a/1s1i/4s4a",
333 	"/2s2a/1s1i/4s4h",
334 	"/2s2a/1s1l/4s4a",
335 	"/2s2a/1s1l/4s4h",
336 	"/2s2a/4s4a",
337 	"/2s2a/4s4h",
338 	"/2s2a/4s4a",
339 	"/2s2a/4s4h",
340 	"/3s3e",
341 	"/3s3e/5s5s",
342 	"/3s3e/5s5s/1s1i",
343 	"/3s3e/5s5s/1s1l",
344 	"/3s3e/5s5s/1s1i/4s4a",
345 	"/3s3e/5s5s/1s1i/4s4h",
346 	"/3s3e/5s5s/1s1l/4s4a",
347 	"/3s3e/5s5s/1s1l/4s4h",
348 	"/3s3e/5s5s/4s4a",
349 	"/3s3e/5s5s/4s4h",
350 	"/3s3e/5s5s/4s4a",
351 	"/3s3e/5s5s/4s4h",
352 	"/3s3e/1s1i",
353 	"/3s3e/1s1l",
354 	"/3s3e/1s1i/4s4a",
355 	"/3s3e/1s1i/4s4h",
356 	"/3s3e/1s1l/4s4a",
357 	"/3s3e/1s1l/4s4h",
358 	"/3s3e/4s4a",
359 	"/3s3e/4s4h",
360 	"/3s3e/4s4a",
361 	"/3s3e/4s4h",
362 	"/5s5s",
363 	"/5s5s/1s1i",
364 	"/5s5s/1s1l",
365 	"/5s5s/1s1i/4s4a",
366 	"/5s5s/1s1i/4s4h",
367 	"/5s5s/1s1l/4s4a",
368 	"/5s5s/1s1l/4s4h",
369 	"/5s5s/4s4a",
370 	"/5s5s/4s4h",
371 	"/5s5s/4s4a",
372 	"/5s5s/4s4h",
373 	"/1s1i",
374 	"/1s1l",
375 	"/1s1i/4s4a",
376 	"/1s1i/4s4h",
377 	"/1s1l/4s4a",
378 	"/1s1l/4s4h",
379 	"/4s4a",
380 	"/4s4h",
381 	"/4s4a",
382 	"/4s4h",
383 	/* done */
384 	(char *)0
385 };
386 
387 
388 int
389 FascistLook(PWDICT *pwp, char *instring)
390 {
391 int i;
392 	char *password;
393 	int32 notfound;
394 	char rpassword[PATH_MAX];
395 
396 	notfound = PW_WORDS(pwp);
397 
398 	(void) strlcpy(rpassword, instring, TRUNCSTRINGSIZE);
399 	password = rpassword;
400 
401 	(void) strcpy(password, Lowercase(password));
402 	(void) Trim(password);
403 
404 	/*
405 	 * it should be safe to use Mangle with its reliance on PATH_SIZE
406 	 * since password cannot be longer than TRUNCSTRINGSIZE;
407 	 * nonetheless this is not an elegant solution
408 	 */
409 
410 	for (i = 0; r_destructors[i]; i++) {
411 	char *a;
412 
413 		if (!(a = Mangle(password, r_destructors[i]))) {
414 		    continue;
415 		}
416 
417 		if (FindPW(pwp, a) != notfound) {
418 		    return (DICTIONARY_WORD);
419 		}
420 	}
421 
422 	(void) strlcpy(password, Reverse(password), PATH_MAX);
423 
424 	for (i = 0; r_destructors[i]; i++) {
425 	char *a;
426 
427 		if (!(a = Mangle(password, r_destructors[i]))) {
428 			continue;
429 		}
430 		if (FindPW(pwp, a) != notfound) {
431 		    return (REVERSE_DICTIONARY_WORD);
432 		}
433 	}
434 
435 	return (0);
436 }
437 
438 int
439 DictCheck(char *password, char *path)
440 {
441 	PWDICT *pwp;
442 	int r;
443 
444 	if ((pwp = PWOpen(path, "rF")) == NULL)
445 		return (DATABASE_OPEN_FAIL);
446 
447 	r = FascistLook(pwp, password);
448 	(void) PWClose(pwp);
449 	return (r);
450 }
451