// safe test results to a log file if enabled void Responder::write_log_file() { try { if(_opt.log_file){ std::map<std::string, std::string> hw_info = get_hw_info(); ofstream logs(_stats_log_filename.c_str()); logs << boost::format("title=%s") % _opt.test_title << endl; logs << boost::format("device=%s") % _usrp->get_mboard_name() << endl; logs << boost::format("device_args=%s") % _opt.device_args << endl; logs << boost::format("type=%s") % hw_info["type"] << endl; if (hw_info.size() > 0) { logs << boost::format("usrp_addr=%s") % hw_info["usrp_addr"] << endl; logs << boost::format("usrp_name=%s") % hw_info["name"] << endl; logs << boost::format("serial=%s") % hw_info["serial"] << endl; logs << boost::format("host_interface=%s") % hw_info["interface"] << endl; logs << boost::format("host_addr=%s") % hw_info["host_addr"] << endl; logs << boost::format("host_mac=%s") % hw_info["mac"] << endl; logs << boost::format("host_vendor=%s (id=%s)") % hw_info["vendor"] % hw_info["vendor_id"] << endl; logs << boost::format("host_device=%s (id=%s)") % hw_info["device"] % hw_info["device_id"] << endl; } logs << boost::format("sample_rate=%f") % _opt.sample_rate << endl; logs << boost::format("samps_per_buff=%i") % _opt.samps_per_buff << endl; logs << boost::format("samps_per_packet=%i") % _samps_per_packet << endl; logs << boost::format("delay_min=%f") % _opt.delay_min << endl; logs << boost::format("delay_max=%f") % _opt.delay_max << endl; logs << boost::format("delay_step=%f") % _delay_step << endl; logs << boost::format("delay=%f") % _delay << endl; logs << boost::format("init_delay=%f") % _opt.init_delay << endl; logs << boost::format("response_duration=%f") % _opt.response_duration << endl; logs << boost::format("response_length=%ld") % _response_length << endl; logs << boost::format("timeout=%f") % _opt.timeout << endl; logs << boost::format("timeout_burst_count=%ld") % _timeout_burst_count << endl; logs << boost::format("timeout_eob_count=%f") % _timeout_eob_count << endl; logs << boost::format("allow_late_bursts=%s") % (_allow_late_bursts ? "yes" : "no") << endl; logs << boost::format("skip_eob=%s") % (_opt.skip_eob ? "yes" : "no") << endl; logs << boost::format("combine_eob=%s") % (_opt.combine_eob ? "yes" : "no") << endl; logs << boost::format("skip_send=%s") % (_opt.skip_send ? "yes" : "no") << endl; logs << boost::format("no_delay=%s") % (_no_delay ? "yes" : "no") << endl; logs << boost::format("simulate_frequency=%f") % _simulate_frequency << endl; logs << boost::format("simulate_duration=%ld") % _simulate_duration << endl; logs << boost::format("original_simulate_duration=%ld") % _original_simulate_duration << endl; logs << boost::format("realtime=%s") % (_opt.realtime ? "yes" : "no") << endl; logs << boost::format("rt_priority=%f") % _opt.rt_priority << endl; logs << boost::format("test_iterations=%ld") % _opt.test_iterations << endl; logs << boost::format("end_test_after_success_count=%i") % _opt.end_test_after_success_count << endl; logs << boost::format("skip_iterations=%i") % _opt.skip_iterations << endl; logs << boost::format("overruns=%i") % _overruns << endl; logs << boost::format("num_total_samps=%ld") % _num_total_samps << endl; logs << boost::format("return_code=%i\t(%s)") % _return_code % enum2str(_return_code) << endl; logs << endl; write_debug_info(logs); if(uhd_error_msgs.length() > 0) { logs << endl << "%% UHD ERROR MESSAGES %%" << endl; logs << uhd_error_msgs; } } } catch(...) { cerr << "Failed to write log file to: " << _stats_log_filename << endl; } }
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; }