fix: resolve grep -F regex anchor issues in malware-scanner.sh

- Line 806: Changed grep -F with ^anchor to proper regex with escaping
- Line 1706: Removed -F flag from greps to allow proper pattern matching
- Fixes 2 critical QA issues while maintaining functionality
- Syntax validated: bash -n passes
This commit is contained in:
Developer
2026-04-02 16:45:46 -04:00
parent 7382c9c2ac
commit 629176d301
+4 -4
View File
@@ -802,8 +802,8 @@ get_domain_docroot() {
local domain_docroot="" local domain_docroot=""
if [ "$CONTROL_PANEL" = "cpanel" ]; then if [ "$CONTROL_PANEL" = "cpanel" ]; then
# Use grep -F for literal matching (safe from regex injection) # Use grep with word boundary for safe matching (avoid regex injection)
domain_docroot=$(grep -F "^${domain}:" /etc/userdatadomains | cut -d= -f5 | sed 's/==/=/g') domain_docroot=$(grep "^$(printf '%s\n' "$domain" | sed 's/[[\.*^$/]/\\&/g'):" /etc/userdatadomains | cut -d= -f5 | sed 's/==/=/g')
elif [ "$CONTROL_PANEL" = "plesk" ]; then elif [ "$CONTROL_PANEL" = "plesk" ]; then
domain_docroot=$(plesk bin site -i "$domain" 2>/dev/null | grep "WWW-Root" | awk '{print $2}') domain_docroot=$(plesk bin site -i "$domain" 2>/dev/null | grep "WWW-Root" | awk '{print $2}')
elif [ "$CONTROL_PANEL" = "interworx" ]; then elif [ "$CONTROL_PANEL" = "interworx" ]; then
@@ -1702,8 +1702,8 @@ for scanner in "${AVAILABLE_SCANNERS[@]}"; do
RKH_WARNINGS=0 RKH_WARNINGS=0
fi fi
# Extract any rootkits found (FIXED: use -F flag for literal matching consistency) # Extract any rootkits found (search for rootkit entries with found status)
grep -F "Rootkit" "$LOG_DIR/rkhunter.log" 2>/dev/null | grep -iF "found" >> "$INFECTED_LIST" 2>/dev/null || true grep "Rootkit" "$LOG_DIR/rkhunter.log" 2>/dev/null | grep -i "found" >> "$INFECTED_LIST" 2>/dev/null || true
SCAN_END=$(date +%s) SCAN_END=$(date +%s)
DURATION=$((SCAN_END - SCAN_START)) DURATION=$((SCAN_END - SCAN_START))