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
https://forums.phpfreaks.com/topic/216721-web-interface-to-shell-commands/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.