PageRenderTime 36ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/lynis-1.2.9/include/tests_php

#
Shell | 215 lines | 124 code | 6 blank | 85 comment | 37 complexity | 2ffcd465aebe529f8c279513edb690e2 MD5 | raw file
Possible License(s): GPL-3.0
  1. #!/bin/sh
  2. #################################################################################
  3. #
  4. # Lynis
  5. # ------------------
  6. #
  7. # Copyright 2007-2009, Michael Boelen (michael@rootkit.nl), The Netherlands
  8. # Web site: http://www.rootkit.nl
  9. #
  10. # Lynis comes with ABSOLUTELY NO WARRANTY. This is free software, and you are
  11. # welcome to redistribute it under the terms of the GNU General Public License.
  12. # See LICENSE file for usage of this software.
  13. #
  14. #################################################################################
  15. #
  16. # Software: PHP
  17. #
  18. #################################################################################
  19. #
  20. InsertSection "Software: PHP"
  21. # Possible locations of php.ini
  22. PHPINILOCS="/etc/php.ini \
  23. /etc/php/cgi-php5/php.ini /etc/php/cli-php5/php.ini /etc/php/apache2-php5/php.ini \
  24. /etc/php5/cgi/php.ini /etc/php5/cli/php.ini /etc/php5/apache2/php.ini \
  25. /private/etc/php.ini \
  26. /var/www/conf/php.ini \
  27. /usr/local/etc/php.ini /usr/local/lib/php.ini"
  28. #Display --indent 2 --text "- Checking PHP..." --result FOUND --color WHITE
  29. #
  30. #################################################################################
  31. #
  32. # Test : PHP-2211
  33. # Description : Check php.ini presence
  34. Register --test-no PHP-2211 --weight L --network NO --description "Check php.ini presence"
  35. if [ ${SKIPTEST} -eq 0 ]; then
  36. logtext "Test: Checking for presence php.ini"
  37. PHPINIFILE=""
  38. for I in ${PHPINILOCS}; do
  39. if [ -f ${I} ]; then
  40. PHPINIFILE=${I}
  41. logtext "Found php.ini file (${PHPINIFILE})"
  42. fi
  43. done
  44. if [ ! "${PHPINIFILE}" = "" ]; then
  45. Display --indent 2 --text "- Checking PHP..." --result "FOUND" --color GREEN
  46. else
  47. Display --indent 2 --text "- Checking PHP..." --result "NOT FOUND" --color WHITE
  48. logtext "Result: no php.ini file found"
  49. fi
  50. fi
  51. #
  52. #################################################################################
  53. #
  54. # Test : PHP-2320
  55. # Description : Check php disable functions option
  56. if [ ! "${PHPINIFILE}" = "" ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
  57. Register --test-no PHP-2320 --preqs-met ${PREQS_MET} --weight L --network NO --description "Check PHP disabled functions"
  58. if [ ${SKIPTEST} -eq 0 ]; then
  59. logtext "Test: Checking for PHP function hardening options"
  60. FIND1=`grep "^disabled_functions=" ${PHPINIFILE}`
  61. FIND2=`grep "^suhosin.executor.func.blacklist" ${PHPINIFILE}`
  62. if [ "${FIND1}" = "" -a "${FIND2}" = "" ]; then
  63. logtext "Result: one or more PHP functions are disabled/blacklisted"
  64. Display --indent 2 --text "- Checking PHP disabled functions..." --result "FOUND" --color GREEN
  65. AddHP 3 3
  66. else
  67. logtext "Result: all PHP functions can be executed"
  68. Display --indent 2 --text "- Checking PHP disabled functions..." --result "NONE" --color YELLOW
  69. ReportSuggestion ${TEST_NO} "Harden PHP by disabling riskful functions (functions of interest: 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)"
  70. AddHP 0 1
  71. fi
  72. fi
  73. #
  74. #################################################################################
  75. #
  76. # Test : PHP-2368
  77. # Description : Check php register_globals option
  78. if [ ! "${PHPINIFILE}" = "" ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
  79. Register --test-no PHP-2368 --preqs-met ${PREQS_MET} --weight L --network NO --description "Check PHP register_globals option"
  80. if [ ${SKIPTEST} -eq 0 ]; then
  81. logtext "Test: Checking register_globals option.."
  82. FIND=`cat ${PHPINIFILE} | egrep -i 'register_globals.*(off|no|0)' | grep -v '^;'`
  83. if [ "${FIND}" = "" ]; then
  84. Display --indent 4 --text "- Checking register_globals option..." --result WARNING --color RED
  85. ReportWarning ${TEST_NO} "M" "PHP option register_globals option is turned on, which can be a risk for variable value overwriting"
  86. ReportSuggestion ${TEST_NO} "Change the register_globals line to: register_globals = Off"
  87. logtext "Result: register_globals option is turned on, which can be a risk for variable value overwriting."
  88. AddHP 1 2
  89. else
  90. Display --indent 4 --text "- Checking register_globals option..." --result OK --color GREEN
  91. logtext "Result: Found 'register_globals' in disabled state (0, no, or off), which is good."
  92. AddHP 2 2
  93. fi
  94. fi
  95. #
  96. #################################################################################
  97. #
  98. # Test : PHP-2372
  99. # Description : Check php expose_php option
  100. if [ ! "${PHPINIFILE}" = "" ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
  101. Register --test-no PHP-2372 --preqs-met ${PREQS_MET} --weight L --network NO --description "Check PHP expose_php option"
  102. if [ ${SKIPTEST} -eq 0 ]; then
  103. logtext "Test: Checking expose_php option.."
  104. FIND=`cat ${PHPINIFILE} | egrep -i 'expose_php.*(off|no|0)' | grep -v '^;'`
  105. if [ "${FIND}" = "" ]; then
  106. Display --indent 4 --text "- Checking expose_php option..." --result ON --color RED
  107. ReportWarning ${TEST_NO} "M" "PHP option expose_php is possibly turned on, which can reveal useful information for attackers."
  108. ReportSuggestion ${TEST_NO} "Change the expose_php line to: expose_php = Off"
  109. report "Result: expose_php option is turned on, which can expose useful information for an attacker"
  110. AddHP 1 2
  111. else
  112. Display --indent 4 --text "- Checking expose_php option..." --result OFF --color GREEN
  113. logtext "Result: Found 'expose_php' in disabled state (0, no, or off)"
  114. AddHP 2 2
  115. fi
  116. fi
  117. #
  118. #################################################################################
  119. #
  120. # Test : PHP-2374
  121. # Description : Check PHP enable_dl option
  122. if [ ! "${PHPINIFILE}" = "" ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
  123. Register --test-no PHP-2374 --preqs-met ${PREQS_MET} --weight L --network NO --description "Check PHP enable_dl option"
  124. if [ ${SKIPTEST} -eq 0 ]; then
  125. logtext "Test: Checking PHP enable_dl option.."
  126. FIND=`cat ${PHPINIFILE} | egrep -i 'enable_dl.*(off|no|0)' | grep -v '^;'`
  127. if [ "${FIND}" = "" ]; then
  128. Display --indent 4 --text "- Checking enable_dl option..." --result ON --color YELLOW
  129. report "Result: enable_dl option is turned on, which can be used for riskful downloads via PHP"
  130. ReportSuggestion ${TEST_NO} "Change the enable_dl line to: enable_dl = Off, to disable downloads via PHP"
  131. AddHP 0 1
  132. else
  133. Display --indent 4 --text "- Checking enable_dl option..." --result OFF --color GREEN
  134. logtext "Result: Found 'enable_dl' in disabled state (0, no, or off)"
  135. AddHP 2 2
  136. fi
  137. fi
  138. #
  139. #################################################################################
  140. #
  141. # Test : PHP-2376
  142. # Description : Check PHP allow_url_fopen option
  143. if [ ! "${PHPINIFILE}" = "" ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
  144. Register --test-no PHP-2376 --preqs-met ${PREQS_MET} --weight L --network NO --description "Check PHP allow_url_fopen option"
  145. if [ ${SKIPTEST} -eq 0 ]; then
  146. logtext "Test: Checking PHP allow_url_fopen option.."
  147. FIND=`cat ${PHPINIFILE} | egrep -i 'allow_url_fopen.*(off|no|0)' | grep -v '^;'`
  148. if [ "${FIND}" = "" ]; then
  149. Display --indent 4 --text "- Checking allow_url_fopen option..." --result ON --color YELLOW
  150. report "Result: allow_url_fopen option is turned on, which can be used for riskful downloads via PHP"
  151. ReportSuggestion ${TEST_NO} "Change the allow_url_fopen line to: allow_url_fopen = Off, to disable downloads via PHP"
  152. AddHP 0 1
  153. else
  154. Display --indent 4 --text "- Checking allow_url_fopen option..." --result OFF --color GREEN
  155. logtext "Result: Found 'allow_url_fopen' in disabled state (0, no, or off)"
  156. AddHP 2 2
  157. fi
  158. fi
  159. #
  160. #################################################################################
  161. #
  162. # Test : PHP-2378
  163. # Description : Check PHP allow_url_include option
  164. if [ ! "${PHPINIFILE}" = "" ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi
  165. Register --test-no PHP-2378 --preqs-met ${PREQS_MET} --weight L --network NO --description "Check PHP allow_url_include option"
  166. if [ ${SKIPTEST} -eq 0 ]; then
  167. logtext "Test: Checking PHP allow_url_include option.."
  168. FIND=`cat ${PHPINIFILE} | egrep -i 'allow_url_include.*(off|no|0)' | grep -v '^;'`
  169. if [ "${FIND}" = "" ]; then
  170. Display --indent 4 --text "- Checking allow_url_include option..." --result ON --color YELLOW
  171. report "Result: allow_url_include option is turned on, which can be used for riskful downloads via PHP"
  172. ReportSuggestion ${TEST_NO} "Change the allow_url_include line to: allow_url_include = Off, to disable downloads via PHP"
  173. AddHP 0 1
  174. else
  175. Display --indent 4 --text "- Checking allow_url_include option..." --result OFF --color GREEN
  176. logtext "Result: Found 'allow_url_include' in disabled state (0, no, or off)"
  177. AddHP 2 2
  178. fi
  179. fi
  180. #
  181. #################################################################################
  182. #
  183. # Disable/use functions:
  184. # safe_mode (only for PHP5?)
  185. # open_basedir (limits access to defined directory, comparable with chrooting)
  186. # disable_classes
  187. # session.save_path
  188. # session.referer_check
  189. # upload_tmp_dir
  190. # file_uploads Off, if possible
  191. # Set display_errors to Off
  192. # Set log_errors to On and define error_log (with value Syslog or a filename)
  193. #
  194. #################################################################################
  195. #
  196. # mod_suexec
  197. # suPHP (/etc/suphp.conf)
  198. #
  199. #################################################################################
  200. #
  201. # Test : PHP-2388
  202. # Description : Check php version number
  203. #
  204. #################################################################################
  205. #
  206. wait_for_keypress
  207. #
  208. #================================================================================
  209. # Lynis - Copyright 2007-2009, Michael Boelen - www.rootkit.nl - The Netherlands