Skip to content

Commit 7812833

Browse files
author
Samson.W
authored
Merge pull request #9 from hardenedlinux/master
Update from the master
2 parents 08e2cf2 + 6fab8a8 commit 7812833

File tree

153 files changed

+3251
-1406
lines changed

Some content is hidden

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

153 files changed

+3251
-1406
lines changed

README-CN.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ hardening [INFO] Treating /home/test/harbian-audit/bin/hardening
3131
$ git clone https://github.com/hardenedlinux/harbian-audit.git && cd harbian-audit
3232
$ sudo cp debian/default /etc/default/cis-hardening
3333
$ sudo sed -i "s#CIS_ROOT_DIR=.*#CIS_ROOT_DIR='$(pwd)'#" /etc/default/cis-hardening
34+
$ sudo bin/hardening.sh --init
3435
```
3536
### 对所有的安全检查项进行审计
3637
```
@@ -74,7 +75,11 @@ hardening [INFO] Treating /home/test/harbian-audit/bin/hardening
7475
### 需要预装的软件
7576
如果是使用的最小安装方式安装的Debian GNU/Linux系统,在使用此项目之前,需要安装如下的软件:
7677
```
77-
sudo apt-get install -y bc net-tools
78+
sudo apt-get install -y bc net-tools pciutils
79+
```
80+
如果系统是Redhat/CentOS,在使用此项目前,需要安装如下的软件包:
81+
```
82+
sudo yum install -y bc net-tools pciutils NetworkManager
7883
```
7984

8085
### 需要预先进行的配置

README.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ hardening [INFO] Treating /home/test/harbian-audit/bin/hardening
3434
$ git clone https://github.com/hardenedlinux/harbian-audit.git && cd harbian-audit
3535
$ sudo cp debian/default /etc/default/cis-hardening
3636
$ sudo sed -i "s#CIS_ROOT_DIR=.*#CIS_ROOT_DIR='$(pwd)'#" /etc/default/cis-hardening
37+
$ sudo bin/hardening.sh --init
3738
$ sudo bin/hardening.sh --audit-all
3839
hardening [INFO] Treating /home/test/harbian-audit/bin/hardening/1.1_install_updates.sh
3940
1.1_install_updates [INFO] Working on 1.1_install_updates
@@ -70,9 +71,14 @@ hardening [INFO] Treating /home/test/harbian-audit/bin/hardening
7071

7172
### Pre-Install
7273

73-
If use Network install from a minimal CD to installed Debian GNU/Linux, need install bc package before use the hardening tool.
74+
If use Network install from a minimal CD to installed Debian GNU/Linux, need install packages before use the hardening tool.
7475
```
75-
sudo apt-get install -y bc net-tools
76+
sudo apt-get install -y bc net-tools pciutils network-manager
77+
```
78+
79+
Redhat/CentOS need install packages before use the hardening tool:
80+
```
81+
sudo yum install -y bc net-tools pciutils NetworkManager
7682
```
7783

7884
### Pre-Set
@@ -155,8 +161,10 @@ This example only allows 192.168.1.[1-255] 192.168.5.[1-255] to access this syst
155161
# sed -i "/^root/a\test ALL=(ALL:ALL) ALL" /etc/sudoers
156162
```
157163

158-
4) Set basic iptables rules
164+
4) Set basic firewall rules
159165
Set the corresponding firewall rules according to the applications used. HardenedLinux community for Debian GNU/Linux basic firewall rules:
166+
167+
### Iptabels format rules:
160168
[etc.iptables.rules.v4.sh](https://github.com/hardenedlinux/harbian-audit/blob/master/docs/configurations/etc.iptables.rules.v4.sh)
161169
to do the following:
162170
```
@@ -168,6 +176,14 @@ $ sudo -s
168176
# ip6tables-save > /etc/iptables/rules.v6
169177
```
170178

179+
### nft format rules:
180+
[nftables.conf](https://github.com/hardenedlinux/harbian-audit/blob/master/docs/configurations/etc.nftables.conf)
181+
to do the following(your network interfacename(Example eth0)):
182+
```
183+
$ sed -i 's/^define int_if = ens33/define int_if = eth0/g' etc.nftables.conf
184+
$ sudo nft -f ./etc.nftables.conf
185+
```
186+
171187
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.
172188

173189
## Special Note
@@ -217,7 +233,9 @@ This document is a description of the additions to the sections not included in
217233
### Manual Operation docs
218234
[How to config grub2 password protection](https://github.com/hardenedlinux/harbian-audit/blob/master/docs/configurations/manual-operation-docs/how_to_config_grub2_password_protection.mkd)
219235
[How to persistent iptables rules with debian 9](https://github.com/hardenedlinux/harbian-audit/blob/master/docs/configurations/manual-operation-docs/how_to_persistent_iptables_rules_with_debian_9.mkd)
220-
[How to deploy audisp-remote for auditd log](https://github.com/hardenedlinux/harbian-audit/blob/master/docs/configurations/manual-operation-docs/how_to_deploy_audisp_remote_for_audit_log.mkd)
236+
[How to deploy audisp-remote for auditd log](https://github.com/hardenedlinux/harbian-audit/blob/master/docs/configurations/manual-operation-docs/how_to_deploy_audisp_remote_for_audit_log.mkd)
237+
[How to migrating from iptables to nftables in debian10](https://github.com/hardenedlinux/harbian-audit/blob/master/docs/configurations/manual-operation-docs/how_to_migrating_from_iptables_to_nftables_in_debian10.md)
238+
[How to persistent nft rules with debian 10](https://github.com/hardenedlinux/harbian-audit/blob/master/docs/configurations/manual-operation-docs/how_to_persistent_nft_rules_with_debian_10.mkd)
221239

222240
### Use case docs
223241
[Nodejs + redis + mysql demo](https://github.com/hardenedlinux/harbian-audit/blob/master/docs/use-cases/nodejs-redis-mysql-usecase/README.md)

bin/hardening.sh

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
#
4-
# harbian audit Debian 9 Hardening
4+
# harbian audit Debian 9 / CentOS Hardening
55
# Authors : Thibault Dewailly, OVH <thibault.dewailly@corp.ovh.com>
66
# Authors : Samson wen, Samson <sccxboy@gmail.com>
77

@@ -23,15 +23,20 @@ AUDIT_ALL_ENABLE_PASSED=0
2323
ALLOW_SERVICE_LIST=0
2424
SET_HARDENING_LEVEL=0
2525
SUDO_MODE=''
26+
INIT_G_CONFIG=0
2627

2728
usage() {
2829
cat << EOF
2930
$LONG_SCRIPT_NAME <RUN_MODE> [OPTIONS], where RUN_MODE is one of:
3031
3132
--help -h
3233
Show this help
33-
34-
--apply
34+
35+
--init
36+
Initialize the global configuration file(/etc/default/cis-hardening) based
37+
on the release version number.
38+
39+
--apply
3540
Apply hardening for enabled scripts.
3641
Beware that NO confirmation is asked whatsoever, which is why you're warmly
3742
advised to use --audit before, which can be regarded as a dry-run mode.
@@ -140,6 +145,9 @@ while [[ $# > 0 ]]; do
140145
-h|--help)
141146
usage
142147
;;
148+
--init)
149+
INIT_G_CONFIG=1
150+
;;
143151
*)
144152
usage
145153
;;
@@ -162,6 +170,30 @@ fi
162170
[ -r $CIS_ROOT_DIR/lib/common.sh ] && . $CIS_ROOT_DIR/lib/common.sh
163171
[ -r $CIS_ROOT_DIR/lib/utils.sh ] && . $CIS_ROOT_DIR/lib/utils.sh
164172

173+
if [ $INIT_G_CONFIG -eq 1 ]; then
174+
if [ -r /etc/redhat-release ]; then
175+
info "This OS is redhat/CentOS."
176+
sed -i 's/^OS_RELEASE=.*/OS_RELEASE=2/g' /etc/default/cis-hardening
177+
. /etc/default/cis-hardening
178+
elif [ -r /etc/debian_version ]; then
179+
info "This OS is Debian."
180+
:
181+
else
182+
crit "This OS not support!"
183+
exit 128
184+
fi
185+
exit 0
186+
fi
187+
188+
if [ $OS_RELEASE -eq 1 ]; then
189+
info "Start auditing for Debian."
190+
elif [ $OS_RELEASE -eq 2 ]; then
191+
info "Start auditing for redhat/CentOS."
192+
else
193+
crit "This OS not support!"
194+
exit 128
195+
fi
196+
165197
# If --allow-service-list is specified, don't run anything, just list the supported services
166198
if [ "$ALLOW_SERVICE_LIST" = 1 ] ; then
167199
declare -a HARDENING_EXCEPTIONS_LIST

bin/hardening/1.1_install_updates.sh

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
#!/bin/bash
22

33
#
4-
# harbian audit Debian 9 Hardening
4+
# harbian audit Debian 9/CentOS Hardening
5+
# Modify by: Samson-W (samson@hardenedlinux.org)
56
#
67

78
#
@@ -13,8 +14,9 @@ set -u # One variable unset, it's over
1314

1415
HARDENING_LEVEL=3
1516

16-
# This function will be called if the script status is on enabled / audit mode
17-
audit () {
17+
18+
audit_debian ()
19+
{
1820
info "Checking if apt needs an update"
1921
apt_update_if_needed
2022
info "Fetching upgrades ..."
@@ -28,16 +30,67 @@ audit () {
2830
fi
2931
}
3032

31-
# This function will be called if the script status is on enabled mode
32-
apply () {
33-
if [ $FNRET -gt 0 ]; then
33+
audit_redhat ()
34+
{
35+
info "Checking if yum needs an update"
36+
info "Fetching upgrades ..."
37+
yum_check_updates
38+
if [ $FNRET -eq 100 ]; then
39+
crit "There are packages available for an update!"
40+
elif [ $FNRET -eq 0 ]; then
41+
ok "No upgrades available"
42+
else
43+
crit "Call yum_check_updates function error!"
44+
fi
45+
}
46+
47+
# This function will be called if the script status is on enabled / audit mode
48+
audit ()
49+
{
50+
if [ $OS_RELEASE -eq 1 ]; then
51+
audit_debian
52+
elif [ $OS_RELEASE -eq 2 ]; then
53+
audit_redhat
54+
else
55+
crit "Current OS is not support!"
56+
FNRET=44
57+
fi
58+
}
59+
60+
apply_debian ()
61+
{
62+
if [ $FNRET -eq 1 ]; then
3463
info "Applying Upgrades..."
3564
DEBIAN_FRONTEND='noninteractive' apt-get -o Dpkg::Options::='--force-confdef' -o Dpkg::Options::='--force-confold' upgrade -y
36-
else
37-
ok "No Upgrades to apply"
65+
else
66+
ok "No Upgrades to apply"
67+
fi
68+
}
69+
70+
apply_redhat ()
71+
{
72+
if [ $FNRET -eq 100 ]; then
73+
info "Applying Upgrades..."
74+
yum upgrade -y
75+
elif [ $FNRET -eq 0 ]; then
76+
ok "No Upgrades to apply"
77+
else
78+
crit "Call yum_check_updates function error!"
3879
fi
3980
}
4081

82+
# This function will be called if the script status is on enabled mode
83+
apply ()
84+
{
85+
if [ $OS_RELEASE -eq 1 ]; then
86+
apply_debian
87+
elif [ $OS_RELEASE -eq 2 ]; then
88+
apply_redhat
89+
else
90+
crit "Current OS is not support!"
91+
fi
92+
}
93+
4194
# This function will check config parameters required
4295
check_config() {
4396
# No parameters for this function

bin/hardening/1.2_enable_verify_sign_packages_from_repository.sh

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22

33
#
4-
# harbian audit Debian 9 Hardening
4+
# harbian audit Debian 9/CentOS Hardening
55
#
66

77
#
@@ -14,9 +14,11 @@ set -u # One variable unset, it's over
1414

1515
HARDENING_LEVEL=2
1616
OPTION='AllowUnauthenticated'
17+
YUM_OPTION='gpgcheck'
18+
YUM_CONF='/etc/yum.conf'
1719

18-
# This function will be called if the script status is on enabled / audit mode
19-
audit () {
20+
audit_debian ()
21+
{
2022
if [ $(grep -v "^#" /etc/apt/ -r | grep -c "${OPTION}.*true") -gt 0 ]; then
2123
crit "The signature of packages option is disable "
2224
FNRET=1
@@ -26,8 +28,37 @@ audit () {
2628
fi
2729
}
2830

29-
# This function will be called if the script status is on enabled mode
30-
apply () {
31+
audit_redhat ()
32+
{
33+
if [ $(grep -c "^$YUM_OPTION" $YUM_CONF) -gt 0 ]; then
34+
if [ $(grep "^$YUM_OPTION" $YUM_CONF | awk -F"=" '{print $2}') -eq 1 ]; then
35+
ok "The signature of packages option is enable "
36+
FNRET=0
37+
else
38+
crit "The signature of packages option is disable "
39+
FNRET=1
40+
fi
41+
else
42+
crit "Option $YUM_OPTION is not set in $YUM_CONF!"
43+
FNRET=2
44+
fi
45+
}
46+
47+
# This function will be called if the script status is on enabled / audit mode
48+
audit ()
49+
{
50+
if [ $OS_RELEASE -eq 1 ]; then
51+
audit_debian
52+
elif [ $OS_RELEASE -eq 2 ]; then
53+
audit_redhat
54+
else
55+
crit "Current OS is not support!"
56+
FNRET=44
57+
fi
58+
}
59+
60+
61+
apply_debian () {
3162
if [ $FNRET = 0 ]; then
3263
ok "The signature of packages option is enable "
3364
else
@@ -39,6 +70,28 @@ apply () {
3970
done
4071
fi
4172
}
73+
apply_redhat () {
74+
if [ $FNRET = 0 ]; then
75+
ok "The signature of packages option is enable "
76+
elif [ $FNRET = 1 ]; then
77+
warn "Set to enabled signature of packages option"
78+
sed -i "s/$YUM_OPTION=.*/$YUM_OPTION=1/g" $YUM_CONF
79+
else
80+
warn "Add $YUM_OPTION option to $YUM_CONF"
81+
add_end_of_file $YUM_CONF "$YUM_OPTION=1"
82+
fi
83+
}
84+
85+
# This function will be called if the script status is on enabled mode
86+
apply () {
87+
if [ $OS_RELEASE -eq 1 ]; then
88+
apply_debian
89+
elif [ $OS_RELEASE -eq 2 ]; then
90+
apply_redhat
91+
else
92+
crit "Current OS is not support!"
93+
fi
94+
}
4295

4396
# This function will check config parameters required
4497
check_config() {

0 commit comments

Comments
 (0)