+ Post New Thread
Results 1 to 11 of 11
Web Development Thread, PHP commands in Coding and Web Development; I am trying to put a command line through some php I have but not having any luck. It seems ...
  1. #1
    Silverman's Avatar
    Join Date
    Oct 2007
    Location
    Worksop, Nottinghamshire
    Posts
    50
    Thank Post
    15
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    PHP commands

    I am trying to put a command line through some php I have but not having any luck.

    It seems quite simple but I cannot get it working. I want to use the shutdown command within php using the system or exec functions. If I use the following code I get an access denied, and if i replace the ip address with a host name I get a host unreachable error.
    Heres the line:
    <?php
    system("shutdown -r -m xxx.xxx.xxx.xxx");
    ?>

    Thanks.

  2. #2

    CESIL's Avatar
    Join Date
    Nov 2006
    Location
    Hampshire
    Posts
    1,403
    Thank Post
    109
    Thanked 267 Times in 198 Posts
    Rep Power
    168
    I would have to guess that this is a permissions problem.

    If the page containing this code is running on a server then it will probably be using the anonymous user account which would not normally have permission to do this sort of thing.

    What web server is this running on, IIS?

  3. #3
    Silverman's Avatar
    Join Date
    Oct 2007
    Location
    Worksop, Nottinghamshire
    Posts
    50
    Thank Post
    15
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    I just have it running locally on wampserver so that i can work with php.

  4. #4

    Join Date
    Nov 2007
    Location
    Preston
    Posts
    98
    Thank Post
    2
    Thanked 4 Times in 4 Posts
    Rep Power
    14
    probably easier to use backticks whilst debugging.

    $output = `shutdown etc`;
    print $output;

    should give you the response.

  5. #5
    Silverman's Avatar
    Join Date
    Oct 2007
    Location
    Worksop, Nottinghamshire
    Posts
    50
    Thank Post
    15
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    'Access is denied.' still

    I assume i need to embed some credentials somewhere or something along these lines.

  6. #6

    Join Date
    Nov 2007
    Location
    Preston
    Posts
    98
    Thank Post
    2
    Thanked 4 Times in 4 Posts
    Rep Power
    14
    Yea at least that proves that.

    i know with nix you could use posix_setuid to create a suid php file but not sure with winblows.

    depends what uid apache is running as, its easier to do it with IIS.

    what wamp are you using? a fully packaged one or did you build it yourself?

  7. #7
    Silverman's Avatar
    Join Date
    Oct 2007
    Location
    Worksop, Nottinghamshire
    Posts
    50
    Thank Post
    15
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Currently using wamp 2.0, a ready packaged one.

  8. #8

    Join Date
    Nov 2007
    Location
    Preston
    Posts
    98
    Thank Post
    2
    Thanked 4 Times in 4 Posts
    Rep Power
    14
    I'd try adding permissions for 'everyone' to cmd.exe and c:\windows\system32\shutdown.exe too then, see how that goes then think about refining those permissions to not include 'everyone'

  9. #9
    Silverman's Avatar
    Join Date
    Oct 2007
    Location
    Worksop, Nottinghamshire
    Posts
    50
    Thank Post
    15
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    No luck unfortunatly.

  10. #10

    Join Date
    Nov 2007
    Location
    Preston
    Posts
    98
    Thank Post
    2
    Thanked 4 Times in 4 Posts
    Rep Power
    14
    Yeah, you'll have to use runas i think

    something like

    `runas /noprofile /userOMAIN\administrator shutdown -r -m xxx.xxx.xxx.xxx`

    the unfortunate thing is runas takes the password via <STDIN>. so you would have to use sanur.exe (google it if you dont know it).

    the other option, and the slightly more fun one, is to use proc_open() within php.

    something like:

    PHP Code:
    <?php
    $descriptorspec 
    = array(
       
    => array("pipe""r"),  // stdin is a pipe that the child will read from
       
    => array("pipe""w"),  // stdout is a pipe that the child will write to
    );

    $cwd '/tmp';
    $env = array('some_option' => 'aeiou');

    $process proc_open('runas /noprofile /user:DOMAIN\administrator shutdown -r -m xxx.xxx.xxx.xxx '$descriptorspec$pipes$cwd$env);

    if (
    is_resource($process)) {
        
    // $pipes now looks like this:
        // 0 => writeable handle connected to child stdin
        // 1 => readable handle connected to child stdout
        // Any error output will be appended to /tmp/error-output.txt

        
    fwrite($pipes[0], 'YOURADMINPASSWORD');
        
    fclose($pipes[0]);

        echo 
    stream_get_contents($pipes[1]);
        
    fclose($pipes[1]);

        
    // It is important that you close any pipes before calling
        // proc_close in order to avoid a deadlock
        
    $return_value proc_close($process);

        echo 
    "command returned $return_value\n";
    }
    ?>
    alot more fun

  11. #11

    Join Date
    Aug 2005
    Location
    London
    Posts
    3,154
    Thank Post
    114
    Thanked 527 Times in 450 Posts
    Blog Entries
    2
    Rep Power
    123
    Can PHP do WMI calls? If so, it might be easier to do the shutdown like that - you can put appropriate credentials in the call to connect to the WMI namespace.

    the other thing to think about if this doesn't work is that it may not be that you don't have permission to access the file "shutdown.exe" but you don't have permission to actually shutdown a remote system. What security context does apache run under? If it's a local, low privilege account then even though it can read shutdown.exe it won't be able to run it. Similarly, if it's localsystem then you have no rights to talk to the network so shutdown would fail.

SHARE:
+ Post New Thread

Similar Threads

  1. script commands
    By chalkwellstu in forum Scripts
    Replies: 16
    Last Post: 29th January 2008, 04:08 PM
  2. Server 2003 run commands.
    By starscream in forum Wireless Networks
    Replies: 3
    Last Post: 26th June 2007, 10:49 AM
  3. VLAN Simulator - Commands
    By Nij.UK in forum Wireless Networks
    Replies: 1
    Last Post: 20th February 2007, 01:27 PM
  4. unix and sql commands
    By danIT in forum General Chat
    Replies: 9
    Last Post: 14th February 2007, 01:19 PM
  5. Avantis CDServe shortcut commands
    By WithoutMotive in forum How do you do....it?
    Replies: 2
    Last Post: 18th July 2006, 10:36 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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