int main(int argc, char** argv) { if (argc > 1 && (!strcmp(argv[1], "--help") || !strcmp(argv[1], "-h"))) usage(0); int socket = ::socket(AF_LINK, SOCK_DGRAM, 0); if (socket < 0) { fprintf(stderr, "%s: The networking stack doesn't seem to be " "available.\n", kProgramName); return 1; } close(socket); if (argc > 1 && (!strcmp(argv[1], "--delete") || !strcmp(argv[1], "--del") || !strcmp(argv[1], "-d") || !strcmp(argv[1], "del") || !strcmp(argv[1], "delete"))) { // Delete interface (addresses) if (argc < 3) usage(1); const char* name = argv[2]; delete_interface(name, argv + 3, argc - 3); return 0; } if (argc > 1 && !strcmp(argv[1], "-a")) { // Accept an optional "-a" option to list all interfaces for those // that are used to it from other platforms. if (argc > 2) usage(1); list_interfaces(NULL); return 0; } const char* name = argv[1]; if (argc > 2) { if (configure_wireless(name, argv + 2, argc - 2)) return 0; // Add or configure an interface configure_interface(name, argv + 2, argc - 2); return 0; } // list interfaces list_interfaces(name); return 0; }
int main(int argc, char** argv) { if (argc > 1 && (!strcmp(argv[1], "--help") || !strcmp(argv[1], "-h"))) usage(0); bool deleteInterfaces = false; if (argc > 1 && (!strcmp(argv[1], "--delete") || !strcmp(argv[1], "--del") || !strcmp(argv[1], "-d"))) { // delete interfaces if (argc < 3) usage(1); deleteInterfaces = true; } // we need a socket to talk to the networking stack int socket = ::socket(AF_INET, SOCK_DGRAM, 0); if (socket < 0) { fprintf(stderr, "%s: The networking stack doesn't seem to be " "available.\n", kProgramName); return 1; } if (deleteInterfaces) { for (int i = 2; i < argc; i++) { delete_interface(socket, argv[i]); } return 0; } else if (argc > 1 && !strcmp(argv[1], "-a")) { // accept -a option for those that are used to it from other platforms if (argc > 2) usage(1); list_interfaces(socket, NULL); return 0; } const char* name = argv[1]; if (argc > 2) { // add or configure an interface configure_interface(socket, name, argv + 2, argc - 2); return 0; } // list interfaces list_interfaces(socket, name); return 0; }
static PyObject* p0fmod_list_interfaces(PyObject *self,PyObject *args) { // -L // Returns // 0 - success int ret=0; list_interfaces(); return Py_BuildValue("i",ret); }
void show_all_interfaces(int family) { int fd; fd=socket(family, SOCK_DGRAM, 0); if(fd<0) { perror("socket()"); exit(EXIT_FAILURE); } list_interfaces(fd, show_interface); close(fd); }
int main(int argc, char **argv) { int result; int option_idx = 0; int do_list_interfaces = 0; int do_config = 0; int do_capture = 0; int i; char* interface = NULL; char* remote_host = NULL; unsigned int remote_port = 22; char* remote_username = NULL; char* remote_password = NULL; int do_dlts = 0; char* fifo = NULL; char* remote_interface = NULL; char* remote_capture_bin = NULL; char* extcap_filter = NULL; char* sshkey = NULL; char* sshkey_passphrase = NULL; char* remote_filter = NULL; unsigned long int count = 0; #ifdef _WIN32 WSADATA wsaData; attach_parent_console(); #endif /* _WIN32 */ opterr = 0; optind = 0; if (argc == 1) { help(argv[0]); return EXIT_FAILURE; } for (i = 0; i < argc; i++) { verbose_print("%s ", argv[i]); } verbose_print("\n"); while ((result = getopt_long(argc, argv, ":", longopts, &option_idx)) != -1) { switch (result) { case OPT_HELP: help(argv[0]); return EXIT_SUCCESS; case OPT_VERBOSE: verbose = TRUE; break; case OPT_VERSION: printf("%u.%u.%u\n", SSHDUMP_VERSION_MAJOR, SSHDUMP_VERSION_MINOR, SSHDUMP_VERSION_RELEASE); return EXIT_SUCCESS; case OPT_LIST_INTERFACES: do_list_interfaces = 1; break; case OPT_LIST_DLTS: do_dlts = 1; break; case OPT_INTERFACE: if (interface) g_free(interface); interface = g_strdup(optarg); break; case OPT_CONFIG: do_config = 1; break; case OPT_CAPTURE: do_capture = 1; break; case OPT_FIFO: if (fifo) g_free(fifo); fifo = g_strdup(optarg); break; case OPT_REMOTE_HOST: if (remote_host) g_free(remote_host); remote_host = g_strdup(optarg); break; case OPT_REMOTE_PORT: remote_port = (unsigned int)strtoul(optarg, NULL, 10); if (remote_port > 65535 || remote_port == 0) { printf("Invalid port: %s\n", optarg); return EXIT_FAILURE; } break; case OPT_REMOTE_USERNAME: if (remote_username) g_free(remote_username); remote_username = g_strdup(optarg); break; case OPT_REMOTE_PASSWORD: if (remote_password) g_free(remote_password); remote_password = g_strdup(optarg); memset(optarg, 'X', strlen(optarg)); break; case OPT_SSHKEY: if (sshkey) g_free(sshkey); sshkey = g_strdup(optarg); break; case OPT_SSHKEY_PASSPHRASE: if (sshkey_passphrase) g_free(sshkey_passphrase); sshkey_passphrase = g_strdup(optarg); memset(optarg, 'X', strlen(optarg)); break; case OPT_REMOTE_INTERFACE: if (remote_interface) g_free(remote_interface); remote_interface = g_strdup(optarg); break; case OPT_REMOTE_CAPTURE_BIN: if (remote_capture_bin) g_free(remote_capture_bin); remote_capture_bin = g_strdup(optarg); break; case OPT_EXTCAP_FILTER: if (extcap_filter) g_free(extcap_filter); extcap_filter = g_strdup(optarg); break; case OPT_REMOTE_FILTER: if (remote_filter) g_free(remote_filter); remote_filter = g_strdup(optarg); break; case OPT_REMOTE_COUNT: count = strtoul(optarg, NULL, 10); break; case ':': /* missing option argument */ printf("Option '%s' requires an argument\n", argv[optind - 1]); break; default: printf("Invalid option: %s\n", argv[optind - 1]); return EXIT_FAILURE; } } if (optind != argc) { printf("Unexpected extra option: %s\n", argv[optind]); return EXIT_FAILURE; } if (do_list_interfaces) return list_interfaces(); if (do_config) return list_config(interface, remote_port); if (do_dlts) return list_dlts(interface); #ifdef _WIN32 result = WSAStartup(MAKEWORD(1,1), &wsaData); if (result != 0) { if (verbose) errmsg_print("ERROR: WSAStartup failed with error: %d\n", result); return 1; } #endif /* _WIN32 */ if (do_capture) { char* filter; int ret = 0; if (!fifo) { errmsg_print("ERROR: No FIFO or file specified\n"); return 1; } if (g_strcmp0(interface, SSH_EXTCAP_INTERFACE)) { errmsg_print("ERROR: invalid interface\n"); return 1; } if (!remote_host) { errmsg_print("Missing parameter: --remote-host"); return 1; } filter = concat_filters(extcap_filter, remote_filter); ret = ssh_open_remote_connection(remote_host, remote_port, remote_username, remote_password, sshkey, sshkey_passphrase, remote_interface, filter, remote_capture_bin, count, fifo); g_free(filter); return ret; } verbose_print("You should not come here... maybe some parameter missing?\n"); return 1; }
int main(int argc, char** argv) { s32 r; setlinebuf(stdout); SAYF("--- p0f " VERSION " by Michal Zalewski <*****@*****.**> ---\n\n"); if (getuid() != geteuid()) FATAL("Please don't make me setuid. See README for more.\n"); while ((r = getopt(argc, argv, "+LS:df:i:m:o:pr:s:t:u:")) != -1) switch (r) { case 'L': list_interfaces(); exit(0); case 'S': #ifdef __CYGWIN__ FATAL("API mode not supported on Windows (see README)."); #else if (api_max_conn != API_MAX_CONN) FATAL("Multiple -S options not supported."); api_max_conn = atol(optarg); if (!api_max_conn || api_max_conn > 100) FATAL("Outlandish value specified for -S."); break; #endif /* ^__CYGWIN__ */ case 'd': if (daemon_mode) FATAL("Double werewolf mode not supported yet."); daemon_mode = 1; break; case 'f': if (fp_file) FATAL("Multiple -f options not supported."); fp_file = (u8*)optarg; break; case 'i': if (use_iface) FATAL("Multiple -i options not supported (try '-i any')."); use_iface = (u8*)optarg; break; case 'm': if (max_conn != MAX_CONN || max_hosts != MAX_HOSTS) FATAL("Multiple -m options not supported."); if (sscanf(optarg, "%u,%u", &max_conn, &max_hosts) != 2 || !max_conn || max_conn > 100000 || !max_hosts || max_hosts > 500000) FATAL("Outlandish value specified for -m."); break; case 'o': if (log_file) FATAL("Multiple -o options not supported."); log_file = (u8*)optarg; break; case 'p': if (set_promisc) FATAL("Even more promiscuous? People will call me slutty!"); set_promisc = 1; break; case 'r': if (read_file) FATAL("Multiple -r options not supported."); read_file = (u8*)optarg; break; case 's': #ifdef __CYGWIN__ FATAL("API mode not supported on Windows (see README)."); #else if (api_sock) FATAL("Multiple -s options not supported."); api_sock = (u8*)optarg; break; #endif /* ^__CYGWIN__ */ case 't': if (conn_max_age != CONN_MAX_AGE || host_idle_limit != HOST_IDLE_LIMIT) FATAL("Multiple -t options not supported."); if (sscanf(optarg, "%u,%u", &conn_max_age, &host_idle_limit) != 2 || !conn_max_age || conn_max_age > 1000000 || !host_idle_limit || host_idle_limit > 1000000) FATAL("Outlandish value specified for -t."); break; case 'u': if (switch_user) FATAL("Split personality mode not supported."); switch_user = (u8*)optarg; break; default: usage(); } if (optind < argc) { if (optind + 1 == argc) orig_rule = (u8*)argv[optind]; else FATAL("Filter rule must be a single parameter (use quotes)."); } if (read_file && api_sock) FATAL("API mode looks down on ofline captures."); if (!api_sock && api_max_conn != API_MAX_CONN) FATAL("Option -S makes sense only with -s."); if (daemon_mode) { if (read_file) FATAL("Daemon mode and offline captures don't mix."); if (!log_file && !api_sock) FATAL("Daemon mode requires -o or -s."); #ifdef __CYGWIN__ if (switch_user) SAYF("[!] Note: under cygwin, -u is largely useless.\n"); #else if (!switch_user) SAYF("[!] Consider specifying -u in daemon mode (see README).\n"); #endif /* ^__CYGWIN__ */ } tzset(); setlocale(LC_TIME, "C"); close_spare_fds(); get_hash_seed(); http_init(); read_config(fp_file ? fp_file : (u8*)FP_FILE); prepare_pcap(); prepare_bpf(); if (log_file) open_log(); if (api_sock) open_api(); if (daemon_mode) { null_fd = open("/dev/null", O_RDONLY); if (null_fd < 0) PFATAL("Cannot open '/dev/null'."); } if (switch_user) drop_privs(); if (daemon_mode) fork_off(); signal(SIGHUP, daemon_mode ? SIG_IGN : abort_handler); signal(SIGINT, abort_handler); signal(SIGTERM, abort_handler); if (read_file) offline_event_loop(); else live_event_loop(); if (!daemon_mode) SAYF("\nAll done. Processed %llu packets.\n", packet_cnt); #ifdef DEBUG_BUILD destroy_all_hosts(); TRK_report(); #endif /* DEBUG_BUILD */ return 0; }
int main(int argc, char *argv[]) { signal (SIGINT, signal_handler); //printf("\033[?1049h\033[H"); clear_log(); my_log("Software switch starting..."); my_log(pcap_lib_version()); int option = 0, ret; char c; pthread_t config_thread; char errbuf[PCAP_ERRBUF_SIZE]; p1 = create_port_struct(1); p2 = create_port_struct(2); while ((option = getopt(argc, argv,"h l 1:2: m")) != -1) { switch (option) { case '1' : strcpy(p1->name, optarg); break; case '2' : strcpy(p2->name, optarg); break; case 'l': list_interfaces(); exit(0); case 'm': mock_rule(); break; case 'h': default: print_usage(); exit(EXIT_FAILURE); } } p1->handle = pcap_create(p1->name, errbuf); if ( (ret = pcap_setdirection(p1->handle, PCAP_D_IN)) != 0){ printf("pcap_setdirection returned %i\n", ret); my_log("pcap_setdirection failed"); pcap_perror(p1->handle, 0); //exit(-1); } if ( pcap_set_promisc(p1->handle, 1) != 0){ printf("pcap_set_promisc returned \n%s\n", pcap_geterr(p1->handle)); my_log("pcap_set_promisc failed"); pcap_perror(p1->handle, 0); exit(-1); } if ( pcap_set_immediate_mode(p1->handle, 1) != 0){ printf("pcap_set_immediate_mode returned \n%s\n", pcap_geterr(p1->handle)); my_log("pcap_set_immediate_mode failed"); pcap_perror(p1->handle, 0); exit(-1); } if ( pcap_activate(p1->handle)){ printf("Failed to open interface %s\n", pcap_geterr(p1->handle)); exit(-1); } else { sprintf(log_b, "Handle activated for %s", p1->name); my_log(log_b); } p2->handle = pcap_create(p2->name, errbuf); if ( pcap_setdirection(p2->handle, PCAP_D_OUT) != 0){ my_log("pcap_setdirection failed"); pcap_perror(p2->handle, 0); //exit(-1); } if ( pcap_set_promisc(p2->handle, 1) != 0){ my_log("pcap_set_promisc failed"); pcap_perror(p2->handle, 0); exit(-1); } if ( pcap_set_immediate_mode(p2->handle, 1) != 0){ my_log("pcap_set_immediate_mode failed"); pcap_perror(p2->handle, 0); exit(-1); } if ( pcap_activate(p2->handle)){ printf("Failed to open interface %s\n", pcap_geterr(p2->handle)); exit(-1); } else { sprintf(log_b, "Handle activated for %s", p2->name); my_log(log_b); } //exit(0); my_log("Deleting mac table.."); clear_mac(); sprintf(log_b, "Default action is %s", (DEFAULT_ACTION == R_ALLOW)? "R_ALLOW" : "R_DENY"); my_log(log_b); my_log("Creating threads..."); pthread_mutex_init(&mutex, NULL); if ( pthread_create(&(p1->thread), 0, port_listener, (void *)p1) ){ my_log("Error creating p1 thread"); exit(-1); } if ( pthread_create(&(p2->thread), 0, port_listener, (void *)p2) ){ my_log("Error creating p2 thread"); exit(-1); } pthread_create(&config_thread, 0, config, 0); while (1) { mac_delete_old_entries(5); if(pause_rendering == 1) continue; // render here system("clear"); print_mac(); print_rules(); print_stats_header(); print_stats(p1->in, "1 IN"); print_stats(p1->out, "1 OUT"); print_stats(p2->in, "2 IN"); print_stats(p2->out, "2 OUT"); printf("p1in: %i\tp1out: %i\tp2in: %i\tp2out: %i\n", p1in, p1out, p2in, p2out); sleep(1); } pthread_join(config_thread, 0); pthread_join(p1->thread, 0); pthread_join(p2->thread, 0); //printf("\033[?1049l"); // go back return 0; }