Compare commits
2 Commits
f7ac93a626
...
02f697f4c1
| Author | SHA1 | Date | |
|---|---|---|---|
| 02f697f4c1 | |||
| f311b9b100 |
@@ -2623,7 +2623,9 @@ monitor_network_attacks() {
|
|||||||
|
|
||||||
# Smart whitelisting: Skip IPs with MANY successful established connections
|
# Smart whitelisting: Skip IPs with MANY successful established connections
|
||||||
# Only whitelist if IP has 20+ established connections (highly unlikely for attacker)
|
# Only whitelist if IP has 20+ established connections (highly unlikely for attacker)
|
||||||
local established_conns=$(ss -tn state established 2>/dev/null | grep "$ip" | wc -l)
|
# CRITICAL FIX: Use -w flag to match whole word (prevent partial IP matches)
|
||||||
|
# Example: "1.1.1.1" should not match "11.1.1.1" or "119.1.1.1"
|
||||||
|
local established_conns=$(ss -tn state established 2>/dev/null | grep -w "$ip" | wc -l)
|
||||||
[ -z "$established_conns" ] && established_conns=0
|
[ -z "$established_conns" ] && established_conns=0
|
||||||
if [ "$established_conns" -ge 20 ]; then
|
if [ "$established_conns" -ge 20 ]; then
|
||||||
# IP has 20+ established connections = highly likely legitimate user
|
# IP has 20+ established connections = highly likely legitimate user
|
||||||
@@ -2932,7 +2934,10 @@ monitor_network_attacks() {
|
|||||||
# Reset alert if connections drop below threshold
|
# Reset alert if connections drop below threshold
|
||||||
unset ALERT_SENT[$ip]
|
unset ALERT_SENT[$ip]
|
||||||
fi
|
fi
|
||||||
done < <(ss -tn state syn-recv 2>/dev/null | grep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}' | sort | uniq -c | awk '$1 > 5 {print $2, $1}')
|
# CRITICAL FIX: Change awk filter from '$1 > 5' to '$1 >= 3'
|
||||||
|
# Reason: Minimum threshold is 3 connections (Tier 4 attacks), so IPs with 3-5 connections must be processed
|
||||||
|
# Before fix: IPs with <6 connections were silently skipped, preventing detection in high-severity attacks
|
||||||
|
done < <(ss -tn state syn-recv 2>/dev/null | grep -oE '([0-9]{1,3}\.){3}[0-9]{1,3}' | sort | uniq -c | awk '$1 >= 3 {print $2, $1}')
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sleep 5 # Check every 5 seconds (faster detection during active attacks)
|
sleep 5 # Check every 5 seconds (faster detection during active attacks)
|
||||||
@@ -3346,8 +3351,10 @@ detect_distributed_attacks() {
|
|||||||
if [ ${#batch_ips[@]} -gt 0 ]; then
|
if [ ${#batch_ips[@]} -gt 0 ]; then
|
||||||
batch_block_ips "${batch_ips[@]}"
|
batch_block_ips "${batch_ips[@]}"
|
||||||
echo -e "${CRITICAL_COLOR}[${time_str}] DISTRIBUTED_ATTACK | ${attack_type} from ${unique_ips} IPs | BLOCKED ALL${NC}" >> "$TEMP_DIR/recent_events"
|
echo -e "${CRITICAL_COLOR}[${time_str}] DISTRIBUTED_ATTACK | ${attack_type} from ${unique_ips} IPs | BLOCKED ALL${NC}" >> "$TEMP_DIR/recent_events"
|
||||||
# BUG FIX: Increment block counter for distributed attacks
|
# CRITICAL FIX: Removed duplicate increment_block_counter call
|
||||||
increment_block_counter 1
|
# batch_block_ips() already calls increment_block_counter with the actual count on line 1027
|
||||||
|
# Adding another increment_block_counter 1 here causes double-counting
|
||||||
|
# (If 10 IPs blocked: would count as 11 instead of 10)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check for subnet-level coordination (25+ IPs from same /24)
|
# Check for subnet-level coordination (25+ IPs from same /24)
|
||||||
@@ -3483,14 +3490,15 @@ auto_mitigation_engine() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Start all log monitoring sources
|
# Start all log monitoring sources
|
||||||
monitor_apache_logs
|
# Start all monitoring subprocesses in background
|
||||||
monitor_ssh_attacks
|
monitor_apache_logs &
|
||||||
monitor_email_attacks
|
monitor_ssh_attacks &
|
||||||
monitor_ftp_attacks
|
monitor_email_attacks &
|
||||||
monitor_database_attacks
|
monitor_ftp_attacks &
|
||||||
monitor_firewall_blocks
|
monitor_database_attacks &
|
||||||
monitor_cphulk_blocks
|
monitor_firewall_blocks &
|
||||||
monitor_network_attacks
|
monitor_cphulk_blocks &
|
||||||
|
monitor_network_attacks &
|
||||||
|
|
||||||
# Display IPset initialization status
|
# Display IPset initialization status
|
||||||
if [ -n "$IPSET_INIT_ERROR" ]; then
|
if [ -n "$IPSET_INIT_ERROR" ]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user