Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re^4: On being 'critical'

by ikegami (Patriarch)
on Dec 15, 2006 at 00:26 UTC ( [id://589950]=note: print w/replies, xml ) Need Help??


in reply to Re^3: On being 'critical'
in thread On being 'critical'

And if the user decides to type '|rm -rf' as an argument to a perl script, they could just as easily type 'rm -rf' at that same command line.

What about when the script runs as a different user than the one calling the script? This could be used to run a command with greater priviledge than one normally has.

For example, given mysetuid.pl

print <>;

An attack:

mysetuid.pl 'cat /etc/shadow |'

Well, at least taint catches this problem:

Insecure dependency in piped open while running with -T switch

Update: Oops, I guess just /etc/shadow would have worked in this case!

Replies are listed 'Best First'.
Re^5: On being 'critical'
by BrowserUk (Patriarch) on Dec 15, 2006 at 01:21 UTC

    As you point out, if real and effective user ids are different, taint mode is enabled automatically. So even if a script relying upon <> is accidently given the setuid bit, nothing nasty happens. That means the attack is not an attack.

    My question still stands.


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      As you point out, if real and effective user ids are different, taint mode is enabled automatically. So even if a script relying upon <> is accidently given the setuid bit, nothing nasty happens. That means the attack is not an attack.

      Except that taint doesn't stop you opening a file for reading. So, is there anything that taint considers opening "for reading", and which one would not be able to invoke using the 3-argument open? Well, there is, and it's hardly ever seen:

      open(FH, '<&=0');

      The special <&=n sequence instructs Perl to duplicate an existing filehandle. What interesting things can setuid programs have open that an attacker may wish to read? How about /etc/passwd after a getpwent() call?

      perl -T -MFcntl=SEEK_SET -e'getpwent(); open(FH,q{<&=3}) or die $!; se +ek(FH,0,SEEK_SET); print <FH>'

      When running as root, the getpw* calls open /etc/shadow to read the password. My box closes the file immediately after, but do you trust every system to do that?

      Network sockets, configuration files, or anything else that uses a filehandle is fair game for this attack. A setuid program that has open filehandles to privileged resources runs the very real risk of revealing information it shouldn't if you can get it to use a 2-argument open with user input.

      Remember, taint doesn't help you here. We're opening a file for reading. ;)

      How about a web application where the user provides a filename? A bit contrived, sure, but I think it fits the criteria.

        I don't know much about web apps, so you tell me. Is there any way that input from a user via a web app will be used by <>, without the programmer explictly assigning it to @ARGV? Even then, shouldn't all cgi scripts have taint mode enabled?

        If the programmer is going to ignore taint or detaint and then assign unvetted filenames from an unknown user into @ARGV, do you think that changing the magic open to use the 3-arg variant will stop them?

        Aren't they just as likely to use the 2-arg open themselves, or a piped open, or IO::Pipe or $secretInfo = `cat $filename`;?

        Also, don't most cgi scripts run under userids that have specifically restricted privileges, and rooted to heavily restricted portions of the server directory space specifically to prevent or severally restrict the possibility of this kind of damage?


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://589950]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-04-25 23:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found