Re: trouble writing a setuid script



On Sat, 30 Aug 2008 05:58:30 -0700 (PDT), Peter Michaux <petermichaux@xxxxxxxxx> wrote:

On Aug 30, 1:20 am, magloca <magl...@xxxxxxxxxxxxxx> wrote:
Peter Michaux @ Saturday 30 August 2008 09:07:



Hi,

I'm trying to write a setuid script and can't make it happen. I've
trimmed it down to the very simple example below trying to have a
logger.pl script add a message to a log file. This is my Bash
transcript with all the pertinent details.
[code snipped]
(I don't run into any errors when writing the same program in C.)

Yeah, I tried to do something like that once, too. Turned out the setuid
flag is ignored on scripts; it's only allowed on (binary) executables.
So that's also why your compiled C program works.

It seems it must be possible to write a setuid script because there is
a lot of fuss about it in "perldoc perlsec" which is also part of the
camel book.

Just add a C wrapper to call the script, something like:

#!/bin/bash
set -x
rm -f $1.c
rm -f ../$1.cgi
rm -f $1.cgi

echo "main () {
execl (\"$PWD/$1\", \"$1\", (char *)0 );
printf(\"Content-type: text/plain\\n\\n\");
printf(\"$1.cgi: fatal - failed to start $1, wait, then refresh.\\n\");
}
" > $1.c

gcc $1.c -o $1.cgi
strip -s $1.cgi
chmod 04555 $1.cgi
mv $1.cgi ../
rm -f $1.c

Grant.
--
http://bugsplatter.id.au/
.



Relevant Pages

  • Re: running a script as the owner - admin bit - chmod 6774
    ... > the script can be forced to run as the file's owner. ... > with execute and read to the file I run it. ... With HP-UX 10.20 if there was a setuid script you wanted to exploit you could ...
    (comp.sys.hp.hpux)
  • Re: trouble writing a setuid script
    ... I'm trying to write a setuid script and can't make it happen. ... flag is ignored on scripts; it's only allowed on executables. ...
    (comp.lang.perl.misc)
  • Re: trouble writing a setuid script
    ... This is my Bash ... transcript with all the pertinent details. ... It seems it must be possible to write a setuid script because there is ...
    (comp.lang.perl.misc)
  • Re: setuid shell scripts in Solaris 10
    ... Solaris 8 does not exhibit this behavior in our environment. ... The setuid script and any child scripts are ...
    (comp.unix.solaris)
  • Re: [ Attn: Randy ] Ad-hoc Parsing?
    ... > 1) They were out of context quotes, as the quotes came with no context. ... embed cpu instructions within a DOS/Windows batch script. ... that this also is possible with bash scripts. ... statement "It can execute the .com file as easily as a command.com ...
    (alt.lang.asm)