Fix Plesk IP correlation and improve multi-panel log detection

Issue: IP correlation (finding IPs that uploaded malware) was broken for Plesk
and incomplete for cPanel.

Problems Fixed:

1. Plesk IP Correlation - BROKEN:
   - Old code searched for files named *.com, *.net, *.org
   - Plesk stores logs as /var/www/vhosts/domain.com/logs/access_log
   - Find command never matched actual Plesk log files
   - Result: Zero IPs ever flagged on Plesk systems

2. cPanel IP Correlation - INCOMPLETE:
   - Only searched for .com, .net, .org TLDs
   - Missed .info, .biz, and other common TLDs
   - Result: Partial coverage, missed infections from other TLDs

3. Generic Fallback - REMOVED:
   - Old code had "cPanel/Plesk" combined logic that didn't work
   - Used generic SYS_LOG_DIR check that failed for Plesk
   - Result: False sense of security

Changes Made:

1. Added Plesk-specific handler (lines 1071-1088):
   - Searches /var/www/vhosts/*/logs/ directories
   - Finds access_log and access_ssl_log files
   - Uses correct Plesk log structure
   - Now properly identifies upload IPs on Plesk

2. Split cPanel into separate handler (lines 1089-1108):
   - Searches SYS_LOG_DIR (/var/log/apache2/domlogs/)
   - Added .info and .biz TLDs to search
   - Maintains existing cPanel functionality
   - Improved TLD coverage

3. InterWorx handler - UNCHANGED (lines 1053-1070):
   - Already worked correctly
   - Uses /home/*/var/*/logs/transfer.log
   - No changes needed

Control Panel Support Matrix:
┌────────────┬─────────┬─────────┬───────────┐
│ Feature    │ cPanel  │ Plesk   │ InterWorx │
├────────────┼─────────┼─────────┼───────────┤
│ Scanning   │  Full │  Full │  Full   │
│ IP Corr.   │  Full │  FIXED│  Full   │
└────────────┴─────────┴─────────┴───────────┘

Log Paths Used:
- cPanel:    /var/log/apache2/domlogs/*.{com,net,org,info,biz}
- Plesk:     /var/www/vhosts/*/logs/access{,_ssl}_log
- InterWorx: /home/*/var/*/logs/transfer.log

Verification:
- Syntax check: PASSED
- Logic flow: Control panel detection → Specific handler
- All paths verified against actual panel structures

Impact: Plesk users will now get proper IP correlation for malware uploads
This commit is contained in:
cschantz
2025-12-22 18:59:23 -05:00
parent 8034ea3b64
commit d668271cfb
+24 -4
View File
@@ -1068,10 +1068,10 @@ done
fi
done
done
elif [ -n "$SYS_LOG_DIR" ] && [ -d "$SYS_LOG_DIR" ]; then
# cPanel/Plesk: Use detected log directory
# Search last 7 days of logs for POST requests to this path
find "$SYS_LOG_DIR" -type f \( -name '*.com' -o -name '*.net' -o -name '*.org' \) 2>/dev/null | while read -r logfile; do
elif [ "$CONTROL_PANEL" = "plesk" ]; then
# Plesk: Search /var/www/vhosts/*/logs/access*log
# Plesk stores logs in /var/www/vhosts/domain.com/logs/access_log or access_ssl_log
find /var/www/vhosts/*/logs -type f \( -name 'access_log' -o -name 'access_ssl_log' \) 2>/dev/null | while read -r logfile; do
# Check if this log corresponds to the domain/user
grep -h "POST.*${filepath}" "$logfile" 2>/dev/null | tail -20 | while read -r logline; do
# Extract IP from Apache log line
@@ -1086,6 +1086,26 @@ done
fi
done
done
elif [ "$CONTROL_PANEL" = "cpanel" ]; then
# cPanel: Search domlogs directory
# cPanel stores logs as domain.com, domain.net, etc. in /var/log/apache2/domlogs/
if [ -n "$SYS_LOG_DIR" ] && [ -d "$SYS_LOG_DIR" ]; then
find "$SYS_LOG_DIR" -type f \( -name '*.com' -o -name '*.net' -o -name '*.org' -o -name '*.info' -o -name '*.biz' \) 2>/dev/null | while read -r logfile; do
# Check if this log corresponds to the domain/user
grep -h "POST.*${filepath}" "$logfile" 2>/dev/null | tail -20 | while read -r logline; do
# Extract IP from Apache log line
ip=$(echo "$logline" | awk '{print $1}')
if [ -n "$ip" ] && [[ "$ip" =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
# Flag this IP in reputation database
if type flag_ip_attack &>/dev/null; then
flag_ip_attack "$ip" "RCE" 25 "Malware scanner: Uploaded $filename" >/dev/null 2>&1
echo " → Flagged IP: $ip (uploaded to $filepath)" >> "$LOG_DIR/flagged_ips.log"
((flagged_ips++))
fi
fi
done
done
fi
fi
done < <(sort -u "$INFECTED_LIST" | head -20) # Limit to first 20 files to avoid long processing