Find the answer to your Linux question:
Results 1 to 3 of 3
ok here is the deal, I need to read, from a browser, the contents of /var/spool/cron Of course its permissions are set to be very unfriendly to PHP (running as ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Apr 2003
    Posts
    57

    how to run a root process from php (not on CLI either)


    ok here is the deal, I need to read, from a browser, the contents of /var/spool/cron

    Of course its permissions are set to be very unfriendly to PHP (running as a linux user account) to read that folder.

    So, I tried making a file in /home called /home/readcrons.php, I added the hashbang at top and chown'd to root, and made it executable. The file itself is pretty simple and there is no security risk in the file.

    Now, in php, I tried:

    <?php
    echo `/home/readcrons.php`;
    ?>

    It spit at me and said you don't have the permissions. I presume that even though the FILE is owned by root, it acts with the permissions of the user calling it, is this correct?

    Is there ANY way I can make this work? There must be something built in that is simple and elegant..

    Thanks,
    Sam

  2. #2
    Linux Newbie nplusplus's Avatar
    Join Date
    Apr 2010
    Location
    Charlotte, NC, USA
    Posts
    106
    Quote Originally Posted by samf View Post
    ok here is the deal, I need to read, from a browser, the contents of /var/spool/cron

    Of course its permissions are set to be very unfriendly to PHP (running as a linux user account) to read that folder.

    So, I tried making a file in /home called /home/readcrons.php, I added the hashbang at top and chown'd to root, and made it executable. The file itself is pretty simple and there is no security risk in the file.

    Now, in php, I tried:

    <?php
    echo `/home/readcrons.php`;
    ?>

    It spit at me and said you don't have the permissions. I presume that even though the FILE is owned by root, it acts with the permissions of the user calling it, is this correct?

    Is there ANY way I can make this work? There must be something built in that is simple and elegant..

    Thanks,
    Sam
    Okay, so, there is this rope called "setuid." All you have to do is tie a knot with it, but once that is done, you'll find it really hard not to hang yourself.

    N

  3. #3
    Just Joined!
    Join Date
    Mar 2008
    Posts
    20
    On most *nix systems, setuid is disabled for scripts.
    An alternative is to create a binary program (with setuid) that runs the script.
    See this howto.

Posting Permissions

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