Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I've read somewhere that when you run a script file with SUID, all the commands in the script file will have the owner's permissions. The same with SGID. So I have a test:
Script file:
Code:
-rwsr-xr-x myacc myacc usertest
Content:
Code:
whoami
cat secret.txt
Text file:
Code:
-rw------- myacc myacc secret.txt
Content: not your concern .
I login as user "youracc", execute the script, and this is the result:
Following the second link from Mr. C., I found this line of script:
cp /bin/sh /tmp/sh; chown root /tmp/sh; chmod 4755 /tmp/sh
If I get it right, it means: copy a shell to /tmp, set the shell's owner to be root, set SUID for the shell. Now we have a shell which can run as root .
I've tried running the script and "chown: Operation not permitted" is what I've received. It makes me confused: to do a chown, we must have root privileges (actually I don't know the differences between "to be root" and "to have root privileges" ), using sudo or something like that. But if we can "sudo", or have root privileges, why do we want to have a shell which "runs as root" ?
A user and a group are simple concepts in Unix/Linux. All processes have a UID/GID/EUID/EGID. The acronyms should be obvious, with the exception being the E, meaning "effective".
To be root is layman's terms to be logged in as root, or to have a shell that has been created with su or sudo to be a root shell. This is nothing more than a process running (shell) with UID=0.
To have root privileges means the process is running as UID=0. I'll ignore GID/EGID, as these group counterparts apply in similar fashion.
It should be clear that UID=0 is what determines permission to access a resource for a given mode (read/write/execute/examine). Names like "root", "toor", "admin" are all just decorative, and administrative candy above UIDs. Same for groups.
is EXTREMELY dangerous and highly insecure. DON'T DO IT, find another way.
As an aside, /tmp is often mounted with the nosetuid flag to DISABLE setuid, and often the noexec flags to deny running an executable from /tmp.
chown requires the process running it to have the UID of either the owner of the object itself, or UID=0. And chmod requires UID=0 if the running process is not the owner, or belong to one of the object's groups if group write is enabled.
- Thanks for reminding me of EUID . Btw, my /tmp is not mount separately, it stays inside / partition.
- The code is a way to get a root shell by exploiting SUID
- After the "cp" command, I am the owner of /tmp/sh:
Then why can't I chown it ? The /tmp has permissions: rwxrwxrwt, and I'm using Ubuntu 8.04. Maybe the code above is written for older linux OSs, which could be vulnerable for this.
A non-root user can NEVER chown files to another user (eg. you can't force files onto another user; consider how this would be a DoS attack on a user with quota's enabled). Only root can do this.
The code above looks like code I've seen from a piece of scripted malware, try to gain a root shell, and planting a trojan horse.
The result in Ubuntu is exactly what I expected, but I can't understand the result in RHEL. As I understand, linux will determine privileges of the process from EUID.
Please explain what happened to my knowledge .
Thanks in advance.
@Mr. C.: Thanks for giving a clue, but it didn't help much, because for avoiding troubles related to SELinux (I've heard SELinux is quite difficult to config), I've disabled SELinux from installing steps of RHEL 4. I've just checked it again, and its state was currently disabled.
Please give me more details (I hope this time you'll leave me more than one word ). Thanks.
defaults: Use default options: rw, suid, dev, exec, auto, nouser and async
PS: by the way, please pay attention to my above result in RedHat: EUID = 0 but `whoami` still calls me 'myacc', and I cannot read /etc/shadow file. Could it be RedHat user authentication based on RUID, not EUID ?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.