#!/bin/bash # ------------------------------- # Security Audit Script # 1. Port Scan # 2. SSL Certificate Check # 3. Rate Limit Test # ------------------------------- if [ $# -lt 3 ]; then echo "Usage: $0 " echo "Example:" echo "./security_audit.sh 192.168.1.10 ghaymah.systems https://ghaymah.systems/api/login" exit 1 fi TARGET_IP=$1 DOMAIN=$2 LOGIN_URL=$3 OUTPUT="security_report.txt" echo "===================================" | tee $OUTPUT echo " Security Audit Report " | tee -a $OUTPUT echo "===================================" | tee -a $OUTPUT echo "" | tee -a $OUTPUT ################################################### # 1. Port Scan ################################################### echo "[1] Scanning Open Ports..." | tee -a $OUTPUT echo "-----------------------------------" | tee -a $OUTPUT nmap -p- -sV --open $TARGET_IP | tee -a $OUTPUT echo "" | tee -a $OUTPUT ################################################### # 2. SSL Check ################################################### echo "[2] Checking SSL Certificate..." | tee -a $OUTPUT echo "-----------------------------------" | tee -a $OUTPUT echo | openssl s_client \ -connect ${DOMAIN}:443 \ -servername ${DOMAIN} 2>/dev/null \ | openssl x509 -noout -dates -issuer -subject \ | tee -a $OUTPUT echo "" | tee -a $OUTPUT ################################################### # 3. Rate Limit Test ################################################### echo "[3] Testing Rate Limiting..." | tee -a $OUTPUT echo "-----------------------------------" | tee -a $OUTPUT for i in {1..20} do RESPONSE=$(curl -s \ -o /dev/null \ -w "%{http_code}" \ -X POST "$LOGIN_URL" \ -H "Content-Type: application/json" \ -d '{"username":"test","password":"wrong_password"}') echo "Request $i -> HTTP $RESPONSE" | tee -a $OUTPUT sleep 0.1 done echo "" | tee -a $OUTPUT echo "===================================" | tee -a $OUTPUT echo "Audit completed successfully." echo "Report saved as: $OUTPUT" echo "==================================="