News for hackers. Stuff that matters.
Re:SSH as a Sudo Replacement by aaaronic on Saturday June 22, 2024 @08:25PM (#40763513)
Am I missing something?

How is logging into ssh (sshd) AS root more secure than using sudo? I honestly don’t even know how dangerous that is because I’ve always been told to never allow it. I see here thought goes into preventing that for a remote user, so I’m not talking about that aspect of security here.

Maybe it has to do with #3 in the sudo limitations — I certainly don’t see any benefits vis-a-vis #1.

I totally get that this is an experiment, but I suspect it is more vulnerable than using sudo, not less (the open socket proxy looks interestingly vulnerable to a man in the middle attack).

Having said all that, I did learn some tricks old tools are capable of, so kudos for showing me something new.

Re:SSH as a Sudo Replacement by lmz on Saturday June 22, 2024 @09:10PM (#40763746)
The sudo binary is suid root / privileged and is exposed directly to the untrusted user. If anything goes wrong inside of sudo (with the user's entire environment as the surface area), it may be exploited.

The ssh approach does not expose a suid binary. Instead it uses the ssh network layer so it is no less secure than accessing ssh over a network, which is considered pretty secure.

Re:SSH as a Sudo Replacement by hughesjj on Saturday June 22, 2024 @09:33PM (#40763881)
...why not just su then?
Re:SSH as a Sudo Replacement by rpgwaiter on Saturday June 22, 2024 @09:41PM (#40763929)
root would need a defined password, which opens up other security concerns
Re:SSH as a Sudo Replacement by akira2501 on Saturday June 22, 2024 @09:49PM (#40763989)
Even if you allow passwordless su for users in the wheel group?
Re:SSH as a Sudo Replacement by bdd8f1df777b on Saturday June 22, 2024 @10:24PM (#40764205)
That's extremely dangerous. Any software running as a wheel user can escalate privileges willy nilly.
Re:SSH as a Sudo Replacement by immibis on Saturday June 22, 2024 @10:44PM (#40764319)
they can also access your ssh private keys
Re:SSH as a Sudo Replacement by rascul on Sunday June 23, 2024 @01:36AM (#40765044)
In theory, those ssh private keys are password protected.

In practice, maybe not.

Re:SSH as a Sudo Replacement by ec109685 on Sunday June 23, 2024 @01:47AM (#40765065)
They were stored in the user’s yubikeys (or similar) in this example.
Re:SSH as a Sudo Replacement by bogantech on Saturday June 22, 2024 @10:25PM (#40764208)
If you do that you deserve what you get
Re:SSH as a Sudo Replacement by djbusby on Saturday June 22, 2024 @09:58PM (#40764045)
Do what!?
Re:SSH as a Sudo Replacement by bobmcnamara on Saturday June 22, 2024 @10:31PM (#40764242)
plzno
Re:SSH as a Sudo Replacement by CaliforniaKarl on Saturday June 22, 2024 @11:02PM (#40764412)
We've got root passwords set on, IIRC, all of our systems. They're long, random, and can only be entered through the console on the VGA port or the IPMI console.
Re:SSH as a Sudo Replacement by lmz on Sunday June 23, 2024 @03:04AM (#40765327)
su is also a suid binary, no? It is probably a lot less complex than sudo.
Re:SSH as a Sudo Replacement by Sparkyte on Sunday June 23, 2024 @03:04AM (#40765326)
I would assume if you has to use SSH or sudo you've already lost. I've been working with people where we just completely lock down the VM or Container. They only allow necessary flow of traffic and are managed entirely from golden builds. If you need to make changes or fix something it is a new vm or container.
Re:SSH as a Sudo Replacement by gunapologist99 on Sunday June 23, 2024 @04:56PM (#40770515)
This premise is incorrect: SSH doesn't need to be an suid binary because it's already running as root, and then SSH creates a new environment for the user, exactly like sudo does, but with all the added complexity and overhead (and surface) of privileged network access.

To be clear, I love SSH and we even run a userify instance to distribute keys, but juts comparatively the surface area of the ssh daemon alone is greater than sudo alone.

(however, even with the extra complexity, you might trust the history of portable OpenSSH more than sudo, and that's a good, but different, conversation to have also.)

Re:SSH as a Sudo Replacement by lmz on Sunday June 23, 2024 @05:31PM (#40770737)
But the area under control by the invoking user is data over one socket vs the whole calling environment e.g. environment vars, local files. Surely that counts for something.
Re:SSH as a Sudo Replacement by gunapologist99 on Monday June 24, 2024 @11:12AM (#40776985)
Unfortunately SSH has to do all that too. :(
Re:SSH as a Sudo Replacement by op00to on Saturday June 22, 2024 @08:35PM (#40763576)
A big part of sudo is that you should be running individual commands using sudo to increase auditability rather than simply running sudo bash or whatever.
Re:SSH as a Sudo Replacement by aaaronic on Saturday June 22, 2024 @08:41PM (#40763613)
I can agree with that, though admit to being guilty of using sudo bash far more often than I should.

I honestly thought they’d be using ssh that way (single command at a time), though I’m still not sure to what security end.

Re:SSH as a Sudo Replacement by op00to on Saturday June 22, 2024 @10:21PM (#40764182)
I sudo bash a lot as well. Some times I regret it when I try to figure out what the hell I did months ago. :)
Re:SSH as a Sudo Replacement by mmh0000 on Saturday June 22, 2024 @09:34PM (#40763888)
If ‘sudo’ is properly configured running bash or anything that allows command execution (vim, eMacs, etc) is disallowed.

Also, may I introduce you to the ‘sudo -i’ option.

Re:SSH as a Sudo Replacement by dns_snek on Sunday June 23, 2024 @04:13AM (#40765620)
> If ‘sudo’ is properly configured running bash or anything that allows command execution (vim, eMacs, etc) is disallowed.

Keep in mind that this is borderline impossible to enforce unless your goal is just to stop the most common ways of accidentally breaking the policy. A list of commands that allows breaking out into a full shell includes: less, apt, man, nano, wget & many more.

https://gtfobins.github.io/#+shell

Re:SSH as a Sudo Replacement by acka on Sunday June 23, 2024 @04:14AM (#40765623)
> eMacs

This made me chuckle. Apple influencing the way Emacs is spelled versus RMS's stance on Free Software couldn't be further apart I think.

Re:SSH as a Sudo Replacement by mmh0000 on Sunday June 23, 2024 @10:13AM (#40767620)
You're correct there! Wrote that up on my tiny Apple device and really couldn't be bothered to correct Apple's spellcheck. Text editing from a 5in touchscreen is very painful.
Re:SSH as a Sudo Replacement by kiririn on Saturday June 22, 2024 @10:03PM (#40764084)
Auditd and pam_tty_audit can take care of all your auditing needs
Re:SSH as a Sudo Replacement by op00to on Saturday June 22, 2024 @10:22PM (#40764183)
Sure! All part of layered controls and reporting.
Re:SSH as a Sudo Replacement by dmw_ng on Sunday June 23, 2024 @04:29AM (#40765708)
It's comical to see the sudo codebase mentioned in the same breath as increasing auditability here
Re:SSH as a Sudo Replacement by o11c on Saturday June 22, 2024 @09:13PM (#40763767)
I'm skeptical of the approach in the linked article, but:

> I honestly don’t even know how dangerous that is because I’ve always been told to never allow it.

You've fallen for the FUD. In reality, logging in directly as root over remote SSH is strictly more secure than logging in as user over remote SSH and then using `sudo`.

If user@home uses ssh to root@server, then root@server is only compromised if user@home is compromised.

If user@home uses ssh to user@server then sudo to root@server, then root@server is compromised if either user@home or user@server is compromised. In particular, it is fairly common for user@server to be running some other software such as daemons or cronjobs. Please don't give out free root escalation (and often lateral movement due to password reuse) to anyone who manages to infect through those!

(This of course does not apply if sudo is used in whitelisted-commands-only mode and does not take either passwords or credentials fully accessible from the remote host)

Re:SSH as a Sudo Replacement by cycomanic on Saturday June 22, 2024 @11:02PM (#40764409)
I'm not sure I agree with this argument. Sure you can say theoretically it's one less account that could be compromised, but in practice I see a bunch of caveats.

1. If we allow password based logins, there will be many orders of magnitude more login attempts to root than any other user. So if you have to allow password based logins, you pretty much never want to allow root login.

2. If we disallow password based logins, a user account would be as save as a root login, except again that the root account is the much more valuable target so will get much more attention. I also do see the relevance of cronjobs (root does run them as well) and naturally no user that has sudo privileges should be be running network exposed services.

3. In cases were admin rights have to be shared amongst multiple users, are you going to share the same key for all users (probably not a good idea) or give every user a separate key (making key management a bit of a nightmare, user management is much easier).

4. As you pointed out yourself sudo gives you much more fine-grained control over commands that can be run.

Re:SSH as a Sudo Replacement by kchr on Sunday June 23, 2024 @07:41AM (#40766683)
> 3. In cases were admin rights have to be shared amongst multiple users, are you going to share the same key for all users (probably not a good idea) or give every user a separate key (making key management a bit of a nightmare, user management is much easier).

To solve the key management nightmare, short-lived SSH certificates can be used to map an identity to a shared user account. Hashicorp Vault is one option for issuing such certificates, but there are other alternatives as well.

https://docs.redhat.com/en/documentation/red_hat_enterprise_....

Re:SSH as a Sudo Replacement by fsniper on Sunday June 23, 2024 @06:24AM (#40766296)
The approach is comparing - Theoretical configuration errors, or theoretical vulnerabilities that may or may not be there with - Having a new daemon running (a new attack surface) which - may also have configuration errors, or vulnerabilities as such - and also removes a few layers of user based authorisation with a single root level

This approach is somehow considered more secure.

And in a rational way, and of course for any rational security perspective this can't be considered more secure, just different.

Re:SSH as a Sudo Replacement by irusensei on Sunday June 23, 2024 @06:48AM (#40766437)
> How is logging into ssh (sshd) AS root more secure than using sudo?

Article describes an additional SSH server listening on an Unix socket. The usual threat model about exposing root logins from the internet may not apply here.

Re:SSH as a Sudo Replacement by joveian on Sunday June 23, 2024 @08:29AM (#40766955)
The big advantage is if setuid and setgid support can be entirely removed. There are a bunch of special cases that have been added over the years to try to deal but increasing priviledges of a process is fundamentally more challenging in the unix security model than only ever lowering priviledges. Of course these days Linux has priviledge escalation via user namespaces as well.
Re:SSH as a Sudo Replacement by jeffhuys on Sunday June 23, 2024 @11:29AM (#40768149)
Psst… privilege has no letter D