1

I created a small script as the root user...

#!/bin/bash

cat /etc/shadow

and set the setuid bit and placed it within the guest folder. When I ran the script as guest, it showed permission denied. Why? I had the root setuid bit set on it which should execute it with the root privileges as root user created the script.

5
  • Despite what the answers from the purported dupe say, if you REALLY want it, you can use setuid scripts on Linux. Even making them unreadable, which regular scripts can't be.
    – user313992
    Commented Sep 23, 2019 at 5:55
  • @mosvy I just tried that trick on my Debian 9. Indeed the unreadable script is executed, but the suid bit of the interpreter script remains ignored. With which system could you verify that?
    – Philippos
    Commented Sep 24, 2019 at 10:49
  • @Philippos You either have your filesystem mounted nosuid or it's an effect of this. I have "fixed" my example for the latter case ;-)
    – user313992
    Commented Sep 24, 2019 at 14:35
  • Latter case here. And as far as I can see, it won't work with /bin/sh being a current dash?
    – Philippos
    Commented Sep 24, 2019 at 15:15
  • @Philippos Since I pass the -p option to sh, it does work with /bin/sh being either a current dash or bash (as that from debian buster). The -p option will cause an error with older versions of dash (or with busybox), I've added a note about that. (btw, I don't get notifications about comments without the at-user)
    – user313992
    Commented Sep 25, 2019 at 15:31

1 Answer 1

1

The reason this doesn't work is that the SUID bit is ignored on interpreted scripts. If you wrote a C program that executed the same command, then it would work.

5
  • So if I set the setuid bit on the "cat" command itself in "/usr/bin/", would it work then?
    – 1zverg
    Commented Sep 21, 2019 at 18:18
  • Yep, that would work too
    – Fox
    Commented Sep 21, 2019 at 18:20
  • But it sounds like a terrible idea. Commented Sep 21, 2019 at 18:49
  • @Henrik Yep that too
    – Fox
    Commented Sep 21, 2019 at 18:50
  • Of course I won't do it lol. I just wanted to be sure whether it would work or not :)
    – 1zverg
    Commented Sep 21, 2019 at 18:53

Not the answer you're looking for? Browse other questions tagged .