Alright, I've read all the forums and other SO posts but to no avail. Been banging my head on the wall for this. I have a very minimal PHP page like this:
<?php
exec('PsExec.exe -accepteula \\\\192.168.10.11 -u "administrator" -p "Ph0nYP@sSw0rd" hostname', $output, $returnVar);
print_r($output);
print_r('Return value is: ' . $returnVar);
?>
It is supposed to simply execute the hostname
command on 192.168.10.11. I execute the page using php.exe mypage.php
but this always results in the following:
Couldn't access 192.168.10.11:
The handle is invalid.
Connecting to 192.168.10.11...
PsExec v2.2 - Execute processes remotely
Copyright (C) 2001-2016 Mark Russinovich
Sysinternals - www.sysinternals.com
I have verified that PSExec works by running the same command from outside of the php page i.e.
PsExec.exe \\192.168.10.11 -u "administrator" -p "Ph0nYP@sSw0rd" hostname
I have verified that the administrator account has access to the
target machine 192.168.10.12 in Control Panel > User Accounts > Give other users access to this computerI have watched a wireshark capture when I execute the PHP page but there is no traffic. So I don't know if it's even successfully launching PSExec.
I have verified the credentials work by going to Run >
\\192.168.10.12\c$ and entering the creds. I am able to browse the
folder.I have tried using PHP's shell_exec and get the same results
So I know the account has access, the creds are good, and that PSExec is working. It seems that once I wrap it inside a php page that something breaks. What does "The handle is invalid" mean here? And what else can I do to troubleshoot or work around it? My goal is to ultimately execute a powershell script on the target box that will use parameters in a POST request to the page. While I'm not married to my current method I'm still very curious as to why it's failing.