TMAegisBeta
Thêm quy tắc cho linux

Linux distributions

TMA-ALINUX2-3.5.1.4

Ensure firewall rules exist for all open ports

Trung bìnhCấp 1Tự độnglinux

Mô tả

Any ports that have been opened on non-loopback addresses need firewall rules to govern traffic.

Cách kiểm tra

Phương pháp kiểm tra: Lệnh shell

shell
alt0() { command -v netstat >/dev/null 2>&1 || { echo "step1: netstat not installed"; return 1; }; o=$(bash -c 'netstat -ln Active Internet connections (only servers)' 2>&1); printf '%s\n' "$o" | tr -s ' \t' '  ' | sed 's/^ //;s/ $//' | grep -Fxq -- 'Proto Recv-Q Send-Q Local Address Foreign Address State' || { echo step1: missing 'Proto Recv-Q Send-Q Local Address Foreign Address State'; return 1; }; printf '%s\n' "$o" | tr -s ' \t' '  ' | sed 's/^ //;s/ $//' | grep -Fxq -- 'tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN' || { echo step1: missing 'tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN'; return 1; }; command -v iptables >/dev/null 2>&1 || { echo "step2: iptables not installed"; return 1; }; o=$(bash -c 'iptables -L INPUT -v -n Chain INPUT (policy DROP 0 packets, 0 bytes)' 2>&1); printf '%s\n' "$o" | tr -s ' \t' '  ' | sed 's/^ //;s/ $//' | grep -Fxq -- 'pkts bytes target prot opt in out source' || { echo step2: missing 'pkts bytes target prot opt in out source'; return 1; }; printf '%s\n' "$o" | tr -s ' \t' '  ' | sed 's/^ //;s/ $//' | grep -Fxq -- destination || { echo step2: missing destination; return 1; }; printf '%s\n' "$o" | tr -s ' \t' '  ' | sed 's/^ //;s/ $//' | grep -Fxq -- '0 0 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0' || { echo step2: missing '0 0 ACCEPT all -- lo * 0.0.0.0/0 0.0.0.0/0'; return 1; }; printf '%s\n' "$o" | tr -s ' \t' '  ' | sed 's/^ //;s/ $//' | grep -Fxq -- '0 0 DROP all -- * * 127.0.0.0/8 0.0.0.0/0' || { echo step2: missing '0 0 DROP all -- * * 127.0.0.0/8 0.0.0.0/0'; return 1; }; printf '%s\n' "$o" | tr -s ' \t' '  ' | sed 's/^ //;s/ $//' | grep -Fxq -- '0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0' || { echo step2: missing '0 0 ACCEPT tcp -- * * 0.0.0.0/0 0.0.0.0/0'; return 1; }; printf '%s\n' "$o" | tr -s ' \t' '  ' | sed 's/^ //;s/ $//' | grep -Fxq -- 'tcp dpt:22 state NEW' || { echo step2: missing 'tcp dpt:22 state NEW'; return 1; }; }; if alt0; then echo compliant; fi
Đầu ra mong đợi
compliant

Cách khắc phục

Phương pháp khắc phục: Hướng dẫn hoặc bản vá hạ tầng

For each port identified in the audit which does not have a firewall rule establish a proper rule for accepting inbound connections: # iptables -A INPUT -p <protocol> --dport <port> -m state --state NEW -j ACCEPT For example: # ss -tunlp |awk 'NR!=1' |awk -F ' ' '{print $1":"$5}' |awk -F ':' '($2!="127.0.0.1"){print $1" "$NF}'| while read protocol port; do iptables -A INPUT -p $protocol --dport $port -m state --state NEW -j ACCEPT; done # service iptables save

Thuộc tính

Hệ điều hành
alinux-2
Thẻ
cis-convertedlinux
Tham chiếu
CIS Aliyun Linux 2 Benchmark v1.0.0 ARCHIVE - 3.5.1.4

Kiểm tra máy này

Chạy lệnh này trên máy bạn được phép kiểm tra. Lần quét chỉ ở chế độ đọc.

shell
tmaegis scan --target linux