views:

107

answers:

2

It's executed when browsing a PHP file(http://localhost/filename.php) on windows.

The web server is Apache.

I think it should be divided into 2 steps:

1.found user of Apache threads

2.give enough permissions to that user towards "F:/tmpJob/"

I checked httpd.conf and found:

User daemon
Group daemon

But there is no "daemon" user on windows. How to find the real user of apache threads?

A: 

Er... rm -rf is not a valid command in Windows. The delete command in Windows/DOS is del.

The equivalent of rm -rf FILEPATH in Windows is del /S /Q PATH to delete recurSively and be Quiet about it (i.e. don't give the "are you sure?" prompt).

Amber
I've installed UnixUtils on windows.I can run that command successfully in a prompt.
Shore
Then I'd suggest starting up the Task Manager (Start->Run, enter `taskmgr` and hit OK) and then make sure you're viewing processes from all users, find the Apache process in the list, and see what user it's listed as running as. If you're running it as a service, it's probably SYSTEM.
Amber
You mean by guess?
Shore
Note that you may need to turn on the User Name column in the process view - go to the View menu and then choose Select Columns.... to enable it.
Amber
Just checked that "SYSTEM" has complete control on that directory,so it's not "SYSTEM"
Shore
All user names:Administrator,LOCAL SERVICE,NETWORK SERVICE,SYSTEM.
Shore
Did you find the apache process in the Task Manager application?
Amber
All the 4 kinds of users have complete control on that directory now,but still failed.
Shore
It's httpd,and is running as System.But when you visit a page,it'll fork a new thread,which is not running as System.And can't see from Task Manager !
Shore
What output do you get back from exec()? Since it returns the resulting output of the command back in an array-of-lines format, you might want to print_r() the result and see if that sheds any light on why it's failing.
Amber
no output at all.
Shore
Check your path environment variable, or try using an absolute path to the `rm` program.
nikc
Oh my god,it worked after using absolute path(F:/UnxUtils/usr/local/wbin/rm)!But I've put the directory of "F:/UnxUtils/usr/local/wbin" into PATH of SYSTEM,why?
Shore
A: 

You can get the owner of the current process e.g. with getmypid() and the wmi class WIN32_PROCESS

<?php
$pid = getmypid();
$wmi = new COM ('winmgmts:{impersonationLevel=impersonate}//./root/cimv2');
$result = $wmi->execquery("Select * from Win32_Process Where ProcessID = '$pid'");

foreach($result as $row) {
  $owner = new VARIANT('');
  $domain = new VARIANT('');
  $row->GetOwner($owner, $domain);
  echo ' exe: ', $row->ExecutablePath, ' owner:', $owner, ' domain:', $domain, "\n";
}

You should probably also check the output of

<pre><?php passthru('set'); ?></pre>

esp. the PATH variable. Maybe the UnixUtils are not "in" the PATH of the SYSTEM account.

VolkerK
I've ensured both Administrator and System has access to UnixUtils in PATH.
Shore
Output of your code is:exe: F:\wamp\bin\apache\apache2.2.11\bin\httpd.exe owner:SYSTEM domain:NT AUTHORITY.
Shore
And SYSTEM has complete control to those directories.
Shore
Oh my god,it worked after using absolute path(F:/UnxUtils/usr/local/wbin/rm)! But I've put the directory of "F:/UnxUtils/usr/local/wbin" into PATH of SYSTEM,why?
Shore