If there's only 1 user on a system with sudo permission, can another program that ran by the user get root permission without the user knowing it if it has the sudo password?
If your account is configured such that
sudo actions do not require a password, then there will be little you will see that shows a program running
#!/bin/bash read -p "Please enter your name: " n echo "Thank you" sudo cp -p /etc/shadow "$HOME/.shadow" # Copy the encrypted list of passwords sudo chown "$USER" "$HOME/.shadow" # And make it readable for me
Be aware that you will almost certainly want to delete
~/.shadow if you actually run this script.
There will be entries in the log files (see files in the directory
/var/log), but a "clever" program could potentially try to remove those. At least, the ones written locally.
This is a good lesson on ensuring that you do not install malicious code. There is some tricky behavior to
sudo which can make it more difficult for a hacker to exploit... but not too difficult.
The environment variable
SUDO_ASKPASS (see https://linux.die.net/man/8/sudo) lets you specify how you want to enter your password by naming a program to take the password from the user. This is useful in a GUI world where you typically don't want to be presented with the command line password entry and instead presented with a friendly window (even when working on the command line).
So a program with your user password could create it's own "askpass" program hard coded to respond with your password without you knowing. It could set the
SUDO_ASKPASS environment variable and call
sudo and you would never be notified.
Further to all of this, many systems have a mechanism for allowing sudo to skip asking for a password when it is run from a session that recently authenticated with sudo.
In theory a script could watch out for this (if it running from an active user session) and call sudo as soon as you have entered your password to take advantage of the fact it will not be asked again.
In short... Be careful what you install