forked from vanhauser-thc/thc-hydra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pw-inspector.c
164 lines (155 loc) · 4.55 KB
/
pw-inspector.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
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define PROGRAM "PW-Inspector"
#define VERSION "v0.2"
#define EMAIL "vh@thc.org"
#define WEB "http://www.thc.org"
#define MAXLENGTH 256
char *prg;
void help() {
printf("%s %s (c) 2005 by van Hauser / THC %s [%s]\n\n", PROGRAM, VERSION, EMAIL, WEB);
printf("Syntax: %s [-i FILE] [-o FILE] [-m MINLEN] [-M MAXLEN] [-c MINSETS] -l -u -n -p -s\n\n", prg);
printf("Options:\n");
printf(" -i FILE file to read passwords from (default: stdin)\n");
printf(" -o FILE file to write valid passwords to (default: stdout)\n");
printf(" -m MINLEN minimum length of a valid password\n");
printf(" -M MAXLEN maximum length of a valid password\n");
printf(" -c MINSETS the minimum number of sets required (default: all given)\n");
printf("Sets:\n");
printf(" -l lowcase characters (a,b,c,d, etc.)\n");
printf(" -u upcase characters (A,B,C,D, etc.)\n");
printf(" -n numbers (1,2,3,4, etc.)\n");
printf(" -p printable characters (which are not -l/-n/-p, e.g. $,!,/,(,*, etc.)\n");
printf(" -s special characters - all others not withint the sets above\n");
printf("\n%s reads passwords in and prints those which meet the requirements.\n", PROGRAM);
printf("The return code is the number of valid passwords found, 0 if none was found.\n");
printf("Use for security: check passwords, if 0 is returned, reject password choice.\n");
printf("Use for hacking: trim your dictionary file to the pw requirements of the target.\n");
printf("Usage only allowed for legal purposes.\n");
exit(-1);
}
int main(int argc, char *argv[]) {
int i, j, k;
int sets = 0, countsets = 0, minlen = 0, maxlen = MAXLENGTH, count = 0;
int set_low = 0, set_up = 0, set_no = 0, set_print = 0, set_other = 0;
FILE *in = stdin, *out = stdout;
char buf[MAXLENGTH + 1];
prg = argv[0];
if (argc < 2)
help();
while ((i = getopt(argc, argv, "i:o:m:M:c:lunps")) >= 0) {
switch (i) {
case 'i':
if ((in = fopen(optarg, "r")) == NULL) {
fprintf(stderr, "Error: unable to open input file %s\n", optarg);
exit(-1);
}
break;
case 'o':
if ((out = fopen(optarg, "w")) == NULL) {
fprintf(stderr, "Error: unable to open output file %s\n", optarg);
exit(-1);
}
break;
case 'm':
minlen = atoi(optarg);
break;
case 'M':
maxlen = atoi(optarg);
break;
case 'c':
countsets = atoi(optarg);
break;
case 'l':
if (set_low == 0) {
set_low = 1;
sets++;
}
break;
case 'u':
if (set_up == 0) {
set_up = 1;
sets++;
}
break;
case 'n':
if (set_no == 0) {
set_no = 1;
sets++;
}
break;
case 'p':
if (set_print == 0) {
set_print = 1;
sets++;
}
break;
case 's':
if (set_other == 0) {
set_other = 1;
sets++;
}
break;
default:
help();
}
}
if (minlen > maxlen) {
fprintf(stderr, "Error: -m MINLEN is greater than -M MAXLEN\n");
exit(-1);
}
if (countsets > sets) {
fprintf(stderr, "Error: -c MINSETS is larger than the sets defined\n");
exit(-1);
}
if (countsets == 0)
countsets = sets;
while (fgets(buf, sizeof(buf), in) != NULL) {
i = -1;
if (buf[0] == 0)
continue;
if (buf[strlen(buf) - 1] == '\n')
buf[strlen(buf) - 1] = 0;
if (strlen(buf) >= minlen && strlen(buf) <= maxlen) {
i = 0;
if (countsets > 0) {
if (set_low)
if (strpbrk(buf, "abcdefghijklmnopqrstuvwxyz") != NULL)
i++;
if (set_up)
if (strpbrk(buf, "ABCDEFGHIJKLMNOPQRSTUVWXYZ") != NULL)
i++;
if (set_no)
if (strpbrk(buf, "0123456789") != NULL)
i++;
if (set_print) {
j = 0;
for (k = 0; k < strlen(buf); k++)
if (isprint((int) buf[k]) != 0 && isalnum((int) buf[k]) == 0)
j = 1;
if (j)
i++;
}
if (set_other) {
j = 0;
for (k = 0; k < strlen(buf); k++)
if (isprint((int) buf[k]) == 0 && isalnum((int) buf[k]) == 0)
j = 1;
if (j)
i++;
}
}
if (i >= countsets) {
fprintf(out, "%s\n", buf);
count++;
}
}
/* fprintf(stderr, "[DEBUG] i: %d minlen: %d maxlen: %d len: %d\n", i, minlen, maxlen, strlen(buf)); */
}
fclose(in);
fclose(out);
return count;
}