Linux - Server This forum is for the discussion of Linux Software used in a server related context. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
10-22-2010, 01:22 PM
|
#1
|
Member
Registered: May 2010
Posts: 87
Rep:
|
web interface to some shell command
Hi all,
I want to create for my private use, a simple web interface to manage some easy task (useradd, userdel, passwd, etc...).
I have some basic knowledge of PHP; how can I realize this? PHP as module or CGI? Which is better in this case?
Thankyou
|
|
|
10-22-2010, 02:30 PM
|
#2
|
LQ Guru
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS, Manjaro
Posts: 6,357
|
web interface to some shell command
Better in this case is to implement webmin.
If unfamiliar, google for it.
We use it a lot!
|
|
|
10-22-2010, 03:13 PM
|
#3
|
LQ Veteran
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
|
From a security standpoint, you really don't want to implement root-level commands in a web interface unless you do like Webmin did and create a completely separate server infrastructure for it. Having your normal web server capable of accessing root-level commands is just asking for trouble.
|
|
|
10-23-2010, 12:31 PM
|
#4
|
Member
Registered: May 2010
Posts: 87
Original Poster
Rep:
|
Quote:
Originally Posted by Hangdog42
Having your normal web server capable of accessing root-level commands is just asking for trouble.
|
Ok, but my web server is not world-accessible from Internet!
It's only for testing / studying
|
|
|
10-24-2010, 04:55 AM
|
#5
|
LQ Newbie
Registered: Dec 2008
Location: NP
Posts: 28
Rep:
|
Quote:
Originally Posted by skoinga
Ok, but my web server is not world-accessible from Internet!
It's only for testing / studying
|
Boss,
CGI scripting is also best but
Go for PHP programming. And add .htaccess restriction and other firewall / TCP wrapper securities to access those .php pages.
http://phpterm.sourceforge.net
Google through it. U can get it.
Last edited by abhandari; 10-24-2010 at 04:58 AM.
|
|
|
10-24-2010, 08:01 AM
|
#6
|
LQ Veteran
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
|
Quote:
Originally Posted by skoinga
Ok, but my web server is not world-accessible from Internet!
It's only for testing / studying
|
As long as you realize that this kind of access isn't acceptable in the real world. Either CGI or PHP will do what you want, but you'll likely have to look into using sudo to get the commands to execute.
|
|
|
10-24-2010, 11:37 AM
|
#7
|
Member
Registered: Aug 2008
Posts: 86
Rep:
|
Hi THere,
I was involved in the creation of a web based front end for a third party telephony system (*Asterisk) running on linux.
Here are some code snippets ...
if(strstr($ID, 'dhcp'))
{
if($ID == 'dhcp_1') // DHCP
$command = '/usr/bin/sudo /usr/sbin/rcdhcpd start'; // /etc/init.d/dhcpd GENERIC
else if($ID == 'dhcp_2')
$command = '/usr/bin/sudo /usr/sbin/rcdhcpd stop';
else
$command = '/usr/bin/sudo /usr/sbin/rcdhcpd restart';
// run command
exec($command);
// run status check
exec('/usr/bin/sudo /usr/sbin/rcdhcpd status', $output, $return_var);
}
// another snippet
$command = 'rm -rf ' . $temp_folder;
exec($command);
// write to socket (authentication)
if($socket)
{
fputs($socket, "Action: Login\r\n");
fputs($socket, "UserName: " . ASTERISK_UNAME . "\r\n");
fputs($socket, "Secret: " . ASTERISK_SECRET . "\r\n");
fputs($socket, "Events: off\r\n\r\n");
// loop through output from Asterisk
$authentication_flag = false;
while ($buf = fread($socket, 512))
{
if(feof($socket))
break;
if(strstr($buf, "Response: Success"))
{
$authentication_flag = true;
break;
}
if(strstr($buf, "END COMMAND"))
break;
}
if($authentication_flag == false)
{
echo 'No Asterisk !';
die();
}
}
Is this poor practice ?
If so, then I would be curious to know web hosting companies provide web front ends to their linux based web hosts.
Surely they too must be running root commands using sudo ....
Any ideas ?
regards,
Steven Matthews
|
|
|
10-24-2010, 06:44 PM
|
#8
|
LQ Veteran
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
|
Quote:
Is this poor practice ?
If so, then I would be curious to know web hosting companies provide web front ends to their linux based web hosts.
Surely they too must be running root commands using sudo ....
|
I think the answer to this depends upon how they've implemented the front end and how sudo is used. If they have limited sudo access to the commands needed to administer the system, then they probably have an acceptable risk. The thing they should be defending against is someone compromising the web server and then having system access as that user. If they've given blanket sudo privileges, then there is the potential for real trouble. In your first snippet, you're using sudo to run rcdhcpd. If your sudoers file limits the web users access to just that command, then it is probably OK. Someone compromising the web server would only have root acces to rcdhcpd, which hopefully won't allow them to escalate.
|
|
|
11-07-2010, 03:52 AM
|
#9
|
Member
Registered: Aug 2008
Posts: 86
Rep:
|
Hi again,
Web development has progressed more and more into the realm of web applications where LAMP technologies are really being taken to their limit.
I would like to know more about how linux servers can be configured and how to communicate with 3rd party backend tools (like Asterisk, see snippets above) BOTH using a web interface. For example CISCO devices like routers can be configured from web pages and the commonly used Plesk panel (Web Hosting Control Panel) offers considerable opportunity for backend manipulation.
Short of using the sudoers file and opening socket connections what other avenues exist and what would be considered the
most secure ?
regards,
Steven Matthews
|
|
|
11-07-2010, 06:35 AM
|
#10
|
LQ Veteran
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
|
Quote:
I would like to know more about how linux servers can be configured and how to communicate with 3rd party backend tools (like Asterisk, see snippets above) BOTH using a web interface. For example CISCO devices like routers can be configured from web pages and the commonly used Plesk panel (Web Hosting Control Panel) offers considerable opportunity for backend manipulation.
|
The problem isn't the use of a web interface for doing admin work, the problem is keeping the admin work separated from the "normal" work such that a compromise of the normal activities doesn't allow access to the admin functions. Look at Webmin as an example. It has a reasonable web interface for lots of admin work, but it is completely and totally separted from the normal Apache stack. Webmin uses its own server and runs under a different user. Similarly the CISCO interface is intended only for admin work, and there isn't the ability to use a router as a general purpose web server. Where people get into trouble is when they try to use the normal LAMP stack to do admin functions. There is one thread around here where the sysadmin gave the apache user full root rights so that he could run a couple of admin commands in a web interface. That means that if the LAMP stack gets compromised (say through a poorly written PHP site), the attacker now has full root privileges and essentially owns the machine.
|
|
1 members found this post helpful.
|
11-08-2010, 12:18 AM
|
#11
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.x
Posts: 18,443
|
As per Hangdog, some stuff like CISCO or Cups (Linux printer daemon) actually don't use the std full Apache server.
Instead, they include a mini webserver in their own code ie a daemon that listens on a nominated port (eg 10000 for webmin, cups port 631 http://en.wikipedia.org/wiki/CUPS ) which can only run as that user and only run the cmds reqd by that SW.
There's nothing to stop you faking up a very restricted webserver; the user can't tell the difference so long as it looks / behaves like Apache within a limited realm.
Last edited by chrism01; 11-16-2010 at 10:59 PM.
|
|
|
11-13-2010, 07:25 AM
|
#12
|
Member
Registered: Aug 2008
Posts: 86
Rep:
|
Thanks for all your useful comments ...
RE Better in this case is to implement webmin.
I wonder how web hosting companies are able to run linux commands from their web interfaces. A common interface is 'Plesk panel' (Web Hosting Control Panel) which offers a whole lot of functionality from creating sub domains to creating new databases which I assume require root priveleges. Do they too use their own bespoke restrictive web servers ?
I created a web front end for third party software (Asterisk server) using sudoers file and sockets connections ....
How could I have integrated webmin into this system ?
Can webmin be integrated with Apache for admin tasks ?
regards,
Steven Matthews
|
|
|
11-13-2010, 08:36 AM
|
#13
|
LQ Veteran
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
|
Quote:
Originally Posted by ksmatthews
I wonder how web hosting companies are able to run linux commands from their web interfaces. A common interface is 'Plesk panel' (Web Hosting Control Panel) which offers a whole lot of functionality from creating sub domains to creating new databases which I assume require root priveleges. Do they too use their own bespoke restrictive web servers ?
|
If you do some research into things like Plesk or cpanel, you will find an awful lot of security problems with this kind of approach. However, in the examples you cited, you can actually do most of those tasks without root privileges. Lets look at subdomains. As long as you can edit the relevant apache config file, you can do the work necessary to add them. You could solve this by having those files owned by a non-root group that has read/write privileges. The only place where you would need root privileges is to restart the server, and that can be handled by sudo that allows the user to run just apachectl (or an appropriate script) as root.
Mysql is a different case. Those users are completely different from system users and have nothing in common (except maybe the name). And in Mysql, the ability to create a database can be granted to normal mysql users, and doesn't require system root privileges.
Quote:
I created a web front end for third party software (Asterisk server) using sudoers file and sockets connections ...
|
It depends upon how you used the sudoers file. If you gave the web user blanket sudo permissions, that is an extraordinarily bad idea. If you limited them to just the commands they needed to run/modify Asterisk, then it might be OK. Really the question to be asking is what happens if the front-end gets compromised? Does that give the attacker root privileges or do they have to find ways to escalate? Also in this case, could an attacker get access to Asterisk and give themselves free calling without having to escalate to root?
Quote:
How could I have integrated webmin into this system ?
|
If standard webmin doesn't have the needed functions, there are modules available, or you can write your own module.
|
|
|
All times are GMT -5. The time now is 08:52 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|