Exemplo n.º 1
0
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);

}
Exemplo n.º 2
0
int
main (int argc, char** argv)
{
	ui_t *ui = NULL;
	sink_t *sink = NULL;
	GThread *sink_thread = NULL;
	GAsyncQueue *queue = NULL;

	g_thread_init (NULL);
	queue = g_async_queue_new ();

	if (!(sink = sink_init (queue)))
		return EXIT_FAILURE;

	if(!(ui = ui_init (queue, &argc, &argv)))
		 return EXIT_FAILURE;

	g_async_queue_unref (queue);
	sink_thread = g_thread_create (sink_run, (gpointer) sink, TRUE, NULL);

	ui_run(ui);
	g_thread_join (sink_thread);

	ui_cleanup (ui);
	sink_cleanup (sink);

	g_printf ("So long, and thanks for the fish !\n");

	return EXIT_SUCCESS;
}
Exemplo n.º 3
0
/*
 * raise an error
 */
void error_msg(char *file, const char *function, int line, char *message, ...)
{
   va_list ap;
   char errmsg[ERROR_MSG_LEN + 1];    /* should be enough */
   int err_code;

#ifdef OS_WINDOWS
   err_code = GetLastError();  /* Most likely not a libc error */
   if (err_code == 0)
      err_code = errno;
#else
   err_code = errno;
#endif
   

   va_start(ap, message);
   vsnprintf(errmsg, ERROR_MSG_LEN, message, ap);
   va_end(ap);

   DEBUG_MSG("ERROR : %d, %s\n[%s:%s:%d] %s \n",  err_code, strerror(err_code),
                   file, function, line, errmsg );
   
   /* close the interface and display the error */
   ui_cleanup();
  
   fprintf(stderr, "ERROR : %d, %s\n[%s:%s:%d]\n\n %s \n\n",  err_code, strerror(err_code),
                   file, function, line, errmsg );

   exit(-err_code);
}
Exemplo n.º 4
0
/*
 * received on CTRL+C or SIGTERM
 */
static void signal_TERM(int sig)
{
   #ifdef HAVE_STRSIGNAL
      DEBUG_MSG("Signal handler... (caught SIGNAL: %d) | %s", sig, strsignal(sig));
   #else
      DEBUG_MSG("Signal handler... (caught SIGNAL: %d)", sig);
   #endif
      
   /* terminate the UI */
   ui_cleanup();

   if (sig == SIGINT) {
      fprintf(stderr, "\n\nUser requested a CTRL+C... (deprecated, next time use proper shutdown)\n\n");
   } else {
   #ifdef HAVE_STRSIGNAL
      fprintf(stderr, "\n\n Shutting down %s (received SIGNAL: %d | %s)\n\n", GBL_PROGRAM, sig, strsignal(sig));
   #else
      fprintf(stderr, "\n\n Shutting down %s (received SIGNAL: %d)\n\n", GBL_PROGRAM, sig);
   #endif
   }
   
   signal(sig, SIG_IGN);

   /* flush and close the log file */
   log_stop();

	/* make sure we exit gracefully */
   clean_exit(0);
}
Exemplo n.º 5
0
Arquivo: ui.c Projeto: punitsoni/rvcon
/* UI Loop */
void ui_start() {
	int c;
	while (1) {
		c = getch(); /* refresh, accept single keystroke of input */
		mvprintw(0, 0, "c=%03d", c, c);
		refresh();
		switch (c) {
		case 'q':
			ui_cleanup();
			break;
		case KEY_UP:
            ui_handle_key_up();
			break;
		case KEY_DOWN:
            ui_handle_key_down();
			break;
		case KEY_LEFT:
            ui_handle_key_left();
			break;
		case KEY_RIGHT:
            ui_handle_key_right();
			break;

		}
	}
}
Exemplo n.º 6
0
Arquivo: ui.c Projeto: barak/gtkboard
void ui_check_who_won()
{
	char *line, *who_str = NULL;
	int who, len;
	if (!move_fout)
		return;
	fprintf (move_fout, "WHO_WON \n");
	fflush (move_fout);
	line = line_read(move_fin);
	if (g_strncasecmp(line, "ACK", 3))
	{
		// NAK ==> not implemented
		ui_gameover = FALSE;
		sb_set_score ("");
		return;
	}
	line += 4;
	line = g_strstrip(line);
	who_str = line;
	while(!isspace(*line) && *line) line++;
	while(isspace(*line)) line++;
	sb_set_score (line);
	if (!g_strncasecmp(who_str, "NYET", 4))
	{
		ui_gameover = FALSE;
		return;
	}
	ui_stopped = TRUE;
	ui_gameover = TRUE;
	if (opt_logfile)
		fprintf(opt_logfile, "RESULT: %s\n", who_str);
	if (!state_gui_active)
		ui_cleanup();
	sb_update ();
	if (game_single_player && !ui_cheated && !g_strncasecmp(who_str, "WON", 3))
	{
		gboolean retval;
		retval = prefs_add_highscore (line, sb_get_human_time ());
		if (retval)
			sound_play (SOUND_HIGHSCORE);
		else 
			sound_play (SOUND_WON);
		if (game_levels)
		{
			GameLevel *next_level = game_levels;
			while (next_level->name)
			{
				if (next_level->game == opt_game)
					break;
				next_level++;
			}
			next_level++;
			if (next_level->name)
				menu_put_level (next_level->name);
		}
	}
	if (game_single_player && !ui_cheated && !g_strncasecmp(who_str, "LOST", 4))
		sound_play (SOUND_LOST);
}
Exemplo n.º 7
0
void bug(char *file, const char *function, int line, char *message)
{
   DEBUG_MSG("BUG : [%s:%s:%d] %s \n", file, function, line, message );
   
   /* close the interface and display the error */
   ui_cleanup();
  
   fprintf(stderr, "\n\nBUG at [%s:%s:%d]\n\n %s \n\n", file, function, line, message );

   exit(-666);
}
Exemplo n.º 8
0
void clean_exit(int errcode)
{
   DEBUG_MSG("clean_exit: %d", errcode);
  
   INSTANT_USER_MSG("\nTerminating %s...\n", GBL_PROGRAM);

   /* kill all the running threads but the current */
   ec_thread_kill_all();

   /* close the UI */
   ui_cleanup();

   /* call all the ATEXIT functions */
   exit(errcode);
}
Exemplo n.º 9
0
int
curses_ui()
{
	int err;

	err = ui_init();
	if (err == -1) {
		return (-1);
	}

	file_list.dir_name = malloc(MAXPATHLEN + 1);
	if (!file_list.dir_name) {
		mvwprintw(main_win, 0, 1, "ERROR: Can't initialize dir_name.");
		wrefresh(main_win);
		return (-1);
	}
	err = first_run_file_list(main_win);
	if (err == -1) {
		mvwprintw(main_win, 0, 1, "ERROR: Can't initialize file list.");
		wrefresh(main_win);
		return (-1);
	}

	sock_fd = get_client_socket();

	err = pthread_create(&receiver_thread, rcv_attr, ui_socket_receiver, rcv_arg);
	if (err != 0) {
		mvwprintw(main_win, 0, 1, "ERROR: receiver thread");
		wrefresh(main_win);
		return (-1);
	}

	show_files(main_win);
	curses_loop();

	// wait for receiver_thread if alive
	if (pthread_kill(receiver_thread, 0) == 0) {
		printw("UI: waiting for receiver_thread..");
		refresh();
		pthread_join(receiver_thread, NULL);
	}

	free_dir_list();
	free(file_list.dir_name);

	ui_cleanup();
	return (0);
}
Exemplo n.º 10
0
/*
 * received when something goes wrong ;)
 */
static void signal_SEGV(int sig)
{
#ifdef DEBUG

#ifndef OS_WINDOWS
   struct rlimit corelimit = {RLIM_INFINITY, RLIM_INFINITY};
#endif

#ifdef SIGBUS
   if (sig == SIGBUS)
      DEBUG_MSG(" !!! BUS ERROR !!!");
   else
#endif
      DEBUG_MSG(" !!! SEGMENTATION FAULT !!!");
   
   ui_cleanup();
   
   fprintf (stderr, "\n"EC_COLOR_YELLOW"Ooops !! This shouldn't happen...\n\n"EC_COLOR_END);
#ifdef SIGBUS
   if (sig == SIGBUS)
      fprintf (stderr, EC_COLOR_RED"Bus error...\n\n"EC_COLOR_END);
   else
#endif
      fprintf (stderr, EC_COLOR_RED"Segmentation Fault...\n\n"EC_COLOR_END);

   fprintf (stderr, "===========================================================================\n");
   fprintf (stderr, " To report this error follow these steps:\n\n");
   fprintf (stderr, "  1) set ec_uid to 0 (so the core will be dumped)\n\n");
   fprintf (stderr, "  2) execute ettercap with \"-w debug_dump.pcap\"\n\n");
   fprintf (stderr, "  3) reproduce the critical situation\n\n");
   fprintf (stderr, "  4) make a report : \n\t\"tar zcvf error.tar.gz %s%s_debug.log debug_dump.pcap\"\n\n", EC_PROGRAM, EC_VERSION);
   fprintf (stderr, "  5) get the gdb backtrace :\n"
                    "  \t - \"gdb %s core\"\n"
                    "  \t - at the gdb prompt \"bt\"\n"
                    "  \t - at the gdb prompt \"quit\" and return to the shell\n"
                    "  \t - copy and paste this output.\n\n", EC_PROGRAM);
   fprintf (stderr, "  6) mail us the output of gdb and the error.tar.gz\n");
   fprintf (stderr, "============================================================================\n");
   
   fprintf (stderr, EC_COLOR_CYAN"\n Core dumping... (use the 'core' file for gdb analysis)\n\n"EC_COLOR_END);
#ifdef HAVE_EC_LUA
   fprintf (stderr, EC_COLOR_CYAN" Lua stack trace: \n"EC_COLOR_END);
   // Let's try to print the lua stack trace, maybe.
   ec_lua_print_stack(stderr);
   fprintf (stderr, "\n");
#endif
   fprintf (stderr, EC_COLOR_YELLOW" Have a nice day!\n"EC_COLOR_END);
   
   /* force the coredump */
#ifndef OS_WINDOWS
   setrlimit(RLIMIT_CORE, &corelimit);
#endif
   signal(sig, SIG_DFL);
   raise(sig);

#else
   
   ui_cleanup();
   
   fprintf(stderr, EC_COLOR_YELLOW"Ooops ! This shouldn't happen...\n"EC_COLOR_END);
#ifdef SIGBUS
   if (sig == SIGBUS)
      fprintf (stderr, EC_COLOR_RED"Bus error...\n\n"EC_COLOR_END);
   else
#endif
      fprintf (stderr, EC_COLOR_RED"Segmentation Fault...\n\n"EC_COLOR_END);
   fprintf(stderr, "Please recompile in debug mode, reproduce the bug and send a bugreport\n\n");
   fprintf (stderr, EC_COLOR_YELLOW" Have a nice day!\n"EC_COLOR_END);

   
   clean_exit(666);
#endif
}
Exemplo n.º 11
0
Arquivo: ui.c Projeto: punitsoni/rvcon
static void ui_handle_signal(int sig) {
	ui_cleanup();
}
Exemplo n.º 12
0
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;
}