Reporting working for Count of Open Ports and Suspicious ports open.
This commit is contained in:
@@ -153,14 +153,88 @@ found_ports=$(ls $results_dir/open-ports)
|
||||
# Loop through each found port
|
||||
for port in $found_ports; do
|
||||
# Remove the .txt extension from the filename
|
||||
port_number="${port%.txt}"
|
||||
port_number=$(basename "$port" .txt)
|
||||
|
||||
# Check if the port is NOT in the allowed_ports list
|
||||
if ! echo "$allowed_ports" | grep -qw "$port_number"; then
|
||||
echo -e "\e[1;31mWARNING: Unexpected port $port_number is open on some hosts! See $results_dir/open-ports/$port.txt for details.\e[0m"
|
||||
echo -e "\e[1;31mWARNING: Unexpected port $port_number is open on some hosts! See $results_dir/open-ports/$port for details.\e[0m"
|
||||
fi
|
||||
done
|
||||
|
||||
# --- Generate Markdown Report ---
|
||||
|
||||
echo -e "\e[33mGenerating Markdown report...\e[0m"
|
||||
|
||||
# Create the Markdown report file
|
||||
report_file="security_report_$current_date.md"
|
||||
|
||||
# Create the Markdown template (using a here document)
|
||||
cat << EOF > "$report_file"
|
||||
# Security Scan Report - $current_date
|
||||
|
||||
## Target Information
|
||||
|
||||
**Input File:** $1
|
||||
|
||||
## Ping Sweep Results
|
||||
|
||||
**(Host IPs from ping sweep will be inserted here)**
|
||||
|
||||
## Open Ports Summary
|
||||
|
||||
**(Summary of open ports and affected hosts will be inserted here)**
|
||||
|
||||
## Suspicious Open Ports
|
||||
|
||||
|
||||
EOF
|
||||
echo -e "\e[33mPopulating Open Ports Summary...\e[0m"
|
||||
|
||||
# Generate the Markdown table for open ports
|
||||
open_ports_table=""
|
||||
open_ports_table+="| Port | Count |\n" # Table header with newline
|
||||
open_ports_table+="|---|---|\n" # Separator line with newline
|
||||
|
||||
for port_file in "$results_dir"/open-ports/*; do
|
||||
port_number=$(basename "$port_file" .txt)
|
||||
ip_count=$(wc -l < "$port_file")
|
||||
open_ports_table+="| $port_number | $ip_count |\n"
|
||||
done
|
||||
|
||||
# Insert the open ports table into the Markdown report
|
||||
sed -i "/(Summary of open ports and affected hosts will be inserted here)/c\\
|
||||
$open_ports_table" "$report_file" # Use 'c' instead of 'a'
|
||||
|
||||
# --- Populate Warning Open Ports ---
|
||||
|
||||
echo -e "\e[33mPopulating Warning Open Ports...\e[0m"
|
||||
|
||||
# Generate the Markdown list for warning open ports
|
||||
warning_ports_list=""
|
||||
|
||||
for port in $found_ports; do
|
||||
port_number="${port%.txt}" # Extract the port number (remove .txt)
|
||||
|
||||
# Check if the port is NOT in the allowed_ports list
|
||||
if ! echo "$allowed_ports" | grep -qw "$port_number"; then
|
||||
warning_ports_list+="* **$port_number:** See $results_dir/open-ports/$port for a list of IP's with the port open.\n"
|
||||
fi
|
||||
done
|
||||
|
||||
# Now, use awk to insert the warning_ports_list into the markdown report
|
||||
awk -v warning_ports="$warning_ports_list" '
|
||||
/## Suspicious Open Ports/ {
|
||||
print;
|
||||
print warning_ports;
|
||||
next
|
||||
}
|
||||
1' "$report_file" > temp_report.md && mv temp_report.md "$report_file"
|
||||
|
||||
echo ""
|
||||
echo -e "\e[1;34m Finished Running Script \e[0m"
|
||||
echo ""
|
||||
|
||||
|
||||
echo ""
|
||||
echo -e "\e[1;34m Finished Running Script \e[0m"
|
||||
echo ""
|
||||
Reference in New Issue
Block a user