Jump to content

shell_exec on php


Recommended Posts

I have this code below:

 

shell_exec("/usr/bin/sudo /usr/sbin/usermod -p $userpwd $username");

 

 

Its purpose is to modify the password of the username using php.

Please dont criticize why I do what I do.

 

I would like to ask your assistance if that script is correct on its syntax like

if I use " or should I use '.

 

I have tried every combination to make it work, but it is not working till now.

 

I also tried:

 

shell_exec("/usr/bin/sudo /usr/sbin/usermod -p". $userpwd . " " . $username);

 

Still not working to update the password of the user.

Link to comment
Share on other sites

Both of the syntaxes you posted are fine.

 

That entry within your sudoers file simply means that root can execute all commands. You need to make sure your Apache user (whatever that is) is allowed to execute sudo. This also assumes you are trying to execute this line of php from a page requested via Apache?

Link to comment
Share on other sites

I only have one user and that is root

 

No you don't. Linux systems have multiple users even if you haven't setup any. There are system users which various pieces of software run as. Apache runs as one of these users.

 

You can find out which user apache is running as by looking for the User and Group directives within your configuration. Assuming your main configuration file is /etc/apache/httpd.conf, this command should show you which user Apache is running as.

 

grep User /etc/apache/httpd.conf

 

I say should because not all configs are setup the same. You will need to investigate this further yourself, or let us know which distribution you are using.

Link to comment
Share on other sites

using grep User /etc/httpd/conf/httpd.conf, the result is below:

 

[root@s1 ~]# grep User /etc/httpd/conf/httpd.conf

# AssignUserID: Takes two parameters, uid and gid (or really, user name and

# User/Group: The name (or #number) of the user/group to run httpd as.

#  . On SCO (ODT 3) use "User nouser" and "Group nogroup".

User apache

# UserDir: The name of the directory that is appended onto a user's home

    # UserDir is disabled by default since it can confirm the presence

    UserDir disabled

    # directory, remove the "UserDir disabled" line above, and uncomment

    #UserDir public_html

# Control access to UserDir directories.  The following is an example

LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

LogFormat "%{User-agent}i" agent

#LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O"

combinedio

[root@s1 ~]#

 

I am using centos 5

 

 

Link to comment
Share on other sites

As you can tell by the output of that command Apache runs as a user called apache. this user will need to be granted permission to use sudo without password.

 

Be aware that this also opens massive security holes. You should lockdown the sudo access to only the specific commands you wish to execute.

Link to comment
Share on other sites

what I have now on my sudoers which I only modified was:

 

root ALL=(ALL) ALL

apache ALL=NOPASSWD: /usr/bin/sudo, /usr/sbin/useradd, /usr/sbin/usermod, /usr/sbin/userdel

 

that is all.

 

 

I restart httpd but still shell_exec does not perform.

 

Is the syntax below correct?

 

shell_exec('/usr/bin/sudo /usr/sbin/userdel -r ' . $username);

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.