From a6516e4af8e805b32bdbe454e313956f963aaca0 Mon Sep 17 00:00:00 2001 From: Nimrod Kor Date: Tue, 18 Feb 2020 11:36:20 +0200 Subject: [PATCH] Check 1.1 - check password access and access key usage (cherry picked from commit f62cde1bf1a32138419cc1488392b93816958595) --- checks/check11 | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/checks/check11 b/checks/check11 index 924a14eb..f34ebed5 100644 --- a/checks/check11 +++ b/checks/check11 @@ -17,19 +17,21 @@ CHECK_ALTERNATE_check101="check11" check11(){ # "Avoid the use of the root account (Scored)." MAX_DAYS=-1 - last_login_date=$(cat $TEMP_REPORT_FILE|awk -F, '{ print $1,$5 }' |grep '' | awk '{ print $2 }') - arn=$(cat $TEMP_REPORT_FILE|awk -F, '{ print $1,$2 }' |grep '' | awk '{ print $2 }') + last_login_dates=$(cat $TEMP_REPORT_FILE | awk -F, '{ print $1,$5,$11,$16 }' | grep '' | cut -d' ' -f2,3,4) - #check if last_login_date date is a valid date, if not, its a pass. - if [[ ${last_login_date%T*} =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]];then - days_not_in_use=$(how_many_days_from_today ${last_login_date%T*}) - if [ "$days_not_in_use" -gt "$MAX_DAYS" ];then - textFail "Root Account $arn last accessed was less then ${MAX_DAYS#-} day ago" - else - textPass "Root Account $arn last accessed was more then ${MAX_DAYS#-} day ago" + failures=0 + for date in $last_login_dates; do + if [[ ${date%T*} =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]];then + days_not_in_use=$(how_many_days_from_today ${date%T*}) + if [ "$days_not_in_use" -gt "$MAX_DAYS" ];then + failures=1 + textFail "Root user in the account was last accessed ${MAX_DAYS#-} day ago" + break + fi fi - else - textPass "Root Account $arn last accessed was more then ${MAX_DAYS#-} day ago" - fi + done + if [[ $failures == 0 ]]; then + textPass "Root user in the account wasn't accessed in the last ${MAX_DAYS#-} days" + fi }