4 ms·
Use /usr/bin/sudo yourcommand with any intermediate command not using path but it's real path hard coded. Edited: Previous suggested using \sudo but it depend
by sinsudo 5mo ago
Use /usr/bin/sudo yourcommand with any intermediate command not using path but it's real path hard coded.
Edited: Previous suggested using
\sudo but it depends of the variable path which can be modified by the attacker.
- mort96 5mo agoYes, that would be one potential solution. But I have certainly never done it and bet >99.999% of the world's use of sudo is through 'sudo'. Plus you only need one slip-up and you're hosed. Even people who try to almost always use '/usr/bin/sudo' will undoubtedly accidentally let a 'sudo' go through. Maybe they copy/paste a command from somewhere (after verifying that it's safe of course) and just didn't think of the sudo issue then and there.
- sinsudo 5mo agoThe real problem is that there should be at least 2 levels for sudo, one for installing software and another that really allows someone to compromise the entire system, both layers should be separate to mitigate risk. At least the most secure layer should allow you to perform secure recovering and diagnosis
- DonHopkins 5mo agoUnix used to have a user named "bin" just for owning all the binaries and performing installs.
- sinsudo 5mo agoThe old bin user is an idea that could be modernized with a new two level sudo concept, the higher one for recovery and diagnosis, already done in Chromebook and other solutions
- DonHopkins 5mo agobin passwords I will always remember: At the University of Maryland CS department systems the bin password was "fuck,you", and there was a devout Christian student on staff who had a problem with that, so we had to change it (to something harder to remember, I just can't recall).
- lrvick 5mo agoYou do not need sudo for installing software. Can just install to ~/.local. Many package managers require sudo, sure, but there is no good reason for them to in a modern linux system, and not all require this. Even with systemd, you can use systemd --user.
- michaelmior 5mo agoThat depends on what the software is. If you want to run a service that bonds to a privileged port for example, you need sudo.
- signed-log 5mo agoFor most things, you can do with capabilities Issue is that it increases friction and you need sudo anyways to set the capabilities. Most web servers would happy to run unprivileged with only CAP_NET_BIND_SERVICE
- lrvick 5mo agoIf you set the appropriate linux capabilities flag on a binary such as sshd at bootup then unprivileged users can bind to 22, no problem. setcap 'cap_net_bind_service=+ep' /usr/sbin/sshd Could even run it as a daemon unprivileged from a home directory with "systemd --user" That said if you have multiple users and want every user to have their own sshd reachable on port 22 on the same machine you probably want to listen on vhost namespaced unix sockets and have something like haproxy listen on port 22 instead. Haproxy could of course also run unprivileged provided it has read access to all the sockets.
- mort96 5mo agoHow do you setcap without root?
- lrvick 5mo agoThe way many including me manage systems without root privileges at runtime is by compiling immutable rootfs images that run in ram with kernel, init, mounting filesystems and assigning any users and privilege assignments, then drop to user privs. That stuff needs to change very seldom, so when you do need to change it you just generate a new tiny rootfs image in a few seconds and reboot to pivot to it or maybe have a kexec trigger if you are feeling fancy. For my primary workstation the entire disk is my home partition and I boot my latest rootfs from a flash drive. In other cases network boot.
- DaSHacka 5mo agoMore than just two levels for sudo, the Linux permission model is completely broken for this very reason. (Also see: https://xkcd.com/1200/ https://xkcd.com/1200/) Honestly, the Android approach is significantly better. (and for that, see Micay's various ramblings posted online)
- exyi 5mo agoOk, so the malware runs a keylogger / clipboard logger, gets the password and runs sudo on it's own. Or replaces your shell by putting exec ~/hackedbash into your bashrc Password on sudo is only useful if you detect the infection before you run sudo
- fragmede 5mo agoCould link it to a yubikey via pam.d so you need a fingerpress to authenticate.
- pastage 5mo agoPhysical attestations are hard to solve, I think it would be nice if all TPMs in laptops had this. Then the problem becomes how do you automate stuff that needs to be done.
- lrvick 5mo agoAnd then the moment you authenticate, the fake sudo still executes its payload. Yubikeys do not fix this issue.
- exyi 5mo agoAt least my password won't leak as often with yubikey, but the attacker can still hack my shell to execute fake sudo. Even if I type /bin/sudo explicitly, there is ptrace, LD_PRELOAD or just replacing the entire bash binary. In practice yubikey sudo keeps you much safer today, as almost nobody uses it and malware won't be prepared for it
- eviks 5mo agoWhy not make a proper link /sudo so you don't have to type out the full path every time, which is very inconvenient? (but the fact that such workarounds are needed still means it's a theater)
- sinsudo 5mo agoAnything that can be modified by an attacker can not be used to secure the sudo command. This is a recursive requirementor hierarchy for secure systems.
- eviks 5mo agoYou can set the permissions so that the attacker can't modify it?
- lrvick 5mo agoYou would need to prevent an attacker from installing shell aliases, or shell config files, or altering any binaries in PATH. Like, sure you could, but you end up with a very useless system. Easier to just use VMs for each security context.
- eviks 5mo agoIs any of this specific to a link vs tyre original full-pathed sudo?
- lrvick 5mo agoA simple LD_PRELOAD command can cause your shell to run "rm -rf /" when you type "/sudo". If your unprivileged user is compromised, you are pretty hosed.
- anthk 5mo agoIt should be a way to make system env vars (profile.d or simlar) as readonly so every users' shell had these set to empty values and unable to change them.
- throwaway7356 5mo agoYeah, works well: $ /usr/bin/sudo() { echo Not the real sudo.; } $ /usr/bin/sudo Not the real sudo. And every other suggestion also doesn't work if the attacker can just replace the shell.
- ChocolateGod 5mo agoSurely if malware has rw access to the home folder, it can adjust the env variables / shell to make this also fake.