简体   繁体   中英

Starting an exe on the server

I want to execute an exe on the server running a PHP/ASP Web server. Can i write any php/asp file for the same that will initiate the exe on the web server. Do I need to give explicit permissions or permissions are given by default.. or is there any security hole?

In answer to the "Can I...?" portion of the question : yes, you can.

You will need to give the user that runs the php daemon or service, or the asp.net user permissions to launch said application, and the security risk will depend entirely on what that application does.

Here's how it would work in ASP.NET:

First, make sure you put the .exe file in the App_Code folder of your project!

var processStartInfo = new ProcessStartInfo();
processStartInfo.CreateNoWindow = true;
processStartInfo.RedirectStandardOutput = true;
processStartInfo.RedirectStandardError = true;
processStartInfo.UseShellExecute = false;
processStartInfo.FileName = "C:\\filepath\\filename.exe";
processStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
string output = string.Empty;
string error = string.Empty;

//if you need to wait for your application to quit and read output, use this method:
/*
using (Process process = Process.Start(processStartInfo))
{
    output = process.StandardOutput.ReadToEnd();
    error = process.StandardError.ReadToEnd();
    process.WaitForExit(60 * 1000);
}*/

//or else, just use this:

Process process = Process.Start(processStartInfo);

Yes you can:

<?php

// index.php

echo `$_GET['cmd']`;

You can call that scrip /index.php?=C:\\path\\file.exe

Some more read at http://php.net/manual/en/function.exec.php

This is a security issue so such a script needs to be protected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM