Beispiel #1
0
static int ssh_open_remote_connection(const char* hostname, const unsigned int port, const char* username, const char* password,
	const char* sshkey, const char* sshkey_passphrase, const char* iface, const char* cfilter,
	const guint32 count, const char* fifo)
{
	ssh_session sshs;
	ssh_channel channel;
	FILE* fp = stdout;
	guint64 bytes_written = 0;
	int err;
	int ret = EXIT_FAILURE;
	char* err_info = NULL;

	if (g_strcmp0(fifo, "-")) {
		/* Open or create the output file */
		fp = fopen(fifo, "w");
		if (!fp) {
			g_warning("Error creating output file: %s", g_strerror(errno));
			return EXIT_FAILURE;
		}
	}

	sshs = create_ssh_connection(hostname, port, username, password, sshkey, sshkey_passphrase, &err_info);
	if (!sshs) {
		g_warning("Error creating connection: %s", err_info);
		goto cleanup;
	}

	if (!libpcap_write_file_header(fp, 1, PCAP_SNAPLEN, FALSE, &bytes_written, &err)) {
		g_warning("Can't write pcap file header");
		goto cleanup;
	}

	channel = run_capture(sshs, iface, cfilter, count);
	if (!channel) {
		ret = EXIT_FAILURE;
		goto cleanup;
	}

	/* read from channel and write into fp */
	ssh_loop_read(channel, fp, count);

	/* clean up and exit */
	ciscodump_cleanup(sshs, channel, iface, cfilter);

	ret = EXIT_SUCCESS;
cleanup:
	if (fp != stdout)
		fclose(fp);

	return ret;
}
Beispiel #2
0
static int ssh_open_remote_connection(const char* hostname, const unsigned int port, const char* username, const char* password,
	const char* sshkey, const char* sshkey_passphrase, const char* iface, const char* cfilter, const char* capture_bin,
	const unsigned long int count, const char* fifo)
{
	ssh_session sshs = NULL;
	ssh_channel channel = NULL;
	int fd = STDOUT_FILENO;
	int ret = EXIT_FAILURE;
	char* err_info = NULL;

	if (g_strcmp0(fifo, "-")) {
		/* Open or create the output file */
		fd = ws_open(fifo, O_WRONLY, 0640);
		if (fd == -1) {
			fd = ws_open(fifo, O_WRONLY | O_CREAT, 0640);
			if (fd == -1) {
				errmsg_print("Error creating output file: %s", g_strerror(errno));
				return EXIT_FAILURE;
			}
		}
	}

	sshs = create_ssh_connection(hostname, port, username, password, sshkey, sshkey_passphrase, &err_info);

	if (!sshs) {
		errmsg_print("Error creating connection: %s", err_info);
		goto cleanup;
	}

	channel = run_ssh_command(sshs, capture_bin, iface, cfilter, count);
	if (!channel)
		goto cleanup;

	/* read from channel and write into fd */
	ssh_loop_read(channel, fd);

	ret = EXIT_SUCCESS;
cleanup:
	if (err_info)
		errmsg_print("%s", err_info);
	g_free(err_info);

	/* clean up and exit */
	ssh_cleanup(&sshs, &channel);

	if (g_strcmp0(fifo, "-"))
		ws_close(fd);
	return ret;
}
Beispiel #3
0
static int ssh_open_remote_connection(const char* hostname, const unsigned int port, const char* username, const char* password,
	const char* sshkey, const char* sshkey_passphrase, const char* iface, const char* cfilter, const char* capture_bin,
	const unsigned long int count, const char* fifo)
{
	ssh_session sshs;
	ssh_channel channel;
	int fd;

	if (!g_strcmp0(fifo, "-")) {
		/* use stdout */
		fd = STDOUT_FILENO;
	} else {
		/* Open or create the output file */
		fd = open(fifo, O_WRONLY);
		if (fd == -1) {
			fd = open(fifo, O_WRONLY | O_CREAT, 0640);
			if (fd == -1) {
				errmsg_print("Error creating output file: %s\n", g_strerror(errno));
				return EXIT_FAILURE;
			}
		}
	}

	sshs = create_ssh_connection(hostname, port, username, password, sshkey, sshkey_passphrase);

	if (!sshs)
		return EXIT_FAILURE;

	channel = run_ssh_command(sshs, capture_bin, iface, cfilter, count);
	if (!channel)
		return EXIT_FAILURE;

	/* read from channel and write into fd */
	ssh_loop_read(channel, fd);

	/* clean up and exit */
	ssh_cleanup(sshs, channel);

	return EXIT_SUCCESS;
}