News for hackers. Stuff that matters.
Re:SSH hacks – a little sanity for remote workers by segfaultbuserr on Wednesday April 29, 2020 @08:21PM (#23026196)
> What are your favorite SSH tips & tricks?

    $ ssh -J user1@host1 user_final@host_final
or

    $ ssh -J user1@host1,user2@host2 user_final@host_final
Not many people know it, you don't need to launch a SSH within a SSH session - SSH has built-in support of using one SSH server as a proxy to another SSH server. Useful for <del>hacking servers</del> accessing servers behind a firewall, or using your own server as a proxy to bypass a bottleneck in the network.
Re:SSH hacks – a little sanity for remote workers by InvaderFizz on Thursday April 30, 2020 @12:27AM (#23027447)
Another lesser known tunneling trick is that SSH will happily act as a SOCKS5 Proxy. I've been using this trick for going on 20 years now.

Just do: ssh -D9090 user@remote

Then, in Firefox, set it to use a SOCK5 proxy of localhost:9090 and "Proxy DNS when using SOCKS v5".

Now, when you use Firefox it is as if you are using Firefox on the machine you are SSH'd into(including DNS resolution!). This is really handy for things like accessing otherwise unreachable resources or other internal resources externally. I use it for accessing iDRAC/IPMI/ESXi (you can also tell Java to use the proxy so VMRC works as well). It is also handy to be able to put all your web traffic as originating from a remote VPS with no advanced setup required.

Re:SSH hacks – a little sanity for remote workers by segfaultbuserr on Thursday April 30, 2020 @01:43AM (#23027789)
> Now, when you use Firefox it is as if you are using Firefox on the machine you are SSH'd into(including DNS resolution!).

Don't forget to check the "Proxy DNS when using SOCKS v5" option in Firefox.

Re:SSH hacks – a little sanity for remote workers by fnordist on Thursday April 30, 2020 @04:07AM (#23028596)
I use the Socks-Proxy only for internal Websites:

You habe to create a local "proxy.pac" file with the following contents:

function FindProxyForURL(URL,host) { host = host.toLowerCase(); if (shExpMatch(host,"*.my-company.com")) { return "SOCKS5 127.0.0.1:9090"; } return "DIRECT"; }

Then set "file:///path/to/proxy.pac" as auto-config URL in the Firefox-proxy-settings. Don't forget to enable DNS-Requests over SOCKS5.

For services, which you can't proxy with SOCKS5, you can use LocalForward in your ssh_config: Match host your-workstation !exec "nc -vz xmpp.my-company.com 5222 &>/dev/null || { echo 'xmpp.my-company.com not reachable, using LocalForward' 1>&2 && exit 1 ; }" LocalForward 127.0xcafe1:5222 xmpp.my-company.com:5222

Then add the following line to your /etc/hosts: 127.12.175.225 xmpp.my-company.com

Re:SSH hacks – a little sanity for remote workers by orbitingpluto on Thursday April 30, 2020 @02:51AM (#23028129)
I used to do this all the time over port 53.

My closest coffee shop would allow people to access Wi-Fi only if you gave them full access to your Facebook account. DNS was the only port open to the outside world.

Re:SSH hacks – a little sanity for remote workers by s_gourichon on Thursday April 30, 2020 @04:08AM (#23028601)
> My closest coffee shop would allow people to access Wi-Fi only if you gave them full access to your Facebook account.

What the???

Re:SSH hacks – a little sanity for remote workers by mercora on Thursday April 30, 2020 @07:10AM (#23029607)
I've seen this on Ubiquity hardware as an option too. Apparently it requires you to "check-in" via facebook to use it, whatever that means exactly. There is also an option to login via facebook without this though.
Re:SSH hacks – a little sanity for remote workers by orbitingpluto on Thursday April 30, 2020 @07:40AM (#23029778)
This was awhile back and was particularly nasty. No token, no check-ins, it was an unapologetic man-in-the-middle login prompt.

Terms of service had wording that made mining all data in your Facebook account sound like the intent.

Re:SSH hacks – a little sanity for remote workers by jandrese on Thursday April 30, 2020 @01:00PM (#23033143)
How about no. Or hell no. If I see a request like that it is an immediate disconnect. Might as well have a requirement that they do a full anal cavity sweep before they can sell you a cup of coffee.
Re:SSH hacks – a little sanity for remote workers by MaxBarraclough on Thursday April 30, 2020 @04:59AM (#23028872)
Interesting that they permit TCP port 53, rather than just UDP port 53.
Re:SSH hacks – a little sanity for remote workers by kubanczyk on Thursday April 30, 2020 @05:23AM (#23028994)
RFC7766 "Recursive server (or forwarder) implementations MUST support TCP so that they do not prevent large responses from a TCP-capable server from reaching its TCP-capable clients."

large responses == some DNSSEC, some IPv6

Re:SSH hacks – a little sanity for remote workers by Piskvorrr on Thursday April 30, 2020 @05:19AM (#23028975)
My guess is that it stems from lax firewall defaults. "Allow port 53 - [tcp/udp/BOTH]?" (Yeah, I know that DNS can also work over 53/tcp, but it's rare compared to the 53/udp volume)
Re:SSH hacks – a little sanity for remote workers by acdha on Thursday April 30, 2020 @02:41PM (#23034470)
It's not as rare as it used to be a couple decades ago. If you block tcp/53 you will find a surprising number of things breaking as record sizes have increased over the years.
Re:SSH hacks – a little sanity for remote workers by mercora on Thursday April 30, 2020 @07:13AM (#23029630)
i think that is fine actually. however, if i would implement such thing i would probably redirect DNS traffic to my DNS server as long as you are not authenticated :)
Re:SSH hacks – a little sanity for remote workers by mgr86 on Thursday April 30, 2020 @07:01AM (#23029560)
I have been doing the same thing for awhile. It allows me to access all the services we have set up on the intranet in the office. With Tmux I move around from machine to machine and keep all the work stuff in the office.

The office is also a large university. Therefore, I have access to many additional library and other subscription services.

It’s great as a lot of the office struggled to get a work setup in place. I’m happily the only one who didn’t need Gotomypc. It also helped me save time durning this transition by not having to answer my less technical coworkers questions about getting Gotomypc set up.

Re:SSH hacks – a little sanity for remote workers by anonymousDan on Thursday April 30, 2020 @05:45AM (#23029117)
Can I use this to potentially view a pdf on a remote server locally (as an alternative to an X server)? Would it be more efficient?
Re:SSH hacks – a little sanity for remote workers by practical_lem on Thursday April 30, 2020 @06:39AM (#23029420)
For those tasks I just use sshfs. I keep a ~/n/${host} directory where I access remote files like they were on my machine.
Re:SSH hacks – a little sanity for remote workers by davb on Wednesday April 29, 2020 @08:49PM (#23026336)
And in your ~/.ssh/config that's the ProxyJump directive. Adding a proper configuration for the bastion/jump host and for the target host means you can just to "ssh target".

In my case, I usually do "ssh target -t tmux -2 att" to attach to my tmux session, then when I detach it will close the SSH connection (and all of my tunnels).

Re:SSH hacks – a little sanity for remote workers by jerf on Wednesday April 29, 2020 @11:23PM (#23027118)
Just in general, look up .ssh/config and configure it.

A lot of software uses ssh to do various things. You can pull a lot of neat tricks with SSH config coming in through a bastion on a non-standard port to a host machine into a shell executed in a docker container with the right .ssh/config, aliased to "machine", and the you can use anything that can run on SSH to "machine" with all that fancy configuration. Check your favorite editor; good odds it can edit files through that mess, or give you a remote directory explorer, or whatever.

Re:SSH hacks – a little sanity for remote workers by fulafel on Thursday April 30, 2020 @01:17AM (#23027654)
Word of warning: using jump hosts shift your mindset towards building an internal network with lax security, the crunchy outside/soft tasty inside security antipattern.

(Yes you don't intend it at the start, but the realities of your later evaluations of where to invest effort security-wise will leave the internal network to rot since you won't think of the scenarios of how it would be compromised)

Re:SSH hacks – a little sanity for remote workers by Symbiote on Thursday April 30, 2020 @09:21AM (#23030480)
Isn't that typically already the mindset, since most people set up networks with non-routable (10, 192.168 etc) IP addresses?
Re:SSH hacks – a little sanity for remote workers by fulafel on Thursday April 30, 2020 @10:47AM (#23031363)
It's a chicken-and-egg situation, yep. But the world seems to be moving towards zero trust networks, distaste towards complexity and opacity brought on by ambiguous rfc1918 addresses, and wide availability of ipv6.
Re:SSH hacks – a little sanity for remote workers by memco on Wednesday April 29, 2020 @09:47PM (#23026655)
Incidentally, I just filed a ticket because ProxyJump is not a known keyword in VScode’s SSH config autocomplete. It’s such a handy tool. Only landed in OpenSSH 7.3 in 2016 so it’s not that surprising it isn’t well known.
Re:SSH hacks – a little sanity for remote workers by mmalone on Wednesday April 29, 2020 @08:59PM (#23026393)
That `tmux` bit is clever. Wonder if you could do that in a `ForceCommand` or something like that so you don’t need to type that part either?
Re:SSH hacks – a little sanity for remote workers by xelxebar on Wednesday April 29, 2020 @11:18PM (#23027097)
A combination of `RemoteCommand` and `RequestTTY` should do the trick:

    Host <host>
        ...
        RequestTTY yes
        RemoteCommand tty
The problem is that this will mess up your one-off command invocations of ssh, git ssh connections, etc:

    $ ssh <host> ls
    Cannot execute command-line and remote command.
However, we can use `Match` blocks to get around that! There are a thousand ways to skin this cat, but one way is to use an environment variable, here `t` for "tmux". Put this at the end of your config:

    Match exec "test ${t:-0} = 1"
        RequestTTY yes
        RemoteCommand tmux has-session && tmux attach-session || tmux
and the following Just Work, reattaching tmux sessions as necessary:

    $ t=1 ssh <host>
    $ ssh <host> ls
Re:SSH hacks – a little sanity for remote workers by mmalone on Wednesday April 29, 2020 @11:41PM (#23027192)
Nice. `Match exec` is one of my favorite things. It's too bad the command being passed to `ssh` (if there is one) isn't available as a `TOKEN` (as far as I can tell). That would put a bow on everything.
Re:SSH hacks – a little sanity for remote workers by pletnes on Friday May 01, 2020 @03:15AM (#23039764)
I simply have two configs for machines I ssh to often - one to the «normal shell» and one to a tmux instance with standard name.
Re:SSH hacks – a little sanity for remote workers by mod on Wednesday April 29, 2020 @09:15PM (#23026488)
(Not OP) I personally don't type my advanced commands, I alias them. So I would use "ssh-target" as my alias there.
Re:SSH hacks – a little sanity for remote workers by chrisweekly on Thursday April 30, 2020 @06:25AM (#23029343)
Same -- and I comment them heavily, so when (like today per this thread) I learn more about said advanced options, I'm "forced" to update my "docs". Always be capturing your knowledge! :)
Re:SSH hacks – a little sanity for remote workers by itsjloh on Thursday April 30, 2020 @01:18AM (#23027662)
Jump hosts are fantastic! With a little bit of sed magic you can also setup wildcard jump hosts, eg:

    Host *-via-dc1
        ProxyCommand ssh [email protected] nc $(echo %h | sed 's/-via-dc1$//') %p
I wrote about it ages ago here https://jloh.co/posts/dynamic-ssh-jump-hosts/
Re:SSH hacks – a little sanity for remote workers by davb on Thursday April 30, 2020 @06:59AM (#23029544)
That's really smart!

I'd maybe even reverse it, having:

  Host my-jump-host
      Hostname my-jump-host.mydomain.example
      User myuser

  Host my-jump-host-*
      User myuser
      ProxyCommand ssh my-jump-host nc $(echo %h | sed 's/^my-jump-host-//') %p

This way, autocomplete in bash would work. Typing "ssh m<tab>", assuming m* doesn't match anything else, would suggest "ssh my-jump-host" (which I often ssh directly to anyway). Then just add "-myotherhost" so the whole sequence becomes "ssh m<tab><bs>-myotherhost". Not a huge saving but I'm lazy and like autocomplete in the shell.
Re:SSH hacks – a little sanity for remote workers by Piskvorrr on Thursday April 30, 2020 @05:23AM (#23028995)
Whoa! Now that's mighty useful, thanks! (Note that this works even without the ProxyJump option, but requires a sane netcat on the jumphost; older busyboxes only had a netcat)
Re:SSH hacks – a little sanity for remote workers by davidcollantes on Friday May 01, 2020 @11:32AM (#23043033)
Let's say all machines are named in the form "vm12345," but the jump server itself is also named in the same form. How would you go to include all vm in a wildcard, but the jump server itself?
Re:SSH hacks – a little sanity for remote workers by lathiat on Wednesday April 29, 2020 @11:04PM (#23027045)
A good trick to combine with this is ControlSockets.. you can have multiple SSH/SCP connections over the same actual SSH connections. And starting a new SSH over the existing connection is much faster than the initial connection particularly if you are on higher latency (e.g. from Australia at 250-400ms)

``` Host xyz HostName 1.2.3.4 ControlMaster auto ControlPath ~/.ssh/sockets/%r@%h-%p ControlPersist 600 ```

Then if you SSH to the same host multiple times it will re-use the connection and it persists for 10 minutes after you disconnect.

If you are using a ProxyJump like the above post this can speed up the initial ProxyJump connection.. or you can just use it with normal SSH (which is what I do) and when i want to open multiple tabs to the same machine its significantly faster.

Re:SSH hacks – a little sanity for remote workers by mmalone on Wednesday April 29, 2020 @11:11PM (#23027075)
I've always wondered what this is useful for. So it's purely for performance?

Why is it faster to establish the connection? Does it re-use the authentication from the existing ControlMaster too, so you skip the handshake? Seems like it could be dangerous if you're not careful. I guess that's why you can configure it to use `ssh-askpass` for conformation (which, btw, is missing on macOS these days).

The other neat-looking directive that I've never tried is `ProxyUseFdpass`, which tells OpenSSH to expect a file descriptor back from your `ProxyCommand` instead of using stdin/stdout. I'm not sure why it exists, but it feels like it could be a performance optimization. Particularly for `scp`. But I've never actually run into a performance problem using `ProxyCommand` so shrug?

Re:SSH hacks – a little sanity for remote workers by kbenson on Thursday April 30, 2020 @02:44AM (#23028083)
I think it's purely for performance, but it does make a big difference. There's a lot of round trips to set up an SSH connection, and depending on the RTT to the server, that can feel like a real delay if there's another host in the connection. If you use a Proxy host for jumping, and it's got a better RTT to most servers you connect to, reusing the existing connection to it might actually make it feel like it connects faster than a direct connection from your workstation would.

e.g.

    $ ping -c 2 foo
    PING foo (a.b.c.d) 56(84) bytes of data.
    64 bytes from foo (a.b.c.d): icmp_seq=1 ttl=55 time=3.56 ms
    64 bytes from foo (a.b.c.d): icmp_seq=2 ttl=55 time=3.62 ms
    
    --- foo ping statistics ---
    2 packets transmitted, 2 received, 0% packet loss, time 3ms
    rtt min/avg/max/mdev = 3.564/3.594/3.624/0.030 ms
    $ time ssh root@foo "echo foo"
    foo
    
    real    0m0.650s
    user    0m0.062s
    sys     0m0.006s
Now if I add the following to .ssh/config:

    Host foo
        controlmaster auto
        controlpath ~/.ssh/ssh-%r@%h:%p
You can see how much faster it gets if I already have a connection to that server open:

    $ time ssh root@foo "echo foo"
    foo
    
    real    0m0.032s
    user    0m0.003s
    sys     0m0.004s
Re:SSH hacks – a little sanity for remote workers by kqr on Thursday April 30, 2020 @04:19AM (#23028657)
This is especially important in some cases where you have local shell wrappers around commands that execute on a remote server with SSH.

I do this for my email, for example, where the actual programs for dealing with my email sits on a server, but on each host I have shell scripts with the same name as the original program, except all they do is SSH to the server and run the actual program there. When navigating a GUI that runs these shell wrappers, you get a lot of opening and closing of SSH sessions very quickly.

Re:SSH hacks – a little sanity for remote workers by beagle3 on Thursday April 30, 2020 @10:47AM (#23031372)
> So it's purely for performance?

It's not just for performance - it "reuses authentication" by not needing it. The authentication is an encapsulation, within which multiple channels get used. Usually, it's just the main "shell" channel; but occasionally it's also forwarding (-L / -R / -D), sftp; what ControlMaster does is let you open more "shell" channels when you run the "ssh" command again, instead of establishing a whole new connection.

> The other neat-looking directive that I've never tried is `ProxyUseFdpass`,

It's so you can use whatever weird communication hardware/protocol you like (serial? non-tcp satellite modem?), and all you have to do to get all of ssh's wonderful features over it, is make provide a file descriptor that works well enough (serial port; pipe you create; etc.)

Re:SSH hacks – a little sanity for remote workers by pletnes on Friday May 01, 2020 @03:33AM (#23039873)
Also for tab completion of directories to rsync on the remote. Otherwise you’d have to type your password on every <tab>. You can use ssh keys and agents to achieve the same, but it’s much slower, and harder to set up IMO.
Re:SSH hacks – a little sanity for remote workers by Piskvorrr on Thursday April 30, 2020 @05:26AM (#23029014)
It's not even establishing the connection: it just goes through the existing ControlMaster. This gets me about ~0.5 sec for a fresh connection, and just-about-instant response for a multiplexed one.
Re:SSH hacks – a little sanity for remote workers by nprescott on Wednesday April 29, 2020 @08:38PM (#23026283)
This is a good one. I've used this in the past in order to get onto IPv6-only networks as well. In my case I don't have IPv6 enabled on my home internet (thanks Verizon!) and I had a tiny virtual machine with Vultr, which at their lowest price point aren't offering IPv4 address space any more. Using a jump through another machine with both 4 and 6 address space saved me from having to cough up more money solely for a IPv4 address.
Re:SSH hacks – a little sanity for remote workers by mmalone on Wednesday April 29, 2020 @08:52PM (#23026350)
You can also use the `ProxyJump` directive in your `~/.ssh/config`, which is the same as `-J` on the command line. So, for example:

    Host host_final
        ProxyJump user1@host1
will do the same thing as `-J user1@host`, but will allow you to just type:

    ssh user_final@host_final
If you're using an older SSH you can do this with a `ProxyCommand` (requires netcat on the jump box, but that's pretty standard):

    Host host_final
        ProxyCommand ssh user1@host1 nc %h %p
There are a bunch of variations on this technique, but these are the most common configs. Super easy transparent bastioning.

You can get really fancy with this stuff, particularly with `ProxyCommand`. We use it to trigger auto-login for our "Single sign-on for SSH" product at smallstep. When you have a `ProxyCommand` configured, instead of opening its own socket, OpenSSH just execs your proxy command and expects stdin & stdout to end up connected to a socket to the remote server. It doesn't care how that happens or what else happens before you get there. So we (ab)use this as a hook to check if you have a valid SSH certificate in your `ssh-agent` and, if you don't, trigger a single sign-on flow. It's nifty.

If you've never read the man pages for `ssh_config` and `sshd_config`, I highly recommend it. It's not that long and there's a lot of good stuff in there.

Re:SSH hacks – a little sanity for remote workers by ryukafalz on Wednesday April 29, 2020 @10:36PM (#23026922)
>If you're using an older SSH you can do this with a `ProxyCommand` (requires netcat on the jump box, but that's pretty standard)

Even without ProxyJump, you can do something similar with ProxyCommand without netcat:

    Host final
    HostName host.example.com
    ProxyCommand ssh -W %h:%p [email protected]
(Granted, this is still more recent, but I think ProxyJump was introduced later than this.)
Re:SSH hacks – a little sanity for remote workers by _wldu on Wednesday April 29, 2020 @08:48PM (#23026334)
Use teredo at home.

apt install miredo (on most debian based systems)

https://en.wikipedia.org/wiki/Teredo_tunneling

Re:SSH hacks – a little sanity for remote workers by segfaultbuserr on Wednesday April 29, 2020 @09:45PM (#23026642)
You can also use Tor as IPv6 proxy in a pure IPv4 network (or as IPv4 proxy in a pure IPv6 network), recent versions of Tor can work under pure IPv6, gaining privacy and connectivity simultaneously. The speed is not actually too bad for web browsing, although not ideal for SSH. But still comes handy sometimes, I'm used it before to clone packages from GitHub on IPv6-only servers.
Re:SSH hacks – a little sanity for remote workers by Polylactic_acid on Wednesday April 29, 2020 @11:14PM (#23027085)
How does github not have an AAAA record in 2020?? The faster people move to gitlab the better. ipv6 servers are not at all rare. Useful for individual use since you can save $1/month by dropping a useless for personal use feature.
Re:SSH hacks – a little sanity for remote workers by segfaultbuserr on Wednesday April 29, 2020 @11:49PM (#23027231)
> How does github not have an AAAA record in 2020?

Yeah, it's hopeless, and it goes as if [0] they explicitly decided not to support it, incredibly frustrating!

> The faster people move to gitlab the better.

A lot projects will always host their master repository on GitHub for better or worse...

[0] Not meant to be an accusation, I don't have any evidence.

Re:SSH hacks – a little sanity for remote workers by mmalone on Thursday April 30, 2020 @12:01AM (#23027291)
Last time I launched a new website it took less than a month for someone to let us know that we'd forgotten to configure a AAAA and our site was inaccessible for them. And that was at new website traffic volume.

So yea, GitHub definitely knows about AAAA records and has intentionally decided not to have one. The question is: why? They must have a reason. Maybe even a good one. I'm curious.

Re:SSH hacks – a little sanity for remote workers by rob-olmos on Thursday April 30, 2020 @02:09AM (#23027895)
Interesting. Any likely reasons why not having IPv6/AAAA make the site inaccessible to them?

Sounds like most of the internet would be inaccessible to them as well?

Re:SSH hacks – a little sanity for remote workers by segfaultbuserr on Thursday April 30, 2020 @02:32AM (#23028017)
A broken AAAA record, perhaps. Sometimes the AAAA is invalid or broken without getting noticed by the sysadmin. I've personally reported broken AAAA records before.
Re:SSH hacks – a little sanity for remote workers by rob-olmos on Saturday May 02, 2020 @11:39PM (#23056697)
I see. Although from the mmalone's comment it sounded like an AAAA record wasn't set at all, rather than set incorrectly.
Re:SSH hacks – a little sanity for remote workers by segfaultbuserr on Thursday April 30, 2020 @12:20AM (#23027406)
I do find some rumors on Reddit [0], which says IPv6 is a low priority project that gives its way to other projects.

[0] https://old.reddit.com/r/ipv6/comments/ec8i7y/github_still_d...

Re:SSH hacks – a little sanity for remote workers by siver_john on Thursday April 30, 2020 @08:44AM (#23030199)
Thank you for being worth the whole reason I clicked on this link. I could have used this forever ago when I was trying to figure out how to do this to bypass a firewall (now I don't need to but this will be useful in the future).