| 1 |
- analysis of ssh connections for callback |
| 2 |
SSH_CLIENT='::1 38502 22' |
| 3 |
SSH_CONNECTION='::1 38502 ::1 22' |
| 4 |
|
| 5 |
-> callback possible to source host |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
[ target host ] <--------------| |
| 10 |
| | |
| 11 |
| | |
| 12 |
| | |
| 13 |
| trigger | configuration |
| 14 |
| | |
| 15 |
v | |
| 16 |
[ configuration host ] ----| |
| 17 |
|
| 18 |
|
| 19 |
- dynamic port allocation for tunneling |
| 20 |
|
| 21 |
[1:37] bento:~% ssh -R 0:localhost:22 localhost |
| 22 |
Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts. |
| 23 |
Allocated port 53161 for remote forward to localhost:22 |
| 24 |
|
| 25 |
SSH_AUTH_SOCK=/tmp/ssh-zDCWbUVcUK/agent.30749 |
| 26 |
SSH_CLIENT='::1 38587 22' |
| 27 |
SSH_CONNECTION='::1 38587 ::1 22' |
| 28 |
SSH_TTY=/dev/pts/21 |
| 29 |
|
| 30 |
|
| 31 |
- ssh_config: |
| 32 |
DynamicForward |
| 33 |
LocalForward |
| 34 |
RemoteForward |
| 35 |
|
| 36 |
- testing |
| 37 |
|
| 38 |
[1:52] bento:cdist% netstat -anp | grep 56844 |
| 39 |
(Not all processes could be identified, non-owned process info |
| 40 |
will not be shown, you would have to be root to see it all.) |
| 41 |
tcp 0 0 127.0.0.1:56844 0.0.0.0:* LISTEN - |
| 42 |
tcp6 0 0 ::1:56844 :::* LISTEN - |
| 43 |
[1:53] bento:cdist% |
| 44 |
|
| 45 |
|
| 46 |
[1:48] bento:~% ssh -R 0:localhost:22 localhost |
| 47 |
Allocated port 56844 for remote forward to localhost:22 |
| 48 |
... |
| 49 |
|
| 50 |
- chatting |
| 51 |
|
| 52 |
01:42 -!- Irssi: Join to #openssh was synced in 0 secs |
| 53 |
01:42 < telmich> good evening |
| 54 |
01:43 < telmich> I am trying to make use of remote port forwarding using dynamic port |
| 55 |
allocation (port=0) -- I am wondering if there is an easy way to |
| 56 |
access the port number on the remote side easily? |
| 57 |
01:44 < telmich> background for this question is: I'd like to allow various clients to |
| 58 |
login to a configuration server, which then configures the clients by |
| 59 |
using the tunnel the client provides for the server to ssh back into |
| 60 |
02:07 < BasketCase> telmich: afaik you need to use a tool like ss/netstat/lsof to see what port it has open |
| 61 |
|
| 62 |
- ssh debug |
| 63 |
|
| 64 |
[11:37] bento:~% ssh -R 0:localhost:22 localhost |
| 65 |
Allocated port 33562 for remote forward to localhost:22 |
| 66 |
|
| 67 |
.. . .x+=:. s |
| 68 |
dF @88> z` ^% :8 |
| 69 |
'88bu. %8P . <k .88 |
| 70 |
. '*88888bu . .@8Ned8" :888ooo |
| 71 |
.udR88N ^"*8888N .@88u .@^%8888" -*8888888 |
| 72 |
<888'888k beWE "888L ''888E` x88: `)8b. 8888 |
| 73 |
9888 'Y" 888E 888E 888E 8888N=*8888 8888 |
| 74 |
9888 888E 888E 888E %8" R88 8888 |
| 75 |
9888 888E 888F 888E @8Wou 9% .8888Lu= |
| 76 |
?8888u../ .888N..888 888& .888888P` ^%888* |
| 77 |
"8888P' `"888*"" R888" ` ^"F 'Y" |
| 78 |
"P' "" "" |
| 79 |
|
| 80 |
Welcome to a cdist automated system! |
| 81 |
|
| 82 |
Last login: Sat May 4 01:52:46 2013 from localhost.localdomain |
| 83 |
debug1: PAM: reinitializing credentials |
| 84 |
debug1: permanently_set_uid: 0/0 |
| 85 |
Environment: |
| 86 |
USER=root |
| 87 |
LOGNAME=root |
| 88 |
HOME=/root |
| 89 |
PATH=/usr/bin:/bin:/usr/sbin:/sbin |
| 90 |
MAIL=/var/spool/mail/root |
| 91 |
SHELL=/bin/bash |
| 92 |
SSH_CLIENT=::1 57848 22 |
| 93 |
SSH_CONNECTION=::1 57848 ::1 22 |
| 94 |
SSH_TTY=/dev/pts/32 |
| 95 |
TERM=rxvt-unicode |
| 96 |
XDG_SESSION_ID=1 |
| 97 |
XDG_RUNTIME_DIR=/run/user/1000 |
| 98 |
XDG_SEAT=seat0 |
| 99 |
XDG_VTNR=1 |
| 100 |
SSH_AUTH_SOCK=/tmp/ssh-6j0elukLHA/agent.17260 |
| 101 |
[root@bento ~]# |
| 102 |
[root@bento nico]# /usr/sbin/sshd -D -d |
| 103 |
debug1: sshd version OpenSSH_6.2, OpenSSL 1.0.1e 11 Feb 2013 |
| 104 |
debug1: read PEM private key done: type RSA |
| 105 |
debug1: private host key: #0 type 1 RSA |
| 106 |
debug1: read PEM private key done: type DSA |
| 107 |
debug1: private host key: #1 type 2 DSA |
| 108 |
debug1: read PEM private key done: type ECDSA |
| 109 |
debug1: private host key: #2 type 3 ECDSA |
| 110 |
debug1: rexec_argv[0]='/usr/sbin/sshd' |
| 111 |
debug1: rexec_argv[1]='-D' |
| 112 |
debug1: rexec_argv[2]='-d' |
| 113 |
Set /proc/self/oom_score_adj from 0 to -1000 |
| 114 |
debug1: Bind to port 22 on 0.0.0.0. |
| 115 |
Server listening on 0.0.0.0 port 22. |
| 116 |
debug1: Bind to port 22 on ::. |
| 117 |
Server listening on :: port 22. |
| 118 |
debug1: Server will not fork when running in debugging mode. |
| 119 |
debug1: rexec start in 5 out 5 newsock 5 pipe -1 sock 8 |
| 120 |
debug1: inetd sockets after dupping: 3, 3 |
| 121 |
Connection from ::1 port 57848 |
| 122 |
debug1: Client protocol version 2.0; client software version OpenSSH_6.2 |
| 123 |
debug1: match: OpenSSH_6.2 pat OpenSSH* |
| 124 |
debug1: Enabling compatibility mode for protocol 2.0 |
| 125 |
debug1: Local version string SSH-2.0-OpenSSH_6.2 |
| 126 |
debug1: permanently_set_uid: 99/99 [preauth] |
| 127 |
debug1: list_hostkey_types: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256 [preauth] |
| 128 |
debug1: SSH2_MSG_KEXINIT sent [preauth] |
| 129 |
debug1: SSH2_MSG_KEXINIT received [preauth] |
| 130 |
debug1: kex: client->server aes128-ctr [email protected] [email protected] [preauth] |
| 131 |
debug1: kex: server->client aes128-ctr [email protected] [email protected] [preauth] |
| 132 |
debug1: expecting SSH2_MSG_KEX_ECDH_INIT [preauth] |
| 133 |
debug1: SSH2_MSG_NEWKEYS sent [preauth] |
| 134 |
debug1: expecting SSH2_MSG_NEWKEYS [preauth] |
| 135 |
debug1: SSH2_MSG_NEWKEYS received [preauth] |
| 136 |
debug1: KEX done [preauth] |
| 137 |
debug1: userauth-request for user root service ssh-connection method none [preauth] |
| 138 |
debug1: attempt 0 failures 0 [preauth] |
| 139 |
debug1: PAM: initializing for "root" |
| 140 |
debug1: PAM: setting PAM_RHOST to "localhost.localdomain" |
| 141 |
debug1: PAM: setting PAM_TTY to "ssh" |
| 142 |
debug1: userauth-request for user root service ssh-connection method publickey [preauth] |
| 143 |
debug1: attempt 1 failures 0 [preauth] |
| 144 |
debug1: test whether pkalg/pkblob are acceptable [preauth] |
| 145 |
debug1: temporarily_use_uid: 0/0 (e=0/0) |
| 146 |
debug1: trying public key file /root/.ssh/authorized_keys |
| 147 |
debug1: fd 4 clearing O_NONBLOCK |
| 148 |
debug1: matching key found: file /root/.ssh/authorized_keys, line 2 |
| 149 |
Found matching RSA key: 2e:1b:3f:10:01:1d:21:6c:6c:1e:3d:a9:33:ba:3c:f7 |
| 150 |
debug1: restore_uid: 0/0 |
| 151 |
Postponed publickey for root from ::1 port 57848 ssh2 [preauth] |
| 152 |
debug1: userauth-request for user root service ssh-connection method publickey [preauth] |
| 153 |
debug1: attempt 2 failures 0 [preauth] |
| 154 |
debug1: temporarily_use_uid: 0/0 (e=0/0) |
| 155 |
debug1: trying public key file /root/.ssh/authorized_keys |
| 156 |
debug1: fd 4 clearing O_NONBLOCK |
| 157 |
debug1: matching key found: file /root/.ssh/authorized_keys, line 2 |
| 158 |
Found matching RSA key: 2e:1b:3f:10:01:1d:21:6c:6c:1e:3d:a9:33:ba:3c:f7 |
| 159 |
debug1: restore_uid: 0/0 |
| 160 |
debug1: ssh_rsa_verify: signature correct |
| 161 |
debug1: do_pam_account: called |
| 162 |
Accepted publickey for root from ::1 port 57848 ssh2 |
| 163 |
debug1: monitor_child_preauth: root has been authenticated by privileged process |
| 164 |
debug1: Enabling compression at level 6. [preauth] |
| 165 |
debug1: monitor_read_log: child log fd closed |
| 166 |
debug1: PAM: establishing credentials |
| 167 |
debug1: Entering interactive session for SSH2. |
| 168 |
debug1: server_init_dispatch_20 |
| 169 |
debug1: server_input_global_request: rtype tcpip-forward want_reply 1 |
| 170 |
debug1: server_input_global_request: tcpip-forward listen localhost port 0 |
| 171 |
debug1: Local forwarding listening on ::1 port 0. |
| 172 |
debug1: Allocated listen port 33562 |
| 173 |
debug1: channel 0: new [port listener] |
| 174 |
debug1: Local forwarding listening on 127.0.0.1 port 33562. |
| 175 |
debug1: channel 1: new [port listener] |
| 176 |
debug1: server_input_channel_open: ctype session rchan 0 win 1048576 max 16384 |
| 177 |
debug1: input_session_request |
| 178 |
debug1: channel 2: new [server-session] |
| 179 |
debug1: session_new: session 0 |
| 180 |
debug1: session_open: channel 2 |
| 181 |
debug1: session_open: session 0: link with channel 2 |
| 182 |
debug1: server_input_channel_open: confirm session |
| 183 |
debug1: server_input_global_request: rtype [email protected] want_reply 0 |
| 184 |
debug1: server_input_channel_req: channel 2 request [email protected] reply 0 |
| 185 |
debug1: session_by_channel: session 0 channel 2 |
| 186 |
debug1: session_input_channel_req: session 0 req [email protected] |
| 187 |
debug1: temporarily_use_uid: 0/0 (e=0/0) |
| 188 |
debug1: restore_uid: 0/0 |
| 189 |
debug1: channel 3: new [auth socket] |
| 190 |
debug1: server_input_channel_req: channel 2 request pty-req reply 1 |
| 191 |
debug1: session_by_channel: session 0 channel 2 |
| 192 |
debug1: session_input_channel_req: session 0 req pty-req |
| 193 |
debug1: Allocating pty. |
| 194 |
debug1: session_pty_req: session 0 alloc /dev/pts/32 |
| 195 |
debug1: server_input_channel_req: channel 2 request shell reply 1 |
| 196 |
debug1: session_by_channel: session 0 channel 2 |
| 197 |
debug1: session_input_channel_req: session 0 req shell |
| 198 |
debug1: Setting controlling tty using TIOCSCTTY. |
| 199 |
|
| 200 |
-------------------------------------------------------------------------------- |
| 201 |
debug1: server_input_global_request: rtype tcpip-forward want_reply 1 |
| 202 |
debug1: server_input_global_request: tcpip-forward listen localhost port 0 |
| 203 |
debug1: Local forwarding listening on ::1 port 0. |
| 204 |
debug1: Allocated listen port 33562 |
| 205 |
debug1: channel 0: new [port listener] |
| 206 |
debug1: Local forwarding listening on 127.0.0.1 port 33562. |
| 207 |
|
| 208 |
[11:49] bento:openssh-6.2p1% grep "Allocated listen port" -r . |
| 209 |
./channels.c: debug("Allocated listen port %d", |
| 210 |
[11:49] bento:openssh-6.2p1% |
| 211 |
|
| 212 |
|
| 213 |
-------------------------------------------------------------------------------- |
| 214 |
[11:54] bento:~% ssh -R 0:localhost:22 -R 0:192.168.1.1:33 localhost |
| 215 |
Allocated port 48392 for remote forward to localhost:22 |
| 216 |
Allocated port 37515 for remote forward to 192.168.1.1:33 |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
debug1: server_input_global_request: rtype tcpip-forward want_reply 1 |
| 222 |
debug1: server_input_global_request: tcpip-forward listen localhost port 0 |
| 223 |
debug1: Local forwarding listening on ::1 port 0. |
| 224 |
debug1: Allocated listen port 48392 |
| 225 |
debug1: channel 0: new [port listener] |
| 226 |
debug1: Local forwarding listening on 127.0.0.1 port 48392. |
| 227 |
debug1: channel 1: new [port listener] |
| 228 |
debug1: server_input_global_request: rtype tcpip-forward want_reply 1 |
| 229 |
debug1: server_input_global_request: tcpip-forward listen localhost port 0 |
| 230 |
debug1: Local forwarding listening on ::1 port 0. |
| 231 |
debug1: Allocated listen port 37515 |
| 232 |
debug1: channel 2: new [port listener] |
| 233 |
debug1: Local forwarding listening on 127.0.0.1 port 37515. |
| 234 |
debug1: channel 3: new [port listener] |
| 235 |
debug1: server_input_channel_open: ctype session rchan 0 win 1048576 max 16384 |
| 236 |
debug1: input_session_request |
| 237 |
debug1: channel 4: new [server-session] |
| 238 |
debug1: session_new: session 0 |
| 239 |
debug1: session_open: channel 4 |
| 240 |
debug1: session_open: session 0: link with channel 4 |
| 241 |
|
| 242 |
debug1: Local forwarding listening on ::1 port 5555. |
| 243 |
debug1: channel 0: new [port listener] |
| 244 |
debug1: Local forwarding listening on 127.0.0.1 port 5555. |
| 245 |
debug1: channel 1: new [port listener] |
| 246 |
debug1: server_input_global_request: rtype tcpip-forward want_reply 1 |
| 247 |
debug1: server_input_global_request: tcpip-forward listen localhost port 4444 |
| 248 |
debug1: Local forwarding listening on ::1 port 4444. |
| 249 |
debug1: channel 2: new [port listener] |
| 250 |
debug1: Local forwarding listening on 127.0.0.1 port 4444. |
| 251 |
debug1: channel 3: new [port listener] |
| 252 |
debug1: server_input_channel_open: ctype session rchan 0 win 1048576 max 16384 |
| 253 |
debug1: input_session_request |
| 254 |
debug1: channel 4: new [server-session] |
| 255 |
debug1: session_new: session 0 |
| 256 |
debug1: session_open: channel 4 |
| 257 |
|
| 258 |
-------------------------------------------------------------------------------- |
| 259 |
|
| 260 |
[12:06] bento:openssh-6.2p1% grep SSH_CONNECTION -r * |
| 261 |
audit-bsm.c: case SSH_CONNECTION_CLOSE: |
| 262 |
audit.c: {SSH_CONNECTION_CLOSE, "CONNECTION_CLOSE"}, |
| 263 |
audit.c: {SSH_CONNECTION_ABANDON, "CONNECTION_ABANDON"}, |
| 264 |
audit.h: SSH_CONNECTION_CLOSE, /* closed after attempting auth or session */ |
| 265 |
audit.h: SSH_CONNECTION_ABANDON, /* closed without completing auth */ |
| 266 |
audit-linux.c: case SSH_CONNECTION_CLOSE: |
| 267 |
monitor.c: case SSH_CONNECTION_CLOSE: |
| 268 |
regress/proxy-connect.sh: SSH_CONNECTION=`${SSH} -$p -F $OBJ/ssh_proxy 999.999.999.999 'echo $SSH_CONNECTION'` |
| 269 |
regress/proxy-connect.sh: if [ "$SSH_CONNECTION" != "UNKNOWN 65535 UNKNOWN 65535" ]; then |
| 270 |
regress/proxy-connect.sh: fail "bad SSH_CONNECTION" |
| 271 |
session.c: child_set_env(&env, &envsize, "SSH_CONNECTION", buf); |
| 272 |
sftp-server.c: if ((cp = getenv("SSH_CONNECTION")) != NULL) { |
| 273 |
sftp-server.c: error("Malformed SSH_CONNECTION variable: \"%s\"", |
| 274 |
sftp-server.c: getenv("SSH_CONNECTION")); |
| 275 |
ssh.0: SSH_CONNECTION Identifies the client and server ends of the |
| 276 |
ssh.1:.It Ev SSH_CONNECTION |
| 277 |
sshd.c: PRIVSEP(audit_event(SSH_CONNECTION_CLOSE)); |
| 278 |
sshd.c: audit_event(SSH_CONNECTION_ABANDON); |
| 279 |
[12:06] bento:openssh-6.2p1% |
| 280 |
|
| 281 |
-------------------------------------------------------------------------------- |
| 282 |
debug1: Remote connections from LOCALHOST:5555 forwarded to local address localhost:22 |
| 283 |
|
| 284 |
-------------------------------------------------------------------------------- |
| 285 |
[12:42] bento:openssh-6.2p1% grep tcpip-forward * |
| 286 |
channels.c: packet_put_cstring("tcpip-forward"); |
| 287 |
channels.c: packet_put_cstring("cancel-tcpip-forward"); |
| 288 |
Binary file channels.o matches |
| 289 |
grep: contrib: Is a directory |
| 290 |
Binary file libssh.a matches |
| 291 |
grep: openbsd-compat: Is a directory |
| 292 |
grep: regress: Is a directory |
| 293 |
grep: scard: Is a directory |
| 294 |
serverloop.c: if (strcmp(rtype, "tcpip-forward") == 0) { |
| 295 |
serverloop.c: debug("server_input_global_request: tcpip-forward listen %s port %d", |
| 296 |
serverloop.c: } else if (strcmp(rtype, "cancel-tcpip-forward") == 0) { |
| 297 |
serverloop.c: debug("%s: cancel-tcpip-forward addr %s port %d", __func__, |
| 298 |
Binary file serverloop.o matches |
| 299 |
Binary file ssh matches |
| 300 |
Binary file sshd matches |
| 301 |
Binary file ssh-keyscan matches |
| 302 |
Binary file ssh-keysign matches |
| 303 |
[12:42] bento:openssh-6.2p1% |
| 304 |
|
| 305 |
-------------------------------------------------------------------------------- |
| 306 |
Channel information for (remote) forwarding: |
| 307 |
|
| 308 |
c = channel_new("port listener", type, sock, sock, -1, |
| 309 |
CHAN_TCP_WINDOW_DEFAULT, CHAN_TCP_PACKET_DEFAULT, |
| 310 |
0, "port listener", 1); |
| 311 |
c->path = xstrdup(host); |
| 312 |
c->host_port = port_to_connect; |
| 313 |
c->listening_addr = addr == NULL ? NULL : xstrdup(addr); |
| 314 |
if (listen_port == 0 && allocated_listen_port != NULL && |
| 315 |
!(datafellows & SSH_BUG_DYNAMIC_RPORT)) |
| 316 |
c->listening_port = *allocated_listen_port; |
| 317 |
else |
| 318 |
c->listening_port = listen_port; |
| 319 |
|
| 320 |
-------------------------------------------------------------------------------- |
| 321 |
|
| 322 |
Code handling remote forwarding in the client: |
| 323 |
- ssh_init_forwarding |
| 324 |
- channel_request_remote_forwarding |
| 325 |
Sends hostname + port for ssh1 only - not send in ssh2 |
| 326 |
|
| 327 |
Code handling forwarding / listening in the server: |
| 328 |
|
| 329 |
- channel_new: creates channels, 2 per listener (ipv4/ipv6) |
| 330 |
- channels_alloc contains number of channels |
| 331 |
- server_input_global_request |
| 332 |
Reads only listen port, not hostname/port to connect to |
| 333 |
- channel_setup_remote_fwd_listener |
| 334 |
- channel_setup_remote_fwd_listener |
| 335 |
|
| 336 |
Code handling environment variables: |
| 337 |
|
| 338 |
- child_set_env |
| 339 |
1236 child_set_env(&env, &envsize, "SSH_CONNECTION", buf); |
| 340 |
|