"Fossies" - the Fresh Open Source Software Archive 
Member "ettercap-0.8.3.1/src/ec_parser.c" (1 Aug 2020, 17116 Bytes) of package /linux/privat/ettercap-0.8.3.1.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "ec_parser.c" see the
Fossies "Dox" file reference documentation and the latest
Fossies "Diffs" side-by-side code changes report:
0.8.3_vs_0.8.3.1.
1 /*
2 ettercap -- parsing utilities
3
4 Copyright (C) ALoR & NaGA
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
20 */
21
22
23 #include <ec.h>
24 #include <ec_parser.h>
25 #include <ec_interfaces.h>
26 #include <ec_sniff.h>
27 #include <ec_send.h>
28 #include <ec_log.h>
29 #include <ec_format.h>
30 #include <ec_mitm.h>
31 #include <ec_filter.h>
32 #include <ec_plugins.h>
33 #include <ec_conf.h>
34 #include <ec_strings.h>
35 #include <ec_encryption.h>
36 #ifdef HAVE_EC_LUA
37 #include <ec_lua.h>
38 #endif
39
40 #include <ctype.h>
41
42 #ifdef HAVE_GETOPT_H
43 #include <getopt.h>
44 #else
45 #include <missing/getopt.h>
46 #endif
47
48 /* protos... */
49
50 static void ec_usage(void);
51
52 /*****************************************/
53
54 void ec_usage(void)
55 {
56
57 fprintf(stdout, "\nUsage: %s [OPTIONS] [TARGET1] [TARGET2]\n", EC_GBL_PROGRAM);
58
59 #ifdef WITH_IPV6
60 fprintf(stdout, "\nTARGET is in the format MAC/IP/IPv6/PORTs (see the man for further detail)\n");
61 #else
62 fprintf(stdout, "\nTARGET is in the format MAC/IP/PORTs (see the man for further detail)\n");
63 #endif
64
65
66 fprintf(stdout, "\nSniffing and Attack options:\n");
67 fprintf(stdout, " -M, --mitm <METHOD:ARGS> perform a mitm attack\n");
68 fprintf(stdout, " -o, --only-mitm don't sniff, only perform the mitm attack\n");
69 fprintf(stdout, " -b, --broadcast sniff packets destined to broadcast\n");
70 fprintf(stdout, " -B, --bridge <IFACE> use bridged sniff (needs 2 ifaces)\n");
71 fprintf(stdout, " -p, --nopromisc do not put the iface in promisc mode\n");
72 fprintf(stdout, " -S, --nosslmitm do not forge SSL certificates\n");
73 fprintf(stdout, " -u, --unoffensive do not forward packets\n");
74 fprintf(stdout, " -r, --read <file> read data from pcapfile <file>\n");
75 fprintf(stdout, " -f, --pcapfilter <string> set the pcap filter <string>\n");
76 fprintf(stdout, " -R, --reversed use reversed TARGET matching\n");
77 fprintf(stdout, " -t, --proto <proto> sniff only this proto (default is all)\n");
78 fprintf(stdout, " --certificate <file> certificate file to use for SSL MiTM\n");
79 fprintf(stdout, " --private-key <file> private key file to use for SSL MiTM\n");
80
81 fprintf(stdout, "\nUser Interface Type:\n");
82 fprintf(stdout, " -T, --text use text only GUI\n");
83 fprintf(stdout, " -q, --quiet do not display packet contents\n");
84 fprintf(stdout, " -s, --script <CMD> issue these commands to the GUI\n");
85 fprintf(stdout, " -C, --curses use curses GUI\n");
86 fprintf(stdout, " -D, --daemon daemonize ettercap (no GUI)\n");
87 fprintf(stdout, " -G, --gtk use GTK+ GUI\n");
88
89
90 fprintf(stdout, "\nLogging options:\n");
91 fprintf(stdout, " -w, --write <file> write sniffed data to pcapfile <file>\n");
92 fprintf(stdout, " -L, --log <logfile> log all the traffic to this <logfile>\n");
93 fprintf(stdout, " -l, --log-info <logfile> log only passive infos to this <logfile>\n");
94 fprintf(stdout, " -m, --log-msg <logfile> log all the messages to this <logfile>\n");
95 fprintf(stdout, " -c, --compress use gzip compression on log files\n");
96
97 fprintf(stdout, "\nVisualization options:\n");
98 fprintf(stdout, " -d, --dns resolves ip addresses into hostnames\n");
99 fprintf(stdout, " -V, --visual <format> set the visualization format\n");
100 fprintf(stdout, " -e, --regex <regex> visualize only packets matching this regex\n");
101 fprintf(stdout, " -E, --ext-headers print extended header for every pck\n");
102 fprintf(stdout, " -Q, --superquiet do not display user and password\n");
103
104 #ifdef HAVE_EC_LUA
105 fprintf(stdout, "\nLUA options:\n");
106 fprintf(stdout, " --lua-script <script1>,[<script2>,...] comma-separted list of LUA scripts\n");
107 fprintf(stdout, " --lua-args n1=v1,[n2=v2,...] comma-separated arguments to LUA script(s)\n");
108 #endif
109
110 fprintf(stdout, "\nGeneral options:\n");
111 fprintf(stdout, " -i, --iface <iface> use this network interface\n");
112 fprintf(stdout, " -I, --liface show all the network interfaces\n");
113 fprintf(stdout, " -Y, --secondary <ifaces> list of secondary network interfaces\n");
114 fprintf(stdout, " -n, --netmask <netmask> force this <netmask> on iface\n");
115 fprintf(stdout, " -A, --address <address> force this local <address> on iface\n");
116 fprintf(stdout, " -P, --plugin <plugin> launch this <plugin> - multiple occurance allowed\n");
117 fprintf(stdout, " --plugin-list <plugin1>,[<plugin2>,...] comma-separated list of plugins\n");
118 fprintf(stdout, " -F, --filter <file> load the filter <file> (content filter)\n");
119 fprintf(stdout, " -z, --silent do not perform the initial ARP scan\n");
120 #ifdef WITH_IPV6
121 fprintf(stdout, " -6, --ip6scan send ICMPv6 probes to discover IPv6 nodes on the link\n");
122 #endif
123 fprintf(stdout, " -j, --load-hosts <file> load the hosts list from <file>\n");
124 fprintf(stdout, " -k, --save-hosts <file> save the hosts list to <file>\n");
125 fprintf(stdout, " -W, --wifi-key <wkey> use this key to decrypt wifi packets (wep or wpa)\n");
126 fprintf(stdout, " -a, --config <config> use the alternative config file <config>\n");
127
128 fprintf(stdout, "\nStandard options:\n");
129 fprintf(stdout, " -v, --version prints the version and exit\n");
130 fprintf(stdout, " -h, --help this help screen\n");
131
132 fprintf(stdout, "\n\n");
133
134 //clean_exit(0);
135 exit(0);
136 }
137
138
139 void parse_options(int argc, char **argv)
140 {
141 int c;
142
143 static struct option long_options[] = {
144 { "help", no_argument, NULL, 'h' },
145 { "version", no_argument, NULL, 'v' },
146
147 { "iface", required_argument, NULL, 'i' },
148 { "lifaces", no_argument, NULL, 'I' },
149 { "netmask", required_argument, NULL, 'n' },
150 { "address", required_argument, NULL, 'A' },
151 { "write", required_argument, NULL, 'w' },
152 { "read", required_argument, NULL, 'r' },
153 { "pcapfilter", required_argument, NULL, 'f' },
154
155 { "reversed", no_argument, NULL, 'R' },
156 { "proto", required_argument, NULL, 't' },
157
158 { "plugin", required_argument, NULL, 'P' },
159 { "plugin-list", required_argument, NULL, 0 },
160
161 { "filter", required_argument, NULL, 'F' },
162 #ifdef HAVE_EC_LUA
163 { "lua-script", required_argument, NULL, 0 },
164 { "lua-args", required_argument, NULL, 0 },
165 #endif
166
167 { "superquiet", no_argument, NULL, 'Q' },
168 { "quiet", no_argument, NULL, 'q' },
169 { "script", required_argument, NULL, 's' },
170 { "silent", no_argument, NULL, 'z' },
171 #ifdef WITH_IPV6
172 { "ip6scan", no_argument, NULL, '6' },
173 #endif
174 { "unoffensive", no_argument, NULL, 'u' },
175 { "nosslmitm", no_argument, NULL, 'S' },
176 { "load-hosts", required_argument, NULL, 'j' },
177 { "save-hosts", required_argument, NULL, 'k' },
178 { "wifi-key", required_argument, NULL, 'W' },
179 { "config", required_argument, NULL, 'a' },
180
181 { "dns", no_argument, NULL, 'd' },
182 { "regex", required_argument, NULL, 'e' },
183 { "visual", required_argument, NULL, 'V' },
184 { "ext-headers", no_argument, NULL, 'E' },
185
186 { "log", required_argument, NULL, 'L' },
187 { "log-info", required_argument, NULL, 'l' },
188 { "log-msg", required_argument, NULL, 'm' },
189 { "compress", no_argument, NULL, 'c' },
190
191 { "text", no_argument, NULL, 'T' },
192 { "curses", no_argument, NULL, 'C' },
193 { "daemon", no_argument, NULL, 'D' },
194 { "gtk", no_argument, NULL, 'G' },
195
196
197 { "mitm", required_argument, NULL, 'M' },
198 { "only-mitm", no_argument, NULL, 'o' },
199 { "bridge", required_argument, NULL, 'B' },
200 { "broadcast", required_argument, NULL, 'b' },
201 { "nopromisc", no_argument, NULL, 'p' },
202 { "gateway", required_argument, NULL, 'Y' },
203 { "certificate", required_argument, NULL, 0 },
204 { "private-key", required_argument, NULL, 0 },
205
206
207 { 0 , 0 , 0 , 0}
208 };
209
210 for (c = 0; c < argc; c++)
211 DEBUG_MSG("parse_options -- [%d] [%s]", c, argv[c]);
212
213
214 /* OPTIONS INITIALIZATION */
215
216 EC_GBL_PCAP->promisc = 1;
217 EC_GBL_FORMAT = &ascii_format;
218 EC_GBL_OPTIONS->ssl_mitm = 1;
219 EC_GBL_OPTIONS->broadcast = 0;
220 EC_GBL_OPTIONS->ssl_cert = NULL;
221 EC_GBL_OPTIONS->ssl_pkey = NULL;
222
223 /* OPTIONS INITIALIZED */
224
225 optind = 0;
226 int option_index = 0;
227
228 while ((c = getopt_long (argc, argv, "A:a:bB:CchDdEe:F:f:GhIi:j:k:L:l:M:m:n:oP:pQqiRr:s:STt:uV:vW:w:Y:z6", long_options, &option_index)) != EOF) {
229 /* used for parsing arguments */
230 char *opt_end = optarg;
231 while (opt_end && *opt_end) opt_end++;
232 /* enable a loaded filter script? */
233
234 switch (c) {
235
236 case 'M':
237 set_mitm(optarg);
238 break;
239
240 case 'o':
241 set_onlymitm();
242 //select_text_interface();
243 break;
244
245 case 'b':
246 set_broadcast();
247 break;
248
249 case 'B':
250 set_iface_bridge(optarg);
251 break;
252
253 case 'p':
254 set_promisc();
255 break;
256 #ifndef JUST_LIBRARY
257 case 'T':
258 select_text_interface();
259 break;
260
261 case 'C':
262 select_curses_interface();
263 break;
264
265 case 'G':
266 select_gtk_interface();
267 break;
268
269
270 case 'D':
271 select_daemon_interface();
272 break;
273 #endif
274
275 case 'R':
276 set_reversed();
277 break;
278
279 case 't':
280 set_proto(optarg);
281 break;
282
283 case 'P':
284 set_plugin(optarg);
285 break;
286
287 case 'i':
288 set_iface(optarg);
289 break;
290
291 case 'I':
292 /* this option is only useful in the text interface */
293 set_lifaces();
294 select_text_interface();
295 break;
296
297 case 'Y':
298 set_secondary(optarg);
299 break;
300
301 case 'n':
302 set_netmask(optarg);
303 break;
304
305 case 'A':
306 set_address(optarg);
307 break;
308
309 case 'r':
310 set_read_pcap(optarg);
311 break;
312
313 case 'w':
314 set_write_pcap(optarg);
315 break;
316
317 case 'f':
318 set_pcap_filter(optarg);
319 break;
320
321 case 'F':
322 set_filter(opt_end, optarg);
323 break;
324
325 case 'L':
326 set_loglevel_packet(optarg);
327 break;
328
329 case 'l':
330 set_loglevel_info(optarg);
331 break;
332
333 case 'm':
334 set_loglevel_true(optarg);
335 break;
336
337 case 'c':
338 set_compress();
339 break;
340
341 case 'e':
342 opt_set_regex(optarg);
343 break;
344
345 case 'Q':
346 set_superquiet();
347 /* no break, quiet must be enabled */
348 /* fall through */
349 case 'q':
350 set_quiet();
351 break;
352
353 case 's':
354 set_script(optarg);
355 break;
356
357 case 'z':
358 set_silent();
359 break;
360
361 #ifdef WITH_IPV6
362 case '6':
363 set_ip6scan();
364 break;
365 #endif
366
367 case 'u':
368 set_unoffensive();
369 break;
370
371 case 'S':
372 disable_sslmitm();
373 break;
374
375 case 'd':
376 set_resolve();
377 break;
378
379 case 'j':
380 set_load_hosts(optarg);
381 break;
382
383 case 'k':
384 set_save_hosts(optarg);
385 break;
386
387 case 'V':
388 opt_set_format(optarg);
389 break;
390
391 case 'E':
392 set_ext_headers();
393 break;
394
395 case 'W':
396 set_wifi_key(optarg);
397 break;
398
399 case 'a':
400 set_conf_file(optarg);
401 break;
402
403 case 'h':
404 ec_usage();
405 break;
406
407 case 'v':
408 printf("%s %s\n", EC_GBL_PROGRAM, EC_GBL_VERSION);
409 clean_exit(0);
410 break;
411
412 /* Certificate and private key options */
413 case 0:
414 if (!strcmp(long_options[option_index].name, "certificate")) {
415 EC_GBL_OPTIONS->ssl_cert = strdup(optarg);
416 }
417 else if (!strcmp(long_options[option_index].name, "private-key")) {
418 EC_GBL_OPTIONS->ssl_pkey = strdup(optarg);
419 #ifdef HAVE_EC_LUA
420 }
421 else if (!strcmp(long_options[option_index].name,"lua-args")) {
422 ec_lua_cli_add_args(strdup(optarg));
423 }
424 else if (!strcmp(long_options[option_index].name,"lua-script")) {
425 ec_lua_cli_add_script(strdup(optarg));
426 break;
427 #endif
428 }
429 else if (!strcmp(long_options[option_index].name, "plugin-list")) {
430 set_plugin_list(strdup(optarg));
431 }
432 else {
433 fprintf(stdout, "\nTry `%s --help' for more options.\n\n", EC_GBL_PROGRAM);
434 clean_exit(-1);
435 }
436
437 break;
438
439 case ':': // missing parameter
440 fprintf(stdout, "\nTry `%s --help' for more options.\n\n", EC_GBL_PROGRAM);
441 clean_exit(-1);
442 break;
443
444 case '?': // unknown option
445 fprintf(stdout, "\nTry `%s --help' for more options.\n\n", EC_GBL_PROGRAM);
446 clean_exit(-1);
447 break;
448 }
449 }
450
451 DEBUG_MSG("parse_options: options parsed");
452
453 /* TARGET1 and TARGET2 parsing */
454 if (argv[optind]) {
455 EC_GBL_OPTIONS->target1 = strdup(argv[optind]);
456 DEBUG_MSG("TARGET1: %s", EC_GBL_OPTIONS->target1);
457
458 if (argv[optind+1]) {
459 EC_GBL_OPTIONS->target2 = strdup(argv[optind+1]);
460 DEBUG_MSG("TARGET2: %s", EC_GBL_OPTIONS->target2);
461 }
462 }
463
464 /* create the list form the TARGET format (MAC/IPrange/PORTrange) */
465 compile_display_filter();
466
467 DEBUG_MSG("parse_options: targets parsed");
468
469 /* check for other options */
470
471 if (EC_GBL_SNIFF->start == NULL)
472 set_unified_sniff();
473
474 if (EC_GBL_OPTIONS->read && EC_GBL_PCAP->filter)
475 FATAL_ERROR("Cannot read from file and set a filter on interface");
476
477 if (EC_GBL_OPTIONS->read && EC_GBL_SNIFF->type != SM_UNIFIED )
478 FATAL_ERROR("You can read from a file ONLY in unified sniffing mode !");
479
480 if (EC_GBL_OPTIONS->mitm && EC_GBL_SNIFF->type != SM_UNIFIED )
481 FATAL_ERROR("You can't do mitm attacks in bridged sniffing mode !");
482
483 if (EC_GBL_SNIFF->type == SM_BRIDGED && EC_GBL_PCAP->promisc == 0)
484 FATAL_ERROR("During bridged sniffing the iface must be in promisc mode !");
485
486 if (EC_GBL_OPTIONS->quiet && EC_GBL_UI->type != UI_TEXT)
487 FATAL_ERROR("The quiet option is useful only with text only UI");
488
489 if (EC_GBL_OPTIONS->load_hosts && EC_GBL_OPTIONS->save_hosts)
490 FATAL_ERROR("Cannot load and save at the same time the hosts list...");
491
492 if (EC_GBL_OPTIONS->unoffensive && EC_GBL_OPTIONS->mitm)
493 FATAL_ERROR("Cannot use mitm attacks in unoffensive mode");
494
495 if (EC_GBL_OPTIONS->read && EC_GBL_OPTIONS->mitm)
496 FATAL_ERROR("Cannot use mitm attacks while reading from file");
497
498 #ifndef JUST_LIBRARY
499 if (EC_GBL_UI->init == NULL)
500 FATAL_ERROR("Please select an User Interface");
501 #endif
502
503 /* force text interface for only mitm attack */
504 /* Do not select text interface for only MiTM mode
505
506 if (EC_GBL_OPTIONS->only_mitm) {
507 if (EC_GBL_OPTIONS->mitm)
508 select_text_interface();
509 else
510 FATAL_ERROR("Only mitm requires at least one mitm method");
511 } */
512
513 DEBUG_MSG("parse_options: options combination looks good");
514 return;
515 }
516
517 /* EOF */
518
519
520 // vim:ts=3:expandtab
521