void clean_exit(int errcode) { DEBUG_MSG("clean_exit: %d", errcode); INSTANT_USER_MSG("\nTerminating %s...\n", GBL_PROGRAM); #ifdef HAVE_EC_LUA /* Cleanup lua */ ec_lua_fini(); #endif /* flush the exit message */ ui_msg_flush(MSG_ALL); /* stop the mitm attack */ mitm_stop(); /* terminate the sniffing engine */ EXECUTE(GBL_SNIFF->cleanup); /* kill all the running threads but the current */ ec_thread_kill_all(); /* close the UI */ ui_cleanup(); /* call all the ATEXIT functions */ exit(errcode); }
/* * stop all the mitm attack(s) */ void gtkui_mitm_stop(void) { GtkWidget *dialog; DEBUG_MSG("gtk_mitm_stop"); /* create the dialog */ dialog = gtk_message_dialog_new(GTK_WINDOW (window), GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, 0, "Stopping the mitm attack..."); gtk_window_set_position(GTK_WINDOW (dialog), GTK_WIN_POS_CENTER); gtk_window_set_resizable(GTK_WINDOW (dialog), FALSE); gtk_widget_queue_draw(dialog); gtk_widget_show_now(dialog); /* for GTK to display the dialog now */ while (gtk_events_pending ()) gtk_main_iteration (); /* stop the mitm process */ mitm_stop(); gtk_widget_destroy(dialog); gtkui_message("MITM attack(s) stopped"); }
/* * stop all the mitm attack(s) */ static void curses_mitm_stop(void) { wdg_t *dlg; DEBUG_MSG("curses_mitm_stop"); /* create the dialog */ wdg_create_object(&dlg, WDG_DIALOG, WDG_OBJ_WANT_FOCUS); wdg_set_color(dlg, WDG_COLOR_SCREEN, EC_COLOR); wdg_set_color(dlg, WDG_COLOR_WINDOW, EC_COLOR); wdg_set_color(dlg, WDG_COLOR_FOCUS, EC_COLOR_FOCUS); wdg_set_color(dlg, WDG_COLOR_TITLE, EC_COLOR_TITLE); wdg_dialog_text(dlg, WDG_NO_BUTTONS, "Stopping the mitm attack..."); wdg_draw_object(dlg); wdg_set_focus(dlg); wdg_update_screen(); /* stop the mitm process */ mitm_stop(); wdg_destroy_object(&dlg); curses_message("MITM attack(s) stopped"); }
int main(int argc, char *argv[]) { /* * Alloc the global structures * We can access these structs via the macro in ec_globals.h */ globals_alloc(); GBL_PROGRAM = strdup(EC_PROGRAM); GBL_VERSION = strdup(EC_VERSION); SAFE_CALLOC(GBL_DEBUG_FILE, strlen(EC_PROGRAM) + strlen(EC_VERSION) + strlen("_debug.log") + 1, sizeof(char)); sprintf(GBL_DEBUG_FILE, "%s%s_debug.log", GBL_PROGRAM, EC_VERSION); DEBUG_INIT(); DEBUG_MSG("main -- here we go !!"); /* initialize the filter mutex */ filter_init_mutex(); /* register the main thread as "init" */ ec_thread_register(EC_PTHREAD_SELF, "init", "initialization phase"); /* activate the signal handler */ signal_handler(); /* ettercap copyright */ fprintf(stdout, "\n" EC_COLOR_BOLD "%s %s" EC_COLOR_END " copyright %s %s\n\n", GBL_PROGRAM, GBL_VERSION, EC_COPYRIGHT, EC_AUTHORS); /* getopt related parsing... */ parse_options(argc, argv); /* check the date */ time_check(); /* load the configuration file */ load_conf(); /* * get the list of available interfaces * * this function will not return if the -I option was * specified on command line. it will instead print the * list and exit */ capture_getifs(); /* initialize the user interface */ ui_init(); /* initialize libpcap */ capture_init(); /* initialize libnet (the function contain all the checks) */ send_init(); /* get hardware infos */ get_hw_info(); /* * always disable the kernel ip forwarding (except when reading from file). * the forwarding will be done by ettercap. */ if (!GBL_OPTIONS->read && !GBL_OPTIONS->unoffensive && !GBL_OPTIONS->only_mitm) disable_ip_forward(); /* binds ports and set redirect for ssl wrapper */ if (!GBL_OPTIONS->read && !GBL_OPTIONS->unoffensive && !GBL_OPTIONS->only_mitm && GBL_SNIFF->type == SM_UNIFIED) ssl_wrap_init(); /* * drop root privileges * we have alread opened the sockets with high privileges * we don't need any more root privs. */ drop_privs(); /***** !! NO PRIVS AFTER THIS POINT !! *****/ /* load all the plugins */ plugin_load_all(); /* print how many dissectors were loaded */ conf_dissectors(); /* load the mac-fingerprints */ manuf_init(); /* load the tcp-fingerprints */ fingerprint_init(); /* load the services names */ services_init(); /* load http known fileds for user/pass */ http_fields_init(); /* set the encoding for the UTF-8 visualization */ set_utf8_encoding(GBL_CONF->utf8_encoding); /* print all the buffered messages */ if (GBL_UI->type == UI_TEXT) USER_MSG("\n"); ui_msg_flush(MSG_ALL); /**** INITIALIZATION PHASE TERMINATED ****/ /* * we are interested only in the mitm attack i * if entered, this function will not return... */ if (GBL_OPTIONS->only_mitm) only_mitm(); /* create the dispatcher thread */ ec_thread_new("top_half", "dispatching module", &top_half, NULL); /* this thread becomes the UI then displays it */ ec_thread_register(EC_PTHREAD_SELF, GBL_PROGRAM, "the user interface"); ui_start(); /******************************************** * reached only when the UI is shutted down ********************************************/ /* flush the exit message */ ui_msg_flush(MSG_ALL); /* stop the mitm attack */ mitm_stop(); /* terminate the sniffing engine */ EXECUTE(GBL_SNIFF->cleanup); /* kill all the running threads but the current */ ec_thread_kill_all(); /* clean up the UI */ ui_cleanup(); return 0; }