3958 lines
357 KiB
Bash
3958 lines
357 KiB
Bash
#!/bin/bash
|
|
############################################################################
|
|
# Lấy thông tin thiết bị
|
|
echo "Operating System: $(cat /etc/os-release | grep PRETTY_NAME | cut -d= -f2 | tr -d '"')"
|
|
echo "Hostname: $(hostname -I)"
|
|
echo "Time: $(date +"%Y-%m-%d %H:%M:%S")"
|
|
echo "############################################################################"
|
|
|
|
##################################################################################################################
|
|
# Tự động kiểm tra IPv6 có được sử dụng hay không
|
|
IPV6_ENABLED=0
|
|
|
|
# Kiểm tra IPv6 có được enable trong kernel không
|
|
if [ -f /proc/net/if_inet6 ] && [ -s /proc/net/if_inet6 ]; then
|
|
# Kiểm tra có interface nào có IPv6 address (ngoài loopback ::1)
|
|
if ip -6 addr show 2>/dev/null | grep -q "inet6" && \
|
|
ip -6 addr show 2>/dev/null | grep "inet6" | grep -vq "::1/128"; then
|
|
IPV6_ENABLED=1
|
|
echo "IPv6 Status: ENABLED"
|
|
else
|
|
echo "IPv6 Status: DISABLED (no IPv6 addresses assigned)"
|
|
fi
|
|
else
|
|
echo "IPv6 Status: DISABLED (kernel support not available)"
|
|
fi
|
|
echo "############################################################################"
|
|
|
|
##################################################################################################################
|
|
# Chỉnh sửa hoặc tạo một file trong thư mục /etc/modprobe.d/filesystem.conf và thêm vào những dòng sau:
|
|
# install cramfs /bin/true
|
|
# Thực hiện câu lệnh sau để gỡ bỏ các filesystem không thông dụng khỏi kernel:
|
|
# rmmod cramfs
|
|
if [[ $(lsmod | grep cramfs | wc -l) -ne 0 || ($(modprobe -n -v cramfs | grep -P "^\h*install /bin/true" 2>/dev/null | wc -l) -eq 0 && ($(modprobe -n -v cramfs 2>/dev/null | grep -P "^\h*install /bin/false" | wc -l) -eq 0 || $(grep -P "^\h*blacklist\s+cramfs" /etc/modprobe.d/*.conf 2>/dev/null | wc -l) -eq 0)) ]]; then
|
|
echo "{\"1.1.1.1. Cấu hình vô hiệu hoá cramfs filesystem\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Chỉnh sửa hoặc tạo một file trong thư mục /etc/modprobe.d/filesystem.conf và thêm vào những dòng sau:
|
|
# install cramfs /bin/true
|
|
# Thực hiện câu lệnh sau để gỡ bỏ các filesystem không thông dụng khỏi kernel:
|
|
# rmmod cramfs"
|
|
if [ $(lsmod | grep cramfs | wc -l) -ne 0 ]; then echo "-------------------"; echo "#lsmod | grep cramfs -eq 0 ";lsmod | grep cramfs; fi
|
|
if [ $(modprobe -n -v cramfs 2>/dev/null | grep -P "^\h*install /bin/true" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#modprobe -n -v cramfs 2>/dev/null | grep -P \"^\\h*install /bin/true\" -ne 0 ";modprobe -n -v cramfs 2>/dev/null | grep -P "^\h*install /bin/true"; fi
|
|
if [ $(modprobe -n -v cramfs 2>/dev/null | grep -P "^\h*install /bin/false" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#modprobe -n -v cramfs 2>/dev/null | grep -P \"^\\h*install /bin/false\" -ne 0 ";modprobe -n -v cramfs 2>/dev/null | grep -P "^\h*install /bin/false"; fi
|
|
if [ $(grep -P "^\h*blacklist\s+cramfs" /etc/modprobe.d/*.conf 2>/dev/null | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -P \"^\\h*blacklist\s+cramfs\" /etc/modprobe.d/*.conf 2>/dev/null -ne 0 ";grep -P "^\h*blacklist\s+cramfs" /etc/modprobe.d/*.conf 2>/dev/null; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"1.1.1.1. Cấu hình vô hiệu hoá cramfs filesystem\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Chỉnh sửa hoặc tạo một file trong thư mục /etc/modprobe.d/filesystem.conf và thêm vào những dòng sau:
|
|
# install freevxfs /bin/true
|
|
# Thực hiện câu lệnh sau để gỡ bỏ các filesystem không thông dụng khỏi kernel:
|
|
# rmmod freevxfs
|
|
if [[ $(lsmod | grep freevxfs | wc -l) -ne 0 || ($(modprobe -n -v freevxfs 2>/dev/null | grep -P "^\h*install /bin/true" | wc -l) -eq 0 && ($(modprobe -n -v freevxfs 2>/dev/null | grep -P "^\h*install /bin/false" | wc -l) -eq 0 || $(grep -P "^\h*blacklist\s+freevxfs" /etc/modprobe.d/* 2>/dev/null | wc -l) -eq 0)) ]]; then
|
|
echo "{\"1.1.1.2. Cấu hình vô hiệu hoá freevxfs filesystem\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Chỉnh sửa hoặc tạo một file trong thư mục /etc/modprobe.d/filesystem.conf và thêm vào những dòng sau:
|
|
# install freevxfs /bin/true
|
|
# Thực hiện câu lệnh sau để gỡ bỏ các filesystem không thông dụng khỏi kernel:
|
|
# rmmod freevxfs"
|
|
if [ $(lsmod | grep freevxfs | wc -l) -ne 0 ]; then echo "-------------------"; echo "#lsmod | grep freevxfs -eq 0 ";lsmod | grep freevxfs; fi
|
|
if [ $(modprobe -n -v freevxfs 2>/dev/null | grep -P "^\h*install /bin/true" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#modprobe -n -v freevxfs 2>/dev/null | grep -P \"^\\h*install /bin/true\" -ne 0 ";modprobe -n -v freevxfs 2>/dev/null | grep -P "^\h*install /bin/true"; fi
|
|
if [ $(modprobe -n -v freevxfs 2>/dev/null | grep -P "^\h*install /bin/false" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#modprobe -n -v freevxfs 2>/dev/null | grep -P \"^\\h*install /bin/false\" -ne 0 ";modprobe -n -v freevxfs 2>/dev/null | grep -P "^\h*install /bin/false"; fi
|
|
if [ $(grep -P "^\h*blacklist\s+freevxfs" /etc/modprobe.d/*.conf 2>/dev/null | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -P \"^\\h*blacklist\s+freevxfs\" /etc/modprobe.d/*.conf 2>/dev/null -ne 0 ";grep -P "^\h*blacklist\s+freevxfs" /etc/modprobe.d/*.conf 2>/dev/null; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"1.1.1.2. Cấu hình vô hiệu hoá freevxfs filesystem\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Chỉnh sửa hoặc tạo một file trong thư mục /etc/modprobe.d/filesystem.conf và thêm vào những dòng sau:
|
|
# install hfs /bin/true
|
|
# Thực hiện câu lệnh sau để gỡ bỏ các filesystem không thông dụng khỏi kernel:
|
|
# rmmod hfs
|
|
if [[ $(lsmod | grep hfs | wc -l) -ne 0 || ($(modprobe -n -v hfs 2>/dev/null | grep -P "^\h*install /bin/true" | wc -l) -eq 0 && ($(modprobe -n -v hfs 2>/dev/null | grep -P "^\h*install /bin/false" | wc -l) -eq 0 || $(grep -P "^\h*blacklist\s+hfs" /etc/modprobe.d/* 2>/dev/null | wc -l) -eq 0)) ]]; then
|
|
echo "{\"1.1.1.3. Cấu hình vô hiệu hoá hfs filesystem\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Chỉnh sửa hoặc tạo một file trong thư mục /etc/modprobe.d/filesystem.conf và thêm vào những dòng sau:
|
|
# install hfs /bin/true
|
|
# Thực hiện câu lệnh sau để gỡ bỏ các filesystem không thông dụng khỏi kernel:
|
|
# rmmod hfs"
|
|
if [ $(lsmod | grep hfs | wc -l) -ne 0 ]; then echo "-------------------"; echo "#lsmod | grep hfs -eq 0 ";lsmod | grep hfs; fi
|
|
if [ $(modprobe -n -v hfs 2>/dev/null | grep -P "^\h*install /bin/true" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#modprobe -n -v hfs 2>/dev/null | grep -P \"^\\h*install /bin/true\" -ne 0 ";modprobe -n -v hfs 2>/dev/null | grep -P "^\h*install /bin/true"; fi
|
|
if [ $(modprobe -n -v hfs 2>/dev/null | grep -P "^\h*install /bin/false" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#modprobe -n -v hfs 2>/dev/null | grep -P \"^\\h*install /bin/false\" -ne 0 ";modprobe -n -v hfs 2>/dev/null | grep -P "^\h*install /bin/false"; fi
|
|
if [ $(grep -P "^\h*blacklist\s+hfs" /etc/modprobe.d/*.conf 2>/dev/null | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -P \"^\\h*blacklist\s+hfs\" /etc/modprobe.d/*.conf 2>/dev/null -ne 0 ";grep -P "^\h*blacklist\s+hfs" /etc/modprobe.d/*.conf 2>/dev/null; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"1.1.1.3. Cấu hình vô hiệu hoá hfs filesystem\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Chỉnh sửa hoặc tạo một file trong thư mục /etc/modprobe.d/filesystem.conf và thêm vào những dòng sau:
|
|
# install hfsplus /bin/true
|
|
# Thực hiện câu lệnh sau để gỡ bỏ các filesystem không thông dụng khỏi kernel:
|
|
# rmmod hfsplus
|
|
if [[ $(lsmod | grep hfsplus | wc -l) -ne 0 || ($(modprobe -n -v hfsplus 2>/dev/null | grep -P "^\h*install /bin/true" | wc -l) -eq 0 && ($(modprobe -n -v hfsplus 2>/dev/null | grep -P "^\h*install /bin/false" | wc -l) -eq 0 || $(grep -P "^\h*blacklist\s+hfsplus" /etc/modprobe.d/* 2>/dev/null | wc -l) -eq 0)) ]]; then
|
|
echo "{\"1.1.1.4. Cấu hình vô hiệu hoá hfsplus filesystem\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Chỉnh sửa hoặc tạo một file trong thư mục /etc/modprobe.d/filesystem.conf và thêm vào những dòng sau:
|
|
# install hfsplus /bin/true
|
|
# Thực hiện câu lệnh sau để gỡ bỏ các filesystem không thông dụng khỏi kernel:
|
|
# rmmod hfsplus"
|
|
if [ $(lsmod | grep hfsplus | wc -l) -ne 0 ]; then echo "-------------------"; echo "#lsmod | grep hfsplus -eq 0 ";lsmod | grep hfsplus; fi
|
|
if [ $(modprobe -n -v hfsplus 2>/dev/null | grep -P "^\h*install /bin/true" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#modprobe -n -v hfsplus 2>/dev/null | grep -P \"^\\h*install /bin/true\" -ne 0 ";modprobe -n -v hfsplus 2>/dev/null | grep -P "^\h*install /bin/true"; fi
|
|
if [ $(modprobe -n -v hfsplus 2>/dev/null | grep -P "^\h*install /bin/false" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#modprobe -n -v hfsplus 2>/dev/null | grep -P \"^\\h*install /bin/false\" -ne 0 ";modprobe -n -v hfsplus 2>/dev/null | grep -P "^\h*install /bin/false"; fi
|
|
if [ $(grep -P "^\h*blacklist\s+hfsplus" /etc/modprobe.d/*.conf 2>/dev/null | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -P \"^\\h*blacklist\s+hfsplus\" /etc/modprobe.d/*.conf 2>/dev/null -ne 0 ";grep -P "^\h*blacklist\s+hfsplus" /etc/modprobe.d/*.conf 2>/dev/null; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"1.1.1.4. Cấu hình vô hiệu hoá hfsplus filesystem\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Chỉnh sửa hoặc tạo một file trong thư mục /etc/modprobe.d/filesystem.conf và thêm vào những dòng sau:
|
|
# install jffs2 /bin/true
|
|
# Thực hiện câu lệnh sau để gỡ bỏ các filesystem không thông dụng khỏi kernel:
|
|
# rmmod jffs2
|
|
if [[ $(lsmod | grep jffs2 | wc -l) -ne 0 || ($(modprobe -n -v jffs2 2>/dev/null | grep -P "^\h*install /bin/true" | wc -l) -eq 0 && ($(modprobe -n -v jffs2 2>/dev/null | grep -P "^\h*install /bin/false" | wc -l) -eq 0 || $(grep -P "^\h*blacklist\s+jffs2" /etc/modprobe.d/* 2>/dev/null | wc -l) -eq 0)) ]]; then
|
|
echo "{\"1.1.1.5. Cấu hình vô hiệu hoá jffs2 filesystem\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Chỉnh sửa hoặc tạo một file trong thư mục /etc/modprobe.d/filesystem.conf và thêm vào những dòng sau:
|
|
# install jffs2 /bin/true
|
|
# Thực hiện câu lệnh sau để gỡ bỏ các filesystem không thông dụng khỏi kernel:
|
|
# rmmod jffs2"
|
|
if [ $(lsmod | grep jffs2 | wc -l) -ne 0 ]; then echo "-------------------"; echo "#lsmod | grep jffs2 -eq 0 ";lsmod | grep jffs2; fi
|
|
if [ $(modprobe -n -v jffs2 2>/dev/null | grep -P "^\h*install /bin/true" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#modprobe -n -v jffs2 2>/dev/null | grep -P \"^\\h*install /bin/true\" -ne 0 ";modprobe -n -v jffs2 2>/dev/null | grep -P "^\h*install /bin/true"; fi
|
|
if [ $(modprobe -n -v jffs2 2>/dev/null | grep -P "^\h*install /bin/false" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#modprobe -n -v jffs2 2>/dev/null | grep -P \"^\\h*install /bin/false\" -ne 0 ";modprobe -n -v jffs2 2>/dev/null | grep -P "^\h*install /bin/false"; fi
|
|
if [ $(grep -P "^\h*blacklist\s+jffs2" /etc/modprobe.d/*.conf 2>/dev/null | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -P \"^\\h*blacklist\s+jffs2\" /etc/modprobe.d/*.conf 2>/dev/null -ne 0 ";grep -P "^\h*blacklist\s+jffs2" /etc/modprobe.d/*.conf 2>/dev/null; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"1.1.1.5. Cấu hình vô hiệu hoá jffs2 filesystem\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Chỉnh sửa hoặc tạo một file trong thư mục /etc/modprobe.d/filesystem.conf và thêm vào những dòng sau:
|
|
# install squashfs /bin/true
|
|
# Thực hiện câu lệnh sau để gỡ bỏ các filesystem không thông dụng khỏi kernel:
|
|
# rmmod squashfs
|
|
if [[ $(lsmod | grep squashfs | wc -l) -ne 0 || ($(modprobe -n -v squashfs 2>/dev/null | grep -P "^\h*install /bin/true" | wc -l) -eq 0 && ($(modprobe -n -v squashfs 2>/dev/null | grep -P "^\h*install /bin/false" | wc -l) -eq 0 || $(grep -P "^\h*blacklist\s+squashfs" /etc/modprobe.d/* 2>/dev/null | wc -l) -eq 0)) ]]; then
|
|
echo "{\"1.1.1.6. Cấu hình vô hiệu hoá squashfs filesystem\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Chỉnh sửa hoặc tạo một file trong thư mục /etc/modprobe.d/filesystem.conf và thêm vào những dòng sau:
|
|
# install squashfs /bin/true
|
|
# Thực hiện câu lệnh sau để gỡ bỏ các filesystem không thông dụng khỏi kernel:
|
|
# rmmod squashfs"
|
|
if [ $(lsmod | grep squashfs | wc -l) -ne 0 ]; then echo "-------------------"; echo "#lsmod | grep squashfs -eq 0 ";lsmod | grep squashfs; fi
|
|
if [ $(modprobe -n -v squashfs 2>/dev/null | grep -P "^\h*install /bin/true" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#modprobe -n -v squashfs 2>/dev/null | grep -P \"^\\h*install /bin/true\" -ne 0 ";modprobe -n -v squashfs 2>/dev/null | grep -P "^\h*install /bin/true"; fi
|
|
if [ $(modprobe -n -v squashfs 2>/dev/null | grep -P "^\h*install /bin/false" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#modprobe -n -v squashfs 2>/dev/null | grep -P \"^\\h*install /bin/false\" -ne 0 ";modprobe -n -v squashfs 2>/dev/null | grep -P "^\h*install /bin/false"; fi
|
|
if [ $(grep -P "^\h*blacklist\s+squashfs" /etc/modprobe.d/*.conf 2>/dev/null | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -P \"^\\h*blacklist\s+squashfs\" /etc/modprobe.d/*.conf 2>/dev/null -ne 0 ";grep -P "^\h*blacklist\s+squashfs" /etc/modprobe.d/*.conf 2>/dev/null; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"1.1.1.6. Cấu hình vô hiệu hoá squashfs filesystem\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Chỉnh sửa hoặc tạo một file trong thư mục /etc/modprobe.d/filesystem.conf và thêm vào những dòng sau:
|
|
# install udf /bin/true
|
|
# Thực hiện câu lệnh sau để gỡ bỏ các filesystem không thông dụng khỏi kernel:
|
|
# rmmod udf
|
|
if [[ $(lsmod | grep udf | wc -l) -ne 0 || ($(modprobe -n -v udf 2>/dev/null | grep -P "^\h*install /bin/true" | wc -l) -eq 0 && ($(modprobe -n -v udf 2>/dev/null | grep -P "^\h*install /bin/false" | wc -l) -eq 0 || $(grep -P "^\h*blacklist\s+udf" /etc/modprobe.d/*.conf 2>/dev/null | wc -l) -eq 0)) ]]; then
|
|
echo "{\"1.1.1.7. Cấu hình vô hiệu hoá udf filesystem\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Chỉnh sửa hoặc tạo một file trong thư mục /etc/modprobe.d/filesystem.conf và thêm vào những dòng sau:
|
|
# install udf /bin/true
|
|
# Thực hiện câu lệnh sau để gỡ bỏ các filesystem không thông dụng khỏi kernel:
|
|
# rmmod udf"
|
|
if [ $(lsmod | grep udf | wc -l) -ne 0 ]; then echo "-------------------"; echo "#lsmod | grep udf -eq 0 ";lsmod | grep udf; fi
|
|
if [ $(modprobe -n -v udf 2>/dev/null | grep -P "^\h*install /bin/true" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#modprobe -n -v udf 2>/dev/null | grep -P \"^\\h*install /bin/true\" -ne 0 ";modprobe -n -v udf 2>/dev/null | grep -P "^\h*install /bin/true"; fi
|
|
if [ $(modprobe -n -v udf 2>/dev/null | grep -P "^\h*install /bin/false" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#modprobe -n -v udf 2>/dev/null | grep -P \"^\\h*install /bin/false\" -ne 0 ";modprobe -n -v udf 2>/dev/null | grep -P "^\h*install /bin/false"; fi
|
|
if [ $(grep -P "^\h*blacklist\s+udf" /etc/modprobe.d/*.conf 2>/dev/null | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -P \"^\\h*blacklist\s+udf\" /etc/modprobe.d/*.conf -ne 0 ";grep -P "^\h*blacklist\s+udf" /etc/modprobe.d/*.conf 2>/dev/null; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"1.1.1.7. Cấu hình vô hiệu hoá udf filesystem\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Chỉnh sửa file /etc/fstab và thêm tùy chọn nodev, nosuid, noexec vào trường thứ 4 trong cấu hình của phân vùng /tmp. Ví dụ:
|
|
# tmpfs /tmp tmpfs defaults,nodev,nosuid,noexec 0 0
|
|
# Thực hiện các lệnh sau để mount phân vùng /tmp và cập nhật cấu hình fstab:
|
|
# mount /tmp
|
|
# mount -o remount /tmp
|
|
if ! findmnt --kernel /tmp >/dev/null 2>&1; then
|
|
echo "{\"1.1.2.1. Cấu hình tuỳ chọn nodev cho phân vùng /tmp\" : \"PASSED\"}"
|
|
elif [ $(findmnt --kernel /tmp | grep nodev | wc -l) -eq 0 ] || [ $(grep -E "\s+/tmp\s+.*nodev" /etc/fstab | wc -l) -eq 0 ]; then
|
|
echo "{\"1.1.2.1. Cấu hình tuỳ chọn nodev cho phân vùng /tmp\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
if [ $(findmnt --kernel /tmp | grep nodev | wc -l) -eq 0 ]; then echo "-------------------"; echo "#findmnt --kernel /tmp | grep nodev -ne 0 ";findmnt --kernel /tmp | grep nodev; fi
|
|
if [ $(grep -E "\s+/tmp\s+.*nodev" /etc/fstab | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -E \"\s+/tmp\s+.*nodev\" /etc/fstab -ne 0 ";grep -E "\s+/tmp\s+.*nodev" /etc/fstab; fi
|
|
echo "-------------------"
|
|
else
|
|
echo "{\"1.1.2.1. Cấu hình tuỳ chọn nodev cho phân vùng /tmp\" : \"PASSED\"}"
|
|
fi
|
|
|
|
if ! findmnt --kernel /tmp >/dev/null 2>&1; then
|
|
echo "{\"1.1.2.2. Cấu hình tuỳ chọn nosuid cho phân vùng /tmp\" : \"PASSED\"}"
|
|
elif [ $(findmnt --kernel /tmp | grep nosuid | wc -l) -eq 0 ] || [ $(grep -E "\s+/tmp\s+.*nosuid" /etc/fstab | wc -l) -eq 0 ]; then
|
|
echo "{\"1.1.2.2. Cấu hình tuỳ chọn nosuid cho phân vùng /tmp\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
if [ $(findmnt --kernel /tmp | grep nosuid | wc -l) -eq 0 ]; then echo "-------------------"; echo "#findmnt --kernel /tmp | grep nosuid -ne 0 ";findmnt --kernel /tmp | grep nosuid; fi
|
|
if [ $(grep -E "\s+/tmp\s+.*nosuid" /etc/fstab | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -E \"\s+/tmp\s+.*nosuid\" /etc/fstab -ne 0 ";grep -E "\s+/tmp\s+.*nosuid" /etc/fstab; fi
|
|
echo "-------------------"
|
|
else
|
|
echo "{\"1.1.2.2. Cấu hình tuỳ chọn nosuid cho phân vùng /tmp\" : \"PASSED\"}"
|
|
fi
|
|
|
|
if ! findmnt --kernel /tmp >/dev/null 2>&1; then
|
|
echo "{\"1.1.2.3. Cấu hình tuỳ chọn noexec cho phân vùng /tmp\" : \"PASSED\"}"
|
|
elif [ $(findmnt --kernel /tmp | grep noexec | wc -l) -eq 0 ] || [ $(grep -E "\s+/tmp\s+.*noexec" /etc/fstab | wc -l) -eq 0 ]; then
|
|
echo "{\"1.1.2.3. Cấu hình tuỳ chọn noexec cho phân vùng /tmp\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
if [ $(findmnt --kernel /tmp | grep noexec | wc -l) -eq 0 ]; then echo "-------------------"; echo "#findmnt --kernel /tmp | grep noexec -ne 0 ";findmnt --kernel /tmp | grep noexec; fi
|
|
if [ $(grep -E "\s+/tmp\s+.*noexec" /etc/fstab | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -E \"\s+/tmp\s+.*noexec\" /etc/fstab -ne 0 ";grep -E "\s+/tmp\s+.*noexec" /etc/fstab; fi
|
|
echo "-------------------"
|
|
else
|
|
echo "{\"1.1.2.3. Cấu hình tuỳ chọn noexec cho phân vùng /tmp\" : \"PASSED\"}"
|
|
fi
|
|
|
|
# Log
|
|
echo "-------------------"
|
|
echo "# Chỉnh sửa file /etc/fstab và thêm tùy chọn nodev, nosuid, noexec vào trường thứ 4 trong cấu hình của phân vùng /tmp. Ví dụ:
|
|
# tmpfs /tmp tmpfs defaults,nodev,nosuid,noexec 0 0
|
|
# Thực hiện các lệnh sau để mount phân vùng /tmp và cập nhật cấu hình fstab:
|
|
# mount /tmp
|
|
# mount -o remount /tmp"
|
|
echo "-------------------"
|
|
#[ $(findmnt --kernel /tmp | wc -l) -ne 0 ] && echo "Directory /tmp is mounted" || echo "Directory /tmp is not mounted"
|
|
echo "######################################"
|
|
|
|
############################################################################
|
|
# Chỉnh sửa file /etc/fstab và thêm tùy chọn nodev, nosuid, noexec vào trường thứ 4 trong cấu hình của phân vùng /var/tmp. Ví dụ:
|
|
# tmpfs /var/tmp tmpfs defaults,nodev,nosuid,noexec 0 0
|
|
# Thực hiện các lệnh sau để mount phân vùng /var/tmp và cập nhật cấu hình fstab:
|
|
# mount /var/tmp
|
|
# mount -o remount /var/tmp
|
|
if ! findmnt --kernel /var/tmp >/dev/null 2>&1; then
|
|
echo "{\"1.1.3.1. Cấu hình tuỳ chọn nodev cho phân vùng /var/tmp\" : \"PASSED\"}"
|
|
elif [ $(findmnt --kernel /var/tmp | grep nodev | wc -l) -eq 0 ] || [ $(grep -E "\s+/var/tmp\s+.*nodev" /etc/fstab | wc -l) -eq 0 ]; then
|
|
echo "{\"1.1.3.1. Cấu hình tuỳ chọn nodev cho phân vùng /var/tmp\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
if [ $(findmnt --kernel /var/tmp | grep nodev | wc -l) -eq 0 ]; then echo "-------------------"; echo "#findmnt --kernel /var/tmp | grep nodev -ne 0 ";findmnt --kernel /var/tmp | grep nodev; fi
|
|
if [ $(grep -E "\s+/var/tmp\s+.*nodev" /etc/fstab | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -E \"\s+/var/tmp\s+.*nodev\" /etc/fstab -ne 0 ";grep -E "\s+/var/tmp\s+.*nodev" /etc/fstab; fi
|
|
echo "-------------------"
|
|
else
|
|
echo "{\"1.1.3.1. Cấu hình tuỳ chọn nodev cho phân vùng /var/tmp\" : \"PASSED\"}"
|
|
fi
|
|
|
|
if ! findmnt --kernel /var/tmp >/dev/null 2>&1; then
|
|
echo "{\"1.1.3.2. Cấu hình tuỳ chọn nosuid cho phân vùng /var/tmp\" : \"PASSED\"}"
|
|
elif [ $(findmnt --kernel /var/tmp | grep nosuid | wc -l) -eq 0 ] || [ $(grep -E "\s+/var/tmp\s+.*nosuid" /etc/fstab | wc -l) -eq 0 ]; then
|
|
echo "{\"1.1.3.2. Cấu hình tuỳ chọn nosuid cho phân vùng /var/tmp\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
if [ $(findmnt --kernel /var/tmp | grep nosuid | wc -l) -eq 0 ]; then echo "-------------------"; echo "#findmnt --kernel /var/tmp | grep nosuid -ne 0 ";findmnt --kernel /var/tmp | grep nosuid; fi
|
|
if [ $(grep -E "\s+/var/tmp\s+.*nosuid" /etc/fstab | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -E \"\s+/var/tmp\s+.*nosuid\" /etc/fstab -ne 0 ";grep -E "\s+/var/tmp\s+.*nosuid" /etc/fstab; fi
|
|
echo "-------------------"
|
|
else
|
|
echo "{\"1.1.3.2. Cấu hình tuỳ chọn nosuid cho phân vùng /var/tmp\" : \"PASSED\"}"
|
|
fi
|
|
|
|
if ! findmnt --kernel /var/tmp >/dev/null 2>&1; then
|
|
echo "{\"1.1.3.3. Cấu hình tuỳ chọn noexec cho phân vùng /var/tmp\" : \"PASSED\"}"
|
|
elif [ $(findmnt --kernel /var/tmp | grep noexec | wc -l) -eq 0 ] || [ $(grep -E "\s+/var/tmp\s+.*noexec" /etc/fstab | wc -l) -eq 0 ]; then
|
|
echo "{\"1.1.3.3. Cấu hình tuỳ chọn noexec cho phân vùng /var/tmp\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
if [ $(findmnt --kernel /var/tmp | grep noexec | wc -l) -eq 0 ]; then echo "-------------------"; echo "#findmnt --kernel /var/tmp | grep noexec -ne 0 ";findmnt --kernel /var/tmp | grep noexec; fi
|
|
if [ $(grep -E "\s+/var/tmp\s+.*noexec" /etc/fstab | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -E \"\s+/var/tmp\s+.*noexec\" /etc/fstab -ne 0 ";grep -E "\s+/var/tmp\s+.*noexec" /etc/fstab; fi
|
|
echo "-------------------"
|
|
else
|
|
echo "{\"1.1.3.3. Cấu hình tuỳ chọn noexec cho phân vùng /var/tmp\" : \"PASSED\"}"
|
|
fi
|
|
|
|
# Log
|
|
echo "-------------------"
|
|
echo "# Chỉnh sửa file /etc/fstab và thêm tùy chọn nodev, nosuid, noexec vào trường thứ 4 trong cấu hình của phân vùng /var/tmp. Ví dụ:
|
|
# tmpfs /var/tmp tmpfs defaults,nodev,nosuid,noexec 0 0
|
|
# Thực hiện các lệnh sau để mount phân vùng /var/tmp và cập nhật cấu hình fstab:
|
|
# mount /var/tmp
|
|
# mount -o remount /var/tmp"
|
|
echo "-------------------"
|
|
#[ $(findmnt --kernel /var/tmp | wc -l) -ne 0 ] && echo "Directory /var/tmp is mounted" || echo "Directory /var/tmp is not mounted"
|
|
echo "######################################"
|
|
|
|
############################################################################
|
|
# Chỉnh sửa file /etc/fstab và thêm tùy chọn nodev, nosuid, noexec vào trường thứ 4 trong cấu hình của phân vùng /home. Ví dụ:
|
|
# <device> /home <fstype> defaults,nodev,nosuid 0 0
|
|
# Thực hiện các lệnh sau để cập nhật cấu hình fstab:
|
|
# mount -o remount /home
|
|
if ! findmnt --kernel /home >/dev/null 2>&1; then
|
|
echo "{\"1.1.4.1. Cấu hình tuỳ chọn nodev cho phân vùng /home\" : \"PASSED\"}"
|
|
elif [ $(findmnt --kernel /home | grep nodev | wc -l) -eq 0 ] || [ $(grep -E "\s+/home\s+.*nodev" /etc/fstab | wc -l) -eq 0 ]; then
|
|
echo "{\"1.1.4.1. Cấu hình tuỳ chọn nodev cho phân vùng /home\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
if [ $(findmnt --kernel /home | grep nodev | wc -l) -eq 0 ]; then echo "-------------------"; echo "#findmnt --kernel /home | grep nodev -ne 0 ";findmnt --kernel /home | grep nodev; fi
|
|
if [ $(grep -E "\s+/home\s+.*nodev" /etc/fstab | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -E \"\s+/home\s+.*nodev\" /etc/fstab -ne 0 ";grep -E "\s+/home\s+.*nodev" /etc/fstab; fi
|
|
echo "-------------------"
|
|
else
|
|
echo "{\"1.1.4.1. Cấu hình tuỳ chọn nodev cho phân vùng /home\" : \"PASSED\"}"
|
|
fi
|
|
|
|
if ! findmnt --kernel /home >/dev/null 2>&1; then
|
|
echo "{\"1.1.4.2. Cấu hình tuỳ chọn nosuid cho phân vùng /home\" : \"PASSED\"}"
|
|
elif [ $(findmnt --kernel /home | grep nosuid | wc -l) -eq 0 ] || [ $(grep -E "\s+/home\s+.*nosuid" /etc/fstab | wc -l) -eq 0 ]; then
|
|
echo "{\"1.1.4.2. Cấu hình tuỳ chọn nosuid cho phân vùng /home\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
if [ $(findmnt --kernel /home | grep nosuid | wc -l) -eq 0 ]; then echo "-------------------"; echo "#findmnt --kernel /home | grep nosuid -ne 0 ";findmnt --kernel /home | grep nosuid; fi
|
|
if [ $(grep -E "\s+/home\s+.*nosuid" /etc/fstab | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -E \"\s+/home\s+.*nosuid\" /etc/fstab -ne 0 ";grep -E "\s+/home\s+.*nosuid" /etc/fstab; fi
|
|
echo "-------------------"
|
|
else
|
|
echo "{\"1.1.4.2. Cấu hình tuỳ chọn nosuid cho phân vùng /home\" : \"PASSED\"}"
|
|
fi
|
|
|
|
# Log
|
|
echo "-------------------"
|
|
echo "# Chỉnh sửa file /etc/fstab và thêm tùy chọn nodev, nosuid, noexec vào trường thứ 4 trong cấu hình của phân vùng /home. Ví dụ:
|
|
# <device> /home <fstype> defaults,nodev,nosuid 0 0
|
|
# Thực hiện các lệnh sau để cập nhật cấu hình fstab:
|
|
# mount -o remount /home"
|
|
echo "-------------------"
|
|
#[ $(findmnt --kernel /home | wc -l) -ne 0 ] && echo "Directory /home is mounted" || echo "Directory /home is not mounted"
|
|
echo "######################################"
|
|
|
|
############################################################################
|
|
# Chỉnh sửa file /etc/fstab và thêm tùy chọn nodev, nosuid, noexec vào trường thứ 4 trong cấu hình của phân vùng /dev/shm. Ví dụ:
|
|
# tmpfs /dev/shm tmpfs defaults,nodev,nosuid,noexec 0 0
|
|
# Thực hiện các lệnh sau để mount phân vùng /dev/shm và cập nhật cấu hình fstab:
|
|
# mount /dev/shm
|
|
# mount -o remount /dev/shm
|
|
if ! findmnt --kernel /dev/shm >/dev/null 2>&1; then
|
|
echo "{\"1.1.5.1. Cấu hình tuỳ chọn nodev cho phân vùng /dev/shm\" : \"PASSED\"}"
|
|
elif [ $(findmnt --kernel /dev/shm | grep nodev | wc -l) -eq 0 ] || [ $(grep -E "\s+/dev/shm\s+.*nodev" /etc/fstab | wc -l) -eq 0 ]; then
|
|
echo "{\"1.1.5.1. Cấu hình tuỳ chọn nodev cho phân vùng /dev/shm\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
if [ $(findmnt --kernel /dev/shm | grep nodev | wc -l) -eq 0 ]; then echo "-------------------"; echo "#findmnt --kernel /dev/shm | grep nodev -ne 0 ";findmnt --kernel /dev/shm | grep nodev; fi
|
|
if [ $(grep -E "\s+/dev/shm\s+.*nodev" /etc/fstab | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -E \"\s+/dev/shm\s+.*nodev\" /etc/fstab -ne 0 ";grep -E "\s+/dev/shm\s+.*nodev" /etc/fstab; fi
|
|
echo "-------------------"
|
|
else
|
|
echo "{\"1.1.5.1. Cấu hình tuỳ chọn nodev cho phân vùng /dev/shm\" : \"PASSED\"}"
|
|
fi
|
|
|
|
if ! findmnt --kernel /dev/shm >/dev/null 2>&1; then
|
|
echo "{\"1.1.5.2. Cấu hình tuỳ chọn nosuid cho phân vùng /dev/shm\" : \"PASSED\"}"
|
|
elif [ $(findmnt --kernel /dev/shm | grep nosuid | wc -l) -eq 0 ] || [ $(grep -E "\s+/dev/shm\s+.*nosuid" /etc/fstab | wc -l) -eq 0 ]; then
|
|
echo "{\"1.1.5.2. Cấu hình tuỳ chọn nosuid cho phân vùng /dev/shm\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
if [ $(findmnt --kernel /dev/shm | grep nosuid | wc -l) -eq 0 ]; then echo "-------------------"; echo "#findmnt --kernel /dev/shm | grep nosuid -ne 0 ";findmnt --kernel /dev/shm | grep nosuid; fi
|
|
if [ $(grep -E "\s+/dev/shm\s+.*nosuid" /etc/fstab | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -E \"\s+/dev/shm\s+.*nosuid\" /etc/fstab -ne 0 ";grep -E "\s+/dev/shm\s+.*nosuid" /etc/fstab; fi
|
|
echo "-------------------"
|
|
else
|
|
echo "{\"1.1.5.2. Cấu hình tuỳ chọn nosuid cho phân vùng /dev/shm\" : \"PASSED\"}"
|
|
fi
|
|
|
|
if ! findmnt --kernel /dev/shm >/dev/null 2>&1; then
|
|
echo "{\"1.1.5.3. Cấu hình tuỳ chọn noexec cho phân vùng /dev/shm\" : \"PASSED\"}"
|
|
elif [ $(findmnt --kernel /dev/shm | grep noexec | wc -l) -eq 0 ] || [ $(grep -E "\s+/dev/shm\s+.*noexec" /etc/fstab | wc -l) -eq 0 ]; then
|
|
echo "{\"1.1.5.3. Cấu hình tuỳ chọn noexec cho phân vùng /dev/shm\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
if [ $(findmnt --kernel /dev/shm | grep noexec | wc -l) -eq 0 ]; then echo "-------------------"; echo "#findmnt --kernel /dev/shm | grep noexec -ne 0 ";findmnt --kernel /dev/shm | grep noexec; fi
|
|
if [ $(grep -E "\s+/dev/shm\s+.*noexec" /etc/fstab | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -E \"\s+/dev/shm\s+.*noexec\" /etc/fstab -ne 0 ";grep -E "\s+/dev/shm\s+.*noexec" /etc/fstab; fi
|
|
echo "-------------------"
|
|
else
|
|
echo "{\"1.1.5.3. Cấu hình tuỳ chọn noexec cho phân vùng /dev/shm\" : \"PASSED\"}"
|
|
fi
|
|
|
|
# Log
|
|
echo "-------------------"
|
|
echo "# Chỉnh sửa file /etc/fstab và thêm tùy chọn nodev, nosuid, noexec vào trường thứ 4 trong cấu hình của phân vùng /dev/shm. Ví dụ:
|
|
# tmpfs /dev/shm tmpfs defaults,nodev,nosuid,noexec 0 0
|
|
# Thực hiện các lệnh sau để mount phân vùng /dev/shm và cập nhật cấu hình fstab:
|
|
# mount /dev/shm
|
|
# mount -o remount /dev/shm"
|
|
echo "-------------------"
|
|
#[ $(findmnt --kernel /dev/shm | wc -l) -ne 0 ] && echo "Directory /dev/shm is mounted" || echo "Directory /dev/shm is not mounted"
|
|
echo "######################################"
|
|
|
|
##################################################################################################################
|
|
# Thực hiện câu lệnh sau để đặt sticky bit cho toàn bộ thư mục dùng chung:
|
|
# df --local -P | awk '{if (NR!=1) print $6}' | xargs -I '{}' find '{}' -xdev -type d \( -perm -0002 -a ! -perm -1000 \) 2>/dev/null | xargs -I '{}' chmod a+t '{}'
|
|
if [ $(df --local -P | awk '{if (NR!=1) print $6}' | xargs -I '{}' find '{}' -xdev -type d \( -perm -0002 -a ! -perm -1000 \) 2>/dev/null | wc -l) -ne 0 ]; then
|
|
echo "{\"1.1.6. Cấu hình sticky bit cho tất cả các thư mục dùng chung\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để đặt sticky bit cho toàn bộ thư mục dùng chung:
|
|
# df --local -P | awk '{if (NR!=1) print \$6}' | xargs -I '{}' find '{}' -xdev -type d \( -perm -0002 -a ! -perm -1000 \) 2>/dev/null | xargs -I '{}' chmod a+t '{}'"
|
|
if [ $(df --local -P | awk '{if (NR!=1) print $6}' | xargs -I '{}' find '{}' -xdev -type d \( -perm -0002 -a ! -perm -1000 \) 2>/dev/null | wc -l) -ne 0 ]; then echo "-------------------"; echo "#df --local -P | awk '{if (NR!=1) print \$6}' | xargs -I '{}' find '{}' -xdev -type d \( -perm -0002 -a ! -perm -1000 \) 2>/dev/null -eq 0 ";df --local -P | awk '{if (NR!=1) print $6}' | xargs -I '{}' find '{}' -xdev -type d \( -perm -0002 -a ! -perm -1000 \) 2>/dev/null; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"1.1.6. Cấu hình sticky bit cho tất cả các thư mục dùng chung\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện câu lệnh sau để vô hiệu hóa autofs:
|
|
# systemctl --now disable autofs
|
|
# Thực hiện câu lệnh sau để gỡ bỏ autofs nếu không có thành phần nào yêu cầu gói autofs:
|
|
# apt purge autofs
|
|
if [ $(dpkg -l | grep "ii autofs" | wc -l) -ne 0 ] || [ $(systemctl is-enabled autofs 2>/dev/null | grep "enabled" | wc -l) -ne 0 ]; then
|
|
echo "{\"2.2.2. Cấu hình vô hiệu hoá autofs services\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để vô hiệu hóa autofs:
|
|
# systemctl --now disable autofs
|
|
# Thực hiện câu lệnh sau để gỡ bỏ autofs nếu không có thành phần nào yêu cầu gói autofs:
|
|
# apt purge autofs"
|
|
if [ $(dpkg -l | grep "ii autofs" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#dpkg -l | grep \"ii autofs\" -eq 0";dpkg -l | grep "ii autofs"; fi
|
|
if [ $(systemctl is-enabled autofs 2>/dev/null | grep "enabled" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#systemctl is-enabled autofs 2>/dev/null | grep \"enabled\" -eq 0 ";systemctl is-enabled autofs 2>/dev/null | grep "enabled"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"2.2.2. Cấu hình vô hiệu hoá autofs services\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Chỉnh sửa hoặc tạo một file trong thư mục /etc/modprobe.d/usb_storage.conf và thêm vào những dòng sau:
|
|
# install usb-storage /bin/true
|
|
# Thực hiện câu lệnh sau để gỡ bỏ USB Storage:
|
|
# rmmod usb-storage
|
|
if [ $(modprobe -n -v usb-storage 2>/dev/null | grep -P "^\h*install.*/bin/true" | wc -l) -eq 0 ] || [ $(lsmod | grep usb-storage | wc -l) -ne 0 ]; then
|
|
echo "{\"1.1.1.8. Cấu hình vô hiệu hoá usb storage\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Chỉnh sửa hoặc tạo một file trong thư mục /etc/modprobe.d/usb_storage.conf và thêm vào những dòng sau:
|
|
# install usb-storage /bin/true
|
|
# Thực hiện câu lệnh sau để gỡ bỏ USB Storage:
|
|
# rmmod usb-storage"
|
|
if [ $(modprobe -n -v usb-storage 2>/dev/null | grep -P "^\h*install.*/bin/true" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#modprobe -n -v usb-storage 2>/dev/null | grep \"^install.*/bin/true\" -ne 0 ";modprobe -n -v usb-storage 2>/dev/null | grep -P "^\h*install.*/bin/true"; fi
|
|
if [ $(lsmod | grep usb-storage | wc -l) -ne 0 ]; then echo "-------------------"; echo "#lsmod | grep usb-storage -eq 0 ";lsmod | grep usb-storage; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"1.1.1.8. Cấu hình vô hiệu hoá usb storage\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện câu lệnh sau và đảm bảo rằng aide được cài đặt:
|
|
# apt install aide aide-common
|
|
# Thực hiện các câu lệnh sau để khởi tạo AIDE:
|
|
# aideinit
|
|
# mv /var/lib/aide/aide.db.new /var/lib/aide/aide.db
|
|
if [ $(dpkg -l | grep "ii aide" | wc -l) -eq 0 ]; then
|
|
echo "{\"1.2.1. Kiểm tra cài đặt AIDE\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau và đảm bảo rằng aide được cài đặt:
|
|
# apt install aide aide-common
|
|
# Thực hiện các câu lệnh sau để khởi tạo AIDE:
|
|
# aideinit
|
|
# mv /var/lib/aide/aide.db.new /var/lib/aide/aide.db"
|
|
if [ $(dpkg -l | grep "ii aide" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#dpkg -l | grep \"ii aide\" -ne 0 ";dpkg -l | grep "ii aide"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"1.2.1. Kiểm tra cài đặt AIDE\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện câu lệnh sau:
|
|
# crontab -u root -e
|
|
# Đặt dòng sau vào crontab:
|
|
# 0 5 * * * /usr/bin/aide.wrapper --config /etc/aide/aide.conf --check
|
|
if [ $(grep -Prs '^([^#\n\r]+\h+)?(\/usr\/s?bin\/|^\h*)aide(\.wrapper)?\h+(-- check|([^#\n\r]+\h+)?\$AIDEARGS)\b' /etc/cron.* /etc/crontab /var/spool/cron/ 2>/dev/null | wc -l) -eq 0 ]; then
|
|
echo "{\"1.2.2. Cấu hình kiểm tra tính toàn vẹn của filesystem\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau:
|
|
# crontab -u root -e
|
|
# Đặt dòng sau vào crontab:
|
|
# 0 5 * * * /usr/bin/aide.wrapper --config /etc/aide/aide.conf --check"
|
|
if [ $(grep -Prs '^([^#\n\r]+\h+)?(\/usr\/s?bin\/|^\h*)aide(\.wrapper)?\h+(-- check|([^#\n\r]+\h+)?\$AIDEARGS)\b' /etc/cron.* /etc/crontab /var/spool/cron/ 2>/dev/null | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -Prs '^([^#\\n\\r]+\\h+)?(\\/usr\\/s?bin\\/|^\\h*)aide(\\.wrapper)?\\h+(-- check|([^#\\n\\r]+\\h+)?\\\$AIDEARGS)\\b' /etc/cron.* /etc/crontab /var/spool/cron/ 2>/dev/null -ne 0 ";grep -Prs '^([^#\n\r]+\h+)?(\/usr\/s?bin\/|^\h*)aide(\.wrapper)?\h+(-- check|([^#\n\r]+\h+)?\$AIDEARGS)\b' /etc/cron.* /etc/crontab /var/spool/cron/ 2>/dev/null; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"1.2.2. Cấu hình kiểm tra tính toàn vẹn của filesystem\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện các câu lệnh sau để đặt các quyền cho file cấu hình grub:
|
|
# chown root:root /boot/grub/grub.cfg
|
|
# chmod u-wx,go-rwx /boot/grub/grub.cfg
|
|
if [ $(stat -c "%a:%u:%g" /boot/grub/grub.cfg 2>/dev/null | grep -P '^\h*[0-4]00:0:0$' | wc -l) -eq 0 ]; then
|
|
echo "{\"1.3.1. Phân quyền đối với file cấu hình bootloader\" : \"FAILED\"}"
|
|
# Log
|
|
echo "# Thực hiện các câu lệnh sau để đặt các quyền cho file cấu hình grub:
|
|
# chown root:root /boot/grub/grub.cfg
|
|
# chmod u-wx,go-rwx /boot/grub/grub.cfg"
|
|
if [ $(stat -c "%a:%u:%g" /boot/grub/grub.cfg 2>/dev/null | grep -P '^\h*[0-4]00:0:0$' | wc -l) -eq 0 ]; then echo "-------------------"; echo "#stat -c \"%a:%u:%g\" \$grubdir/user.cfg 2>/dev/null | grep -P '^\h*[0-4]00:0:0\$' -ne 0 ";stat -c "%a:%u:%g" $grubdir/user.cfg 2>/dev/null | grep -P '^\h*[0-4]00:0:0$'; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"1.3.1. Phân quyền đối với file cấu hình bootloader\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện câu lệnh sau và tiến hành cài đặt theo cửa sổ câu lệnh để cài đặt mật khẩu cho tài khoản root:
|
|
# passwd root
|
|
if [ $(grep -Ei '^root:\$([0-9]|[A-Z])' /etc/shadow | wc -l) -eq 0 ]; then
|
|
echo "{\"1.3.2. Cấu hình xác thực khi truy cập single user mode\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau và tiến hành cài đặt theo cửa sổ câu lệnh để cài đặt mật khẩu cho tài khoản root:
|
|
# passwd root"
|
|
if [ $(grep -Ei '^root:\$([0-9]|[A-Z])' /etc/shadow | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -Ei '^root:\\\$([0-9]|[A-Z])' /etc/shadow -ne 0 ";grep -Ei '^root:\$([0-9]|[A-Z])' /etc/shadow; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"1.3.2. Cấu hình xác thực khi truy cập single user mode\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện câu lệnh sau và tiến hành cài đặt theo cửa sổ câu lệnh để cài đặt mật khẩu cho tài khoản root:
|
|
# passwd root
|
|
if [ $(grep -Ei '^root:\$([0-9]|[A-Z])' /etc/shadow | wc -l) -eq 0 ]; then
|
|
echo "{\"1.3.3. Cấu hình xác thực khi truy cập single user mode\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau và tiến hành cài đặt theo cửa sổ câu lệnh để cài đặt mật khẩu cho tài khoản root:
|
|
# passwd root"
|
|
if [ $(grep -Ei '^root:\$([0-9]|[A-Z])' /etc/shadow | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -Ei '^root:\\\$([0-9]|[A-Z])' /etc/shadow -ne 0 ";grep -Ei '^root:\$([0-9]|[A-Z])' /etc/shadow; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"1.3.3. Cấu hình xác thực khi truy cập single user mode\" : \"PASSED\"}"
|
|
fi
|
|
|
|
##################################################################################################################
|
|
# echo -e "\n######################################"
|
|
# if [[ $(grep -E "\s[6].[0-9]" /etc/os-release | wc -l) -ne 0 && $(grep "^PROMPT=" /etc/sysconfig/init 2>/dev/null | grep "no" | wc -l) -eq 0 ]]; then
|
|
# echo "{\"1.3.4. Cấu hình vô hiệu hoá interactive boot\" : \"FAILED\"}"
|
|
# else
|
|
# echo "{\"1.3.4. Cấu hình vô hiệu hoá interactive boot\" : \"PASSED\"}"
|
|
# fi
|
|
# # Log
|
|
# if [ $(grep -E "\s[6].[0-9]" /etc/os-release | wc -l) -ne 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -E \"\\s[6].[0-9]\" /etc/os-release -eq 0"; grep -E "\s[6].[0-9]" /etc/os-release
|
|
# if [ $(grep "^PROMPT" /etc/sysconfig/init 2>/dev/null | grep "no" | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep \"^PROMPT\" /etc/sysconfig/init 2>/dev/null | grep \"no\" -ne 0"; grep "^PROMPT" /etc/sysconfig/init 2>/dev/null | grep "no"
|
|
# echo "----------LOG----------"
|
|
# echo "#cat /etc/os-release -eq 6.x"; cat /etc/os-release
|
|
# echo "#grep \"^PROMPT\" /etc/sysconfig/init"; grep "^PROMPT" /etc/sysconfig/init
|
|
|
|
############################################################################
|
|
# Chỉnh sửa hoặc tạo một file /etc/sysctl.conf hoặc /etc/sysctl.d/*.conf và thêm vào dòng sau:
|
|
# kernel.randomize_va_space = 2
|
|
# Thực hiện câu lệnh sau để đặt thông số vào kernel đang hoạt động:
|
|
# sysctl -w kernel.randomize_va_space=2
|
|
if [ $(sysctl kernel.randomize_va_space 2>/dev/null | grep 2 | wc -l) -eq 0 ] || [ $(grep -P "^\h*kernel.randomize_va_space.*=.*2" /etc/sysctl.conf /etc/sysctl.d/*.conf 2>/dev/null | wc -l) -eq 0 ]; then
|
|
echo "{\"1.4.1. Cấu hình kích hoạt ASLR (address space layout randomization)\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Chỉnh sửa hoặc tạo một file /etc/sysctl.conf hoặc /etc/sysctl.d/*.conf và thêm vào dòng sau:
|
|
# kernel.randomize_va_space = 2
|
|
# Thực hiện câu lệnh sau để đặt thông số vào kernel đang hoạt động:
|
|
# sysctl -w kernel.randomize_va_space=2"
|
|
if [ $(sysctl kernel.randomize_va_space 2>/dev/null | grep 2 | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sysctl kernel.randomize_va_space 2>/dev/null | grep 2 -ne 0 ";sysctl kernel.randomize_va_space 2>/dev/null | grep 2; fi
|
|
if [ $(grep -P "^\h*kernel.randomize_va_space.*=.*2" /etc/sysctl.conf /etc/sysctl.d/*.conf 2>/dev/null | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -P \"^\\h*kernel.randomize_va_space.*=.*2\" /etc/sysctl.conf /etc/sysctl.d/*.conf 2>/dev/null -ne 0 ";grep -P "^\h*kernel.randomize_va_space.*=.*2" /etc/sysctl.conf /etc/sysctl.d/*.conf 2>/dev/null ; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"1.4.1. Cấu hình kích hoạt ASLR (address space layout randomization)\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện câu lệnh sau để khôi phục binaries trở về bình thường:
|
|
# prelink -ua
|
|
# Gỡ cài đặt prelink sử dụng trình quản lý package phù hợp:
|
|
# apt purge prelink
|
|
if [ $(dpkg -l | grep "ii prelink" | wc -l) -ne 0 ]; then
|
|
echo "{\"1.4.2. Cấu hình vô hiệu hoá prelink\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để khôi phục binaries trở về bình thường:
|
|
# prelink -ua
|
|
# Gỡ cài đặt prelink sử dụng trình quản lý package phù hợp:
|
|
# apt purge prelink"
|
|
if [ $(dpkg -l | grep "ii prelink" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#dpkg -l | grep \"ii prelink\" -eq 0 ";dpkg -l | grep "ii prelink"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"1.4.2. Cấu hình vô hiệu hoá prelink\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Chỉnh sửa file /etc/security/limits.conf hoặc /etc/security/limits.d/*.conf và thêm dòng sau:
|
|
# * hard core 0
|
|
# Chỉnh sửa file /etc/sysctl.conf hoặc /etc/sysctl.d/*.conf và thêm dòng sau:
|
|
# fs.suid_dumpable = 0
|
|
# Thực hiện câu lệnh sau để đặt thông số vào kernel đang hoạt động:
|
|
# sysctl -w fs.suid_dumpable=0
|
|
# Chỉnh sửa file /etc/systemd/coredump.conf và thêm dòng sau để vô hiệu hoá core dump:
|
|
# Storage=none
|
|
# ProcessSizeMax=0
|
|
# Thực hiện câu lệnh sau để tải lại cấu hình của systemd daemon:
|
|
# systemctl daemon-reload
|
|
if \
|
|
! grep -Psq '^\h*\*\h+hard\h+core\h+0(\h+|$)' /etc/security/limits.conf /etc/security/limits.d/*.conf 2>/dev/null \
|
|
|| [ "$(sysctl -n fs.suid_dumpable 2>/dev/null)" != "0" ] \
|
|
|| ! grep -Psq '^\h*fs\.suid_dumpable\h*=\h*0(\h*|$)' /etc/sysctl.conf /etc/sysctl.d/*.conf 2>/dev/null \
|
|
|| ( systemctl list-unit-files --type=service --type=socket 2>/dev/null \
|
|
| grep -q '^systemd-coredump' \
|
|
&& { \
|
|
! grep -Psiq '^\h*Storage\h*=\h*none(\h*|$)' /etc/systemd/coredump.conf /etc/systemd/coredump.conf.d/*.conf 2>/dev/null \
|
|
|| ! grep -Psiq '^\h*ProcessSizeMax\h*=\h*0(\h*|$)' /etc/systemd/coredump.conf /etc/systemd/coredump.conf.d/*.conf 2>/dev/null ; \
|
|
} )
|
|
then
|
|
echo '{"1.4.3. Cấu hình vô hiệu hoá core dump" : "FAILED"}'
|
|
echo "######################################"
|
|
echo "# Cách khắc phục đề xuất:"
|
|
echo "# 1) Vô hiệu hoá core theo limits:"
|
|
echo "# echo '* hard core 0' > /etc/security/limits.d/99-coredump.conf"
|
|
echo "# 2) Vô hiệu hoá SUID dump:"
|
|
echo "# echo 'fs.suid_dumpable = 0' > /etc/sysctl.d/99-coredump.conf && sysctl -w fs.suid_dumpable=0"
|
|
echo "# 3) Nếu có systemd-coredump: tạo drop-in rồi reload:"
|
|
echo "# mkdir -p /etc/systemd/coredump.conf.d"
|
|
echo "# printf '[Coredump]\\nStorage=none\\nProcessSizeMax=0\\n' > /etc/systemd/coredump.conf.d/override.conf"
|
|
echo "# systemctl daemon-reload"
|
|
echo "######################################"
|
|
else
|
|
echo '{"1.4.3. Cấu hình vô hiệu hoá core dump" : "PASSED"}'
|
|
fi
|
|
|
|
############################################################################
|
|
# Chỉnh sửa file /etc/motd với nội dung phù hợp dựa theo chính sách của tổ chức, loại bỏ các trường hợp \m, \r, \s, hoặc \v.
|
|
# Nếu không sử dụng motd, thực hiện câu lệnh sau để xoá bỏ file /etc/motd:
|
|
# rm /etc/motd
|
|
if [ $(grep -E -i "(\\\v|\\\r|\\\m|\\\s|$(grep '^ID=' /etc/os-release | cut -d= -f2 | sed -e 's/"//g'))" /etc/motd 2>/dev/null | wc -l) -ne 0 ]; then
|
|
echo "{\"1.5.1. Kiểm soát nội dung motd (Message Of The Day)\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Chỉnh sửa file /etc/motd với nội dung phù hợp dựa theo chính sách của tổ chức, loại bỏ các trường hợp \m, \r, \s, hoặc \v.
|
|
# Nếu không sử dụng motd, thực hiện câu lệnh sau để xoá bỏ file /etc/motd:
|
|
# rm /etc/motd"
|
|
if [ $(grep -E -i "(\\\v|\\\r|\\\m|\\\s|$(grep '^ID=' /etc/os-release | cut -d= -f2 | sed -e 's/"//g'))" /etc/motd 2>/dev/null | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -E -i \"(\\\\\\v|\\\\\\r|\\\\\\m|\\\\\\s|\$(grep '^ID=' /etc/os-release | cut -d= -f2 | sed -e 's/\"//g'))\" /etc/motd 2>/dev/null -eq 0 ";grep -E -i "(\\\v|\\\r|\\\m|\\\s|$(grep '^ID=' /etc/os-release | cut -d= -f2 | sed -e 's/"//g'))" /etc/motd 2>/dev/null ; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"1.5.1. Kiểm soát nội dung motd (Message Of The Day)\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện câu lệnh sau để đặt lại nội dung cho file /etc/issue:
|
|
# echo "Authorized uses only. All activity may be monitored and reported." > /etc/issue
|
|
if [ $(grep -E -i "(\\\v|\\\r|\\\m|\\\s|$(grep '^ID=' /etc/os-release | cut -d= -f2 | sed -e 's/"//g'))" /etc/issue 2>/dev/null | wc -l) -ne 0 ]; then
|
|
echo "{\"1.5.2. Kiểm soát nội dung thông báo khi đăng nhập\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để đặt lại nội dung cho file /etc/issue:
|
|
# echo \"Authorized uses only. All activity may be monitored and reported.\" > /etc/issue"
|
|
if [ $(grep -E -i "(\\\v|\\\r|\\\m|\\\s|$(grep '^ID=' /etc/os-release | cut -d= -f2 | sed -e 's/"//g'))" /etc/issue 2>/dev/null | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -E -i \"(\\\\\\v|\\\\\\r|\\\\\\m|\\\\\\s|\$(grep '^ID=' /etc/os-release | cut -d= -f2 | sed -e 's/\"//g'))\" /etc/issue 2>/dev/null -eq 0 ";grep -E -i "(\\\v|\\\r|\\\m|\\\s|$(grep '^ID=' /etc/os-release | cut -d= -f2 | sed -e 's/"//g'))" /etc/issue 2>/dev/null ; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"1.5.2. Kiểm soát nội dung thông báo khi đăng nhập\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện câu lệnh sau để đặt lại nội dung cho file /etc/issue.net:
|
|
# echo "Authorized uses only. All activity may be monitored and reported." > /etc/issue.net
|
|
if [ $(grep -E -i "(\\\v|\\\r|\\\m|\\\s|$(grep '^ID=' /etc/os-release | cut -d= -f2 | sed -e 's/"//g'))" /etc/issue.net 2>/dev/null | wc -l) -ne 0 ]; then
|
|
echo "{\"1.5.3. Kiểm soát nội dung thông báo khi đăng nhập từ xa\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để đặt lại nội dung cho file /etc/issue.net:
|
|
# echo \"Authorized uses only. All activity may be monitored and reported.\" > /etc/issue.net"
|
|
if [ $(grep -E -i "(\\\v|\\\r|\\\m|\\\s|$(grep '^ID=' /etc/os-release | cut -d= -f2 | sed -e 's/"//g'))" /etc/issue.net 2>/dev/null | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -E -i \"(\\\\\\v|\\\\\\r|\\\\\\m|\\\\\\s|\$(grep '^ID=' /etc/os-release | cut -d= -f2 | sed -e 's/\"//g'))\" /etc/issue.net 2>/dev/null -eq 0 ";grep -E -i "(\\\v|\\\r|\\\m|\\\s|$(grep '^ID=' /etc/os-release | cut -d= -f2 | sed -e 's/"//g'))" /etc/issue.net 2>/dev/null ; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"1.5.3. Kiểm soát nội dung thông báo khi đăng nhập từ xa\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện các câu lệnh sau để đặt quyền cho file /etc/motd:
|
|
# chown root:root /etc/motd
|
|
# chmod u-x,go-wx /etc/motd
|
|
motd=/etc/motd
|
|
# Nếu là symlink thì lấy đích thật, còn không thì dùng chính nó
|
|
if [ -L "$motd" ]; then
|
|
motd_target=$(readlink -f -- "$motd" 2>/dev/null || echo "")
|
|
else
|
|
motd_target="$motd"
|
|
fi
|
|
|
|
# 1) Không có file để kiểm tra -> coi là PASSED (không rò rỉ thông tin qua MOTD)
|
|
if [ -z "$motd_target" ] || [ ! -e "$motd_target" ]; then
|
|
echo '{"1.5.4. Cấu hình phân quyền đối với file /etc/motd" : "PASSED"}'
|
|
echo "######################################"
|
|
# exit 0
|
|
|
|
# 2) Có file -> kiểm tra quyền/owner root:root và mode <= 644 (không x với owner, không w cho group/others)
|
|
# Mẫu: ^[0-6][0-4][0-4]:0:0$ tương ứng u<=6, g<=4, o<=4 ; uid=0, gid=0
|
|
elif stat -c "%a:%u:%g" -- "$motd_target" 2>/dev/null \
|
|
| grep -Pq '^[0-6][0-4][0-4]:0:0$'
|
|
then
|
|
echo '{"1.5.4. Cấu hình phân quyền đối với file /etc/motd" : "PASSED"}'
|
|
else
|
|
echo '{"1.5.4. Cấu hình phân quyền đối với file /etc/motd" : "FAILED"}'
|
|
echo "######################################"
|
|
echo "# Thực hiện các câu lệnh sau để đặt quyền cho file:"
|
|
echo "# chown root:root \"$motd_target\""
|
|
echo "# chmod u-x,go-wx \"$motd_target\" # tương đương chmod 0644 hoặc chặt hơn"
|
|
echo "-------------------"
|
|
echo "# Hiện trạng:"
|
|
stat -c "%A %a %U:%G %n" -- "$motd_target" 2>/dev/null || true
|
|
echo "######################################"
|
|
fi
|
|
|
|
|
|
############################################################################
|
|
# Thực hiện các câu lệnh sau để đặt quyền cho /etc/issue:
|
|
# chown root:root /etc/issue
|
|
# chmod u-x,go-wx /etc/issue
|
|
if [ $(stat -c "%a:%u:%g" /etc/issue 2>/dev/null | grep -P "^\h*[0-6][0-4][0-4]:0:0$" | wc -l) -eq 0 ]; then
|
|
echo "{\"1.5.5. Cấu hình phân quyền đối với file /etc/issue\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện các câu lệnh sau để đặt quyền cho /etc/issue:
|
|
# chown root:root /etc/issue
|
|
# chmod u-x,go-wx /etc/issue"
|
|
if [ $(stat -c "%a:%u:%g" /etc/issue 2>/dev/null | grep -P "^\h*[0-6][0-4][0-4]:0:0$" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#stat -c \"%a:%u:%g\" /etc/issue 2>/dev/null | grep -P \"^\\h*[0-6][0-4][0-4]:0:0\$\" -ne 0 ";stat -c "%a:%u:%g" /etc/issue 2>/dev/null | grep -P "^\h*[0-6][0-4][0-4]:0:0$"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"1.5.5. Cấu hình phân quyền đối với file /etc/issue\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện các câu lệnh sau để đặt quyền cho /etc/issue.net:
|
|
# chown root:root /etc/issue.net
|
|
# chmod u-x,go-wx /etc/issue.net
|
|
if [ $(stat -c "%a:%u:%g" /etc/issue.net 2>/dev/null | grep -P "^\h*[0-6][0-4][0-4]:0:0$" | wc -l) -eq 0 ]; then
|
|
echo "{\"1.5.6. Cấu hình phân quyền đối với file /etc/issue.net\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện các câu lệnh sau để đặt quyền cho /etc/issue.net:
|
|
# chown root:root /etc/issue.net
|
|
# chmod u-x,go-wx /etc/issue.net"
|
|
if [ $(stat -c "%a:%u:%g" /etc/issue.net 2>/dev/null | grep -P "^\h*[0-6][0-4][0-4]:0:0$" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#stat -c \"%a:%u:%g\" /etc/issue.net 2>/dev/null | grep -P \"^\\h*[0-6][0-4][0-4]:0:0\$\" -ne 0 ";stat -c "%a:%u:%g" /etc/issue.net 2>/dev/null | grep -P "^\h*[0-6][0-4][0-4]:0:0$"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"1.5.6. Cấu hình phân quyền đối với file /etc/issue.net\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Tạo hoặc chỉnh sửa file /etc/gdm3/greeter.dconf-defaults và thêm vào các dòng sau:
|
|
# [org/gnome/login-screen]
|
|
# banner-message-enable=true
|
|
# banner-message-text='Authorized uses only. All activity may be monitored and reported.'
|
|
# disable-user-list=true
|
|
# Thực hiện câu lệnh sau để cập nhật dữ liệu hệ thống:
|
|
# dpkg-reconfigure gdm3
|
|
# B1) Phát hiện GNOME/GDM đã cài chưa (bất kỳ một trong các dấu hiệu sau):
|
|
# - Gói gdm3/gnome-shell đã cài
|
|
# - Tồn tại thư mục /etc/gdm3
|
|
# - Có session GNOME trong /usr/share/xsessions
|
|
if dpkg -l gdm3 gnome-shell 2>/dev/null | awk '$1=="ii"{f=1} END{exit !f}'; then
|
|
HAS_GNOME=1
|
|
elif [ -d /etc/gdm3 ]; then
|
|
HAS_GNOME=1
|
|
elif ls /usr/share/xsessions 2>/dev/null | grep -qE '^gnome.*\.desktop$'; then
|
|
HAS_GNOME=1
|
|
else
|
|
HAS_GNOME=0
|
|
fi
|
|
|
|
if [ "$HAS_GNOME" -ne 1 ]; then
|
|
echo '{"1.5.7. Kiểm soát nội dung thông báo khi truy cập GNOME" : "PASSED"}'
|
|
echo "######################################"
|
|
echo "# Ghi chú: Không phát hiện GNOME/GDM trên hệ thống, bỏ qua kiểm tra."
|
|
echo "######################################"
|
|
# exit 0
|
|
|
|
# B2) GNOME có mặt: kiểm tra các dòng trong /etc/gdm3/greeter.dconf-defaults
|
|
# Yêu cầu:
|
|
# [org/gnome/login-screen]
|
|
# banner-message-enable=true
|
|
# banner-message-text=...
|
|
# disable-user-list=true
|
|
#CFG=/etc/gdm3/greeter.dconf-defaults
|
|
|
|
elif \
|
|
! grep -Pqs '^\h*\[org/gnome/login-screen\]' "/etc/gdm3/greeter.dconf-defaults" 2>/dev/null || \
|
|
! grep -Pqs '^\h*banner-message-enable=true(\s*|$)' "/etc/gdm3/greeter.dconf-defaults" 2>/dev/null || \
|
|
! grep -Pqs '^\h*banner-message-text' "/etc/gdm3/greeter.dconf-defaults" 2>/dev/null || \
|
|
! grep -Pqs '^\h*disable-user-list=true(\s*|$)' "/etc/gdm3/greeter.dconf-defaults" 2>/dev/null
|
|
then
|
|
echo '{"1.5.7. Kiểm soát nội dung thông báo khi truy cập GNOME" : "FAILED"}'
|
|
echo "######################################"
|
|
echo "# Tạo/chỉnh sửa /etc/gdm3/greeter.dconf-defaults với nội dung tối thiểu:"
|
|
echo "# [org/gnome/login-screen]"
|
|
echo "# banner-message-enable=true"
|
|
echo "# banner-message-text='Authorized uses only. All activity may be monitored and reported.'"
|
|
echo "# disable-user-list=true"
|
|
echo "# Sau đó cập nhật cấu hình GDM:"
|
|
echo "# dpkg-reconfigure gdm3"
|
|
echo "-------------------"
|
|
echo "# Hiện trạng (nếu có):"
|
|
[ -f "/etc/gdm3/greeter.dconf-defaults" ] && grep -nE '^\s*(\[org/gnome/login-screen\]|banner-message-enable|banner-message-text|disable-user-list)' "/etc/gdm3/greeter.dconf-defaults" || echo "(không tìm thấy /etc/gdm3/greeter.dconf-defaults)"
|
|
echo "######################################"
|
|
else
|
|
echo '{"1.5.7. Kiểm soát nội dung thông báo khi truy cập GNOME" : "PASSED"}'
|
|
fi
|
|
|
|
##################################################################################################################
|
|
# Kiểm tra cấu hình dịch vụ TimeSync
|
|
# Logic: Nếu chrony HOẶC ntp pass thì cả 2.1.1 và 2.1.2 đều PASSED
|
|
if [ $(( \
|
|
$(systemctl is-active --quiet chrony 2>/dev/null && echo 1 || echo 0) + \
|
|
$(systemctl is-active --quiet ntp 2>/dev/null && echo 1 || echo 0) + \
|
|
$(systemctl is-active --quiet systemd-timesyncd 2>/dev/null && echo 1 || echo 0) )) -gt 1 ]; then
|
|
|
|
echo '{"2.1.1. Cấu hình sử dụng chrony" : "FAILED"}'
|
|
echo '{"2.1.2. Cấu hình sử dụng NTP" : "FAILED"}'
|
|
echo "######################################"
|
|
echo "# Phát hiện nhiều dịch vụ NTP đang chạy đồng thời:"
|
|
systemctl is-active --quiet chrony 2>/dev/null && echo "chrony: active"
|
|
systemctl is-active --quiet ntp 2>/dev/null && echo "ntp: active"
|
|
systemctl is-active --quiet systemd-timesyncd 2>/dev/null && echo "systemd-timesyncd: active"
|
|
echo "# Khuyến nghị: chỉ giữ lại 1 dịch vụ."
|
|
echo "######################################"
|
|
|
|
elif systemctl is-active --quiet chrony 2>/dev/null; then
|
|
if grep -Eq '^\s*(server|pool)\s+\S+' /etc/chrony/chrony.conf 2>/dev/null; then
|
|
# Chrony pass -> cả 2 đều PASSED
|
|
echo '{"2.1.1. Cấu hình sử dụng chrony" : "PASSED"}'
|
|
echo '{"2.1.2. Cấu hình sử dụng NTP" : "PASSED"}'
|
|
else
|
|
echo '{"2.1.1. Cấu hình sử dụng chrony" : "FAILED"}'
|
|
echo '{"2.1.2. Cấu hình sử dụng NTP" : "FAILED"}'
|
|
echo "######################################"
|
|
echo "# Dịch vụ active: chrony (thiếu server/pool trong /etc/chrony/chrony.conf)"
|
|
echo "######################################"
|
|
fi
|
|
|
|
elif systemctl is-active --quiet ntp 2>/dev/null; then
|
|
if grep -Eq '^\s*(server|pool)\s+\S+' /etc/ntp.conf 2>/dev/null; then
|
|
# NTP pass -> cả 2 đều PASSED
|
|
echo '{"2.1.1. Cấu hình sử dụng chrony" : "PASSED"}'
|
|
echo '{"2.1.2. Cấu hình sử dụng NTP" : "PASSED"}'
|
|
else
|
|
echo '{"2.1.1. Cấu hình sử dụng chrony" : "FAILED"}'
|
|
echo '{"2.1.2. Cấu hình sử dụng NTP" : "FAILED"}'
|
|
echo "######################################"
|
|
echo "# Dịch vụ active: ntp (thiếu server/pool trong /etc/ntp.conf)"
|
|
echo "######################################"
|
|
fi
|
|
|
|
#elif systemctl is-active --quiet systemd-timesyncd 2>/dev/null; then
|
|
# if grep -Eq '^\s*(NTP|FallbackNTP)=' /etc/systemd/timesyncd.conf 2>/dev/null \
|
|
# || timedatectl show-timesync 2>/dev/null \
|
|
# | awk -F= '/^(ServerName|ServerAddress)=/ {f=1} END{exit !f}'; then
|
|
# echo '{"2.1.2. Cấu hình sử dụng NTP" : "PASSED"}'
|
|
# else
|
|
# echo '{"2.1.2. Cấu hình sử dụng NTP" : "FAILED"}'
|
|
# echo "######################################"
|
|
# echo "# Dịch vụ active: systemd-timesyncd (chưa thấy NTP/FallbackNTP hay server hiệu lực)"
|
|
# echo "######################################"
|
|
# fi
|
|
|
|
else
|
|
echo '{"2.1.1. Cấu hình sử dụng chrony" : "FAILED"}'
|
|
echo '{"2.1.2. Cấu hình sử dụng NTP" : "FAILED"}'
|
|
echo "######################################"
|
|
echo "# Không có dịch vụ NTP nào đang active (chrony/ntp/systemd-timesyncd)."
|
|
echo "######################################"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện các câu lệnh sau để gỡ bỏ X Window, Avahi Server, CUPS, DHCP Server, LDAP server, NFS, DNS Server, FTP Server, HTTP server, IMAP and POP3 server, Samba, HTTP Proxy Server, SNMP Server, rsync service, NIS Server, telnetd, rsh-server:
|
|
# # X Window
|
|
# apt remove --purge '^xserver-xorg'
|
|
# # Avahi Server
|
|
# systemctl stop avahi-daaemon.service avahi-daemon.socket
|
|
# apt purge avahi-daemon
|
|
# # CUPS
|
|
# apt purge cups
|
|
# # DHCP Server
|
|
# apt purge isc-dhcp-server
|
|
# # LDAP server
|
|
# apt purge slapd
|
|
# # NFS
|
|
# apt purge nfs-kernel-server
|
|
# # DNS Server
|
|
# apt remove --purge '^bind9'
|
|
# # FTP Server
|
|
# apt purge vsftpd
|
|
# # HTTP server
|
|
# apt purge apache2
|
|
# # IMAP and POP3 server
|
|
# apt purge dovecot-imapd-imapd dovecot-imapd-pop3d
|
|
# # Samba
|
|
# apt purge samba
|
|
# # HTTP Proxy Server
|
|
# apt purge squid
|
|
# # SNMP Server
|
|
# apt purge snmp snmpd
|
|
# # NIS server
|
|
# apt purge nis
|
|
# # telnetd
|
|
# apt-get remove telnetd
|
|
# # rsh-server
|
|
# apt-get remove rsh-server
|
|
|
|
######################################
|
|
echo -e "\n######################################"
|
|
if dpkg -l | grep -q xinetd || systemctl is-enabled xinetd.service 2>/dev/null | grep -q '^enabled' || systemctl is-active xinetd.service 2>/dev/null | grep -q '^active'; then
|
|
echo "{\"2.2.1. Cấu hình vô hiệu hoá xinetd services\" : \"FAILED\"}"
|
|
else
|
|
echo "{\"2.2.1. Cấu hình vô hiệu hoá xinetd services\" : \"PASSED\"}"
|
|
fi
|
|
|
|
# Log trạng thái
|
|
if dpkg -l | grep -q xinetd; then
|
|
echo "----------[FAILED]----------";
|
|
else
|
|
echo "----------[PASSED]----------";
|
|
fi
|
|
echo "#dpkg -l | grep xinetd";
|
|
dpkg -l | grep xinetd
|
|
|
|
if systemctl is-enabled xinetd.service 2>/dev/null | grep -q '^enabled'; then
|
|
echo "----------[FAILED]----------";
|
|
else
|
|
echo "----------[PASSED]----------";
|
|
fi
|
|
echo "#systemctl is-enabled xinetd.service";
|
|
systemctl is-enabled xinetd.service 2>/dev/null
|
|
|
|
if systemctl is-active xinetd.service 2>/dev/null | grep -q '^active'; then
|
|
echo "----------[FAILED]----------";
|
|
else
|
|
echo "----------[PASSED]----------";
|
|
fi
|
|
echo "#systemctl is-active xinetd.service";
|
|
systemctl is-active xinetd.service 2>/dev/null
|
|
|
|
echo "----------LOG----------"
|
|
echo "#systemctl is-enabled xinetd.service"; systemctl is-enabled xinetd.service 2>/dev/null
|
|
echo "#systemctl is-active xinetd.service"; systemctl is-active xinetd.service 2>/dev/null
|
|
|
|
###############################################################################################
|
|
|
|
if [ $(dpkg -l | grep "ii xserver-xorg" | wc -l) -ne 0 ]; then
|
|
echo "{\"2.2.3. Cấu hình vô hiệu hoá X window server services\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "Thực hiện câu lệnh sau để gỡ bỏ X Window:
|
|
# apt remove --purge '^xserver-xorg'"
|
|
if [ $(dpkg -l | grep "ii xserver-xorg" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#dpkg -l | grep \"ii xserver-xorg\" -eq 0 ";dpkg -l | grep "ii xserver-xorg"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"2.2.3. Cấu hình vô hiệu hoá X window server services\" : \"PASSED\"}"
|
|
fi
|
|
|
|
######################################
|
|
if [ $(dpkg -l | grep "ii avahi-daemon" | wc -l) -ne 0 ]; then
|
|
echo "{\"2.2.4. Cấu hình vô hiệu hoá avahi daemon services\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "Thực hiện câu lệnh sau để gỡ bỏ Avahi Server:
|
|
# systemctl stop avahi-daaemon.service avahi-daemon.socket
|
|
# apt purge avahi-daemon"
|
|
if [ $(dpkg -l | grep "ii avahi-daemon" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#dpkg -l | grep \"ii avahi-daemon\" -eq 0 ";dpkg -l | grep "ii avahi-daemon"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"2.2.4. Cấu hình vô hiệu hoá avahi daemon services\" : \"PASSED\"}"
|
|
fi
|
|
|
|
######################################
|
|
if [ $(systemctl is-enabled cups 2>/dev/null | grep "enabled" | wc -l) -ne 0 ] || [ $(systemctl is-active cups 2>/dev/null | grep "^active" | wc -l) -ne 0 ]; then
|
|
echo "{\"2.2.5. Cấu hình vô hiệu hoá cups services\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để vô hiệu hoá CUPS services:
|
|
# systemctl stop cups
|
|
# systemctl disable cups
|
|
# systemctl mask cups"
|
|
if [ $(systemctl is-enabled cups 2>/dev/null | grep "enabled" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#systemctl is-enabled cups | grep \"enabled\" -eq 0 ";systemctl is-enabled cups 2>/dev/null | grep "enabled"; fi
|
|
if [ $(systemctl is-active cups 2>/dev/null | grep "^active" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#systemctl is-active cups | grep \"^active\" -eq 0 ";systemctl is-active cups 2>/dev/null | grep "^active"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"2.2.5. Cấu hình vô hiệu hoá cups services\" : \"PASSED\"}"
|
|
fi
|
|
|
|
######################################
|
|
if [ $(dpkg -l | grep "ii isc-dhcp-server" | wc -l) -ne 0 ]; then
|
|
echo "{\"2.2.6. Cấu hình vô hiệu hoá dhcp server services\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để gỡ bỏ DHCP Server:
|
|
# apt purge isc-dhcp-server"
|
|
if [ $(dpkg -l | grep "ii isc-dhcp-server" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#dpkg -l | grep \"ii isc-dhcp-server\" -eq 0 ";dpkg -l | grep "ii isc-dhcp-server"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"2.2.6. Cấu hình vô hiệu hoá dhcp server services\" : \"PASSED\"}"
|
|
fi
|
|
|
|
######################################
|
|
if [ $(dpkg -l | grep "ii slapd" | wc -l) -ne 0 ]; then
|
|
echo "{\"2.2.7. Cấu hình vô hiệu hoá ldap server services\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để gỡ bỏ LDAP server:
|
|
# apt purge slapd"
|
|
if [ $(dpkg -l | grep "ii slapd" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#dpkg -l | grep \"ii slapd\" -eq 0 ";dpkg -l | grep "ii slapd"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"2.2.7. Cấu hình vô hiệu hoá ldap server services\" : \"PASSED\"}"
|
|
fi
|
|
|
|
######################################
|
|
if [ $(dpkg -l | grep "ii nfs-kernel-server" | wc -l) -ne 0 ]; then
|
|
echo "{\"2.2.6. Cấu hình vô hiệu hoá NFS\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để gỡ bỏ NFS:
|
|
# apt purge nfs-kernel-server"
|
|
if [ $(dpkg -l | grep "ii nfs-kernel-server" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#dpkg -l | grep \"ii nfs-kernel-server\" -eq 0 ";dpkg -l | grep "ii nfs-kernel-server"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"2.2.6. Cấu hình vô hiệu hoá NFS\" : \"PASSED\"}"
|
|
fi
|
|
|
|
######################################
|
|
# Script kiểm tra dịch vụ DNS server
|
|
if \
|
|
{ command -v dpkg-query >/dev/null 2>&1 && \
|
|
dpkg-query -W -f='${db:Status-Abbrev} ${Package}\n' \
|
|
bind9 dnsmasq unbound pdns-server pdns-recursor knot knot-resolver coredns 2>/dev/null \
|
|
| awk '$1 ~ /^ii/ {exit 0} END{exit 1}'; } \
|
|
|| { command -v systemctl >/dev/null 2>&1 && \
|
|
systemctl list-unit-files --type=service 2>/dev/null \
|
|
| awk '$1 ~ /^(bind9|dnsmasq|unbound|pdns|pdns-recursor|knot|knot-resolver|coredns)\.service$/ && $2 ~ /enabled|linked/ {exit 0} END{exit 1}'; } \
|
|
|| { command -v systemctl >/dev/null 2>&1 && \
|
|
systemctl list-units --type=service --all 2>/dev/null \
|
|
| grep -E -q '(bind9|dnsmasq|unbound|pdns|pdns-recursor|knot|knot-resolver|coredns)\.service'; } \
|
|
|| { command -v ss >/dev/null 2>&1 && \
|
|
ss -lntup 2>/dev/null \
|
|
| awk '
|
|
$5 ~ /:53$/ {
|
|
addr=$5
|
|
sub(/%[^:]+/, "", addr) # bỏ %lo, %eth0...
|
|
gsub(/^\[|\]$/, "", addr) # bỏ [] IPv6
|
|
split(addr, a, ":"); ip=a[1]
|
|
if (ip != "127.0.0.1" && ip != "127.0.0.53" && ip != "::1" && $0 !~ /systemd-resolve(d)?/) {
|
|
print; found=1
|
|
}
|
|
}
|
|
END { exit !found }
|
|
'; } \
|
|
|| { ! command -v ss >/dev/null 2>&1 && command -v netstat >/dev/null 2>&1 && \
|
|
netstat -lntup 2>/dev/null \
|
|
| awk '
|
|
$4 ~ /:53$/ {
|
|
addr=$4
|
|
sub(/%[^:]+/, "", addr)
|
|
gsub(/^\[|\]$/, "", addr)
|
|
split(addr, a, ":"); ip=a[1]
|
|
if (ip != "127.0.0.1" && ip != "127.0.0.53" && ip != "::1" && $0 !~ /systemd-resolve(d)?/) {
|
|
print; found=1
|
|
}
|
|
}
|
|
END { exit !found }
|
|
'; }
|
|
then
|
|
echo '{"2.2.8. Cấu hình vô hiệu hoá dns server services" : "FAILED"}'
|
|
echo "######################################"
|
|
else
|
|
echo '{"2.2.8. Cấu hình vô hiệu hoá dns server services" : "PASSED"}'
|
|
fi
|
|
|
|
######################################
|
|
echo -e "\n######################################"
|
|
if [[ $(grep -E "\s[7-9].[0-9]" /etc/os-release | wc -l) -ne 0 && $(dpkg-query -l dnsmasq 2>/dev/null | grep '^ii' | wc -l) -ne 0 && ($(systemctl is-enabled dnsmasq.service 2>/dev/null | grep 'enabled' | wc -l) -ne 0 || $(systemctl is-active dnsmasq.service 2>/dev/null | grep '^active' | wc -l) -ne 0) ]]; then
|
|
echo "{\"2.2.9. Cấu hình vô hiệu hoá dnsmasq services\" : \"FAILED\"}"
|
|
else
|
|
echo "{\"2.2.9. Cấu hình vô hiệu hoá dnsmasq services\" : \"PASSED\"}"
|
|
fi
|
|
|
|
# Log
|
|
if grep -E "\s[7-9].[0-9]" /etc/os-release &>/dev/null; then
|
|
echo "----------[FAILED]----------";
|
|
else
|
|
echo "----------[PASSED]----------";
|
|
fi
|
|
echo "#grep -E \"\\s[7-9].[0-9]\" /etc/os-release";
|
|
grep -E "\s[7-9].[0-9]" /etc/os-release
|
|
|
|
if dpkg-query -l dnsmasq 2>/dev/null | grep '^ii' &>/dev/null; then
|
|
echo "----------[FAILED]----------";
|
|
else
|
|
echo "----------[PASSED]----------";
|
|
fi
|
|
echo "#dpkg-query -l dnsmasq";
|
|
dpkg-query -l dnsmasq 2>/dev/null
|
|
|
|
if systemctl is-enabled dnsmasq.service 2>/dev/null | grep 'enabled' &>/dev/null; then
|
|
echo "----------[FAILED]----------";
|
|
else
|
|
echo "----------[PASSED]----------";
|
|
fi
|
|
echo "#systemctl is-enabled dnsmasq.service";
|
|
systemctl is-enabled dnsmasq.service 2>/dev/null
|
|
|
|
if systemctl is-active dnsmasq.service 2>/dev/null | grep '^active' &>/dev/null; then
|
|
echo "----------[FAILED]----------";
|
|
else
|
|
echo "----------[PASSED]----------";
|
|
fi
|
|
echo "#systemctl is-active dnsmasq.service";
|
|
systemctl is-active dnsmasq.service 2>/dev/null
|
|
|
|
echo "----------LOG----------"
|
|
cat /etc/os-release
|
|
|
|
|
|
######################################
|
|
if [ $(dpkg -l | grep "ii vsftpd" | wc -l) -ne 0 ]; then
|
|
echo "{\"2.2.10. Cấu hình vô hiệu hoá ftp server services\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để gỡ bỏ FTP Server:
|
|
# apt purge vsftpd"
|
|
if [ $(dpkg -l | grep "ii vsftpd" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#dpkg -l | grep \"ii vsftpd\" -eq 0 ";dpkg -l | grep "ii vsftpd"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"2.2.10. Cấu hình vô hiệu hoá ftp server services\" : \"PASSED\"}"
|
|
fi
|
|
|
|
######################################
|
|
if [ $(dpkg -l | grep "ii apache2" | wc -l) -ne 0 ]; then
|
|
echo "{\"2.2.12. Cấu hình vô hiệu hoá web server services\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để gỡ bỏ HTTP server:
|
|
# apt purge apache2"
|
|
if [ $(dpkg -l | grep "ii apache2" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#dpkg -l | grep \"ii apache2\" -eq 0 ";dpkg -l | grep "ii apache2"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"2.2.12. Cấu hình vô hiệu hoá web server services\" : \"PASSED\"}"
|
|
fi
|
|
|
|
########################################################
|
|
echo -e "\n######################################"
|
|
if [[ $(grep -E "\s[7-9].[0-9]" /etc/os-release | wc -l) -ne 0 && $(dpkg -l | grep -q "^ii\s*tftpd-hpa") && \
|
|
($(systemctl is-enabled tftp.socket 2>/dev/null | grep 'enabled' &>/dev/null || \
|
|
systemctl is-enabled tftpd-hpa.service 2>/dev/null | grep 'enabled' &>/dev/null || \
|
|
systemctl is-active tftp.socket 2>/dev/null | grep '^active' &>/dev/null || \
|
|
systemctl is-active tftpd-hpa.service 2>/dev/null | grep '^active' &>/dev/null)) ]]; then
|
|
echo "{\"2.2.11. Cấu hình vô hiệu hoá tftp server services\" : \"FAILED\"}"
|
|
else
|
|
echo "{\"2.2.11. Cấu hình vô hiệu hoá tftp server services\" : \"PASSED\"}"
|
|
fi
|
|
|
|
# Log
|
|
if grep -E "\s[7-9].[0-9]" /etc/os-release &>/dev/null; then
|
|
echo "----------[FAILED]----------";
|
|
else
|
|
echo "----------[PASSED]----------";
|
|
fi
|
|
echo "#grep -E \"\\s[7-9].[0-9]\" /etc/os-release";
|
|
grep -E "\s[7-9].[0-9]" /etc/os-release
|
|
|
|
if dpkg -l | grep -q "^ii\s*tftpd-hpa"; then
|
|
echo "----------[FAILED]----------";
|
|
else
|
|
echo "----------[PASSED]----------";
|
|
fi
|
|
echo "#dpkg -l | grep tftpd-hpa";
|
|
dpkg -l | grep tftpd-hpa
|
|
|
|
if systemctl is-enabled tftp.socket 2>/dev/null | grep 'enabled' &>/dev/null; then
|
|
echo "----------[FAILED]----------";
|
|
else
|
|
echo "----------[PASSED]----------";
|
|
fi
|
|
echo "#systemctl is-enabled tftp.socket";
|
|
systemctl is-enabled tftp.socket 2>/dev/null
|
|
|
|
if systemctl is-enabled tftpd-hpa.service 2>/dev/null | grep 'enabled' &>/dev/null; then
|
|
echo "----------[FAILED]----------";
|
|
else
|
|
echo "----------[PASSED]----------";
|
|
fi
|
|
echo "#systemctl is-enabled tftpd-hpa.service";
|
|
systemctl is-enabled tftpd-hpa.service 2>/dev/null
|
|
|
|
if systemctl is-active tftp.socket 2>/dev/null | grep '^active' &>/dev/null; then
|
|
echo "----------[FAILED]----------";
|
|
else
|
|
echo "----------[PASSED]----------";
|
|
fi
|
|
echo "#systemctl is-active tftp.socket";
|
|
systemctl is-active tftp.socket 2>/dev/null
|
|
|
|
if systemctl is-active tftpd-hpa.service 2>/dev/null | grep '^active' &>/dev/null; then
|
|
echo "----------[FAILED]----------";
|
|
else
|
|
echo "----------[PASSED]----------";
|
|
fi
|
|
echo "#systemctl is-active tftpd-hpa.service";
|
|
systemctl is-active tftpd-hpa.service 2>/dev/null
|
|
|
|
echo "----------LOG----------"
|
|
|
|
|
|
######################################
|
|
if [ $(dpkg -l | grep "ii dovecot-imapd" | wc -l) -ne 0 ] || [ $(dpkg -l | grep "ii dovecot-pop3d" | wc -l) -ne 0 ]; then
|
|
echo "{\"2.2.13. Cấu hình vô hiệu hoá imap and pop3 server services\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để gỡ bỏ IMAP and POP3 Server:
|
|
# yum remove dovecot-imapd dovecot-pop3d"
|
|
if [ $(dpkg -l | grep "ii dovecot-imapd" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#dpkg -l | grep \"ii dovecot-imapd\" -eq 0 ";dpkg -l | grep "ii dovecot-imapd"; fi
|
|
if [ $(dpkg -l | grep "ii dovecot-pop3d" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#dpkg -l | grep \"ii dovecot-pop3d\" -eq 0 ";dpkg -l | grep "ii dovecot-pop3d"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"2.2.13. Cấu hình vô hiệu hoá imap and pop3 server services\" : \"PASSED\"}"
|
|
fi
|
|
|
|
######################################
|
|
if [ $(systemctl is-enabled smbd 2>/dev/null | grep "enabled" | wc -l) -ne 0 ] || [ $(systemctl is-active smbd 2>/dev/null | grep "^active" | wc -l) -ne 0 ] || [ $(systemctl is-enabled nmbd 2>/dev/null | grep "enabled" | wc -l) -ne 0 ] || [ $(systemctl is-active nmbd 2>/dev/null | grep "^active" | wc -l) -ne 0 ]; then
|
|
echo "{\"2.2.14. Cấu hình vô hiệu hoá samba file server services\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để vô hiệu hoá Samba services:
|
|
# systemctl stop smbd nmbd
|
|
# systemctl disable smbd nmbd
|
|
# systemctl mask smbd nmbd"
|
|
if [ $(systemctl is-enabled smbd 2>/dev/null | grep "enabled" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#systemctl is-enabled smbd | grep \"enabled\" -eq 0 ";systemctl is-enabled smbd 2>/dev/null | grep "enabled"; fi
|
|
if [ $(systemctl is-active smbd 2>/dev/null | grep "^active" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#systemctl is-active smbd | grep \"^active\" -eq 0 ";systemctl is-active smbd 2>/dev/null | grep "^active"; fi
|
|
if [ $(systemctl is-enabled nmbd 2>/dev/null | grep "enabled" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#systemctl is-enabled nmbd | grep \"enabled\" -eq 0 ";systemctl is-enabled nmbd 2>/dev/null | grep "enabled"; fi
|
|
if [ $(systemctl is-active nmbd 2>/dev/null | grep "^active" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#systemctl is-active nmbd | grep \"^active\" -eq 0 ";systemctl is-active nmbd 2>/dev/null | grep "^active"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"2.2.14. Cấu hình vô hiệu hoá samba file server services\" : \"PASSED\"}"
|
|
fi
|
|
|
|
######################################
|
|
if [ $(dpkg -l | grep "ii squid" | wc -l) -ne 0 ]; then
|
|
echo "{\"2.2.15. Cấu hình vô hiệu hoá web proxy server services\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để gỡ bỏ HTTP Proxy Server:
|
|
# apt purge squid"
|
|
if [ $(dpkg -l | grep "ii squid" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#dpkg -l | grep \"ii squid\" -eq 0 ";dpkg -l | grep "ii squid"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"2.2.15. Cấu hình vô hiệu hoá web proxy server services\" : \"PASSED\"}"
|
|
fi
|
|
|
|
######################################
|
|
if [ $(dpkg -l | grep "ii snmp" | wc -l) -ne 0 ] || [ $(dpkg -l | grep "ii snmpd" | wc -l) -ne 0 ]; then
|
|
echo "{\"2.2.16. Cấu hình vô hiệu hoá snmp services\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để gỡ bỏ SNMP Server:
|
|
# apt purge snmp snmpd"
|
|
if [ $(dpkg -l | grep "ii snmp" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#dpkg -l | grep \"ii snmp\" -eq 0 ";dpkg -l | grep "ii snmp"; fi
|
|
if [ $(dpkg -l | grep "ii snmpd" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#dpkg -l | grep \"ii snmpd\" -eq 0 ";dpkg -l | grep "ii snmpd"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"2.2.16. Cấu hình vô hiệu hoá snmp services\" : \"PASSED\"}"
|
|
fi
|
|
|
|
######################################
|
|
if [ $(dpkg -l | grep "ii telnetd" | wc -l) -ne 0 ]; then
|
|
echo "{\"2.2.14. Cấu hình vô hiệu hoá telnetd\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để gỡ bỏ telnetd:
|
|
# apt-get remove telnetd"
|
|
if [ $(dpkg -l | grep "ii telnetd" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#dpkg -l | grep \"ii telnetd\" -eq 0 ";dpkg -l | grep "ii telnetd"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"2.2.14. Cấu hình vô hiệu hoá telnetd\" : \"PASSED\"}"
|
|
fi
|
|
|
|
######################################
|
|
if [ $(dpkg -l | grep "ii rsh-server" | wc -l) -ne 0 ]; then
|
|
echo "{\"2.2.15. Cấu hình vô hiệu hoá rsh-server\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để gỡ bỏ rsh-server:
|
|
# yum remove rsh-server"
|
|
if [ $(dpkg -l | grep "ii rsh-server" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#dpkg -l | grep \"ii rsh-server\" -eq 0 ";dpkg -l | grep "ii rsh-server"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"2.2.15. Cấu hình vô hiệu hoá rsh-server\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Chỉnh sửa /etc/postfix/main.cf và thêm các dòng sau vào phần RECEIVING MAIL. Nếu dòng đó đã tồn tại, thay đổi nó để giống như dưới đây:
|
|
# inet_interfaces = loopback-only
|
|
# Thực hiện câu lệnh sau để khởi động lại postfix:
|
|
# systemctl restart postfix
|
|
if [ $(ss -lntu | grep -E ':25\s' | grep -E -v '\s(127.0.0.1|\[?::1\]?):25\s' | wc -l) -ne 0 ]; then
|
|
echo "{\"2.2.18. Cấu hình mail transfer agents sang chế độ local-only\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Chỉnh sửa /etc/postfix/main.cf và thêm các dòng sau vào phần RECEIVING MAIL. Nếu dòng đó đã tồn tại, thay đổi nó để giống như dưới đây:
|
|
# inet_interfaces = loopback-only
|
|
# Thực hiện câu lệnh sau để khởi động lại postfix:
|
|
# systemctl restart postfix"
|
|
if [ $(ss -lntu | grep -E ':25\s' | grep -E -v '\s(127.0.0.1|\[?::1\]?):25\s' | wc -l) -ne 0 ]; then echo "-------------------"; echo "#ss -lntu | grep -E ':25\s' | grep -E -v '\s(127.0.0.1|\[?::1\]?):25\s' -eq 0 ";ss -lntu | grep -E ':25\s' | grep -E -v '\s(127.0.0.1|\[?::1\]?):25\s'; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"2.2.18. Cấu hình mail transfer agents sang chế độ local-only\" : \"PASSED\"}"
|
|
fi
|
|
|
|
##################################################################################################################
|
|
echo -e "\n######################################"
|
|
if dpkg -l | grep -q ypserv && \
|
|
(systemctl is-enabled ypserv.service 2>/dev/null | grep -q 'enabled' || \
|
|
systemctl is-active ypserv.service 2>/dev/null | grep -q '^active'); then
|
|
echo "{\"2.2.17. Cấu hình vô hiệu hoá nis server services\" : \"FAILED\"}"
|
|
else
|
|
echo "{\"2.2.17. Cấu hình vô hiệu hoá nis server services\" : \"PASSED\"}"
|
|
fi
|
|
|
|
# Log
|
|
if dpkg -l | grep -q ypserv; then
|
|
echo "----------[FAILED]----------";
|
|
else
|
|
echo "----------[PASSED]----------";
|
|
fi
|
|
echo "#dpkg -l | grep ypserv";
|
|
dpkg -l | grep ypserv
|
|
|
|
if systemctl is-enabled ypserv.service 2>/dev/null | grep -q 'enabled'; then
|
|
echo "----------[FAILED]----------";
|
|
else
|
|
echo "----------[PASSED]----------";
|
|
fi
|
|
echo "#systemctl is-enabled ypserv.service";
|
|
systemctl is-enabled ypserv.service 2>/dev/null
|
|
|
|
if systemctl is-active ypserv.service 2>/dev/null | grep -q '^active'; then
|
|
echo "----------[FAILED]----------";
|
|
else
|
|
echo "----------[PASSED]----------";
|
|
fi
|
|
echo "#systemctl is-active ypserv.service";
|
|
systemctl is-active ypserv.service 2>/dev/null
|
|
|
|
echo "----------LOG----------"
|
|
echo "#systemctl is-enabled ypserv.service"; systemctl is-enabled ypserv.service 2>/dev/null
|
|
echo "#systemctl is-active ypserv.service"; systemctl is-active ypserv.service 2>/dev/null
|
|
|
|
############################################################################
|
|
echo -e "\n######################################"
|
|
if dpkg -l | grep -q nfs-kernel-server && \
|
|
(systemctl is-enabled nfs-server.service 2>/dev/null | grep -q 'enabled' || \
|
|
systemctl is-active nfs-server.service 2>/dev/null | grep -q '^active'); then
|
|
echo "{\"2.2.19. Cấu hình vô hiệu hoá network file system services\" : \"FAILED\"}"
|
|
else
|
|
echo "{\"2.2.19. Cấu hình vô hiệu hoá network file system services\" : \"PASSED\"}"
|
|
fi
|
|
|
|
# Log
|
|
if dpkg -l | grep -q nfs-kernel-server; then
|
|
echo "----------[FAILED]----------";
|
|
else
|
|
echo "----------[PASSED]----------";
|
|
fi
|
|
echo "#dpkg -l | grep nfs-kernel-server";
|
|
dpkg -l | grep nfs-kernel-server
|
|
|
|
if systemctl is-enabled nfs-server.service 2>/dev/null | grep -q 'enabled'; then
|
|
echo "----------[FAILED]----------";
|
|
else
|
|
echo "----------[PASSED]----------";
|
|
fi
|
|
echo "#systemctl is-enabled nfs-server.service";
|
|
systemctl is-enabled nfs-server.service 2>/dev/null
|
|
|
|
if systemctl is-active nfs-server.service 2>/dev/null | grep -q '^active'; then
|
|
echo "----------[FAILED]----------";
|
|
else
|
|
echo "----------[PASSED]----------";
|
|
fi
|
|
echo "#systemctl is-active nfs-server.service";
|
|
systemctl is-active nfs-server.service 2>/dev/null
|
|
|
|
echo "----------LOG----------"
|
|
echo "#systemctl is-enabled nfs-server.service"; systemctl is-enabled nfs-server.service 2>/dev/null
|
|
echo "#systemctl is-active nfs-server.service"; systemctl is-active nfs-server.service 2>/dev/null
|
|
|
|
|
|
############################################################################
|
|
# Thực hiện câu lệnh sau để vô hiệu hoá rsync services:
|
|
# systemctl stop rsync
|
|
# systemctl disable rsync
|
|
# systemctl mask rsync
|
|
if [ $(systemctl is-enabled rsync 2>/dev/null | grep "enabled" | wc -l) -ne 0 ] || [ $(systemctl is-active rsync 2>/dev/null | grep "^active" | wc -l) -ne 0 ]; then
|
|
echo "{\"2.2.20. Cấu hình vô hiệu hoá rsync services\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để vô hiệu hoá rsync services:
|
|
# systemctl stop rsync
|
|
# systemctl disable rsync
|
|
# systemctl mask rsync"
|
|
if [ $(systemctl is-enabled rsync 2>/dev/null | grep "enabled" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#systemctl is-enabled rsync | grep \"enabled\" -eq 0 ";systemctl is-enabled rsync 2>/dev/null | grep "enabled"; fi
|
|
if [ $(systemctl is-active rsync 2>/dev/null | grep "^active" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#systemctl is-active rsync | grep \"^active\" -eq 0 ";systemctl is-active rsync 2>/dev/null | grep "^active"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"2.2.20. Cấu hình vô hiệu hoá rsync services\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện các câu lệnh sau để gỡ bỏ NIS Client, rsh client, talk client, telnet client, LDAP client, RPC:
|
|
# # NIS Client
|
|
# apt purge nis
|
|
# # rsh client
|
|
# apt purge rsh-client
|
|
# # talk client
|
|
# apt purge talk
|
|
# # telnet client
|
|
# apt purge telnet
|
|
# # LDAP client
|
|
# apt purge ldap-utils
|
|
# # RPC
|
|
# apt purge rpcbind
|
|
|
|
######################################
|
|
if [ $(dpkg -l | grep "ii nis" | wc -l) -ne 0 ]; then
|
|
echo "{\"2.3.1. Cấu hình vô hiệu hoá nis client\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để gỡ bỏ NIS Client:
|
|
# apt purge nis"
|
|
if [ $(dpkg -l | grep "ii nis" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#dpkg -l | grep \"ii nis\" -eq 0 ";dpkg -l | grep "ii nis"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"2.3.1. Cấu hình vô hiệu hoá nis client\" : \"PASSED\"}"
|
|
fi
|
|
|
|
######################################
|
|
if [ $(dpkg -l | grep "ii rsh-client" | wc -l) -ne 0 ]; then
|
|
echo "{\"2.3.2. Cấu hình vô hiệu hoá rsh client\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để gỡ bỏ rsh client:
|
|
# apt purge rsh-client"
|
|
if [ $(dpkg -l | grep "ii rsh-client" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#dpkg -l | grep \"ii rsh-client\" -eq 0 ";dpkg -l | grep "ii rsh-client"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"2.3.2. Cấu hình vô hiệu hoá rsh client\" : \"PASSED\"}"
|
|
fi
|
|
|
|
######################################
|
|
if [ $(dpkg -l | grep "ii talk" | wc -l) -ne 0 ]; then
|
|
echo "{\"2.3.3. Cấu hình vô hiệu hoá talk client\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để gỡ bỏ talk client:
|
|
# apt purge talk"
|
|
if [ $(dpkg -l | grep "ii talk" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#dpkg -l | grep \"ii talk\" -eq 0 ";dpkg -l | grep "ii talk"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"2.3.3. Cấu hình vô hiệu hoá talk client\" : \"PASSED\"}"
|
|
fi
|
|
|
|
######################################
|
|
if [ $(dpkg -l | grep "ii telnet" | wc -l) -ne 0 ]; then
|
|
echo "{\"2.3.4. Cấu hình vô hiệu hoá telnet client\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để gỡ bỏ telnet client:
|
|
# apt purge telnet"
|
|
if [ $(dpkg -l | grep "ii telnet" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#dpkg -l | grep \"ii telnet\" -eq 0 ";dpkg -l | grep "ii telnet"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"2.3.4. Cấu hình vô hiệu hoá telnet client\" : \"PASSED\"}"
|
|
fi
|
|
|
|
######################################
|
|
if [ $(dpkg -l | grep "ii ldap-utils" | wc -l) -ne 0 ]; then
|
|
echo "{\"2.3.5. Cấu hình vô hiệu hoá ldap client\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để gỡ bỏ LDAP client:
|
|
# apt purge ldap-utils"
|
|
if [ $(dpkg -l | grep "ii ldap-utils" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#dpkg -l | grep \"ii ldap-utils\" -eq 0 ";dpkg -l | grep "ii ldap-utils"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"2.3.5. Cấu hình vô hiệu hoá ldap client\" : \"PASSED\"}"
|
|
fi
|
|
|
|
######################################
|
|
if [ $(dpkg -l | grep "ii rpcbind" | wc -l) -ne 0 ]; then
|
|
echo "{\"2.3.6. Cấu hình vô hiệu hoá rpc\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để gỡ bỏ RPC:
|
|
# apt purge rpcbind"
|
|
if [ $(dpkg -l | grep "ii rpcbind" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#dpkg -l | grep \"ii rpcbind\" -eq 0 ";dpkg -l | grep "ii rpcbind"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"2.3.6. Cấu hình vô hiệu hoá rpc\" : \"PASSED\"}"
|
|
fi
|
|
|
|
##################################################################################################################
|
|
# echo -e "\n######################################"
|
|
if [[ $(grep -E "\s[7-9].[0-9]" /etc/os-release | wc -l) -ne 0 && $(dpkg -l | grep -q "^ii\sftp") ]]; then
|
|
echo "{\"2.3.7. Cấu hình vô hiệu hoá ftp client\" : \"FAILED\"}"
|
|
else
|
|
echo "{\"2.3.7. Cấu hình vô hiệu hoá ftp client\" : \"PASSED\"}"
|
|
fi
|
|
|
|
# Log
|
|
if grep -E "\s[7-9].[0-9]" /etc/os-release &>/dev/null; then
|
|
echo "----------[FAILED]----------";
|
|
else
|
|
echo "----------[PASSED]----------";
|
|
fi
|
|
echo "#grep -E \"\\s[7-9].[0-9]\" /etc/os-release";
|
|
grep -E "\s[7-9].[0-9]" /etc/os-release
|
|
|
|
if dpkg -l | grep -q "^ii\sftp"; then
|
|
echo "----------[FAILED]----------";
|
|
else
|
|
echo "----------[PASSED]----------";
|
|
fi
|
|
echo "#dpkg -l | grep ftp";
|
|
dpkg -l | grep ftp
|
|
|
|
echo "----------LOG----------"
|
|
|
|
|
|
##################################################################################################################
|
|
# IPv6
|
|
output=""; grubfile=$(find /boot -type f \( -name 'grubenv' -o -name 'grub.conf' -o -name 'grub.cfg' \) -exec grep -Pl -- '^\h*(kernelopts=|linux|kernel)' {} \;); searchloc="/run/sysctl.d/*.conf /etc/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /lib/sysctl.d/*.conf /etc/sysctl.conf"; if [ -s "$grubfile" ]; then ! grep -P -- "^\h*(kernelopts=|linux|kernel)" "$grubfile" | grep -vq -- ipv6.disable=1 && output="disabled"; fi; if grep -Pqs -- "^\h*net\.ipv6\.conf\.all\.disable_ipv6\h*=\h*1\h*(#.*)?$" $searchloc && \ grep -Pqs -- "^\h*net\.ipv6\.conf\.default\.disable_ipv6\h*=\h*1\h*(#.*)?$" $searchloc && \ sysctl net.ipv6.conf.all.disable_ipv6 | grep -Pqs -- "^\h*net\.ipv6\.conf\.all\.disable_ipv6\h*=\h*1\h*(#.*)?$" && \ sysctl net.ipv6.conf.default.disable_ipv6 | grep -Pqs -- "^\h*net\.ipv6\.conf\.default\.disable_ipv6\h*=\h*1\h*(#.*)?$"; then [ -n "$output" ] || output="disabled"; fi; [ -n "$output" ] || output="enabled";
|
|
echo -e "\n######################################"
|
|
# Check IPv4 forwarding (luôn check)
|
|
ipv4_forward_fail=0
|
|
if [[ $(sysctl net.ipv4.ip_forward 2>/dev/null | grep "0" | wc -l) -eq 0 \
|
|
|| $(grep -Ps "^\h*net\.ipv4\.ip_forward\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -eq 0 \
|
|
|| $(grep -Ps "^\h*net\.ipv4\.ip_forward\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -ne 0 ]]; then
|
|
ipv4_forward_fail=1
|
|
fi
|
|
|
|
# Check IPv6 forwarding (chỉ khi IPv6 enabled)
|
|
ipv6_forward_fail=0
|
|
if [ "$IPV6_ENABLED" -eq 1 ]; then
|
|
if [[ $(sysctl net.ipv6.conf.all.forwarding 2>/dev/null | grep "0" | wc -l) -eq 0 \
|
|
|| $(grep -Ps "^\h*net\.ipv6\.conf\.all\.forwarding\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -eq 0 \
|
|
|| $(grep -Ps "^\h*net\.ipv6\.conf\.all\.forwarding\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -ne 0 ]]; then
|
|
ipv6_forward_fail=1
|
|
fi
|
|
fi
|
|
|
|
# Kết luận: FAIL nếu IPv4 fail HOẶC (IPv6 enabled VÀ IPv6 fail)
|
|
if [ $ipv4_forward_fail -eq 1 ] || [ $ipv6_forward_fail -eq 1 ]; then
|
|
echo "{\"3.1.1. Cấu hình vô hiệu hoá IP forwarding\" : \"FAILED\"}"
|
|
else
|
|
echo "{\"3.1.1. Cấu hình vô hiệu hoá IP forwarding\" : \"PASSED\"}"
|
|
fi
|
|
# # Log
|
|
# if [ $(sysctl net.ipv4.ip_forward 2>/dev/null | grep "0" | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#sysctl net.ipv4.ip_forward 2>/dev/null | grep \"0\" -ne 0"; sysctl net.ipv4.ip_forward 2>/dev/null | grep "0"
|
|
# if [ $(grep -Ps "^\h*net\.ipv4\.ip_forward\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv4\\.ip_forward\\s*=\\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null -ne 0"; grep -Ps "^\h*net\.ipv4\.ip_forward\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null
|
|
# if [ $(grep -Ps "^\h*net\.ipv4\.ip_forward\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -ne 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv4\\.ip_forward\\s*=\\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null -eq 0"; grep -Ps "^\h*net\.ipv4\.ip_forward\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null
|
|
# if [ $(echo $output | grep "enabled" | wc -l) -ne 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#echo \$output | grep \"enabled\" -eq 0"; echo $output | grep "enabled"
|
|
# if [ $(sysctl net.ipv6.conf.all.forwarding 2>/dev/null | grep "0" | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#sysctl net.ipv6.conf.all.forwarding 2>/dev/null | grep \"0\" -ne 0"; sysctl net.ipv6.conf.all.forwarding 2>/dev/null | grep "0"
|
|
# if [ $(grep -Ps "^\h*net\.ipv6\.conf\.all\.forwarding\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv6\\.conf\\.all\\.forwarding\\s*=\\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null -ne 0"; grep -Ps "^\h*net\.ipv6\.conf\.all\.forwarding\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null
|
|
# if [ $(grep -Ps "^\h*net\.ipv6\.conf\.all\.forwarding\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -ne 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv6\\.conf\\.all\\.forwarding\\s*=\\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null -eq 0"; grep -Ps "^\h*net\.ipv6\.conf\.all\.forwarding\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null
|
|
# echo "----------LOG----------"
|
|
# echo "#sysctl net.ipv4.ip_forward"; sysctl net.ipv4.ip_forward
|
|
# echo "#grep -Ps \"^\\h*net\\.ipv4\\.ip_forward\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf"; grep -Ps "^\h*net\.ipv4\.ip_forward" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# echo "#grep -Ps \"^\\h*net\\.ipv4\\.ip_forward\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf"; grep -Ps "^\h*net\.ipv4\.ip_forward" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# echo "#echo \"IPV6: \$output\""; echo "IPV6: $output"
|
|
# echo "#sysctl net.ipv6.conf.all.forwarding"; sysctl net.ipv6.conf.all.forwarding
|
|
# echo "#grep -Ps \"^\\h*net\\.ipv6\\.conf\\.all\\.forwarding\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf"; grep -Ps "^\h*net\.ipv6\.conf\.all\.forwarding" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# echo "#grep -Ps \"^\\h*net\\.ipv6\\.conf\\.all\\.forwarding\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf"; grep -Ps "^\h*net\.ipv6\.conf\.all\.forwarding" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
|
|
##################################################################################################################
|
|
echo -e "\n######################################"
|
|
if [[ $(sysctl net.ipv4.conf.all.send_redirects | grep "0" | wc -l) -eq 0 || $(grep -Ps "^\h*net\.ipv4\.conf\.all\.send_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 || $(grep -Ps "^\h*net\.ipv4\.conf\.all\.send_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 || $(sysctl net.ipv4.conf.default.send_redirects | grep "0" | wc -l) -eq 0 || $(grep -Ps "^\h*net\.ipv4\.conf\.default\.send_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 || $(grep -Ps "^\h*net\.ipv4\.conf\.default\.send_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]]; then
|
|
echo "{\"3.1.2. Cấu hình vô hiệu hoá tính năng chuyển hướng gói tin (packet redirect)\" : \"FAILED\"}"
|
|
else
|
|
echo "{\"3.1.2. Cấu hình vô hiệu hoá tính năng chuyển hướng gói tin (packet redirect)\" : \"PASSED\"}"
|
|
fi
|
|
# # Log
|
|
# if [ $(sysctl net.ipv4.conf.all.send_redirects | grep "0" | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#sysctl net.ipv4.conf.all.send_redirects | grep \"0\" -ne 0"; sysctl net.ipv4.conf.all.send_redirects | grep "0"
|
|
# if [ $(grep -Ps "^\h*net\.ipv4\.conf\.all\.send_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv4\\.conf\\.all\\.send_redirects\\s*=\\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -ne 0"; grep -Ps "^\h*net\.ipv4\.conf\.all\.send_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# if [ $(grep -Ps "^\h*net\.ipv4\.conf\.all\.send_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv4\\.conf\\.all\\.send_redirects\\s*=\\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -eq 0"; grep -Ps "^\h*net\.ipv4\.conf\.all\.send_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# if [ $(sysctl net.ipv4.conf.default.send_redirects | grep "0" | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#sysctl net.ipv4.conf.default.send_redirects | grep \"0\" -ne 0"; sysctl net.ipv4.conf.default.send_redirects | grep "0"
|
|
# if [ $(grep -Ps "^\h*net\.ipv4\.conf\.default\.send_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv4\\.conf\\.default\\.send_redirects\\s*=\\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -ne 0"; grep -Ps "^\h*net\.ipv4\.conf\.default\.send_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# if [ $(grep -Ps "^\h*net\.ipv4\.conf\.default\.send_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv4\\.conf\\.default\\.send_redirects\\s*=\\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -eq 0"; grep -Ps "^\h*net\.ipv4\.conf\.default\.send_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# echo "----------LOG----------"
|
|
# echo "#sysctl net.ipv4.conf.all.send_redirects"; sysctl net.ipv4.conf.all.send_redirects
|
|
# echo "#grep -Ps \"^\\h*net\\.ipv4\\.conf\\.all\\.send_redirects\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf"; grep -Ps "^\h*net\.ipv4\.conf\.all\.send_redirects" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# echo "#sysctl net.ipv4.conf.default.send_redirects"; sysctl net.ipv4.conf.default.send_redirects
|
|
# echo "#grep -Ps \"^\\h*net\\.ipv4\\.conf\\.default\\.send_redirects\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf"; grep -Ps "^\h*net\.ipv4\.conf\.default\.send_redirects" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
|
|
##################################################################################################################f
|
|
# IPv6
|
|
output=""; grubfile=$(find /boot -type f \( -name 'grubenv' -o -name 'grub.conf' -o -name 'grub.cfg' \) -exec grep -Pl -- '^\h*(kernelopts=|linux|kernel)' {} \;); searchloc="/run/sysctl.d/*.conf /etc/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /lib/sysctl.d/*.conf /etc/sysctl.conf"; if [ -s "$grubfile" ]; then ! grep -P -- "^\h*(kernelopts=|linux|kernel)" "$grubfile" | grep -vq -- ipv6.disable=1 && output="disabled"; fi; if grep -Pqs -- "^\h*net\.ipv6\.conf\.all\.disable_ipv6\h*=\h*1\h*(#.*)?$" $searchloc && \ grep -Pqs -- "^\h*net\.ipv6\.conf\.default\.disable_ipv6\h*=\h*1\h*(#.*)?$" $searchloc && \ sysctl net.ipv6.conf.all.disable_ipv6 | grep -Pqs -- "^\h*net\.ipv6\.conf\.all\.disable_ipv6\h*=\h*1\h*(#.*)?$" && \ sysctl net.ipv6.conf.default.disable_ipv6 | grep -Pqs -- "^\h*net\.ipv6\.conf\.default\.disable_ipv6\h*=\h*1\h*(#.*)?$"; then [ -n "$output" ] || output="disabled"; fi; [ -n "$output" ] || output="enabled";
|
|
echo -e "\n######################################"
|
|
# Check IPv4 accept_source_route (luôn check)
|
|
ipv4_source_route_fail=0
|
|
if [[ $(sysctl net.ipv4.conf.all.accept_source_route 2>/dev/null | grep "0" | wc -l) -eq 0 \
|
|
|| $(grep -Ps "^\h*net\.ipv4\.conf\.all\.accept_source_route\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -eq 0 \
|
|
|| $(grep -Ps "^\h*net\.ipv4\.conf\.all\.accept_source_route\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -ne 0 \
|
|
|| $(sysctl net.ipv4.conf.default.accept_source_route 2>/dev/null | grep "0" | wc -l) -eq 0 \
|
|
|| $(grep -Ps "^\h*net\.ipv4\.conf\.default\.accept_source_route\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -eq 0 \
|
|
|| $(grep -Ps "^\h*net\.ipv4\.conf\.default\.accept_source_route\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -ne 0 ]]; then
|
|
ipv4_source_route_fail=1
|
|
fi
|
|
|
|
# Check IPv6 accept_source_route (chỉ khi IPv6 enabled)
|
|
ipv6_source_route_fail=0
|
|
if [ "$IPV6_ENABLED" -eq 1 ]; then
|
|
if [[ $(sysctl net.ipv6.conf.all.accept_source_route 2>/dev/null | grep "0" | wc -l) -eq 0 \
|
|
|| $(grep -Ps "^\h*net\.ipv6\.conf\.all\.accept_source_route\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -eq 0 \
|
|
|| $(grep -Ps "^\h*net\.ipv6\.conf\.all\.accept_source_route\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -ne 0 \
|
|
|| $(sysctl net.ipv6.conf.default.accept_source_route 2>/dev/null | grep "0" | wc -l) -eq 0 \
|
|
|| $(grep -Ps "^\h*net\.ipv6\.conf\.default\.accept_source_route\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -eq 0 \
|
|
|| $(grep -Ps "^\h*net\.ipv6\.conf\.default\.accept_source_route\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -ne 0 ]]; then
|
|
ipv6_source_route_fail=1
|
|
fi
|
|
fi
|
|
|
|
# Kết luận
|
|
if [ $ipv4_source_route_fail -eq 1 ] || [ $ipv6_source_route_fail -eq 1 ]; then
|
|
echo "{\"3.2.1. Cấu hình từ chối các gói tin với nguồn được định tuyến trước\" : \"FAILED\"}"
|
|
else
|
|
echo "{\"3.2.1. Cấu hình từ chối các gói tin với nguồn được định tuyến trước\" : \"PASSED\"}"
|
|
fi
|
|
# # Log
|
|
# if [ $(sysctl net.ipv4.conf.all.accept_source_route | grep "0" | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#sysctl net.ipv4.conf.all.accept_source_route | grep \"0\" -ne 0"; sysctl net.ipv4.conf.all.accept_source_route | grep "0"
|
|
# if [ $(grep -Ps "^\h*net\.ipv4\.conf\.all\.accept_source_route\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv4\\.conf\\.all\\.accept_source_route\\s*=\\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -ne 0"; grep -Ps "^\h*net\.ipv4\.conf\.all\.accept_source_route\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# if [ $(grep -Ps "^\h*net\.ipv4\.conf\.all\.accept_source_route\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv4\\.conf\\.all\\.accept_source_route\\s*=\\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -eq 0"; grep -Ps "^\h*net\.ipv4\.conf\.all\.accept_source_route\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# if [ $(sysctl net.ipv4.conf.default.accept_source_route | grep "0" | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#sysctl net.ipv4.conf.default.accept_source_route | grep \"0\" -ne 0"; sysctl net.ipv4.conf.default.accept_source_route | grep "0"
|
|
# if [ $(grep -Ps "^\h*net\.ipv4\.conf\.default\.accept_source_route\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv4\\.conf\\.default\\.accept_source_route\\s*=\\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -ne 0"; grep -Ps "^\h*net\.ipv4\.conf\.default\.accept_source_route\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# if [ $(grep -Ps "^\h*net\.ipv4\.conf\.default\.accept_source_route\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv4\\.conf\\.default\\.accept_source_route\\s*=\\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -eq 0"; grep -Ps "^\h*net\.ipv4\.conf\.default\.accept_source_route\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# if [ $(echo $output | grep "enabled" | wc -l) -ne 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#echo \$output | grep \"enabled\" -eq 0"; echo $output | grep "enabled"
|
|
# if [ $(sysctl net.ipv6.conf.all.accept_source_route | grep "0" | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#sysctl net.ipv6.conf.all.accept_source_route | grep \"0\" -ne 0"; sysctl net.ipv6.conf.all.accept_source_route | grep "0"
|
|
# if [ $(grep -Ps "^\h*net\.ipv6\.conf\.all\.accept_source_route\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv6\\.conf\\.all\\.accept_source_route\\s*=\\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -ne 0"; grep -Ps "^\h*net\.ipv6\.conf\.all\.accept_source_route\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# if [ $(grep -Ps "^\h*net\.ipv6\.conf\.all\.accept_source_route\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv6\\.conf\\.all\\.accept_source_route\\s*=\\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -eq 0"; grep -Ps "^\h*net\.ipv6\.conf\.all\.accept_source_route\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# if [ $(sysctl net.ipv6.conf.default.accept_source_route | grep "0" | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#sysctl net.ipv6.conf.default.accept_source_route | grep \"0\" -ne 0"; sysctl net.ipv6.conf.default.accept_source_route | grep "0"
|
|
# if [ $(grep -Ps "^\h*net\.ipv6\.conf\.default\.accept_source_route\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv6\\.conf\\.default\\.accept_source_route\\s*=\\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -ne 0"; grep -Ps "^\h*net\.ipv6\.conf\.default\.accept_source_route\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# if [ $(grep -Ps "^\h*net\.ipv6\.conf\.default\.accept_source_route\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv6\\.conf\\.default\\.accept_source_route\\s*=\\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -eq 0"; grep -Ps "^\h*net\.ipv6\.conf\.default\.accept_source_route\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# echo "----------LOG----------"
|
|
# echo "#sysctl net.ipv4.conf.all.accept_source_route"; sysctl net.ipv4.conf.all.accept_source_route
|
|
# echo "#grep -Ps \"^\\h*net\\.ipv4\\.conf\\.all\\.accept_source_route\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf"; grep -Ps "^\h*net\.ipv4\.conf\.all\.accept_source_route" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# echo "#sysctl net.ipv4.conf.default.accept_source_route"; sysctl net.ipv4.conf.default.accept_source_route
|
|
# echo "#grep -Ps \"^\\h*net\\.ipv4\\.conf\\.default\\.accept_source_route\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf"; grep -Ps "^\h*net\.ipv4\.conf\.default\.accept_source_route" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# echo "#echo \"IPV6: \$output\""; echo "IPV6: $output"
|
|
# echo "#sysctl net.ipv6.conf.all.accept_source_route"; sysctl net.ipv6.conf.all.accept_source_route
|
|
# echo "#grep -Ps \"^\\h*net\\.ipv6\\.conf\\.all\\.accept_source_route\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf"; grep -Ps "^\h*net\.ipv6\.conf\.all\.accept_source_route" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# echo "#sysctl net.ipv6.conf.default.accept_source_route"; sysctl net.ipv6.conf.default.accept_source_route
|
|
# echo "#grep -Ps \"^\\h*net\\.ipv6\\.conf\\.default\\.accept_source_route\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf"; grep -Ps "^\h*net\.ipv6\.conf\.default\.accept_source_route" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
|
|
##################################################################################################################
|
|
# IPv6
|
|
output=""; grubfile=$(find /boot -type f \( -name 'grubenv' -o -name 'grub.conf' -o -name 'grub.cfg' \) -exec grep -Pl -- '^\h*(kernelopts=|linux|kernel)' {} \;); searchloc="/run/sysctl.d/*.conf /etc/sysctl.d/*.conf /usr/local/lib/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /lib/sysctl.d/*.conf /etc/sysctl.conf"; if [ -s "$grubfile" ]; then ! grep -P -- "^\h*(kernelopts=|linux|kernel)" "$grubfile" | grep -vq -- ipv6.disable=1 && output="disabled"; fi; if grep -Pqs -- "^\h*net\.ipv6\.conf\.all\.disable_ipv6\h*=\h*1\h*(#.*)?$" $searchloc && \ grep -Pqs -- "^\h*net\.ipv6\.conf\.default\.disable_ipv6\h*=\h*1\h*(#.*)?$" $searchloc && \ sysctl net.ipv6.conf.all.disable_ipv6 | grep -Pqs -- "^\h*net\.ipv6\.conf\.all\.disable_ipv6\h*=\h*1\h*(#.*)?$" && \ sysctl net.ipv6.conf.default.disable_ipv6 | grep -Pqs -- "^\h*net\.ipv6\.conf\.default\.disable_ipv6\h*=\h*1\h*(#.*)?$"; then [ -n "$output" ] || output="disabled"; fi; [ -n "$output" ] || output="enabled";
|
|
echo -e "\n######################################"
|
|
# Check IPv4 accept_redirects (luôn check)
|
|
ipv4_redirects_fail=0
|
|
if [[ $(sysctl net.ipv4.conf.all.accept_redirects 2>/dev/null | grep "0" | wc -l) -eq 0 \
|
|
|| $(grep -Ps "^\h*net\.ipv4\.conf\.all\.accept_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -eq 0 \
|
|
|| $(grep -Ps "^\h*net\.ipv4\.conf\.all\.accept_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -ne 0 \
|
|
|| $(sysctl net.ipv4.conf.default.accept_redirects 2>/dev/null | grep "0" | wc -l) -eq 0 \
|
|
|| $(grep -Ps "^\h*net\.ipv4\.conf\.default\.accept_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -eq 0 \
|
|
|| $(grep -Ps "^\h*net\.ipv4\.conf\.default\.accept_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -ne 0 ]]; then
|
|
ipv4_redirects_fail=1
|
|
fi
|
|
|
|
# Check IPv6 accept_redirects (chỉ khi IPv6 enabled)
|
|
ipv6_redirects_fail=0
|
|
if [ "$IPV6_ENABLED" -eq 1 ]; then
|
|
if [[ $(sysctl net.ipv6.conf.all.accept_redirects 2>/dev/null | grep "0" | wc -l) -eq 0 \
|
|
|| $(grep -Ps "^\h*net\.ipv6\.conf\.all\.accept_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -eq 0 \
|
|
|| $(grep -Ps "^\h*net\.ipv6\.conf\.all\.accept_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -ne 0 \
|
|
|| $(sysctl net.ipv6.conf.default.accept_redirects 2>/dev/null | grep "0" | wc -l) -eq 0 \
|
|
|| $(grep -Ps "^\h*net\.ipv6\.conf\.default\.accept_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -eq 0 \
|
|
|| $(grep -Ps "^\h*net\.ipv6\.conf\.default\.accept_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -ne 0 ]]; then
|
|
ipv6_redirects_fail=1
|
|
fi
|
|
fi
|
|
|
|
# Kết luận
|
|
if [ $ipv4_redirects_fail -eq 1 ] || [ $ipv6_redirects_fail -eq 1 ]; then
|
|
echo "{\"3.2.2. Cấu hình từ chối các ICMP redirect message\" : \"FAILED\"}"
|
|
else
|
|
echo "{\"3.2.2. Cấu hình từ chối các ICMP redirect message\" : \"PASSED\"}"
|
|
fi
|
|
# # Log
|
|
# if [ $(sysctl net.ipv4.conf.all.accept_redirects | grep "0" | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#sysctl net.ipv4.conf.all.accept_redirects | grep \"0\" -ne 0"; sysctl net.ipv4.conf.all.accept_redirects | grep "0"
|
|
# if [ $(grep -Ps "^\h*net\.ipv4\.conf\.all\.accept_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv4\\.conf\\.all\\.accept_redirects\\s*=\\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -ne 0"; grep -Ps "^\h*net\.ipv4\.conf\.all\.accept_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# if [ $(grep -Ps "^\h*net\.ipv4\.conf\.all\.accept_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv4\\.conf\\.all\\.accept_redirects\\s*=\\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -eq 0"; grep -Ps "^\h*net\.ipv4\.conf\.all\.accept_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# if [ $(sysctl net.ipv4.conf.default.accept_redirects | grep "0" | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#sysctl net.ipv4.conf.default.accept_redirects | grep \"0\" -ne 0"; sysctl net.ipv4.conf.default.accept_redirects | grep "0"
|
|
# if [ $(grep -Ps "^\h*net\.ipv4\.conf\.default\.accept_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv4\\.conf\\.default\\.accept_redirects\\s*=\\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -ne 0"; grep -Ps "^\h*net\.ipv4\.conf\.default\.accept_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# if [ $(grep -Ps "^\h*net\.ipv4\.conf\.default\.accept_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv4\\.conf\\.default\\.accept_redirects\\s*=\\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -eq 0"; grep -Ps "^\h*net\.ipv4\.conf\.default\.accept_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# if [ $(echo $output | grep "enabled" | wc -l) -ne 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#echo \$output | grep \"enabled\" -eq 0"; echo $output | grep "enabled"
|
|
# if [ $(sysctl net.ipv6.conf.all.accept_redirects | grep "0" | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#sysctl net.ipv6.conf.all.accept_redirects | grep \"0\" -ne 0"; sysctl net.ipv6.conf.all.accept_redirects | grep "0"
|
|
# if [ $(grep -Ps "^\h*net\.ipv6\.conf\.all\.accept_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv6\\.conf\\.all\\.accept_redirects\\s*=\\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -ne 0"; grep -Ps "^\h*net\.ipv6\.conf\.all\.accept_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# if [ $(grep -Ps "^\h*net\.ipv6\.conf\.all\.accept_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv6\\.conf\\.all\\.accept_redirects\\s*=\\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -eq 0"; grep -Ps "^\h*net\.ipv6\.conf\.all\.accept_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# if [ $(sysctl net.ipv6.conf.default.accept_redirects | grep "0" | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#sysctl net.ipv6.conf.default.accept_redirects | grep \"0\" -ne 0"; sysctl net.ipv6.conf.default.accept_redirects | grep "0"
|
|
# if [ $(grep -Ps "^\h*net\.ipv6\.conf\.default\.accept_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv6\\.conf\\.default\\.accept_redirects\\s*=\\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -ne 0"; grep -Ps "^\h*net\.ipv6\.conf\.default\.accept_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# if [ $(grep -Ps "^\h*net\.ipv6\.conf\.default\.accept_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv6\\.conf\\.default\\.accept_redirects\\s*=\\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -eq 0"; grep -Ps "^\h*net\.ipv6\.conf\.default\.accept_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# echo "----------LOG----------"
|
|
# echo "#sysctl net.ipv4.conf.all.accept_redirects"; sysctl net.ipv4.conf.all.accept_redirects
|
|
# echo "#grep -Ps \"^\\h*net\\.ipv4\\.conf\\.all\\.accept_redirects\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf"; grep -Ps "^\h*net\.ipv4\.conf\.all\.accept_redirects" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# echo "#sysctl net.ipv4.conf.default.accept_redirects"; sysctl net.ipv4.conf.default.accept_redirects
|
|
# echo "#grep -Ps \"^\\h*net\\.ipv4\\.conf\\.default\\.accept_redirects\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf"; grep -Ps "^\h*net\.ipv4\.conf\.default\.accept_redirects" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# echo "#echo \"IPV6: \$output\""; echo "IPV6: $output"
|
|
# echo "#sysctl net.ipv6.conf.all.accept_redirects"; sysctl net.ipv6.conf.all.accept_redirects
|
|
# echo "#grep -Ps \"^\\h*net\\.ipv6\\.conf\\.all\\.accept_redirects\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf"; grep -Ps "^\h*net\.ipv6\.conf\.all\.accept_redirects" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# echo "#sysctl net.ipv6.conf.default.accept_redirects"; sysctl net.ipv6.conf.default.accept_redirects
|
|
# echo "#grep -Ps \"^\\h*net\\.ipv6\\.conf\\.default\\.accept_redirects\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf"; grep -Ps "^\h*net\.ipv6\.conf\.default\.accept_redirects" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
|
|
##################################################################################################################
|
|
echo -e "\n######################################"
|
|
if [[ $(sysctl net.ipv4.conf.all.secure_redirects | grep "0" | wc -l) -eq 0 || $(grep -Ps "^\h*net\.ipv4\.conf\.all\.secure_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 || $(grep -Ps "^\h*net\.ipv4\.conf\.all\.secure_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 || $(sysctl net.ipv4.conf.default.secure_redirects | grep "0" | wc -l) -eq 0 || $(grep -Ps "^\h*net\.ipv4\.conf\.default\.secure_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 || $(grep -Ps "^\h*net\.ipv4\.conf\.default\.secure_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]]; then
|
|
echo "{\"3.2.3. Cấu hình từ chối các secure ICMP redirect message\" : \"FAILED\"}"
|
|
else
|
|
echo "{\"3.2.3. Cấu hình từ chối các secure ICMP redirect message\" : \"PASSED\"}"
|
|
fi
|
|
# # Log
|
|
# if [ $(sysctl net.ipv4.conf.all.secure_redirects | grep "0" | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#sysctl net.ipv4.conf.all.secure_redirects | grep \"0\" -ne 0"; sysctl net.ipv4.conf.all.secure_redirects | grep "0"
|
|
# if [ $(grep -Ps "^\h*net\.ipv4\.conf\.all\.secure_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv4\\.conf\\.all\\.secure_redirects\\s*=\\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -ne 0"; grep -Ps "^\h*net\.ipv4\.conf\.all\.secure_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# if [ $(grep -Ps "^\h*net\.ipv4\.conf\.all\.secure_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv4\\.conf\\.all\\.secure_redirects\\s*=\\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -eq 0"; grep -Ps "^\h*net\.ipv4\.conf\.all\.secure_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# if [ $(sysctl net.ipv4.conf.default.secure_redirects | grep "0" | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#sysctl net.ipv4.conf.default.secure_redirects | grep \"0\" -ne 0"; sysctl net.ipv4.conf.default.secure_redirects | grep "0"
|
|
# if [ $(grep -Ps "^\h*net\.ipv4\.conf\.default\.secure_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv4\\.conf\\.default\\.secure_redirects\\s*=\\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -ne 0"; grep -Ps "^\h*net\.ipv4\.conf\.default\.secure_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# if [ $(grep -Ps "^\h*net\.ipv4\.conf\.default\.secure_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv4\\.conf\\.default\\.secure_redirects\\s*=\\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -eq 0"; grep -Ps "^\h*net\.ipv4\.conf\.default\.secure_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# echo "----------LOG----------"
|
|
# echo "#sysctl net.ipv4.conf.all.secure_redirects"; sysctl net.ipv4.conf.all.secure_redirects
|
|
# echo "#grep -Ps \"^\\h*net\\.ipv4\\.conf\\.all\\.secure_redirects\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf"; grep -Ps "^\h*net\.ipv4\.conf\.all\.secure_redirects" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# echo "#sysctl net.ipv4.conf.default.secure_redirects"; sysctl net.ipv4.conf.default.secure_redirects
|
|
# echo "#grep -Ps \"^\\h*net\\.ipv4\\.conf\\.default\\.secure_redirects\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf"; grep -Ps "^\h*net\.ipv4\.conf\.default\.secure_redirects" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
|
|
##################################################################################################################
|
|
echo -e "\n######################################"
|
|
if [[ $(sysctl net.ipv4.icmp_echo_ignore_broadcasts | grep "1" | wc -l) -eq 0 || $(grep -Ps "^\h*net\.ipv4\.icmp_echo_ignore_broadcasts\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 || $(grep -Ps "^\h*net\.ipv4\.icmp_echo_ignore_broadcasts\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]]; then
|
|
echo "{\"3.2.4. Cấu hình từ chối các gói tin ICMP request broadcast\" : \"FAILED\"}"
|
|
else
|
|
echo "{\"3.2.4. Cấu hình từ chối các gói tin ICMP request broadcast\" : \"PASSED\"}"
|
|
fi
|
|
# # Log
|
|
# if [ $(sysctl net.ipv4.icmp_echo_ignore_broadcasts | grep "1" | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#sysctl net.ipv4.icmp_echo_ignore_broadcasts | grep \"1\" -ne 0"; sysctl net.ipv4.icmp_echo_ignore_broadcasts | grep "1"
|
|
# if [ $(grep -Ps "^\h*net\.ipv4\.icmp_echo_ignore_broadcasts\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv4\\.icmp_echo_ignore_broadcasts\\s*=\\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -ne 0"; grep -Ps "^\h*net\.ipv4\.icmp_echo_ignore_broadcasts\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# if [ $(grep -Ps "^\h*net\.ipv4\.icmp_echo_ignore_broadcasts\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv4\\.icmp_echo_ignore_broadcasts\\s*=\\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -eq 0"; grep -Ps "^\h*net\.ipv4\.icmp_echo_ignore_broadcasts\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# echo "----------LOG----------"
|
|
# echo "#sysctl net.ipv4.icmp_echo_ignore_broadcasts"; sysctl net.ipv4.icmp_echo_ignore_broadcasts
|
|
# echo "#grep -Ps \"^\\h*net\\.ipv4\\.icmp_echo_ignore_broadcasts\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf"; grep -Ps "^\h*net\.ipv4\.icmp_echo_ignore_broadcasts" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
|
|
##################################################################################################################
|
|
echo -e "\n######################################"
|
|
if [[ $(sysctl net.ipv4.icmp_ignore_bogus_error_responses | grep "1" | wc -l) -eq 0 || $(grep -Ps "^\h*net\.ipv4\.icmp_ignore_bogus_error_responses\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 || $(grep -Ps "^\h*net\.ipv4\.icmp_ignore_bogus_error_responses\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]]; then
|
|
echo "{\"3.2.5. Cấu hình bỏ qua phản hồi ICMP không hợp lệ\" : \"FAILED\"}"
|
|
else
|
|
echo "{\"3.2.5. Cấu hình bỏ qua phản hồi ICMP không hợp lệ\" : \"PASSED\"}"
|
|
fi
|
|
# # Log
|
|
# if [ $(sysctl net.ipv4.icmp_ignore_bogus_error_responses | grep "1" | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#sysctl net.ipv4.icmp_ignore_bogus_error_responses | grep \"1\" -ne 0"; sysctl net.ipv4.icmp_ignore_bogus_error_responses | grep "1"
|
|
# if [ $(grep -Ps "^\h*net\.ipv4\.icmp_ignore_bogus_error_responses\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv4\\.icmp_ignore_bogus_error_responses\\s*=\\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -ne 0"; grep -Ps "^\h*net\.ipv4\.icmp_ignore_bogus_error_responses\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# if [ $(grep -Ps "^\h*net\.ipv4\.icmp_ignore_bogus_error_responses\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv4\\.icmp_ignore_bogus_error_responses\\s*=\\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -eq 0"; grep -Ps "^\h*net\.ipv4\.icmp_ignore_bogus_error_responses\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# echo "----------LOG----------"
|
|
# echo "#sysctl net.ipv4.icmp_ignore_bogus_error_responses"; sysctl net.ipv4.icmp_ignore_bogus_error_responses
|
|
# echo "#grep -Ps \"^\\h*net\\.ipv4\\.icmp_ignore_bogus_error_responses\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf"; grep -Ps "^\h*net\.ipv4\.icmp_ignore_bogus_error_responses" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
|
|
##################################################################################################################
|
|
echo -e "\n######################################"
|
|
if [[ $(sysctl net.ipv4.conf.all.rp_filter | grep "1" | wc -l) -eq 0 || $(grep -Ps "^\h*net\.ipv4\.conf\.all\.rp_filter\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 || $(grep -Ps "^\h*net\.ipv4\.conf\.all\.rp_filter\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 || $(sysctl net.ipv4.conf.default.rp_filter | grep "1" | wc -l) -eq 0 || $(grep -Ps "^\h*net\.ipv4\.conf\.default\.rp_filter\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 || $(grep -Ps "^\h*net\.ipv4\.conf\.default\.rp_filter\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]]; then
|
|
echo "{\"3.2.6. Cấu hình Reverse Path Filtering\" : \"FAILED\"}"
|
|
else
|
|
echo "{\"3.2.6. Cấu hình Reverse Path Filtering\" : \"PASSED\"}"
|
|
fi
|
|
# # Log
|
|
# if [ $(sysctl net.ipv4.conf.all.rp_filter | grep "1" | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#sysctl net.ipv4.conf.all.rp_filter | grep \"1\" -ne 0"; sysctl net.ipv4.conf.all.rp_filter | grep "1"
|
|
# if [ $(grep -Ps "^\h*net\.ipv4\.conf\.all\.rp_filter\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv4\\.conf\\.all\\.rp_filter\\s*=\\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -ne 0"; grep -Ps "^\h*net\.ipv4\.conf\.all\.rp_filter\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# if [ $(grep -Ps "^\h*net\.ipv4\.conf\.all\.rp_filter\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv4\\.conf\\.all\\.rp_filter\\s*=\\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -eq 0"; grep -Ps "^\h*net\.ipv4\.conf\.all\.rp_filter\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# if [ $(sysctl net.ipv4.conf.default.rp_filter | grep "1" | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#sysctl net.ipv4.conf.default.rp_filter | grep \"1\" -ne 0"; sysctl net.ipv4.conf.default.rp_filter | grep "1"
|
|
# if [ $(grep -Ps "^\h*net\.ipv4\.conf\.default\.rp_filter\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv4\\.conf\\.default\\.rp_filter\\s*=\\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -ne 0"; grep -Ps "^\h*net\.ipv4\.conf\.default\.rp_filter\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# if [ $(grep -Ps "^\h*net\.ipv4\.conf\.default\.rp_filter\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv4\\.conf\\.default\\.rp_filter\\s*=\\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -eq 0"; grep -Ps "^\h*net\.ipv4\.conf\.default\.rp_filter\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# echo "----------LOG----------"
|
|
# echo "#sysctl net.ipv4.conf.all.rp_filter"; sysctl net.ipv4.conf.all.rp_filter
|
|
# echo "#grep -Ps \"^\\h*net\\.ipv4\\.conf\\.all\\.rp_filter\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf"; grep -Ps "^\h*net\.ipv4\.conf\.all\.rp_filter" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
# echo "#sysctl net.ipv4.conf.default.rp_filter"; sysctl net.ipv4.conf.default.rp_filter
|
|
# echo "#grep -Ps \"^\\h*net\\.ipv4\\.conf\\.default\\.rp_filter\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf"; grep -Ps "^\h*net\.ipv4\.conf\.default\.rp_filter" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
|
|
##################################################################################################################
|
|
echo -e "\n######################################"
|
|
if [[ $(sysctl net.ipv4.tcp_syncookies | grep "1" | wc -l) -eq 0 || $(grep -Ps "^\h*net\.ipv4\.tcp_syncookies\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 || $(grep -Ps "^\h*net\.ipv4\.tcp_syncookies\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]]; then
|
|
echo "{\"3.2.7. Cấu hình TCP SYN Cookies\" : \"FAILED\"}"
|
|
else
|
|
echo "{\"3.2.7. Cấu hình TCP SYN Cookies\" : \"PASSED\"}"
|
|
fi
|
|
# Log
|
|
if [ $(sysctl net.ipv4.tcp_syncookies | grep "1" | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#sysctl net.ipv4.tcp_syncookies | grep \"1\" -ne 0"; sysctl net.ipv4.tcp_syncookies | grep "1"
|
|
if [ $(grep -Ps "^\h*net\.ipv4\.tcp_syncookies\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv4\\.tcp_syncookies\\s*=\\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -ne 0"; grep -Ps "^\h*net\.ipv4\.tcp_syncookies\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
if [ $(grep -Ps "^\h*net\.ipv4\.tcp_syncookies\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]; then echo "----------[FAILED]----------"; else echo "----------[PASSED]----------"; fi; echo "#grep -Ps \"^\\h*net\\.ipv4\\.tcp_syncookies\\s*=\\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -eq 0"; grep -Ps "^\h*net\.ipv4\.tcp_syncookies\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
echo "----------LOG----------"
|
|
echo "#sysctl net.ipv4.tcp_syncookies"; sysctl net.ipv4.tcp_syncookies
|
|
echo "#grep -Ps \"^\\h*net\\.ipv4\\.tcp_syncookies\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf"; grep -Ps "^\h*net\.ipv4\.tcp_syncookies" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf
|
|
|
|
|
|
############################################################################
|
|
# Đặt các thông số sau vào file /etc/sysctl.conf hoặc /etc/sysctl.d/*.conf:
|
|
# net.ipv4.conf.all.accept_source_route = 0
|
|
# net.ipv4.conf.default.accept_source_route = 0
|
|
# Thực hiện các câu lệnh sau để đặt các tham số vào kernel đang hoạt động:
|
|
# sysctl -w net.ipv4.conf.all.accept_source_route=0
|
|
# sysctl -w net.ipv4.conf.default.accept_source_route=0
|
|
# Nếu sử dụng Ipv6:
|
|
# Đặt các thông số sau vào file /etc/sysctl.conf hoặc /etc/sysctl.d/*.conf:
|
|
# net.ipv6.conf.all.accept_source_route = 0
|
|
# net.ipv6.conf.default.accept_source_route = 0
|
|
# Thực hiện các câu lệnh sau để đặt các tham số vào kernel đang hoạt động:
|
|
# sysctl -w net.ipv6.conf.all.accept_source_route=0
|
|
# sysctl -w net.ipv6.conf.default.accept_source_route=0
|
|
if [[ $(sysctl net.ipv4.conf.all.accept_source_route | grep "0" | wc -l) -eq 0 || $(grep -Ps "^\h*net\.ipv4\.conf\.all\.accept_source_route\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 || $(grep -Ps "^\h*net\.ipv4\.conf\.all\.accept_source_route\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 || $(sysctl net.ipv4.conf.default.accept_source_route | grep "0" | wc -l) -eq 0 || $(grep -Ps "^\h*net\.ipv4\.conf\.default\.accept_source_route\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 || $(grep -Ps "^\h*net\.ipv4\.conf\.default\.accept_source_route\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 || ($IPV6_ENABLED -eq 1 && ($(sysctl net.ipv6.conf.all.accept_source_route 2>/dev/null | grep "0" | wc -l) -eq 0 || $(grep -Ps "^\h*net\.ipv6\.conf\.all\.accept_source_route\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -eq 0 || $(grep -Ps "^\h*net\.ipv6\.conf\.all\.accept_source_route\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -ne 0 || $(sysctl net.ipv6.conf.default.accept_source_route 2>/dev/null | grep "0" | wc -l) -eq 0 || $(grep -Ps "^\h*net\.ipv6\.conf\.default\.accept_source_route\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -eq 0 || $(grep -Ps "^\h*net\.ipv6\.conf\.default\.accept_source_route\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -ne 0)) ]]; then
|
|
echo "{\"3.3.1. Cấu hình từ chối các gói tin với nguồn được định tuyến trước (Source Routed Packet Acceptance)\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Đặt các thông số sau vào file /etc/sysctl.conf hoặc /etc/sysctl.d/*.conf:
|
|
# net.ipv4.conf.all.accept_source_route = 0
|
|
# net.ipv4.conf.default.accept_source_route = 0
|
|
# Thực hiện các câu lệnh sau để đặt các tham số vào kernel đang hoạt động:
|
|
# sysctl -w net.ipv4.conf.all.accept_source_route=0
|
|
# sysctl -w net.ipv4.conf.default.accept_source_route=0
|
|
# Nếu sử dụng Ipv6:
|
|
# Đặt các thông số sau vào file /etc/sysctl.conf hoặc /etc/sysctl.d/*.conf:
|
|
# net.ipv6.conf.all.accept_source_route = 0
|
|
# net.ipv6.conf.default.accept_source_route = 0
|
|
# Thực hiện các câu lệnh sau để đặt các tham số vào kernel đang hoạt động:
|
|
# sysctl -w net.ipv6.conf.all.accept_source_route=0
|
|
# sysctl -w net.ipv6.conf.default.accept_source_route=0"
|
|
if [ $(sysctl net.ipv4.conf.all.accept_source_route | grep "0" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sysctl net.ipv4.conf.all.accept_source_route | grep \"0\" -ne 0 ";sysctl net.ipv4.conf.all.accept_source_route | grep "0"; fi
|
|
if [ $(grep -Ps "^\h*net\.ipv4\.conf\.all\.accept_source_route\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -Ps \"^\\h*net\.ipv4\.conf\.all\.accept_source_route\s*=\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -ne 0 ";grep -Ps "^\h*net\.ipv4\.conf\.all\.accept_source_route\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf; fi
|
|
if [ $(grep -Ps "^\h*net\.ipv4\.conf\.all\.accept_source_route\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -Ps \"^\\h*net\.ipv4\.conf\.all\.accept_source_route\s*=\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -eq 0 ";grep -Ps "^\h*net\.ipv4\.conf\.all\.accept_source_route\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf; fi
|
|
if [ $(sysctl net.ipv4.conf.default.accept_source_route | grep "0" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sysctl net.ipv4.conf.default.accept_source_route | grep \"0\" -ne 0 ";sysctl net.ipv4.conf.default.accept_source_route | grep "0"; fi
|
|
if [ $(grep -Ps "^\h*net\.ipv4\.conf\.default\.accept_source_route\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -Ps \"^\\h*net\.ipv4\.conf\.default\.accept_source_route\s*=\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -ne 0 ";grep -Ps "^\h*net\.ipv4\.conf\.default\.accept_source_route\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf; fi
|
|
if [ $(grep -Ps "^\h*net\.ipv4\.conf\.default\.accept_source_route\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -Ps \"^\\h*net\.ipv4\.conf\.default\.accept_source_route\s*=\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -eq 0 ";grep -Ps "^\h*net\.ipv4\.conf\.default\.accept_source_route\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf; fi
|
|
if [ "$IPV6_ENABLED" -eq 1 ] && [ $(sysctl net.ipv6.conf.all.accept_source_route 2>/dev/null | grep "0" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sysctl net.ipv6.conf.all.accept_source_route | grep \"0\" -ne 0 ";sysctl net.ipv6.conf.all.accept_source_route 2>/dev/null | grep "0"; fi
|
|
if [ "$IPV6_ENABLED" -eq 1 ] && [ $(grep -Ps "^\h*net\.ipv6\.conf\.all\.accept_source_route\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -Ps \"^\\h*net\.ipv6\.conf\.all\.accept_source_route\s*=\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -ne 0 ";grep -Ps "^\h*net\.ipv6\.conf\.all\.accept_source_route\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null; fi
|
|
if [ "$IPV6_ENABLED" -eq 1 ] && [ $(grep -Ps "^\h*net\.ipv6\.conf\.all\.accept_source_route\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -Ps \"^\\h*net\.ipv6\.conf\.all\.accept_source_route\s*=\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -eq 0 ";grep -Ps "^\h*net\.ipv6\.conf\.all\.accept_source_route\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null; fi
|
|
if [ "$IPV6_ENABLED" -eq 1 ] && [ $(sysctl net.ipv6.conf.default.accept_source_route 2>/dev/null | grep "0" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sysctl net.ipv6.conf.default.accept_source_route | grep \"0\" -ne 0 ";sysctl net.ipv6.conf.default.accept_source_route 2>/dev/null | grep "0"; fi
|
|
if [ "$IPV6_ENABLED" -eq 1 ] && [ $(grep -Ps "^\h*net\.ipv6\.conf\.default\.accept_source_route\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -Ps \"^\\h*net\.ipv6\.conf\.default\.accept_source_route\s*=\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -ne 0 ";grep -Ps "^\h*net\.ipv6\.conf\.default\.accept_source_route\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null; fi
|
|
if [ "$IPV6_ENABLED" -eq 1 ] && [ $(grep -Ps "^\h*net\.ipv6\.conf\.default\.accept_source_route\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -Ps \"^\\h*net\.ipv6\.conf\.default\.accept_source_route\s*=\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -eq 0 ";grep -Ps "^\h*net\.ipv6\.conf\.default\.accept_source_route\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"3.3.1. Cấu hình từ chối các gói tin với nguồn được định tuyến trước (Source Routed Packet Acceptance)\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Đặt các tham số sau và file /etc/sysctl.conf hoặc /etc/sysctl.d/*.conf:
|
|
# net.ipv4.conf.all.accept_redirects = 0
|
|
# net.ipv4.conf.default.accept_redirects = 0
|
|
# Thực hiện các câu lệnh sau để đặt các tham số vào kernel đang hoạt động:
|
|
# sysctl -w net.ipv4.conf.all.accept_redirects=0
|
|
# sysctl -w net.ipv4.conf.default.accept_redirects=0
|
|
# Nếu sử dụng Ipv6:
|
|
# Đặt các tham số sau và file /etc/sysctl.conf hoặc /etc/sysctl.d/*.conf:
|
|
# net.ipv6.conf.all.accept_redirects = 0
|
|
# net.ipv6.conf.default.accept_redirects = 0
|
|
# Thực hiện các câu lệnh sau để đặt các tham số vào kernel đang hoạt động:
|
|
# sysctl -w net.ipv6.conf.all.accept_redirects=0
|
|
# sysctl -w net.ipv6.conf.default.accept_redirects=0
|
|
if [ $(sysctl net.ipv4.conf.all.accept_redirects | grep "0" | wc -l) -eq 0 ] || [ $(grep -Ps "^\h*net\.ipv4\.conf\.all\.accept_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ] || [ $(grep -Ps "^\h*net\.ipv4\.conf\.all\.accept_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ] || [ $(sysctl net.ipv4.conf.default.accept_redirects | grep "0" | wc -l) -eq 0 ] || [ $(grep -Ps "^\h*net\.ipv4\.conf\.default\.accept_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ] || [ $(grep -Ps "^\h*net\.ipv4\.conf\.default\.accept_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ] || [[ ($IPV6_ENABLED -eq 1 && ($(sysctl net.ipv6.conf.all.accept_redirects 2>/dev/null | grep "0" | wc -l) -eq 0 || $(grep -Ps "^\h*net\.ipv6\.conf\.all\.accept_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -eq 0 || $(grep -Ps "^\h*net\.ipv6\.conf\.all\.accept_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -ne 0 || $(sysctl net.ipv6.conf.default.accept_redirects 2>/dev/null | grep "0" | wc -l) -eq 0 || $(grep -Ps "^\h*net\.ipv6\.conf\.default\.accept_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -eq 0 || $(grep -Ps "^\h*net\.ipv6\.conf\.default\.accept_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -ne 0)) ]]; then
|
|
echo "{\"3.3.2. Cấu hình từ chối các ICMP redirect message\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Đặt các tham số sau và file /etc/sysctl.conf hoặc /etc/sysctl.d/*.conf:
|
|
# net.ipv4.conf.all.accept_redirects = 0
|
|
# net.ipv4.conf.default.accept_redirects = 0
|
|
# Thực hiện các câu lệnh sau để đặt các tham số vào kernel đang hoạt động:
|
|
# sysctl -w net.ipv4.conf.all.accept_redirects=0
|
|
# sysctl -w net.ipv4.conf.default.accept_redirects=0
|
|
# Nếu sử dụng Ipv6:
|
|
# Đặt các tham số sau và file /etc/sysctl.conf hoặc /etc/sysctl.d/*.conf:
|
|
# net.ipv6.conf.all.accept_redirects = 0
|
|
# net.ipv6.conf.default.accept_redirects = 0
|
|
# Thực hiện các câu lệnh sau để đặt các tham số vào kernel đang hoạt động:
|
|
# sysctl -w net.ipv6.conf.all.accept_redirects=0
|
|
# sysctl -w net.ipv6.conf.default.accept_redirects=0"
|
|
if [ $(sysctl net.ipv4.conf.all.accept_redirects | grep "0" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sysctl net.ipv4.conf.all.accept_redirects | grep \"0\" -ne 0 ";sysctl net.ipv4.conf.all.accept_redirects | grep "0"; fi
|
|
if [ $(grep -Ps "^\h*net\.ipv4\.conf\.all\.accept_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -Ps \"^\\h*net\.ipv4\.conf\.all\.accept_redirects\s*=\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -ne 0 ";grep -Ps "^\h*net\.ipv4\.conf\.all\.accept_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf; fi
|
|
if [ $(grep -Ps "^\h*net\.ipv4\.conf\.all\.accept_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -Ps \"^\\h*net\.ipv4\.conf\.all\.accept_redirects\s*=\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -eq 0 ";grep -Ps "^\h*net\.ipv4\.conf\.all\.accept_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf; fi
|
|
if [ $(sysctl net.ipv4.conf.default.accept_redirects | grep "0" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sysctl net.ipv4.conf.default.accept_redirects | grep \"0\" -ne 0 ";sysctl net.ipv4.conf.default.accept_redirects | grep "0"; fi
|
|
if [ $(grep -Ps "^\h*net\.ipv4\.conf\.default\.accept_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -Ps \"^\\h*net\.ipv4\.conf\.default\.accept_redirects\s*=\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -ne 0 ";grep -Ps "^\h*net\.ipv4\.conf\.default\.accept_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf; fi
|
|
if [ $(grep -Ps "^\h*net\.ipv4\.conf\.default\.accept_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -Ps \"^\\h*net\.ipv4\.conf\.default\.accept_redirects\s*=\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -eq 0 ";grep -Ps "^\h*net\.ipv4\.conf\.default\.accept_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf; fi
|
|
if [ "$IPV6_ENABLED" -eq 1 ] && [ $(sysctl net.ipv6.conf.all.accept_redirects 2>/dev/null | grep "0" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sysctl net.ipv6.conf.all.accept_redirects | grep \"0\" -ne 0 ";sysctl net.ipv6.conf.all.accept_redirects 2>/dev/null | grep "0"; fi
|
|
if [ "$IPV6_ENABLED" -eq 1 ] && [ $(grep -Ps "^\h*net\.ipv6\.conf\.all\.accept_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -Ps \"^\\h*net\.ipv6\.conf\.all\.accept_redirects\s*=\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -ne 0 ";grep -Ps "^\h*net\.ipv6\.conf\.all\.accept_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null; fi
|
|
if [ "$IPV6_ENABLED" -eq 1 ] && [ $(grep -Ps "^\h*net\.ipv6\.conf\.all\.accept_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -Ps \"^\\h*net\.ipv6\.conf\.all\.accept_redirects\s*=\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -eq 0 ";grep -Ps "^\h*net\.ipv6\.conf\.all\.accept_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null; fi
|
|
if [ "$IPV6_ENABLED" -eq 1 ] && [ $(sysctl net.ipv6.conf.default.accept_redirects 2>/dev/null | grep "0" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sysctl net.ipv6.conf.default.accept_redirects | grep \"0\" -ne 0 ";sysctl net.ipv6.conf.default.accept_redirects 2>/dev/null | grep "0"; fi
|
|
if [ "$IPV6_ENABLED" -eq 1 ] && [ $(grep -Ps "^\h*net\.ipv6\.conf\.default\.accept_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -Ps \"^\\h*net\.ipv6\.conf\.default\.accept_redirects\s*=\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -ne 0 ";grep -Ps "^\h*net\.ipv6\.conf\.default\.accept_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null; fi
|
|
if [ "$IPV6_ENABLED" -eq 1 ] && [ $(grep -Ps "^\h*net\.ipv6\.conf\.default\.accept_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -Ps \"^\\h*net\.ipv6\.conf\.default\.accept_redirects\s*=\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -eq 0 ";grep -Ps "^\h*net\.ipv6\.conf\.default\.accept_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"3.3.2. Cấu hình từ chối các ICMP redirect message\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Đặt các tham số sau vào file /etc/sysctl.conf hoặc /etc/sysctl.d/*.conf:
|
|
# net.ipv4.conf.all.secure_redirects = 0
|
|
# net.ipv4.conf.default.secure_redirects = 0
|
|
# Thực hiện các câu lệnh sau để đặt các tham số vào kernel đang hoạt động:
|
|
# sysctl -w net.ipv4.conf.all.secure_redirects=0
|
|
# sysctl -w net.ipv4.conf.default.secure_redirects=0
|
|
if [ $(sysctl net.ipv4.conf.all.secure_redirects | grep "0" | wc -l) -eq 0 ] || [ $(grep -Ps "^\h*net\.ipv4\.conf\.all\.secure_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ] || [ $(grep -Ps "^\h*net\.ipv4\.conf\.all\.secure_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ] || [ $(sysctl net.ipv4.conf.default.secure_redirects | grep "0" | wc -l) -eq 0 ] || [ $(grep -Ps "^\h*net\.ipv4\.conf\.default\.secure_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ] || [ $(grep -Ps "^\h*net\.ipv4\.conf\.default\.secure_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]; then
|
|
echo "{\"3.3.3. Cấu hình từ chối các secure ICMP redirect message\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Đặt các tham số sau vào file /etc/sysctl.conf hoặc /etc/sysctl.d/*.conf:
|
|
# net.ipv4.conf.all.secure_redirects = 0
|
|
# net.ipv4.conf.default.secure_redirects = 0
|
|
# Thực hiện các câu lệnh sau để đặt các tham số vào kernel đang hoạt động:
|
|
# sysctl -w net.ipv4.conf.all.secure_redirects=0
|
|
# sysctl -w net.ipv4.conf.default.secure_redirects=0"
|
|
if [ $(sysctl net.ipv4.conf.all.secure_redirects | grep "0" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sysctl net.ipv4.conf.all.secure_redirects | grep \"0\" -ne 0 ";sysctl net.ipv4.conf.all.secure_redirects | grep "0"; fi
|
|
if [ $(grep -Ps "^\h*net\.ipv4\.conf\.all\.secure_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -Ps \"^\\h*net\.ipv4\.conf\.all\.secure_redirects\s*=\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -ne 0 ";grep -Ps "^\h*net\.ipv4\.conf\.all\.secure_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf; fi
|
|
if [ $(grep -Ps "^\h*net\.ipv4\.conf\.all\.secure_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -Ps \"^\\h*net\.ipv4\.conf\.all\.secure_redirects\s*=\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -eq 0 ";grep -Ps "^\h*net\.ipv4\.conf\.all\.secure_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf; fi
|
|
if [ $(sysctl net.ipv4.conf.default.secure_redirects | grep "0" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sysctl net.ipv4.conf.default.secure_redirects | grep \"0\" -ne 0 ";sysctl net.ipv4.conf.default.secure_redirects | grep "0"; fi
|
|
if [ $(grep -Ps "^\h*net\.ipv4\.conf\.default\.secure_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -Ps \"^\\h*net\.ipv4\.conf\.default\.secure_redirects\s*=\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -ne 0 ";grep -Ps "^\h*net\.ipv4\.conf\.default\.secure_redirects\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf; fi
|
|
if [ $(grep -Ps "^\h*net\.ipv4\.conf\.default\.secure_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -Ps \"^\\h*net\.ipv4\.conf\.default\.secure_redirects\s*=\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -eq 0 ";grep -Ps "^\h*net\.ipv4\.conf\.default\.secure_redirects\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"3.3.3. Cấu hình từ chối các secure ICMP redirect message\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Đặt tham số sau vào file /etc/sysctl.conf hoặc /etc/sysctl.d/*.conf:
|
|
# net.ipv4.icmp_echo_ignore_broadcasts = 1
|
|
# Thực hiện các câu lệnh sau để đặt tham số vào kernel đang hoạt động:
|
|
# sysctl -w net.ipv4.icmp_echo_ignore_broadcasts=1
|
|
if [ $(sysctl net.ipv4.icmp_echo_ignore_broadcasts | grep "1" | wc -l) -eq 0 ] || [ $(grep -Ps "^\h*net\.ipv4\.icmp_echo_ignore_broadcasts\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ] || [ $(grep -Ps "^\h*net\.ipv4\.icmp_echo_ignore_broadcasts\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]; then
|
|
echo "{\"3.3.4. Cấu hình từ chối các gói tin ICMP request broadcast\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Đặt tham số sau vào file /etc/sysctl.conf hoặc /etc/sysctl.d/*.conf:
|
|
# net.ipv4.icmp_echo_ignore_broadcasts = 1
|
|
# Thực hiện các câu lệnh sau để đặt tham số vào kernel đang hoạt động:
|
|
# sysctl -w net.ipv4.icmp_echo_ignore_broadcasts=1"
|
|
if [ $(sysctl net.ipv4.icmp_echo_ignore_broadcasts | grep "1" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sysctl net.ipv4.icmp_echo_ignore_broadcasts | grep \"0\" -ne 0 ";sysctl net.ipv4.icmp_echo_ignore_broadcasts | grep "1"; fi
|
|
if [ $(grep -Ps "^\h*net\.ipv4\.icmp_echo_ignore_broadcasts\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -Ps \"^\\h*net\.ipv4\.icmp_echo_ignore_broadcasts\s*=\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -ne 0 ";grep -Ps "^\h*net\.ipv4\.icmp_echo_ignore_broadcasts\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf; fi
|
|
if [ $(grep -Ps "^\h*net\.ipv4\.icmp_echo_ignore_broadcasts\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -Ps \"^\\h*net\.ipv4\.icmp_echo_ignore_broadcasts\s*=\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -eq 0 ";grep -Ps "^\h*net\.ipv4\.icmp_echo_ignore_broadcasts\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"3.3.4. Cấu hình từ chối các gói tin ICMP request broadcast\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Đặt tham số sau vào file /etc/sysctl.conf hoặc /etc/sysctl.d/*.conf:
|
|
# net.ipv4.icmp_ignore_bogus_error_responses = 1
|
|
# Thực hiện các câu lệnh sau để đặt tham số vào kernel đang hoạt động:
|
|
# sysctl -w net.ipv4.icmp_ignore_bogus_error_responses=1
|
|
if [ $(sysctl net.ipv4.icmp_ignore_bogus_error_responses | grep "1" | wc -l) -eq 0 ] || [ $(grep -Ps "^\h*net\.ipv4\.icmp_ignore_bogus_error_responses\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ] || [ $(grep -Ps "^\h*net\.ipv4\.icmp_ignore_bogus_error_responses\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]; then
|
|
echo "{\"3.3.5. Cấu hình bỏ qua phản hồi ICMP không hợp lệ\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Đặt tham số sau vào file /etc/sysctl.conf hoặc /etc/sysctl.d/*.conf:
|
|
# net.ipv4.icmp_ignore_bogus_error_responses = 1
|
|
# Thực hiện các câu lệnh sau để đặt tham số vào kernel đang hoạt động:
|
|
# sysctl -w net.ipv4.icmp_ignore_bogus_error_responses=1"
|
|
if [ $(sysctl net.ipv4.icmp_ignore_bogus_error_responses | grep "1" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sysctl net.ipv4.icmp_ignore_bogus_error_responses | grep \"0\" -ne 0 ";sysctl net.ipv4.icmp_ignore_bogus_error_responses | grep "1"; fi
|
|
if [ $(grep -Ps "^\h*net\.ipv4\.icmp_ignore_bogus_error_responses\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -Ps \"^\\h*net\.ipv4\.icmp_ignore_bogus_error_responses\s*=\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -ne 0 ";grep -Ps "^\h*net\.ipv4\.icmp_ignore_bogus_error_responses\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf; fi
|
|
if [ $(grep -Ps "^\h*net\.ipv4\.icmp_ignore_bogus_error_responses\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -Ps \"^\\h*net\.ipv4\.icmp_ignore_bogus_error_responses\s*=\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -eq 0 ";grep -Ps "^\h*net\.ipv4\.icmp_ignore_bogus_error_responses\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"3.3.5. Cấu hình bỏ qua phản hồi ICMP không hợp lệ\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Đặt các tham số sau vào file /etc/sysctl.conf hoặc /etc/sysctl.d/*.conf:
|
|
# net.ipv4.conf.all.rp_filter = 1
|
|
# net.ipv4.conf.default.rp_filter = 1
|
|
# Thực hiện các câu lệnh sau để đặt các tham số vào kernel đang hoạt động:
|
|
# sysctl -w net.ipv4.conf.all.rp_filter=1
|
|
# sysctl -w net.ipv4.conf.default.rp_filter=1
|
|
if [ $(sysctl net.ipv4.conf.all.rp_filter | grep "1" | wc -l) -eq 0 ] || [ $(grep -Ps "^\h*net\.ipv4\.conf\.all\.rp_filter\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ] || [ $(grep -Ps "^\h*net\.ipv4\.conf\.all\.rp_filter\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ] || [ $(sysctl net.ipv4.conf.default.rp_filter | grep "1" | wc -l) -eq 0 ] || [ $(grep -Ps "^\h*net\.ipv4\.conf\.default\.rp_filter\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ] || [ $(grep -Ps "^\h*net\.ipv4\.conf\.default\.rp_filter\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]; then
|
|
echo "{\"3.3.6. Cấu hình Reverse Path Filtering\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Đặt các tham số sau vào file /etc/sysctl.conf hoặc /etc/sysctl.d/*.conf:
|
|
# net.ipv4.conf.all.rp_filter = 1
|
|
# net.ipv4.conf.default.rp_filter = 1
|
|
# Thực hiện các câu lệnh sau để đặt các tham số vào kernel đang hoạt động:
|
|
# sysctl -w net.ipv4.conf.all.rp_filter=1
|
|
# sysctl -w net.ipv4.conf.default.rp_filter=1"
|
|
if [ $(sysctl net.ipv4.conf.all.rp_filter | grep "1" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sysctl net.ipv4.conf.all.rp_filter | grep \"0\" -ne 0 ";sysctl net.ipv4.conf.all.rp_filter | grep "1"; fi
|
|
if [ $(grep -Ps "^\h*net\.ipv4\.conf\.all\.rp_filter\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -Ps \"^\\h*net\.ipv4\.conf\.all\.rp_filter\s*=\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -ne 0 ";grep -Ps "^\h*net\.ipv4\.conf\.all\.rp_filter\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf; fi
|
|
if [ $(grep -Ps "^\h*net\.ipv4\.conf\.all\.rp_filter\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -Ps \"^\\h*net\.ipv4\.conf\.all\.rp_filter\s*=\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -eq 0 ";grep -Ps "^\h*net\.ipv4\.conf\.all\.rp_filter\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf; fi
|
|
if [ $(sysctl net.ipv4.conf.default.rp_filter | grep "1" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sysctl net.ipv4.conf.default.rp_filter | grep \"0\" -ne 0 ";sysctl net.ipv4.conf.default.rp_filter | grep "1"; fi
|
|
if [ $(grep -Ps "^\h*net\.ipv4\.conf\.default\.rp_filter\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -Ps \"^\\h*net\.ipv4\.conf\.default\.rp_filter\s*=\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -ne 0 ";grep -Ps "^\h*net\.ipv4\.conf\.default\.rp_filter\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf; fi
|
|
if [ $(grep -Ps "^\h*net\.ipv4\.conf\.default\.rp_filter\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -Ps \"^\\h*net\.ipv4\.conf\.default\.rp_filter\s*=\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -eq 0 ";grep -Ps "^\h*net\.ipv4\.conf\.default\.rp_filter\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"3.3.6. Cấu hình Reverse Path Filtering\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Đặt tham số sau và file /etc/sysctl.conf hoặc /etc/sysctl.d/*.conf:
|
|
# net.ipv4.tcp_syncookies = 1
|
|
# Thực hiện các câu lệnh sau để đặt các tham số vào kernel đang hoạt động:
|
|
# sysctl -w net.ipv4.tcp_syncookies=1
|
|
# sysctl -w net.ipv4.route.flush=1
|
|
if [ $(sysctl net.ipv4.tcp_syncookies | grep "1" | wc -l) -eq 0 ] || [ $(grep -Ps "^\h*net\.ipv4\.tcp_syncookies\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ] || [ $(grep -Ps "^\h*net\.ipv4\.tcp_syncookies\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]; then
|
|
echo "{\"3.3.7. Cấu hình TCP SYN Cookies\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Đặt tham số sau và file /etc/sysctl.conf hoặc /etc/sysctl.d/*.conf:
|
|
# net.ipv4.tcp_syncookies = 1
|
|
# Thực hiện các câu lệnh sau để đặt các tham số vào kernel đang hoạt động:
|
|
# sysctl -w net.ipv4.tcp_syncookies=1
|
|
# sysctl -w net.ipv4.route.flush=1"
|
|
if [ $(sysctl net.ipv4.tcp_syncookies | grep "1" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sysctl net.ipv4.tcp_syncookies | grep \"0\" -ne 0 ";sysctl net.ipv4.tcp_syncookies | grep "1"; fi
|
|
if [ $(grep -Ps "^\h*net\.ipv4\.tcp_syncookies\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -Ps \"^\\h*net\.ipv4\.tcp_syncookies\s*=\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -ne 0 ";grep -Ps "^\h*net\.ipv4\.tcp_syncookies\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf; fi
|
|
if [ $(grep -Ps "^\h*net\.ipv4\.tcp_syncookies\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -Ps \"^\\h*net\.ipv4\.tcp_syncookies\s*=\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -eq 0 ";grep -Ps "^\h*net\.ipv4\.tcp_syncookies\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"3.3.7. Cấu hình TCP SYN Cookies\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Đặt tham số sau và file /etc/sysctl.conf hoặc /etc/sysctl.d/*.conf:
|
|
# net.ipv6.conf.all.accept_ra = 0
|
|
# net.ipv6.conf.default.accept_ra = 0
|
|
# Thực hiện các câu lệnh sau để đặt các tham số vào kernel đang hoạt động:
|
|
# sysctl -w net.ipv6.conf.all.accept_ra=0
|
|
# sysctl -w net.ipv6.conf.default.accept_ra=0
|
|
# *Lưu ý: Mục này chỉ áp dụng nếu sử dụng IPv6
|
|
if [ "$IPV6_ENABLED" -eq 1 ] && [[ ($(sysctl net.ipv6.conf.all.accept_ra 2>/dev/null | grep "0" | wc -l) -eq 0 || $(grep -Ps "^\h*net\.ipv6\.conf\.all\.accept_ra\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -eq 0 || $(grep -Ps "^\h*net\.ipv6\.conf\.all\.accept_ra\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -ne 0 || $(sysctl net.ipv6.conf.default.accept_ra 2>/dev/null | grep "0" | wc -l) -eq 0 || $(grep -Ps "^\h*net\.ipv6\.conf\.default\.accept_ra\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -eq 0 || $(grep -Ps "^\h*net\.ipv6\.conf\.default\.accept_ra\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -ne 0) ]]; then
|
|
echo "{\"3.3.8. Cấu hình từ chối IPv6 router advertisements\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Đặt tham số sau và file /etc/sysctl.conf hoặc /etc/sysctl.d/*.conf:
|
|
# net.ipv6.conf.all.accept_ra = 0
|
|
# net.ipv6.conf.default.accept_ra = 0
|
|
# Thực hiện các câu lệnh sau để đặt các tham số vào kernel đang hoạt động:
|
|
# sysctl -w net.ipv6.conf.all.accept_ra=0
|
|
# sysctl -w net.ipv6.conf.default.accept_ra=0
|
|
# *Lưu ý: Mục này chỉ áp dụng nếu sử dụng IPv6"
|
|
if [ $(sysctl net.ipv6.conf.all.accept_ra 2>/dev/null | grep "0" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sysctl net.ipv6.conf.all.accept_ra | grep \"0\" -ne 0 ";sysctl net.ipv6.conf.all.accept_ra 2>/dev/null | grep "0"; fi
|
|
if [ $(grep -Ps "^\h*net\.ipv6\.conf\.all\.accept_ra\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -Ps \"^\\h*net\.ipv6\.conf\.all\.accept_ra\s*=\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -ne 0 ";grep -Ps "^\h*net\.ipv6\.conf\.all\.accept_ra\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null; fi
|
|
if [ $(grep -Ps "^\h*net\.ipv6\.conf\.all\.accept_ra\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -Ps \"^\\h*net\.ipv6\.conf\.all\.accept_ra\s*=\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -eq 0 ";grep -Ps "^\h*net\.ipv6\.conf\.all\.accept_ra\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null; fi
|
|
if [ $(sysctl net.ipv6.conf.default.accept_ra 2>/dev/null | grep "0" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sysctl net.ipv6.conf.default.accept_ra | grep \"0\" -ne 0 ";sysctl net.ipv6.conf.default.accept_ra 2>/dev/null | grep "0"; fi
|
|
if [ $(grep -Ps "^\h*net\.ipv6\.conf\.default\.accept_ra\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -Ps \"^\\h*net\.ipv6\.conf\.default\.accept_ra\s*=\s*0\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -ne 0 ";grep -Ps "^\h*net\.ipv6\.conf\.default\.accept_ra\s*=\s*0" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null; fi
|
|
if [ $(grep -Ps "^\h*net\.ipv6\.conf\.default\.accept_ra\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -Ps \"^\\h*net\.ipv6\.conf\.default\.accept_ra\s*=\s*1\" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf -eq 0 ";grep -Ps "^\h*net\.ipv6\.conf\.default\.accept_ra\s*=\s*1" /etc/sysctl.conf /etc/sysctl.d/*.conf /usr/lib/sysctl.d/*.conf /run/sysctl.d/*.conf 2>/dev/null; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"3.3.8. Cấu hình từ chối IPv6 router advertisements\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
## Thực hiện câu lệnh sau để cài đặt ufw:
|
|
## apt install ufw
|
|
## Thực hiện các câu lệnh sau để kích hoạt ufw:
|
|
## systemctl unmask ufw.service
|
|
## systemctl --now enable ufw.service
|
|
## ufw enable
|
|
#if [ $(dpkg -l | grep "ii ufw" | wc -l) -ne 0 ] && [ $(systemctl is-enabled ufw | grep "^enabled$" | wc -l) -eq 0 ]; then
|
|
# echo "{\"3.4.1.1. Cấu hình kích hoạt ufw\" : \"FAILED\"}"
|
|
# # Log
|
|
# echo "######################################"
|
|
# echo "# Thực hiện câu lệnh sau để cài đặt ufw:
|
|
## apt install ufw
|
|
## Thực hiện các câu lệnh sau để kích hoạt ufw:
|
|
## systemctl unmask ufw.service
|
|
## systemctl --now enable ufw.service
|
|
## ufw enable"
|
|
# if [ $(dpkg -l | grep "ii ufw" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#dpkg -l | grep \"ii ufw\" -eq 0 ";dpkg -l | grep "ii ufw"; fi
|
|
# if [ $(systemctl is-enabled ufw | grep "^enabled$" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#systemctl is-enabled ufw | grep \"^enabled\$\" -ne 0 ";systemctl is-enabled ufw | grep "^enabled$"; fi
|
|
# echo "######################################"
|
|
#else
|
|
# echo "{\"3.4.1.1. Cấu hình kích hoạt ufw\" : \"PASSED\"}"
|
|
# export UFW_PASS=1
|
|
#fi
|
|
#
|
|
#############################################################################
|
|
## Thực hiện câu lệnh sau để cài đặt iptables và iptables-persistent:
|
|
## apt install iptables iptables-persistent
|
|
## Thực hiện câu lệnh sau để kích hoạt iptables:
|
|
## systemctl --now enable iptables
|
|
#if [ $(dpkg -l | grep "ii iptables" | wc -l) -eq 0 ] || [ $(dpkg -l | grep "ii iptables-persistent" | wc -l) -eq 0 ] || [ $(systemctl is-enabled iptables | grep "^enabled$" | wc -l) -eq 0 ]; then
|
|
# echo "{\"3.4.2.1. Cấu hình kích hoạt Iptables\" : \"FAILED\"}"
|
|
# # Log
|
|
# echo "######################################"
|
|
# echo "# Thực hiện câu lệnh sau để cài đặt iptables và iptables-persistent:
|
|
## apt install iptables iptables-persistent
|
|
## Thực hiện câu lệnh sau để kích hoạt iptables:
|
|
## systemctl --now enable iptables"
|
|
# if [ $(dpkg -l | grep "ii iptables" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#dpkg -l | grep \"ii iptables\" -ne 0 ";dpkg -l | grep "ii iptables"; fi
|
|
# if [ $(dpkg -l | grep "ii iptables-persistent" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#dpkg -l | grep \"ii iptables-persistent\" -ne 0 ";dpkg -l | grep "ii iptables-persistent"; fi
|
|
# if [ $(systemctl is-enabled iptables 2>/dev/null | grep "^enabled$" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#systemctl is-enabled iptables 2>/dev/null | grep \"^enabled\$\" -ne 0 ";systemctl is-enabled iptables 2>/dev/null | grep "^enabled$"; fi
|
|
# echo "######################################"
|
|
#else
|
|
# echo "{\"3.4.2.1. Cấu hình kích hoạt Iptables\" : \"PASSED\"}"
|
|
# export IPT_PASS=1
|
|
#fi
|
|
|
|
# Nếu UFW (cài + enabled) HOẶC iptables (cài đủ + enabled) đạt → cả hai PASSED
|
|
if { dpkg -l | grep -Eq '^ii\s+ufw(\s|$)' && systemctl is-enabled ufw 2>/dev/null | grep -q '^enabled$'; } \
|
|
|| { dpkg -l | grep -Eq '^ii\s+iptables(\s|$)' && dpkg -l | grep -Eq '^ii\s+iptables-persistent(\s|$)' && systemctl is-enabled iptables 2>/dev/null | grep -q '^enabled$'; }
|
|
then
|
|
echo '{"3.4.1.1. Cấu hình kích hoạt ufw" : "PASSED"}'
|
|
echo '{"3.4.2.1. Cấu hình kích hoạt Iptables" : "PASSED"}'
|
|
|
|
# Chỉ export khi đúng loại tường lửa đó pass
|
|
if dpkg -l | grep -Eq '^ii\s+ufw(\s|$)' && systemctl is-enabled ufw 2>/dev/null | grep -q '^enabled$'; then
|
|
export UFW_PASS=1
|
|
fi
|
|
if dpkg -l | grep -Eq '^ii\s+iptables(\s|$)' && dpkg -l | grep -Eq '^ii\s+iptables-persistent(\s|$)' && systemctl is-enabled iptables 2>/dev/null | grep -q '^enabled$'; then
|
|
export IPT_PASS=1
|
|
fi
|
|
|
|
else
|
|
######################## UFW: FAILED ########################
|
|
echo '{"3.4.1.1. Cấu hình kích hoạt ufw" : "FAILED"}'
|
|
echo "######################################"
|
|
echo "# Cài đặt & kích hoạt UFW:"
|
|
echo "# apt install ufw"
|
|
echo "# systemctl unmask ufw.service"
|
|
echo "# systemctl --now enable ufw.service"
|
|
echo "# ufw enable"
|
|
if ! dpkg -l | grep -Eq '^ii\s+ufw(\s|$)'; then
|
|
echo "-------------------"; echo '# Thiếu gói ufw'; dpkg -l | grep -E '^ii\s+ufw' || true
|
|
fi
|
|
if ! systemctl is-enabled ufw 2>/dev/null | grep -q '^enabled$'; then
|
|
echo "-------------------"; echo '# ufw chưa enabled'; systemctl is-enabled ufw 2>/dev/null || true
|
|
fi
|
|
echo "######################################"
|
|
|
|
##################### IPTABLES: FAILED ######################
|
|
echo '{"3.4.2.1. Cấu hình kích hoạt Iptables" : "FAILED"}'
|
|
echo "######################################"
|
|
echo "# Cài đặt & kích hoạt iptables:"
|
|
echo "# apt install iptables iptables-persistent"
|
|
echo "# systemctl --now enable iptables"
|
|
if ! dpkg -l | grep -Eq '^ii\s+iptables(\s|$)'; then
|
|
echo "-------------------"; echo '# Thiếu gói iptables'; dpkg -l | grep -E '^ii\s+iptables' || true
|
|
fi
|
|
if ! dpkg -l | grep -Eq '^ii\s+iptables-persistent(\s|$)'; then
|
|
echo "-------------------"; echo '# Thiếu gói iptables-persistent'; dpkg -l | grep -E '^ii\s+iptables-persistent' || true
|
|
fi
|
|
if ! systemctl is-enabled iptables 2>/dev/null | grep -q '^enabled$'; then
|
|
echo "-------------------"; echo '# iptables service chưa enabled'; systemctl is-enabled iptables 2>/dev/null || true
|
|
fi
|
|
echo "######################################"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện câu lệnh sau để gỡ bỏ iptables-persistent:
|
|
# apt purge iptables-persistent
|
|
# Thực hiện câu lệnh sau để vô hiệu hoá nftables:
|
|
# systemctl --now mask nftables
|
|
if [ "$IPT_PASS" = "1" ]; then
|
|
echo "{\"3.4.1.2. Cấu hình vô hiệu hoá iptables-persistent, nftables khi sử dụng ufw\" : \"PASSED\"}"
|
|
elif [ $(dpkg -l | grep "ii iptables-persistent" | wc -l) -ne 0 ] || [[ ($(dpkg -l | grep "ii nftables" | wc -l) -ne 0 && $(systemctl is-enabled nftables | grep "^masked$" | wc -l) -eq 0) ]]; then
|
|
echo "{\"3.4.1.2. Cấu hình vô hiệu hoá iptables-persistent, nftables khi sử dụng ufw\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để gỡ bỏ iptables-persistent:
|
|
# apt purge iptables-persistent
|
|
# Thực hiện câu lệnh sau để vô hiệu hoá nftables:
|
|
# systemctl --now mask nftables"
|
|
if [ $(dpkg -l | grep "ii iptables-persistent" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#dpkg -l | grep \"ii iptables-persistent\" -eq 0 ";dpkg -l | grep "ii iptables-persistent"; fi
|
|
if [ $(dpkg -l | grep "ii nftables" | wc -l) -ne 0 ] && [ $(systemctl is-enabled nftables | grep "^masked$" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#systemctl is-enabled nftables | grep \"^masked\$\" -ne 0 ";systemctl is-enabled nftables | grep "^masked$"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"3.4.1.2. Cấu hình vô hiệu hoá iptables-persistent, nftables khi sử dụng ufw\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện các câu lệnh sau để cài đặt các luật cho đường truyền loopback:
|
|
# ufw allow in on lo
|
|
# ufw allow out on lo
|
|
# ufw deny in from 127.0.0.0/8
|
|
# ufw deny in from ::1
|
|
|
|
if [ "$IPT" = "1" ]; then
|
|
echo "{\"3.4.1.3. Cấu hình ufw loopback traffic\" : \"PASSED\"}"
|
|
elif [ $(ufw status | grep -P "^Anywhere on lo\h*ALLOW\h*Anywhere\h*$" | wc -l) -eq 0 ] || [ $(ufw status | grep -P "^Anywhere\h*ALLOW OUT\h*Anywhere on lo\h*$" | wc -l) -eq 0 ] || [ $(ufw status | grep -P "^Anywhere on lo\h*ALLOW\h*Anywhere\h*$" | wc -l) -eq 0 ] || [ $(ufw status | grep -P "^Anywhere\h*DENY\h*127.0.0.0/8\h*$" | wc -l) -eq 0 ] || [[ ($(echo $output | grep "enabled" | wc -l) -ne 0 && ($(ufw status | grep -P "^Anywhere \(v6\) on lo\h*ALLOW\h*Anywhere \(v6\)\h*$" | wc -l) -eq 0 || $(ufw status | grep -P "^Anywhere \(v6\)\h*ALLOW OUT\h*Anywhere \(v6\) on lo\h*$" | wc -l) -eq 0 || $(ufw status | grep -P "^Anywhere \(v6\)\h*DENY\h*::1\h*$" | wc -l) -eq 0)) ]]; then
|
|
echo "{\"3.4.1.3. Cấu hình ufw loopback traffic\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện các câu lệnh sau để cài đặt các luật cho đường truyền loopback:
|
|
# ufw allow in on lo
|
|
# ufw allow out on lo
|
|
# ufw deny in from 127.0.0.0/8
|
|
# ufw deny in from ::1"
|
|
if [ $(ufw status | grep -P "^Anywhere on lo\h*ALLOW\h*Anywhere\h*$" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#ufw status | grep -P \"^Anywhere on lo\\h*ALLOW\\h*Anywhere\\h*\$\" -ne 0 ";ufw status | grep -P "^Anywhere on lo\h*ALLOW\h*Anywhere\h*$"; fi
|
|
if [ $(ufw status | grep -P "^Anywhere\h*ALLOW OUT\h*Anywhere on lo\h*$" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#ufw status | grep -P \"^Anywhere\\h*ALLOW OUT\\h*Anywhere on lo\\h*\$\" -ne 0 ";ufw status | grep -P "^Anywhere\h*ALLOW OUT\h*Anywhere on lo\h*$"; fi
|
|
if [ $(ufw status | grep -P "^Anywhere on lo\h*ALLOW\h*Anywhere\h*$" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#ufw status | grep -P \"^Anywhere on lo\\h*ALLOW\\h*Anywhere\\h*\$\" -ne 0 ";ufw status | grep -P "^Anywhere on lo\h*ALLOW\h*Anywhere\h*$"; fi
|
|
if [ $(ufw status | grep -P "^Anywhere\h*DENY\h*127.0.0.0/8\h*$" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#ufw status | grep -P \"^Anywhere\\h*DENY\\h*127.0.0.0/8\\h*\$\" -ne 0 ";ufw status | grep -P "^Anywhere\h*DENY\h*127.0.0.0/8\h*$"; fi
|
|
if [ $(echo $output | grep "enabled" | wc -l) -ne 0 ] && [ $(ufw status | grep -P "^Anywhere \(v6\) on lo\h*ALLOW\h*Anywhere \(v6\)\h*$" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#ufw status | grep -P \"^Anywhere \(v6\) on lo\\h*ALLOW\\h*Anywhere \(v6\)\\h*\$\" -ne 0 ";ufw status | grep -P "^Anywhere \\\(v6\\\) on lo\h*ALLOW\h*Anywhere \\\(v6\\\)\h*$"; fi
|
|
if [ $(echo $output | grep "enabled" | wc -l) -ne 0 ] && [ $(ufw status | grep -P "^Anywhere \(v6\)\h*ALLOW OUT\h*Anywhere \(v6\) on lo\h*$" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#ufw status | grep -P \"^Anywhere \\\(v6\\\)\\h*ALLOW OUT\\h*Anywhere \\\(v6\\\) on lo\\h*\$\" -ne 0 ";ufw status | grep -P "^Anywhere \(v6\)\h*ALLOW OUT\h*Anywhere \(v6\) on lo\h*$"; fi
|
|
if [ $(echo $output | grep "enabled" | wc -l) -ne 0 ] && [ $(ufw status | grep -P "^Anywhere \(v6\)\h*DENY\h*::1\h*$" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#ufw status | grep -P \"^Anywhere \\\(v6\\\)\\h*DENY\\h*::1\\h*\$\" -ne 0 ";ufw status | grep -P "^Anywhere \(v6\)\h*DENY\h*::1\h*$"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"3.4.1.3. Cấu hình ufw loopback traffic\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Hiển thị các rule firewall hiện tại cho UFW
|
|
# Các cấu hình khuyến nghị:
|
|
# ufw allow ssh
|
|
# ufw allow in <port>/<tcp or udp protocol>
|
|
#!/usr/bin/env bash
|
|
|
|
if [ "$IPT_PASS" = "1" ]; then
|
|
echo '{"3.4.1.4. Cấu hình ufw rule cho tất cả các port và protocol đang mở" : "PASSED"}'
|
|
|
|
elif ! command -v ufw >/dev/null 2>&1; then
|
|
echo '{"3.4.1.4. Cấu hình ufw rule cho tất cả các port và protocol đang mở" : "FAILED"}'
|
|
echo "######################################"
|
|
echo "# UFW không được cài đặt"
|
|
echo "######################################"
|
|
|
|
elif ! ufw status | grep -iq '^Status:[[:space:]]*active'; then
|
|
echo '{"3.4.1.4. Cấu hình ufw rule cho tất cả các port và protocol đang mở" : "FAILED"}'
|
|
echo "######################################"
|
|
echo "# UFW không được kích hoạt"
|
|
ufw status || true
|
|
echo "######################################"
|
|
|
|
else
|
|
# UFW đang active - lấy các rules hiện tại
|
|
echo '{"3.4.1.4. Cấu hình ufw rule cho tất cả các port và protocol đang mở" : "PASSED"}'
|
|
echo "######################################"
|
|
echo "# Các rule UFW hiện tại:"
|
|
echo "-------------------"
|
|
ufw status numbered || true
|
|
echo "-------------------"
|
|
echo "# Inbound rules (ALLOW):"
|
|
ufw status | grep -E "ALLOW.*Anywhere" | grep -v "ALLOW OUT" || echo " (Không có rules)"
|
|
echo "-------------------"
|
|
echo "# Outbound rules (ALLOW OUT):"
|
|
ufw status | grep "ALLOW OUT" || echo " (Không có rules)"
|
|
if grep -q '^IPV6=yes' /etc/default/ufw 2>/dev/null; then
|
|
echo "-------------------"
|
|
echo "# IPv6 rules:"
|
|
ufw status | grep "(v6)" || echo " (Không có rules IPv6)"
|
|
fi
|
|
echo "######################################"
|
|
fi
|
|
|
|
|
|
############################################################################
|
|
# Thực hiện các câu lệnh sau để cài đặt chính sách mặc định là DENY
|
|
# ufw default deny incoming
|
|
# ufw default deny outgoing
|
|
# ufw default disabled routed
|
|
if [ "$IPT_PASS" = "1" ]; then
|
|
echo "{\"3.4.1.5. Cấu hình chính sách từ chối mặc định cho ufw\" : \"PASSED\"}"
|
|
elif [ $(ufw status verbose | grep -P "^Default.*deny\h*\(incoming\)" | wc -l) -eq 0 ] || [ $(ufw status verbose | grep -P "^Default.*deny\h*\(outgoing\)" | wc -l) -eq 0 ] || [ $(ufw status verbose | grep -P "^Default.*disabled\h*\(routed\)" | wc -l) -eq 0 ]; then
|
|
echo "{\"3.4.1.5. Cấu hình chính sách từ chối mặc định cho ufw\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện các câu lệnh sau để cài đặt chính sách mặc định là DENY
|
|
# ufw default deny incoming
|
|
# ufw default deny outgoing
|
|
# ufw default disabled routed"
|
|
if [ $(ufw status verbose | grep -P "^Default.*deny\h*\(incoming\)" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#ufw status verbose | grep -P \"^Default.*deny\\h*\\(incoming\\)\" -ne 0 ";ufw status verbose | grep -P "^Default.*deny\h*\(incoming\)"; fi
|
|
if [ $(ufw status verbose | grep -P "^Default.*deny\h*\(outgoing\)" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#ufw status verbose | grep -P \"^Default.*deny\\h*\\(outgoing\\)\" -ne 0 ";ufw status verbose | grep -P "^Default.*deny\h*\(outgoing\)"; fi
|
|
if [ $(ufw status verbose | grep -P "^Default.*disabled\h*\(routed\)" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#ufw status verbose | grep -P \"^Default.*disabled\\h*\\(routed\\)\" -ne 0 ";ufw status verbose | grep -P "^Default.*disabled\h*\(routed\)"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"3.4.1.5. Cấu hình chính sách từ chối mặc định cho ufw\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện câu lệnh sau để vô hiệu hoá ufw:
|
|
# apt purge ufw
|
|
# Thực hiện câu lệnh sau để vô hiệu hoá nftables:
|
|
# systemctl --now mask nftables
|
|
if [ "$UFW_PASS" = "1" ]; then
|
|
echo "{\"3.4.2.2. Cấu hình vô hiệu hoá ufw, nftables khi sử dụng iptables\" : \"PASSED\"}"
|
|
elif [ $(dpkg -l | grep "ii ufw" | wc -l) -ne 0 ] || [[ ($(dpkg -l | grep "ii nftables" | wc -l) -ne 0 && $(systemctl is-enabled nftables | grep "masked" | wc -l) -eq 0) ]]; then
|
|
echo "{\"3.4.2.2. Cấu hình vô hiệu hoá ufw, nftables khi sử dụng iptables\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để vô hiệu hoá ufw:
|
|
# apt purge ufw
|
|
# Thực hiện câu lệnh sau để vô hiệu hoá nftables:
|
|
# systemctl --now mask nftables"
|
|
if [ $(dpkg -l | grep "ii ufw" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#dpkg -l | grep \"ii ufw\" -eq 0 ";dpkg -l | grep "ii ufw"; fi
|
|
if [ $(dpkg -l | grep "ii nftables" | wc -l) -ne 0 ] && [ $(systemctl is-enabled nftables | grep "^masked$" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#systemctl is-enabled nftables | grep \"^masked\$\" -ne 0 ";systemctl is-enabled nftables | grep "^masked$"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"3.4.2.2. Cấu hình vô hiệu hoá ufw, nftables khi sử dụng iptables\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện các câu lệnh sau để cài đặt các luật cho đường truyền loopback:
|
|
# iptables -A INPUT -i lo -j ACCEPT
|
|
# iptables -A OUTPUT -o lo -j ACCEPT
|
|
# iptables -A INPUT -s 127.0.0.0/8 -j DROP
|
|
# Nếu sử dụng IPv6:
|
|
# Thực hiện các câu lệnh sau để cài đặt các luật cho đường truyền loopback:
|
|
# ip6tables -A INPUT -i lo -j ACCEPT
|
|
# ip6tables -A OUTPUT -o lo -j ACCEPT
|
|
# ip6tables -A INPUT -s ::1 -j DROP
|
|
if [ "$UFW_PASS" = "1" ]; then
|
|
echo "{\"3.4.2.3. Cấu hình iptables loopback traffic\" : \"PASSED\"}"
|
|
elif [ $(iptables -L INPUT -v -n | grep "ACCEPT.*lo" | wc -l) -eq 0 ] || [ $(iptables -L OUTPUT -v -n | grep "ACCEPT.*lo" | wc -l) -eq 0 ] || [ $(iptables -L INPUT -v -n | grep "DROP.*127\.0\.0\.0/8" | wc -l) -eq 0 ] || [[ ($(echo $output | grep "enabled" | wc -l) -ne 0 && ($(ip6tables -L INPUT -v -n | grep "ACCEPT.*lo" | wc -l) -eq 0 || $(ip6tables -L OUTPUT -v -n | grep "ACCEPT.*lo" | wc -l) -eq 0 || $(ip6tables -L INPUT -v -n | grep "DROP.*::1" | wc -l) -eq 0 )) ]]; then
|
|
echo "{\"3.4.2.3. Cấu hình iptables loopback traffic\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện các câu lệnh sau để cài đặt các luật cho đường truyền loopback:
|
|
# iptables -A INPUT -i lo -j ACCEPT
|
|
# iptables -A OUTPUT -o lo -j ACCEPT
|
|
# iptables -A INPUT -s 127.0.0.0/8 -j DROP
|
|
# Nếu sử dụng IPv6:
|
|
# Thực hiện các câu lệnh sau để cài đặt các luật cho đường truyền loopback:
|
|
# ip6tables -A INPUT -i lo -j ACCEPT
|
|
# ip6tables -A OUTPUT -o lo -j ACCEPT
|
|
# ip6tables -A INPUT -s ::1 -j DROP"
|
|
if [ $(iptables -L INPUT -v -n | grep "ACCEPT.*lo" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#iptables -L INPUT -v -n | grep \"ACCEPT.*lo\" -ne 0 ";iptables -L INPUT -v -n | grep "ACCEPT.*lo"; fi
|
|
if [ $(iptables -L OUTPUT -v -n | grep "ACCEPT.*lo" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#iptables -L OUTPUT -v -n | grep \"ACCEPT.*lo\" -ne 0 ";iptables -L OUTPUT -v -n | grep "ACCEPT.*lo"; fi
|
|
if [ $(iptables -L INPUT -v -n | grep "DROP.*127\.0\.0\.0/8" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#iptables -L INPUT -v -n | grep \"DROP.*127\\.0\\.0\\.0/8\" -ne 0 ";iptables -L INPUT -v -n | grep "DROP.*127\.0\.0\.0/8"; fi
|
|
if [ $(echo $output | grep "enabled" | wc -l) -ne 0 ] && [ $(ip6tables -L INPUT -v -n | grep "ACCEPT.*lo" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#ip6tables -L INPUT -v -n | grep \"ACCEPT.*lo\" -ne 0 ";ip6tables -L INPUT -v -n | grep "ACCEPT.*lo"; fi
|
|
if [ $(echo $output | grep "enabled" | wc -l) -ne 0 ] && [ $(ip6tables -L OUTPUT -v -n | grep "ACCEPT.*lo" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#ip6tables -L OUTPUT -v -n | grep \"ACCEPT.*lo\" -ne 0 ";ip6tables -L OUTPUT -v -n | grep "ACCEPT.*lo"; fi
|
|
if [ $(echo $output | grep "enabled" | wc -l) -ne 0 ] && [ $(ip6tables -L INPUT -v -n | grep "DROP.*::1" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#ip6tables -L INPUT -v -n | grep \"DROP.*::1\" -ne 0 ";ip6tables -L INPUT -v -n | grep "DROP.*::1"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"3.4.2.3. Cấu hình iptables loopback traffic\" : \"PASSED\"}"
|
|
PASSED=$((PASSED + 1))
|
|
fi
|
|
|
|
############################################################################
|
|
# Với mỗi cổng được xác định ở bước kiểm tra mà không có luật tường lửa nào, thiết lập luật phù hợp để chấp nhận kết nối đến:
|
|
# iptables -A INPUT -p <protocol> --dport <port> -m state --state NEW -j ACCEPT
|
|
# Các cấu hình khuyến nghị:
|
|
# iptables -A OUTPUT -p icmp -m state --state NEW,ESTABLISHED -j ACCEPT
|
|
# iptables -A INPUT -p icmp -m state --state ESTABLISHED -j ACCEPT
|
|
# # Mở kết nối inbound ssh(tcp port 22)
|
|
# iptables -A INPUT -p tcp --dport 22 -m state --state NEW -j ACCEPT
|
|
# Nếu sử dụng IPv6:
|
|
# Với mỗi cổng được xác định ở bước kiểm tra mà không có luật tường lửa nào, thiết lập luật phù hợp để chấp nhận kết nối đến:
|
|
# ip6tables -A INPUT -p <protocol> --dport <port> -m state --state NEW -j ACCEPT
|
|
# Các cấu hình khuyến nghị
|
|
# ip6tables -A OUTPUT -p icmp -m state --state NEW,ESTABLISHED -j ACCEPT
|
|
# ip6tables -A INPUT -p icmp -m state --state ESTABLISHED -j ACCEPT
|
|
# # Mở kết nối inbound ssh(tcp port 22)
|
|
# Hiển thị các rule firewall hiện tại cho iptables
|
|
# Gợi ý cấu hình:
|
|
# iptables -A INPUT -p tcp --dport <port> -m state --state NEW -j ACCEPT
|
|
# ip6tables -A INPUT -p tcp --dport <port> -m state --state NEW -j ACCEPT
|
|
#!/usr/bin/env bash
|
|
|
|
# 3.4.2.4. Cấu hình iptables rule cho tất cả các port và protocol đang mở
|
|
|
|
if [ "$UFW_PASS" = "1" ]; then
|
|
echo '{"3.4.2.4. Cấu hình iptables rule cho tất cả các port và protocol đang mở" : "PASSED"}'
|
|
|
|
elif ! command -v iptables >/dev/null 2>&1; then
|
|
echo '{"3.4.2.4. Cấu hình iptables rule cho tất cả các port và protocol đang mở" : "FAILED"}'
|
|
echo "######################################"
|
|
echo "# iptables không được cài đặt"
|
|
echo "######################################"
|
|
|
|
else
|
|
# Lấy các rules hiện tại
|
|
echo '{"3.4.2.4. Cấu hình iptables rule cho tất cả các port và protocol đang mở" : "PASSED"}'
|
|
echo "######################################"
|
|
echo "# Các rule iptables IPv4 hiện tại:"
|
|
echo "-------------------"
|
|
echo "# INPUT chain:"
|
|
iptables -L INPUT -v -n --line-numbers 2>/dev/null || true
|
|
echo "-------------------"
|
|
echo "# OUTPUT chain:"
|
|
iptables -L OUTPUT -v -n --line-numbers 2>/dev/null || true
|
|
echo "-------------------"
|
|
echo "# FORWARD chain:"
|
|
iptables -L FORWARD -v -n --line-numbers 2>/dev/null || true
|
|
|
|
# Hiển thị các TCP ports đang ACCEPT trong INPUT
|
|
echo "-------------------"
|
|
echo "# Các TCP ports được phép (INPUT ACCEPT):"
|
|
iptables -L INPUT -v -n 2>/dev/null | grep -P 'ACCEPT.*\btcp\b.*\bdpt:' | awk '{
|
|
for(i=1;i<=NF;i++) {
|
|
if($i ~ /dpt:[0-9]+/) {
|
|
port = $i
|
|
gsub(/dpt:/, "", port)
|
|
print " - Port " port "/tcp"
|
|
}
|
|
}
|
|
}' | sort -u || echo " (Không tìm thấy rules)"
|
|
|
|
# Hiển thị các UDP ports đang ACCEPT trong INPUT
|
|
echo "-------------------"
|
|
echo "# Các UDP ports được phép (INPUT ACCEPT):"
|
|
iptables -L INPUT -v -n 2>/dev/null | grep -P 'ACCEPT.*\budp\b.*\bdpt:' | awk '{
|
|
for(i=1;i<=NF;i++) {
|
|
if($i ~ /dpt:[0-9]+/) {
|
|
port = $i
|
|
gsub(/dpt:/, "", port)
|
|
print " - Port " port "/udp"
|
|
}
|
|
}
|
|
}' | sort -u || echo " (Không tìm thấy rules)"
|
|
|
|
# Kiểm tra IPv6
|
|
if [ "$IPV6_ENABLED" -eq 1 ] && command -v ip6tables >/dev/null 2>&1 && ip6tables -L -v -n >/dev/null 2>&1; then
|
|
echo "-------------------"
|
|
echo "# Các rule iptables IPv6 hiện tại:"
|
|
echo "-------------------"
|
|
echo "# INPUT chain (IPv6):"
|
|
ip6tables -L INPUT -v -n --line-numbers 2>/dev/null || true
|
|
echo "-------------------"
|
|
echo "# OUTPUT chain (IPv6):"
|
|
ip6tables -L OUTPUT -v -n --line-numbers 2>/dev/null || true
|
|
|
|
# Hiển thị các TCP ports đang ACCEPT trong INPUT (IPv6)
|
|
echo "-------------------"
|
|
echo "# Các TCP ports được phép IPv6 (INPUT ACCEPT):"
|
|
ip6tables -L INPUT -v -n 2>/dev/null | grep -P 'ACCEPT.*\btcp\b.*\bdpt:' | awk '{
|
|
for(i=1;i<=NF;i++) {
|
|
if($i ~ /dpt:[0-9]+/) {
|
|
port = $i
|
|
gsub(/dpt:/, "", port)
|
|
print " - Port " port "/tcp (v6)"
|
|
}
|
|
}
|
|
}' | sort -u || echo " (Không tìm thấy rules)"
|
|
fi
|
|
|
|
echo "######################################"
|
|
fi
|
|
|
|
|
|
############################################################################
|
|
# Thực hiện các câu lệnh sau để cài đặt chính sách mặc định là DROP:
|
|
# iptables -P INPUT DROP
|
|
# iptables -P OUTPUT DROP
|
|
# iptables -P FORWARD DROP
|
|
# Nếu sử dụng IPv6:
|
|
# Thực hiện các câu lệnh sau để cài đặt chính sách mặc định là DROP:
|
|
# ip6tables -P INPUT DROP
|
|
# ip6tables -P OUTPUT DROP
|
|
# ip6tables -P FORWARD DROP
|
|
# *Lưu ý: Thực hiện việc cấu hình chính sách ở mục 2.3.4.2.3 và 2.3.4.2.4 trước để tránh kết nối bị gián đoạn.
|
|
if [ "$UFW_PASS" = "1" ]; then
|
|
echo "{\"3.4.2.5. Cấu hình chính sách từ chối mặc định cho iptables\" : \"PASSED\"}"
|
|
elif [ $(iptables -L | grep "INPUT.*DROP" | wc -l) -eq 0 ] || [ $(iptables -L | grep "FORWARD.*DROP" | wc -l) -eq 0 ] || [ $(iptables -L | grep "OUTPUT.*DROP" | wc -l) -eq 0 ] || [[ ($(echo $output | grep "enabled" | wc -l) -ne 0 && ($(ip6tables -L | grep "INPUT.*DROP" | wc -l) -eq 0 || $(ip6tables -L | grep "FORWARD.*DROP" | wc -l) -eq 0 || $(ip6tables -L | grep "OUTPUT.*DROP" | wc -l) -eq 0)) ]]; then
|
|
echo "{\"3.4.2.5. Cấu hình chính sách từ chối mặc định cho iptables\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện các câu lệnh sau để cài đặt chính sách mặc định là DROP:
|
|
# iptables -P INPUT DROP
|
|
# iptables -P OUTPUT DROP
|
|
# iptables -P FORWARD DROP
|
|
# Thực hiện câu lệnh sau để lưu cấu hình iptables:
|
|
# service iptables save
|
|
# Nếu sử dụng IPv6:
|
|
# Thực hiện các câu lệnh sau để cài đặt chính sách mặc định là DROP:
|
|
# ip6tables -P INPUT DROP
|
|
# ip6tables -P OUTPUT DROP
|
|
# ip6tables -P FORWARD DROP
|
|
# Thực hiện câu lệnh sau để lưu cấu hình ip6tables
|
|
# service ip6tables save
|
|
# *Lưu ý: Thực hiện việc cấu hình chính sách ở mục 2.3.4.2.3 và 2.3.4.2.4 trước để tránh kết nối bị gián đoạn."
|
|
if [ $(iptables -L | grep "INPUT.*DROP" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#iptables -L | grep \"INPUT.*DROP\" -ne 0 ";iptables -L | grep "INPUT.*DROP"; fi
|
|
if [ $(iptables -L | grep "FORWARD.*DROP" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#iptables -L | grep \"FORWARD.*DROP\" -ne 0 ";iptables -L | grep "FORWARD.*DROP"; fi
|
|
if [ $(iptables -L | grep "OUTPUT.*DROP" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#iptables -L | grep \"OUTPUT.*DROP\" -ne 0 ";iptables -L | grep "OUTPUT.*DROP"; fi
|
|
if [ $(ip6tables -L | grep "INPUT.*DROP" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#ip6tables -L | grep \"INPUT.*DROP\" -ne 0 ";ip6tables -L | grep "INPUT.*DROP"; fi
|
|
if [ $(ip6tables -L | grep "FORWARD.*DROP" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#ip6tables -L | grep \"FORWARD.*DROP\" -ne 0 ";ip6tables -L | grep "FORWARD.*DROP"; fi
|
|
if [ $(ip6tables -L | grep "OUTPUT.*DROP" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#ip6tables -L | grep \"OUTPUT.*DROP\" -ne 0 ";ip6tables -L | grep "OUTPUT.*DROP"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"3.4.2.5. Cấu hình chính sách từ chối mặc định cho iptables\" : \"PASSED\"}"
|
|
fi
|
|
|
|
##################################################################################################################
|
|
# Thực hiện câu lệnh sau để cài đặt rsyslog:
|
|
# apt install rsyslog
|
|
# Thực hiện câu lệnh sau để kích hoạt rsyslog:
|
|
# systemctl --now enable rsyslog
|
|
if [ $(dpkg -l | grep "ii rsyslog" | wc -l) -eq 0 ] || [ $(systemctl is-enabled rsyslog | grep "^enabled$" | wc -l) -eq 0 ]; then
|
|
echo "{\"4.1.1.1. Cấu hình kích hoạt rsyslog service\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để cài đặt rsyslog:
|
|
# apt install rsyslog
|
|
# Thực hiện câu lệnh sau để kích hoạt rsyslog:
|
|
# systemctl --now enable rsyslog"
|
|
if [ $(dpkg -l | grep "ii rsyslog" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#dpkg -l | grep \"ii rsyslog\" -ne 0 ";dpkg -l | grep "ii rsyslog"; fi
|
|
if [ $(systemctl is-enabled rsyslog | grep "^enabled$" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#systemctl is-enabled rsyslog | grep \"^enabled\$\" -ne 0 ";systemctl is-enabled rsyslog | grep "^enabled$"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"4.1.1.1. Cấu hình kích hoạt rsyslog service\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Chỉnh sửa file /etc/rsyslog.conf hoặc /etc/rsyslog.d/*.conf và đặt $FileCreateMode là 0640 hoặc nghiêm ngặt hơn:
|
|
# $FileCreateMode 0640
|
|
# Thực hiện câu lệnh sau để khởi động lại rsyslog:
|
|
# systemctl restart rsyslog
|
|
# *Lưu ý: Đảm bảo cấu hình này không bị viết đè bởi các thiết lập kém nghiêm ngặt hơn ở bất kỳ file conf nào trong /etc/rsyslog.d/*.
|
|
if [ $(grep "^\$FileCreateMode" /etc/rsyslog.conf /etc/rsyslog.d/* 2>/dev/null | grep -E "0[6-7][0-4]0" | wc -l) -eq 0 ] || [ $(grep -Ev "FileCreateMode.*0[6-7][0-4]0" /etc/rsyslog.conf /etc/rsyslog.d/* 2>/dev/null | grep "^\$FileCreateMode" | wc -l) -ne 0 ]; then
|
|
echo "{\"4.1.1.2. Phân quyền đối với file log sinh ra từ rsyslog\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Chỉnh sửa file /etc/rsyslog.conf hoặc /etc/rsyslog.d/*.conf và đặt \$FileCreateMode là 0640 hoặc nghiêm ngặt hơn:
|
|
# \$FileCreateMode 0640
|
|
# Thực hiện câu lệnh sau để khởi động lại rsyslog:
|
|
# systemctl restart rsyslog
|
|
# *Lưu ý: Đảm bảo cấu hình này không bị viết đè bởi các thiết lập kém nghiêm ngặt hơn ở bất kỳ file conf nào trong /etc/rsyslog.d/*."
|
|
if [ $(grep "^\$FileCreateMode" /etc/rsyslog.conf /etc/rsyslog.d/* 2>/dev/null | grep -E "0[6-7][0-4]0" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -P \"^\\h*\\\$FileCreateMode\" /etc/rsyslog.conf /etc/rsyslog.d/* 2>/dev/null | grep -E \"0[6-7][0-4]0\" -ne 0 ";grep -P "^\h*\$FileCreateMode.*0[6-7][0-4]0" /etc/rsyslog.conf /etc/rsyslog.d/* 2>/dev/null | grep -E "0[6-7][0-4]0"; fi
|
|
if [ $(grep -Ev "FileCreateMode.*0[6-7][0-4]0" /etc/rsyslog.conf /etc/rsyslog.d/* 2>/dev/null | grep "^\$FileCreateMode" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -Ev \"FileCreateMode.*0[6-7][0-4]0\" /etc/rsyslog.conf /etc/rsyslog.d/* 2>/dev/null | grep \"^\\\$FileCreateMode\" -eq 0 ";grep -Ev "FileCreateMode.*0[6-7][0-4]0" /etc/rsyslog.conf /etc/rsyslog.d/* 2>/dev/null | grep "^\$FileCreateMode"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"4.1.1.2. Phân quyền đối với file log sinh ra từ rsyslog\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Chỉnh sửa file /etc/rsyslog.conf và /etc/rsyslog.d/*.conf và thêm vào 1 trong các dòng sau:
|
|
# <files to sent to the remote log server> action(type="omfwd" target="<FQDN or ip of loghost>" port="<port number>" protocol="tcp" action.resumeRetryCount="<number of re-tries>" queue.type="LinkedList" queue.size=<number of messages to queue>") # Hoặc
|
|
# *.* @@< FQDN or ip of loghost >
|
|
# Thực hiện câu lệnh sau để khởi động lại rsyslog:
|
|
# systemctl restart rsyslog
|
|
if [ $(grep -P "^\h*(local6|authpriv).*[^I][^I]*@" /etc/rsyslog.conf /etc/rsyslog.d/*.conf 2>/dev/null | wc -l) -eq 0 ] && [ $(grep -E '^\h*([^#]+\s+)?action\(([^#]+\s+)?\btarget=\"?[^#"]+\"?\b' /etc/rsyslog.conf /etc/rsyslog.d/*.conf 2>/dev/null | wc -l) -eq 0 ]; then
|
|
echo "{\"4.1.1.3. Cấu hình lưu trữ log sinh ra từ rsyslog tập trung\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Chỉnh sửa file /etc/rsyslog.conf và /etc/rsyslog.d/*.conf và thêm vào 1 trong các dòng sau:
|
|
# <files to sent to the remote log server> action(type=\"omfwd\" target=\"<FQDN or ip of loghost>\" port=\"<port number>\" protocol=\"tcp\" action.resumeRetryCount=\"<number of re-tries>\" queue.type=\"LinkedList\" queue.size=<number of messages to queue>\") # Hoặc
|
|
# *.* @@< FQDN or ip of loghost >
|
|
# Thực hiện câu lệnh sau để khởi động lại rsyslog:
|
|
# systemctl restart rsyslog"
|
|
if [ $(grep -P "^\h*(local6|authpriv).*[^I][^I]*@" /etc/rsyslog.conf /etc/rsyslog.d/*.conf 2>/dev/null | wc -l) -eq 0 ] && [ $(grep -E '^\h*([^#]+\s+)?action\(([^#]+\s+)?\btarget=\"?[^#"]+\"?\b' /etc/rsyslog.conf /etc/rsyslog.d/*.conf 2>/dev/null | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -P \"^\\h*\(local6|authpriv\).*[^I][^I]*@\" /etc/rsyslog.conf /etc/rsyslog.d/*.conf 2>/dev/null -ne 0 ";grep -P "^\h*(local6|authpriv).*[^I][^I]*@" /etc/rsyslog.conf /etc/rsyslog.d/*.conf 2>/dev/null; fi
|
|
if [ $(grep "^(local6|authpriv).*[^I][^I]*@" /etc/rsyslog.conf /etc/rsyslog.d/*.conf 2>/dev/null | wc -l) -eq 0 ] && [ $(grep -E '^\h*([^#]+\s+)?action\(([^#]+\s+)?\btarget=\"?[^#"]+\"?\b' /etc/rsyslog.conf /etc/rsyslog.d/*.conf 2>/dev/null | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -E '^\h*([^#]+\s+)?action\(([^#]+\s+)?\btarget=\\"?[^#\"]+\\"?\b' /etc/rsyslog.conf /etc/rsyslog.d/*.conf 2>/dev/null -ne 0 ";grep -E '^\h*([^#]+\s+)?action\(([^#]+\s+)?\btarget=\"?[^#"]+\"?\b' /etc/rsyslog.conf /etc/rsyslog.d/*.conf 2>/dev/null; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"4.1.1.3. Cấu hình lưu trữ log sinh ra từ rsyslog tập trung\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
echo -e "\n######################################"
|
|
if [[ $(grep -E "\s[6].[0-9]" /etc/os-release | wc -l) -ne 0 && $(find /var/log -type f -perm /g+wx,o+rwx -ls | wc -l) -ne 0 ]]; then
|
|
echo "{\"4.1.1.4. Phân quyền đối với tất cả các file log\" : \"FAILED\"}"
|
|
else
|
|
echo "{\"4.1.1.4. Phân quyền đối với tất cả các file log\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện câu lệnh sau để đặt quyền cho toàn bộ file log:
|
|
# find /var/log -type f -exec chmod g-wx,o-rwx {} +
|
|
if [ $(find /var/log -type f -perm /g+wx,o+rwx -ls | wc -l) -ne 0 ]; then
|
|
echo "{\"4.1.2. Phân quyền đối với tất cả các file log\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để đặt quyền cho toàn bộ file log:
|
|
# find /var/log -type f -exec chmod g-wx,o-rwx {} +"
|
|
if [ $(find /var/log -type f -perm /g+wx,o+rwx -ls | wc -l) -ne 0 ]; then echo "-------------------"; echo "#find /var/log -type f -perm /g+wx,o+rwx -ls -eq 0 ";find /var/log -type f -perm /g+wx,o+rwx -ls; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"4.1.2. Phân quyền đối với tất cả các file log\" : \"PASSED\"}"
|
|
fi
|
|
|
|
##################################################################################################################
|
|
# Thực hiện câu lệnh sau để kích hoạt cron:
|
|
# systemctl --now enable cron
|
|
if [ $(systemctl is-enabled cron | grep "^enabled$" | wc -l) -eq 0 ]; then
|
|
echo "{\"5.1.1. Cấu hình kích hoạt cron daemon\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để kích hoạt cron:
|
|
# systemctl --now enable cron"
|
|
if [ $(systemctl is-enabled cron | grep "^enabled$" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#systemctl is-enabled cron | grep \"^enabled\$\" -ne 0 ";systemctl is-enabled cron | grep "^enabled$"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.1.1. Cấu hình kích hoạt cron daemon\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện các câu lệnh sau để đảm bảo rằng để đặt chủ sở hữu và quyền cho file /etc/crontab:
|
|
# chown root:root /etc/crontab
|
|
# chmod og-rwx /etc/crontab
|
|
if [ $(stat /etc/crontab | grep "0*00.*Uid:.*0/.*root.*Gid:.*0/.*root" | wc -l) -eq 0 ]; then
|
|
echo "{\"5.1.2. Cấu hình phân quyền cho file /etc/crontab\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện các câu lệnh sau để đảm bảo rằng để đặt chủ sở hữu và quyền cho file /etc/crontab:
|
|
# chown root:root /etc/crontab
|
|
# chmod og-rwx /etc/crontab"
|
|
if [ $(stat /etc/crontab | grep "0*00.*Uid:.*0/.*root.*Gid:.*0/.*root" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#stat /etc/crontab | grep \"0*00.*Uid:.*0/.*root.*Gid:.*0/.*root\" -ne 0 ";stat /etc/crontab | grep "0*00.*Uid:.*0/.*root.*Gid:.*0/.*root"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.1.2. Cấu hình phân quyền cho file /etc/crontab\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện các câu lệnh sau để đặt chủ sở hữu và quyền cho file /etc/cron.hourly:
|
|
# chown root:root /etc/cron.hourly
|
|
# chmod og-rwx /etc/cron.hourly
|
|
if [ $(stat /etc/cron.hourly | grep "0*00.*Uid:.*0/.*root.*Gid:.*0/.*root" | wc -l) -eq 0 ]; then
|
|
echo "{\"5.1.3. Cấu hình phân quyền cho file /etc/cron.hourly\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện các câu lệnh sau để đặt chủ sở hữu và quyền cho file /etc/cron.hourly:
|
|
# chown root:root /etc/cron.hourly
|
|
# chmod og-rwx /etc/cron.hourly"
|
|
if [ $(stat /etc/cron.hourly | grep "0*00.*Uid:.*0/.*root.*Gid:.*0/.*root" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#stat /etc/cron.hourly | grep \"0*00.*Uid:.*0/.*root.*Gid:.*0/.*root\" -ne 0 ";stat /etc/cron.hourly | grep "0*00.*Uid:.*0/.*root.*Gid:.*0/.*root"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.1.3. Cấu hình phân quyền cho file /etc/cron.hourly\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện các câu lệnh sau và đặt chủ sở hữu và quyền cho file /etc/cron.daily:
|
|
# chown root:root /etc/cron.daily
|
|
# chmod og-rwx /etc/cron.daily
|
|
if [ $(stat /etc/cron.daily | grep "0*00.*Uid:.*0/.*root.*Gid:.*0/.*root" | wc -l) -eq 0 ]; then
|
|
echo "{\"5.1.4. Cấu hình phân quyền cho file /etc/cron.daily\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện các câu lệnh sau và đặt chủ sở hữu và quyền cho file /etc/cron.daily:
|
|
# chown root:root /etc/cron.daily
|
|
# chmod og-rwx /etc/cron.daily"
|
|
if [ $(stat /etc/cron.daily | grep "0*00.*Uid:.*0/.*root.*Gid:.*0/.*root" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#stat /etc/cron.daily | grep \"0*00.*Uid:.*0/.*root.*Gid:.*0/.*root\" -ne 0 ";stat /etc/cron.daily | grep "0*00.*Uid:.*0/.*root.*Gid:.*0/.*root"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.1.4. Cấu hình phân quyền cho file /etc/cron.daily\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện các câu lệnh sau để đặt chủ sở hữu và quyền cho file /etc/cron.weekly:
|
|
# chown root:root /etc/cron.weekly
|
|
# chmod og-rwx /etc/cron.weekly
|
|
if [ $(stat /etc/cron.weekly | grep "0*00.*Uid:.*0/.*root.*Gid:.*0/.*root" | wc -l) -eq 0 ]; then
|
|
echo "{\"5.1.5. Cấu hình phân quyền cho file /etc/cron.weekly\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện các câu lệnh sau để đặt chủ sở hữu và quyền cho file /etc/cron.weekly:
|
|
# chown root:root /etc/cron.weekly
|
|
# chmod og-rwx /etc/cron.weekly"
|
|
if [ $(stat /etc/cron.weekly | grep "0*00.*Uid:.*0/.*root.*Gid:.*0/.*root" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#stat /etc/cron.weekly | grep \"0*00.*Uid:.*0/.*root.*Gid:.*0/.*root\" -ne 0 ";stat /etc/cron.weekly | grep "0*00.*Uid:.*0/.*root.*Gid:.*0/.*root"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.1.5. Cấu hình phân quyền cho file /etc/cron.weekly\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện các câu lệnh sau để đặt chủ sở hữu và quyền cho file /etc/cron.monthly:
|
|
# chown root:root /etc/cron.monthly
|
|
# chmod og-rwx /etc/cron.monthly
|
|
if [ $(stat /etc/cron.monthly | grep "0*00.*Uid:.*0/.*root.*Gid:.*0/.*root" | wc -l) -eq 0 ]; then
|
|
echo "{\"5.1.6. Cấu hình phân quyền cho của file /etc/cron.monthly\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện các câu lệnh sau để đặt chủ sở hữu và quyền cho file /etc/cron.monthly:
|
|
# chown root:root /etc/cron.monthly
|
|
# chmod og-rwx /etc/cron.monthly"
|
|
if [ $(stat /etc/cron.monthly | grep "0*00.*Uid:.*0/.*root.*Gid:.*0/.*root" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#stat /etc/cron.monthly | grep \"0*00.*Uid:.*0/.*root.*Gid:.*0/.*root\" -ne 0 ";stat /etc/cron.monthly | grep "0*00.*Uid:.*0/.*root.*Gid:.*0/.*root"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.1.6. Cấu hình phân quyền cho của file /etc/cron.monthly\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện câu lệnh sau để đặt chủ sở hữu và quyền cho file /etc/cron.d:
|
|
# chown root:root /etc/cron.d
|
|
# chmod og-rwx /etc/cron.d
|
|
if [ $(stat /etc/cron.d | grep "0*00.*Uid:.*0/.*root.*Gid:.*0/.*root" | wc -l) -eq 0 ]; then
|
|
echo "{\"5.1.7. Cấu hình phân quyền cho file /etc/cron.d\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để đặt chủ sở hữu và quyền cho file /etc/cron.d:
|
|
# chown root:root /etc/cron.d
|
|
# chmod og-rwx /etc/cron.d"
|
|
if [ $(stat /etc/cron.d | grep "0*00.*Uid:.*0/.*root.*Gid:.*0/.*root" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#stat /etc/cron.d | grep \"0*00.*Uid:.*0/.*root.*Gid:.*0/.*root\" -ne 0 ";stat /etc/cron.d | grep "0*00.*Uid:.*0/.*root.*Gid:.*0/.*root"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.1.7. Cấu hình phân quyền cho file /etc/cron.d\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện các câu lệnh sau để xóa /etc/cron.deny và /etc/at.deny, tạo và đặt quyền và chủ sở hữu cho /etc/cron.allow và /etc/at.allow:
|
|
# rm /etc/cron.deny
|
|
# rm /etc/at.deny
|
|
# touch /etc/cron.allow
|
|
# touch /etc/at.allow
|
|
# chmod o-rwx /etc/cron.allow
|
|
# chmod g-wx /etc/cron.allow
|
|
# chmod o-rwx /etc/at.allow
|
|
# chmod g-wx /etc/at.allow
|
|
# chown root:root /etc/cron.allow
|
|
# chown root:root /etc/at.allow
|
|
if [ -e "/etc/cron.deny" ] || [ -e "/etc/at.deny" ] || [ $(stat /etc/cron.allow 2>/dev/null | grep "0*[04]0.*Uid:.*0/.*root.*Gid:.*0/.*root" | wc -l) -eq 0 ] || [ $(stat /etc/at.allow 2>/dev/null | grep "0*[04]0.*Uid:.*0/.*root.*Gid:.*0/.*root" | wc -l) -eq 0 ]; then
|
|
echo "{\"5.1.8. Cấu hình at/cron hạn chế chỉ cho người dùng được ủy quyền\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện các câu lệnh sau để xóa /etc/cron.deny và /etc/at.deny, tạo và đặt quyền và chủ sở hữu cho /etc/cron.allow và /etc/at.allow:
|
|
# rm /etc/cron.deny
|
|
# rm /etc/at.deny
|
|
# touch /etc/cron.allow
|
|
# touch /etc/at.allow
|
|
# chmod o-rwx /etc/cron.allow
|
|
# chmod g-wx /etc/cron.allow
|
|
# chmod o-rwx /etc/at.allow
|
|
# chmod g-wx /etc/at.allow
|
|
# chown root:root /etc/cron.allow
|
|
# chown root:root /etc/at.allow"
|
|
if [ -e "/etc/cron.deny" ]; then echo "-------------------";echo "Directory /etc/cron.deny exists"; fi
|
|
if [ -e "/etc/at.deny" ]; then echo "-------------------";echo "Directory /etc/at.deny exists"; fi
|
|
if [ $(stat /etc/cron.allow 2>/dev/null | grep "0*[04]0.*Uid:.*0/.*root.*Gid:.*0/.*root" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#stat /etc/cron.allow 2>/dev/null | grep \"0*[04]0.*Uid:.*0/.*root.*Gid:.*0/.*root\" -ne 0 ";stat /etc/cron.allow 2>/dev/null | grep "0*[04]0.*Uid:.*0/.*root.*Gid:.*0/.*root"; fi
|
|
if [ $(stat /etc/at.allow 2>/dev/null | grep "0*[04]0.*Uid:.*0/.*root.*Gid:.*0/.*root" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#stat /etc/at.allow 2>/dev/null | grep \"0*[04]0.*Uid:.*0/.*root.*Gid:.*0/.*root\" -ne 0 ";stat /etc/at.allow 2>/dev/null | grep "0*[04]0.*Uid:.*0/.*root.*Gid:.*0/.*root"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.1.8. Cấu hình at/cron hạn chế chỉ cho người dùng được ủy quyền\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện các câu lệnh sau để đặt chủ sở hữu và quyền cho file /etc/ssh/sshd_config:
|
|
# chown root:root /etc/ssh/sshd_config
|
|
# chmod og-rwx /etc/ssh/sshd_config
|
|
if [ $(stat /etc/ssh/sshd_config | grep "0*00.*Uid:.*0/.*root.*Gid:.*0/.*root" | wc -l) -eq 0 ]; then
|
|
echo "{\"5.2.1. Cấu hình phân quyền cho file /etc/ssh/sshd_config\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện các câu lệnh sau để đặt chủ sở hữu và quyền cho file /etc/ssh/sshd_config:
|
|
# chown root:root /etc/ssh/sshd_config
|
|
# chmod og-rwx /etc/ssh/sshd_config"
|
|
if [ $(stat /etc/ssh/sshd_config | grep "0*00.*Uid:.*0/.*root.*Gid:.*0/.*root" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#stat /etc/ssh/sshd_config | grep \"0*00.*Uid:.*0/.*root.*Gid:.*0/.*root\" -ne 0 ";stat /etc/ssh/sshd_config | grep "0*00.*Uid:.*0/.*root.*Gid:.*0/.*root"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.2.1. Cấu hình phân quyền cho file /etc/ssh/sshd_config\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện các câu lệnh sau để đặt chủ sở hữu và quyền cho các file SSH host private key:
|
|
# find /etc/ssh -xdev -type f -name 'ssh_host_*_key' -exec chmod u-x,g-wx,o-rwx {} \;
|
|
# find /etc/ssh -xdev -type f -name 'ssh_host_*_key' -exec chown root:ssh_keys {} \;
|
|
if [ $(find /etc/ssh -xdev -type f -name 'ssh_host_*_key' -exec stat {} \; | grep -E "Access:.*\(06[0-4]0.*Uid: \( *0/ +root\).*Gid: \( .*/( +root|ssh_keys)\)" | wc -l) -eq 0 ] || [ $(find /etc/ssh -xdev -type f -name 'ssh_host_*_key' -exec stat {} \; | grep -Ev "Access:.*\(06[0-4]0.*Uid: \( *0/ +root\).*Gid: \( .*/( +root|ssh_keys)\)" | grep "Access:.*Uid.*Gid" | wc -l) -ne 0 ]; then
|
|
echo "{\"5.2.2. Cấu hình phân quyền cho các file SSH private host key\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện các câu lệnh sau để đặt chủ sở hữu và quyền cho các file SSH host private key:
|
|
# find /etc/ssh -xdev -type f -name 'ssh_host_*_key' -exec chmod u-x,g-wx,o-rwx {} \;
|
|
# find /etc/ssh -xdev -type f -name 'ssh_host_*_key' -exec chown root:ssh_keys {} \;"
|
|
if [ $(find /etc/ssh -xdev -type f -name 'ssh_host_*_key' -exec stat {} \; | grep -E "Access:.*\(06[0-4]0.*Uid: \( *0/ +root\).*Gid: \( .*/( +root|ssh_keys)\)" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#find /etc/ssh -xdev -type f -name 'ssh_host_*_key' -exec stat {} \; | grep -E \"Access:.*\(06[0-4]0.*Uid: \( *0/ +root\).*Gid: \( .*/( +root|ssh_keys)\)\" -ne 0 ";find /etc/ssh -xdev -type f -name 'ssh_host_*_key' -exec stat {} \; | grep -E "Access:.*\(06[0-4]0.*Uid: \( *0/ +root\).*Gid: \( .*/( +root|ssh_keys)\)"; fi
|
|
if [ $(find /etc/ssh -xdev -type f -name 'ssh_host_*_key' -exec stat {} \; | grep -Ev "Access:.*\(06[0-4]0.*Uid: \( *0/ +root\).*Gid: \( .*/( +root|ssh_keys)\)" | grep "Access:.*Uid.*Gid" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#find /etc/ssh -xdev -type f -name 'ssh_host_*_key' -exec stat {} \; | grep -Ev \"Access:.*\(06[0-4]0.*Uid: \( *0/ +root\).*Gid: \( .*/( +root|ssh_keys)\)\" | grep \"Access:.*Uid.*Gid\" -eq 0 ";find /etc/ssh -xdev -type f -name 'ssh_host_*_key' -exec stat {} \; | grep -Ev "Access:.*\(06[0-4]0.*Uid: \( *0/ +root\).*Gid: \( .*/( +root|ssh_keys)\)" | grep "Access:.*Uid.*Gid"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.2.2. Cấu hình phân quyền cho các file SSH private host key\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện các câu lệnh sau để đặt quyền và chủ sở hữu cho các file SSH host public key:
|
|
# find /etc/ssh -xdev -type f -name 'ssh_host_*_key.pub' -exec chmod u-x,go-wx {} \;
|
|
# find /etc/ssh -xdev -type f -name 'ssh_host_*_key.pub' -exec chown root:root {} \;
|
|
if [ $(find /etc/ssh -xdev -type f -name 'ssh_host_*_key.pub' -exec stat {} \; | grep -E "Access:.*\(06[0-4][0-4].*Uid: \( *0/ +root\).*Gid: \( .*/( +root|ssh_keys)\)" | wc -l) -eq 0 ] || [ $(find /etc/ssh -xdev -type f -name 'ssh_host_*_key.pub' -exec stat {} \; | grep -Ev "Access:.*\(06[0-4][0-4].*Uid: \( *0/ +root\).*Gid: \( .*/( +root|ssh_keys)\)" | grep "Access:.*Uid.*Gid" | wc -l) -ne 0 ]; then
|
|
echo "{\"5.2.3. Cấu hình phân quyền cho các file SSH public host key\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện các câu lệnh sau để đặt quyền và chủ sở hữu cho các file SSH host public key:
|
|
# find /etc/ssh -xdev -type f -name 'ssh_host_*_key.pub' -exec chmod u-x,go-wx {} \;
|
|
# find /etc/ssh -xdev -type f -name 'ssh_host_*_key.pub' -exec chown root:root {} \;"
|
|
if [ $(find /etc/ssh -xdev -type f -name 'ssh_host_*_key.pub' -exec stat {} \; | grep -E "Access:.*\(06[0-4][0-4].*Uid: \( *0/ +root\).*Gid: \( .*/( +root|ssh_keys)\)" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#find /etc/ssh -xdev -type f -name 'ssh_host_*_key.pub' -exec stat {} \; | grep -E \"Access:.*\(06[0-4][0-4].*Uid: \( *0/ +root\).*Gid: \( .*/( +root|ssh_keys)\)\" -ne 0 ";find /etc/ssh -xdev -type f -name 'ssh_host_*_key.pub' -exec stat {} \; | grep -E "Access:.*\(06[0-4][0-4].*Uid: \( *0/ +root\).*Gid: \( .*/( +root|ssh_keys)\)"; fi
|
|
if [ $(find /etc/ssh -xdev -type f -name 'ssh_host_*_key.pub' -exec stat {} \; | grep -Ev "Access:.*\(06[0-4][0-4].*Uid: \( *0/ +root\).*Gid: \( .*/( +root|ssh_keys)\)" | grep "Access:.*Uid.*Gid" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#find /etc/ssh -xdev -type f -name 'ssh_host_*_key.pub' -exec stat {} \; | grep -Ev \"Access:.*\(06[0-4][0-4].*Uid: \( *0/ +root\).*Gid: \( .*/( +root|ssh_keys)\)\" | grep \"Access:.*Uid.*Gid\" -eq 0 ";find /etc/ssh -xdev -type f -name 'ssh_host_*_key.pub' -exec stat {} \; | grep -Ev "Access:.*\(06[0-4][0-4].*Uid: \( *0/ +root\).*Gid: \( .*/( +root|ssh_keys)\)" | grep "Access:.*Uid.*Gid"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.2.3. Cấu hình phân quyền cho các file SSH public host key\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Chỉnh sửa file /etc/ssh/sshd_config và đặt tham số như sau:
|
|
# AllowUsers <list of users>
|
|
# # Hoặc
|
|
# AllowGroups <list of groups>
|
|
# # Hoặc
|
|
# DenyUsers <list of users>
|
|
# # Hoặc
|
|
# DenyGroups <list of groups>
|
|
if [ $(sshd -T | grep -E '^\h*(allow|deny)(users|groups)\s+\S+' | wc -l) -eq 0 ]; then
|
|
echo "{\"5.2.4. Cấu hình giới hạn truy cập cho máy chủ SSH\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Chỉnh sửa file /etc/ssh/sshd_config và đặt tham số như sau:
|
|
# AllowUsers <list of users>
|
|
# # Hoặc
|
|
# AllowGroups <list of groups>
|
|
# # Hoặc
|
|
# DenyUsers <list of users>
|
|
# # Hoặc
|
|
# DenyGroups <list of groups>"
|
|
if [ $(sshd -T | grep -E '^\h*(allow|deny)(users|groups)\s+\S+' | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sshd -T | grep -E '^\h*(allow|deny)(users|groups)\s+\S+' -ne 0 ";sshd -T | grep -E '^\h*(allow|deny)(users|groups)\s+\S+'; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.2.4. Cấu hình giới hạn truy cập cho máy chủ SSH\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Chỉnh sửa file /etc/ssh/sshd_config và thêm một trong các tham số sau:
|
|
# LogLevel INFO
|
|
# # Hoặc
|
|
# LogLevel VERBOSE
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -P "^\h*loglevel.*(INFO|VERBOSE)" | wc -l) -eq 0 ] || [ $(grep -i 'loglevel' /etc/ssh/sshd_config | grep -Evi '(VERBOSE|INFO)' | wc -l) -ne 0 ]; then
|
|
echo "{\"5.2.5. Cấu hình LogLevel cho máy chủ SSH\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Chỉnh sửa file /etc/ssh/sshd_config và thêm một trong các tham số sau:
|
|
# LogLevel INFO
|
|
# # Hoặc
|
|
# LogLevel VERBOSE"
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -P "^\h*loglevel.*(INFO|VERBOSE)" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sshd -T -C user=root -C host=\"\$(hostname)\" -C addr=\"\$(grep \$(hostname) /etc/hosts | awk '{print \$1}')\" | grep -P \"^\\h*loglevel.*(INFO|VERBOSE)\" -ne 0 ";sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -P "^\h*loglevel.*(INFO|VERBOSE)"; fi
|
|
if [ $(grep -i 'loglevel' /etc/ssh/sshd_config | grep -Evi '(VERBOSE|INFO)' | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -i 'loglevel' /etc/ssh/sshd_config | grep -Evi '(VERBOSE|INFO)' -eq 0 ";grep -i 'loglevel' /etc/ssh/sshd_config | grep -Evi '(VERBOSE|INFO)'; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.2.5. Cấu hình LogLevel cho máy chủ SSH\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Chỉnh sửa file /etc/ssh/sshd_config và đặt tham số như sau:
|
|
# UsePAM yes
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -i "usepam.*yes" | wc -l) -eq 0 ] || [ $(grep -Ei '^\h*UsePAM\s+no' /etc/ssh/sshd_config | wc -l) -ne 0 ]; then
|
|
echo "{\"5.2.6. Cấu hình sử dụng SSH PAM\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Chỉnh sửa file /etc/ssh/sshd_config và đặt tham số như sau:
|
|
# UsePAM yes"
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -i "usepam.*yes" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sshd -T -C user=root -C host=\"\$(hostname)\" -C addr=\"\$(grep \$(hostname) /etc/hosts | awk '{print \$1}')\" | grep -i \"usepam.*yes\" -ne 0 ";sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -i "usepam.*yes"; fi
|
|
if [ $(grep -Ei '^\h*UsePAM\s+no' /etc/ssh/sshd_config | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -Ei '^\h*UsePAM\s+no' /etc/ssh/sshd_config -eq 0 ";grep -Ei '^\h*UsePAM\s+no' /etc/ssh/sshd_config; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.2.6. Cấu hình sử dụng SSH PAM\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Chỉnh sửa file /etc/ssh/sshd_config và đặt tham số như sau:
|
|
# PermitRootLogin no
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep "permitrootlogin.*no" | wc -l) -eq 0 ] || [ $(grep -Ei '^\h*PermitRootLogin\s+yes' /etc/ssh/sshd_config | wc -l) -ne 0 ]; then
|
|
echo "{\"5.2.7. Cấu hình vô hiệu hoá đăng nhập bằng root cho máy chủ SSH\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Chỉnh sửa file /etc/ssh/sshd_config và đặt tham số như sau:
|
|
# PermitRootLogin no"
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep "permitrootlogin.*no" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sshd -T -C user=root -C host=\"\$(hostname)\" -C addr=\"\$(grep \$(hostname) /etc/hosts | awk '{print \$1}')\" | grep "permitrootlogin.*no" -ne 0 ";sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep "permitrootlogin.*no"; fi
|
|
if [ $(grep -Ei '^\h*PermitRootLogin\s+yes' /etc/ssh/sshd_config | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -Ei '^\h*PermitRootLogin\s+yes' /etc/ssh/sshd_config -eq 0 ";grep -Ei '^\h*PermitRootLogin\s+yes' /etc/ssh/sshd_config; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.2.7. Cấu hình vô hiệu hoá đăng nhập bằng root cho máy chủ SSH\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Chỉnh sửa file /etc/ssh/sshd_config và đặt tham số như sau:
|
|
# HostbasedAuthentication no
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep "hostbasedauthentication.*no" | wc -l) -eq 0 ] || [ $(grep -Ei '^\h*HostbasedAuthentication\s+yes' /etc/ssh/sshd_config | wc -l) -ne 0 ]; then
|
|
echo "{\"5.2.8. Cấu hình vô hiệu hoá HostbasedAuthentication cho máy chủ SSH\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Chỉnh sửa file /etc/ssh/sshd_config và đặt tham số như sau:
|
|
# HostbasedAuthentication no"
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep "hostbasedauthentication.*no" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sshd -T -C user=root -C host=\"\$(hostname)\" -C addr=\"\$(grep \$(hostname) /etc/hosts | awk '{print \$1}')\" | grep \"hostbasedauthentication.*no\" -ne 0 ";sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep "hostbasedauthentication.*no"; fi
|
|
if [ $(grep -Ei '^\h*HostbasedAuthentication\s+yes' /etc/ssh/sshd_config | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -Ei '^\h*HostbasedAuthentication\s+yes' /etc/ssh/sshd_config -eq 0 ";grep -Ei '^\h*HostbasedAuthentication\s+yes' /etc/ssh/sshd_config; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.2.8. Cấu hình vô hiệu hoá HostbasedAuthentication cho máy chủ SSH\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Chỉnh sửa file /etc/ssh/sshd_config và đặt tham số như sau:
|
|
# PermitEmptyPasswords no
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep "permitemptypasswords.*no" | wc -l) -eq 0 ] || [ $(grep -Ei '^\h*PermitEmptyPasswords\s+yes' /etc/ssh/sshd_config | wc -l) -ne 0 ]; then
|
|
echo "{\"5.2.9. Cấu hình vô hiệu hoá PermitEmptyPasswords cho máy chủ SSH\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Chỉnh sửa file /etc/ssh/sshd_config và đặt tham số như sau:
|
|
# PermitEmptyPasswords no"
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep "permitemptypasswords.*no" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sshd -T -C user=root -C host=\"\$(hostname)\" -C addr=\"\$(grep \$(hostname) /etc/hosts | awk '{print \$1}')\" | grep \"permitemptypasswords.*no\" -ne 0 ";sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep "permitemptypasswords.*no"; fi
|
|
if [ $(grep -Ei '^\h*PermitEmptyPasswords\s+yes' /etc/ssh/sshd_config | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -Ei '^\h*PermitEmptyPasswords\s+yes' /etc/ssh/sshd_config -eq 0 ";grep -Ei '^\h*PermitEmptyPasswords\s+yes' /etc/ssh/sshd_config; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.2.9. Cấu hình vô hiệu hoá PermitEmptyPasswords cho máy chủ SSH\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Chỉnh sửa file /etc/ssh/sshd_config và đặt tham số như sau:
|
|
# PermitUserEnvironment no
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep "permituserenvironment.*no" | wc -l) -eq 0 ] || [ $(grep -Ei '^\h*PermitUserEnvironment\s+yes' /etc/ssh/sshd_config | wc -l) -ne 0 ]; then
|
|
echo "{\"5.2.10. Cấu hình vô hiệu hoá PermitUserEnviroment cho máy chủ SSH\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Chỉnh sửa file /etc/ssh/sshd_config và đặt tham số như sau:
|
|
# PermitUserEnvironment no"
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep "permituserenvironment.*no" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sshd -T -C user=root -C host=\"\$(hostname)\" -C addr=\"\$(grep \$(hostname) /etc/hosts | awk '{print \$1}')\" | grep \"permituserenvironment.*no\" -ne 0 ";sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep "permituserenvironment.*no"; fi
|
|
if [ $(grep -Ei '^\h*PermitUserEnvironment\s+yes' /etc/ssh/sshd_config | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -Ei '^\h*PermitUserEnvironment\s+yes' /etc/ssh/sshd_config -eq 0 ";grep -Ei '^\h*PermitUserEnvironment\s+yes' /etc/ssh/sshd_config; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.2.10. Cấu hình vô hiệu hoá PermitUserEnviroment cho máy chủ SSH\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Chỉnh sửa file /etc/ssh/sshd_config và đặt tham số như sau:
|
|
# IgnoreRhosts yes
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep "ignorerhosts.*yes" | wc -l) -eq 0 ] || [ $(grep -Ei '^\h*ignorerhosts\s+no\b' /etc/ssh/sshd_config | wc -l) -ne 0 ]; then
|
|
echo "{\"5.2.11. Cấu hình vô hiệu hoá IgnoreRhosts cho máy chủ SSH\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Chỉnh sửa file /etc/ssh/sshd_config và đặt tham số như sau:
|
|
# IgnoreRhosts yes"
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep "ignorerhosts.*yes" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sshd -T -C user=root -C host=\"\$(hostname)\" -C addr=\"\$(grep \$(hostname) /etc/hosts | awk '{print \$1}')\" | grep \"ignorerhosts.*yes\" -ne 0 ";sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep "ignorerhosts.*yes"; fi
|
|
if [ $(grep -Ei '^\h*ignorerhosts\s+no\b' /etc/ssh/sshd_config | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -Ei '^\h*ignorerhosts\s+no\b' /etc/ssh/sshd_config -eq 0 ";grep -Ei '^\h*ignorerhosts\s+no\b' /etc/ssh/sshd_config; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.2.11. Cấu hình vô hiệu hoá IgnoreRhosts cho máy chủ SSH\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Chỉnh sửa file /etc/ssh/sshd_config và đặt tham số như sau:
|
|
# X11Forwarding no
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -i "x11forwarding.*no" | wc -l) -eq 0 ] || [ $(grep -Ei '^\h*x11forwarding\s+yes' /etc/ssh/sshd_config | wc -l) -ne 0 ]; then
|
|
echo "{\"5.2.12. Cấu hình vô hiệu hoá X11 Forwarding cho máy chủ SSH\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Chỉnh sửa file /etc/ssh/sshd_config và đặt tham số như sau:
|
|
# X11Forwarding no"
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -i "x11forwarding.*no" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sshd -T -C user=root -C host=\"\$(hostname)\" -C addr=\"\$(grep \$(hostname) /etc/hosts | awk '{print \$1}')\" | grep -i \"x11forwarding.*no\" -ne 0 ";sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -i "x11forwarding.*no"; fi
|
|
if [ $(grep -Ei '^\h*x11forwarding\s+yes' /etc/ssh/sshd_config | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -Ei '^\h*x11forwarding\s+yes' /etc/ssh/sshd_config -eq 0 ";grep -Ei '^\h*x11forwarding\s+yes' /etc/ssh/sshd_config; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.2.12. Cấu hình vô hiệu hoá X11 Forwarding cho máy chủ SSH\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Chỉnh sửa file /etc/ssh/sshd_config và thêm/thay đổi dòng Ciphers để chứa danh sách thuật toán được chấp thuận, ví dụ:
|
|
# Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -Ei '^\s*ciphers\s+([^#]+,)?(3des-cbc|aes128-cbc|aes192-cbc|aes256-cbc|arcfour|arcfour128|arcfour256|blowfish-cbc|cast128-cbc|rijndael-cbc@lysator.liu.se)\b' | wc -l) -ne 0 ] || [ $(grep -Eis '^\s*ciphers\s+([^#]+,)?(3des-cbc|aes128-cbc|aes192-cbc|aes256-cbc|arcfour|arcfour128|arcfour256|blowfish-cbc|cast128-cbc|rijndael-cbc@lysator.liu.se)\b' /etc/ssh/sshd_config /etc/ssh/sshd_config.d/*.conf | wc -l) -ne 0 ] || [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -Pi "^\h*Ciphers\h*chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr\h*$" | wc -l) -eq 0 ]; then
|
|
echo "{\"5.2.13. Cấu hình sử dụng các thuật toán mã hoá được cho phép\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Chỉnh sửa file /etc/ssh/sshd_config và thêm/thay đổi dòng Ciphers để chứa danh sách thuật toán được chấp thuận, ví dụ:
|
|
# Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr"
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -Ei '^\s*ciphers\s+([^#]+,)?(3des-cbc|aes128-cbc|aes192-cbc|aes256-cbc|arcfour|arcfour128|arcfour256|blowfish-cbc|cast128-cbc|rijndael-cbc@lysator.liu.se)\b' | wc -l) -ne 0 ]; then echo "-------------------"; echo "#sshd -T -C user=root -C host=\"\$(hostname)\" -C addr=\"\$(grep \$(hostname) /etc/hosts | awk '{print \$1}')\" | grep -Ei '^\\s*ciphers\\s+([^#]+,)?(3des-cbc|aes128-cbc|aes192-cbc|aes256-cbc|arcfour|arcfour128|arcfour256|blowfish-cbc|cast128-cbc|rijndael-cbc@lysator.liu.se)\\b' -eq 0 ";sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -Ei '^\s*ciphers\s+([^#]+,)?(3des-cbc|aes128-cbc|aes192-cbc|aes256-cbc|arcfour|arcfour128|arcfour256|blowfish-cbc|cast128-cbc|rijndael-cbc@lysator.liu.se)\b'; fi
|
|
if [ $(grep -Eis '^\s*ciphers\s+([^#]+,)?(3des-cbc|aes128-cbc|aes192-cbc|aes256-cbc|arcfour|arcfour128|arcfour256|blowfish-cbc|cast128-cbc|rijndael-cbc@lysator.liu.se)\b' /etc/ssh/sshd_config /etc/ssh/sshd_config.d/*.conf | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -Eis '^\\s*ciphers\\s+([^#]+,)?(3des-cbc|aes128-cbc|aes192-cbc|aes256-cbc|arcfour|arcfour128|arcfour256|blowfish-cbc|cast128-cbc|rijndael-cbc@lysator.liu.se)\\b' /etc/ssh/sshd_config /etc/ssh/sshd_config.d/*.conf -eq 0 ";grep -Eis '^\s*ciphers\s+([^#]+,)?(3des-cbc|aes128-cbc|aes192-cbc|aes256-cbc|arcfour|arcfour128|arcfour256|blowfish-cbc|cast128-cbc|rijndael-cbc@lysator.liu.se)\b' /etc/ssh/sshd_config /etc/ssh/sshd_config.d/*.conf; fi
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -Pi "^\h*Ciphers\h*chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr\h*$" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sshd -T -C user=root -C host=\"\$(hostname)\" -C addr=\"\$(grep \$(hostname) /etc/hosts | awk '{print \$1}')\" | grep -Pi \"^\\h*Ciphers\\h*chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr\\h*\$\" -ne 0 ";sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -Pi "^\h*Ciphers\h*chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr\h*$"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.2.13. Cấu hình sử dụng các thuật toán mã hoá được cho phép\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Chỉnh sửa file /etc/ssh/sshd_config và thêm/thay đổi dòng MACs để chứa danh sách MAC được chấp thuận, ví dụ:
|
|
# MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512,hmac-sha2-256
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -Pi "^\h*MACs\h*hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512,hmac-sha2-256\h*$" | wc -l) -eq 0 ]; then
|
|
echo "{\"5.2.14. Cấu hình các thuật toán MAC được cho phép\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Chỉnh sửa file /etc/ssh/sshd_config và thêm/thay đổi dòng MACs để chứa danh sách MAC được chấp thuận, ví dụ:
|
|
# MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512,hmac-sha2-256"
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -Pi "^\h*MACs\h*hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512,hmac-sha2-256\h*$" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sshd -T -C user=root -C host=\"\$(hostname)\" -C addr=\"\$(grep \$(hostname) /etc/hosts | awk '{print \$1}')\" | grep -Pi \"^\\h*MACs\\h*hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512,hmac-sha2-256\\h*\$\" -ne 0 ";sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -Pi "^\h*MACs\h*hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512,hmac-sha2-256\h*$"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.2.14. Cấu hình các thuật toán MAC được cho phép\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Chỉnh sửa file /etc/ssh/sshd_config và thêm/thay đổi dòng KexAlgorithms để chứa danh sách thuật toán được chấp thuận, ví dụ:
|
|
# KexAlgorithms curve25519-sha256,curve25519-sha256@libssh.org,diffie-hellman-group14-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,ecdh-sha2-nistp521,ecdh-sha2-nistp384,ecdh-sha2-nistp256,diffie-hellman-group-exchange-sha256
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -Pi "^\h*KexAlgorithms\h*curve25519-sha256,curve25519-sha256@libssh.org,diffie-hellman-group14-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,ecdh-sha2-nistp521,ecdh-sha2-nistp384,ecdh-sha2-nistp256,diffie-hellman-group-exchange-sha256\h*$" | wc -l) -eq 0 ] || [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -Ei '^\s*kexalgorithms\s+([^#]+,)?(diffie-hellman-group1-sha1|diffie-hellman-group14-sha1|diffie-hellman-group-exchange-sha1)\b' | wc -l) -ne 0 ] || [ $(grep -Ei '^\s*kexalgorithms\s+([^#]+,)?(diffie-hellman-group1-sha1|diffie-hellman-group14-sha1|diffie-hellman-group-exchange-sha1)\b' /etc/ssh/sshd_config | wc -l) -ne 0 ]; then
|
|
echo "{\"5.2.15. Cấu hình thuật toán trao đổi khoá được cho phép\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Chỉnh sửa file /etc/ssh/sshd_config và thêm/thay đổi dòng KexAlgorithms để chứa danh sách thuật toán được chấp thuận, ví dụ:
|
|
# KexAlgorithms curve25519-sha256,curve25519-sha256@libssh.org,diffie-hellman-group14-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,ecdh-sha2-nistp521,ecdh-sha2-nistp384,ecdh-sha2-nistp256,diffie-hellman-group-exchange-sha256"
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -Pi "^\h*KexAlgorithms\h*curve25519-sha256,curve25519-sha256@libssh.org,diffie-hellman-group14-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,ecdh-sha2-nistp521,ecdh-sha2-nistp384,ecdh-sha2-nistp256,diffie-hellman-group-exchange-sha256\h*$" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sshd -T -C user=root -C host=\"\$(hostname)\" -C addr=\"\$(grep \$(hostname) /etc/hosts | awk '{print \$1}')\" | grep -Pi \"^\\h*KexAlgorithms\\h*curve25519-sha256,curve25519-sha256@libssh.org,diffie-hellman-group14-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,ecdh-sha2-nistp521,ecdh-sha2-nistp384,ecdh-sha2-nistp256,diffie-hellman-group-exchange-sha256\\h*\$\" -ne 0 ";sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -Pi "^\h*KexAlgorithms\h*curve25519-sha256,curve25519-sha256@libssh.org,diffie-hellman-group14-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,ecdh-sha2-nistp521,ecdh-sha2-nistp384,ecdh-sha2-nistp256,diffie-hellman-group-exchange-sha256\h*$"; fi
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -Ei '^\s*kexalgorithms\s+([^#]+,)?(diffie-hellman-group1-sha1|diffie-hellman-group14-sha1|diffie-hellman-group-exchange-sha1)\b' | wc -l) -ne 0 ]; then echo "-------------------"; echo "#sshd -T -C user=root -C host=\"\$(hostname)\" -C addr=\"\$(grep \$(hostname) /etc/hosts | awk '{print \$1}')\" | grep -Ei '^\\s*kexalgorithms\\s+([^#]+,)?(diffie-hellman-group1-sha1|diffie-hellman-group14-sha1|diffie-hellman-group-exchange-sha1)\\b' -eq 0 ";sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -Ei '^\s*kexalgorithms\s+([^#]+,)?(diffie-hellman-group1-sha1|diffie-hellman-group14-sha1|diffie-hellman-group-exchange-sha1)\b'; fi
|
|
if [ $(grep -Ei '^\s*kexalgorithms\s+([^#]+,)?(diffie-hellman-group1-sha1|diffie-hellman-group14-sha1|diffie-hellman-group-exchange-sha1)\b' /etc/ssh/sshd_config | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -Ei '^\\s*kexalgorithms\\s+([^#]+,)?(diffie-hellman-group1-sha1|diffie-hellman-group14-sha1|diffie-hellman-group-exchange-sha1)\\b' /etc/ssh/sshd_config -eq 0 ";grep -Ei '^\s*kexalgorithms\s+([^#]+,)?(diffie-hellman-group1-sha1|diffie-hellman-group14-sha1|diffie-hellman-group-exchange-sha1)\b' /etc/ssh/sshd_config; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.2.15. Cấu hình thuật toán trao đổi khoá được cho phép\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Chỉnh sửa file /etc/ssh/sshd_config và đặt tham số như sau:
|
|
# AllowTcpForwarding no
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -Pi "^\h*AllowTcpForwarding\h*no\h*$" | wc -l) -eq 0 ] || [ $(grep -Pi '^\h*AllowTcpForwarding\h*yes\h*$' /etc/ssh/sshd_config | wc -l) -ne 0 ]; then
|
|
echo "{\"5.2.16. Cấu hình vô hiệu hoá SSH AllowTcpForwarding\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Chỉnh sửa file /etc/ssh/sshd_config và đặt tham số như sau:
|
|
# AllowTcpForwarding no"
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -Pi "^\h*AllowTcpForwarding\h*no\h*$" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sshd -T -C user=root -C host=\"\$(hostname)\" -C addr=\"\$(grep \$(hostname) /etc/hosts | awk '{print \$1}')\" | grep -Pi \"^\\h*AllowTcpForwarding\\h*no\\h*\$\" -ne 0 ";sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -Pi "^\h*AllowTcpForwarding\h*no\h*$"; fi
|
|
if [ $(grep -Pi '^\h*AllowTcpForwarding\h*yes\h*$' /etc/ssh/sshd_config | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -Pi '^\\h*AllowTcpForwarding\\h*yes\\h*\$' /etc/ssh/sshd_config -eq 0 ";grep -Pi '^\h*AllowTcpForwarding\h*yes\h*$' /etc/ssh/sshd_config; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.2.16. Cấu hình vô hiệu hoá SSH AllowTcpForwarding\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Chỉnh sửa file /etc/ssh/sshd_config và đặt tham số như sau:
|
|
# Banner /etc/issue.net
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep "^banner.*/etc/issue.net" | wc -l) -eq 0 ] || [ $(grep -Ei '^\h*Banner\s+/etc/issue\.net' /etc/ssh/sshd_config | wc -l) -eq 0 ]; then
|
|
echo "{\"5.2.17. Cấu hình cảnh báo SSH\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Chỉnh sửa file /etc/ssh/sshd_config và đặt tham số như sau:
|
|
# Banner /etc/issue.net"
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep "^banner.*/etc/issue.net" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sshd -T -C user=root -C host=\"\$(hostname)\" -C addr=\"\$(grep \$(hostname) /etc/hosts | awk '{print \$1}')\" | grep \"^banner.*/etc/issue.net\" -ne 0 ";sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep "^banner.*/etc/issue.net"; fi
|
|
if [ $(grep -Ei '^\h*Banner\s+/etc/issue\.net' /etc/ssh/sshd_config | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -Ei '^\h*Banner\s+/etc/issue\.net' /etc/ssh/sshd_config -ne 0 ";grep -Ei '^\h*Banner\s+/etc/issue\.net' /etc/ssh/sshd_config; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.2.17. Cấu hình cảnh báo SSH\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Chỉnh sửa file /etc/ssh/sshd_config và đặt tham số như sau hoặc nhỏ hơn:
|
|
# MaxAuthTries 4
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep "maxauthtries\s[0-4]" | wc -l) -eq 0 ] || [ $(grep -Ei '^\h*maxauthtries\s+([5-9]|[1-9][0-9]+)' /etc/ssh/sshd_config | wc -l) -ne 0 ]; then
|
|
echo "{\"5.2.18. Cấu hình SSH MaxAuthTries\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Chỉnh sửa file /etc/ssh/sshd_config và đặt tham số như sau hoặc nhỏ hơn:
|
|
# MaxAuthTries 4"
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep "maxauthtries\s[0-4]" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sshd -T -C user=root -C host=\"\$(hostname)\" -C addr=\"\$(grep \$(hostname) /etc/hosts | awk '{print \$1}')\" | grep \"maxauthtries\s[0-4]\" -ne 0 ";sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep "maxauthtries\s[0-4]"; fi
|
|
if [ $(grep -Ei '^\h*maxauthtries\s+([5-9]|[1-9][0-9]+)' /etc/ssh/sshd_config | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -Ei '^\h*maxauthtries\s+([5-9]|[1-9][0-9]+)' /etc/ssh/sshd_config -eq 0 ";grep -Ei '^\h*maxauthtries\s+([5-9]|[1-9][0-9]+)' /etc/ssh/sshd_config; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.2.18. Cấu hình SSH MaxAuthTries\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Chỉnh sửa file /etc/ssh/sshd_config và đặt tham số như sau:
|
|
# MaxStartups 10:30:60
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -Ei "maxstartups\s10:30:60" | wc -l) -eq 0 ] || [ $(grep -Ei '^\h*maxstartups\s+(((1[1-9]|[1-9][0-9][0-9]+):([0-9]+):([0-9]+))|(([0-9]+):(3[1-9]|[4-9][0-9]|[1-9][0-9][0-9]+):([0-9]+))|(([0-9]+):([0-9]+):(6[1-9]|[7-9][0-9]|[1-9][0-9][0-9]+)))' /etc/ssh/sshd_config | wc -l) -ne 0 ]; then
|
|
echo "{\"5.2.19. Cấu hình SSH MaxStartups\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Chỉnh sửa file /etc/ssh/sshd_config và đặt tham số như sau:
|
|
# MaxStartups 10:30:60"
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -Ei "maxstartups\s10:30:60" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sshd -T -C user=root -C host=\"\$(hostname)\" -C addr=\"\$(grep \$(hostname) /etc/hosts | awk '{print \$1}')\" | grep -Ei \"maxstartups\s10:30:60\" -ne 0 ";sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -Ei "maxstartups\s10:30:60"; fi
|
|
if [ $(grep -Ei '^\h*maxstartups\s+(((1[1-9]|[1-9][0-9][0-9]+):([0-9]+):([0-9]+))|(([0-9]+):(3[1-9]|[4-9][0-9]|[1-9][0-9][0-9]+):([0-9]+))|(([0-9]+):([0-9]+):(6[1-9]|[7-9][0-9]|[1-9][0-9][0-9]+)))' /etc/ssh/sshd_config | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -Ei '^\h*maxstartups\s+(((1[1-9]|[1-9][0-9][0-9]+):([0-9]+):([0-9]+))|(([0-9]+):(3[1-9]|[4-9][0-9]|[1-9][0-9][0-9]+):([0-9]+))|(([0-9]+):([0-9]+):(6[1-9]|[7-9][0-9]|[1-9][0-9][0-9]+)))' /etc/ssh/sshd_config -eq 0 ";grep -Ei '^\h*maxstartups\s+(((1[1-9]|[1-9][0-9][0-9]+):([0-9]+):([0-9]+))|(([0-9]+):(3[1-9]|[4-9][0-9]|[1-9][0-9][0-9]+):([0-9]+))|(([0-9]+):([0-9]+):(6[1-9]|[7-9][0-9]|[1-9][0-9][0-9]+)))' /etc/ssh/sshd_config; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.2.19. Cấu hình SSH MaxStartups\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Chỉnh sửa file /etc/ssh/sshd_config và đặt tham số như sau hoặc nhỏ hơn:
|
|
# MaxSessions 10
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -Ei "maxsessions\s([1-9]|10)" | wc -l) -eq 0 ] || [ $(grep -Ei '^\h*MaxSessions\s+(0|1[1-9]|[2-9][0-9]|[1-9][0-9][0-9]+)' /etc/ssh/sshd_config | wc -l) -ne 0 ]; then
|
|
echo "{\"5.2.20. Cấu hình SSH MaxSessions\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Chỉnh sửa file /etc/ssh/sshd_config và đặt tham số như sau hoặc nhỏ hơn:
|
|
# MaxSessions 10"
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -Ei "maxsessions\s([1-9]|10)" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sshd -T -C user=root -C host=\"\$(hostname)\" -C addr=\"\$(grep \$(hostname) /etc/hosts | awk '{print \$1}')\" | grep -Ei \"maxsessions\s([1-9]|10)\" -ne 0 ";sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -Ei "maxsessions\s([1-9]|10)"; fi
|
|
if [ $(grep -Ei '^\h*MaxSessions\s+(0|1[1-9]|[2-9][0-9]|[1-9][0-9][0-9]+)' /etc/ssh/sshd_config | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -Ei '^\h*MaxSessions\s+(0|1[1-9]|[2-9][0-9]|[1-9][0-9][0-9]+)' /etc/ssh/sshd_config -eq 0 ";grep -Ei '^\h*MaxSessions\s+(0|1[1-9]|[2-9][0-9]|[1-9][0-9][0-9]+)' /etc/ssh/sshd_config; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.2.20. Cấu hình SSH MaxSessions\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Chỉnh sửa file /etc/ssh/sshd_config và đặt tham số như sau hoặc bé hơn:
|
|
# LoginGraceTime 60
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -E "logingracetime\s([1-9]|[1-5][0-9]|60)" | wc -l) -eq 0 ] || [ $(grep -Ei '^\h*LoginGraceTime\s+(0|6[1-9]|[7-9][0-9]|[1-9][0-9][0-9]+|[^1]m)' /etc/ssh/sshd_config | wc -l) -ne 0 ]; then
|
|
echo "{\"5.2.21. Cấu hình SSH LoginGraceTime\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Chỉnh sửa file /etc/ssh/sshd_config và đặt tham số như sau hoặc bé hơn:
|
|
# LoginGraceTime 60"
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -E "logingracetime\s([1-9]|[1-5][0-9]|60)" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sshd -T -C user=root -C host=\"\$(hostname)\" -C addr=\"\$(grep \$(hostname) /etc/hosts | awk '{print \$1}')\" | grep -E \"logingracetime\s([1-9]|[1-5][0-9]|60)\" -ne 0 ";sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -E "logingracetime\s([1-9]|[1-5][0-9]|60)"; fi
|
|
if [ $(grep -Ei '^\h*LoginGraceTime\s+(0|6[1-9]|[7-9][0-9]|[1-9][0-9][0-9]+|[^1]m)' /etc/ssh/sshd_config | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -Ei '^\h*LoginGraceTime\s+(0|6[1-9]|[7-9][0-9]|[1-9][0-9][0-9]+|[^1]m)' /etc/ssh/sshd_config -eq 0 ";grep -Ei '^\h*LoginGraceTime\s+(0|6[1-9]|[7-9][0-9]|[1-9][0-9][0-9]+|[^1]m)' /etc/ssh/sshd_config; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.2.21. Cấu hình SSH LoginGraceTime\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Chỉnh sửa file /etc/ssh/sshd_config và đặt tham số như sau:
|
|
# ClientAliveInterval 900
|
|
# ClientAliveCountMax 0
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -E "clientaliveinterval\s([6-8][0-9][0-9]|900)" | wc -l) -eq 0 ] || [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -E "clientalivecountmax\s0" | wc -l) -eq 0 ] || [ $(grep -Ei '^\h*ClientAliveInterval\s+(0|9[0-9][1-9]|[1-9][0-9][0-9][0-9]+|1[6-9]m|[2-9][0-9]m|[1-9][0-9][0-9]+m)\b' /etc/ssh/sshd_config | wc -l) -ne 0 ] || [ $(grep -Ei '^\h*ClientAliveCountMax\s+([1-9]|[1-9][0-9]+)\b' /etc/ssh/sshd_config | wc -l) -ne 0 ]; then
|
|
echo "{\"5.2.22. Cấu hình khoảng thời gian chờ không hoạt động cho máy chủ SSH\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Chỉnh sửa file /etc/ssh/sshd_config và đặt tham số như sau:
|
|
# ClientAliveInterval 900
|
|
# ClientAliveCountMax 0"
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -E "clientaliveinterval\s([6-8][0-9][0-9]|900)" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sshd -T -C user=root -C host=\"\$(hostname)\" -C addr=\"\$(grep \$(hostname) /etc/hosts | awk '{print \$1}')\" | grep -E \"clientaliveinterval\s([6-8][0-9][0-9]|900)\" -ne 0 ";sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -E "clientaliveinterval\s([1-8][0-9][0-9]|900)"; fi
|
|
if [ $(sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -E "clientalivecountmax\s0" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#sshd -T -C user=root -C host=\"\$(hostname)\" -C addr=\"\$(grep \$(hostname) /etc/hosts | awk '{print \$1}')\" | grep -E \"clientalivecountmax\s0\" -ne 0 ";sshd -T -C user=root -C host="$(hostname)" -C addr="$(grep $(hostname) /etc/hosts | awk '{print $1}')" | grep -E "clientalivecountmax\s0"; fi
|
|
if [ $(grep -Ei '^\h*ClientAliveInterval\s+(0|9[0-9][1-9]|[1-9][0-9][0-9][0-9]+|1[6-9]m|[2-9][0-9]m|[1-9][0-9][0-9]+m)\b' /etc/ssh/sshd_config | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -Ei '^\h*ClientAliveInterval\s+(0|9[0-9][1-9]|[1-9][0-9][0-9][0-9]+|1[6-9]m|[2-9][0-9]m|[1-9][0-9][0-9]+m)\b' /etc/ssh/sshd_config -eq 0 ";grep -Ei '^\h*ClientAliveInterval\s+(0|9[0-9][1-9]|[1-9][0-9][0-9][0-9]+|1[6-9]m|[2-9][0-9]m|[1-9][0-9][0-9]+m)\b' /etc/ssh/sshd_config; fi
|
|
if [ $(grep -Ei '^\h*ClientAliveCountMax\s+([1-9]|[1-9][0-9]+)\b' /etc/ssh/sshd_config | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -Ei '^\h*ClientAliveCountMax\s+([1-9]|[1-9][0-9]+)\b' /etc/ssh/sshd_config -eq 0 ";grep -Ei '^\h*ClientAliveCountMax\s+([1-9]|[1-9][0-9]+)\b' /etc/ssh/sshd_config; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.2.22. Cấu hình khoảng thời gian chờ không hoạt động cho máy chủ SSH\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện câu lệnh sau để cài đặt pam_pwquality:
|
|
# apt install libpam-pwquality
|
|
# Chỉnh sửa file /etc/security/pwquality.conf để thêm hoặc cập nhật một trong những thiết lập sau:
|
|
# minlen = 8
|
|
# enforce_for_root
|
|
# minclass = 4
|
|
# # Hoặc
|
|
# minlen = 8
|
|
# enforce_for_root
|
|
# dcredit = -1
|
|
# ucredit = -1
|
|
# ocredit = -1
|
|
# lcredit = -1
|
|
# *Lưu ý: Các thiết lập trong file /etc/security/pwquality.conf phải sử dụng dấu cách xung quanh dấu “=”.
|
|
if [ $(dpkg -l | grep "ii libpam-pwquality" | wc -l) -eq 0 ] || [ $(grep -P "^\h*minlen = ([8-9]|[1-9][0-9])" /etc/security/pwquality.conf | wc -l) -eq 0 ] || [ $(grep -P "^\h*enforce_for_root" /etc/security/pwquality.conf | wc -l) -eq 0 ] || [[ ($(grep "^minclass = 4" /etc/security/pwquality.conf | wc -l) -eq 0 && ($(grep "^dcredit = -1" /etc/security/pwquality.conf | wc -l) -eq 0 || $(grep "^ucredit = -1" /etc/security/pwquality.conf | wc -l) -eq 0 || $(grep "^ocredit = -1" /etc/security/pwquality.conf | wc -l) -eq 0 || $(grep "^lcredit = -1" /etc/security/pwquality.conf | wc -l) -eq 0)) ]]; then
|
|
echo "{\"5.3.1. Cấu hình điều kiện tạo mật khẩu\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để cài đặt pam_pwquality:
|
|
# apt install libpam-pwquality
|
|
# Chỉnh sửa file /etc/security/pwquality.conf để thêm hoặc cập nhật một trong những thiết lập sau:
|
|
# minlen = 8
|
|
# enforce_for_root
|
|
# minclass = 4
|
|
# # Hoặc
|
|
# minlen = 8
|
|
# enforce_for_root
|
|
# dcredit = -1
|
|
# ucredit = -1
|
|
# ocredit = -1
|
|
# lcredit = -1
|
|
# *Lưu ý: Các thiết lập trong file /etc/security/pwquality.conf phải sử dụng dấu cách xung quanh dấu “=”."
|
|
if [ $(dpkg -l | grep "ii libpam-pwquality" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#dpkg -l | grep \"ii libpam-pwquality\" -ne 0 ";dpkg -l | grep "ii libpam-pwquality"; fi
|
|
if [ $(grep -P "^\h*minlen = ([8-9]|[1-9][0-9])" /etc/security/pwquality.conf | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -P \"^\\h*minlen = ([8-9]|[1-9][0-9])\" /etc/security/pwquality.conf -ne 0 ";grep -P "^\h*minlen = ([8-9]|[1-9][0-9])" /etc/security/pwquality.conf; fi
|
|
if [ $(grep -P "^\h*enforce_for_root" /etc/security/pwquality.conf | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -P \"^\\h*enforce_for_root\" /etc/security/pwquality.conf -ne 0 ";grep -P "^\h*enforce_for_root" /etc/security/pwquality.conf; fi
|
|
if [ $(grep "^minclass = 4" /etc/security/pwquality.conf | wc -l) -eq 0 ] && [[ ($(grep "^dcredit = -1" /etc/security/pwquality.conf | wc -l) -eq 0 || $(grep "^ucredit = -1" /etc/security/pwquality.conf | wc -l) -eq 0 || $(grep "^ocredit = -1" /etc/security/pwquality.conf | wc -l) -eq 0 || $(grep "^lcredit = -1" /etc/security/pwquality.conf | wc -l) -eq 0) ]]; then echo "-------------------"; echo "#grep \"^minclass = 4\" /etc/security/pwquality.conf -ne 0 ";grep "^minclass = 4" /etc/security/pwquality.conf; fi
|
|
if [ $(grep "^minclass = 4" /etc/security/pwquality.conf | wc -l) -eq 0 ] && [ $(grep "^dcredit = -1" /etc/security/pwquality.conf | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep \"^dcredit = -1\" /etc/security/pwquality.conf -ne 0 ";grep "^dcredit = -1" /etc/security/pwquality.conf; fi
|
|
if [ $(grep "^minclass = 4" /etc/security/pwquality.conf | wc -l) -eq 0 ] && [ $(grep "^ucredit = -1" /etc/security/pwquality.conf | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep \"^ucredit = -1\" /etc/security/pwquality.conf -ne 0 ";grep "^ucredit = -1" /etc/security/pwquality.conf; fi
|
|
if [ $(grep "^minclass = 4" /etc/security/pwquality.conf | wc -l) -eq 0 ] && [ $(grep "^ocredit = -1" /etc/security/pwquality.conf | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep \"^ocredit = -1\" /etc/security/pwquality.conf -ne 0 ";grep "^ocredit = -1" /etc/security/pwquality.conf; fi
|
|
if [ $(grep "^minclass = 4" /etc/security/pwquality.conf | wc -l) -eq 0 ] && [ $(grep "^lcredit = -1" /etc/security/pwquality.conf | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep \"^lcredit = -1\" /etc/security/pwquality.conf -ne 0 ";grep "^lcredit = -1" /etc/security/pwquality.conf; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.3.1. Cấu hình điều kiện tạo mật khẩu\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Đối với phiên bản 22.04 trở lên:
|
|
# Chỉnh sửa file /etc/pam.d/common-auth để thêm hoặc cập nhật những thiết lập sau, thứ tự các cấu hình phải theo mẫu (bao quanh dòng chứa pam_unix.so và trước dòng pam_deny.so, các dòng này có sẵn trong file):
|
|
# auth required pam_faillock.so preauth
|
|
# # pam_unix.so có sẵn trong file
|
|
# auth [success=1 default=ignore] pam_unix.so nullok
|
|
# auth [default=die] pam_faillock.so authfail
|
|
# auth sufficient pam_faillock.so authsucc
|
|
# # pam_deny.so có sẵn trong file
|
|
# auth requisite pam_deny.so
|
|
# Thêm dòng sau vào cuối file /etc/pam.d/common-account:
|
|
# account required pam_faillock.so
|
|
# Chỉnh sửa file /etc/security/faillock.conf để thêm hoặc cập nhật những thiết lập sau:
|
|
# deny = 5
|
|
# fail_interval = 900
|
|
# unlock time = 900
|
|
# Đối với phiên bản 20.04 trở về trước:
|
|
# Chỉnh sửa file /etc/pam.d/common-auth và thêm dòng sau:
|
|
# auth required pam_tally2.so onerr=fail audit silent deny=5 unlock_time=900
|
|
# Chỉnh sửa file /etc/pam.d/common-account và thêm các dòng sau:
|
|
# account requisite pam_deny.so
|
|
# account required pam_tally2.so
|
|
# *Lưu ý: Nếu người dùng bị khóa do đã thử quá số lần cho phép, được định danh ở tham số deny= trong mô-đun pam_faillock.so, người dùng đó có thể được mở khóa bằng cách sử dụng lệnh /usr/sbin/faillock --user username --reset. Câu lệnh này sẽ reset lại số lần thử không thành công xuống 0. Nếu câu lệnh trên không hoạt động thử câu lệnh sau để reset số lần không thành công xuống 0: pam_tally2 --user <username> --reset.
|
|
# 22.04+ (faillock)
|
|
if grep -Eq 'VERSION_ID="(2[2-9]|[3-9][0-9])\.' /etc/os-release; then
|
|
if \
|
|
! grep -Pq '^\h*auth\h*required\h*pam_faillock\.so.*preauth' /etc/pam.d/common-auth || \
|
|
! grep -Pq '^\h*auth\h*\[default=die\]\h*pam_faillock\.so.*authfail' /etc/pam.d/common-auth || \
|
|
! grep -Pq '^\h*auth\h*sufficient\h*pam_faillock\.so.*authsucc' /etc/pam.d/common-auth || \
|
|
! grep -Pq '^\h*account\h*required\h*pam_faillock\.so' /etc/pam.d/common-account || \
|
|
! grep -Pq '^\h*deny\h*=\h*5' /etc/security/faillock.conf || \
|
|
! grep -Pq '^\h*fail_interval\h*=\h*900' /etc/security/faillock.conf || \
|
|
! grep -Pq '^\h*unlock_time\h*=\h*900' /etc/security/faillock.conf
|
|
then
|
|
echo '{"5.3.2. Cấu hình khoá truy cập do nhiều lần nhập mật khẩu thất bại" : "FAILED"}'
|
|
echo "######################################"
|
|
echo "# HƯỚNG DẪN CHO 22.04+:"
|
|
echo "# /etc/pam.d/common-auth (đặt quanh pam_unix.so và trước pam_deny.so):"
|
|
echo "# auth required pam_faillock.so preauth"
|
|
echo "# auth [success=1 default=ignore] pam_unix.so nullok"
|
|
echo "# auth [default=die] pam_faillock.so authfail"
|
|
echo "# auth sufficient pam_faillock.so authsucc"
|
|
echo "# auth requisite pam_deny.so"
|
|
echo "# /etc/pam.d/common-account: account required pam_faillock.so"
|
|
echo "# /etc/security/faillock.conf:"
|
|
echo "# deny = 5"
|
|
echo "# fail_interval = 900"
|
|
echo "# unlock_time = 900"
|
|
echo "# Mở khoá: faillock --user <username> --reset"
|
|
|
|
# Chỉ ra mục thiếu
|
|
if ! grep -Pq '^\h*auth\h*required\h*pam_faillock\.so.*preauth' /etc/pam.d/common-auth; then
|
|
echo "-------------------"; echo "# Thiếu: auth required pam_faillock.so preauth (common-auth)"; grep -Pn 'pam_faillock\.so' /etc/pam.d/common-auth
|
|
fi
|
|
if ! grep -Pq '^\h*auth\h*\[default=die\]\h*pam_faillock\.so.*authfail' /etc/pam.d/common-auth; then
|
|
echo "-------------------"; echo "# Thiếu: auth [default=die] pam_faillock.so authfail (common-auth)"
|
|
fi
|
|
if ! grep -Pq '^\h*auth\h*sufficient\h*pam_faillock\.so.*authsucc' /etc/pam.d/common-auth; then
|
|
echo "-------------------"; echo "# Thiếu: auth sufficient pam_faillock.so authsucc (common-auth)"
|
|
fi
|
|
if ! grep -Pq '^\h*account\h*required\h*pam_faillock\.so' /etc/pam.d/common-account; then
|
|
echo "-------------------"; echo "# Thiếu: account required pam_faillock.so (common-account)"
|
|
fi
|
|
if ! grep -Pq '^\h*deny\h*=\h*5' /etc/security/faillock.conf; then
|
|
echo "-------------------"; echo "# Thiếu: deny = 5 (faillock.conf)"
|
|
fi
|
|
if ! grep -Pq '^\h*fail_interval\h*=\h*900' /etc/security/faillock.conf; then
|
|
echo "-------------------"; echo "# Thiếu: fail_interval = 900 (faillock.conf)"
|
|
fi
|
|
if ! grep -Pq '^\h*unlock_time\h*=\h*900' /etc/security/faillock.conf; then
|
|
echo "-------------------"; echo "# Thiếu: unlock_time = 900 (faillock.conf)"
|
|
fi
|
|
echo "######################################"
|
|
else
|
|
echo '{"5.3.2. Cấu hình khoá truy cập do nhiều lần nhập mật khẩu thất bại" : "PASSED"}'
|
|
fi
|
|
|
|
# ≤ 20.04 (tally2)
|
|
else
|
|
if \
|
|
! grep -Pq '^\h*auth\h*required\h*pam_tally2\.so.*onerr=fail.*deny=5.*unlock_time=900' /etc/pam.d/common-auth || \
|
|
! grep -Pq '^\h*account\h*requisite\h*pam_deny\.so' /etc/pam.d/common-account || \
|
|
! grep -Pq '^\h*account\h*required\h*pam_tally2\.so' /etc/pam.d/common-account
|
|
then
|
|
echo '{"5.3.2. Cấu hình khoá truy cập do nhiều lần nhập mật khẩu thất bại" : "FAILED"}'
|
|
echo "######################################"
|
|
echo "# HƯỚNG DẪN CHO ≤20.04:"
|
|
echo "# /etc/pam.d/common-auth:"
|
|
echo "# auth required pam_tally2.so onerr=fail audit silent deny=5 unlock_time=900"
|
|
echo "# /etc/pam.d/common-account:"
|
|
echo "# account requisite pam_deny.so"
|
|
echo "# account required pam_tally2.so"
|
|
echo "# Mở khoá (nếu dùng tally2): pam_tally2 --user <username> --reset"
|
|
|
|
# Chỉ ra mục thiếu
|
|
if ! grep -Pq '^\h*auth\h*required\h*pam_tally2\.so.*onerr=fail.*deny=5.*unlock_time=900' /etc/pam.d/common-auth; then
|
|
echo "-------------------"; echo "# Thiếu: auth required pam_tally2.so ... deny=5 unlock_time=900 (common-auth)"
|
|
fi
|
|
if ! grep -Pq '^\h*account\h*requisite\h*pam_deny\.so' /etc/pam.d/common-account; then
|
|
echo "-------------------"; echo "# Thiếu: account requisite pam_deny.so (common-account)"
|
|
fi
|
|
if ! grep -Pq '^\h*account\h*required\h*pam_tally2\.so' /etc/pam.d/common-account; then
|
|
echo "-------------------"; echo "# Thiếu: account required pam_tally2.so (common-account)"
|
|
fi
|
|
echo "######################################"
|
|
else
|
|
echo '{"5.3.2. Cấu hình khoá truy cập do nhiều lần nhập mật khẩu thất bại" : "PASSED"}'
|
|
fi
|
|
fi
|
|
|
|
############################################################################
|
|
# Đối với phiên bản 22.04 trở lên:
|
|
# Chỉnh sửa file /etc/pam.d/common-password thêm hoặc chỉnh sửa tham số remember trong dòng có chứa pam_unix.so thành 5 như sau:
|
|
# password [success=1 default=ignore] pam_unix.so remember=5
|
|
# Đối với phiên bản 20.04 trở về trước:
|
|
# Chỉnh sửa file /etc/pam.d/common-password thêm hoặc chỉnh sửa tham số remember trong dòng có chứa pam_pwhistory.so thành 5 như sau:
|
|
# password required pam_pwhistory.so remember=5
|
|
if [ $(grep -P "^\h*password\h*required\h*pam_pwhistory\.so.*remember=5" /etc/pam.d/common-password | wc -l) -eq 0 ] && [[ ($(cat /etc/os-release | grep -E "VERSION_ID=\"(2[2-9]|[3-9][0-9])\." | wc -l) -ne 0 && $(grep -P "^\h*password.*\[success=1 default=ignore\]\h*pam_unix\.so.*remember.*5" /etc/pam.d/common-password | wc -l) -eq 0) ]]; then
|
|
echo "{\"5.3.3. Giới hạn việc sử dụng lại mật khẩu\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Đối với phiên bản 22.04 trở lên:
|
|
# Chỉnh sửa file /etc/pam.d/common-password thêm hoặc chỉnh sửa tham số remember trong dòng có chứa pam_unix.so thành 5 như sau:
|
|
# password [success=1 default=ignore] pam_unix.so remember=5
|
|
# Đối với phiên bản 20.04 trở về trước:
|
|
# Chỉnh sửa file /etc/pam.d/common-password thêm hoặc chỉnh sửa tham số remember trong dòng có chứa pam_pwhistory.so thành 5 như sau:
|
|
# password required pam_pwhistory.so remember=5"
|
|
if [[ ($(cat /etc/os-release | grep -E "VERSION_ID=\"(2[2-9]|[3-9][0-9])\." | wc -l) -ne 0 && $(grep -P "^\h*password.*\[success=1 default=ignore\]\h*pam_unix\.so.*remember.*5" /etc/pam.d/common-password | wc -l) -eq 0) ]] && [ $(grep -P "^\h*password\h*required\h*pam_pwhistory\.so.*remember=5" /etc/pam.d/common-password | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -P \"^\\h*password\\h*required\\h*pam_pwhistory\\.so.*remember=5\" /etc/pam.d/common-password -ne 0 ";grep -P "^\h*password\h*required\h*pam_pwhistory\.so.*remember=5" /etc/pam.d/common-password; fi
|
|
if [ $(grep -P "^\h*password\h*required\h*pam_pwhistory\.so.*remember=5" /etc/pam.d/common-password | wc -l) -eq 0 ] && [ $(grep -P "^\h*password.*\[success=1 default=ignore\]\h*pam_unix\.so.*remember.*5" /etc/pam.d/common-password | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -P \"^\\h*password.*\\[success=1 default=ignore\\]\\h*pam_unix\\.so.*remember.*5\" /etc/pam.d/common-password -ne 0 ";grep -P "^\h*password.*\[success=1 default=ignore\]\h*pam_unix\.so.*remember.*5" /etc/pam.d/common-password; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.3.3. Giới hạn việc sử dụng lại mật khẩu\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Đối với phiên bản 22.04 trở lên:
|
|
# Chỉnh sửa file /etc/pam.d/common-password đảm bảo rằng không có bất cứ thuật toán hash nào được cấu hình trong pam_unix.so như dưới đây:
|
|
# password [success=1 default=ignore] pam_unix.so remember=5
|
|
# Thêm hoặc chỉnh sửa ENCRYPT_METHOD trong file /etc/login.defs như sau:
|
|
# ENCRYPT_METHOD yescrypt
|
|
# Đối với phiên bản 20.04 trở về trước: Chỉnh sửa file /etc/pam.d/common-password để có tuỳ chọn sha512 cho pam_unix.so như dưới đây:
|
|
# password [success=1 default=ignore] pam_unix.so sha512 remember=5
|
|
if [ $(grep -P "^\h*password\h*\[success=1 default=ignore\]\h*pam_unix.so.*sha512" /etc/pam.d/common-password | wc -l) -eq 0 ] && [[ ($(cat /etc/os-release | grep -E "VERSION_ID=\"(2[2-9]|[3-9][0-9])\." | wc -l) -ne 0 && ($(grep -v ^# /etc/pam.d/common-password | grep -E "(yescrypt|md5|bigcrypt|sha256|sha512|blowfish)" | wc -l) -ne 0 || $(grep -Pi "^\h*ENCRYPT_METHOD\h*yescrypt\h*$" /etc/login.defs | wc -l) -eq 0)) ]]; then
|
|
echo "{\"5.3.4. Cấu hình thuật toán hash mật khẩu mạnh\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Đối với phiên bản 22.04 trở lên:
|
|
# Chỉnh sửa file /etc/pam.d/common-password đảm bảo rằng không có bất cứ thuật toán hash nào được cấu hình trong pam_unix.so như dưới đây:
|
|
# password [success=1 default=ignore] pam_unix.so remember=5
|
|
# Thêm hoặc chỉnh sửa ENCRYPT_METHOD trong file /etc/login.defs như sau:
|
|
# ENCRYPT_METHOD yescrypt
|
|
# Đối với phiên bản 20.04 trở về trước: Chỉnh sửa file /etc/pam.d/common-password để có tuỳ chọn sha512 cho pam_unix.so như dưới đây:
|
|
# password [success=1 default=ignore] pam_unix.so sha512 remember=5"
|
|
if [ $(grep -P "^\h*password\h*\[success=1 default=ignore\]\h*pam_unix.so.*sha512" /etc/pam.d/common-password | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -P \"^\\h*password\\h*\\[success=1 default=ignore\\]\\h*pam_unix.so.*sha512\" /etc/pam.d/common-password -ne 0 ";grep -P "^\h*password\h*\[success=1 default=ignore\]\h*pam_unix.so.*sha512" /etc/pam.d/common-password; fi
|
|
if [ $(grep -v ^# /etc/pam.d/common-password | grep -E "(yescrypt|md5|bigcrypt|sha256|sha512|blowfish)" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -v ^# /etc/pam.d/common-password | grep -E \"(yescrypt|md5|bigcrypt|sha256|sha512|blowfish)\" -eq 0 ";grep -v ^# /etc/pam.d/common-password | grep -E "(yescrypt|md5|bigcrypt|sha256|sha512|blowfish)"; fi
|
|
if [ $(grep -Pi "^\h*ENCRYPT_METHOD\h*yescrypt\h*$" /etc/login.defs | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -Pi \"^\\h*ENCRYPT_METHOD\\h*yescrypt\\h*\$\" /etc/login.defs -ne 0 ";grep -Pi "^\h*ENCRYPT_METHOD\h*yescrypt\h*$" /etc/login.defs; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.3.4. Cấu hình thuật toán hash mật khẩu mạnh\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Đặt tham số PASS_MIIN_DAYS trong file /etc/login.defs là 7:
|
|
# PASS_MIN_DAYS 7
|
|
# Chỉnh sửa tham số cho người dùng sử dụng mật khẩu bằng câu lệnh sau:
|
|
# chage --mindays 7 <user>
|
|
if [ $(grep -P "^\h*PASS_MIN_DAYS.*7" /etc/login.defs | wc -l) -eq 0 ] || [ $(grep -P "^\h*[^:]+:[^\!*]" /etc/shadow | cut -d: -f1,4 | awk -F: '($2<7) {print}' | grep -v "root" | wc -l) -ne 0 ]; then
|
|
echo "{\"5.4.1.1. Cấu hình thời gian tối thiểu giữa những lần thay đổi mật khẩu\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Đặt tham số PASS_MIIN_DAYS trong file /etc/login.defs là 7:
|
|
# PASS_MIN_DAYS 7
|
|
# Chỉnh sửa tham số cho người dùng sử dụng mật khẩu bằng câu lệnh sau:
|
|
# chage --mindays 7 <user>"
|
|
if [ $(grep -P "^\h*PASS_MIN_DAYS.*7" /etc/login.defs | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -P \"^\\h*PASS_MIN_DAYS.*7\" /etc/login.defs -ne 0 ";grep -P "^\h*PASS_MIN_DAYS.*7" /etc/login.defs; fi
|
|
if [ $(grep -P "^\h*[^:]+:[^\!*]" /etc/shadow | cut -d: -f1,4 | awk -F: '($2<7) {print}' | grep -v "root" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -P \"^\\h*[^:]+:[^\!*]\" /etc/shadow | cut -d: -f1,4 | awk -F: '(\$2<7) {print}' | grep -v \"root\" -eq 0 ";grep -P "^\h*[^:]+:[^\!*]" /etc/shadow | cut -d: -f1,4 | awk -F: '($2<7) {print}' | grep -v "root"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.4.1.1. Cấu hình thời gian tối thiểu giữa những lần thay đổi mật khẩu\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Đặt tham số PASS_MAX_DAYS trong file /etc/login.defs tuân theo chính sách của tổ chức:
|
|
# PASS_MAX_DAYS 180
|
|
# Chỉnh sửa tham số cho người dùng sử dụng mật khẩu bằng câu lệnh sau:
|
|
# chage --maxdays 180 <user>
|
|
if [ $(grep -P "^\h*PASS_MAX_DAYS\h*(9[0-9]|[1-2][0-9][0-9]|3[0-6][0-9]|36[0-5])$" /etc/login.defs | wc -l) -eq 0 ] || [ $(grep -E '^[^:]+:[^!*]' /etc/shadow | cut -d: -f1,5 | awk -F ':' '{if($2<90||$2>365) print}' | grep -v "root" | wc -l) -ne 0 ]; then
|
|
echo "{\"5.4.1.2. Cấu hình thời gian hết hạn sử dụng mật khẩu\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Đặt tham số PASS_MAX_DAYS trong file /etc/login.defs tuân theo chính sách của tổ chức:
|
|
# PASS_MAX_DAYS 180
|
|
# Chỉnh sửa tham số cho người dùng sử dụng mật khẩu bằng câu lệnh sau:
|
|
# chage --maxdays 180 <user>"
|
|
if [ $(grep -P "^\h*PASS_MAX_DAYS\h*(9[0-9]|[1-2][0-9][0-9]|3[0-6][0-9]|36[0-5])$" /etc/login.defs | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -P \"^\\h*PASS_MAX_DAYS\\h*(9[0-9]|[1-2][0-9][0-9]|3[0-6][0-9]|36[0-5])\$\" /etc/login.defs -ne 0 ";grep -P "^\h*PASS_MAX_DAYS\h*(9[0-9]|[1-2][0-9][0-9]|3[0-6][0-9]|36[0-5])$" /etc/login.defs; fi
|
|
if [ $(grep -E '^[^:]+:[^!*]' /etc/shadow | cut -d: -f1,5 | awk -F ':' '{if($2<90||$2>365) print}' | grep -v "root" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -E '^[^:]+:[^!*]' /etc/shadow | cut -d: -f1,5 | awk -F ':' '{if(\$2<90||\$2>365) print}' | grep -v "root" -eq 0 ";grep -E '^[^:]+:[^!*]' /etc/shadow | cut -d: -f1,5 | awk -F ':' '{if($2<90||$2>365) print}' | grep -v "root"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.4.1.2. Cấu hình thời gian hết hạn sử dụng mật khẩu\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Đặt tham số PASS_WARN_AGE trong file /etc/login.defs là 7:
|
|
# PASS_WARN_AGE 7
|
|
# Chỉnh sửa tham số của người dùng sử dụng mật khẩu bằng câu lệnh sau:
|
|
# chage --warndays 7 <user>
|
|
if [ $(grep -P "^\h*PASS_WARN_AGE.*7" /etc/login.defs | wc -l) -eq 0 ] || [ $(grep -P "^\h*[^:]+:[^\!*]" /etc/shadow | cut -d: -f1,6 | awk -F: '($2<7) {print}' | wc -l) -ne 0 ]; then
|
|
echo "{\"5.4.1.3. Cấu hình thời gian cảnh báo mật khẩu hết hạn\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Đặt tham số PASS_WARN_AGE trong file /etc/login.defs là 7:
|
|
# PASS_WARN_AGE 7
|
|
# Chỉnh sửa tham số của người dùng sử dụng mật khẩu bằng câu lệnh sau:
|
|
# chage --warndays 7 <user>"
|
|
if [ $(grep -P "^\h*PASS_WARN_AGE.*7" /etc/login.defs | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -P \"^\\h*PASS_WARN_AGE.*7\" /etc/login.defs -ne 0 ";grep -P "^\h*PASS_WARN_AGE.*7" /etc/login.defs; fi
|
|
if [ $(grep -P "^\h*[^:]+:[^\!*]" /etc/shadow | cut -d: -f1,6 | awk -F: '($2<7) {print}' | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -P \"^\\h*[^:]+:[^\!*]\" /etc/shadow | cut -d: -f1,6 | awk -F: '(\$2<7) {print}' -eq 0 ";grep -P "^\h*[^:]+:[^\!*]" /etc/shadow | cut -d: -f1,6 | awk -F: '($2<7) {print}'; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.4.1.3. Cấu hình thời gian cảnh báo mật khẩu hết hạn\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện câu lệnh sau dể đặt khoảng thời gian tài khoản không hoạt động là 30 ngày:
|
|
# useradd -D -f 30
|
|
# Chỉnh sửa thông số của người dùng sử dụng mật khẩu bằng câu lệnh sau:
|
|
# chage --inactive 30 <user>
|
|
if [ $(useradd -D | grep "INACTIVE.*30" | wc -l) -eq 0 ] || [ $(grep -Ev "^\+" /etc/shadow | awk -F: '( $2!="*" && $2!="!!" && $7>30 && $7!="") {print}' | wc -l) -ne 0 ]; then
|
|
echo "{\"5.4.1.4. Cấu hình thời gian khoá tài khoản không thay mật khẩu sau khi hết hạn\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau dể đặt khoảng thời gian tài khoản không hoạt động là 30 ngày:
|
|
# useradd -D -f 30
|
|
# Chỉnh sửa thông số của người dùng sử dụng mật khẩu bằng câu lệnh sau:
|
|
# chage --inactive 30 <user>"
|
|
if [ $(useradd -D | grep "INACTIVE.*30" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#useradd -D | grep \"INACTIVE.*30\" -ne 0 ";useradd -D | grep "INACTIVE.*30"; fi
|
|
if [ $(grep -Ev "^\+" /etc/shadow | awk -F: '( $2!="*" && $2!="!!" && $7>30 && $7!="") {print}' | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -Ev \"^\+\" /etc/shadow | awk -F: '( \$2!=\"*\" && \$2!=\"!!\" && \$7>30 && \$7!=\"\") {print}' -eq 0 ";grep -Ev "^\+" /etc/shadow | awk -F: '( $2!="*" && $2!="!!" && $7>30 && $7!="") {print}'; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.4.1.4. Cấu hình thời gian khoá tài khoản không thay mật khẩu sau khi hết hạn\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện câu lệnh sau để liệt kê các tài khoản có thời giant hay đổi mật khẩu lần cuối không hợp lệ:
|
|
# awk -F: '/^[^:]+:[^!*]/{print $1}' /etc/shadow | while read -r usr; do change=$(LC_ALL=C date -d "$(LC_ALL=C chage --list $usr | grep '^Last password change' | cut -d: -f2 | grep -v 'never$')" +%s 2>/dev/null); if [[ "$change" -gt "$(date +%s)" ]]; then echo "User: \"$usr\" last password change was \"$(LC_ALL=C chage --list $usr | grep '^Last password change' | cut -d: -f2)\""; fi; done
|
|
# Tiến hành khoá tài khoản, hết hạn mật khẩu hoặc đặt lại mật khẩu các tài khoản được tìm thấy.
|
|
if [ $(awk -F: '/^[^:]+:[^!*]/{print $1}' /etc/shadow | while read -r usr; do change=$(LC_ALL=C date -d "$(LC_ALL=C chage --list $usr | grep '^Last password change' | cut -d: -f2 | grep -v 'never$')" +%s 2>/dev/null); if [[ "$change" -gt "$(date +%s)" ]]; then echo "User: \"$usr\" last password change was \"$(LC_ALL=C chage --list $usr | grep '^Last password change' | cut -d: -f2)\""; fi; done | wc -l) -ne 0 ]; then
|
|
echo "{\"5.4.1.5. Đảm bảo thời gian thay đổi mật khẩu lần cuối hợp lệ\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để liệt kê các tài khoản có thời giant hay đổi mật khẩu lần cuối không hợp lệ:
|
|
# awk -F: '/^[^:]+:[^!*]/{print \$1}' /etc/shadow | while read -r usr; do change=\$(LC_ALL=C date -d \"\$(LC_ALL=C chage --list \$usr | grep '^Last password change' | cut -d: -f2 | grep -v 'never\$')\" +%s 2>/dev/null); if [[ \"\$change\" -gt \"\$(date +%s)\" ]]; then echo \"User: \\\"\$usr\\\" last password change was \\\"\$(LC_ALL=C chage --list \$usr | grep '^Last password change' | cut -d: -f2)\\\"\"; fi; done
|
|
# Tiến hành khoá tài khoản, hết hạn mật khẩu hoặc đặt lại mật khẩu các tài khoản được tìm thấy."
|
|
if [ $(awk -F: '/^[^:]+:[^!*]/{print $1}' /etc/shadow | while read -r usr; do change=$(LC_ALL=C date -d "$(LC_ALL=C chage --list $usr | grep '^Last password change' | cut -d: -f2 | grep -v 'never$')" +%s 2>/dev/null); if [[ "$change" -gt "$(date +%s)" ]]; then echo "User: \"$usr\" last password change was \"$(LC_ALL=C chage --list $usr | grep '^Last password change' | cut -d: -f2)\""; fi; done | wc -l) -ne 0 ]; then echo "-------------------"; echo "#awk -F: '/^[^:]+:[^!*]/{print \$1}' /etc/shadow | while read -r usr; do change=\$(LC_ALL=C date -d \"\$(LC_ALL=C chage --list \$usr | grep '^Last password change' | cut -d: -f2 | grep -v 'never\$')\" +%s 2>/dev/null); if [[ \"\$change\" -gt \"\$(date +%s)\" ]]; then echo \"User: \\\"\$usr\\\" last password change was \\\"\$(LC_ALL=C chage --list \$usr | grep '^Last password change' | cut -d: -f2)\\\"\"; fi; done -eq 0 ";awk -F: '/^[^:]+:[^!*]/{print $1}' /etc/shadow | while read -r usr; do change=$(LC_ALL=C date -d "$(LC_ALL=C chage --list $usr | grep '^Last password change' | cut -d: -f2 | grep -v 'never$')" +%s 2>/dev/null);if [[ "$change" -gt "$(date +%s)" ]]; then echo "User: \"$usr\" last password change was \"$(LC_ALL=C chage --list $usr | grep '^Last password change' | cut -d: -f2)\""; fi; done; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.4.1.5. Đảm bảo thời gian thay đổi mật khẩu lần cuối hợp lệ\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Đặt shell cho tất cả tài khoản hệ thống sang /sbin/nologin:
|
|
# usermod -s /sbin/nologin <user>
|
|
# Thực hiện câu lệnh sau sẽ đặt mọi tài khoản hệ thống sang non-login shell:
|
|
# awk -F: '($1!~/^(root|halt|sync|shutdown|nfsnobody)$/ && $3<'"$(awk '/^\s*UID_MIN/{print $2}' /etc/login.defs)"' && $7!~/^(\/usr)?\/sbin\/nologin(\/)?$/ && $7!~/(\/usr)?\/bin\/false(\/)?$/) { print $1 }' /etc/passwd | while read user; do usermod -s $(which nologin) $user; done
|
|
# Khoá tất cả tài khoản hệ thống không phải root:
|
|
# usermod -L <user>
|
|
# Thực hiện câu lệnh sau sẽ tự động khoá mọi tài khoản hệ thống ngoài root:
|
|
# awk -F: '($1!="root" && $1!~/^\+/ && $3<'"$(awk '/^\s*UID_MIN/{print $2}' /etc/login.defs)"') {print $1}' /etc/passwd | xargs -I '{}' passwd -S '{}' | awk '($2!="L" && $2!="LK") {print $1}' | while read user; do usermod -L $user; done
|
|
if [ $(awk -F: '($1!~/^(root|halt|sync|shutdown|nfsnobody)$/ && $3<'"$(awk '/^\s*UID_MIN/{print $2}' /etc/login.defs)"' && $7!~/^(\/usr)?\/sbin\/nologin(\/)?$/ && $7!~/(\/usr)?\/bin\/false(\/)?$/) { print $1 }' /etc/passwd | wc -l) -ne 0 ] || [ $(awk -F: '($1!="root" && $1!~/^\+/ && $3<'"$(awk '/^\s*UID_MIN/{print $2}' /etc/login.defs)"') {print $1}' /etc/passwd | xargs -I '{}' passwd -S '{}' | awk '($2!="L" && $2!="LK") {print $1}' | wc -l) -ne 0 ]; then
|
|
echo "{\"5.4.2. Cấu hình vô hiệu hoá đăng nhập bằng tài khoản hệ thống\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Đặt shell cho tất cả tài khoản hệ thống sang /sbin/nologin:
|
|
# usermod -s /sbin/nologin <user>
|
|
# Thực hiện câu lệnh sau sẽ đặt mọi tài khoản hệ thống sang non-login shell:
|
|
# awk -F: '(\$1\!~/^(root|halt|sync|shutdown|nfsnobody)\$/ && \$3<'\"\$(awk '/^\\s*UID_MIN/{print \$2}' /etc/login.defs)\"' && \$7\!~/^(\\/usr)?\\/sbin\\/nologin(\\/)?\$/ && \$7\!~/(\\/usr)?\\/bin\\/false(\\/)?\$/) { print \$1 }' /etc/passwd | while read user; do usermod -s \$(which nologin) \$user; done
|
|
# Khoá tất cả tài khoản hệ thống không phải root:
|
|
# usermod -L <user>
|
|
# Thực hiện câu lệnh sau sẽ tự động khoá mọi tài khoản hệ thống ngoài root:
|
|
# awk -F: '(\$1!=\"root\" && \$1\!~/^\\+/ && \$3<'\"\$(awk '/^\\s*UID_MIN/{print \$2}' /etc/login.defs)\"') {print \$1}' /etc/passwd | xargs -I '{}' passwd -S '{}' | awk '(\$2!=\"L\" && \$2!=\"LK\") {print \$1}' | while read user; do usermod -L \$user; done"
|
|
if [ $(awk -F: '($1!~/^(root|halt|sync|shutdown|nfsnobody)$/ && $3<'"$(awk '/^\s*UID_MIN/{print $2}' /etc/login.defs)"' && $7!~/^(\/usr)?\/sbin\/nologin(\/)?$/ && $7!~/(\/usr)?\/bin\/false(\/)?$/) { print $1 }' /etc/passwd | wc -l) -ne 0 ]; then echo "-------------------"; echo "#awk -F: '(\$1\!~/^(root|halt|sync|shutdown|nfsnobody)\$/ && \$3<'\"\$(awk '/^\\s*UID_MIN/{print \$2}' /etc/login.defs)\"' && \$7\!~/^(\\/usr)?\\/sbin\\/nologin(\\/)?\$/ && \$7\!~/(\\/usr)?\\/bin\\/false(\\/)?\$/) { print \$1 }' /etc/passwd -eq 0 ";awk -F: '($1!~/^(root|halt|sync|shutdown|nfsnobody)$/ && $3<'"$(awk '/^\s*UID_MIN/{print $2}' /etc/login.defs)"' && $7!~/^(\/usr)?\/sbin\/nologin(\/)?$/ && $7!~/(\/usr)?\/bin\/false(\/)?$/) { print $1 }' /etc/passwd; fi
|
|
if [ $(awk -F: '($1!="root" && $1!~/^\+/ && $3<'"$(awk '/^\s*UID_MIN/{print $2}' /etc/login.defs)"') {print $1}' /etc/passwd | xargs -I '{}' passwd -S '{}' | awk '($2!="L" && $2!="LK") {print $1}' | wc -l) -ne 0 ]; then echo "-------------------"; echo "#awk -F: '(\$1!=\"root\" && \$1\!~/^\\+/ && \$3<'\"\$(awk '/^\\s*UID_MIN/{print \$2}' /etc/login.defs)\"') {print \$1}' /etc/passwd | xargs -I '{}' passwd -S '{}' | awk '(\$2!=\"L\" && \$2!=\"LK\") {print \$1}' -eq 0 ";awk -F: '($1!="root" && $1!~/^\+/ && $3<'"$(awk '/^\s*UID_MIN/{print $2}' /etc/login.defs)"') {print $1}' /etc/passwd | xargs -I '{}' passwd -S '{}' | awk '($2!="L" && $2!="LK") {print $1}'; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.4.2. Cấu hình vô hiệu hoá đăng nhập bằng tài khoản hệ thống\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện câu lệnh sau để đặt group mặc định cho người dùng root là GID 0:
|
|
# usermod -g 0 root
|
|
if [ $(grep -P "^\h*root:" /etc/passwd | cut -d: -f1,4 | grep "0" | wc -l) -eq 0 ]; then
|
|
echo "{\"5.4.3. Cấu hình group mặc định của tài khoản root\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để đặt group mặc định cho người dùng root là GID 0:
|
|
# usermod -g 0 root"
|
|
if [ $(grep -P "^\h*root:" /etc/passwd | cut -d: -f1,4 | grep "0" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -P \"^\\h*root:\" /etc/passwd | cut -d: -f1,4 | grep \"0\" -ne 0 ";grep -P "^\h*root:" /etc/passwd | cut -d: -f1,4 | grep "0"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.4.3. Cấu hình group mặc định của tài khoản root\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Chỉnh sửa file /etc/profile và /etc/profile.d/*.sh, thêm vào hoặc chỉnh sửa tất cả các tham số umask như sau:
|
|
# umask 027
|
|
if [[ (($(grep -Ei '^\h*UMASK\s+(0[0-7][2-7]7|[0-7][2-7]7)\b' /etc/login.defs | wc -l) -eq 0 || $(grep -Ei '^\h*USERGROUPS_ENAB\s*"?no"?\b' /etc/login.defs | wc -l) -eq 0) && $(grep -E '^\h*session\s+(optional|requisite|required)\s+pam_umask.so\b' /etc/pam.d/password-auth /etc/pam.d/system-auth 2>/dev/null | wc -l) -eq 0 && $(grep -REi '^\h*UMASK\s+\s*(0[0-7][2-7]7|[0-7][2-7]7|u=(r?|w?|x?)(r?|w?|x?)(r?|w?|x?),g=(r?x?|x?r?),o=)\b' /etc/profile* | wc -l) -eq 0) ]] || [ $(grep -RPi '(^|^[^#]*)\s*umask\s+([0-7][0-7][01][0-7]\b|[0-7][0-7][0-7][0-6]\b|[0-7][01][0-7]\b|[0-7][0-7][0-6]\b|(u=[rwx]{0,3},)?(g=[rwx]{0,3},)?o=[rwx]+\b|(u=[rwx]{1,3},)?g=[^rx]{1,3}( ,o=[rwx]{0,3})?\b)' /etc/login.defs /etc/profile* | wc -l) -ne 0 ]; then
|
|
echo "{\"5.4.4. Cấu hình user umask mặc định\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Chỉnh sửa file /etc/profile và /etc/profile.d/*.sh, thêm vào hoặc chỉnh sửa tất cả các tham số umask như sau:
|
|
# umask 027"
|
|
if [ $(grep -Ei '^\h*UMASK\s+(0[0-7][2-7]7|[0-7][2-7]7)\b' /etc/login.defs | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -Ei '^\h*UMASK\s+(0[0-7][2-7]7|[0-7][2-7]7)\b' /etc/login.defs -ne 0 ";grep -Ei '^\h*UMASK\s+(0[0-7][2-7]7|[0-7][2-7]7)\b' /etc/login.defs; fi
|
|
if [ $(grep -Ei '^\h*USERGROUPS_ENAB\s*"?no"?\b' /etc/login.defs | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -Ei '^\h*USERGROUPS_ENAB\s*\"?no\"?\b' /etc/login.defs -ne 0 ";grep -Ei '^\h*USERGROUPS_ENAB\s*"?no"?\b' /etc/login.defs; fi
|
|
if [ $(grep -E '^\h*session\s+(optional|requisite|required)\s+pam_umask.so\b' /etc/pam.d/password-auth /etc/pam.d/system-auth 2>/dev/null | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -E '^\h*session\s+(optional|requisite|required)\s+pam_umask.so\b' /etc/pam.d/password-auth /etc/pam.d/system-auth 2>/dev/null -ne 0 ";grep -E '^\h*session\s+(optional|requisite|required)\s+pam_umask.so\b' /etc/pam.d/password-auth /etc/pam.d/system-auth 2>/dev/null; fi
|
|
if [ $(grep -REi '^\h*UMASK\s+\s*(0[0-7][2-7]7|[0-7][2-7]7|u=(r?|w?|x?)(r?|w?|x?)(r?|w?|x?),g=(r?x?|x?r?),o=)\b' /etc/profile* | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -REi '^\h*UMASK\s+\s*(0[0-7][2-7]7|[0-7][2-7]7|u=(r?|w?|x?)(r?|w?|x?)(r?|w?|x?),g=(r?x?|x?r?),o=)\b' /etc/profile* -ne 0 ";grep -REi '^\h*UMASK\s+\s*(0[0-7][2-7]7|[0-7][2-7]7|u=(r?|w?|x?)(r?|w?|x?)(r?|w?|x?),g=(r?x?|x?r?),o=)\b' /etc/profile*; fi
|
|
if [ $(grep -RPi '(^|^[^#]*)\s*umask\s+([0-7][0-7][01][0-7]\b|[0-7][0-7][0-7][0-6]\b|[0-7][01][0-7]\b|[0-7][0-7][0-6]\b|(u=[rwx]{0,3},)?(g=[rwx]{0,3},)?o=[rwx]+\b|(u=[rwx]{1,3},)?g=[^rx]{1,3}( ,o=[rwx]{0,3})?\b)' /etc/login.defs /etc/profile* | wc -l) -ne 0 ]; then echo "-------------------"; echo "#grep -RPi '(^|^[^#]*)\s*umask\s+([0-7][0-7][01][0-7]\b|[0-7][0-7][0-7][0-6]\b|[0-7][01][0-7]\b|[0-7][0-7][0-6]\b|(u=[rwx]{0,3},)?(g=[rwx]{0,3},)?o=[rwx]+\b|(u=[rwx]{1,3},)?g=[^rx]{1,3}( ,o=[rwx]{0,3})?\b)' /etc/login.defs /etc/profile* -eq 0 ";grep -RPi '(^|^[^#]*)\s*umask\s+([0-7][0-7][01][0-7]\b|[0-7][0-7][0-7][0-6]\b|[0-7][01][0-7]\b|[0-7][0-7][0-6]\b|(u=[rwx]{0,3},)?(g=[rwx]{0,3},)?o=[rwx]+\b|(u=[rwx]{1,3},)?g=[^rx]{1,3}( ,o=[rwx]{0,3})?\b)' /etc/login.defs /etc/profile*; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.4.4. Cấu hình user umask mặc định\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Chỉnh sửa một trong các file /etc/bash.bashrc, /etc/profile và /etc/profile.d/*.sh thêm hoặc thay đổi các tham số TMOUT phù hợp với chính sách:
|
|
# readonly TMOUT=900 ; export TMOUT
|
|
if [ $(grep "TMOUT=900" /etc/bash.bashrc /etc/profile /etc/profile.d/*.sh | wc -l) -eq 0 ] || [ $(grep -E "readonly\s+TMOUT" /etc/bash.bashrc /etc/profile /etc/profile.d/*.sh | wc -l) -eq 0 ] || [ $(grep -E "export\s+TMOUT" /etc/bash.bashrc /etc/profile /etc/profile.d/*.sh | wc -l) -eq 0 ]; then
|
|
echo "{\"5.4.5. Cấu hình shell timeout mặc định\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Chỉnh sửa một trong các file /etc/bash.bashrc, /etc/profile và /etc/profile.d/*.sh thêm hoặc thay đổi các tham số TMOUT phù hợp với chính sách:
|
|
# readonly TMOUT=900 ; export TMOUT"
|
|
if [ $(grep "TMOUT=900" /etc/profile /etc/profile.d/*.sh | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep \"TMOUT=900\" /etc/bash.bashrc /etc/profile /etc/profile.d/*.sh -ne 0 ";grep "TMOUT=900" /etc/bash.bashrc /etc/profile /etc/profile.d/*.sh; fi
|
|
if [ $(grep -E "readonly\s+TMOUT" /etc/bash.bashrc /etc/profile /etc/profile.d/*.sh | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -E \"readonly\s+TMOUT\" /etc/bash.bashrc /etc/profile /etc/profile.d/*.sh -ne 0 ";grep -E "readonly\s+TMOUT" /etc/bash.bashrc /etc/profile /etc/profile.d/*.sh; fi
|
|
if [ $(grep -E "export\s+TMOUT" /etc/bash.bashrc /etc/profile /etc/profile.d/*.sh | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -E \"export\s+TMOUT\" /etc/bash.bashrc /etc/profile /etc/profile.d/*.sh -ne 0 ";grep -E "export\s+TMOUT" /etc/bash.bashrc /etc/profile /etc/profile.d/*.sh; fi
|
|
# if [ $(echo $TMOUT | grep "^900$" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#echo \$TMOUT | grep \"^900\$\" -ne 0 ";echo $TMOUT | grep "^900$"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.4.5. Cấu hình shell timeout mặc định\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Tạo ra một nhóm rỗng sẽ được chỉ định để sử dụng trong lệnh su, tên nhóm nên được đặt tên theo chính sách:
|
|
# groupadd sugroup
|
|
# Thêm dòng sau vào file /etc/pam.d/su, chỉ định nhóm rỗng vừa tạo vào:
|
|
# auth required pam_wheel.so use_uid group=sugroup
|
|
if [ $(grep -Pi '^\h*auth\h+(?:required|requisite)\h+pam_wheel\.so\h+(?:[^#\n\r]+\h+)?((?!\2)(use_uid\b|group=\H+\b))\h+(?:[^#\n\r]+\h+)?((?!\1)(use_uid\b|group=\H+\b))(\ h+.*)?$' /etc/pam.d/su | wc -l) -eq 0 ] || [ $(grep -P "^\h*sugroup:x:.*:$" /etc/group | wc -l) -eq 0 ]; then
|
|
echo "{\"5.4.6. Cấu hình hạn chế truy cập cho câu lệnh su\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Tạo ra một nhóm rỗng sẽ được chỉ định để sử dụng trong lệnh su, tên nhóm nên được đặt tên theo chính sách:
|
|
# groupadd sugroup
|
|
# Thêm dòng sau vào file /etc/pam.d/su, chỉ định nhóm rỗng vừa tạo vào:
|
|
# auth required pam_wheel.so use_uid group=sugroup
|
|
# Tạo một danh sách người dùng được ngăn cách bởi dấu phẩy ở dòng wheel trong file /etc/group:
|
|
# wheel:x:10:root,<user list>"
|
|
if [ $(grep -Pi '^\h*auth\h+(?:required|requisite)\h+pam_wheel\.so\h+(?:[^#\n\r]+\h+)?((?!\2)(use_uid\b|group=\H+\b))\h+(?:[^#\n\r]+\h+)?((?!\1)(use_uid\b|group=\H+\b))(\ h+.*)?$' /etc/pam.d/su | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -Pi '^\h*auth\h+(?:required|requisite)\h+pam_wheel\.so\h+(?:[^#\n\r]+\h+)?((?!\2)(use_uid\b|group=\H+\b))\h+(?:[^#\n\r]+\h+)?((?!\1)(use_uid\b|group=\H+\b))(\ h+.*)?\$' /etc/pam.d/su -ne 0 ";grep -Pi '^\h*auth\h+(?:required|requisite)\h+pam_wheel\.so\h+(?:[^#\n\r]+\h+)?((?!\2)(use_uid\b|group=\H+\b))\h+(?:[^#\n\r]+\h+)?((?!\1)(use_uid\b|group=\H+\b))(\ h+.*)?$' /etc/pam.d/su; fi
|
|
if [ $(grep -P "^\h*sugroup:x:.*:$" /etc/group | wc -l) -eq 0 ]; then echo "-------------------"; echo "#grep -P \"^\\h*sugroup:x:.*:\$\" /etc/group -ne 0 ";grep -P "^\h*sugroup:x:.*:$" /etc/group; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"5.4.6. Cấu hình hạn chế truy cập cho câu lệnh su\" : \"PASSED\"}"
|
|
fi
|
|
|
|
##################################################################################################################
|
|
# Thực hiện các câu lệnh sau để đặt quyền ở file /etc/passwd /etc/shadow, /etc/group, /etc/gshadow, /etc/passwd-, /etc/shadow-, /etc/group-, /etc/gshadow-:
|
|
# # /etc/passwd
|
|
# chown root:root /etc/passwd
|
|
# chmod 644 /etc/passwd
|
|
# # /etc/shadow
|
|
# chown root:root /etc/shadow
|
|
# chmod 0640 /etc/shadow
|
|
# # /etc/group
|
|
# chown root:root /etc/group
|
|
# chmod u-x,g-wx,o-wx /etc/group
|
|
# # /etc/gshadow
|
|
# chown root:root /etc/gshadow
|
|
# chmod 0640 /etc/gshadow
|
|
# # /etc/passwd-
|
|
# chown root:root /etc/passwd-
|
|
# chmod u-x,go-wx /etc/passwd-
|
|
# # /etc/shadow-
|
|
# chown root:root /etc/shadow-
|
|
# chmod 0640 /etc/shadow-
|
|
# # /etc/group-
|
|
# chown root:root /etc/group-
|
|
# chmod u-x,go-wx /etc/group-
|
|
# # /etc/gshadow-
|
|
# chown root:root /etc/gshadow-
|
|
# chmod 0640 /etc/gshadow-
|
|
if [ $(stat /etc/passwd | grep "0644.*Uid:.*0/.*root.*Gid:.*0/.*root" | wc -l) -eq 0 ]; then
|
|
echo "{\"6.1.1. Cấu hình phân quyền cho file /etc/passwd\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện các câu lệnh sau để đặt quyền ở file /etc/passwd:
|
|
# # /etc/passwd
|
|
# chown root:root /etc/passwd
|
|
# chmod 644 /etc/passwd"
|
|
if [ $(stat /etc/passwd | grep "0644.*Uid:.*0/.*root.*Gid:.*0/.*root" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#stat /etc/passwd | grep \"0644.*Uid:.*0/.*root.*Gid:.*0/.*root\" -ne 0 ";stat /etc/passwd | grep "0644.*Uid:.*0/.*root.*Gid:.*0/.*root"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"6.1.1. Cấu hình phân quyền cho file /etc/passwd\" : \"PASSED\"}"
|
|
fi
|
|
|
|
if [ $(stat /etc/shadow | grep "0640.*Uid:.*0/.*root.*Gid:.*0/.*root" | wc -l) -eq 0 ]; then
|
|
echo "{\"6.1.2. Cấu hình phân quyền cho file /etc/shadow\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện các câu lệnh sau để đặt quyền ở file /etc/shadow:
|
|
# # /etc/shadow
|
|
# chown root:root /etc/shadow
|
|
# chmod u-x,g-wx,o-rwx /etc/shadow"
|
|
if [ $(stat /etc/shadow | grep "0640.*Uid:.*0/.*root.*Gid:.*0/.*root" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#stat /etc/shadow | grep \"0640.*Uid:.*0/.*root.*Gid:.*0/.*root\" -ne 0 ";stat /etc/shadow | grep "0640.*Uid:.*0/.*root.*Gid:.*0/.*root"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"6.1.2. Cấu hình phân quyền cho file /etc/shadow\" : \"PASSED\"}"
|
|
fi
|
|
|
|
if [ $(stat /etc/group | grep "0644.*Uid:.*0/.*root.*Gid:.*0/.*root" | wc -l) -eq 0 ]; then
|
|
echo "{\"6.1.3. Cấu hình phân quyền cho file /etc/group\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện các câu lệnh sau để đặt quyền ở file /etc/group:
|
|
# # /etc/group
|
|
# chown root:root /etc/group
|
|
# chmod u-x,g-wx,o-wx /etc/group"
|
|
if [ $(stat /etc/group | grep "0644.*Uid:.*0/.*root.*Gid:.*0/.*root" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#stat /etc/group | grep \"0644.*Uid:.*0/.*root.*Gid:.*0/.*root\" -ne 0 ";stat /etc/group | grep "0644.*Uid:.*0/.*root.*Gid:.*0/.*root"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"6.1.3. Cấu hình phân quyền cho file /etc/group\" : \"PASSED\"}"
|
|
fi
|
|
|
|
if [ $(stat /etc/gshadow | grep "0640.*Uid:.*0/.*root.*Gid:.*0/.*root" | wc -l) -eq 0 ]; then
|
|
echo "{\"6.1.4. Cấu hình phân quyền cho file /etc/gshadow\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện các câu lệnh sau để đặt quyền ở file /etc/gshadow:
|
|
# # /etc/gshadow
|
|
# chown root:root /etc/gshadow
|
|
# chmod u-x,g-wx,o-rwx /etc/gshadow"
|
|
if [ $(stat /etc/gshadow | grep "0640.*Uid:.*0/.*root.*Gid:.*0/.*root" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#stat /etc/gshadow | grep \"0640.*Uid:.*0/.*root.*Gid:.*0/.*root\" -ne 0 ";stat /etc/gshadow | grep "0640.*Uid:.*0/.*root.*Gid:.*0/.*root"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"6.1.4. Cấu hình phân quyền cho file /etc/gshadow\" : \"PASSED\"}"
|
|
fi
|
|
|
|
if [ $(stat /etc/passwd- | grep "0[0246][04][04].*Uid:.*0/.*root.*Gid:.*0/.*root" | wc -l) -eq 0 ]; then
|
|
echo "{\"6.1.5. Cấu hình phân quyền cho file /etc/passwd-\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện các câu lệnh sau để đặt quyền ở file /etc/passwd-:
|
|
# # /etc/passwd-
|
|
# chown root:root /etc/passwd-
|
|
# chmod u-x,go-wx /etc/passwd-"
|
|
if [ $(stat /etc/passwd- | grep "0[0246][04][04].*Uid:.*0/.*root.*Gid:.*0/.*root" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#stat /etc/passwd- | grep \"0[0246][04][04].*Uid:.*0/.*root.*Gid:.*0/.*root\" -ne 0 ";stat /etc/passwd- | grep "0[0246][04][04].*Uid:.*0/.*root.*Gid:.*0/.*root"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"6.1.5. Cấu hình phân quyền cho file /etc/passwd-\" : \"PASSED\"}"
|
|
fi
|
|
|
|
if [ $(stat /etc/shadow- | grep "0640.*Uid:.*0/.*root.*Gid:.*0/.*root" | wc -l) -eq 0 ]; then
|
|
echo "{\"6.1.6. Cấu hình phân quyền cho file /etc/shadow-\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện các câu lệnh sau để đặt quyền ở file /etc/shadow-:
|
|
# # /etc/shadow-
|
|
# chown root:root /etc/shadow-
|
|
# chmod 0640 /etc/shadow-"
|
|
if [ $(stat /etc/shadow- | grep "0640.*Uid:.*0/.*root.*Gid:.*0/.*root" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#stat /etc/shadow- | grep \"0640.*Uid:.*0/.*root.*Gid:.*0/.*root\" -ne 0 ";stat /etc/shadow- | grep "0640.*Uid:.*0/.*root.*Gid:.*0/.*root"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"6.1.6. Cấu hình phân quyền cho file /etc/shadow-\" : \"PASSED\"}"
|
|
fi
|
|
|
|
if [ $(stat /etc/group- | grep "0[0246][04][04].*Uid:.*0/.*root.*Gid:.*0/.*root" | wc -l) -eq 0 ]; then
|
|
echo "{\"6.1.7. Cấu hình phân quyền cho file /etc/group-\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện các câu lệnh sau để đặt quyền ở file /etc/group-:
|
|
# # /etc/group-
|
|
# chown root:root /etc/group-
|
|
# chmod u-x,go-wx /etc/group-"
|
|
if [ $(stat /etc/group- | grep "0[0246][04][04].*Uid:.*0/.*root.*Gid:.*0/.*root" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#stat /etc/group- | grep \"0[0246][04][04].*Uid:.*0/.*root.*Gid:.*0/.*root\" -ne 0 ";stat /etc/group- | grep "0[0246][04][04].*Uid:.*0/.*root.*Gid:.*0/.*root"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"6.1.7. Cấu hình phân quyền cho file /etc/group-\" : \"PASSED\"}"
|
|
fi
|
|
|
|
if [ $(stat /etc/gshadow- | grep -E "0640.*Uid:.*0/.*root.*Gid:.*0/.*root" | wc -l) -eq 0 ]; then
|
|
echo "{\"6.1.8. Cấu hình phân quyền cho file /etc/gshadow-\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện các câu lệnh sau để đặt quyền ở file /etc/gshadow-:
|
|
# # /etc/gshadow-
|
|
# chown root:root /etc/gshadow-
|
|
# chmod 0640 /etc/gshadow-"
|
|
if [ $(stat /etc/gshadow- | grep -E "0640.*Uid:.*0/.*root.*Gid:.*0/.*root" | wc -l) -eq 0 ]; then echo "-------------------"; echo "#stat /etc/gshadow- | grep -E \"0640.*Uid:.*0/.*root.*Gid:.*0/.*root\" -ne 0 ";stat /etc/gshadow- | grep -E "0640.*Uid:.*0/.*root.*Gid:.*0/.*root"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"6.1.8. Cấu hình phân quyền cho file /etc/gshadow-\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện các câu lệnh sau để xác định các file world-writable trong hệ thống:
|
|
# df --local -P | awk '{if (NR!=1) print $6}' | xargs -I '{}' find '{}' -xdev -type f -perm -0002
|
|
# find / -xdev -type f -perm -0002
|
|
# Thực hiện câu lệnh sau để xóa quyền ghi đối với danh mục "other" cho các file vừa tìm được, tham khảo tài liệu của nhà cung cấp có liên quan để tránh vi phạm bất kỳ phụ thuộc ứng dụng nào trên một tệp nhất định.
|
|
# chmod o-w <filename>
|
|
if [ $(df --local -P | awk '{if (NR!=1) print $6}' | xargs -I '{}' find '{}' -xdev -path /proc -prune -o -type f -perm -0002 -print 2>/dev/null | wc -l) -ne 0 ] || [ $(find / -xdev -path /proc -prune -o -type f -perm -0002 -print 2>/dev/null | wc -l) -ne 0 ]; then
|
|
echo "{\"6.1.9. Đảm bảo không có file world-writable tồn tại\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện các câu lệnh sau để xác định các file world-writable trong hệ thống:
|
|
# df --local -P | awk '{if (NR!=1) print \$6}' | xargs -I '{}' find '{}' -xdev -type f -perm -0002
|
|
# find / -xdev -type f -perm -0002
|
|
# Thực hiện câu lệnh sau để xóa quyền ghi đối với danh mục \"other\" cho các file vừa tìm được, tham khảo tài liệu của nhà cung cấp có liên quan để tránh vi phạm bất kỳ phụ thuộc ứng dụng nào trên một tệp nhất định.
|
|
# chmod o-w <filename>"
|
|
if [ $(df --local -P | awk '{if (NR!=1) print $6}' | xargs -I '{}' find '{}' -xdev -path /proc -prune -o -type f -perm -0002 -print 2>/dev/null | wc -l) -ne 0 ]; then echo "-------------------"; echo "#df --local -P | awk '{if (NR!=1) print \$6}' | xargs -I '{}' find '{}' -xdev -path /proc -prune -o -type f -perm -0002 -print 2>/dev/null -eq 0 ";df --local -P | awk '{if (NR!=1) print $6}' | xargs -I '{}' find '{}' -xdev -path /proc -prune -o -type f -perm -0002 -print 2>/dev/null; fi
|
|
if [ $(find / -xdev -path /proc -prune -o -type f -perm -0002 -print 2>/dev/null | wc -l) -ne 0 ]; then echo "-------------------"; echo "#find / -xdev -path /proc -prune -o -type f -perm -0002 -print 2>/dev/null -eq 0 ";find / -xdev -path /proc -prune -o -type f -perm -0002 -print 2>/dev/null; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"6.1.9. Đảm bảo không có file world-writable tồn tại\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện các câu lệnh sau để xác định các file và thư mục được sở hữu bởi người dùng hoặc group không được liệt kê trong file cấu hình hệ thống:
|
|
# df --local -P | awk '{if (NR!=1) print $6}' | xargs -I '{}' find '{}' -xdev -nouser
|
|
# find /* -xdev -nouser
|
|
# Thực hiện câu lệnh sau để đặt lại quyền sở hữu các file vừa tìm được cho một số người dùng hoặc group đang hoạt động trên hệ thống:
|
|
# chown <owner>:<group> <filename>
|
|
if [ $(df --local -P | awk '{if (NR!=1) print $6}' | xargs -I '{}' find '{}' -xdev -nouser 2>/dev/null | wc -l) -ne 0 ] || [ $(find /* -xdev -nouser 2>/dev/null | wc -l) -ne 0 ]; then
|
|
echo "{\"6.1.10. Đảm bảo các file hoặc thư mục không có chủ sở hữu không tồn tại\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện các câu lệnh sau để xác định các file và thư mục được sở hữu bởi người dùng hoặc group không được liệt kê trong file cấu hình hệ thống:
|
|
# df --local -P | awk '{if (NR!=1) print \$6}' | xargs -I '{}' find '{}' -xdev -nouser
|
|
# find /* -xdev -nouser
|
|
# Thực hiện câu lệnh sau để đặt lại quyền sở hữu các file vừa tìm được cho một số người dùng hoặc group đang hoạt động trên hệ thống:
|
|
# chown <owner>:<group> <filename>"
|
|
if [ $(df --local -P | awk '{if (NR!=1) print $6}' | xargs -I '{}' find '{}' -xdev -nouser 2>/dev/null | wc -l) -ne 0 ]; then echo "-------------------"; echo "#df --local -P | awk '{if (NR!=1) print \$6}' | xargs -I '{}' find '{}' -xdev -nouser 2>/dev/null -eq 0 ";df --local -P | awk '{if (NR!=1) print $6}' | xargs -I '{}' find '{}' -xdev -nouser 2>/dev/null; fi
|
|
if [ $(find /* -xdev -nouser 2>/dev/null | wc -l) -ne 0 ]; then echo "-------------------"; echo "#find /* -xdev -nouser 2>/dev/null -eq 0 ";find /* -xdev -nouser 2>/dev/null; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"6.1.10. Đảm bảo các file hoặc thư mục không có chủ sở hữu không tồn tại\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện các câu lệnh sau để xác định các file và thư mục được sở hữu bởi người dùng hoặc group không được liệt kê trong file cấu hình hệ thống:
|
|
# df --local -P | awk '{if (NR!=1) print $6}' | xargs -I '{}' find '{}' -xdev -nogroup
|
|
# find /* -xdev -nogroup
|
|
# Thực hiện câu lệnh sau để đặt lại quyền sở hữu các file vừa tìm được cho một số người dùng hoặc group đang hoạt động trên hệ thống:
|
|
# chown <owner>:<group> <filename>
|
|
if [ $(df --local -P | awk '{if (NR!=1) print $6}' | xargs -I '{}' find '{}' -xdev -nogroup 2>/dev/null | wc -l) -ne 0 ] || [ $(find /* -xdev -nogroup 2>/dev/null | wc -l) -ne 0 ]; then
|
|
echo "{\"6.1.11. Đảm bảo các file hoặc thư mục không có nhóm không tồn tại\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện các câu lệnh sau để xác định các file và thư mục được sở hữu bởi người dùng hoặc group không được liệt kê trong file cấu hình hệ thống:
|
|
# df --local -P | awk '{if (NR!=1) print \$6}' | xargs -I '{}' find '{}' -xdev -nogroup
|
|
# find /* -xdev -nogroup
|
|
# Thực hiện câu lệnh sau để đặt lại quyền sở hữu các file vừa tìm được cho một số người dùng hoặc group đang hoạt động trên hệ thống:
|
|
# chown <owner>:<group> <filename>"
|
|
if [ $(df --local -P | awk '{if (NR!=1) print $6}' | xargs -I '{}' find '{}' -xdev -nogroup 2>/dev/null | wc -l) -ne 0 ]; then echo "-------------------"; echo "#df --local -P | awk '{if (NR!=1) print \$6}' | xargs -I '{}' find '{}' -xdev -nogroup 2>/dev/null -eq 0 ";df --local -P | awk '{if (NR!=1) print $6}' | xargs -I '{}' find '{}' -xdev -nogroup 2>/dev/null; fi
|
|
if [ $(find /* -xdev -nogroup 2>/dev/null | wc -l) -ne 0 ]; then echo "-------------------"; echo "#find /* -xdev -nogroup 2>/dev/null -eq 0 ";find /* -xdev -nogroup 2>/dev/null; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"6.1.11. Đảm bảo các file hoặc thư mục không có nhóm không tồn tại\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện câu lệnh sau để đặt shadowed passwords cho tất cả người dùng:
|
|
# sed -e 's/^\([a-zA-Z0-9_]*\):[^:]*:/\1:x:/' -i /etc/passwd
|
|
if [ $(awk -F: '($2 != "x" ) { print $1 " is not set to shadowed passwords "}' /etc/passwd | wc -l) -ne 0 ]; then
|
|
echo "{\"6.2.1. Cấu hình tài khoản trong /etc/passwd sử dụng shadowed passwords\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để đặt shadowed passwords cho tất cả người dùng:
|
|
# sed -e 's/^\\([a-zA-Z0-9_]*\\):[^:]*:/\\1:x:/' -i /etc/passwd"
|
|
if [ $(awk -F: '($2 != "x" ) { print $1 " is not set to shadowed passwords "}' /etc/passwd | wc -l) -ne 0 ]; then echo "-------------------"; echo "#awk -F: '(\$2 != \"x\" ) { print \$1 \" is not set to shadowed passwords \"}' /etc/passwd -eq 0 ";awk -F: '($2 != "x" ) { print $1 " is not set to shadowed passwords "}' /etc/passwd; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"6.2.1. Cấu hình tài khoản trong /etc/passwd sử dụng shadowed passwords\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Nếu có tài khoản nào trong file /etc/shadow không có mật khẩu, thực hiện câu lệnh sau để khoá tài khoản đến khi xác định được nguyên nhân tài khoản đó không có mật khẩu:
|
|
# passwd -l <username>
|
|
# Đồng thời, kiểm tra tài khoản đó được đăng nhập hay chưa và tìm hiểu xem tài khoản đó được sử dụng với mục đích gì để nếu nó cần phải bị xóa.
|
|
if [ $(awk -F: '$5==90 && $6==7 {print}' /etc/shadow | awk -F: ' $2=="!" || $2=="" || $2=="!!"{print $1 " " $2}' | wc -l) -ne 0 ]; then
|
|
echo "{\"6.2.2. Đảm bảo trường mật khẩu không để trống\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Nếu có tài khoản nào trong file /etc/shadow không có mật khẩu, thực hiện câu lệnh sau để khoá tài khoản đến khi xác định được nguyên nhân tài khoản đó không có mật khẩu:
|
|
# passwd -l <username>
|
|
# Đồng thời, kiểm tra tài khoản đó được đăng nhập hay chưa và tìm hiểu xem tài khoản đó được sử dụng với mục đích gì để nếu nó cần phải bị xóa."
|
|
if [ $(awk -F: '$5==90 && $6==7 {print}' /etc/shadow | awk -F: ' $2=="!" || $2=="" || $2=="!!"{print $1 " " $2}' | wc -l) -ne 0 ]; then echo "-------------------"; echo "#awk -F: '\$5==90 && \$6==7 {print}' /etc/shadow | awk -F: ' \$2==\"!\" || \$2==\"\" || \$2==\"!!\"{print \$1 \" \" \$2}' -eq 0 ";awk -F: '$5==90 && $6==7 {print}' /etc/shadow | awk -F: ' $2=="!" || $2=="" || $2=="!!"{print $1 " " $2}'; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"6.2.2. Đảm bảo trường mật khẩu không để trống\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện câu lệnh sau để xác định các nhóm tồn tại trong file /etc/passwd không tồn tại trong file /etc/group:
|
|
# for i in $(cut -s -d: -f4 /etc/passwd | sort -u ); do grep -q -P "^.*?:[^:]*:$i:" /etc/group || echo "Group $i"; done
|
|
# Thực hiện hành động thích hợp để sửa bất kỳ group nào được tìm thấy.
|
|
if [ $(for i in $(cut -s -d: -f4 /etc/passwd | sort -u ); do grep -q -P "^.*?:[^:]*:$i:" /etc/group || echo "Group $i"; done | wc -l) -ne 0 ]; then
|
|
echo "{\"6.2.3. Đảm bảo mọi nhóm trong file /etc/passwd tồn tại trong file /etc/group\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để xác định các nhóm tồn tại trong file /etc/passwd không tồn tại trong file /etc/group:
|
|
# for i in \$(cut -s -d: -f4 /etc/passwd | sort -u ); do grep -q -P \"^.*?:[^:]*:\$i:\" /etc/group || echo \"Group \$i\"; done
|
|
# Thực hiện hành động thích hợp để sửa bất kỳ group nào được tìm thấy."
|
|
if [ $(for i in $(cut -s -d: -f4 /etc/passwd | sort -u ); do grep -q -P "^.*?:[^:]*:$i:" /etc/group || echo "Group $i"; done | wc -l) -ne 0 ]; then echo "-------------------"; echo "#for i in \$(cut -s -d: -f4 /etc/passwd | sort -u ); do grep -q -P \"^.*?:[^:]*:\$i:\" /etc/group || echo \"Group \$i\"; done -eq 0 ";for i in $(cut -s -d: -f4 /etc/passwd | sort -u ); do grep -q -P "^.*?:[^:]*:$i:" /etc/group || echo "Group $i"; done; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"6.2.3. Đảm bảo mọi nhóm trong file /etc/passwd tồn tại trong file /etc/group\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện câu lệnh sau để xoá bỏ tất cả người dùng khỏi shadow group:
|
|
# sed -ri 's/(^shadow:[^:]*:[^:]*:)([^:]+$)/\1/' /etc/group
|
|
# Thực hiện câu lệnh sau để thay đổi nhóm chính của những người dùng:
|
|
# usermod -g <primary group> <user>
|
|
if [ $(awk -F: '($1=="shadow") {print $NF}' /etc/group | grep -Pv "^$" | wc -l) -ne 0 ] || [ $(awk -F: -v GID="$(awk -F: '($1=="shadow") {print $3}' /etc/group)" '($4==GID) {print $1}' /etc/passwd | wc -l) -ne 0 ]; then
|
|
echo "{\"6.2.4. Đảm bảo shadow group rỗng\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để xoá bỏ tất cả người dùng khỏi shadow group:
|
|
# sed -ri 's/(^shadow:[^:]*:[^:]*:)([^:]+\$)/\\1/' /etc/group
|
|
# Thực hiện câu lệnh sau để thay đổi nhóm chính của những người dùng:
|
|
# usermod -g <primary group> <user>"
|
|
if [ $(awk -F: '($1=="shadow") {print $NF}' /etc/group | grep -Pv "^$" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#awk -F: '(\$1==\"shadow\") {print \$NF}' /etc/group | grep -Pv \"^\$\" -eq 0 ";awk -F: '($1=="shadow") {print $NF}' /etc/group | grep -Pv "^$"; fi
|
|
if [ $(awk -F: -v GID="$(awk -F: '($1=="shadow") {print $3}' /etc/group)" '($4==GID) {print $1}' /etc/passwd | wc -l) -ne 0 ]; then echo "-------------------"; echo "#awk -F: -v GID=\"\$(awk -F: '(\$1==\"shadow\") {print \$3}' /etc/group)\" '(\$4==GID) {print \$1}' /etc/passwd -eq 0 ";awk -F: -v GID="$(awk -F: '($1=="shadow") {print $3}' /etc/group)" '($4==GID) {print $1}' /etc/passwd; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"6.2.4. Đảm bảo shadow group rỗng\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện câu lệnh sau để xác định các UID tồn tại trong file /etc/passwd không tồn tại trong file /etc/group:
|
|
# cut -f3 -d":" /etc/passwd | sort -n | uniq -c | while read x ; do [ -z "$x" ] && break; set - $x; if [ $1 -gt 1 ]; then users=$(awk -F: '($3 == n) { print $1 }' n=$2 /etc/passwd | xargs); echo "Duplicate UID ($2): $users"; fi; done
|
|
# Dựa theo kết quả trên, tạo ra một UID độc nhất và kiểm tra toàn bộ file sở hữu bởi UID bị trùng để xác định các file đó thuộc về UID nào.
|
|
if [ $(cut -f3 -d":" /etc/passwd | sort -n | uniq -c | while read x ; do [ -z "$x" ] && break; set - $x; if [ $1 -gt 1 ]; then users=$(awk -F: '($3 == n) { print $1 }' n=$2 /etc/passwd | xargs); echo "Duplicate UID ($2): $users"; fi; done | wc -l) -ne 0 ]; then
|
|
echo "{\"6.2.5. Đảm bảo UID không bị lặp\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để xác định các UID tồn tại trong file /etc/passwd không tồn tại trong file /etc/group:
|
|
# cut -f3 -d\":\" /etc/passwd | sort -n | uniq -c | while read x ; do [ -z \"\$x\" ] && break; set - \$x; if [ \$1 -gt 1 ]; then users=\$(awk -F: '(\$3 == n) { print \$1 }' n=\$2 /etc/passwd | xargs); echo \"Duplicate UID (\$2): \$users\"; fi; done
|
|
# Dựa theo kết quả trên, tạo ra một UID độc nhất và kiểm tra toàn bộ file sở hữu bởi UID bị trùng để xác định các file đó thuộc về UID nào."
|
|
if [ $(cut -f3 -d":" /etc/passwd | sort -n | uniq -c | while read x ; do [ -z "$x" ] && break; set - $x; if [ $1 -gt 1 ]; then users=$(awk -F: '($3 == n) { print $1 }' n=$2 /etc/passwd | xargs); echo "Duplicate UID ($2): $users"; fi; done | wc -l) -ne 0 ]; then echo "-------------------"; echo "#cut -f3 -d\":\" /etc/passwd | sort -n | uniq -c | while read x ; do [ -z \"\$x\" ] && break; set - \$x; if [ \$1 -gt 1 ]; then users=\$(awk -F: '(\$3 == n) { print \$1 }' n=\$2 /etc/passwd | xargs); echo \"Duplicate UID (\$2): \$users\"; fi; done -eq 0 ";cut -f3 -d":" /etc/passwd | sort -n | uniq -c | while read x ; do [ -z "$x" ] && break; set - $x; if [ $1 -gt 1 ]; then users=$(awk -F: '($3 == n) { print $1 }' n=$2 /etc/passwd | xargs); echo "Duplicate UID ($2): $users"; fi; done; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"6.2.5. Đảm bảo UID không bị lặp\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện câu lệnh sau để xác định các GID bị lặp trong file /etc/group:
|
|
# cut -d: -f3 /etc/group | sort | uniq -d | while read x ; do echo "Duplicate GID ($x) in /etc/group"; done
|
|
# Dựa theo kết quả trên, tạo ra một GID độc nhất và kiểm tra toàn bộ file sở hữu bởi GID bị trùng để xác định các file đó thuộc về GID nào.
|
|
# Có thể sử dụng lệnh grpck để kiểm tra các mâu thuẫn khác trong file/etc/group.
|
|
if [ $(cut -d: -f3 /etc/group | sort | uniq -d | while read x ; do echo "Duplicate GID ($x) in /etc/group"; done | wc -l) -ne 0 ]; then
|
|
echo "{\"6.2.6. Đảm bảo GID không bị lặp\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để xác định các GID bị lặp trong file /etc/group:
|
|
# cut -d: -f3 /etc/group | sort | uniq -d | while read x ; do echo \"Duplicate GID (\$x) in /etc/group\"; done
|
|
# Dựa theo kết quả trên, tạo ra một GID độc nhất và kiểm tra toàn bộ file sở hữu bởi GID bị trùng để xác định các file đó thuộc về GID nào.
|
|
# Có thể sử dụng lệnh grpck để kiểm tra các mâu thuẫn khác trong file/etc/group."
|
|
if [ $(cut -d: -f3 /etc/group | sort | uniq -d | while read x ; do echo "Duplicate GID ($x) in /etc/group"; done | wc -l) -ne 0 ]; then echo "-------------------"; echo "#cut -d: -f3 /etc/group | sort | uniq -d | while read x ; do echo \"Duplicate GID (\$x) in /etc/group\"; done -eq 0 ";cut -d: -f3 /etc/group | sort | uniq -d | while read x ; do echo "Duplicate GID ($x) in /etc/group"; done; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"6.2.6. Đảm bảo GID không bị lặp\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện câu lệnh sau để xác định các username bị lặp trong file /etc/passwd:
|
|
# cut -d: -f1 /etc/passwd | sort | uniq -d | while read x; do echo "Duplicate username ${x} in /etc/passwd"; done
|
|
# Dựa theo kết quả trên, tạo ra một tên người dùng độc nhất cho người dùng. Quyền sở hữu của người dùng ở file sẽ tự động cập nhật thay đổi nếu người dùng có UID độc nhất.
|
|
if [ $(cut -d: -f1 /etc/passwd | sort | uniq -d | while read x; do echo "Duplicate username ${x} in /etc/passwd"; done | wc -l) -ne 0 ]; then
|
|
echo "{\"6.2.7. Đảm bảo tên người dùng không bị lặp\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để xác định các username bị lặp trong file /etc/passwd:
|
|
# cut -d: -f1 /etc/passwd | sort | uniq -d | while read x; do echo \"Duplicate username \${x} in /etc/passwd\"; done
|
|
# Dựa theo kết quả trên, tạo ra một tên người dùng độc nhất cho người dùng. Quyền sở hữu của người dùng ở file sẽ tự động cập nhật thay đổi nếu người dùng có UID độc nhất."
|
|
if [ $(cut -d: -f1 /etc/passwd | sort | uniq -d | while read x; do echo "Duplicate username ${x} in /etc/passwd"; done | wc -l) -ne 0 ]; then echo "-------------------"; echo "#cut -d: -f1 /etc/passwd | sort | uniq -d | while read x; do echo \"Duplicate username \${x} in /etc/passwd\"; done -eq 0 ";cut -d: -f1 /etc/passwd | sort | uniq -d | while read x; do echo "Duplicate username ${x} in /etc/passwd"; done; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"6.2.7. Đảm bảo tên người dùng không bị lặp\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện câu lệnh sau để xác định các username bị lặp trong file /etc/group:
|
|
# cut -d: -f1 /etc/group | sort | uniq -d | while read -r x; do echo "Duplicate group name ${x} in /etc/group"; done
|
|
# Dựa theo kết quả trên, tạo ra một tên group độc nhất cho người dùng. Quyền sở hữu của group ở file sẽ tự động cập nhật thay đổi nếu group có GID độc nhất.
|
|
if [ $(cut -d: -f1 /etc/group | sort | uniq -d | while read -r x; do echo "Duplicate group name ${x} in /etc/group"; done | wc -l) -ne 0 ]; then
|
|
echo "{\"6.2.8. Đảm bảo tên group không bị lặp\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện câu lệnh sau để xác định các username bị lặp trong file /etc/group:
|
|
# cut -d: -f1 /etc/group | sort | uniq -d | while read -r x; do echo \"Duplicate group name \${x} in /etc/group\"; done
|
|
# Dựa theo kết quả trên, tạo ra một tên group độc nhất cho người dùng. Quyền sở hữu của group ở file sẽ tự động cập nhật thay đổi nếu group có GID độc nhất."
|
|
if [ $(cut -d: -f1 /etc/group | sort | uniq -d | while read -r x; do echo "Duplicate group name ${x} in /etc/group"; done | wc -l) -ne 0 ]; then echo "-------------------"; echo "#cut -d: -f1 /etc/group | sort | uniq -d | while read -r x; do echo \"Duplicate group name \${x} in /etc/group\"; done -eq 0 ";cut -d: -f1 /etc/group | sort | uniq -d | while read -r x; do echo "Duplicate group name ${x} in /etc/group"; done; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"6.2.8. Đảm bảo tên group không bị lặp\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện đoạn script sau để kiểm tra tính toàn vẹn cho môi trường PATH của root:
|
|
# RPCV="$(sudo -Hiu root env 2>/dev/null | grep '^PATH=' | cut -d= -f2)"; echo "$RPCV" | grep -q "::" && echo "root's path contains a empty directory (::)"; echo "$RPCV" | grep -q ":$" && echo "root's path contains a trailing (:)" ; for x in $(echo "$RPCV" | tr ":" " "); do if [ -d "$x" ]; then ls -ldH "$x" | awk '$9 == "." {print "PATH contains current working directory (.)"} $3 != "root" {print $9, "is not owned by root"} substr($1,6,1) != "-" {print $9, "is group writable"} substr($1,9,1) != "-" {print $9, "is world writable"}'; else echo "$x is not a directory"; fi; done
|
|
# Sửa chữa hoặc lý giải kết quả tìm được.
|
|
if [ $(RPCV="$(sudo -Hiu root env 2>/dev/null | grep '^PATH=' | cut -d= -f2)"; echo "$RPCV" | grep -q "::" && echo "root's path contains a empty directory (::)"; echo "$RPCV" | grep -q ":$" && echo "root's path contains a trailing (:)" ; for x in $(echo "$RPCV" | tr ":" " "); do if [ -d "$x" ]; then ls -ldH "$x" | awk '$9 == "." {print "PATH contains current working directory (.)"} $3 != "root" {print $9, "is not owned by root"} substr($1,6,1) != "-" {print $9, "is group writable"} substr($1,9,1) != "-" {print $9, "is world writable"}'; else echo "$x is not a directory"; fi; done | grep -v "/root/bin" | wc -l) -ne 0 ]; then
|
|
echo "{\"6.2.9. Đảm bảo tính toàn vẹn cho biến môi trường PATH của root\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện đoạn script sau để kiểm tra tính toàn vẹn cho môi trường PATH của root:
|
|
# RPCV=\"\$(sudo -Hiu root env 2>/dev/null | grep '^PATH=' | cut -d= -f2)\"; echo \"\$RPCV\" | grep -q \"::\" && echo \"root's path contains a empty directory (::)\"; echo \"\$RPCV\" | grep -q \":\$\" && echo \"root's path contains a trailing (:)\" ; for x in \$(echo \"\$RPCV\" | tr \":\" \" \"); do if [ -d \"\$x\" ]; then ls -ldH \"\$x\" | awk '\$9 == \".\" {print \"PATH contains current working directory (.)\"} \$3 != \"root\" {print \$9, \"is not owned by root\"} substr(\$1,6,1) != \"-\" {print \$9, \"is group writable\"} substr(\$1,9,1) != \"-\" {print \$9, \"is world writable\"}'; else echo \"\$x is not a directory\"; fi; done
|
|
# Sửa chữa hoặc lý giải kết quả tìm được."
|
|
if [ $(RPCV="$(sudo -Hiu root env 2>/dev/null | grep '^PATH=' | cut -d= -f2)"; echo "$RPCV" | grep -q "::" && echo "root's path contains a empty directory (::)"; echo "$RPCV" | grep -q ":$" && echo "root's path contains a trailing (:)" ; for x in $(echo "$RPCV" | tr ":" " "); do if [ -d "$x" ]; then ls -ldH "$x" | awk '$9 == "." {print "PATH contains current working directory (.)"} $3 != "root" {print $9, "is not owned by root"} substr($1,6,1) != "-" {print $9, "is group writable"} substr($1,9,1) != "-" {print $9, "is world writable"}'; else echo "$x is not a directory"; fi; done | grep -v "/root/bin" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#RPCV=\"\$(sudo -Hiu root env 2>/dev/null | grep '^PATH=' | cut -d= -f2)\"; echo \"\$RPCV\" | grep -q \"::\" && echo \"root's path contains a empty directory (::)\"; echo \"\$RPCV\" | grep -q \":\$\" && echo \"root's path contains a trailing (:)\" ; for x in \$(echo \"\$RPCV\" | tr \":\" \" \"); do if [ -d \"\$x\" ]; then ls -ldH \"\$x\" | awk '\$9 == \".\" {print \"PATH contains current working directory (.)\"} \$3 != \"root\" {print \$9, \"is not owned by root\"} substr(\$1,6,1) != \"-\" {print \$9, \"is group writable\"} substr(\$1,9,1) != \"-\" {print \$9, \"is world writable\"}'; else echo \"\$x is not a directory\"; fi; done | grep -v \"/root/bin\" -eq 0 ";RPCV="$(sudo -Hiu root env 2>/dev/null | grep '^PATH=' | cut -d= -f2)"; echo "$RPCV" | grep -q "::" && echo "root's path contains a empty directory (::)"; echo "$RPCV" | grep -q ":$" && echo "root's path contains a trailing (:)" ; for x in $(echo "$RPCV" | tr ":" " "); do if [ -d "$x" ]; then ls -ldH "$x" | awk '$9 == "." {print "PATH contains current working directory (.)"} $3 != "root" {print $9, "is not owned by root"} substr($1,6,1) != "-" {print $9, "is group writable"} substr($1,9,1) != "-" {print $9, "is world writable"}'; else echo "$x is not a directory"; fi; done | grep -v "/root/bin"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"6.2.9. Đảm bảo tính toàn vẹn cho biến môi trường PATH của root\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Loại bỏ bất kỳ user nào ngoài root có UID là 0 hoặc chỉ định chúng một UID mới, phù hợp với chính sách của tổ chức.
|
|
if [ $(cat /etc/passwd | awk -F: '$3==0 {print $1}' | grep -v "root" | wc -l) -ne 0 ]; then
|
|
echo "{\"6.2.10. Đảm bảo root là tài khoản duy nhất có UID là 0\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Loại bỏ bất kỳ user nào ngoài root có UID là 0 hoặc chỉ định chúng một UID mới, phù hợp với chính sách của tổ chức."
|
|
if [ $(cat /etc/passwd | awk -F: '$3==0 {print $1}' | grep -v "root" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#cat /etc/passwd | awk -F: '\$3==0 {print \$1}' | grep -v \"root\" -eq 0 ";cat /etc/passwd | awk -F: '$3==0 {print $1}' | grep -v "root"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"6.2.10. Đảm bảo root là tài khoản duy nhất có UID là 0\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện đoạn script sau để tạo và đảm bảo người dùng tương ứng sở hữu thư mục đó. Những người dùng không có thư mục home nên bị xóa hoặc chỉ định họ một thư mục home phù hợp:
|
|
# awk -F: '($1!~/(halt|sync|shutdown|nfsnobody)/ && $7!~/^(\/usr)?\/sbin\/nologin(\/)?$/ && $7!~/(\/usr)?\/bin\/false(\/)?$/) { print $1 " " $6 }' /etc/passwd | while read -r user dir; do if [ ! -d "$dir" ]; then mkdir "$dir"; chmod g-w,o-wrx "$dir"; chown "$user" "$dir"; fi; done
|
|
if [ $(awk -F: '($1!~/(halt|sync|shutdown|nfsnobody)/ && $7!~/^(\/usr)?\/sbin\/nologin(\/)?$/ && $7!~/(\/usr)?\/bin\/false(\/)?$/) { print $1 " " $6 }' /etc/passwd | while read -r user dir; do if [ ! -d "$dir" ]; then mkdir "$dir"; chmod g-w,o-wrx "$dir"; chown "$user" "$dir"; fi; done | wc -l) -ne 0 ]; then
|
|
echo "{\"6.2.11. Đảm bảo mọi người dùng đều tồn tại thư mục home\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện đoạn script sau để tạo và đảm bảo người dùng tương ứng sở hữu thư mục đó. Những người dùng không có thư mục home nên bị xóa hoặc chỉ định họ một thư mục home phù hợp:
|
|
# awk -F: '(\$1\!~/(halt|sync|shutdown|nfsnobody)/ && \$7\!~/^(\\/usr)?\\/sbin\\/nologin(\\/)?\$/ && \$7\!~/(\\/usr)?\\/bin\\/false(\\/)?\$/) { print \$1 \" \" \$6 }' /etc/passwd | while read -r user dir; do if [ ! -d \"\$dir\" ]; then mkdir \"\$dir\"; chmod g-w,o-wrx \"\$dir\"; chown \"\$user\" \"\$dir\"; fi; done"
|
|
if [ $(awk -F: '($1!~/(halt|sync|shutdown|nfsnobody)/ && $7!~/^(\/usr)?\/sbin\/nologin(\/)?$/ && $7!~/(\/usr)?\/bin\/false(\/)?$/) { print $1 " " $6 }' /etc/passwd | while read -r user dir; do if [ ! -d "$dir" ]; then mkdir "$dir"; chmod g-w,o-wrx "$dir"; chown "$user" "$dir"; fi; done | wc -l) -ne 0 ]; then echo "-------------------"; echo "#awk -F: '(\$1\!~/(halt|sync|shutdown|nfsnobody)/ && \$7\!~/^(\\/usr)?\\/sbin\\/nologin(\\/)?\$/ && \$7\!~/(\\/usr)?\\/bin\\/false(\\/)?\$/) { print \$1 \" \" \$6 }' /etc/passwd | while read -r user dir; do if [ ! -d \"\$dir\" ]; then mkdir \"\$dir\"; chmod g-w,o-wrx \"\$dir\"; chown \"\$user\" \"\$dir\"; fi; done -eq 0 ";awk -F: '($1!~/(halt|sync|shutdown|nfsnobody)/ && $7!~/^(\/usr)?\/sbin\/nologin(\/)?$/ && $7!~/(\/usr)?\/bin\/false(\/)?$/) { print $1 " " $6 }' /etc/passwd | while read -r user dir; do if [ ! -d "$dir" ]; then mkdir "$dir"; chmod g-w,o-wrx "$dir"; chown "$user" "$dir"; fi; done; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"6.2.11. Đảm bảo mọi người dùng đều tồn tại thư mục home\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện đoạn script sau để tạo hoặc thay đổi quyền sở hữu của bất kỳ thư mục home nào không được sở hữu bởi người dùng được định danh sang đúng người dùng:
|
|
# awk -F: '($1!~/(halt|sync|shutdown|nfsnobody)/ && $7!~/^(\/usr)?\/sbin\/nologin(\/)?$/ && $7!~/(\/usr)?\/bin\/false(\/)?$/) { print $1 " " $6 }' /etc/passwd | while read -r user dir; do if [ ! -d "$dir" ]; then echo "User: "$user" home directory: "$dir" does not exist "; mkdir "$dir"; chmod g-w,o-rwx "$dir"; chown "$user" "$dir"; else owner=$(stat -L -c "%U" "$dir"); if [ "$owner" != "$user" ]; then chmod g-w,o-rwx "$dir"; chown "$user" "$dir"; fi; fi; done
|
|
if [ $(awk -F: '($1!~/(halt|sync|shutdown|nfsnobody)/ && $7!~/^(\/usr)?\/sbin\/nologin(\/)?$/ && $7!~/(\/usr)?\/bin\/false(\/)?$/) { print $1 " " $6 }' /etc/passwd | while read -r user dir; do if [ ! -d "$dir" ]; then echo "User: $user home directory: $dir does not exist "; mkdir "$dir"; chmod g-w,o-rwx "$dir"; chown "$user" "$dir"; else owner=$(stat -L -c "%U" "$dir"); if [ "$owner" != "$user" ]; then chmod g-w,o-rwx "$dir"; chown "$user" "$dir"; fi; fi; done | wc -l) -ne 0 ]; then
|
|
echo "{\"6.2.12. Đảm bảo người dùng sở hữu thư mục home của chính họ\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện đoạn script sau để tạo hoặc thay đổi quyền sở hữu của bất kỳ thư mục home nào không được sở hữu bởi người dùng được định danh sang đúng người dùng:
|
|
# awk -F: '(\$1\!~/(halt|sync|shutdown|nfsnobody)/ && \$7\!~/^(\\/usr)?\\/sbin\\/nologin(\\/)?\$/ && \$7\!~/(\\/usr)?\\/bin\\/false(\\/)?\$/) { print \$1 \" \" \$6 }' /etc/passwd | while read -r user dir; do if [ ! -d \"\$dir\" ]; then echo \"User: \"\$user\" home directory: \"\$dir\" does not exist \"; mkdir \"\$dir\"; chmod g-w,o-rwx \"\$dir\"; chown \"\$user\" \"\$dir\"; else owner=\$(stat -L -c \"%U\" \"\$dir\"); if [ \"\$owner\" != \"\$user\" ]; then chmod g-w,o-rwx \"\$dir\"; chown \"\$user\" \"\$dir\"; fi; fi; done"
|
|
if [ $(awk -F: '($1!~/(halt|sync|shutdown|nfsnobody)/ && $7!~/^(\/usr)?\/sbin\/nologin(\/)?$/ && $7!~/(\/usr)?\/bin\/false(\/)?$/) { print $1 " " $6 }' /etc/passwd | while read -r user dir; do if [ ! -d "$dir" ]; then echo "User: $user home directory: $dir does not exist "; mkdir "$dir"; chmod g-w,o-rwx "$dir"; chown "$user" "$dir"; else owner=$(stat -L -c "%U" "$dir"); if [ "$owner" != "$user" ]; then chmod g-w,o-rwx "$dir"; chown "$user" "$dir"; fi; fi; done | wc -l) -ne 0 ]; then echo "-------------------"; echo "#awk -F: '(\$1\!~/(halt|sync|shutdown|nfsnobody)/ && \$7\!~/^(\\/usr)?\\/sbin\\/nologin(\\/)?\$/ && \$7\!~/(\\/usr)?\\/bin\\/false(\\/)?\$/) { print \$1 \" \" \$6 }' /etc/passwd | while read -r user dir; do if [ ! -d \"\$dir\" ]; then echo \"User: \$user home directory: \$dir does not exist \"; mkdir \"\$dir\"; chmod g-w,o-rwx \"\$dir\"; chown \"\$user\" \"\$dir\"; else owner=\$(stat -L -c \"%U\" \"\$dir\"); if [ \"\$owner\" != \"\$user\" ]; then chmod g-w,o-rwx \"\$dir\"; chown \"\$user\" \"\$dir\"; fi; fi; done -eq 0 ";awk -F: '($1!~/(halt|sync|shutdown|nfsnobody)/ && $7!~/^(\/usr)?\/sbin\/nologin(\/)?$/ && $7!~/(\/usr)?\/bin\/false(\/)?$/) { print $1 " " $6 }' /etc/passwd | while read -r user dir; do if [ ! -d "$dir" ]; then echo "User: $user home directory: $dir does not exist "; mkdir "$dir"; chmod g-w,o-rwx "$dir"; chown "$user" "$dir"; else owner=$(stat -L -c "%U" "$dir"); if [ "$owner" != "$user" ]; then chmod g-w,o-rwx "$dir"; chown "$user" "$dir"; fi; fi; done; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"6.2.12. Đảm bảo người dùng sở hữu thư mục home của chính họ\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện đoạn script sau để đặt quyền cho thư mục home của tất cả người dùng là 750:
|
|
# awk -F: '($1!~/(halt|sync|shutdown|nfsnobody)/ && $7!~/^(\/usr)?\/sbin\/nologin(\/)?$/ && $7!~/(\/usr)?\/bin\/false(\/)?$/) {print $6}' /etc/passwd | while read -r dir; do if [ -d "$dir" ]; then dirperm=$(stat -L -c "%A" "$dir"); if [ "$(echo "$dirperm" | cut -c6)" != "-" ] || [ "$(echo "$dirperm" | cut -c8)" != "-" ] || [ "$(echo "$dirperm" | cut -c9)" != "-" ] || [ "$(echo "$dirperm" | cut -c10)" != "-" ]; then chmod g-w,o-rwx "$dir"; fi; fi; done
|
|
if [ $(awk -F: '($1!~/(halt|sync|shutdown|nfsnobody)/ && $7!~/^(\/usr)?\/sbin\/nologin(\/)?$/ && $7!~/(\/usr)?\/bin\/false(\/)?$/) {print $1 " " $6}' /etc/passwd | while read -r user dir; do if [ ! -d "$dir" ]; then echo "User: \"$user\" home directory: \"$dir\" doesn't exist"; else dirperm=$(stat -L -c "%A" "$dir"); if [ "$(echo "$dirperm" | cut -c6)" != "-" ] || [ "$(echo "$dirperm" | cut -c8)" != "-" ] || [ "$(echo "$dirperm" | cut -c9)" != "-" ] || [ "$(echo "$dirperm" | cut -c10)" != "-" ]; then echo "User: \"$user\" home directory: \"$dir\" has permissions: \"$(stat -L -c "%a" "$dir")\""; fi; fi; done | wc -l) -ne 0 ]; then
|
|
echo "{\"6.2.13. Đảm bảo quyền thư mục home của người dùng có mức bảo mật cao\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện đoạn script sau để đặt quyền cho thư mục home của tất cả người dùng là 750:
|
|
# awk -F: '(\$1\!~/(halt|sync|shutdown|nfsnobody)/ && \$7\!~/^(\\/usr)?\\/sbin\\/nologin(\\/)?\$/ && \$7\!~/(\\/usr)?\\/bin\\/false(\\/)?\$/) {print \$6}' /etc/passwd | while read -r dir; do if [ -d \"\$dir\" ]; then dirperm=\$(stat -L -c \"%A\" \"\$dir\"); if [ \"\$(echo \"\$dirperm\" | cut -c6)\" != \"-\" ] || [ \"\$(echo \"\$dirperm\" | cut -c8)\" != \"-\" ] || [ \"\$(echo \"\$dirperm\" | cut -c9)\" != \"-\" ] || [ \"\$(echo \"\$dirperm\" | cut -c10)\" != \"-\" ]; then chmod g-w,o-rwx \"\$dir\"; fi; fi; done"
|
|
if [ $(awk -F: '($1!~/(halt|sync|shutdown|nfsnobody)/ && $7!~/^(\/usr)?\/sbin\/nologin(\/)?$/ && $7!~/(\/usr)?\/bin\/false(\/)?$/) {print $1 " " $6}' /etc/passwd | while read -r user dir; do if [ ! -d "$dir" ]; then echo "User: \"$user\" home directory: \"$dir\" doesn't exist"; else dirperm=$(stat -L -c "%A" "$dir"); if [ "$(echo "$dirperm" | cut -c6)" != "-" ] || [ "$(echo "$dirperm" | cut -c8)" != "-" ] || [ "$(echo "$dirperm" | cut -c9)" != "-" ] || [ "$(echo "$dirperm" | cut -c10)" != "-" ]; then echo "User: \"$user\" home directory: \"$dir\" has permissions: \"$(stat -L -c "%a" "$dir")\""; fi; fi; done | wc -l) -ne 0 ]; then echo "-------------------"; echo "#awk -F: '(\$1\!~/(halt|sync|shutdown|nfsnobody)/ && \$7\!~/^(\\/usr)?\\/sbin\\/nologin(\\/)?\$/ && \$7\!~/(\\/usr)?\\/bin\\/false(\\/)?\$/) {print \$1 \" \" \$6}' /etc/passwd | while read -r user dir; do if [ ! -d \"\$dir\" ]; then echo \"User: \\\"\$user\\\" home directory: \\\"\$dir\\\" doesn't exist\"; else dirperm=\$(stat -L -c \"%A\" \"\$dir\"); if [ \"\$(echo \"\$dirperm\" | cut -c6)\" != \"-\" ] || [ \"\$(echo \"\$dirperm\" | cut -c8)\" != \"-\" ] || [ \"\$(echo \"\$dirperm\" | cut -c9)\" != \"-\" ] || [ \"\$(echo \"\$dirperm\" | cut -c10)\" != \"-\" ]; then echo \"User: \\\"\$user\\\" home directory: \\\"\$dir\\\" has permissions: \\\"\$(stat -L -c \"%a\" \"\$dir\")\\\"\"; fi; fi; done -eq 0 ";awk -F: '($1!~/(halt|sync|shutdown|nfsnobody)/ && $7!~/^(\/usr)?\/sbin\/nologin(\/)?$/ && $7!~/(\/usr)?\/bin\/false(\/)?$/) {print $1 " " $6}' /etc/passwd | while read -r user dir; do if [ ! -d "$dir" ]; then echo "User: \"$user\" home directory: \"$dir\" doesn't exist"; else dirperm=$(stat -L -c "%A" "$dir"); if [ "$(echo "$dirperm" | cut -c6)" != "-" ] || [ "$(echo "$dirperm" | cut -c8)" != "-" ] || [ "$(echo "$dirperm" | cut -c9)" != "-" ] || [ "$(echo "$dirperm" | cut -c10)" != "-" ]; then echo "User: \"$user\" home directory: \"$dir\" has permissions: \"$(stat -L -c "%a" "$dir")\""; fi; fi; done; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"6.2.13. Đảm bảo quyền thư mục home của người dùng có mức bảo mật cao\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Việc chỉnh sửa toàn cục cho thư mục của người dùng mà không báo trước có thể khiến người dùng không hài lòng. Bởi vậy, khuyến nghị tạo nên một chính sách theo dõi để báo cáo file .netrc của người dùng và xác định hành động nên làm theo chính sách.
|
|
if [ $(find /home -name ".netrc" | wc -l) -ne 0 ]; then
|
|
echo "{\"6.2.14. Đảm bảo không người dùng nào có file .netrc\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Việc chỉnh sửa toàn cục cho thư mục của người dùng mà không báo trước có thể khiến người dùng không hài lòng. Bởi vậy, khuyến nghị tạo nên một chính sách theo dõi để báo cáo file .netrc của người dùng và xác định hành động nên làm theo chính sách."
|
|
if [ $(find /home -name ".netrc" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#find /home -name \".netrc\" -eq 0 ";find /home -name ".netrc"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"6.2.14. Đảm bảo không người dùng nào có file .netrc\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Việc chỉnh sửa toàn cục cho thư mục của người dùng mà không báo trước có thể khiến người dùng không hài lòng. Bởi vậy, khuyến nghị tạo nên một chính sách theo dõi để báo cáo file .forward của người dùng và xác định hành động nên làm theo chính sách.
|
|
if [ $(find /home/ -type f -name "*.forward" 2>/dev/null | wc -l) -ne 0 ]; then
|
|
echo "{\"6.2.15. Đảm bảo không người dùng nào có file .forward\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Việc chỉnh sửa toàn cục cho thư mục của người dùng mà không báo trước có thể khiến người dùng không hài lòng. Bởi vậy, khuyến nghị tạo nên một chính sách theo dõi để báo cáo file .forward của người dùng và xác định hành động nên làm theo chính sách."
|
|
if [ $(find /home/ -type f -name "*.forward" 2>/dev/null | wc -l) -ne 0 ]; then echo "-------------------"; echo "#find /home/ -type f -name \"*.forward\" 2>/dev/null -eq 0 ";find /home/ -type f -name "*.forward" 2>/dev/null; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"6.2.15. Đảm bảo không người dùng nào có file .forward\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Việc chỉnh sửa toàn cục cho thư mục của người dùng mà không báo trước có thể khiến người dùng không hài lòng. Bởi vậy, khuyến nghị tạo nên một chính sách theo dõi để báo cáo file .rhost của người dùng và xác định hành động nên làm theo chính sách.
|
|
if [ $(find /home -name ".rhosts" | wc -l) -ne 0 ]; then
|
|
echo "{\"6.2.16. Đảm bảo không người dùng nào có file .rhosts\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Việc chỉnh sửa toàn cục cho thư mục của người dùng mà không báo trước có thể khiến người dùng không hài lòng. Bởi vậy, khuyến nghị tạo nên một chính sách theo dõi để báo cáo file .rhost của người dùng và xác định hành động nên làm theo chính sách."
|
|
if [ $(find /home -name ".rhosts" | wc -l) -ne 0 ]; then echo "-------------------"; echo "#find /home -name \".rhosts\" -eq 0 ";find /home -name ".rhosts"; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"6.2.16. Đảm bảo không người dùng nào có file .rhosts\" : \"PASSED\"}"
|
|
fi
|
|
|
|
############################################################################
|
|
# Thực hiện đoạn script sau để loại bỏ quyền ghi các file dot của group và other:
|
|
# awk -F: '($1!~/(halt|sync|shutdown)/ && $7!~/^(\/usr)?\/sbin\/nologin(\/)?$/ && $7!~/(\/usr)?\/bin\/false(\/)?$/) { print $1 " " $6 }' /etc/passwd | while read -r user dir; do if [ -d "$dir" ]; then for file in "$dir"/.*; do if [ ! -h "$file" ] && [ -f "$file" ]; then fileperm=$(stat -L -c "%A" "$file"); if [ "$(echo "$fileperm" | cut -c6)" != "-" ] || [ "$(echo "$fileperm" | cut -c9)" != "-" ]; then chmod go-w "$file"; fi; fi; done; fi; done
|
|
if [ $(find /home/ -name ".[A-Za-z0-9]*" -perm /g+w,o+w 2>/dev/null | wc -l) -ne 0 ]; then
|
|
echo "{\"6.2.17. Đảm bảo các file dot của người dùng không cấp quyền write cho group hoặc other\" : \"FAILED\"}"
|
|
# Log
|
|
echo "######################################"
|
|
echo "# Thực hiện đoạn script sau để loại bỏ quyền ghi các file dot của group và other:
|
|
# awk -F: '(\$1\!~/(halt|sync|shutdown)/ && \$7\!~/^(\\/usr)?\\/sbin\\/nologin(\\/)?\$/ && \$7\!~/(\\/usr)?\\/bin\\/false(\\/)?\$/) { print \$1 \" \" \$6 }' /etc/passwd | while read -r user dir; do if [ -d \"\$dir\" ]; then for file in \"\$dir\"/.*; do if [ ! -h \"\$file\" ] && [ -f \"\$file\" ]; then fileperm=\$(stat -L -c \"%A\" \"\$file\"); if [ \"\$(echo \"\$fileperm\" | cut -c6)\" != \"-\" ] || [ \"\$(echo \"\$fileperm\" | cut -c9)\" != \"-\" ]; then chmod go-w \"\$file\"; fi; fi; done; fi; done"
|
|
if [ $(find /home/ -name ".[A-Za-z0-9]*" -perm /g+w,o+w 2>/dev/null | wc -l) -ne 0 ]; then echo "-------------------"; echo "#find /home/ -name \".[A-Za-z0-9]*\" -perm /g+w,o+w -eq 0 ";find /home/ -name ".[A-Za-z0-9]*" -perm /g+w,o+w 2>/dev/null; fi
|
|
echo "######################################"
|
|
else
|
|
echo "{\"6.2.17. Đảm bảo các file dot của người dùng không cấp quyền write cho group hoặc other\" : \"PASSED\"}"
|
|
fi |