A lot depends on how your server is configured. Are you using mod_suexec? If so, what have you set the CGI user to for your virtual host? Is that user given rights in the sudoers file? If not, what rights have you given the server user (e.g. apache) in the sudoers group? Without mod_suexec all scripts run with the rights of the server-wide CGI user (i.e. the user directive in your apache configuration file)

Do you have FollowSymLinks turned on? What is the <Directory> directive set to for /usr/bin, /usr/sbin? On a secure server you will probably have told Apache not to access those directories at all and following symbolic links is probably turned off as well.

In general, exercising sensitive root level commands through a web interface is a really bad idea security wise. To implement it you would have to violate a key security principle: give services only the rights they need to run and no more. Most of the changes you would have to make would also make your server in general wide open to attack. For example, adding apache to sudoers with ALL rights would essentially let anyone who hacked into your server account also be able to root your entire machine. Knowing the password for the apache user would be enough to run any script for which the apache user had sudoer rights.

And if you've hard coded the password in the script (your code looks like you have) or turned off the password requirement in the sudoer's file because prompting for it got in the way of your CGI script, you'll have even more problems. Even if you were using mod_suexec anyone with rights to install and run CGI scripts for that particular virtual host would share your root privileges with you!

Even if it is a pain, you are still better off doing your root level administration via an ssh connection rather than the web interface. You have much more control over who gets what rights that way.

If you really must do web based root level administration, you would be better off

But again, I still think this is a really bad idea. Use ssh, preferrably on an account with PPK only access.

Best, beth

Update: added comments about mod_pam


In reply to Re: Executing Sudo Console via Web by ELISHEVA
in thread Executing Sudo Console via Web by ecuguru

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.