The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Running shell script as root from php page

Discussion in 'cPanel Developers' started by edlemmers, Jun 22, 2016.

Tags:
  1. edlemmers

    edlemmers Member

    Joined:
    Jan 30, 2013
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Hello,

    I have successfully created a php file that using the WHM API to create an account. I also have a collection of shell and perl scripts that created a while back that install a CMS into an account. I have been running these scripts thru SSH as root for a long time. What I would like to do is run that script as root from a php page using the CPanel account created in the script that uses the WHM API. How would I go about doing this?

    Thanks!
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,678
    Likes Received:
    654
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello,

    Could you provide a more specific example of this, and more information on what you are attempting to accomplish?

    Thank you.
     
  3. edlemmers

    edlemmers Member

    Joined:
    Jan 30, 2013
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator

    With the WHM API, you can access the WHM features by building a URL of the form:
    Code:
    https://hostname.example.com:2087/cpsess##########/json-api/somekeyword?someparamname=somevalue&etc=etc

    and then simply directing to this URL, or setup AJAX POST, or use a cURL operation to POST. One thing that would work very nicely is if I could setup my own keyword to run my custom script through this API interface. I would then be able to run my script with very high privileges while taking advantage of the security of the API system. If it is not possible to do this, is there some other way to run shell scripts as root through a web pages of some sort?
     
  4. edlemmers

    edlemmers Member

    Joined:
    Jan 30, 2013
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Another possible way to do what I need to do: How would I run my script from the post hook in createacct?

    Thanks
     
  5. Islandhosting

    Islandhosting Member

    Joined:
    May 15, 2015
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    Location:
    Canada
    cPanel Access Level:
    Root Administrator
    Twitter:
    I might misunderstand what you're asking, but cPanel plugins (PHP or not) can't run scripts as root or any other UID besides that of the user who is using the plugin, as far as I know. This makes a lot of sense security-wise.

    cPanel's APIs do provide a way to call routines with escalated privileges though:

    Guide to API Privilege Escalation
     
Loading...

Share This Page