Bugzilla – Attachment 1701 Details for
Bug 1661
netcat feature
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
adds new option "-Ghost:port" that is equivalent to running "ssh nc host port"
openssh-netcat.patch (text/plain), 4.47 KB, created by
Salvador Fandiño
on 2009-10-21 10:32:55 AEDT
(
hide
)
Description:
adds new option "-Ghost:port" that is equivalent to running "ssh nc host port"
Filename:
MIME Type:
Creator:
Salvador Fandiño
Created:
2009-10-21 10:32:55 AEDT
Size:
4.47 KB
patch
obsolete
>diff --git a/channels.c b/channels.c >index 56047f3..70ed68d 100644 >--- a/channels.c >+++ b/channels.c >@@ -1314,16 +1314,27 @@ port_open_helper(Channel *c, char *rtype) > { > int direct; > char buf[1024]; >- char *remote_ipaddr = get_peer_ipaddr(c->sock); >- int remote_port = get_peer_port(c->sock); >+ char *remote_ipaddr; >+ int remote_port; > > direct = (strcmp(rtype, "direct-tcpip") == 0); > >- snprintf(buf, sizeof buf, >- "%s: listening port %d for %.100s port %d, " >- "connect from %.200s port %d", >- rtype, c->listening_port, c->path, c->host_port, >- remote_ipaddr, remote_port); >+ if (c->sock != -1) { >+ remote_ipaddr = get_peer_ipaddr(c->sock); >+ remote_port = get_peer_port(c->sock); >+ snprintf(buf, sizeof buf, >+ "%s: listening port %d for %.100s port %d, " >+ "connect from %.200s port %d", >+ rtype, c->listening_port, c->path, c->host_port, >+ remote_ipaddr, remote_port); >+ >+ } else { >+ remote_ipaddr = xstrdup("-"); >+ remote_port = 0; >+ snprintf(buf, sizeof buf, >+ "%s: to %.100s port %d, from stdio", >+ rtype, c->path, c->host_port); >+ } > > xfree(c->remote_name); > c->remote_name = xstrdup(buf); >@@ -2712,6 +2723,24 @@ channel_request_remote_forwarding(const char *listen_host, u_short listen_port, > } > > /* >+ * Forward stdio to remote TCP port >+ */ >+int >+channel_setup_netcat(const char *host, u_short port, int rfd, int wfd) { >+ char *rtype = "direct-tcpip"; >+ Channel *c; >+ c = channel_new(rtype, SSH_CHANNEL_OPENING, rfd, wfd, -1, >+ CHAN_TCP_WINDOW_DEFAULT, CHAN_TCP_PACKET_DEFAULT, >+ 0, rtype, 0); >+ c->listening_port = 0; >+ c->host_port = port; >+ c->path = xstrdup(host); >+ c->force_drain = 1; >+ port_open_helper(c, rtype); >+ return c->self; >+} >+ >+/* > * Request cancellation of remote forwarding of connection host:port from > * local side. > */ >diff --git a/channels.h b/channels.h >index 3800b2d..f564546 100644 >--- a/channels.h >+++ b/channels.h >@@ -246,6 +246,7 @@ int channel_setup_local_fwd_listener(const char *, u_short, > void channel_request_rforward_cancel(const char *host, u_short port); > int channel_setup_remote_fwd_listener(const char *, u_short, int *, int); > int channel_cancel_rport_listener(const char *, u_short); >+int channel_setup_netcat(const char *, u_short, int, int); > > /* x11 forwarding */ > >diff --git a/ssh.c b/ssh.c >index eb46cfd..a365d0f 100644 >--- a/ssh.c >+++ b/ssh.c >@@ -165,6 +165,9 @@ pid_t proxy_command_pid = 0; > extern int muxserver_sock; > extern u_int muxclient_command; > >+/* netcat */ >+static char *netcat_host; >+static int netcat_port; > > /* Prints a help message to the user. This function never returns. */ > >@@ -261,7 +264,7 @@ main(int ac, char **av) > argv0 = av[0]; > > again: >- while ((opt = getopt(ac, av, "1246ab:c:e:fgi:kl:m:no:p:qstvx" >+ while ((opt = getopt(ac, av, "1246ab:c:e:fgG:i:kl:m:no:p:qstvx" > "ACD:F:I:KL:MNO:PR:S:TVw:XYy")) != -1) { > switch (opt) { > case '1': >@@ -299,6 +302,23 @@ main(int ac, char **av) > case 'g': > options.gateway_ports = 1; > break; >+ case 'G': >+ if (parse_forward(&fwd, optarg, 1, 0)) { >+ no_shell_flag = 1; >+ no_tty_flag = 1; >+ >+ netcat_port = fwd.listen_port; >+ netcat_host = fwd.listen_host; >+ if (!netcat_host) >+ netcat_host = "localhost"; >+ } >+ else { >+ fprintf(stderr, >+ "Bad remote address specification " >+ "'%s'\n", optarg); >+ exit(255); >+ } >+ break; > case 'O': > if (strcmp(optarg, "check") == 0) > muxclient_command = SSHMUX_COMMAND_ALIVE_CHECK; >@@ -799,6 +819,9 @@ main(int ac, char **av) > } > } > >+ if (netcat_host && !compat20) >+ fatal("netcat feature not available for SSH1 connections"); >+ > exit_status = compat20 ? ssh_session2() : ssh_session(); > packet_close(); > >@@ -1168,6 +1191,28 @@ ssh_session2_open(void) > } > > static int >+ssh_netcat_open(void) { >+ int in, out, id; >+ >+ in = (stdin_null_flag ? open(_PATH_DEVNULL, O_RDONLY) : dup(STDIN_FILENO)); >+ out = dup(STDOUT_FILENO); >+ >+ if (in < 0 || out < 0) >+ fatal("dup() in/out failed"); >+ >+ if (!isatty(in)) >+ set_nonblock(in); >+ if (!isatty(out)) >+ set_nonblock(out); >+ >+ id = channel_setup_netcat(netcat_host, netcat_port, in, out); >+ >+ debug3("ssh_netcat_open: channel_new: %d", id); >+ >+ return id; >+} >+ >+static int > ssh_session2(void) > { > int id = -1; >@@ -1177,6 +1222,8 @@ ssh_session2(void) > > if (!no_shell_flag || (datafellows & SSH_BUG_DUMMYCHAN)) > id = ssh_session2_open(); >+ if (netcat_host) >+ id = ssh_netcat_open(); > > /* If we don't expect to open a new session, then disallow it */ > if (options.control_master == SSHCTL_MASTER_NO &&
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 1661
: 1701