From 6261fabf7a0705b1e55b845b38c02c70b0a5f742 Mon Sep 17 00:00:00 2001 From: Developer Date: Tue, 21 Apr 2026 21:11:51 -0400 Subject: [PATCH] Fix: Consolidate scanner detection arrays to single lowercase name ISSUE: Maldet menu was running all scanners (ImunifyAV, ClamAV, RKHunter) instead of only Maldet due to architectural flaw in scanner detection. ROOT CAUSE: Two separate scanner detection systems populated different arrays: - detect_scanners() function: populated lowercase available_scanners[] - main scanning logic: populated uppercase AVAILABLE_SCANNERS[] These arrays never communicated, causing MALDET_ONLY filter to fail. FIX: Consolidated all scanner detection to use single lowercase available_scanners[] - Line 1395: Changed initial array declaration - Lines 1397-1416: Fixed scanner detection assignments - Lines 1445, 1468: Fixed rkhunter temp install assignments - Line 1498: Fixed empty array check - Line 1544: Fixed scanner count logging - Line 1606: Fixed summary report scanner list - Lines 1617, 1620: Fixed completion tracking loops - Lines 2075, 2081, 2087, 2092: Fixed scanner-specific result reporting - Line 2135: Fixed validation loop RESULT: - Maldet menu now correctly runs ONLY Maldet scans - Multi-scanner orchestration still works correctly - Single consistent data structure throughout execution - MALDET_ONLY filter now works as intended VERIFIED: bash -n syntax check passes --- modules/security/malware-scanner.sh | 36 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/modules/security/malware-scanner.sh b/modules/security/malware-scanner.sh index db0c78a..d1c1118 100755 --- a/modules/security/malware-scanner.sh +++ b/modules/security/malware-scanner.sh @@ -1391,21 +1391,21 @@ log_message "Scan session started" # Create marker file to indicate scan is running touch "$SCAN_DIR/.scan_running" -# Detect available scanners -AVAILABLE_SCANNERS=() +# Detect available scanners (consolidate into lowercase array) +available_scanners=() if command -v imunify-antivirus &>/dev/null; then - AVAILABLE_SCANNERS+=("imunify") + available_scanners+=("imunify") log_message "Detected: ImunifyAV" fi if command -v clamscan &>/dev/null; then - AVAILABLE_SCANNERS+=("clamav") + available_scanners+=("clamav") log_message "Detected: ClamAV" fi if command -v maldet &>/dev/null; then - AVAILABLE_SCANNERS+=("maldet") + available_scanners+=("maldet") log_message "Detected: Maldet" fi @@ -1413,7 +1413,7 @@ fi RKHUNTER_TEMP_INSTALLED=false if command -v rkhunter &>/dev/null; then - AVAILABLE_SCANNERS+=("rkhunter") + available_scanners+=("rkhunter") log_message "Detected: Rootkit Hunter" else # Auto-install rkhunter temporarily for this scan @@ -1442,7 +1442,7 @@ else log_message "WARNING: RKHunter property baseline creation failed" fi - AVAILABLE_SCANNERS+=("rkhunter") + available_scanners+=("rkhunter") RKHUNTER_TEMP_INSTALLED=true log_message "RKHunter installed temporarily" echo " ✓ RKHunter installed (will be removed after scan)" @@ -1465,7 +1465,7 @@ else log_message "WARNING: RKHunter property baseline creation failed" fi - AVAILABLE_SCANNERS+=("rkhunter") + available_scanners+=("rkhunter") RKHUNTER_TEMP_INSTALLED=true log_message "RKHunter installed temporarily" echo " ✓ RKHunter installed (will be removed after scan)" @@ -1495,7 +1495,7 @@ if [ "${MALDET_ONLY:-0}" = "1" ]; then fi # If no scanners found, show installation guide and exit gracefully -if [ ${#AVAILABLE_SCANNERS[@]} -eq 0 ]; then +if [ ${#available_scanners[@]} -eq 0 ]; then log_message "WARNING: No scanners found on this system" echo "" echo -e "${RED}No malware scanners detected!${NC}" @@ -1541,7 +1541,7 @@ if [ ${#AVAILABLE_SCANNERS[@]} -eq 0 ]; then exit 0 fi -log_message "Found ${#AVAILABLE_SCANNERS[@]} scanner(s): ${AVAILABLE_SCANNERS[*]}" +log_message "Found ${#available_scanners[@]} scanner(s): ${available_scanners[*]}" # Scan paths (will be replaced) SCAN_PATHS=() @@ -1603,7 +1603,7 @@ fi echo "==========================================" echo "Session: $(basename "$SCAN_DIR")" echo "Started: $(date)" - echo "Scanners: ${AVAILABLE_SCANNERS[*]}" + echo "Scanners: ${available_scanners[*]}" echo "Paths: ${#SCAN_PATHS[@]}" echo "" printf '%s\n' "${SCAN_PATHS[@]}" @@ -1614,10 +1614,10 @@ fi # Track completion SCANNERS_COMPLETED=0 -TOTAL_SCANNERS=${#AVAILABLE_SCANNERS[@]} +TOTAL_SCANNERS=${#available_scanners[@]} # Run each scanner -for scanner in "${AVAILABLE_SCANNERS[@]}"; do +for scanner in "${available_scanners[@]}"; do SCANNER_NUM=$((SCANNERS_COMPLETED + 1)) echo "" @@ -2072,24 +2072,24 @@ done echo "────────────────────────────────────────" # ImunifyAV results - if echo "${AVAILABLE_SCANNERS[*]}" | grep -q "imunify"; then + if echo "${available_scanners[*]}" | grep -q "imunify"; then IMUNIFY_COUNT=$(grep -o "ImunifyAV scan complete - Found: [0-9]*" "$SUMMARY_FILE" | grep -o "[0-9]*$" || echo "N/A") printf "%-20s %s\n" "ImunifyAV:" "$IMUNIFY_COUNT threats detected" fi # ClamAV results - if echo "${AVAILABLE_SCANNERS[*]}" | grep -q "clamav"; then + if echo "${available_scanners[*]}" | grep -q "clamav"; then CLAM_COUNT=$(grep -o "ClamAV scan complete - Found: [0-9]*" "$SUMMARY_FILE" | grep -o "[0-9]*$" || echo "N/A") printf "%-20s %s\n" "ClamAV:" "$CLAM_COUNT infected files" fi # Maldet results - if echo "${AVAILABLE_SCANNERS[*]}" | grep -q "maldet"; then + if echo "${available_scanners[*]}" | grep -q "maldet"; then printf "%-20s %s\n" "Maldet:" "Scan complete (check logs)" fi # RKHunter results - if echo "${AVAILABLE_SCANNERS[*]}" | grep -q "rkhunter"; then + if echo "${available_scanners[*]}" | grep -q "rkhunter"; then RKH_COUNT=$(grep -o "RKHunter scan complete - Warnings: [0-9]*" "$SUMMARY_FILE" | grep -o "[0-9]*$" || echo "N/A") printf "%-20s %s\n" "Rootkit Hunter:" "$RKH_COUNT warnings" fi @@ -2132,7 +2132,7 @@ log_message "Validating scan results..." validation_issues=0 # Check that each scanner produced output -for scanner in "${AVAILABLE_SCANNERS[@]}"; do +for scanner in "${available_scanners[@]}"; do case "$scanner" in imunify) if [ ! -s "$LOG_DIR/imunify.log" ]; then