/* * set the percentage */ int wdg_percentage_set(wdg_t *wo, size_t p, size_t max) { WDG_WO_EXT(struct wdg_percentage, ww); /* set the percentage */ ww->percent = p * 100 / max; WDG_DEBUG_MSG("wdg_percentage_set: %d", ww->percent); wdg_percentage_redraw(wo); /* reached the max, selfdestruct */ if (p == max) { WDG_DEBUG_MSG("wdg_percentage_set: FINISHED"); wdg_destroy_object(&wo); wdg_redraw_all(); return WDG_PERCENTAGE_FINISHED; } /* user has requested to stop the task */ if (ww->interrupt) { WDG_DEBUG_MSG("wdg_percentage_set: INTERRUPTED"); ww->interrupt = 0; wdg_destroy_object(&wo); wdg_redraw_all(); return WDG_PERCENTAGE_INTERRUPTED; } return WDG_PERCENTAGE_UPDATED; }
/* * 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"); }
/* * show the data in a joined window */ static void curses_connection_data_join(void) { char src[MAX_ASCII_ADDR_LEN]; char dst[MAX_ASCII_ADDR_LEN]; char title[64]; DEBUG_MSG("curses_connection_data_join"); if (wdg_conndata) { struct conn_object *tmp_conn = curr_conn; wdg_destroy_object(&wdg_conndata); curses_destroy_conndata(); curr_conn = tmp_conn; } /* don't timeout this connection */ curr_conn->flags |= CONN_VIEWING; wdg_create_object(&wdg_conndata, WDG_COMPOUND, WDG_OBJ_WANT_FOCUS); wdg_set_color(wdg_conndata, WDG_COLOR_SCREEN, EC_COLOR); wdg_set_color(wdg_conndata, WDG_COLOR_WINDOW, EC_COLOR); wdg_set_color(wdg_conndata, WDG_COLOR_FOCUS, EC_COLOR_FOCUS); wdg_set_color(wdg_conndata, WDG_COLOR_TITLE, EC_COLOR_TITLE); wdg_set_title(wdg_conndata, "Connection data", WDG_ALIGN_LEFT); wdg_set_size(wdg_conndata, 1, 2, -1, SYSMSG_WIN_SIZE - 1); wdg_create_object(&wdg_join, WDG_SCROLL, 0); snprintf(title, 64, "%s:%d - %s:%d", ip_addr_ntoa(&curr_conn->L3_addr1, src), ntohs(curr_conn->L4_addr1), ip_addr_ntoa(&curr_conn->L3_addr2, dst), ntohs(curr_conn->L4_addr2)); wdg_set_title(wdg_join, title, WDG_ALIGN_LEFT); wdg_set_color(wdg_join, WDG_COLOR_TITLE, EC_COLOR_TITLE); wdg_set_color(wdg_join, WDG_COLOR_FOCUS, EC_COLOR_FOCUS); wdg_set_size(wdg_join, 2, 3, -2, SYSMSG_WIN_SIZE - 2); /* set the buffers */ wdg_scroll_set_lines(wdg_join, GBL_CONF->connection_buffer / (current_screen.cols / 2) ); /* link the widget together within the compound */ wdg_compound_add(wdg_conndata, wdg_join); /* add the destroy callback */ wdg_add_destroy_key(wdg_conndata, CTRL('Q'), curses_destroy_conndata); /* * do not add inject callback because we can determine where to inject in * joined mode... */ wdg_compound_add_callback(wdg_conndata, 'j', curses_connection_data_split); wdg_compound_add_callback(wdg_conndata, 'k', curses_connection_kill_wrapper); wdg_compound_add_callback(wdg_conndata, ' ', curses_connection_data_help); wdg_draw_object(wdg_conndata); wdg_set_focus(wdg_conndata); /* print the old data */ connbuf_print(&curr_conn->data, join_print); /* add the hook on the connection to receive data only from it */ conntrack_hook_conn_add(curr_conn, join_print_po); }
/* * copy the temp buffers to the real ones */ static void wdg_input_consolidate(struct wdg_object *wo) { WDG_WO_EXT(struct wdg_input_handle, ww); char *buf; int i = 0, j; size_t buflen; void (*callback)(void); WDG_DEBUG_MSG("wdg_input_consolidate"); while(ww->fields[i] != NULL) { /* get the buffer */ buf = field_buffer(ww->fields[i+1], 0); buflen = strlen(buf); /* trim out the trailing spaces */ for (j = buflen - 1; j >= 0; j--) if (buf[j] == ' ') buf[j] = 0; else break; /* copy the buffer in the real one */ strcpy(ww->buffers[i/2], buf); /* skip the label */ i += 2; } /* execute the callback */ callback = ww->callback; wdg_destroy_object(&wo); wdg_redraw_all(); WDG_EXECUTE(callback); }
/* * destroy the dialog and * call the function associated to the button */ static void wdg_dialog_callback(struct wdg_object *wo) { WDG_WO_EXT(struct wdg_dialog, ww); void (*callback)(void); WDG_DEBUG_MSG("wdg_dialog_callback"); callback = ww->buttons[ww->focus_button].callback; wdg_destroy_object(&wo); wdg_redraw_all(); WDG_EXECUTE(callback); }
void curses_sniff_live(void) { wdg_t *menu; DEBUG_MSG("curses_sniff_live"); wdg_create_object(&menu, WDG_MENU, WDG_OBJ_WANT_FOCUS | WDG_OBJ_ROOT_OBJECT); wdg_set_title(menu, GBL_VERSION, WDG_ALIGN_RIGHT); wdg_set_color(menu, WDG_COLOR_SCREEN, EC_COLOR); wdg_set_color(menu, WDG_COLOR_WINDOW, EC_COLOR_MENU); wdg_set_color(menu, WDG_COLOR_FOCUS, EC_COLOR_FOCUS); wdg_set_color(menu, WDG_COLOR_TITLE, EC_COLOR_TITLE); /* add the menu from external files */ wdg_menu_add(menu, menu_start); wdg_menu_add(menu, menu_targets); if (GBL_SNIFF->type != SM_BRIDGED) wdg_menu_add(menu, menu_hosts); wdg_menu_add(menu, menu_view); if (GBL_SNIFF->type != SM_BRIDGED) wdg_menu_add(menu, menu_mitm); wdg_menu_add(menu, menu_filters); wdg_menu_add(menu, menu_logging); #ifdef HAVE_PLUGINS wdg_menu_add(menu, menu_plugins); #endif wdg_menu_add(menu, menu_help); wdg_draw_object(menu); /* repaint the whole screen */ wdg_redraw_all(); wdg_set_focus(menu); /* add the message flush callback */ wdg_add_idle_callback(curses_flush_msg); /* * give the control to the event dispatcher * with the emergency exit key 'Q' */ wdg_events_handler(CTRL('X')); wdg_destroy_object(&menu); }
void curses_interface(void) { DEBUG_MSG("curses_interface"); /* which interface do we have to display ? */ if (GBL_OPTIONS->read) curses_sniff_offline(); else curses_sniff_live(); /* destroy the previously allocated object */ wdg_destroy_object(&sysmsg_win); }
/* * called by the messages dispatcher when the file dialog is focused */ static int wdg_file_get_msg(struct wdg_object *wo, int key, struct wdg_mouse_event *mouse) { WDG_WO_EXT(struct wdg_file_handle, ww); /* handle the message */ switch (key) { case KEY_MOUSE: /* is the mouse event within our edges ? */ if (wenclose(ww->win, mouse->y, mouse->x)) { wdg_set_focus(wo); /* pass it to the menu */ if (wdg_file_driver(wo, key, mouse) != WDG_E_SUCCESS) wdg_file_redraw(wo); } else return -WDG_E_NOTHANDLED; break; case KEY_RETURN: case KEY_DOWN: case KEY_UP: case KEY_PPAGE: case KEY_NPAGE: /* move only if focused */ if (wo->flags & WDG_OBJ_FOCUSED) { if (wdg_file_driver(wo, key, mouse) != WDG_E_SUCCESS) wdg_file_redraw(wo); } else return -WDG_E_NOTHANDLED; break; case KEY_ESC: case CTRL('Q'): wdg_destroy_object(&wo); wdg_redraw_all(); break; /* message not handled */ default: return -WDG_E_NOTHANDLED; break; } return WDG_E_SUCCESS; }
/* * called by the messages dispatcher when the menu is focused */ static int wdg_input_get_msg(struct wdg_object *wo, int key, struct wdg_mouse_event *mouse) { WDG_WO_EXT(struct wdg_input_handle, ww); WDG_DEBUG_MSG("keypress get msg: %d", key); /* handle the message */ switch (key) { case KEY_MOUSE: /* is the mouse event within our edges ? */ if (wenclose(ww->win, mouse->y, mouse->x)) { wdg_set_focus(wo); /* redraw the menu */ wdg_input_redraw(wo); } else { return -WDG_E_NOTHANDLED; } break; case KEY_ESC: case CTRL('Q'): wdg_destroy_object(&wo); wdg_redraw_all(); return WDG_EFINISHED; break; /* message not handled */ default: if (wo->flags & WDG_OBJ_FOCUSED) { return wdg_input_driver(wo, key, mouse); } else { return -WDG_E_NOTHANDLED; } break; } return WDG_E_SUCCESS; }
/* * destroy the dialog and * call the function associated to the file open dialog */ static void wdg_file_callback(struct wdg_object *wo, const char *path, char *file) { WDG_WO_EXT(struct wdg_file_handle, ww); void (*callback)(const char *, char *); char *p, *f; WDG_DEBUG_MSG("wdg_file_callback"); /* save the values before destroying the object */ callback = ww->callback; WDG_SAFE_STRDUP(p, path); WDG_SAFE_STRDUP(f, file); /* destroy the object */ wdg_destroy_object(&wo); wdg_redraw_all(); /* call the callback */ WDG_EXECUTE(callback, p, f); /* free saved data */ WDG_SAFE_FREE(f); WDG_SAFE_FREE(p); }
/* * display the initial menu to setup global options * at startup. */ static void curses_setup(void) { wdg_t *menu; struct wdg_menu file[] = { {"File", 'F', "", NULL}, {"Open...", CTRL('O'), "C-o", curses_file_open}, {"Dump to file...", CTRL('D'), "C-d", curses_file_write}, {"-", 0, "", NULL}, {"Exit", CTRL('X'), "C-x", curses_exit}, {NULL, 0, NULL, NULL}, }; struct wdg_menu live[] = { {"Sniff", 'S', "", NULL}, {"Unified sniffing...", 'U', "U", curses_unified_sniff}, {"Bridged sniffing...", 'B', "B", curses_bridged_sniff}, {"-", 0, "", NULL}, {"Set pcap filter...", 'p', "p", curses_pcap_filter}, {NULL, 0, NULL, NULL}, }; struct wdg_menu options[] = { {"Options", 'O', "", NULL}, {"Unoffensive", 0, tag_unoff, toggle_unoffensive}, {"Promisc mode", 0, tag_promisc, toggle_nopromisc}, {"Set netmask", 'n', "n" , curses_set_netmask}, {NULL, 0, NULL, NULL}, }; DEBUG_MSG("curses_setup"); wdg_create_object(&menu, WDG_MENU, WDG_OBJ_WANT_FOCUS | WDG_OBJ_ROOT_OBJECT); wdg_set_title(menu, GBL_VERSION, WDG_ALIGN_RIGHT); wdg_set_color(menu, WDG_COLOR_SCREEN, EC_COLOR); wdg_set_color(menu, WDG_COLOR_WINDOW, EC_COLOR_MENU); wdg_set_color(menu, WDG_COLOR_FOCUS, EC_COLOR_FOCUS); wdg_set_color(menu, WDG_COLOR_TITLE, EC_COLOR_TITLE); wdg_menu_add(menu, file); wdg_menu_add(menu, live); wdg_menu_add(menu, options); wdg_menu_add(menu, menu_help); wdg_draw_object(menu); DEBUG_MSG("curses_setup: menu created"); /* create the bottom windows for user messages */ wdg_create_object(&sysmsg_win, WDG_SCROLL, WDG_OBJ_WANT_FOCUS); wdg_set_title(sysmsg_win, "User messages:", WDG_ALIGN_LEFT); wdg_set_size(sysmsg_win, 0, SYSMSG_WIN_SIZE, 0, 0); wdg_set_color(sysmsg_win, WDG_COLOR_SCREEN, EC_COLOR); wdg_set_color(sysmsg_win, WDG_COLOR_WINDOW, EC_COLOR); wdg_set_color(sysmsg_win, WDG_COLOR_BORDER, EC_COLOR_BORDER); wdg_set_color(sysmsg_win, WDG_COLOR_FOCUS, EC_COLOR_FOCUS); wdg_set_color(sysmsg_win, WDG_COLOR_TITLE, EC_COLOR_TITLE); wdg_scroll_set_lines(sysmsg_win, 500); wdg_draw_object(sysmsg_win); /* give the focus to the menu */ wdg_set_focus(menu); DEBUG_MSG("curses_setup: sysmsg created"); /* initialize the options */ if (GBL_OPTIONS->unoffensive) tag_unoff[0] = '*'; else tag_unoff[0] = ' '; if (GBL_PCAP->promisc) tag_promisc[0] = '*'; else tag_promisc[0] = ' '; /* give the control to the interface */ wdg_events_handler('u'); wdg_destroy_object(&menu); DEBUG_MSG("curses_setup: end"); }
/* * details for a connection */ static void curses_connection_detail(void *conn) { struct conn_tail *c = (struct conn_tail *)conn; char tmp[MAX_ASCII_ADDR_LEN]; char *proto = ""; char name[MAX_HOSTNAME_LEN]; unsigned int row = 0; DEBUG_MSG("curses_connection_detail"); /* if the object already exist, set the focus to it */ if (wdg_conn_detail) { wdg_destroy_object(&wdg_conn_detail); wdg_conn_detail = NULL; } wdg_create_object(&wdg_conn_detail, WDG_WINDOW, WDG_OBJ_WANT_FOCUS); wdg_set_title(wdg_conn_detail, "Connection detail:", WDG_ALIGN_LEFT); wdg_set_size(wdg_conn_detail, 1, 2, 75, 23); wdg_set_color(wdg_conn_detail, WDG_COLOR_SCREEN, EC_COLOR); wdg_set_color(wdg_conn_detail, WDG_COLOR_WINDOW, EC_COLOR); wdg_set_color(wdg_conn_detail, WDG_COLOR_BORDER, EC_COLOR_BORDER); wdg_set_color(wdg_conn_detail, WDG_COLOR_FOCUS, EC_COLOR_FOCUS); wdg_set_color(wdg_conn_detail, WDG_COLOR_TITLE, EC_COLOR_TITLE); wdg_draw_object(wdg_conn_detail); wdg_set_focus(wdg_conn_detail); /* add the destroy callback */ wdg_add_destroy_key(wdg_conn_detail, CTRL('Q'), NULL); /* print the information */ wdg_window_print(wdg_conn_detail, 1, ++row, "Source MAC address : %s", mac_addr_ntoa(c->co->L2_addr1, tmp)); wdg_window_print(wdg_conn_detail, 1, ++row, "Destination MAC address : %s", mac_addr_ntoa(c->co->L2_addr2, tmp)); ++row; wdg_window_print(wdg_conn_detail, 1, ++row, "Source IP address : %s", ip_addr_ntoa(&(c->co->L3_addr1), tmp)); if (host_iptoa(&(c->co->L3_addr1), name) == E_SUCCESS) wdg_window_print(wdg_conn_detail, 1, ++row, "Source hostname : %s", name); #ifdef HAVE_GEOIP if (GBL_CONF->geoip_support_enable) wdg_window_print(wdg_conn_detail, 1, ++row, "Source location : %s", geoip_country_by_ip(&c->co->L3_addr1)); #endif wdg_window_print(wdg_conn_detail, 1, ++row, "Destination IP address : %s", ip_addr_ntoa(&(c->co->L3_addr2), tmp)); if (host_iptoa(&(c->co->L3_addr2), name) == E_SUCCESS) wdg_window_print(wdg_conn_detail, 1, ++row, "Destination hostname : %s", name); #ifdef HAVE_GEOIP if (GBL_CONF->geoip_support_enable) wdg_window_print(wdg_conn_detail, 1, ++row, "Destination location : %s", geoip_country_by_ip(&c->co->L3_addr2)); #endif ++row; switch (c->co->L4_proto) { case NL_TYPE_UDP: proto = "UDP"; break; case NL_TYPE_TCP: proto = "TCP"; break; } wdg_window_print(wdg_conn_detail, 1, ++row, "Protocol : %s", proto); wdg_window_print(wdg_conn_detail, 1, ++row, "Source port : %-5d %s", ntohs(c->co->L4_addr1), service_search(c->co->L4_addr1, c->co->L4_proto)); wdg_window_print(wdg_conn_detail, 1, ++row, "Destination port : %-5d %s", ntohs(c->co->L4_addr2), service_search(c->co->L4_addr2, c->co->L4_proto)); row++; wdg_window_print(wdg_conn_detail, 1, ++row, "--> %d <-- %d total: %d ", c->co->tx, c->co->rx, c->co->xferred); row++; if (c->co->DISSECTOR.user) { wdg_window_print(wdg_conn_detail, 1, ++row, "Account : %s / %s", c->co->DISSECTOR.user, c->co->DISSECTOR.pass); if (c->co->DISSECTOR.info) wdg_window_print(wdg_conn_detail, 1, ++row, "Additional Info : %s", c->co->DISSECTOR.info); } }