void cleanup_interface(struct config_interfaces * target, int flag) { /* * Flag: 1st bit - 8021x is set. * 2nd bit - WPA is set. * 3rd bit - WEP is set. * 4th bit - open auth is set. */ int wep_res , psk_res, wpa_res, s = -1; struct ifreq ifr; struct ieee80211_nwid nwid; struct ieee80211_nwkey nwkey; struct ieee80211_wpapsk psk; struct ieee80211_wpaparams wpa; s = open_socket(AF_INET); memset(&nwkey, 0, sizeof(nwkey)); strlcpy(nwkey.i_name, target->if_name, sizeof(nwkey.i_name)); wep_res = ioctl(s, SIOCG80211NWKEY, (caddr_t) & nwkey); printf("wep: %d\n", wep_res); memset(&psk, 0, sizeof(psk)); strlcpy(psk.i_name, target->if_name, sizeof(psk.i_name)); psk_res = ioctl(s, SIOCG80211WPAPSK, (caddr_t) & psk); printf("psk_res: %d\n", psk_res); memset(&wpa, 0, sizeof(wpa)); strlcpy(wpa.i_name, target->if_name, sizeof(wpa.i_name)); wpa_res = ioctl(s, SIOCG80211WPAPARMS, &wpa); printf("wpa_res: %d\n", wpa_res); close(s); printf("nwkey wep on: %d\n", nwkey.i_wepon); if (nwkey.i_wepon && flag != 2) { printf("removing wep stuff\n"); set_wep_key(0, NULL, 0); } printf("psk enabled: %d\n", psk.i_enabled); if (psk.i_enabled && flag != 4) { printf("removing psk stuff\n"); set_psk_key(0, 0, target->if_name, 0); } if ((wpa.i_akms & IEEE80211_WPA_AKM_8021X) && flag != 8) { printf("removing 80211x stuff\n"); set_wpa8021x(target->if_name, 0); set_bssid(NULL, target->if_name, 0); if (target->supplicant_pid) kill(target->supplicant_pid, SIGTERM); target->supplicant_pid = 0; } }
static void curses_set_wepkey(void) { set_wep_key(wkey); }
static void gtkui_set_wepkey(void) { set_wep_key(wkey); }
void parse_options(int argc, char **argv) { int c; static struct option long_options[] = { { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'v' }, { "iface", required_argument, NULL, 'i' }, { "iflist", no_argument, NULL, 'I' }, { "netmask", required_argument, NULL, 'n' }, { "write", required_argument, NULL, 'w' }, { "read", required_argument, NULL, 'r' }, { "pcapfilter", required_argument, NULL, 'f' }, { "reversed", no_argument, NULL, 'R' }, { "proto", required_argument, NULL, 't' }, { "plugin", required_argument, NULL, 'P' }, { "filter", required_argument, NULL, 'F' }, { "superquiet", no_argument, NULL, 'Q' }, { "quiet", no_argument, NULL, 'q' }, { "script", required_argument, NULL, 's' }, { "silent", no_argument, NULL, 'z' }, { "unoffensive", no_argument, NULL, 'u' }, { "load-hosts", required_argument, NULL, 'j' }, { "save-hosts", required_argument, NULL, 'k' }, { "wep-key", required_argument, NULL, 'W' }, { "config", required_argument, NULL, 'a' }, { "dns", no_argument, NULL, 'd' }, { "regex", required_argument, NULL, 'e' }, { "visual", required_argument, NULL, 'V' }, { "ext-headers", no_argument, NULL, 'E' }, { "log", required_argument, NULL, 'L' }, { "log-info", required_argument, NULL, 'l' }, { "log-msg", required_argument, NULL, 'm' }, { "compress", no_argument, NULL, 'c' }, { "text", no_argument, NULL, 'T' }, { "curses", no_argument, NULL, 'C' }, { "gtk", no_argument, NULL, 'G' }, { "daemon", no_argument, NULL, 'D' }, { "mitm", required_argument, NULL, 'M' }, { "only-mitm", no_argument, NULL, 'o' }, { "bridge", required_argument, NULL, 'B' }, { "promisc", no_argument, NULL, 'p' }, { 0 , 0 , 0 , 0} }; #ifdef HAVE_GTK if (strcmp(argv[0], "ettercap-gtk") == 0) select_gtk_interface(); #endif #ifdef HAVE_NCURSES if (strcmp(argv[0], "ettercap-curses") == 0) select_curses_interface(); #endif if (strcmp(argv[0], "ettercap-text") == 0) select_text_interface(); for (c = 0; c < argc; c++) DEBUG_MSG("parse_options -- [%d] [%s]", c, argv[c]); /* OPTIONS INITIALIZATION */ GBL_PCAP->promisc = 1; GBL_FORMAT = &ascii_format; /* OPTIONS INITIALIZED */ optind = 0; while ((c = getopt_long (argc, argv, "a:B:CchDdEe:F:f:GhIi:j:k:L:l:M:m:n:oP:pQqiRr:s:Tt:UuV:vW:w:z", long_options, (int *)0)) != EOF) { switch (c) { case 'M': GBL_OPTIONS->mitm = 1; if (mitm_set(optarg) != ESUCCESS) FATAL_ERROR("MITM method '%s' not supported...\n", optarg); break; case 'o': GBL_OPTIONS->only_mitm = 1; //select_text_interface(); break; case 'B': GBL_OPTIONS->iface_bridge = strdup(optarg); set_bridge_sniff(); break; case 'p': GBL_PCAP->promisc = 0; break; case 'T': select_text_interface(); break; case 'C': #ifdef HAVE_NCURSES select_curses_interface(); #else fprintf(stdout, "\nncurses-interface not supported.\n\n"); clean_exit(-1); #endif break; case 'G': #ifdef HAVE_GTK select_gtk_interface(); #else fprintf(stdout, "\nGTK-Interface not supported.\n\n"); clean_exit(-1); #endif break; case 'D': select_daemon_interface(); break; case 'R': GBL_OPTIONS->reversed = 1; break; case 't': GBL_OPTIONS->proto = strdup(optarg); break; case 'P': /* user has requested the list */ if (!strcasecmp(optarg, "list")) { plugin_list(); clean_exit(0); } /* else set the plugin */ GBL_OPTIONS->plugin = strdup(optarg); break; case 'i': GBL_OPTIONS->iface = strdup(optarg); break; case 'I': /* this option is only useful in the text interface */ select_text_interface(); GBL_OPTIONS->iflist = 1; break; case 'n': GBL_OPTIONS->netmask = strdup(optarg); break; case 'r': /* we don't want to scan the lan while reading from file */ GBL_OPTIONS->silent = 1; GBL_OPTIONS->read = 1; GBL_OPTIONS->pcapfile_in = strdup(optarg); break; case 'w': GBL_OPTIONS->write = 1; GBL_OPTIONS->pcapfile_out = strdup(optarg); break; case 'f': GBL_PCAP->filter = strdup(optarg); break; case 'F': if (filter_load_file(optarg, GBL_FILTERS) != ESUCCESS) FATAL_ERROR("Cannot load filter file \"%s\"", optarg); break; case 'L': if (set_loglevel(LOG_PACKET, optarg) == -EFATAL) clean_exit(-EFATAL); break; case 'l': if (set_loglevel(LOG_INFO, optarg) == -EFATAL) clean_exit(-EFATAL); break; case 'm': if (set_msg_loglevel(LOG_TRUE, optarg) == -EFATAL) clean_exit(-EFATAL); break; case 'c': GBL_OPTIONS->compress = 1; break; case 'e': if (set_regex(optarg) == -EFATAL) clean_exit(-EFATAL); break; case 'Q': GBL_OPTIONS->superquiet = 1; /* no break, quiet must be enabled */ case 'q': GBL_OPTIONS->quiet = 1; break; case 's': GBL_OPTIONS->script = strdup(optarg); break; case 'z': GBL_OPTIONS->silent = 1; break; case 'u': GBL_OPTIONS->unoffensive = 1; break; case 'd': GBL_OPTIONS->resolve = 1; break; case 'j': GBL_OPTIONS->silent = 1; GBL_OPTIONS->load_hosts = 1; GBL_OPTIONS->hostsfile = strdup(optarg); break; case 'k': GBL_OPTIONS->save_hosts = 1; GBL_OPTIONS->hostsfile = strdup(optarg); break; case 'V': if (set_format(optarg) != ESUCCESS) clean_exit(-EFATAL); break; case 'E': GBL_OPTIONS->ext_headers = 1; break; case 'W': set_wep_key(optarg); break; case 'a': GBL_CONF->file = strdup(optarg); break; case 'h': ec_usage(); break; case 'v': printf("%s %s\n", GBL_PROGRAM, GBL_VERSION); clean_exit(0); break; case ':': // missing parameter fprintf(stdout, "\nTry `%s --help' for more options.\n\n", GBL_PROGRAM); clean_exit(-1); break; case '?': // unknown option fprintf(stdout, "\nTry `%s --help' for more options.\n\n", GBL_PROGRAM); clean_exit(-1); break; } } DEBUG_MSG("parse_options: options parsed"); /* TARGET1 and TARGET2 parsing */ if (argv[optind]) { GBL_OPTIONS->target1 = strdup(argv[optind]); DEBUG_MSG("TARGET1: %s", GBL_OPTIONS->target1); if (argv[optind+1]) { GBL_OPTIONS->target2 = strdup(argv[optind+1]); DEBUG_MSG("TARGET2: %s", GBL_OPTIONS->target2); } } /* create the list form the TARGET format (MAC/IPrange/PORTrange) */ compile_display_filter(); DEBUG_MSG("parse_options: targets parsed"); /* check for other options */ if (GBL_SNIFF->start == NULL) set_unified_sniff(); if (GBL_OPTIONS->read && GBL_PCAP->filter) FATAL_ERROR("Cannot read from file and set a filter on interface"); if (GBL_OPTIONS->read && GBL_SNIFF->type != SM_UNIFIED ) FATAL_ERROR("You can read from a file ONLY in unified sniffing mode !"); if (GBL_OPTIONS->mitm && GBL_SNIFF->type != SM_UNIFIED ) FATAL_ERROR("You can't do mitm attacks in bridged sniffing mode !"); if (GBL_SNIFF->type == SM_BRIDGED && GBL_PCAP->promisc == 0) FATAL_ERROR("During bridged sniffing the iface must be in promisc mode !"); if (GBL_OPTIONS->quiet && GBL_UI->type != UI_TEXT) FATAL_ERROR("The quiet option is useful only with text only UI"); if (GBL_OPTIONS->load_hosts && GBL_OPTIONS->save_hosts) FATAL_ERROR("Cannot load and save at the same time the hosts list..."); if (GBL_OPTIONS->unoffensive && GBL_OPTIONS->mitm) FATAL_ERROR("Cannot use mitm attacks in unoffensive mode"); if (GBL_OPTIONS->read && GBL_OPTIONS->mitm) FATAL_ERROR("Cannot use mitm attacks while reading from file"); if (GBL_UI->init == NULL) { FATAL_ERROR("Please select an User Interface"); } /* force text interface for only mitm attack */ //if (GBL_OPTIONS->only_mitm) { // if (GBL_OPTIONS->mitm) // select_text_interface(); // else // FATAL_ERROR("Only mitm requires at least one mitm method"); //} DEBUG_MSG("parse_options: options combination looks good"); return; }
int setup_wlaninterface(struct config_interfaces * target) { int retries = 1, res = 0; struct config_ssid *match, *all = all_matching_network(target); char *if_name = target->if_name; match = all; if (!match) return 0; if (network_matches(if_name, match)) { printf("already using matched ssid, we do nothing\n"); clear_ssid(all); return 1; } while (match) { printf("setting up network: %s\n", match->ssid_name); set_network_id((char *) match->ssid_name, if_name); printf("%s\n", match->ssid_auth); update_status(CONNECTING, match->ssid_name); if (strcmp(match->ssid_auth, "802.1x") == 0) { printf("do 8021x stuff\n"); if (!target->supplicant_pid) target->supplicant_pid = start_wpa_supplicant(target->if_name, target->supplicant_pid, 1); cleanup_interface(target, 8); set_bssid((char *) match->ssid_bssid, if_name, 1); set_wpa8021x(if_name, 1); sleep(3); config_wpa_supplicant(if_name, match, 1); } else if (strcmp(match->ssid_auth, "wpa") == 0) { printf("do wpa stuff\n"); cleanup_interface(target, 4); set_psk_key((char *) match->ssid_name, (char *) match->ssid_pass, if_name, 1); } else if (strcmp(match->ssid_auth, "wep") == 0) { printf("do wep stuff\n"); cleanup_interface(target, 2); set_wep_key((char *) match->ssid_pass, if_name, 1); } else if (strcmp(match->ssid_auth, "none") == 0) { printf("no security has been set\n"); cleanup_interface(target, 1); } if (target->ipv6_auto) set_ipv6_auto(if_name); start_dhclient(if_name); while (retries != 0) { if (connection_active(if_name, 1)) { /* * If we are successfully connected to the network * and we don't need additional auth, then we are good. */ sleep(1); res = internet_connectivity_check(match); if (res == 1) { update_status(CONNECTED, match->ssid_name); return 1; } else if (res == 2) { /* * This is a hotspot; run user-defined command * or open default web browser. */ if (!config->additional_auth_exec) hotspot(match); return 1; } else { printf("not active, waiting...\n"); sleep(5); retries--; } } } match = match->next; retries = 1; } clear_ssid(all); return res; }
static int set_wsec(char *ifname, void *credential, int mode) { char tmp[128]; unsigned char psk_mode = 0; WpsEnrCred *cred = (WpsEnrCred *)credential; char prefix[] = "wlXXXXXXXXXX_"; bool b_wps_version2 = false; char *value; value = nvram_get("wps_version2"); if (value && !strcmp(value, "enabled")) b_wps_version2 = true; /* empty credential check */ if (cred->ssidLen == 0) { TUTRACE((TUTRACE_INFO, "Ignore apply new credential because ssid is empty\n")); return 0; } TUTRACE((TUTRACE_INFO, "nvram set key = %s keyMgmt = %s ssid = %s(b_configured)\n", cred->nwKey, cred->keyMgmt, cred->ssid)); /* convert os name to wl name */ if (osifname_to_nvifname(ifname, prefix, sizeof(prefix)) != 0) { TUTRACE((TUTRACE_INFO, "Convert to nvname failed\n")); return 0; } strcat(prefix, "_"); /* Check credential */ if (findstr(cred->keyMgmt, "WPA-PSK")) psk_mode |= 1; if (findstr(cred->keyMgmt, "WPA2-PSK")) psk_mode |= 2; /* for version 2, force psk2 if psk1 is on */ if (b_wps_version2 && (psk_mode & 1)) { psk_mode |= 2; } switch (psk_mode) { case 1: wps_osl_set_conf(strcat_r(prefix, "akm", tmp), "psk "); wps_osl_set_conf(strcat_r(prefix, "auth_mode_x", tmp), "psk"); break; case 2: wps_osl_set_conf(strcat_r(prefix, "akm", tmp), "psk2 "); wps_osl_set_conf(strcat_r(prefix, "auth_mode_x", tmp), "psk2"); break; case 3: wps_osl_set_conf(strcat_r(prefix, "akm", tmp), "psk psk2 "); wps_osl_set_conf(strcat_r(prefix, "auth_mode_x", tmp), "pskpsk2"); break; default: wps_osl_set_conf(strcat_r(prefix, "akm", tmp), ""); wps_osl_set_conf(strcat_r(prefix, "auth_mode_x", tmp), "open"); break; } if (findstr(cred->keyMgmt, "SHARED")) { wps_osl_set_conf(strcat_r(prefix, "auth", tmp), "1"); wps_osl_set_conf(strcat_r(prefix, "auth_mode_x", tmp), "shared"); } else wps_osl_set_conf(strcat_r(prefix, "auth", tmp), "0"); /* set SSID */ wps_osl_set_conf(strcat_r(prefix, "ssid", tmp), cred->ssid); if (psk_mode) { wps_osl_set_conf(strcat_r(prefix, "wep", tmp), "disabled"); wps_osl_set_conf(strcat_r(prefix, "wep_x", tmp), "0"); } /* for version 2, force aes if tkip is on */ if (b_wps_version2 && (cred->encrType & WPS_ENCRTYPE_TKIP)) { cred->encrType |= WPS_ENCRTYPE_AES; } /* set Encr type */ if (cred->encrType == WPS_ENCRTYPE_NONE) { wps_osl_set_conf(strcat_r(prefix, "wep", tmp), "disabled"); wps_osl_set_conf(strcat_r(prefix, "wep_x", tmp), "0"); } else if (cred->encrType == WPS_ENCRTYPE_WEP) wps_osl_set_conf(strcat_r(prefix, "wep", tmp), "enabled"); else if (cred->encrType == WPS_ENCRTYPE_TKIP) wps_osl_set_conf(strcat_r(prefix, "crypto", tmp), "tkip"); else if (cred->encrType == WPS_ENCRTYPE_AES) wps_osl_set_conf(strcat_r(prefix, "crypto", tmp), "aes"); else if (cred->encrType == (WPS_ENCRTYPE_TKIP | WPS_ENCRTYPE_AES)) wps_osl_set_conf(strcat_r(prefix, "crypto", tmp), "tkip+aes"); else wps_osl_set_conf(strcat_r(prefix, "crypto", tmp), "tkip"); if (cred->encrType == WPS_ENCRTYPE_WEP) { char buf[16] = {0}; sprintf(buf, "%d", cred->wepIndex); wps_osl_set_conf(strcat_r(prefix, "key", tmp), buf); sprintf(buf, "key%d", cred->wepIndex); set_wep_key(strcat_r(prefix, buf, tmp), cred->nwKey, cred->nwKeyLen); if ((cred->nwKeyLen == 5) || (cred->nwKeyLen == 10)) wps_osl_set_conf(strcat_r(prefix, "wep_x", tmp), "1"); else wps_osl_set_conf(strcat_r(prefix, "wep_x", tmp), "2"); } else { /* set key */ if (cred->nwKeyLen < 64) { wps_osl_set_conf(strcat_r(prefix, "wpa_psk", tmp), cred->nwKey); } else { char temp_key[65] = {0}; memcpy(temp_key, cred->nwKey, 64); temp_key[64] = 0; wps_osl_set_conf(strcat_r(prefix, "wpa_psk", tmp), temp_key); } } /* Disable nmode for WEP and TKIP for TGN spec */ switch (cred->encrType) { case WPS_ENCRTYPE_WEP: case WPS_ENCRTYPE_TKIP: wps_osl_set_conf(strcat_r(prefix, "nmode", tmp), "0"); break; default: wps_osl_set_conf(strcat_r(prefix, "nmode", tmp), "-1"); break; } nvram_set("w_Setting", "1"); return 1; }
void parse_options(int argc, char **argv) { int c; static struct option long_options[] = { { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'v' }, { "update", no_argument, NULL, 'U' }, { "iface", required_argument, NULL, 'i' }, { "lifaces", no_argument, NULL, 'I' }, { "netmask", required_argument, NULL, 'n' }, { "address", required_argument, NULL, 'A' }, { "write", required_argument, NULL, 'w' }, { "read", required_argument, NULL, 'r' }, { "pcapfilter", required_argument, NULL, 'f' }, { "reversed", no_argument, NULL, 'R' }, { "proto", required_argument, NULL, 't' }, { "plugin", required_argument, NULL, 'P' }, { "filter", required_argument, NULL, 'F' }, { "superquiet", no_argument, NULL, 'Q' }, { "quiet", no_argument, NULL, 'q' }, { "script", required_argument, NULL, 's' }, { "silent", no_argument, NULL, 'z' }, { "unoffensive", no_argument, NULL, 'u' }, { "nosslmitm", no_argument, NULL, 'S' }, { "load-hosts", required_argument, NULL, 'j' }, { "save-hosts", required_argument, NULL, 'k' }, { "wep-key", required_argument, NULL, 'W' }, { "config", required_argument, NULL, 'a' }, { "dns", no_argument, NULL, 'd' }, { "regex", required_argument, NULL, 'e' }, { "visual", required_argument, NULL, 'V' }, { "ext-headers", no_argument, NULL, 'E' }, { "log", required_argument, NULL, 'L' }, { "log-info", required_argument, NULL, 'l' }, { "log-msg", required_argument, NULL, 'm' }, { "compress", no_argument, NULL, 'c' }, { "text", no_argument, NULL, 'T' }, { "curses", no_argument, NULL, 'C' }, { "daemon", no_argument, NULL, 'D' }, { "gtk", no_argument, NULL, 'G' }, { "mitm", required_argument, NULL, 'M' }, { "only-mitm", no_argument, NULL, 'o' }, { "bridge", required_argument, NULL, 'B' }, { "broadcast", required_argument, NULL, 'b' }, { "promisc", no_argument, NULL, 'p' }, { "gateway", required_argument, NULL, 'Y' }, { "certificate", required_argument, NULL, 0 }, { "private-key", required_argument, NULL, 0 }, { 0 , 0 , 0 , 0} }; for (c = 0; c < argc; c++) DEBUG_MSG("parse_options -- [%d] [%s]", c, argv[c]); /* OPTIONS INITIALIZATION */ GBL_PCAP->promisc = 1; GBL_FORMAT = &ascii_format; GBL_OPTIONS->ssl_mitm = 1; GBL_OPTIONS->broadcast = 0; GBL_OPTIONS->ssl_cert = NULL; GBL_OPTIONS->ssl_pkey = NULL; /* OPTIONS INITIALIZED */ optind = 0; int option_index = 0; while ((c = getopt_long (argc, argv, "A:a:bB:CchDdEe:F:f:GhIi:j:k:L:l:M:m:n:oP:pQqiRr:s:STt:UuV:vW:w:Y:z", long_options, &option_index)) != EOF) { /* used for parsing arguments */ char *opt_end = optarg; while (opt_end && *opt_end) opt_end++; /* enable a loaded filter script? */ uint8_t f_enabled = 1; switch (c) { case 'M': GBL_OPTIONS->mitm = 1; if (mitm_set(optarg) != ESUCCESS) FATAL_ERROR("MITM method '%s' not supported...\n", optarg); break; case 'o': GBL_OPTIONS->only_mitm = 1; //select_text_interface(); break; case 'b': GBL_OPTIONS->broadcast = 1; break; case 'B': GBL_OPTIONS->iface_bridge = strdup(optarg); set_bridge_sniff(); break; case 'p': GBL_PCAP->promisc = 0; break; case 'T': select_text_interface(); break; case 'C': select_curses_interface(); break; case 'G': select_gtk_interface(); break; case 'D': select_daemon_interface(); break; case 'R': GBL_OPTIONS->reversed = 1; break; case 't': GBL_OPTIONS->proto = strdup(optarg); break; case 'P': /* user has requested the list */ if (!strcasecmp(optarg, "list")) { plugin_list(); clean_exit(0); } /* else set the plugin */ GBL_OPTIONS->plugin = strdup(optarg); break; case 'i': GBL_OPTIONS->iface = strdup(optarg); break; case 'I': /* this option is only useful in the text interface */ select_text_interface(); GBL_OPTIONS->lifaces = 1; break; case 'Y': GBL_OPTIONS->secondary = parse_iflist(optarg); break; case 'n': GBL_OPTIONS->netmask = strdup(optarg); break; case 'A': GBL_OPTIONS->address = strdup(optarg); break; case 'r': /* we don't want to scan the lan while reading from file */ GBL_OPTIONS->silent = 1; GBL_OPTIONS->read = 1; GBL_OPTIONS->pcapfile_in = strdup(optarg); break; case 'w': GBL_OPTIONS->write = 1; GBL_OPTIONS->pcapfile_out = strdup(optarg); break; case 'f': GBL_PCAP->filter = strdup(optarg); break; case 'F': /* is there a :0 or :1 appended to the filename? */ if ( (opt_end-optarg >=2) && *(opt_end-2) == ':' ) { *(opt_end-2) = '\0'; f_enabled = !( *(opt_end-1) == '0' ); } if (filter_load_file(optarg, GBL_FILTERS, f_enabled) != ESUCCESS) FATAL_ERROR("Cannot load filter file \"%s\"", optarg); break; case 'L': if (set_loglevel(LOG_PACKET, optarg) == -EFATAL) clean_exit(-EFATAL); break; case 'l': if (set_loglevel(LOG_INFO, optarg) == -EFATAL) clean_exit(-EFATAL); break; case 'm': if (set_msg_loglevel(LOG_TRUE, optarg) == -EFATAL) clean_exit(-EFATAL); break; case 'c': GBL_OPTIONS->compress = 1; break; case 'e': if (set_regex(optarg) == -EFATAL) clean_exit(-EFATAL); break; case 'Q': GBL_OPTIONS->superquiet = 1; /* no break, quiet must be enabled */ case 'q': GBL_OPTIONS->quiet = 1; break; case 's': GBL_OPTIONS->script = strdup(optarg); break; case 'z': GBL_OPTIONS->silent = 1; break; case 'u': GBL_OPTIONS->unoffensive = 1; break; case 'S': GBL_OPTIONS->ssl_mitm = 0; break; case 'd': GBL_OPTIONS->resolve = 1; break; case 'j': GBL_OPTIONS->silent = 1; GBL_OPTIONS->load_hosts = 1; GBL_OPTIONS->hostsfile = strdup(optarg); break; case 'k': GBL_OPTIONS->save_hosts = 1; GBL_OPTIONS->hostsfile = strdup(optarg); break; case 'V': if (set_format(optarg) != ESUCCESS) clean_exit(-EFATAL); break; case 'E': GBL_OPTIONS->ext_headers = 1; break; case 'W': set_wep_key(optarg); break; case 'a': GBL_CONF->file = strdup(optarg); break; case 'U': /* load the conf for the connect timeout value */ load_conf(); global_update(); /* NOT REACHED */ break; case 'h': ec_usage(); break; case 'v': printf("%s %s\n", GBL_PROGRAM, GBL_VERSION); clean_exit(0); break; /* Certificate and private key options */ case 0: if (!strcmp(long_options[option_index].name, "certificate")) { GBL_OPTIONS->ssl_cert = strdup(optarg); } else if (!strcmp(long_options[option_index].name, "private-key")) { GBL_OPTIONS->ssl_pkey = strdup(optarg); } else { fprintf(stdout, "\nTry `%s --help' for more options.\n\n", GBL_PROGRAM); clean_exit(-1); } break; case ':': // missing parameter fprintf(stdout, "\nTry `%s --help' for more options.\n\n", GBL_PROGRAM); clean_exit(-1); break; case '?': // unknown option fprintf(stdout, "\nTry `%s --help' for more options.\n\n", GBL_PROGRAM); clean_exit(-1); break; } } DEBUG_MSG("parse_options: options parsed"); /* TARGET1 and TARGET2 parsing */ if (argv[optind]) { GBL_OPTIONS->target1 = strdup(argv[optind]); DEBUG_MSG("TARGET1: %s", GBL_OPTIONS->target1); if (argv[optind+1]) { GBL_OPTIONS->target2 = strdup(argv[optind+1]); DEBUG_MSG("TARGET2: %s", GBL_OPTIONS->target2); } } /* create the list form the TARGET format (MAC/IPrange/PORTrange) */ compile_display_filter(); DEBUG_MSG("parse_options: targets parsed"); /* check for other options */ if (GBL_SNIFF->start == NULL) set_unified_sniff(); if (GBL_OPTIONS->read && GBL_PCAP->filter) FATAL_ERROR("Cannot read from file and set a filter on interface"); if (GBL_OPTIONS->read && GBL_SNIFF->type != SM_UNIFIED ) FATAL_ERROR("You can read from a file ONLY in unified sniffing mode !"); if (GBL_OPTIONS->mitm && GBL_SNIFF->type != SM_UNIFIED ) FATAL_ERROR("You can't do mitm attacks in bridged sniffing mode !"); if (GBL_SNIFF->type == SM_BRIDGED && GBL_PCAP->promisc == 0) FATAL_ERROR("During bridged sniffing the iface must be in promisc mode !"); if (GBL_OPTIONS->quiet && GBL_UI->type != UI_TEXT) FATAL_ERROR("The quiet option is useful only with text only UI"); if (GBL_OPTIONS->load_hosts && GBL_OPTIONS->save_hosts) FATAL_ERROR("Cannot load and save at the same time the hosts list..."); if (GBL_OPTIONS->unoffensive && GBL_OPTIONS->mitm) FATAL_ERROR("Cannot use mitm attacks in unoffensive mode"); if (GBL_OPTIONS->read && GBL_OPTIONS->mitm) FATAL_ERROR("Cannot use mitm attacks while reading from file"); if (GBL_UI->init == NULL) FATAL_ERROR("Please select an User Interface"); /* force text interface for only mitm attack */ /* Do not select text interface for only MiTM mode if (GBL_OPTIONS->only_mitm) { if (GBL_OPTIONS->mitm) select_text_interface(); else FATAL_ERROR("Only mitm requires at least one mitm method"); } */ DEBUG_MSG("parse_options: options combination looks good"); return; }