Jump to content

web interface to shell commands


ksmatthews

Recommended Posts

Hi THere,

 

They say that from a security standpoint, we should not implement root-level commands in a web interface ....

 

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 code  poor practice ?

 

If so, then I would be curious to know how 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  :shrug:

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.