Improved html output with scoring information

This commit is contained in:
Toni de la Fuente
2021-04-08 00:14:24 +02:00
parent dacfea6b32
commit 3dfca9c9dd
3 changed files with 66 additions and 17 deletions

View File

@@ -55,18 +55,18 @@ addHtmlHeader() {
display: none;
}
</style>
<title>Prowler - AWS Security Assesments</title>
<title>Prowler - AWS Security Assessments</title>
</head>
<body>
<nav class="navbar navbar-expand-xl sticky-top navbar-dark bg-dark">
<a class="navbar-brand" href="#">Prowler - Security Assesments in AWS</a>
<a class="navbar-brand" href="#">Prowler - Security Assessments in AWS</a>
</nav>
<div class="container-fluid">
<div class="row mt-3">
<div class="col-md-4">
<div class="card">
<div class="card-header">
Report Information
Report Information:
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item">
@@ -90,10 +90,10 @@ addHtmlHeader() {
</div>
</div>
<div class="col-md-8">
<div class="col-md-4">
<div class="card">
<div class="card-header">
Assesment Summary
Assessment Summary:
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item">
@@ -114,6 +114,30 @@ addHtmlHeader() {
</ul>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-header">
Scoring Information:
</div>
<ul class="list-group list-group-flush">
<li class="list-group-item">
<b>Prowler Score:</b> PROWLER_SCORE%
</li>
<li class="list-group-item">
<b>Total Resources:</b> TOTAL_RESOURCES
</li>
<li class="list-group-item">
<b>Passed:</b> PASS_COUNTER
</li>
<li class="list-group-item">
<b>Failed:</b> FAIL_COUNTER
</li>
<li class="list-group-item">
<b>Total Checks Executed:</b> CHECKS_COUNTER
</li>
</ul>
</div>
</div>
</div>
<div class="row mt-3">
<div class="col-md-12">

View File

@@ -139,6 +139,14 @@ bsd_test_tcp_connectivity() {
nc -z -G $TIMEOUT $HOST $PORT >/dev/null 2>&1 && echo "200" || echo "000"
}
gnu_replace_sed(){
sed -i $1 $2
}
bsd_replace_sed(){
sed -i '' $1 $2
}
# Functions to manage dates depending on OS
if [ "$OSTYPE" == "linux-gnu" ] || [ "$OSTYPE" == "linux-musl" ]; then
TEMP_REPORT_FILE=$(mktemp -t -p /tmp prowler.cred_report-XXXXXX)
@@ -171,6 +179,10 @@ if [ "$OSTYPE" == "linux-gnu" ] || [ "$OSTYPE" == "linux-musl" ]; then
convert_date_to_timestamp() {
gnu_convert_date_to_timestamp "$1"
}
replace_sed() {
gnu_replace_sed $1 $2
}
elif [[ "$OSTYPE" == "darwin"* ]] || [[ "$OSTYPE" == "freebsd"* ]]; then
# BSD/OSX commands compatibility
TEMP_REPORT_FILE=$(mktemp -t prowler.cred_report-XXXXXX)
@@ -244,6 +256,9 @@ elif [[ "$OSTYPE" == "darwin"* ]] || [[ "$OSTYPE" == "freebsd"* ]]; then
test_tcp_connectivity() {
bsd_test_tcp_connectivity "$1" "$2" "$3"
}
replace_sed() {
bsd_replace_sed $1 $2
}
elif [[ "$OSTYPE" == "cygwin" ]]; then
# POSIX compatibility layer and Linux environment emulation for Windows
TEMP_REPORT_FILE=$(mktemp -t -p /tmp prowler.cred_report-XXXXXX)
@@ -274,6 +289,9 @@ elif [[ "$OSTYPE" == "cygwin" ]]; then
convert_date_to_timestamp() {
gnu_convert_date_to_timestamp "$1"
}
replace_sed() {
gnu_replace_sed $1 $2
}
else
echo "Unknown Operating System! Valid \$OSTYPE: linux-gnu, linux-musl, darwin* or cygwin"
echo "Found: $OSTYPE"

View File

@@ -13,19 +13,19 @@
# Scoring POC
scoring(){
if [[ ! $PASS_COUNTER ]]; then
PASS_COUNTER=0
fi
if [[ ! $FAIL_COUNTER ]]; then
FAIL_COUNTER=0
fi
# TOTAL_RESOURCES=$(awk "BEGIN {print $FAIL_COUNTER+$PASS_COUNTER; exit}")
TOTAL_RESOURCES=$(($FAIL_COUNTER + $PASS_COUNTER))
# Score is % of passed compared to failures. The higher score, the better
PROWLER_SCORE=$(( $PASS_COUNTER * 100 / $TOTAL_RESOURCES ))
if [[ $SCORING == "1" ]]; then
if [[ ! $PASS_COUNTER ]]; then
PASS_COUNTER=0
fi
if [[ ! $FAIL_COUNTER ]]; then
FAIL_COUNTER=0
fi
# TOTAL_RESOURCES=$(awk "BEGIN {print $FAIL_COUNTER+$PASS_COUNTER; exit}")
TOTAL_RESOURCES=$(($FAIL_COUNTER + $PASS_COUNTER))
# Score is % of passed compared to failures. The higher score, the better
PROWLER_SCORE=$(( $PASS_COUNTER * 100 / $TOTAL_RESOURCES ))
echo -e "$BLUE------------------------------------------------------------------ $NORMAL"
echo -e "$CYAN _"
echo -e " _ __ _ __ _____ _| | ___ _ __"
@@ -49,5 +49,12 @@ scoring(){
echo -e "$BLUE------------------------------------------------------------------ $NORMAL"
echo -e " * the highest the better (0 to 100)$NORMAL"
echo -e " Prowler scoring uses any check, including CIS not scored checks$NORMAL"
fi
if [[ "${MODES[@]}" =~ "html" ]]; then
replace_sed 's/PROWLER_SCORE/'$PROWLER_SCORE'/g' ${OUTPUT_FILE_NAME}.$EXTENSION_HTML
replace_sed 's/PASS_COUNTER/'$PASS_COUNTER'/g' ${OUTPUT_FILE_NAME}.$EXTENSION_HTML
replace_sed 's/TOTAL_RESOURCES/'$TOTAL_RESOURCES'/g' ${OUTPUT_FILE_NAME}.$EXTENSION_HTML
replace_sed 's/FAIL_COUNTER/'$FAIL_COUNTER'/g' ${OUTPUT_FILE_NAME}.$EXTENSION_HTML
replace_sed 's/CHECKS_COUNTER/'$CHECKS_COUNTER'/g' ${OUTPUT_FILE_NAME}.$EXTENSION_HTML
fi
}