Perl, suid, and linux headache
Results 1 to 6 of 6

Thread: Perl, suid, and linux headache

  1. #1
    Senior Member
    Join Date
    Jul 2002
    Location
    Texas
    Posts
    168

    Perl, suid, and linux headache

    So im trying to do this lab in perl on a solaris machine. Everything works fine until the program is setuid which it needs to be. What im trying to do is get the full path to the script itself and use that path to create files in that dir.

    Im using the builtin $0 var to get the full path and file name, then using

    $dir = dirname($0); // gets the path name minus the trailing /

    I tried using pwd but that doesnt work unless you call the script from its directory.
    This works fine, until the script is suid, at which point the $dir variable changes to /dev/fd
    instead of /share/longpre/bertka.

    Any ideas on how to get around this another way?
    <chsh> I've read more interesting technical discussion on the wall of a public bathroom than I have at AO at times

  2. #2
    Just Another Geek
    Join Date
    Jul 2002
    Location
    Rotterdam, Netherlands
    Posts
    3,401
    Solaris != Linux...

    Try a small test script
    Code:
    #!/usr/bin/perl
    
    print "name: $0\n";
    To see what happens with $0..

    What happens in the dirname sub?
    Oliver's Law:
    Experience is something you don't get until just after you need it.

  3. #3
    Senior Member
    Join Date
    Jul 2002
    Location
    Texas
    Posts
    168
    $0 == /share/longpre/bertka/path.pl when not setuid
    $0 == /dev/fd/4 when setuid

    im not sure what happens in the dirname sub. I should have made it clear about what the issue was, sorry. Its not with the dirname sub but with perls internal variable $0
    good job on finding my linux/solaris typo.
    <chsh> I've read more interesting technical discussion on the wall of a public bathroom than I have at AO at times

  4. #4
    Elite Hacker
    Join Date
    Mar 2003
    Posts
    1,407
    Seems like a bug. It's probably too late now, but can you just have an argument be the path?


    ./script `pwd`

    Maybe document that there seemed to be some sort of bug and you had to use a workaround.

  5. #5
    Jaded Network Admin nebulus200's Avatar
    Join Date
    Jun 2002
    Posts
    1,356
    A little suprised, I tested myself and confirmed the behaviour, definitely seems like a bug (using the test script):

    [504] user@sol (~)% chmod +sx test.pl
    [505] user@sol (~)% ls -al test.pl
    -rwsr-sr-x 1 user user 33 May 14 07:26 test.pl
    [506] user@sol (~)% uname -r
    5.9
    [507] user@sol (~)% uname -ra
    SunOS sol 5.9 Generic_118558-22 sun4u sparc SUNW,Sun-Fire-280R
    [508] user@sol (~)% ./test.pl
    name: /dev/fd/3
    [509] user@sol (~)% chmod -s test.pl
    [510] user@sol (~)% ./test.pl
    name: ./test.pl

    Is there some reason you can't use pwd ?

    [527] user@sol (~)% ls -al test.pl
    -rwxr-xr-x 1 user sol 193 May 14 07:36 test.pl
    [528] user@sol (~)% chmod +s test.pl
    [529] user@sol (~)% ./test.pl
    name: /dev/fd/3
    CWD: /export/home/user
    Code:
    #!/bin/perl
    
    print "name: $0\n";
    $dir = `pwd`;
    print "CWD: $dir\n";
    There is only one constant, one universal, it is the only real truth: causality. Action. Reaction. Cause and effect...There is no escape from it, we are forever slaves to it. Our only hope, our only peace is to understand it, to understand the 'why'. 'Why' is what separates us from them, you from me. 'Why' is the only real social power, without it you are powerless.

    (Merovingian - Matrix Reloaded)

  6. #6
    Senior Member
    Join Date
    Jul 2002
    Location
    Texas
    Posts
    168
    I didnt want to use pwd as it prints the dir the user is in when they call the script and not the dir the script is in. It was my first choice and i tested it and that was the issue that came up.
    <chsh> I've read more interesting technical discussion on the wall of a public bathroom than I have at AO at times

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •