Skip to content

Instantly share code, notes, and snippets.

@Gomah
Created September 29, 2013 23:54
Show Gist options
  • Save Gomah/6757641 to your computer and use it in GitHub Desktop.
Save Gomah/6757641 to your computer and use it in GitHub Desktop.
Server safetest
<?php
// Config
$forbiden_functions = array('escapeshellarg', 'escapeshellcmd', 'exec', 'link', 'passthru', 'pcntl_exec', 'popen', 'proc_close', 'proc_get_status', 'proc_nice', 'proc_open', 'proc_terminate', 'symlink', 'shell_exec','system');
$must_functions = array( 'base64_decode', 'fpassthru', 'ini_set', 'php_uname');
// Start
$disabled_functions = array_map("trim", explode(",",@ini_get("disable_functions")));
$issues = array();
// Functions should be disabled
foreach ($forbiden_functions as $functions_ouput)
{ if(function_exists($functions_ouput) && !(in_array($functions_ouput, $disabled_functions)))
$issues[] = "Function ".$functions_ouput." should be disabled!"; }
unset($functions_ouput);
// Functions should be enabled
foreach ($must_functions as $functions_ouput)
{ if(!function_exists($functions_ouput) || in_array($functions_ouput, $disabled_functions))
$issues[] = "Function ".$functions_ouput." should be enabled!"; }
unset($functions_ouput);
// Is eval here?
if( in_array("eval", $disabled_functions) )
{ $issues[] = "Language construct eval is required to be enabled in PHP!"; }
// Is safe mode enabled?
if (ini_get('safe_mode'))
$issues[] = "Issue: safe_mode is On!";
// Is magic_quotes_gpc enabled?
if (ini_get('magic_quotes_gpc'))
$issues[] = "Issue: magic_quotes_gpc is On!";
// Output results
if( !count($issues) )
{ echo "Your host is OK!"; }
else
{ echo "<pre>Your host have ".count($issues)." problems!\n\n";
foreach($issues as $issue)
echo "Issue: {$issue} \n";
echo "</pre>"; }
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment