Debian Codegraph @

src/core/arg.c

raw symbols SCIP
1 /*
2 *
3 * Ophcrack is a Lanmanager/NTLM hash cracker based on the faster time-memory
4 * trade-off using rainbow tables.
5 *
6 * Created with the help of: Maxime Mueller, Luca Wullschleger, Claude
7 * Hochreutiner, Andreas Huber and Etienne Dysli.
8 *
9 * Copyright (c) 2008 Philippe Oechslin, Cedric Tissieres, Bertrand Mesot
10 *
11 * Ophcrack is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * Ophcrack is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with Ophcrack; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 * This program is released under the GPL with the additional exemption
26 * that compiling, linking, and/or using OpenSSL is allowed.
27 *
28 *
29 *
30 *
31 */
32 #include <config.h>
33 #include <stdlib.h>
34 #include <assert.h>
35 #include <regex.h>
36 #include <string.h>
37
38 #include "arg.h"
39 #include "misc.h"
40 /*-------------------------------------------------------------------------*/
41 arg_t *arg_alloc(void) {
42 arg_t *arg = (arg_t*)malloc(sizeof(arg_t));;
43
44 arg_default(arg);
45
46 arg->verbose = 0;
47 arg->showempty = 1;
48 arg->debug = 0;
49 arg->quiet = 0;
50 arg->run = 0;
51 arg->exportcsv = 0;
52 arg->preload = 3;
53
54
55 #ifdef HAVE_GUI
56 arg->use_gui = 1;
57 #else
58 arg->use_gui = 0;
59 #endif
60
61 arg->cfname = 0;
62 arg->hfname = 0;
63 arg->ofname = 0;
64 arg->xfname = 0;
65 arg->sfname = 0;
66 arg->lfname = 0;
67
68 arg->tblstr = 0;
69 arg->samdir = 0;
70 arg->stats = 0;
71 arg->ssave = 0;
72
73 arg->lfile = stdout;
74
75 arg->table_path = list_alloc();
76 arg->table_str_conf = list_alloc();
77 arg->table_str_cmd = list_alloc();
78
79 return arg;
80 }
81 /*-------------------------------------------------------------------------*/
82 void arg_free(arg_t *arg) {
83 list_free(arg->table_path);
84 list_free(arg->table_str_conf);
85 list_free(arg->table_str_cmd);
86 free(arg);
87 }
88 /*-------------------------------------------------------------------------*/
89 void arg_default(arg_t *arg) {
90 arg->nthreads = 8;
91 arg->nhredux = 50000;
92 arg->mdqueue = 500;
93 arg->bforce = 1;
94 arg->bforce_len = 4;
95 arg->hideuname = 0;
96 arg->auditmode = 0;
97 }
98 /*-------------------------------------------------------------------------*/
99 int arg_read_conf(arg_t *arg) {
100 assert(arg->cfname != 0);
101
102 FILE *cfile = fopen(arg->cfname, "r");
103 if (cfile == 0) return -1;
104
105 static const char *pattern[11] = {
106 "^[ \t]*#",
107 "^[ \t]*$",
108 "^[ \t]*table[ \t]+([^\t]+)[ \t]*$",
109 "^[ \t]*nthreads[ \t]+([^ \t]+)[ \t]*$",
110 "^[ \t]*nhredux[ \t]+([^ \t]+)[ \t]*$",
111 "^[ \t]*maxdqueue[ \t]+([^ \t]+)[ \t]*$",
112 "^[ \t]*bforce[ \t]+([^ \t]+)[ \t]*$",
113 "^[ \t]*session_file[ \t]+([^ \t]+)[ \t]*$",
114 "^[ \t]*session_save[ \t]+([^ \t]+)[ \t]*$",
115 "^[ \t]*hideuname[ \t]+([^ \t]+)[ \t]*$",
116 "^[ \t]*auditmode[ \t]+([^ \t]+)[ \t]*$"};
117
118 regex_t regex[11];
119 regmatch_t match[2];
120
121 /* Compile the regular expressions. */
122
123 int n = sizeof(regex) / sizeof(regex_t);
124 int i;
125
126 for (i=0; i<n; ++i)
127 regcomp(regex+i, pattern[i], REG_EXTENDED);
128
129 /* Parse each line of the config file. */
130
131 char buff[STR_BUFF_SIZE];
132 char tmp[STR_BUFF_SIZE];
133 int count = 0;
134
135 while (fgets(buff, sizeof(buff), cfile) != 0 && ++count) {
136 /* Remove the newline. */
137
138 int len = strlen(buff);
139 if (buff[len-1] == '\n') buff[len-1] = '\0';
140
141 /* Test all the regexs to see if one match. */
142
143 for (i=0; i<n; ++i)
144 if (regexec(regex+i, buff, 2, match, 0) == 0) break;
145
146 /* Nothing matched. We have found an invalid parameter. */
147
148 if (i == n) {
149 printf("Invalid parameter at line %d of %s\n", count, arg->cfname);
150 continue;
151 }
152
153 /* Skip comments and empty lines. */
154
155 if (i < 2) continue;
156
157 /* Hande the parameters. */
158
159 int so = match[1].rm_so;
160 int eo = match[1].rm_eo;
161
162 len = eo-so+1;
163 snprintf(tmp, len+1, "%s", buff+so);
164
165 /* table */
166
167 if (i == 2)
168 list_add_tail(arg->table_str_conf, strdup(tmp));
169
170 /* nthreads */
171
172 else if (i == 3)
173 arg->nthreads = atoi(tmp);
174
175 /* nhredux */
176
177 else if (i == 4)
178 arg->nhredux = atoi(tmp);
179
180 /* maxdqueue */
181
182 else if (i == 5)
183 arg->mdqueue = atoi(tmp);
184
185 /* bforce */
186
187 else if (i == 6)
188 arg->bforce = atoi(tmp);
189
190 /* session file */
191
192 else if (i == 7)
193 arg->sfname = strdup(tmp);
194
195 /* session save */
196
197 else if (i == 8)
198 arg->ssave = atoi(tmp);
199
200 /* hide usernames */
201 else if (i == 9)
202 arg->hideuname = atoi(tmp);
203
204 /* audit mode */
205 else if (i == 10)
206 arg->auditmode = atoi(tmp);
207
208 }
209
210 for (i=0; i<n; ++i) regfree(regex+i);
211 fclose(cfile);
212
213 return 0;
214 }