Getting access is denied for cmd command using php function

后端 未结 1 1261
说谎
说谎 2021-01-25 04:00

I am running PHP under IIS 6.

When I use any PHP function to run cmd commands (like exec() or system()), it always shows \"Access is denied\".<

1条回答
  •  -上瘾入骨i
    2021-01-25 04:24

    When you execute some command using exec, that command will be executed with the user account that is running IIS (which tipically is IUSR_«machine-name» on IIS 6), so your project's permissions don't have nothing to do with this.

    What you need to do is to chance the permissions of the file C:\Windows\System32\cmd.exe and add permissions for IUSR_«machine-name».

    Besides this, you'll probably need to use CACLS to change the access control list. Replace IUSR_MachineName on the following command for the user executing PHP and then execute this command:

    CACLS c:\windows\system32\cmd.exe /E /G IUSR_MachineName:F
    

    If you get an error and can't change the ACL, your last resource is to execute the following command first:

    takeown /F c:\windows\system32\cmd.exe
    

    You also might need to set the correct permissions and ACL for the commands you're trying to execute (for eg C:\Windows\System32\schtasks.exe)

    Note: Do this with caution though. If you have some vulnerability that allows your users to execute commands, it can have nasty consequences.

    0 讨论(0)
提交回复
热议问题