2014-08-26 17:33:55 +02:00
#!/bin/sh
#################################################################################
#
# Lynis
# ------------------
#
2016-03-13 16:00:39 +01:00
# Copyright 2007-2013, Michael Boelen
# Copyright 2013-2016, CISOfy
#
# Website : https://cisofy.com
# Blog : http://linux-audit.com
# GitHub : https://github.com/CISOfy/lynis
2014-08-26 17:33:55 +02:00
#
# Lynis comes with ABSOLUTELY NO WARRANTY. This is free software, and you are
# welcome to redistribute it under the terms of the GNU General Public License.
# See LICENSE file for usage of this software.
#
#################################################################################
#
# Software: PHP
#
#################################################################################
#
2014-12-09 18:11:38 +01:00
InsertSection "PHP"
2014-08-26 17:33:55 +02:00
# Possible locations of php.ini
PHPINILOCS="/etc/php.ini \
/etc/php/cgi-php5/php.ini /etc/php/cli-php5/php.ini /etc/php/apache2-php5/php.ini \
/etc/php/apache2-php5.4/php.ini /etc/php/apache2-php5.5/php.ini \
/etc/php5/cgi/php.ini \
/etc/php5/cli/php.ini \
/etc/php5/cli-php5.4/php.ini /etc/php5/cli-php5.5/php.ini /etc/php5/cli-php5.6/php.ini \
/etc/php5/apache2/php.ini \
2015-02-15 23:02:46 +01:00
/etc/php5/fpm/php.ini \
2014-08-26 17:33:55 +02:00
/private/etc/php.ini \
/var/www/conf/php.ini \
2014-12-05 12:29:18 +01:00
/usr/local/etc/php.ini /usr/local/lib/php.ini \
/usr/pkg/etc/php.ini"
2014-08-26 17:33:55 +02:00
PHPINIDIRS="/etc/php5/conf.d"
#
#################################################################################
#
# Test : PHP-2211
# Description : Check php.ini presence
Register --test-no PHP-2211 --weight L --network NO --description "Check php.ini presence"
if [ ${SKIPTEST} -eq 0 ]; then
2015-12-21 21:17:15 +01:00
LogText "Test: Checking for presence php.ini"
2014-08-26 17:33:55 +02:00
PHPINIFILE=""
PHPINI_ALLFILES=""
for I in ${PHPINILOCS}; do
2015-12-21 21:17:15 +01:00
LogText "Test: checking presence ${I}"
2014-08-26 17:33:55 +02:00
if [ -f ${I} ]; then
PHPINIFILE=${I}
2015-12-21 21:17:15 +01:00
LogText "Result: Found php.ini file (${PHPINIFILE})"
LogText "Note: Adding file to php.ini array"
2014-08-26 17:33:55 +02:00
PHPINI_ALLFILES="${PHPINI_ALLFILES} ${PHPINIFILE}"
else
2015-12-21 21:17:15 +01:00
LogText "Result: file ${I} not found"
2014-08-26 17:33:55 +02:00
fi
done
# Check all known locations
for I in ${PHPINIDIRS}; do
tFILES=`ls ${I}/*.ini 2>/dev/null`
if [ "${tFILES}" = "" ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: no files found for ${I}"
2014-08-26 17:33:55 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: found files in location ${I}, checking"
2014-08-26 17:33:55 +02:00
for I in ${tFILES}; do
if [ -f ${I} ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: file ${I} exists, adding to php.ini array"
2014-08-26 17:33:55 +02:00
PHPINI_ALLFILES="${PHPINI_ALLFILES} ${I}"
fi
done
fi
done
if [ ! "${PHPINIFILE}" = "" ]; then
2014-09-15 12:01:09 +02:00
Display --indent 2 --text "- Checking PHP" --result "FOUND" --color GREEN
2015-12-21 21:17:15 +01:00
LogText "Result: using single file ${PHPINIFILE} for main php.ini tests"
LogText "Result: using php.ini array ${PHPINI_ALLFILES} for further tests"
2014-08-26 17:33:55 +02:00
else
2014-09-15 12:01:09 +02:00
Display --indent 2 --text "- Checking PHP" --result "NOT FOUND" --color WHITE
2015-12-21 21:17:15 +01:00
LogText "Result: no php.ini file found"
2014-08-26 17:33:55 +02:00
fi
fi
#
#################################################################################
#
# Test : PHP-2320
# Description : Check php disable functions option
if [ ! "${PHPINI_ALLFILES}" = "" ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
Register --test-no PHP-2320 --preqs-met ${PREQS_MET} --weight L --network NO --description "Check PHP disabled functions"
if [ ${SKIPTEST} -eq 0 ]; then
FOUND=0
for I in ${PHPINI_ALLFILES}; do
2015-12-21 21:17:15 +01:00
LogText "Test: Checking for PHP function hardening disabled_functions or suhosin.executor.func.blacklist in file ${I}"
2014-08-26 17:33:55 +02:00
FIND=`grep "^disable_functions.*=" ${I}`
if [ "${FIND}" = "" ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: ${I}: disabled_functions not found"
2014-08-26 17:33:55 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: ${I}: found disabled_functions"
2014-08-26 17:33:55 +02:00
FOUND=1
fi
FIND=`grep "^suhosin.executor.func.blacklist=" ${I}`
if [ "${FIND}" = "" ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: ${I}: suhosin.executor.func.blacklist not found"
2014-08-26 17:33:55 +02:00
else
2015-12-21 21:17:15 +01:00
LogText "Result: ${I}: found suhosin.executor.func.blacklist"
2014-08-26 17:33:55 +02:00
FOUND=1
fi
done
if [ ${FOUND} -eq 0 ]; then
2015-12-21 21:17:15 +01:00
LogText "Result: all PHP functions can be executed"
2014-09-15 12:01:09 +02:00
Display --indent 4 --text "- Checking PHP disabled functions" --result "NONE" --color YELLOW
2014-08-26 17:33:55 +02:00
ReportSuggestion ${TEST_NO} "Harden PHP by disabling risky functions"
2015-12-21 21:17:15 +01:00
LogText "Functions of interest to research/disable: chown, diskfreespace, disk_free_space, disk_total_space, dl, exec, escapeshellarg, escapeshellcmd, fileinode, highlight_file, max_execution_time, passthru, pclose, phpinfo, popen, proc_close, proc_open, proc_get_status, proc_nice, proc_open, proc_terminate, set_time_limit, shell_exec, show_source, system)"
2014-08-26 17:33:55 +02:00
AddHP 0 1
else
2015-12-21 21:17:15 +01:00
LogText "Result: one or more PHP functions are disabled/blacklisted"
2014-09-15 12:01:09 +02:00
Display --indent 4 --text "- Checking PHP disabled functions" --result "FOUND" --color GREEN
2014-08-26 17:33:55 +02:00
AddHP 3 3
fi
fi
#
#################################################################################
#
# Test : PHP-2368
# Description : Check php register_globals option
# Notes : Don't test for it if PHP version is 5.4.0 or later (it has been removed)
2015-01-16 00:15:20 +01:00
if [ ! "${PHPINIFILE}" = "" -a ! "${PHPVERSION}" = "" -a ! "${EGREPBINARY}" = "" ]; then
2015-02-15 23:50:28 +01:00
if [ -f "${PHPINIFILE}" ]; then
FIND=`echo ${PHPVERSION} | ${EGREPBINARY} "^(4.|5.[0-3])"`
if [ "${FIND}" = "" ]; then
PREQS_MET="NO"; Debug "Found most likely PHP version 5.4.0 or higher (${PHPVERSION}) which does not use register_globals"
else
PREQS_MET="YES"; Debug "Found PHP version 4 or up to 5.3 (${FIND}) which we are going to scan"
fi
else
Debug "File php.ini (${PHPINIFILE}) not found"
2014-08-26 17:33:55 +02:00
fi
2015-02-15 23:50:28 +01:00
else
PREQS_MET="NO"
Debug "Skipping test: php.ini not found, or PHP version empty"
Debug "php.ini: ${PHPINIFILE}"
Debug "version: ${PHPVERSION}"
2014-08-26 17:33:55 +02:00
fi
Register --test-no PHP-2368 --preqs-met ${PREQS_MET} --weight L --network NO --description "Check PHP register_globals option"
if [ ${SKIPTEST} -eq 0 ]; then
2015-12-21 21:17:15 +01:00
LogText "Test: Checking PHP register_globals option"
2015-10-10 13:25:14 +02:00
FIND=`egrep -i 'register_globals.*(on|yes|1)' ${PHPINIFILE} | grep -v '^;'`
2014-08-26 17:33:55 +02:00
if [ ! "${FIND}" = "" ]; then
2014-09-15 12:01:09 +02:00
Display --indent 4 --text "- Checking register_globals option" --result WARNING --color RED
2014-08-26 17:33:55 +02:00
ReportWarning ${TEST_NO} "M" "PHP option register_globals option is turned on, which can be a risk for variable value overwriting"
ReportSuggestion ${TEST_NO} "Change the register_globals line to: register_globals = Off"
2015-12-21 21:17:15 +01:00
LogText "Result: register_globals option is turned on, which can be a risk for variable value overwriting."
2014-08-26 17:33:55 +02:00
AddHP 1 2
else
2014-09-15 12:01:09 +02:00
Display --indent 4 --text "- Checking register_globals option" --result OK --color GREEN
2015-12-21 21:17:15 +01:00
LogText "Result: No 'register_globals' found. Most likely it is in disabled state (0, no, or off), which is the default nowadays and considered the safe value."
2014-08-26 17:33:55 +02:00
ReportManual ${TEST_NO}:01
AddHP 2 2
fi
fi
#
#################################################################################
#
# Test : PHP-2372
# Description : Check php expose_php option
# Notes : Extend test to check all PHP files YYY
if [ ! "${PHPINIFILE}" = "" ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
Register --test-no PHP-2372 --preqs-met ${PREQS_MET} --weight L --network NO --description "Check PHP expose_php option"
if [ ${SKIPTEST} -eq 0 ]; then
2015-12-21 21:17:15 +01:00
LogText "Test: Checking expose_php option"
2015-10-10 13:25:14 +02:00
FIND=`egrep -i 'expose_php.*(off|no|0)' ${PHPINIFILE} | grep -v '^;'`
2014-08-26 17:33:55 +02:00
if [ "${FIND}" = "" ]; then
2014-09-15 12:01:09 +02:00
Display --indent 4 --text "- Checking expose_php option" --result ON --color RED
2014-08-26 17:33:55 +02:00
ReportWarning ${TEST_NO} "M" "PHP option expose_php is possibly turned on, which can reveal useful information for attackers."
ReportSuggestion ${TEST_NO} "Change the expose_php line to: expose_php = Off"
2015-12-21 21:17:15 +01:00
Report "Result: expose_php option is turned on, which can expose useful information for an attacker"
2014-08-26 17:33:55 +02:00
AddHP 1 2
else
2014-09-15 12:01:09 +02:00
Display --indent 4 --text "- Checking expose_php option" --result OFF --color GREEN
2015-12-21 21:17:15 +01:00
LogText "Result: Found 'expose_php' in disabled state (0, no, or off)"
2014-08-26 17:33:55 +02:00
AddHP 2 2
fi
#YYY Check through all files
fi
#
#################################################################################
#
# Test : PHP-2374
# Description : Check PHP enable_dl option
# Notes : Extend test to check all PHP files YYY
if [ ! "${PHPINIFILE}" = "" ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
Register --test-no PHP-2374 --preqs-met ${PREQS_MET} --weight L --network NO --description "Check PHP enable_dl option"
if [ ${SKIPTEST} -eq 0 ]; then
2015-12-21 21:17:15 +01:00
LogText "Test: Checking PHP enable_dl option"
2015-10-10 13:25:14 +02:00
FIND=`egrep -i 'enable_dl.*(off|no|0)' ${PHPINIFILE} | grep -v '^;'`
2014-08-26 17:33:55 +02:00
if [ "${FIND}" = "" ]; then
2014-09-15 12:01:09 +02:00
Display --indent 4 --text "- Checking enable_dl option" --result ON --color YELLOW
2015-12-21 21:17:15 +01:00
Report "Result: enable_dl option is turned on, which can be used for riskful downloads via PHP"
2014-08-26 17:33:55 +02:00
ReportSuggestion ${TEST_NO} "Change the enable_dl line to: enable_dl = Off, to disable downloads via PHP"
AddHP 0 1
else
2014-09-15 12:01:09 +02:00
Display --indent 4 --text "- Checking enable_dl option" --result OFF --color GREEN
2015-12-21 21:17:15 +01:00
LogText "Result: Found 'enable_dl' in disabled state (0, no, or off)"
2014-08-26 17:33:55 +02:00
AddHP 2 2
fi
#YYY Check through all files
fi
#
#################################################################################
#
# Test : PHP-2376
# Description : Check PHP allow_url_fopen option
# Notes : Extend test to check all PHP files YYY
if [ ! "${PHPINIFILE}" = "" ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
Register --test-no PHP-2376 --preqs-met ${PREQS_MET} --weight L --network NO --description "Check PHP allow_url_fopen option"
if [ ${SKIPTEST} -eq 0 ]; then
2015-12-21 21:17:15 +01:00
LogText "Test: Checking PHP allow_url_fopen option"
2015-10-10 13:25:14 +02:00
FIND=`egrep -i 'allow_url_fopen.*(off|no|0)' ${PHPINIFILE} | grep -v '^;'`
2014-08-26 17:33:55 +02:00
if [ "${FIND}" = "" ]; then
2014-09-15 12:01:09 +02:00
Display --indent 4 --text "- Checking allow_url_fopen option" --result ON --color YELLOW
2015-12-21 21:17:15 +01:00
Report "Result: allow_url_fopen option is turned on, which can be used for riskful downloads via PHP"
2014-08-26 17:33:55 +02:00
ReportSuggestion ${TEST_NO} "Change the allow_url_fopen line to: allow_url_fopen = Off, to disable downloads via PHP"
AddHP 0 1
else
2014-09-15 12:01:09 +02:00
Display --indent 4 --text "- Checking allow_url_fopen option" --result OFF --color GREEN
2015-12-21 21:17:15 +01:00
LogText "Result: Found 'allow_url_fopen' in disabled state (0, no, or off)"
2014-08-26 17:33:55 +02:00
AddHP 2 2
fi
#YYY Check through all files
fi
#
#################################################################################
#
# Test : PHP-2378
# Description : Check PHP allow_url_include option
# Notes : Extend test to check all PHP files YYY
if [ ! "${PHPINIFILE}" = "" ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
Register --test-no PHP-2378 --preqs-met ${PREQS_MET} --weight L --network NO --description "Check PHP allow_url_include option"
if [ ${SKIPTEST} -eq 0 ]; then
2015-12-21 21:17:15 +01:00
LogText "Test: Checking PHP allow_url_include option"
2015-10-10 13:25:14 +02:00
FIND=`egrep -i 'allow_url_include.*(off|no|0)' ${PHPINIFILE} | grep -v '^;'`
2014-08-26 17:33:55 +02:00
if [ "${FIND}" = "" ]; then
2014-09-15 12:01:09 +02:00
Display --indent 4 --text "- Checking allow_url_include option" --result ON --color YELLOW
2015-12-21 21:17:15 +01:00
Report "Result: allow_url_include option is turned on, which can be used for riskful downloads via PHP"
2014-08-26 17:33:55 +02:00
ReportSuggestion ${TEST_NO} "Change the allow_url_include line to: allow_url_include = Off, to disable downloads via PHP"
AddHP 0 1
else
2014-09-15 12:01:09 +02:00
Display --indent 4 --text "- Checking allow_url_include option" --result OFF --color GREEN
2015-12-21 21:17:15 +01:00
LogText "Result: Found 'allow_url_include' in disabled state (0, no, or off)"
2014-08-26 17:33:55 +02:00
AddHP 2 2
fi
fi
#
#################################################################################
#
wait_for_keypress
#
#================================================================================
2015-12-21 21:17:15 +01:00
# Lynis - Copyright 2007-2016, Michael Boelen, CISOfy - https://cisofy.com