-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkernel_check.sh
More file actions
115 lines (99 loc) · 4.79 KB
/
kernel_check.sh
File metadata and controls
115 lines (99 loc) · 4.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
# ==========================================
# Kernel Parameter Hardening Audit Script
# ==========================================
# Ensure the script is run as root (sysctl reads are safer as root)
if [ "$EUID" -ne 0 ]; then
echo "Please run this script as root (sudo ./kernel_check.sh)."
exit 1
fi
echo "=== SECTION 7: KERNEL PARAMETER HARDENING ==="
# ---------------------------------------------------------
# Check 7.1.1: Address Space Layout Randomization (ASLR)
# ---------------------------------------------------------
ID="7.1.1 "
DESC="Ensure ASLR is fully enabled"
VAL=$(sysctl -n kernel.randomize_va_space 2>/dev/null)
if [ "$VAL" = "2" ]; then
printf "ID: %s | [PASSED] | %s\n" "$ID" "$DESC"
echo " Remediation: None required. ASLR is fully enabled."
else
printf "ID: %s | [FAILED] | %s\n" "$ID" "$DESC"
echo " Remediation: Set 'kernel.randomize_va_space = 2' in /etc/sysctl.d/99-security.conf and run 'sysctl -p'."
fi
# ---------------------------------------------------------
# Check 7.1.2: SYN Cookies (tcp_syncookies)
# ---------------------------------------------------------
ID="7.1.2 "
DESC="Ensure TCP SYN Cookies are enabled"
VAL=$(sysctl -n net.ipv4.tcp_syncookies 2>/dev/null)
if [ "$VAL" = "1" ]; then
printf "ID: %s | [PASSED] | %s\n" "$ID" "$DESC"
echo " Remediation: None required. SYN flood protection is active."
else
printf "ID: %s | [FAILED] | %s\n" "$ID" "$DESC"
echo " Remediation: Set 'net.ipv4.tcp_syncookies = 1' in /etc/sysctl.d/99-security.conf and run 'sysctl -p'."
fi
# ---------------------------------------------------------
# Check 7.1.3: ICMP Redirect Acceptance
# ---------------------------------------------------------
ID="7.1.3 "
DESC="Ensure ICMP redirects are not accepted"
VAL_ALL=$(sysctl -n net.ipv4.conf.all.accept_redirects 2>/dev/null)
VAL_DEF=$(sysctl -n net.ipv4.conf.default.accept_redirects 2>/dev/null)
if [ "$VAL_ALL" = "0" ] && [ "$VAL_DEF" = "0" ]; then
printf "ID: %s | [PASSED] | %s\n" "$ID" "$DESC"
echo " Remediation: None required. Malicious routing table manipulation is blocked."
else
printf "ID: %s | [FAILED] | %s\n" "$ID" "$DESC"
echo " Remediation: Set 'net.ipv4.conf.all.accept_redirects = 0' and 'net.ipv4.conf.default.accept_redirects = 0' in /etc/sysctl.d/99-security.conf."
fi
# ---------------------------------------------------------
# Check 7.1.4: Source Routing
# ---------------------------------------------------------
ID="7.1.4 "
DESC="Ensure source routed packets are not accepted"
VAL_ALL=$(sysctl -n net.ipv4.conf.all.accept_source_route 2>/dev/null)
VAL_DEF=$(sysctl -n net.ipv4.conf.default.accept_source_route 2>/dev/null)
if [ "$VAL_ALL" = "0" ] && [ "$VAL_DEF" = "0" ]; then
printf "ID: %s | [PASSED] | %s\n" "$ID" "$DESC"
echo " Remediation: None required. Source routing is disabled."
else
printf "ID: %s | [FAILED] | %s\n" "$ID" "$DESC"
echo " Remediation: Set 'net.ipv4.conf.all.accept_source_route = 0' and 'net.ipv4.conf.default.accept_source_route = 0' in /etc/sysctl.d/99-security.conf."
fi
# ---------------------------------------------------------
# Check 7.1.5: Martian Packet Logging
# ---------------------------------------------------------
ID="7.1.5 "
DESC="Ensure suspicious packets are logged (Martians)"
VAL_ALL=$(sysctl -n net.ipv4.conf.all.log_martians 2>/dev/null)
VAL_DEF=$(sysctl -n net.ipv4.conf.default.log_martians 2>/dev/null)
if [ "$VAL_ALL" = "1" ] && [ "$VAL_DEF" = "1" ]; then
printf "ID: %s | [PASSED] | %s\n" "$ID" "$DESC"
echo " Remediation: None required. Martian packet logging is enabled."
else
printf "ID: %s | [FAILED] | %s\n" "$ID" "$DESC"
echo " Remediation: Set 'net.ipv4.conf.all.log_martians = 1' and 'net.ipv4.conf.default.log_martians = 1' in /etc/sysctl.d/99-security.conf."
fi
# ---------------------------------------------------------
# Check 7.1.6: IP Forwarding (Docker-Aware)
# ---------------------------------------------------------
ID="7.1.6 "
DESC="Ensure IP forwarding is securely configured"
VAL=$(sysctl -n net.ipv4.ip_forward 2>/dev/null)
# Check if Docker is installed and running
DOCKER_ACTIVE=false
if command -v docker >/dev/null 2>&1 && systemctl is-active --quiet docker; then
DOCKER_ACTIVE=true
fi
if [ "$VAL" = "0" ]; then
printf "ID: %s | [PASSED] | %s\n" "$ID" "$DESC"
echo " Remediation: None required. IP forwarding is disabled."
elif [ "$VAL" = "1" ] && [ "$DOCKER_ACTIVE" = true ]; then
printf "ID: %s | [PASSED] | %s\n" "$ID" "$DESC"
echo " Remediation: None required. IP forwarding is enabled, but Docker is detected (Required for containers)."
else
printf "ID: %s | [FAILED] | %s\n" "$ID" "$DESC"
echo " Remediation: Set 'net.ipv4.ip_forward = 0' in /etc/sysctl.d/99-security.conf (Unless this server is a router)."
fi