LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 10-22-2010, 01:22 PM   #1
skoinga
Member
 
Registered: May 2010
Posts: 87

Rep: Reputation: 0
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
 
Old 10-22-2010, 02:30 PM   #2
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 5,597

Rep: Reputation: 2691Reputation: 2691Reputation: 2691Reputation: 2691Reputation: 2691Reputation: 2691Reputation: 2691Reputation: 2691Reputation: 2691Reputation: 2691Reputation: 2691
web interface to some shell command

Better in this case is to implement webmin.
If unfamiliar, google for it.
We use it a lot!
 
Old 10-22-2010, 03:13 PM   #3
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
Blog Entries: 1

Rep: Reputation: 422Reputation: 422Reputation: 422Reputation: 422Reputation: 422
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.
 
Old 10-23-2010, 12:31 PM   #4
skoinga
Member
 
Registered: May 2010
Posts: 87

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Hangdog42 View Post
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
 
Old 10-24-2010, 04:55 AM   #5
abhandari
LQ Newbie
 
Registered: Dec 2008
Location: NP
Posts: 28

Rep: Reputation: 1
Thumbs up

Quote:
Originally Posted by skoinga View Post
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.
 
Old 10-24-2010, 08:01 AM   #6
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
Blog Entries: 1

Rep: Reputation: 422Reputation: 422Reputation: 422Reputation: 422Reputation: 422
Quote:
Originally Posted by skoinga View Post
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.
 
Old 10-24-2010, 11:37 AM   #7
ksmatthews
Member
 
Registered: Aug 2008
Posts: 86

Rep: Reputation: 15
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
 
Old 10-24-2010, 06:44 PM   #8
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
Blog Entries: 1

Rep: Reputation: 422Reputation: 422Reputation: 422Reputation: 422Reputation: 422
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.
 
Old 11-07-2010, 03:52 AM   #9
ksmatthews
Member
 
Registered: Aug 2008
Posts: 86

Rep: Reputation: 15
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
 
Old 11-07-2010, 06:35 AM   #10
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
Blog Entries: 1

Rep: Reputation: 422Reputation: 422Reputation: 422Reputation: 422Reputation: 422
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.
Old 11-08-2010, 12:18 AM   #11
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,356

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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.
 
Old 11-13-2010, 07:25 AM   #12
ksmatthews
Member
 
Registered: Aug 2008
Posts: 86

Rep: Reputation: 15
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
 
Old 11-13-2010, 08:36 AM   #13
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
Blog Entries: 1

Rep: Reputation: 422Reputation: 422Reputation: 422Reputation: 422Reputation: 422
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
web-interface to command line program? possible? PB0711 Programming 3 04-27-2009 10:52 AM
Can I execute shell command in my web hosting server? arnablinuxfreak Linux - Server 2 03-09-2009 09:57 PM
How to run root privileged Linux command as normal user via shell shell tcegrid Linux - Newbie 1 06-23-2008 03:38 PM
shell interface vs shell scripting? I'm confused jcchenz Linux - Software 1 10-26-2005 03:32 PM
Command line through a web interface tangle Linux - Software 2 01-13-2005 02:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 05:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration