| File: | builds/wireshark/wireshark/extcap/sshdump.c |
| Warning: | line 271, column 9 Opened stream never closed. Potential resource leak |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* sshdump.c | |||
| 2 | * sshdump is extcap tool used to capture data using a remote ssh host | |||
| 3 | * | |||
| 4 | * Copyright 2015, Dario Lombardo | |||
| 5 | * | |||
| 6 | * Wireshark - Network traffic analyzer | |||
| 7 | * By Gerald Combs <[email protected]> | |||
| 8 | * Copyright 1998 Gerald Combs | |||
| 9 | * | |||
| 10 | * SPDX-License-Identifier: GPL-2.0-or-later | |||
| 11 | */ | |||
| 12 | ||||
| 13 | #include "config.h" | |||
| 14 | #define WS_LOG_DOMAIN"sshdump" "sshdump" | |||
| 15 | ||||
| 16 | #include <extcap/extcap-base.h> | |||
| 17 | #include <extcap/ssh-base.h> | |||
| 18 | #include <wsutil/interface.h> | |||
| 19 | #include <wsutil/file_util.h> | |||
| 20 | #include <wsutil/strtoi.h> | |||
| 21 | #include <wsutil/filesystem.h> | |||
| 22 | #include <wsutil/privileges.h> | |||
| 23 | #include <wsutil/please_report_bug.h> | |||
| 24 | #include <wsutil/wslog.h> | |||
| 25 | #include <app/application_flavor.h> | |||
| 26 | ||||
| 27 | #include <errno(*__errno_location ()).h> | |||
| 28 | #include <string.h> | |||
| 29 | #include <fcntl.h> | |||
| 30 | ||||
| 31 | #include <cli_main.h> | |||
| 32 | ||||
| 33 | static char* sshdump_extcap_interface; | |||
| 34 | #define DEFAULT_SSHDUMP_EXTCAP_INTERFACE"sshdump" "sshdump" | |||
| 35 | ||||
| 36 | #define SSHDUMP_VERSION_MAJOR"1" "1" | |||
| 37 | #define SSHDUMP_VERSION_MINOR"2" "2" | |||
| 38 | #define SSHDUMP_VERSION_RELEASE"0" "0" | |||
| 39 | ||||
| 40 | #define SSH_READ_BLOCK_SIZE256 256 | |||
| 41 | ||||
| 42 | enum { | |||
| 43 | EXTCAP_BASE_OPTIONS_ENUMEXTCAP_OPT_LIST_INTERFACES, EXTCAP_OPT_VERSION, EXTCAP_OPT_LIST_DLTS , EXTCAP_OPT_INTERFACE, EXTCAP_OPT_CONFIG, EXTCAP_OPT_CONFIG_OPTION_NAME , EXTCAP_OPT_CONFIG_OPTION_VALUE, EXTCAP_OPT_CLEANUP_POSTKILL , EXTCAP_OPT_CAPTURE, EXTCAP_OPT_CAPTURE_FILTER, EXTCAP_OPT_FIFO , EXTCAP_OPT_LOG_LEVEL, EXTCAP_OPT_LOG_FILE, | |||
| 44 | OPT_HELP, | |||
| 45 | OPT_VERSION, | |||
| 46 | SSH_BASE_PACKET_OPTIONS_ENUMOPT_REMOTE_HOST, OPT_REMOTE_PORT, OPT_REMOTE_USERNAME, OPT_REMOTE_PASSWORD , OPT_SSHKEY, OPT_SSHKEY_PASSPHRASE, OPT_PROXYCOMMAND, OPT_SSH_SHA1 , OPT_UPDATE_KNOWN_HOSTS, OPT_REMOTE_INTERFACE, OPT_REMOTE_FILTER, | |||
| 47 | OPT_REMOTE_CAPTURE_COMMAND_SELECT, | |||
| 48 | OPT_REMOTE_CAPTURE_COMMAND, | |||
| 49 | OPT_REMOTE_COUNT, | |||
| 50 | OPT_REMOTE_SUDO, // Deprecated | |||
| 51 | OPT_REMOTE_PRIV, | |||
| 52 | OPT_REMOTE_PRIV_USER, | |||
| 53 | OPT_REMOTE_NOPROM | |||
| 54 | }; | |||
| 55 | ||||
| 56 | static const struct ws_option longopts[] = { | |||
| 57 | EXTCAP_BASE_OPTIONS{ "extcap-interfaces", 0, ((void*)0), EXTCAP_OPT_LIST_INTERFACES }, { "extcap-version", 2, ((void*)0), EXTCAP_OPT_VERSION}, { "extcap-dlts" , 0, ((void*)0), EXTCAP_OPT_LIST_DLTS}, { "extcap-interface", 1, ((void*)0), EXTCAP_OPT_INTERFACE}, { "extcap-config", 0, ( (void*)0), EXTCAP_OPT_CONFIG}, { "extcap-config-option-name", 1, ((void*)0), EXTCAP_OPT_CONFIG_OPTION_NAME}, { "extcap-config-option-value" , 1, ((void*)0), EXTCAP_OPT_CONFIG_OPTION_VALUE }, { "extcap-cleanup-postkill" , 0, ((void*)0), EXTCAP_OPT_CLEANUP_POSTKILL }, { "capture", 0 , ((void*)0), EXTCAP_OPT_CAPTURE}, { "extcap-capture-filter", 1, ((void*)0), EXTCAP_OPT_CAPTURE_FILTER}, { "fifo", 1, ((void *)0), EXTCAP_OPT_FIFO}, { "log-level", 1, ((void*)0), EXTCAP_OPT_LOG_LEVEL }, { "log-file", 1, ((void*)0), EXTCAP_OPT_LOG_FILE}, | |||
| 58 | { "help", ws_no_argument0, NULL((void*)0), OPT_HELP}, | |||
| 59 | { "version", ws_no_argument0, NULL((void*)0), OPT_VERSION}, | |||
| 60 | SSH_BASE_PACKET_OPTIONS{ "remote-host", 1, ((void*)0), OPT_REMOTE_HOST}, { "remote-port" , 1, ((void*)0), OPT_REMOTE_PORT}, { "remote-username", 1, (( void*)0), OPT_REMOTE_USERNAME}, { "remote-password", 1, ((void *)0), OPT_REMOTE_PASSWORD}, { "remote-count", 1, ((void*)0), OPT_REMOTE_COUNT }, { "sshkey", 1, ((void*)0), OPT_SSHKEY}, { "sshkey-passphrase" , 1, ((void*)0), OPT_SSHKEY_PASSPHRASE}, { "proxycommand", 1, ((void*)0), OPT_PROXYCOMMAND}, { "ssh-sha1", 0, ((void*)0), OPT_SSH_SHA1 }, { "update-known-hosts", 0, ((void*)0), OPT_UPDATE_KNOWN_HOSTS }, { "remote-interface", 1, ((void*)0), OPT_REMOTE_INTERFACE} , { "remote-filter", 1, ((void*)0), OPT_REMOTE_FILTER}, | |||
| 61 | { "remote-capture-command-select", ws_required_argument1, NULL((void*)0), OPT_REMOTE_CAPTURE_COMMAND_SELECT}, | |||
| 62 | { "remote-capture-command", ws_required_argument1, NULL((void*)0), OPT_REMOTE_CAPTURE_COMMAND}, | |||
| 63 | { "remote-sudo", ws_no_argument0, NULL((void*)0), OPT_REMOTE_SUDO }, // Deprecated | |||
| 64 | { "remote-priv", ws_required_argument1, NULL((void*)0), OPT_REMOTE_PRIV }, | |||
| 65 | { "remote-priv-user", ws_required_argument1, NULL((void*)0), OPT_REMOTE_PRIV_USER }, | |||
| 66 | { "remote-noprom", ws_no_argument0, NULL((void*)0), OPT_REMOTE_NOPROM }, | |||
| 67 | { 0, 0, 0, 0} | |||
| 68 | }; | |||
| 69 | ||||
| 70 | static char* interfaces_list_to_filter(GSList* if_list, unsigned int remote_port); | |||
| 71 | ||||
| 72 | static int ssh_loop_read(ssh_channel channel, FILE* fp) | |||
| 73 | { | |||
| 74 | int nbytes; | |||
| 75 | int ret = EXIT_SUCCESS0; | |||
| 76 | char buffer[SSH_READ_BLOCK_SIZE256]; | |||
| 77 | ||||
| 78 | /* read from stdin until data are available */ | |||
| 79 | while (ssh_channel_is_open(channel) && !ssh_channel_is_eof(channel)) { | |||
| 80 | nbytes = ssh_channel_read(channel, buffer, SSH_READ_BLOCK_SIZE256, 0); | |||
| 81 | if (nbytes < 0) { | |||
| 82 | ws_warning("Error reading from channel")do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c" , 82, __func__, "Error reading from channel"); } } while (0); | |||
| 83 | goto end; | |||
| 84 | } | |||
| 85 | if (nbytes == 0) { | |||
| 86 | break; | |||
| 87 | } | |||
| 88 | if (fwrite(buffer, 1, nbytes, fp) != (unsigned)nbytes) { | |||
| 89 | ws_warning("Error writing to fifo")do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c" , 89, __func__, "Error writing to fifo"); } } while (0); | |||
| 90 | ret = EXIT_FAILURE1; | |||
| 91 | goto end; | |||
| 92 | } | |||
| 93 | fflush(fp); | |||
| 94 | } | |||
| 95 | ||||
| 96 | /* read loop finished... maybe something wrong happened. Read from stderr */ | |||
| 97 | while (ssh_channel_is_open(channel) && !ssh_channel_is_eof(channel)) { | |||
| 98 | nbytes = ssh_channel_read(channel, buffer, SSH_READ_BLOCK_SIZE256, 1); | |||
| 99 | if (nbytes < 0) { | |||
| 100 | ws_warning("Error reading from channel")do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c" , 100, __func__, "Error reading from channel"); } } while (0); | |||
| 101 | goto end; | |||
| 102 | } | |||
| 103 | if (fwrite(buffer, 1, nbytes, stderrstderr) != (unsigned)nbytes) { | |||
| 104 | ws_warning("Error writing to stderr")do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c" , 104, __func__, "Error writing to stderr"); } } while (0); | |||
| 105 | break; | |||
| 106 | } | |||
| 107 | } | |||
| 108 | ||||
| 109 | end: | |||
| 110 | if (ssh_channel_send_eof(channel) != SSH_OK0) { | |||
| 111 | ws_warning("Error sending EOF in ssh channel")do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c" , 111, __func__, "Error sending EOF in ssh channel"); } } while (0); | |||
| 112 | ret = EXIT_FAILURE1; | |||
| 113 | } | |||
| 114 | return ret; | |||
| 115 | } | |||
| 116 | ||||
| 117 | static char* local_interfaces_to_filter(const uint16_t remote_port) | |||
| 118 | { | |||
| 119 | GSList* interfaces = local_interfaces_to_list(); | |||
| 120 | char* filter = interfaces_list_to_filter(interfaces, remote_port); | |||
| 121 | g_slist_free_full(interfaces, g_free); | |||
| 122 | return filter; | |||
| 123 | } | |||
| 124 | ||||
| 125 | static ssh_channel run_ssh_command(ssh_session sshs, const char* capture_command_select, | |||
| 126 | const char* capture_command, const char* privilege, bool_Bool noprom, | |||
| 127 | const char* iface, const char* cfilter, const uint32_t count) | |||
| 128 | { | |||
| 129 | char* cmdline = NULL((void*)0); | |||
| 130 | ssh_channel channel; | |||
| 131 | char** ifaces_array = NULL((void*)0); | |||
| 132 | int ifaces_array_num = 0; | |||
| 133 | GString *ifaces_string; | |||
| 134 | char *ifaces = NULL((void*)0); | |||
| 135 | char* quoted_iface = NULL((void*)0); | |||
| 136 | char* quoted_filter = NULL((void*)0); | |||
| 137 | char* count_str = NULL((void*)0); | |||
| 138 | unsigned int remote_port = 22; | |||
| 139 | ||||
| 140 | channel = ssh_channel_new(sshs); | |||
| 141 | if (!channel) { | |||
| 142 | ws_warning("Can't create channel")do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c" , 142, __func__, "Can't create channel"); } } while (0); | |||
| 143 | return NULL((void*)0); | |||
| 144 | } | |||
| 145 | ||||
| 146 | if (ssh_channel_open_session(channel) != SSH_OK0) { | |||
| 147 | ws_warning("Can't open session")do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c" , 147, __func__, "Can't open session"); } } while (0); | |||
| 148 | ssh_channel_free(channel); | |||
| 149 | return NULL((void*)0); | |||
| 150 | } | |||
| 151 | ||||
| 152 | ssh_options_get_port(sshs, &remote_port); | |||
| 153 | ||||
| 154 | if (capture_command_select == NULL((void*)0) || !g_strcmp0(capture_command_select, "other")) { | |||
| 155 | if (capture_command && *capture_command) { | |||
| 156 | cmdline = g_strdup(capture_command)g_strdup_inline (capture_command); | |||
| 157 | ws_debug("Remote capture command has disabled other options")do { if (1) { ws_log_full("sshdump", LOG_LEVEL_DEBUG, "extcap/sshdump.c" , 157, __func__, "Remote capture command has disabled other options" ); } } while (0); | |||
| 158 | } else { | |||
| 159 | capture_command_select = "tcpdump"; | |||
| 160 | } | |||
| 161 | } | |||
| 162 | ||||
| 163 | /* escape parameters to go save with the shell */ | |||
| 164 | if (!g_strcmp0(capture_command_select, "tcpdump")) { | |||
| 165 | quoted_iface = iface ? g_shell_quote(iface) : NULL((void*)0); | |||
| 166 | quoted_filter = g_shell_quote(cfilter ? cfilter : ""); | |||
| 167 | if (count > 0) | |||
| 168 | count_str = ws_strdup_printf("-c %u", count)wmem_strdup_printf(((void*)0), "-c %u", count); | |||
| 169 | ||||
| 170 | cmdline = ws_strdup_printf("%s tcpdump -U %s%s %s -w - %s %s",wmem_strdup_printf(((void*)0), "%s tcpdump -U %s%s %s -w - %s %s" , privilege, quoted_iface ? "-i " : "", quoted_iface ? quoted_iface : "", noprom ? "-p" : "", count_str ? count_str : "", quoted_filter ) | |||
| 171 | privilege,wmem_strdup_printf(((void*)0), "%s tcpdump -U %s%s %s -w - %s %s" , privilege, quoted_iface ? "-i " : "", quoted_iface ? quoted_iface : "", noprom ? "-p" : "", count_str ? count_str : "", quoted_filter ) | |||
| 172 | quoted_iface ? "-i " : "",wmem_strdup_printf(((void*)0), "%s tcpdump -U %s%s %s -w - %s %s" , privilege, quoted_iface ? "-i " : "", quoted_iface ? quoted_iface : "", noprom ? "-p" : "", count_str ? count_str : "", quoted_filter ) | |||
| 173 | quoted_iface ? quoted_iface : "",wmem_strdup_printf(((void*)0), "%s tcpdump -U %s%s %s -w - %s %s" , privilege, quoted_iface ? "-i " : "", quoted_iface ? quoted_iface : "", noprom ? "-p" : "", count_str ? count_str : "", quoted_filter ) | |||
| 174 | noprom ? "-p" : "",wmem_strdup_printf(((void*)0), "%s tcpdump -U %s%s %s -w - %s %s" , privilege, quoted_iface ? "-i " : "", quoted_iface ? quoted_iface : "", noprom ? "-p" : "", count_str ? count_str : "", quoted_filter ) | |||
| 175 | count_str ? count_str : "",wmem_strdup_printf(((void*)0), "%s tcpdump -U %s%s %s -w - %s %s" , privilege, quoted_iface ? "-i " : "", quoted_iface ? quoted_iface : "", noprom ? "-p" : "", count_str ? count_str : "", quoted_filter ) | |||
| 176 | quoted_filter)wmem_strdup_printf(((void*)0), "%s tcpdump -U %s%s %s -w - %s %s" , privilege, quoted_iface ? "-i " : "", quoted_iface ? quoted_iface : "", noprom ? "-p" : "", count_str ? count_str : "", quoted_filter ); | |||
| 177 | } else if (!g_strcmp0(capture_command_select, "dumpcap")) { | |||
| 178 | if (iface) { | |||
| 179 | ifaces_array = g_strsplit(iface, " ", -1); | |||
| 180 | ifaces_string = g_string_new(NULL((void*)0)); | |||
| 181 | while (ifaces_array[ifaces_array_num]) | |||
| 182 | { | |||
| 183 | quoted_iface = g_shell_quote(ifaces_array[ifaces_array_num]); | |||
| 184 | g_string_append_printf(ifaces_string, "-i %s ", quoted_iface); | |||
| 185 | ifaces_array_num++; | |||
| 186 | } | |||
| 187 | ifaces = g_string_free(ifaces_string, FALSE)(__builtin_constant_p ((0)) ? (((0)) ? (g_string_free) ((ifaces_string ), ((0))) : g_string_free_and_steal (ifaces_string)) : (g_string_free ) ((ifaces_string), ((0)))); | |||
| 188 | } | |||
| 189 | quoted_filter = g_shell_quote(cfilter ? cfilter : ""); | |||
| 190 | if (count > 0) | |||
| 191 | count_str = ws_strdup_printf("-c %u", count)wmem_strdup_printf(((void*)0), "-c %u", count); | |||
| 192 | ||||
| 193 | cmdline = ws_strdup_printf("%s dumpcap %s %s -w - %s -f %s",wmem_strdup_printf(((void*)0), "%s dumpcap %s %s -w - %s -f %s" , privilege, noprom ? "-p" : "", ifaces ? ifaces : "", count_str ? count_str : "", quoted_filter) | |||
| 194 | privilege,wmem_strdup_printf(((void*)0), "%s dumpcap %s %s -w - %s -f %s" , privilege, noprom ? "-p" : "", ifaces ? ifaces : "", count_str ? count_str : "", quoted_filter) | |||
| 195 | noprom ? "-p" : "",wmem_strdup_printf(((void*)0), "%s dumpcap %s %s -w - %s -f %s" , privilege, noprom ? "-p" : "", ifaces ? ifaces : "", count_str ? count_str : "", quoted_filter) | |||
| 196 | ifaces ? ifaces : "",wmem_strdup_printf(((void*)0), "%s dumpcap %s %s -w - %s -f %s" , privilege, noprom ? "-p" : "", ifaces ? ifaces : "", count_str ? count_str : "", quoted_filter) | |||
| 197 | count_str ? count_str : "",wmem_strdup_printf(((void*)0), "%s dumpcap %s %s -w - %s -f %s" , privilege, noprom ? "-p" : "", ifaces ? ifaces : "", count_str ? count_str : "", quoted_filter) | |||
| 198 | quoted_filter)wmem_strdup_printf(((void*)0), "%s dumpcap %s %s -w - %s -f %s" , privilege, noprom ? "-p" : "", ifaces ? ifaces : "", count_str ? count_str : "", quoted_filter); | |||
| 199 | ||||
| 200 | g_free(ifaces)(__builtin_object_size ((ifaces), 0) != ((size_t) - 1)) ? g_free_sized (ifaces, __builtin_object_size ((ifaces), 0)) : (g_free) (ifaces ); | |||
| 201 | g_strfreev(ifaces_array); | |||
| 202 | } | |||
| 203 | ||||
| 204 | ws_debug("Running: %s", cmdline)do { if (1) { ws_log_full("sshdump", LOG_LEVEL_DEBUG, "extcap/sshdump.c" , 204, __func__, "Running: %s", cmdline); } } while (0); | |||
| 205 | if (ssh_channel_request_exec(channel, cmdline) != SSH_OK0) { | |||
| 206 | ws_warning("Can't request exec")do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c" , 206, __func__, "Can't request exec"); } } while (0); | |||
| 207 | ssh_channel_close(channel); | |||
| 208 | ssh_channel_free(channel); | |||
| 209 | channel = NULL((void*)0); | |||
| 210 | } | |||
| 211 | ||||
| 212 | g_free(quoted_iface)(__builtin_object_size ((quoted_iface), 0) != ((size_t) - 1)) ? g_free_sized (quoted_iface, __builtin_object_size ((quoted_iface ), 0)) : (g_free) (quoted_iface); | |||
| 213 | g_free(quoted_filter)(__builtin_object_size ((quoted_filter), 0) != ((size_t) - 1) ) ? g_free_sized (quoted_filter, __builtin_object_size ((quoted_filter ), 0)) : (g_free) (quoted_filter); | |||
| 214 | g_free(cmdline)(__builtin_object_size ((cmdline), 0) != ((size_t) - 1)) ? g_free_sized (cmdline, __builtin_object_size ((cmdline), 0)) : (g_free) ( cmdline); | |||
| 215 | g_free(count_str)(__builtin_object_size ((count_str), 0) != ((size_t) - 1)) ? g_free_sized (count_str, __builtin_object_size ((count_str), 0)) : (g_free ) (count_str); | |||
| 216 | ||||
| 217 | return channel; | |||
| 218 | } | |||
| 219 | ||||
| 220 | static int ssh_open_remote_connection(const ssh_params_t* params, const char* iface, const char* cfilter, | |||
| 221 | const char* capture_command_select, const char* capture_command, const char* privilege, | |||
| 222 | bool_Bool noprom, const uint32_t count, const char* fifo) | |||
| 223 | { | |||
| 224 | ssh_session sshs = NULL((void*)0); | |||
| 225 | ssh_channel channel = NULL((void*)0); | |||
| 226 | FILE* fp = stdoutstdout; | |||
| 227 | int ret = EXIT_FAILURE1; | |||
| 228 | char* err_info = NULL((void*)0); | |||
| 229 | ||||
| 230 | if (g_strcmp0(fifo, "-")) { | |||
| 231 | /* Open or create the output file */ | |||
| 232 | fp = fopen(fifo, "wb"); | |||
| 233 | if (fp
| |||
| 234 | ws_warning("Error creating output file: %s (%s)", fifo, g_strerror(errno))do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c" , 234, __func__, "Error creating output file: %s (%s)", fifo, g_strerror((*__errno_location ()))); } } while (0); | |||
| 235 | return EXIT_FAILURE1; | |||
| 236 | } | |||
| 237 | } | |||
| 238 | ||||
| 239 | sshs = create_ssh_connection(params, &err_info); | |||
| 240 | ||||
| 241 | if (!sshs) { | |||
| 242 | ws_warning("Error creating connection.")do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c" , 242, __func__, "Error creating connection."); } } while (0); | |||
| 243 | goto cleanup; | |||
| 244 | } | |||
| 245 | ||||
| 246 | channel = run_ssh_command(sshs, capture_command_select, capture_command, privilege, noprom, iface, cfilter, count); | |||
| 247 | ||||
| 248 | if (!channel) { | |||
| 249 | ws_warning("Can't run ssh command.")do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c" , 249, __func__, "Can't run ssh command."); } } while (0); | |||
| 250 | goto cleanup; | |||
| 251 | } | |||
| 252 | ||||
| 253 | /* read from channel and write into fp */ | |||
| 254 | if (ssh_loop_read(channel, fp) != EXIT_SUCCESS0) { | |||
| 255 | ws_warning("Error in read loop.")do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c" , 255, __func__, "Error in read loop."); } } while (0); | |||
| 256 | ret = EXIT_FAILURE1; | |||
| 257 | goto cleanup; | |||
| 258 | } | |||
| 259 | ||||
| 260 | ret = EXIT_SUCCESS0; | |||
| 261 | cleanup: | |||
| 262 | if (err_info) | |||
| 263 | ws_warning("%s", err_info)do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c" , 263, __func__, "%s", err_info); } } while (0); | |||
| 264 | g_free(err_info)(__builtin_object_size ((err_info), 0) != ((size_t) - 1)) ? g_free_sized (err_info, __builtin_object_size ((err_info), 0)) : (g_free) (err_info); | |||
| 265 | ||||
| 266 | /* clean up and exit */ | |||
| 267 | ssh_cleanup(&sshs, &channel); | |||
| 268 | ||||
| 269 | if (g_strcmp0(fifo, "-")) | |||
| 270 | fclose(fp); | |||
| 271 | return ret; | |||
| ||||
| 272 | } | |||
| 273 | ||||
| 274 | static char* interfaces_list_to_filter(GSList* interfaces, unsigned int remote_port) | |||
| 275 | { | |||
| 276 | GString* filter = g_string_new(NULL((void*)0)); | |||
| 277 | GSList* cur; | |||
| 278 | ||||
| 279 | // If no port is given, assume the default one. This might not be | |||
| 280 | // correct if the port is looked up from the ssh config file, but it is | |||
| 281 | // better than nothing. | |||
| 282 | if (remote_port == 0) { | |||
| 283 | remote_port = 22; | |||
| 284 | } | |||
| 285 | ||||
| 286 | if (!interfaces) { | |||
| 287 | g_string_append_printf(filter, "not port %u", remote_port); | |||
| 288 | } else { | |||
| 289 | g_string_append_printf(filter, "not ((host %s", (char*)interfaces->data); | |||
| 290 | cur = g_slist_next(interfaces)((interfaces) ? (((GSList *)(interfaces))->next) : ((void* )0)); | |||
| 291 | while (cur) { | |||
| 292 | g_string_append_printf(filter, " or host %s", (char*)cur->data); | |||
| 293 | cur = g_slist_next(cur)((cur) ? (((GSList *)(cur))->next) : ((void*)0)); | |||
| 294 | } | |||
| 295 | g_string_append_printf(filter, ") and port %u)", remote_port); | |||
| 296 | } | |||
| 297 | return g_string_free(filter, FALSE)(__builtin_constant_p ((0)) ? (((0)) ? (g_string_free) ((filter ), ((0))) : g_string_free_and_steal (filter)) : (g_string_free ) ((filter), ((0)))); | |||
| 298 | } | |||
| 299 | ||||
| 300 | static int list_config(char *interface, unsigned int remote_port) | |||
| 301 | { | |||
| 302 | unsigned inc = 0; | |||
| 303 | char* ipfilter; | |||
| 304 | ||||
| 305 | if (!interface) { | |||
| 306 | ws_warning("ERROR: No interface specified.")do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c" , 306, __func__, "ERROR: No interface specified."); } } while (0); | |||
| 307 | return EXIT_FAILURE1; | |||
| 308 | } | |||
| 309 | ||||
| 310 | if (g_strcmp0(interface, sshdump_extcap_interface)) { | |||
| 311 | ws_warning("ERROR: interface must be %s", sshdump_extcap_interface)do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c" , 311, __func__, "ERROR: interface must be %s", sshdump_extcap_interface ); } } while (0); | |||
| 312 | return EXIT_FAILURE1; | |||
| 313 | } | |||
| 314 | ||||
| 315 | ipfilter = local_interfaces_to_filter(remote_port); | |||
| 316 | ||||
| 317 | ssh_base_list_config(&inc); | |||
| 318 | ||||
| 319 | printf("arg {number=%u}{call=--remote-interface}{display=Remote interface}" | |||
| 320 | "{type=string}{tooltip=The remote network interface used for capture" | |||
| 321 | "}{group=Capture}\n", inc++); | |||
| 322 | printf("arg {number=%u}{call=--remote-capture-command-select}{display=Remote capture command selection}" | |||
| 323 | "{type=radio}{tooltip=The remote capture command to build a command line for}{group=Capture}\n", inc); | |||
| 324 | printf("value {arg=%u}{value=dumpcap}{display=dumpcap}\n", inc); | |||
| 325 | printf("value {arg=%u}{value=tcpdump}{display=tcpdump}{default=true}\n", inc); | |||
| 326 | printf("value {arg=%u}{value=other}{display=Other:}\n", inc++); | |||
| 327 | printf("arg {number=%u}{call=--remote-capture-command}{display=Remote capture command}" | |||
| 328 | "{type=string}{tooltip=The remote command used to capture}{group=Capture}\n", inc++); | |||
| 329 | // Deprecated | |||
| 330 | //printf("arg {number=%u}{call=--remote-sudo}{display=Use sudo on the remote machine}" | |||
| 331 | // "{type=boolflag}{tooltip=Prepend the capture command with sudo on the remote machine}" | |||
| 332 | // "{group=Capture}\n", inc++); | |||
| 333 | printf("arg {number=%u}{call=--remote-priv}{display=Gain capture privilege on the remote machine}" | |||
| 334 | "{type=radio}{tooltip=Optionally prepend the capture command with sudo or doas on the remote machine}" | |||
| 335 | "{group=Capture}\n", inc); | |||
| 336 | printf("value {arg=%u}{value=none}{display=none}{default=true}\n", inc); | |||
| 337 | printf("value {arg=%u}{value=sudo}{display=sudo}\n", inc); | |||
| 338 | printf("value {arg=%u}{value=doas -n}{display=doas}\n", inc++); | |||
| 339 | printf("arg {number=%u}{call=--remote-priv-user}{display=Privileged user name for sudo or doas}" | |||
| 340 | "{type=string}{tooltip=User name of privileged user to execute the capture command on the remote machine}" | |||
| 341 | "{group=Capture}\n", inc++); | |||
| 342 | printf("arg {number=%u}{call=--remote-noprom}{display=No promiscuous mode}" | |||
| 343 | "{type=boolflag}{tooltip=Don't use promiscuous mode on the remote machine}{group=Capture}" | |||
| 344 | "\n", inc++); | |||
| 345 | printf("arg {number=%u}{call=--remote-filter}{display=Remote capture filter}{type=string}" | |||
| 346 | "{tooltip=The remote capture filter}", inc++); | |||
| 347 | if (ipfilter) | |||
| 348 | printf("{default=%s}", ipfilter); | |||
| 349 | printf("{group=Capture}\n"); | |||
| 350 | printf("arg {number=%u}{call=--remote-count}{display=Packets to capture}" | |||
| 351 | "{type=unsigned}{default=0}{tooltip=The number of remote packets to capture. (Default: inf)}" | |||
| 352 | "{group=Capture}\n", inc++); | |||
| 353 | ||||
| 354 | extcap_config_debug(&inc); | |||
| 355 | ||||
| 356 | g_free(ipfilter)(__builtin_object_size ((ipfilter), 0) != ((size_t) - 1)) ? g_free_sized (ipfilter, __builtin_object_size ((ipfilter), 0)) : (g_free) (ipfilter); | |||
| 357 | ||||
| 358 | return EXIT_SUCCESS0; | |||
| 359 | } | |||
| 360 | ||||
| 361 | static char* concat_filters(const char* extcap_filter, const char* remote_filter) | |||
| 362 | { | |||
| 363 | if (!extcap_filter && remote_filter) | |||
| 364 | return g_strdup(remote_filter)g_strdup_inline (remote_filter); | |||
| 365 | ||||
| 366 | if (!remote_filter && extcap_filter) | |||
| 367 | return g_strdup(extcap_filter)g_strdup_inline (extcap_filter); | |||
| 368 | ||||
| 369 | if (!remote_filter && !extcap_filter) | |||
| 370 | return NULL((void*)0); | |||
| 371 | ||||
| 372 | return ws_strdup_printf("(%s) and (%s)", extcap_filter, remote_filter)wmem_strdup_printf(((void*)0), "(%s) and (%s)", extcap_filter , remote_filter); | |||
| 373 | } | |||
| 374 | ||||
| 375 | int main(int argc, char *argv[]) | |||
| 376 | { | |||
| 377 | char* err_msg; | |||
| 378 | int result; | |||
| 379 | int option_idx = 0; | |||
| 380 | ssh_params_t* ssh_params = ssh_params_new(); | |||
| 381 | char* remote_interface = NULL((void*)0); | |||
| 382 | char* remote_capture_command_select = NULL((void*)0); | |||
| 383 | char* remote_capture_command = NULL((void*)0); | |||
| 384 | char* remote_filter = NULL((void*)0); | |||
| 385 | uint32_t count = 0; | |||
| 386 | int ret = EXIT_FAILURE1; | |||
| 387 | extcap_parameters* extcap_conf = g_new0(extcap_parameters, 1)((extcap_parameters *) g_malloc0_n ((1), sizeof (extcap_parameters ))); | |||
| 388 | char* help_url; | |||
| 389 | char* help_header = NULL((void*)0); | |||
| 390 | char* priv = NULL((void*)0); | |||
| 391 | char* priv_user = NULL((void*)0); | |||
| 392 | bool_Bool noprom = false0; | |||
| 393 | char* interface_description = g_strdup("SSH remote capture")g_strdup_inline ("SSH remote capture"); | |||
| 394 | ||||
| 395 | /* Set the program name. */ | |||
| 396 | g_set_prgname("sshdump"); | |||
| 397 | ||||
| 398 | /* Initialize log handler early so we can have proper logging during startup. */ | |||
| 399 | extcap_log_init(); | |||
| 400 | ||||
| 401 | sshdump_extcap_interface = g_path_get_basename(argv[0]); | |||
| 402 | if (g_str_has_suffix(sshdump_extcap_interface, ".exe")(__builtin_constant_p (".exe")? __extension__ ({ const char * const __str = (sshdump_extcap_interface); const char * const __suffix = (".exe"); gboolean __result = (0); if (__str == ( (void*)0) || __suffix == ((void*)0)) __result = (g_str_has_suffix ) (__str, __suffix); else { const size_t __str_len = strlen ( ((__str) + !(__str))); const size_t __suffix_len = strlen ((( __suffix) + !(__suffix))); if (__str_len >= __suffix_len) __result = memcmp (__str + __str_len - __suffix_len, ((__suffix) + !( __suffix)), __suffix_len) == 0; } __result; }) : (g_str_has_suffix ) (sshdump_extcap_interface, ".exe") )) { | |||
| ||||
| 403 | sshdump_extcap_interface[strlen(sshdump_extcap_interface) - 4] = '\0'; | |||
| 404 | } | |||
| 405 | ||||
| 406 | /* | |||
| 407 | * Get credential information for later use. | |||
| 408 | */ | |||
| 409 | init_process_policies(); | |||
| 410 | ||||
| 411 | /* | |||
| 412 | * Attempt to get the pathname of the directory containing the | |||
| 413 | * executable file. | |||
| 414 | */ | |||
| 415 | err_msg = configuration_init(argv[0], "wireshark"); | |||
| 416 | if (err_msg != NULL((void*)0)) { | |||
| 417 | ws_warning("Can't get pathname of directory containing the extcap program: %s.",do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c" , 418, __func__, "Can't get pathname of directory containing the extcap program: %s." , err_msg); } } while (0) | |||
| 418 | err_msg)do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c" , 418, __func__, "Can't get pathname of directory containing the extcap program: %s." , err_msg); } } while (0); | |||
| 419 | g_free(err_msg)(__builtin_object_size ((err_msg), 0) != ((size_t) - 1)) ? g_free_sized (err_msg, __builtin_object_size ((err_msg), 0)) : (g_free) ( err_msg); | |||
| 420 | } | |||
| 421 | ||||
| 422 | help_url = data_file_url("sshdump.html", application_configuration_environment_prefix()); | |||
| 423 | extcap_base_set_util_info(extcap_conf, argv[0], SSHDUMP_VERSION_MAJOR"1", SSHDUMP_VERSION_MINOR"2", | |||
| 424 | SSHDUMP_VERSION_RELEASE"0", help_url); | |||
| 425 | g_free(help_url)(__builtin_object_size ((help_url), 0) != ((size_t) - 1)) ? g_free_sized (help_url, __builtin_object_size ((help_url), 0)) : (g_free) (help_url); | |||
| 426 | add_libssh_info(extcap_conf); | |||
| 427 | if (g_strcmp0(sshdump_extcap_interface, DEFAULT_SSHDUMP_EXTCAP_INTERFACE"sshdump")) { | |||
| 428 | char* temp = interface_description; | |||
| 429 | interface_description = ws_strdup_printf("%s, custom version", interface_description)wmem_strdup_printf(((void*)0), "%s, custom version", interface_description ); | |||
| 430 | g_free(temp)(__builtin_object_size ((temp), 0) != ((size_t) - 1)) ? g_free_sized (temp, __builtin_object_size ((temp), 0)) : (g_free) (temp); | |||
| 431 | } | |||
| 432 | extcap_base_register_interface(extcap_conf, sshdump_extcap_interface, interface_description, 147, "Remote capture dependent DLT"); | |||
| 433 | g_free(interface_description)(__builtin_object_size ((interface_description), 0) != ((size_t ) - 1)) ? g_free_sized (interface_description, __builtin_object_size ((interface_description), 0)) : (g_free) (interface_description ); | |||
| 434 | ||||
| 435 | help_header = ws_strdup_printf(wmem_strdup_printf(((void*)0), " %s --extcap-interfaces\n" " %s --extcap-interface=%s --extcap-dlts\n" " %s --extcap-interface=%s --extcap-config\n" " %s --extcap-interface=%s --remote-host myhost --remote-port 22222 " "--remote-username myuser --remote-interface eth2 --remote-capture-command 'tcpdump -U -i eth0 -w -' " "--fifo=FILENAME --capture\n", argv[0], argv[0], sshdump_extcap_interface , argv[0], sshdump_extcap_interface, argv[0], sshdump_extcap_interface ) | |||
| 436 | " %s --extcap-interfaces\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces\n" " %s --extcap-interface=%s --extcap-dlts\n" " %s --extcap-interface=%s --extcap-config\n" " %s --extcap-interface=%s --remote-host myhost --remote-port 22222 " "--remote-username myuser --remote-interface eth2 --remote-capture-command 'tcpdump -U -i eth0 -w -' " "--fifo=FILENAME --capture\n", argv[0], argv[0], sshdump_extcap_interface , argv[0], sshdump_extcap_interface, argv[0], sshdump_extcap_interface ) | |||
| 437 | " %s --extcap-interface=%s --extcap-dlts\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces\n" " %s --extcap-interface=%s --extcap-dlts\n" " %s --extcap-interface=%s --extcap-config\n" " %s --extcap-interface=%s --remote-host myhost --remote-port 22222 " "--remote-username myuser --remote-interface eth2 --remote-capture-command 'tcpdump -U -i eth0 -w -' " "--fifo=FILENAME --capture\n", argv[0], argv[0], sshdump_extcap_interface , argv[0], sshdump_extcap_interface, argv[0], sshdump_extcap_interface ) | |||
| 438 | " %s --extcap-interface=%s --extcap-config\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces\n" " %s --extcap-interface=%s --extcap-dlts\n" " %s --extcap-interface=%s --extcap-config\n" " %s --extcap-interface=%s --remote-host myhost --remote-port 22222 " "--remote-username myuser --remote-interface eth2 --remote-capture-command 'tcpdump -U -i eth0 -w -' " "--fifo=FILENAME --capture\n", argv[0], argv[0], sshdump_extcap_interface , argv[0], sshdump_extcap_interface, argv[0], sshdump_extcap_interface ) | |||
| 439 | " %s --extcap-interface=%s --remote-host myhost --remote-port 22222 "wmem_strdup_printf(((void*)0), " %s --extcap-interfaces\n" " %s --extcap-interface=%s --extcap-dlts\n" " %s --extcap-interface=%s --extcap-config\n" " %s --extcap-interface=%s --remote-host myhost --remote-port 22222 " "--remote-username myuser --remote-interface eth2 --remote-capture-command 'tcpdump -U -i eth0 -w -' " "--fifo=FILENAME --capture\n", argv[0], argv[0], sshdump_extcap_interface , argv[0], sshdump_extcap_interface, argv[0], sshdump_extcap_interface ) | |||
| 440 | "--remote-username myuser --remote-interface eth2 --remote-capture-command 'tcpdump -U -i eth0 -w -' "wmem_strdup_printf(((void*)0), " %s --extcap-interfaces\n" " %s --extcap-interface=%s --extcap-dlts\n" " %s --extcap-interface=%s --extcap-config\n" " %s --extcap-interface=%s --remote-host myhost --remote-port 22222 " "--remote-username myuser --remote-interface eth2 --remote-capture-command 'tcpdump -U -i eth0 -w -' " "--fifo=FILENAME --capture\n", argv[0], argv[0], sshdump_extcap_interface , argv[0], sshdump_extcap_interface, argv[0], sshdump_extcap_interface ) | |||
| 441 | "--fifo=FILENAME --capture\n", argv[0], argv[0], sshdump_extcap_interface, argv[0],wmem_strdup_printf(((void*)0), " %s --extcap-interfaces\n" " %s --extcap-interface=%s --extcap-dlts\n" " %s --extcap-interface=%s --extcap-config\n" " %s --extcap-interface=%s --remote-host myhost --remote-port 22222 " "--remote-username myuser --remote-interface eth2 --remote-capture-command 'tcpdump -U -i eth0 -w -' " "--fifo=FILENAME --capture\n", argv[0], argv[0], sshdump_extcap_interface , argv[0], sshdump_extcap_interface, argv[0], sshdump_extcap_interface ) | |||
| 442 | sshdump_extcap_interface, argv[0], sshdump_extcap_interface)wmem_strdup_printf(((void*)0), " %s --extcap-interfaces\n" " %s --extcap-interface=%s --extcap-dlts\n" " %s --extcap-interface=%s --extcap-config\n" " %s --extcap-interface=%s --remote-host myhost --remote-port 22222 " "--remote-username myuser --remote-interface eth2 --remote-capture-command 'tcpdump -U -i eth0 -w -' " "--fifo=FILENAME --capture\n", argv[0], argv[0], sshdump_extcap_interface , argv[0], sshdump_extcap_interface, argv[0], sshdump_extcap_interface ); | |||
| 443 | extcap_help_add_header(extcap_conf, help_header); | |||
| 444 | g_free(help_header)(__builtin_object_size ((help_header), 0) != ((size_t) - 1)) ? g_free_sized (help_header, __builtin_object_size ((help_header ), 0)) : (g_free) (help_header); | |||
| 445 | extcap_help_add_option(extcap_conf, "--help", "print this help"); | |||
| 446 | extcap_help_add_option(extcap_conf, "--version", "print the version"); | |||
| 447 | ssh_base_add_help_options(extcap_conf); | |||
| 448 | extcap_help_add_option(extcap_conf, "--remote-interface <iface>", "the remote capture interface"); | |||
| 449 | extcap_help_add_option(extcap_conf, "--remote-capture-command-select <selection>", "dumpcap, tcpdump or other remote capture command"); | |||
| 450 | extcap_help_add_option(extcap_conf, "--remote-capture-command <capture command>", "the remote capture command"); | |||
| 451 | //extcap_help_add_option(extcap_conf, "--remote-sudo", "use sudo on the remote machine to capture"); // Deprecated | |||
| 452 | extcap_help_add_option(extcap_conf, "--remote-priv <selection>", "none, sudo or doas"); | |||
| 453 | extcap_help_add_option(extcap_conf, "--remote-priv-user <username>", "privileged user name"); | |||
| 454 | extcap_help_add_option(extcap_conf, "--remote-noprom", "don't use promiscuous mode on the remote machine"); | |||
| 455 | extcap_help_add_option(extcap_conf, "--remote-filter <filter>", "a filter for remote capture (default: don't listen on local interfaces IPs)"); | |||
| 456 | extcap_help_add_option(extcap_conf, "--remote-count <count>", "the number of packets to capture"); | |||
| 457 | ||||
| 458 | ws_opterr = 0; | |||
| 459 | ws_optind = 0; | |||
| 460 | ||||
| 461 | if (argc == 1) { | |||
| 462 | extcap_help_print(extcap_conf); | |||
| 463 | goto end; | |||
| 464 | } | |||
| 465 | ||||
| 466 | while ((result = ws_getopt_long(argc, argv, ":", longopts, &option_idx)) != -1) { | |||
| 467 | ||||
| 468 | switch (result) { | |||
| 469 | ||||
| 470 | case OPT_HELP: | |||
| 471 | extcap_help_print(extcap_conf); | |||
| 472 | ret = EXIT_SUCCESS0; | |||
| 473 | goto end; | |||
| 474 | ||||
| 475 | case OPT_VERSION: | |||
| 476 | extcap_version_print(extcap_conf); | |||
| 477 | ret = EXIT_SUCCESS0; | |||
| 478 | goto end; | |||
| 479 | ||||
| 480 | case OPT_REMOTE_HOST: | |||
| 481 | g_free(ssh_params->host)(__builtin_object_size ((ssh_params->host), 0) != ((size_t ) - 1)) ? g_free_sized (ssh_params->host, __builtin_object_size ((ssh_params->host), 0)) : (g_free) (ssh_params->host); | |||
| 482 | ssh_params->host = g_strdup(ws_optarg)g_strdup_inline (ws_optarg); | |||
| 483 | break; | |||
| 484 | ||||
| 485 | case OPT_REMOTE_PORT: | |||
| 486 | if (!ws_strtou16(ws_optarg, NULL((void*)0), &ssh_params->port) || ssh_params->port == 0) { | |||
| 487 | ws_warning("Invalid port: %s", ws_optarg)do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c" , 487, __func__, "Invalid port: %s", ws_optarg); } } while (0 ); | |||
| 488 | goto end; | |||
| 489 | } | |||
| 490 | break; | |||
| 491 | ||||
| 492 | case OPT_REMOTE_USERNAME: | |||
| 493 | g_free(ssh_params->username)(__builtin_object_size ((ssh_params->username), 0) != ((size_t ) - 1)) ? g_free_sized (ssh_params->username, __builtin_object_size ((ssh_params->username), 0)) : (g_free) (ssh_params->username ); | |||
| 494 | ssh_params->username = g_strdup(ws_optarg)g_strdup_inline (ws_optarg); | |||
| 495 | break; | |||
| 496 | ||||
| 497 | case OPT_REMOTE_PASSWORD: | |||
| 498 | g_free(ssh_params->password)(__builtin_object_size ((ssh_params->password), 0) != ((size_t ) - 1)) ? g_free_sized (ssh_params->password, __builtin_object_size ((ssh_params->password), 0)) : (g_free) (ssh_params->password ); | |||
| 499 | ssh_params->password = g_strdup(ws_optarg)g_strdup_inline (ws_optarg); | |||
| 500 | memset(ws_optarg, 'X', strlen(ws_optarg)); | |||
| 501 | break; | |||
| 502 | ||||
| 503 | case OPT_SSHKEY: | |||
| 504 | g_free(ssh_params->sshkey_path)(__builtin_object_size ((ssh_params->sshkey_path), 0) != ( (size_t) - 1)) ? g_free_sized (ssh_params->sshkey_path, __builtin_object_size ((ssh_params->sshkey_path), 0)) : (g_free) (ssh_params-> sshkey_path); | |||
| 505 | ssh_params->sshkey_path = g_strdup(ws_optarg)g_strdup_inline (ws_optarg); | |||
| 506 | break; | |||
| 507 | ||||
| 508 | case OPT_SSHKEY_PASSPHRASE: | |||
| 509 | g_free(ssh_params->sshkey_passphrase)(__builtin_object_size ((ssh_params->sshkey_passphrase), 0 ) != ((size_t) - 1)) ? g_free_sized (ssh_params->sshkey_passphrase , __builtin_object_size ((ssh_params->sshkey_passphrase), 0 )) : (g_free) (ssh_params->sshkey_passphrase); | |||
| 510 | ssh_params->sshkey_passphrase = g_strdup(ws_optarg)g_strdup_inline (ws_optarg); | |||
| 511 | memset(ws_optarg, 'X', strlen(ws_optarg)); | |||
| 512 | break; | |||
| 513 | ||||
| 514 | case OPT_PROXYCOMMAND: | |||
| 515 | g_free(ssh_params->proxycommand)(__builtin_object_size ((ssh_params->proxycommand), 0) != ( (size_t) - 1)) ? g_free_sized (ssh_params->proxycommand, __builtin_object_size ((ssh_params->proxycommand), 0)) : (g_free) (ssh_params-> proxycommand); | |||
| 516 | ssh_params->proxycommand = g_strdup(ws_optarg)g_strdup_inline (ws_optarg); | |||
| 517 | break; | |||
| 518 | ||||
| 519 | case OPT_SSH_SHA1: | |||
| 520 | ssh_params->ssh_sha1 = true1; | |||
| 521 | break; | |||
| 522 | ||||
| 523 | case OPT_UPDATE_KNOWN_HOSTS: | |||
| 524 | ssh_params->update_known_hosts = true1; | |||
| 525 | break; | |||
| 526 | ||||
| 527 | case OPT_REMOTE_INTERFACE: | |||
| 528 | g_free(remote_interface)(__builtin_object_size ((remote_interface), 0) != ((size_t) - 1)) ? g_free_sized (remote_interface, __builtin_object_size ( (remote_interface), 0)) : (g_free) (remote_interface); | |||
| 529 | remote_interface = g_strdup(ws_optarg)g_strdup_inline (ws_optarg); | |||
| 530 | break; | |||
| 531 | ||||
| 532 | case OPT_REMOTE_CAPTURE_COMMAND_SELECT: | |||
| 533 | g_free(remote_capture_command_select)(__builtin_object_size ((remote_capture_command_select), 0) != ((size_t) - 1)) ? g_free_sized (remote_capture_command_select , __builtin_object_size ((remote_capture_command_select), 0)) : (g_free) (remote_capture_command_select); | |||
| 534 | remote_capture_command_select = g_strdup(ws_optarg)g_strdup_inline (ws_optarg); | |||
| 535 | break; | |||
| 536 | ||||
| 537 | case OPT_REMOTE_CAPTURE_COMMAND: | |||
| 538 | g_free(remote_capture_command)(__builtin_object_size ((remote_capture_command), 0) != ((size_t ) - 1)) ? g_free_sized (remote_capture_command, __builtin_object_size ((remote_capture_command), 0)) : (g_free) (remote_capture_command ); | |||
| 539 | remote_capture_command = g_strdup(ws_optarg)g_strdup_inline (ws_optarg); | |||
| 540 | break; | |||
| 541 | ||||
| 542 | case OPT_REMOTE_SUDO: | |||
| 543 | // Deprecated | |||
| 544 | g_free(priv)(__builtin_object_size ((priv), 0) != ((size_t) - 1)) ? g_free_sized (priv, __builtin_object_size ((priv), 0)) : (g_free) (priv); | |||
| 545 | priv = g_strdup("sudo")g_strdup_inline ("sudo"); | |||
| 546 | break; | |||
| 547 | ||||
| 548 | case OPT_REMOTE_PRIV: | |||
| 549 | g_free(priv)(__builtin_object_size ((priv), 0) != ((size_t) - 1)) ? g_free_sized (priv, __builtin_object_size ((priv), 0)) : (g_free) (priv); | |||
| 550 | priv = g_strdup(ws_optarg)g_strdup_inline (ws_optarg); | |||
| 551 | break; | |||
| 552 | ||||
| 553 | case OPT_REMOTE_PRIV_USER: | |||
| 554 | g_free(priv_user)(__builtin_object_size ((priv_user), 0) != ((size_t) - 1)) ? g_free_sized (priv_user, __builtin_object_size ((priv_user), 0)) : (g_free ) (priv_user); | |||
| 555 | priv_user = g_strdup(ws_optarg)g_strdup_inline (ws_optarg); | |||
| 556 | break; | |||
| 557 | ||||
| 558 | case OPT_REMOTE_FILTER: | |||
| 559 | g_free(remote_filter)(__builtin_object_size ((remote_filter), 0) != ((size_t) - 1) ) ? g_free_sized (remote_filter, __builtin_object_size ((remote_filter ), 0)) : (g_free) (remote_filter); | |||
| 560 | remote_filter = g_strdup(ws_optarg)g_strdup_inline (ws_optarg); | |||
| 561 | break; | |||
| 562 | ||||
| 563 | case OPT_REMOTE_COUNT: | |||
| 564 | if (!ws_strtou32(ws_optarg, NULL((void*)0), &count)) { | |||
| 565 | ws_warning("Invalid value for count: %s", ws_optarg)do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c" , 565, __func__, "Invalid value for count: %s", ws_optarg); } } while (0); | |||
| 566 | goto end; | |||
| 567 | } | |||
| 568 | break; | |||
| 569 | ||||
| 570 | case OPT_REMOTE_NOPROM: | |||
| 571 | noprom = true1; | |||
| 572 | break; | |||
| 573 | ||||
| 574 | case ':': | |||
| 575 | /* missing option argument */ | |||
| 576 | ws_warning("Option '%s' requires an argument", argv[ws_optind - 1])do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c" , 576, __func__, "Option '%s' requires an argument", argv[ws_optind - 1]); } } while (0); | |||
| 577 | break; | |||
| 578 | ||||
| 579 | default: | |||
| 580 | if (!extcap_base_parse_options(extcap_conf, result - EXTCAP_OPT_LIST_INTERFACES, ws_optarg)) { | |||
| 581 | ws_warning("Invalid option: %s", argv[ws_optind - 1])do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c" , 581, __func__, "Invalid option: %s", argv[ws_optind - 1]); } } while (0); | |||
| 582 | goto end; | |||
| 583 | } | |||
| 584 | } | |||
| 585 | } | |||
| 586 | ||||
| 587 | extcap_cmdline_debug(argv, argc); | |||
| 588 | ||||
| 589 | if (extcap_base_handle_interface(extcap_conf)) { | |||
| 590 | ret = EXIT_SUCCESS0; | |||
| 591 | goto end; | |||
| 592 | } | |||
| 593 | ||||
| 594 | if (extcap_conf->show_config) { | |||
| 595 | ret = list_config(extcap_conf->interface, ssh_params->port); | |||
| 596 | goto end; | |||
| 597 | } | |||
| 598 | ||||
| 599 | err_msg = ws_init_sockets(); | |||
| 600 | if (err_msg != NULL((void*)0)) { | |||
| 601 | ws_warning("ERROR: %s", err_msg)do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c" , 601, __func__, "ERROR: %s", err_msg); } } while (0); | |||
| 602 | g_free(err_msg)(__builtin_object_size ((err_msg), 0) != ((size_t) - 1)) ? g_free_sized (err_msg, __builtin_object_size ((err_msg), 0)) : (g_free) ( err_msg); | |||
| 603 | ws_warning("%s", please_report_bug())do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c" , 603, __func__, "%s", please_report_bug()); } } while (0); | |||
| 604 | goto end; | |||
| 605 | } | |||
| 606 | ||||
| 607 | if (extcap_conf->capture) { | |||
| 608 | char* filter; | |||
| 609 | char* privilege; | |||
| 610 | ||||
| 611 | if (!ssh_params->host) { | |||
| 612 | ws_warning("Missing parameter: --remote-host")do { if (1) { ws_log_full("sshdump", LOG_LEVEL_WARNING, "extcap/sshdump.c" , 612, __func__, "Missing parameter: --remote-host"); } } while (0); | |||
| 613 | goto end; | |||
| 614 | } | |||
| 615 | ||||
| 616 | if ((priv
| |||
| 617 | if ((priv_user) && strlen(g_strstrip(priv_user)g_strchomp (g_strchug (priv_user)))) | |||
| 618 | /* Both sudo and doas use the same command line option */ | |||
| 619 | privilege = g_strconcat(priv, " -u ", priv_user, NULL((void*)0)); | |||
| 620 | else | |||
| 621 | privilege = g_strdup(priv)g_strdup_inline (priv); | |||
| 622 | } else { | |||
| 623 | privilege = g_strdup("")g_strdup_inline (""); | |||
| 624 | } | |||
| 625 | ||||
| 626 | // This may result in the use of a different port number than was given in | |||
| 627 | // the default filter string, as presented in the config dialog. The default | |||
| 628 | // given is always using the default SSH port since there's no remote SSH port | |||
| 629 | // given on the command line to get the extcap arguments. | |||
| 630 | // However the remote SSH port used here is the one given on the command line | |||
| 631 | // when the capture us started, which is the intended one. | |||
| 632 | // And this is only happening when no remote filter is specified on the command | |||
| 633 | // line to start the capture. | |||
| 634 | if (remote_filter
| |||
| 635 | remote_filter = local_interfaces_to_filter(ssh_params->port); | |||
| 636 | filter = concat_filters(extcap_conf->capture_filter, remote_filter); | |||
| 637 | ssh_params_set_log_level(ssh_params, extcap_conf->debug); | |||
| 638 | ret = ssh_open_remote_connection(ssh_params, remote_interface, | |||
| 639 | filter, remote_capture_command_select, remote_capture_command, | |||
| 640 | privilege, noprom, count, extcap_conf->fifo); | |||
| 641 | g_free(filter)(__builtin_object_size ((filter), 0) != ((size_t) - 1)) ? g_free_sized (filter, __builtin_object_size ((filter), 0)) : (g_free) (filter ); | |||
| 642 | g_free(privilege)(__builtin_object_size ((privilege), 0) != ((size_t) - 1)) ? g_free_sized (privilege, __builtin_object_size ((privilege), 0)) : (g_free ) (privilege); | |||
| 643 | } else { | |||
| 644 | ws_debug("You should not come here... maybe some parameter missing?")do { if (1) { ws_log_full("sshdump", LOG_LEVEL_DEBUG, "extcap/sshdump.c" , 644, __func__, "You should not come here... maybe some parameter missing?" ); } } while (0); | |||
| 645 | ret = EXIT_FAILURE1; | |||
| 646 | } | |||
| 647 | ||||
| 648 | end: | |||
| 649 | /* clean up stuff */ | |||
| 650 | ssh_params_free(ssh_params); | |||
| 651 | g_free(remote_capture_command_select)(__builtin_object_size ((remote_capture_command_select), 0) != ((size_t) - 1)) ? g_free_sized (remote_capture_command_select , __builtin_object_size ((remote_capture_command_select), 0)) : (g_free) (remote_capture_command_select); | |||
| 652 | g_free(remote_capture_command)(__builtin_object_size ((remote_capture_command), 0) != ((size_t ) - 1)) ? g_free_sized (remote_capture_command, __builtin_object_size ((remote_capture_command), 0)) : (g_free) (remote_capture_command ); | |||
| 653 | g_free(remote_interface)(__builtin_object_size ((remote_interface), 0) != ((size_t) - 1)) ? g_free_sized (remote_interface, __builtin_object_size ( (remote_interface), 0)) : (g_free) (remote_interface); | |||
| 654 | g_free(remote_filter)(__builtin_object_size ((remote_filter), 0) != ((size_t) - 1) ) ? g_free_sized (remote_filter, __builtin_object_size ((remote_filter ), 0)) : (g_free) (remote_filter); | |||
| 655 | g_free(priv)(__builtin_object_size ((priv), 0) != ((size_t) - 1)) ? g_free_sized (priv, __builtin_object_size ((priv), 0)) : (g_free) (priv); | |||
| 656 | g_free(priv_user)(__builtin_object_size ((priv_user), 0) != ((size_t) - 1)) ? g_free_sized (priv_user, __builtin_object_size ((priv_user), 0)) : (g_free ) (priv_user); | |||
| 657 | extcap_base_cleanup(&extcap_conf); | |||
| 658 | return ret; | |||
| 659 | } | |||
| 660 | ||||
| 661 | /* | |||
| 662 | * Editor modelines - https://www.wireshark.org/tools/modelines.html | |||
| 663 | * | |||
| 664 | * Local variables: | |||
| 665 | * c-basic-offset: 8 | |||
| 666 | * tab-width: 8 | |||
| 667 | * indent-tabs-mode: t | |||
| 668 | * End: | |||
| 669 | * | |||
| 670 | * vi: set shiftwidth=8 tabstop=8 noexpandtab: | |||
| 671 | * :indentSize=8:tabSize=8:noTabs=false: | |||
| 672 | */ |