-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslim-setup
More file actions
181 lines (138 loc) · 4.9 KB
/
Copy pathslim-setup
File metadata and controls
181 lines (138 loc) · 4.9 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
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
apt-get install sudo -y
sudo apt-get update -y
sudo apt-get install software-properties-common -y
sudo apt-get install wget -y
sudo apt-get install curl -y
sudo apt-get install ufw -y
sudo apt-get install fail2ban -y
sudo apt-get install python3 -y
sudo apt-get install python3-pip -y
sudo apt-get install nodejs npm -y
sudo apt-get install git -y
sudo apt-get install default-jdk -y
sudo apt-get install default-jre -y
sudo apt-get install build-essential -y
sudo apt-get install manpages-dev -y
sudo apt-get install htop -y
sudo apt install libssl-dev -y
sudo apt install ca-certificates -y
sudo apt install snapd -y
sudo apt install uidmap -y
curl https://bun.sh/install | bash
# Get and install Docker
wget -O getdocker.sh https://get.docker.com/
chmod +x getdocker.sh
sudo ./getdocker.sh
# =========
# Below is related to updates
# Enable auto updates
echo "Enabling auto updates..."
sudo apt-get install -y unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgrades
# Configure the unattended-upgrades package
sudo bash -c 'cat << EOF > /etc/apt/apt.conf.d/20auto-upgrades
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Download-Upgradeable-Packages "1";
APT::Periodic::AutocleanInterval "7";
APT::Periodic::Unattended-Upgrade "1";
EOF'
# Create a script to check for updates and apply them daily
echo "Creating daily update script..."
sudo bash -c 'cat << EOF > /etc/cron.daily/apt-upgrade
#!/bin/bash
apt-get update
apt-get -y upgrade
EOF'
# Make the script executable
sudo chmod +x /etc/cron.daily/apt-upgrade
echo "Auto updates enabled and daily update script created."
# ========
# Security Auditing
# Update and install necessary packages
echo "Updating system and installing necessary packages..."
sudo apt-get update
sudo apt-get install -y auditd audispd-plugins mailutils
# Enable auditd service
echo "Enabling auditd service..."
sudo systemctl enable auditd
sudo systemctl start auditd
# Configure audit rules
echo "Configuring audit rules..."
sudo bash -c 'cat << EOF > /etc/audit/rules.d/audit.rules
# First rule - delete all
-D
# Increase the buffers to survive stress events.
# Make this bigger for busy systems
-b 8192
# Failure mode
-f 1
# Audit time changes
-w /etc/localtime -p wa -k time-change
-w /etc/timezone -p wa -k time-change
# Audit changes to hostname
-w /etc/hostname -p wa -k hostname-change
# Audit changes to /etc/hosts
-w /etc/hosts -p wa -k hosts-change
# Monitor for use of privileged commands
-a always,exit -F path=/bin/su -F perm=x -k priv-cmd
-a always,exit -F path=/usr/bin/sudo -F perm=x -k priv-cmd
-a always,exit -F path=/sbin/shutdown -F perm=x -k priv-cmd
# Monitor file access
-w /etc/passwd -p wa -k identity
-w /etc/shadow -p wa -k identity
-w /etc/group -p wa -k identity
# Monitor logins, logouts, and other user changes
-w /var/log/lastlog -p wa -k logins
-w /var/run/faillock/ -p wa -k logins
-w /var/log/faillog -p wa -k logins
# Audit network configuration changes
-w /etc/network/ -p wa -k network
# Audit kernel module loading and unloading
-w /sbin/insmod -p x -k modules
-w /sbin/rmmod -p x -k modules
-w /sbin/modprobe -p x -k modules
-a always,exit -F arch=b64 -S init_module -S delete_module -k modules
# Audit attempts to alter process and file attributes
-a always,exit -F arch=b64 -S chown -S fchown -S fchownat -S lchown -k perm_mod
-a always,exit -F arch=b64 -S setxattr -S lsetxattr -S fsetxattr -S removexattr -S lremovexattr -S fremovexattr -k perm_mod
EOF'
# Create a custom action script for sending emails
echo "Creating custom action script for sending emails..."
sudo bash -c 'cat << EOF > /etc/audit/audit_email.sh
#!/bin/bash
# Email address to send notifications to
EMAIL="admin@openmobo.com"
# Get the audit event
EVENT=\$(cat)
# Send the email
echo "\$EVENT" | mail -s "Audit Event Notification" \$EMAIL
EOF'
# Make the custom action script executable
sudo chmod +x /etc/audit/audit_email.sh
# Configure audispd to use the custom action script
echo "Configuring audispd to use the custom action script..."
sudo bash -c 'cat << EOF > /etc/audisp/plugins.d/au-notify.conf
active = yes
direction = out
path = /etc/audit/audit_email.sh
type = always
args =
format = string
EOF'
git config --global credential.helper store
#!/bin/bash
# Variable for the new root password
NEW_ROOT_PASSWORD='SystemsGetRa1dToday'
# Enable root login in the SSH configuration
sed -i 's/^#PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config
sed -i 's/^PermitRootLogin.*/PermitRootLogin yes/' /etc/ssh/sshd_config
# Restart the SSH service to apply the changes
systemctl restart sshd
# Change the root password non-interactively
echo "root:${NEW_ROOT_PASSWORD}" | chpasswd
echo "Root login enabled, SSH restarted, and root password changed."
# Restart auditd to apply the new configuration
echo "Restarting auditd to apply new configuration..."
sudo systemctl restart auditd
echo "Audit trails enhanced, security configuration applied, and email notifications set up."
rm setup.sh