|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +# -------------------------- CUT THIS SECTION --------------------------- |
| 4 | +# This is a template to create a customized plugin |
| 5 | +# |
| 6 | +# Each plugin should at least have several variables defined with the |
| 7 | +# prefix PLUGIN_* (see below) |
| 8 | +# |
| 9 | +# If you want to learn what functions you can use, check include/functions |
| 10 | +# |
| 11 | +# -------------------------- CUT THIS SECTION --------------------------- |
| 12 | + |
| 13 | +######################################################################### |
| 14 | +# |
| 15 | +# * DO NOT REMOVE * |
| 16 | +#----------------------------------------------------- |
| 17 | + |
| 18 | +# PLUGIN_CATEGORY=PASS |
| 19 | +# PLUGIN_DESC=A test for check if there is password hashes stored in /etc/passwd |
| 20 | +# PLUGIN_NAME=tests_passwd |
| 21 | +# PLUGIN_REQUIRED_TESTS= |
| 22 | +#----------------------------------------------------- |
| 23 | +# |
| 24 | +######################################################################### |
| 25 | +check_password_hashes() { |
| 26 | + IFS=$'\n' |
| 27 | + passwd_content=$(${AWKBINARY} '{print $0}' /etc/passwd) |
| 28 | + LogText "Test:obtain /etc/passwd file content" |
| 29 | + for each_passwd in ${passwd_content}; |
| 30 | + do |
| 31 | + IFS=':' |
| 32 | + arr=($each_passwd) |
| 33 | + if [ "${arr[1]}" != "x" ];then |
| 34 | + IFS=$'\n' |
| 35 | + Report "sensetive_passwd_hashes[]=$each_passwd" |
| 36 | + fi |
| 37 | + done |
| 38 | +} |
| 39 | +######################################################################### |
| 40 | +# |
| 41 | + # Add custom section to screen output |
| 42 | + InsertSection "PASS" |
| 43 | +# |
| 44 | +################################################################################# |
| 45 | +# |
| 46 | + # Test : PASS-0001 |
| 47 | + # Description : We show some lines on the screen |
| 48 | + |
| 49 | + # Register our first custom test |
| 50 | + # We consider it to be a lightweight test (no heavy IO, or long searches), no network connection needed |
| 51 | + Register --test-no PASS-0001 --weight L --network NO --description "A test for check if there is password hashess stored in /etc/passwd" |
| 52 | + if [ ${SKIPTEST} -eq 0 ]; then |
| 53 | + # The Display function makes it easy to show something on screen, with colors. |
| 54 | + # --indent defines amount of spaces |
| 55 | + # --text text to be displayed on screen |
| 56 | + # --result text at end of line |
| 57 | + # --color color of result text |
| 58 | + Display --indent 2 --text "- Checking if there is a password hashes on /etc/passwd file" --result OK --color GREEN |
| 59 | + check_password_hashes; |
| 60 | + fi |
| 61 | +# |
| 62 | +################################################################################# |
| 63 | +# |
| 64 | + |
| 65 | + # First check if OPENSSLBINARY is known as a prerequisite for this test. |
| 66 | + if [ ! -z "${OPENSSLBINARY}" ]; then PREQS_MET="YES"; else PREQS_MET="NO"; fi |
| 67 | + Register --test-no CUST-0001 --preqs-met ${PREQS_MET} --weight M --network NO --description "Description of custom test" |
| 68 | + if [ ${SKIPTEST} -eq 0 ]; then |
| 69 | + FOUNDPROBLEM=0 |
| 70 | + DIR="/my/path" |
| 71 | + LogText "Test: we are going to check if we can find a particular directory (${DIR})" |
| 72 | + # Check if a directory exists |
| 73 | + if [ -d ${DIR} ]; then |
| 74 | + LogText "Result: log entry for easier debugging or additional information" |
| 75 | + else |
| 76 | + FOUNDPROBLEM=1 |
| 77 | + LogText "Result: directory ${DIR} was not found!" |
| 78 | + ReportWarning "${TEST_NO}" "This is a test warning line" "${DIR}" "text:Create directory ${DIR}" |
| 79 | + fi |
| 80 | + |
| 81 | + if [ ${FOUNDPROBLEM} -eq 0 ]; then |
| 82 | + Display --indent 2 --text "- Checking if everything is OK..." --result OK --color GREEN |
| 83 | + else |
| 84 | + Display --indent 2 --text "- Checking if everything is OK..." --result WARNING --color RED |
| 85 | + ReportSuggestion ${TEST_NO} "This is a suggestion" |
| 86 | + fi |
| 87 | + fi |
| 88 | +# |
| 89 | +################################################################################# |
| 90 | +# |
| 91 | + |
| 92 | +# Wait for keypress (unless --quick is being used) |
| 93 | +WaitForKeyPress |
| 94 | + |
| 95 | +#EOF |
0 commit comments