Skip to content

Commit 3f9fef4

Browse files
author
Samson.W
authored
Merge pull request #12 from hardenedlinux/master
Pull from master to harbian-audit-deepin
2 parents 7812833 + 61327ff commit 3f9fef4

File tree

43 files changed

+792
-508
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+792
-508
lines changed

README-CN.md

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,24 +151,41 @@ EXCEPTIONS=""
151151
4) 设置基本的iptables防火墙规则
152152
根据实现场景进行防火墙规则的配置,可参考HardenedLinux社区归纳的基于Debian GNU/Linux的防火墙规则的基本规则:
153153
[etc.iptables.rules.v4.sh](https://github.com/hardenedlinux/harbian-audit/blob/master/docs/configurations/etc.iptables.rules.v4.sh)
154-
执行如下的命令进行部署:
154+
155+
基于iptables的部署:
155156
```
156157
$ INTERFACENAME="your network interfacename(Example eth0)"
157-
$ sed -i "s/PUB_IFS=.*/PUB_IFS=\"$INTERFACENAME\"/g" docs/configurations/etc.iptables.rules.v4.sh
158-
$ sudo bash docs/configurations/etc.iptables.rules.v4.sh
158+
$ sudo bash docs/configurations/etc.iptables.rules.v4.sh $INTERFACENAME
159159
$ sudo -s
160160
# iptables-save > /etc/iptables/rules.v4
161161
# ip6tables-save > /etc/iptables/rules.v6
162162
```
163-
5) 使用passwd命令改变所有用户的密码,以满足pam_cracklib模块配置的密码复杂度及健壮性。
163+
基于nft的部署:
164+
按照以下命令修改nftables.conf(你的对外网口的名称,例如:eth0):
165+
```
166+
$ sed -i 's/^define int_if = ens33/define int_if = eth0/g' etc.nftables.conf
167+
$ sudo nft -f ./etc.nftables.conf
168+
```
169+
5) 当所有安全基线项都修复完成后,使用--final方法将完成以下的最终的工作:
170+
1.使用passwd命令去重新设置常规用户及root用户的密码,以满足pam_cracklib模块配置的密码强度和健壮性。
171+
2. 重新初始化aide工具的数据库。
172+
```
173+
$ sudo bin/hardening.sh --final
174+
```
164175

165176
## 特别注意
166-
一些检查项需要依赖多次修复,且操作系统需要多次重启。需要进行两次修复的项有:
177+
178+
### 必须在第一次修复应用后进行修复的项
179+
8.1.32 因为此项一旦设置,审计规则将不能够再进行添加。
180+
181+
### 必须在所有项都修复应用后进行修复的项
182+
8.4.1 8.4.2 这都是与aide检测文件完整性相关的项,最好是在所有项都修复好后再进行修复,以修复好的系统中的文件进行完整性的数据库的初始化。
183+
184+
### 一些检查项需要依赖多次修复,且操作系统需要多次重启
185+
#### 需要进行两次修复的项
167186
8.1.1.2
168187
8.1.1.3
169188
8.1.12
170-
171-
需要修复3次的项:
172189
4.5
173190

174191
## 玩(如何添加检查项)
@@ -219,15 +236,15 @@ This document is a description of the additions to the sections not included in
219236
The HardenedLinux community has created public AMI images for three different regions.
220237

221238
Destination region: US East(Ohio)
222-
AMI ID: ami-0459b7f679f8941a4
239+
AMI ID: ami-091d37e9d358aaa84
223240
AMI Name: harbian-audit complianced for Debian GNU/Linux 9
224241

225242
Destination region: EU(Frankfurt)
226-
AMI ID: ami-022f30970530a0c5b
243+
AMI ID: ami-073725a8c2cf45418
227244
AMI Name: harbian-audit complianced for Debian GNU/Linux 9
228245

229246
Destination region: Asia Pacific(Tokyo)
230-
AMI ID: ami-003de0c48c2711265
247+
AMI ID: ami-06c0adb6ee5e7d417
231248
AMI Name: harbian-audit complianced for Debian GNU/Linux 9
232249

233250
#### 相关文档

README.md

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,7 @@ Set the corresponding firewall rules according to the applications used. Hardene
169169
to do the following:
170170
```
171171
$ INTERFACENAME="your network interfacename(Example eth0)"
172-
$ sed -i "s/PUB_IFS=.*/PUB_IFS=\"$INTERFACENAME\"/g" docs/configurations/etc.iptables.rules.v4.sh
173-
$ sudo bash docs/configurations/etc.iptables.rules.v4.sh
172+
$ sudo bash docs/configurations/etc.iptables.rules.v4.sh $INTERFACENAME
174173
$ sudo -s
175174
# iptables-save > /etc/iptables/rules.v4
176175
# ip6tables-save > /etc/iptables/rules.v6
@@ -183,18 +182,28 @@ to do the following(your network interfacename(Example eth0)):
183182
$ sed -i 's/^define int_if = ens33/define int_if = eth0/g' etc.nftables.conf
184183
$ sudo nft -f ./etc.nftables.conf
185184
```
186-
187-
5) Use the passwd command to change the passwords of all users, and change the password to a secure and reliable password entry with the same password complexity set by the pam_cracklib module.
185+
5) When all repairs are completed. --final method will:
186+
1. Use passwd command to change the password of the regular and root user to apply the password complexity and robustness of the pam_cracklib module configuration.
187+
2. Aide reinitializes.
188+
```
189+
$ sudo bin/hardening.sh --final
190+
```
188191

189192
## Special Note
190193
Some check items check a variety of situations and are interdependent, they must be applied (fix) multiple times, and the OS must be a reboot after each applies (fix).
191194

192-
Items that need to be fix twice:
195+
### Items that must be applied after the first application(reboot after is better)
196+
8.1.32 Because this item is set, the audit rules will not be added.
197+
198+
### Items that must be applied after all application is ok
199+
8.4.1
200+
8.4.2
201+
These are all related to the aide. It is best to fix all the items after they have been fixed to fix the integrity of the database in the system.
202+
203+
### Items that need to be fix twice
193204
8.1.1.2
194205
8.1.1.3
195206
8.1.12
196-
197-
Items that need to be fix three times:
198207
4.5
199208

200209
## Hacking
@@ -249,15 +258,15 @@ This document is a description of the additions to the sections not included in
249258
The HardenedLinux community has created public AMI images for three different regions.
250259

251260
Destination region: US East(Ohio)
252-
AMI ID: ami-0459b7f679f8941a4
261+
AMI ID: ami-091d37e9d358aaa84
253262
AMI Name: harbian-audit complianced for Debian GNU/Linux 9
254263

255264
Destination region: EU(Frankfurt)
256-
AMI ID: ami-022f30970530a0c5b
265+
AMI ID: ami-073725a8c2cf45418
257266
AMI Name: harbian-audit complianced for Debian GNU/Linux 9
258267

259268
Destination region: Asia Pacific(Tokyo)
260-
AMI ID: ami-003de0c48c2711265
269+
AMI ID: ami-06c0adb6ee5e7d417
261270
AMI Name: harbian-audit complianced for Debian GNU/Linux 9
262271

263272
#### Docs

bin/hardening.sh

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ ALLOW_SERVICE_LIST=0
2424
SET_HARDENING_LEVEL=0
2525
SUDO_MODE=''
2626
INIT_G_CONFIG=0
27+
FINAL_G_CONFIG=0
2728

2829
usage() {
2930
cat << EOF
@@ -32,11 +33,11 @@ $LONG_SCRIPT_NAME <RUN_MODE> [OPTIONS], where RUN_MODE is one of:
3233
--help -h
3334
Show this help
3435
35-
--init
36-
Initialize the global configuration file(/etc/default/cis-hardening) based
37-
on the release version number.
36+
--init
37+
Initialize the global configuration file(/etc/default/cis-hardening) based
38+
on the release version number.
3839
39-
--apply
40+
--apply
4041
Apply hardening for enabled scripts.
4142
Beware that NO confirmation is asked whatsoever, which is why you're warmly
4243
advised to use --audit before, which can be regarded as a dry-run mode.
@@ -81,7 +82,13 @@ $LONG_SCRIPT_NAME <RUN_MODE> [OPTIONS], where RUN_MODE is one of:
8182
as http, mail, etc. Can be specified multiple times to allow multiple services.
8283
Use --allow-service-list to get a list of supported services.
8384
Example:
84-
bin/hardening.sh --set-hardening-level 5 --allow-service dns,http
85+
bin/hardening.sh --set-hardening-level 5 --allow-service dns,http
86+
87+
--final
88+
The final action that needs to be done when all repairs are completed. The action items are:
89+
1. Use passwd to change the password of the regular and root user to update the user
90+
password strength and robustness;
91+
2. Aide reinitializes.
8592
8693
OPTIONS:
8794
@@ -148,6 +155,9 @@ while [[ $# > 0 ]]; do
148155
--init)
149156
INIT_G_CONFIG=1
150157
;;
158+
--final)
159+
FINAL_G_CONFIG=1
160+
;;
151161
*)
152162
usage
153163
;;
@@ -170,6 +180,7 @@ fi
170180
[ -r $CIS_ROOT_DIR/lib/common.sh ] && . $CIS_ROOT_DIR/lib/common.sh
171181
[ -r $CIS_ROOT_DIR/lib/utils.sh ] && . $CIS_ROOT_DIR/lib/utils.sh
172182

183+
# For --init
173184
if [ $INIT_G_CONFIG -eq 1 ]; then
174185
if [ -r /etc/redhat-release ]; then
175186
info "This OS is redhat/CentOS."
@@ -194,6 +205,36 @@ else
194205
exit 128
195206
fi
196207

208+
# For --final
209+
if [ $FINAL_G_CONFIG -eq 1 ]; then
210+
# Reset passwd for regular and root user
211+
USERSNAME=$(cat /etc/passwd | awk -F':' '{if($3>=1000 && $3<65534) {print $1}}')
212+
for USER in $USERSNAME; do
213+
RESETCONTIN="n"
214+
read -p "Will password of $USER be reset, are you sure to continue?(y/N)" RESETCONTIN
215+
if [ "$RESETCONTIN" == "y" ]; then
216+
passwd $USER
217+
else
218+
continue
219+
fi
220+
done
221+
RESETCONTIN="n"
222+
read -p "Will password of root be reset, are you sure to continue?(y/N)" RESETCONTIN
223+
if [ "$RESETCONTIN" == "y" ]; then
224+
passwd
225+
fi
226+
227+
# Reinit aide database
228+
info "Will reinitialize the AIDE database"
229+
if [ $OS_RELEASE -eq 1 ]; then
230+
aideinit
231+
elif [ $OS_RELEASE -eq 2 ]; then
232+
aide --init
233+
mv /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz
234+
fi
235+
exit 0
236+
fi
237+
197238
# If --allow-service-list is specified, don't run anything, just list the supported services
198239
if [ "$ALLOW_SERVICE_LIST" = 1 ] ; then
199240
declare -a HARDENING_EXCEPTIONS_LIST

bin/hardening/2.1_tmp_partition.sh

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@ HARDENING_LEVEL=2
1616

1717
# Quick factoring as many script use the same logic
1818
PARTITION="/tmp"
19-
TMPMOUNTNAME="tmp.mount"
19+
SERVICENAME="tmp.mount"
20+
SERVICEPATH_DEBIAN="/usr/share/systemd/tmp.mount"
21+
REDHAT_SERVICEPATH="/usr/lib/systemd/system/tmp.mount"
22+
DEBIAN_SERVICEPATH="/lib/systemd/system/tmp.mount"
2023

2124
# This function will be called if the script status is on enabled / audit mode
2225
audit () {
@@ -36,19 +39,12 @@ audit () {
3639
fi
3740
else
3841
warn "$PARTITION is not partition in /etc/fstab, check tmp.mount service"
39-
if [ $(systemctl | grep -c "tmp.mount[[:space:]]*loaded[[:space:]]active[[:space:]]mounted") -eq 1 ]; then
40-
ok "$TMPMOUNTNAME service is active!"
41-
is_mounted "$PARTITION"
42-
if [ $FNRET -gt 0 ]; then
43-
warn "$PARTITION is not mounted"
44-
FNRET=3
45-
else
46-
ok "$PARTITION is mounted"
47-
FNRET=0
48-
fi
42+
is_service_active $SERVICENAME
43+
if [ $FNRET -eq 0 ]; then
44+
ok "$SERVICENAME service is active!"
4945
else
50-
crit "$TMPMOUNTNAME service is not active!"
51-
FNRET=4
46+
crit "$SERVICENAME service is inactive!"
47+
FNRET=3
5248
fi
5349
fi
5450
}
@@ -63,12 +59,30 @@ apply () {
6359
warn "mounting $PARTITION"
6460
mount $PARTITION
6561
elif [ $FNRET = 3 ]; then
66-
$SUDO_CMD systemctl daemon-reload
67-
$SUDO_CMD systemctl start "$TMPMOUNTNAME"
68-
elif [ $FNRET = 4 ]; then
69-
$SUDO_CMD systemctl enable "$TMPMOUNTNAME"
70-
$SUDO_CMD systemctl daemon-reload
71-
$SUDO_CMD systemctl start "$TMPMOUNTNAME"
62+
if [ $OS_RELEASE -eq 1 ]; then
63+
if [ -e $DEBIAN_SERVICEPATH ]; then
64+
$SUDO_CMD systemctl enable "$SERVICENAME"
65+
$SUDO_CMD systemctl daemon-reload
66+
$SUDO_CMD systemctl start "$SERVICENAME"
67+
else
68+
if [ -e $SERVICEPATH_DEBIAN ]; then
69+
cp $SERVICEPATH_DEBIAN $DEBIAN_SERVICEPATH
70+
$SUDO_CMD systemctl enable "$SERVICENAME"
71+
$SUDO_CMD systemctl daemon-reload
72+
$SUDO_CMD systemctl start "$SERVICENAME"
73+
else
74+
crit "System unit file $DEBIAN_SERVICEPATH is not exist!"
75+
fi
76+
fi
77+
elif [ $OS_RELEASE -eq 2 ]; then
78+
if [ -e $REDHAT_SERVICEPATH ]; then
79+
$SUDO_CMD systemctl enable "$SERVICENAME"
80+
$SUDO_CMD systemctl daemon-reload
81+
$SUDO_CMD systemctl start "$SERVICENAME"
82+
else
83+
crit "System unit file $REDHAT_SERVICEPATH is not exist!"
84+
fi
85+
fi
7286
fi
7387
}
7488

bin/hardening/2.2_tmp_nodev.sh

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ HARDENING_LEVEL=2
1818
PARTITION="/tmp"
1919
OPTION="nodev"
2020
SERVICENAME="tmp.mount"
21-
SERVICEPATH="/usr/share/systemd/tmp.mount"
21+
SERVICEPATH_DEBIAN="/usr/share/systemd/tmp.mount"
2222
REDHAT_SERVICEPATH="/usr/lib/systemd/system/tmp.mount"
23+
DEBIAN_SERVICEPATH="/lib/systemd/system/tmp.mount"
2324

2425
# This function will be called if the script status is on enabled / audit mode
2526
audit () {
@@ -46,43 +47,45 @@ audit () {
4647
fi
4748
else
4849
warn "$PARTITION is not partition in /etc/fstab, check tmp.mount service"
49-
if [ -e $SERVICEPATH -o -e $REDHAT_SERVICEPATH ]; then
50-
if [ $OS_RELEASE -eq 2 ]; then
51-
has_mount_option_systemd $REDHAT_SERVICEPATH $OPTION
52-
else
53-
has_mount_option_systemd $SERVICEPATH $OPTION
54-
fi
55-
if [ $FNRET -gt 0 ]; then
56-
crit "$PARTITION has no option $OPTION in systemd service!"
57-
FNRET=3
58-
else
59-
ok "$PARTITION has $OPTION in systemd service"
60-
has_mounted_option $PARTITION $OPTION
61-
if [ $FNRET -gt 0 ]; then
62-
warn "$PARTITION is not mounted with $OPTION at runtime"
50+
if [ $OS_RELEASE -eq 1 ]; then
51+
UNITSERVICEPATH=$DEBIAN_SERVICEPATH
52+
elif [ $OS_RELEASE -eq 2 ]; then
53+
UNITSERVICEPATH=$REDHAT_SERVICEPATH
54+
fi
55+
if [ -e $UNITSERVICEPATH ]; then
56+
has_mount_option_systemd $UNITSERVICEPATH $OPTION
57+
if [ $FNRET -gt 0 ]; then
58+
crit "$PARTITION has no option $OPTION in systemd service!"
59+
FNRET=3
60+
else
61+
ok "$PARTITION has $OPTION in systemd service"
62+
has_mounted_option $PARTITION $OPTION
63+
if [ $FNRET -gt 0 ]; then
64+
warn "$PARTITION is not mounted with $OPTION at runtime"
6365
FNRET=5
6466
else
6567
ok "$PARTITION mounted with $OPTION"
6668
FNRET=0
6769
fi
6870
fi
69-
else
70-
if [ $OS_RELEASE -eq 2 ]; then
71-
crit "$REDHAT_SERVICEPATH is not exist!"
72-
else
73-
crit "$SERVICEPATH is not exist!"
74-
fi
75-
FNRET=2
76-
fi
77-
fi
71+
else
72+
crit "$UNITSERVICEPATH is not exist! Please apply 2.1 first!"
73+
FNRET=2
74+
fi
75+
fi
7876
}
7977

8078
# This function will be called if the script status is on enabled mode
8179
apply () {
80+
if [ $OS_RELEASE -eq 1 ]; then
81+
UNITSERVICEPATH=$DEBIAN_SERVICEPATH
82+
elif [ $OS_RELEASE -eq 2 ]; then
83+
UNITSERVICEPATH=$REDHAT_SERVICEPATH
84+
fi
8285
if [ $FNRET = 0 ]; then
8386
ok "$PARTITION is correctly set"
8487
elif [ $FNRET = 2 ]; then
85-
crit "$PARTITION is not a partition, correct this by yourself, I cannot help you here"
88+
crit "System unit $UNITSERVICEPATH is not exist! Please apply 2.1 first!"
8689
elif [ $FNRET = 1 ]; then
8790
info "Adding $OPTION to fstab"
8891
add_option_to_fstab $PARTITION $OPTION
@@ -95,11 +98,7 @@ apply () {
9598
fi
9699
elif [ $FNRET = 3 ]; then
97100
info "Adding $OPTION to systemd"
98-
if [ $OS_RELEASE -eq 2 ]; then
99-
add_option_to_systemd $REDHAT_SERVICEPATH $OPTION $SERVICENAME
100-
else
101-
add_option_to_systemd $SERVICEPATH $OPTION $SERVICENAME
102-
fi
101+
add_option_to_systemd $UNITSERVICEPATH $OPTION $SERVICENAME
103102
remount_partition_by_systemd $SERVICENAME $PARTITION
104103
elif [ $FNRET = 4 ]; then
105104
info "Remounting $PARTITION from fstab"

0 commit comments

Comments
 (0)