-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsys-sec.sh
162 lines (137 loc) · 3.65 KB
/
sys-sec.sh
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/bash
# Set the path to the script's directory
SCRIPT_DIR=$(dirname "$0")
# Set the path to the system's log files
LOG_DIR=/var/log
# Set the path to the system's firewall configuration file
FIREWALL_CONFIG=/etc/sysconfig/iptables
# Set the path to the system's SSH configuration file
SSH_CONFIG=/etc/ssh/sshd_config
# Set the path to the system's SELinux configuration file
SELINUX_CONFIG=/etc/selinux/config
# Set the path to the system's system configuration file
SYSTEM_CONFIG=/etc/default/system
# Set the path to the system's network configuration file
NETWORK_CONFIG=/etc/network/interfaces
# Set the path to the system's system users and groups file
USERS_GROUPS_FILE=/etc/passwd
# Set the path to the system's file system permissions file
FS_PERMS_FILE=/etc/group
# Function to check firewall configuration
check_firewall() {
if [ ! -f "$FIREWALL_CONFIG" ]; then
echo "Error: Firewall configuration file not found!"
exit 1
fi
# Check if the firewall is enabled
if grep -q "iptables" "$FIREWALL_CONFIG"; then
echo "Firewall is enabled."
else
echo "Error: Firewall is not enabled!"
exit 1
fi
}
# Function to check system updates and patches
check_updates() {
# Check if there are any pending updates
if apt-get update -y && apt-get upgrade -y; then
echo "System is up to date."
else
echo "Error: System is not up to date!"
exit 1
fi
}
# Function to check SSH configuration
check_ssh() {
if [ ! -f "$SSH_CONFIG" ]; then
echo "Error: SSH configuration file not found!"
exit 1
fi
# Check if the SSH server is listening
if netstat -tlnp | grep -q "ssh"; then
echo "SSH server is listening."
else
echo "Error: SSH server is not listening!"
exit 1
fi
}
# Function to check SELinux configuration
check_selinux() {
if [ ! -f "$SELINUX_CONFIG" ]; then
echo "Error: SELinux configuration file not found!"
exit 1
fi
# Check if SELinux is enabled
if grep -q "SELINUX=enforcing" "$SELINUX_CONFIG"; then
echo "SELinux is enabled."
else
echo "Error: SELinux is not enabled!"
exit 1
fi
}
# Function to check system logs
check_logs() {
if [ ! -d "$LOG_DIR" ]; then
echo "Error: Log directory not found!"
exit 1
fi
# Check if the log files are not empty
if [ -s "$LOG_DIR/access.log" ]; then
echo "Log files are not empty."
else
echo "Error: Log files are empty!"
exit 1
fi
}
# Function to check network configuration
check_network() {
if [ ! -f "$NETWORK_CONFIG" ]; then
echo "Error: Network configuration file not found!"
exit 1
fi
# Check if the network interface is up
if ip addr show | grep -q "eth0"; then
echo "Network interface is up."
else
echo "Error: Network interface is down!"
exit 1
fi
}
# Function to check system users and groups
check_users_groups() {
if [ ! -f "$USERS_GROUPS_FILE" ]; then
echo "Error: Users and groups file not found!"
exit 1
fi
# Check if there are any suspicious users or groups
if grep -q "root" "$USERS_GROUPS_FILE"; then
echo "Root user is present."
else
echo "Error: Root user is not present!"
exit 1
fi
}
# Function to check file system permissions
check_fs_perms() {
if [ ! -f "$FS_PERMS_FILE" ]; then
echo "Error: File system permissions file not found!"
exit 1```
if grep -q "root" "$FS_PERMS_FILE"; then
echo "Root user has correct permissions."
else
echo "Error: Root user has incorrect permissions!"
exit 1
fi
}
# Run the checks
check_firewall
check_updates
check_ssh
check_selinux
check_logs
check_network
check_users_groups
check_fs_perms
# Exit with a success message
echo "System security checks completed successfully."
exit 0