|
| 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 and if /etc/passwd is writeable also if /etc/shadow is readable |
| 20 | +# PLUGIN_NAME=check_passwd_shadow |
| 21 | +# PLUGIN_REQUIRED_TESTS= |
| 22 | +#----------------------------------------------------- |
| 23 | +# |
| 24 | +######################################################################### |
| 25 | + |
| 26 | +check_password_hashes() { |
| 27 | + # define some constant |
| 28 | + IFS_OLD=$IFS |
| 29 | + IFS=$'\n' |
| 30 | + ENCRYPTEDPASS='x' |
| 31 | + #start |
| 32 | + LogText "Test:obtain /etc/passwd file content" |
| 33 | + passwd_content=$(${AWKBINARY} '{print $0}' /etc/passwd) |
| 34 | + for each_passwd in ${passwd_content}; |
| 35 | + do |
| 36 | + IFS=':' |
| 37 | + passwd_split_colon=($each_passwd) |
| 38 | + if [ "${passwd_split_colon[1]}" != "$ENCRYPTEDPASS" ];then |
| 39 | + IFS=$'\n' |
| 40 | + Report "sensetive_passwd_hashes[]=$each_passwd" |
| 41 | + fi |
| 42 | + done |
| 43 | + IFS=$IFS_OLD |
| 44 | +} |
| 45 | + |
| 46 | +check_passwd_writeable() { |
| 47 | + #start |
| 48 | + LogText "Test:obtain /etc/passwd file permission in number format" |
| 49 | + passwd_permission_number=$(stat -c %a /etc/passwd) |
| 50 | + if [ "$passwd_permission_number" -gt "644" ];then |
| 51 | + Report "passwd_writeable[]=$(ls -la /etc/passwd)" |
| 52 | + fi |
| 53 | +} |
| 54 | + |
| 55 | +check_shadow_readable() { |
| 56 | + #start |
| 57 | + LogText "Test:obtain /etc/shadow file permission in number format" |
| 58 | + shadow_permission_number=$(stat -c %a /etc/shadow) |
| 59 | + if [ "$shadow_permission_number" -gt "640" ];then |
| 60 | + Report "shadow_readable[]=$(ls -la /etc/shadow)" |
| 61 | + fi |
| 62 | +} |
| 63 | +######################################################################### |
| 64 | +# |
| 65 | + # Add custom section to screen output |
| 66 | + InsertSection "PASS" |
| 67 | +# |
| 68 | +################################################################################# |
| 69 | +# |
| 70 | + # Test : PASS-0001 |
| 71 | + # Description : We show some lines on the screen |
| 72 | + |
| 73 | + # Register our first custom test |
| 74 | + # We consider it to be a lightweight test (no heavy IO, or long searches), no network connection needed |
| 75 | + Register --test-no PASS-0001 --weight L --network NO --description "A test for check if there is password hashess stored in /etc/passwd" |
| 76 | + if [ ${SKIPTEST} -eq 0 ]; then |
| 77 | + # The Display function makes it easy to show something on screen, with colors. |
| 78 | + # --indent defines amount of spaces |
| 79 | + # --text text to be displayed on screen |
| 80 | + # --result text at end of line |
| 81 | + # --color color of result text |
| 82 | + Display --indent 2 --text "- Checking if there is a password hashes on /etc/passwd file" --result OK --color GREEN |
| 83 | + check_password_hashes; |
| 84 | + fi |
| 85 | +# |
| 86 | +################################################################################# |
| 87 | +# |
| 88 | + # Test : PASS-0002 |
| 89 | + # Description : We show some lines on the screen |
| 90 | + |
| 91 | + # Register our first custom test |
| 92 | + # We consider it to be a lightweight test (no heavy IO, or long searches), no network connection needed |
| 93 | + Register --test-no PASS-0002 --weight L --network NO --description "A test for check if /etc/shadow is readable" |
| 94 | + if [ ${SKIPTEST} -eq 0 ]; then |
| 95 | + # The Display function makes it easy to show something on screen, with colors. |
| 96 | + # --indent defines amount of spaces |
| 97 | + # --text text to be displayed on screen |
| 98 | + # --result text at end of line |
| 99 | + # --color color of result text |
| 100 | + Display --indent 2 --text "- Checking if /etc/shadow is readable" --result OK --color GREEN |
| 101 | + check_shadow_readable; |
| 102 | + fi |
| 103 | +# |
| 104 | +################################################################################# |
| 105 | +# |
| 106 | + # Test : PASS-0003 |
| 107 | + # Description : We show some lines on the screen |
| 108 | + |
| 109 | + # Register our first custom test |
| 110 | + # We consider it to be a lightweight test (no heavy IO, or long searches), no network connection needed |
| 111 | + Register --test-no PASS-0003 --weight L --network NO --description "A test for check if /etc/passwd is writeable" |
| 112 | + if [ ${SKIPTEST} -eq 0 ]; then |
| 113 | + # The Display function makes it easy to show something on screen, with colors. |
| 114 | + # --indent defines amount of spaces |
| 115 | + # --text text to be displayed on screen |
| 116 | + # --result text at end of line |
| 117 | + # --color color of result text |
| 118 | + Display --indent 2 --text "- Checking if /etc/passwd is writeable" --result OK --color GREEN |
| 119 | + check_passwd_writeable; |
| 120 | + fi |
| 121 | +# |
| 122 | +################################################################################# |
| 123 | +# Wait for keypress (unless --quick is being used) |
| 124 | +WaitForKeyPress |
| 125 | + |
| 126 | +#EOF |
0 commit comments