0

几天前,我通过 SSH 在我的 Ubuntu 主机上安装了 CSF。一切似乎都运行良好,我有机会玩了几个小时。弄清楚我如何关闭和打开端口。一切似乎都运行良好。

今天我尝试对我的 3306 mysql 端口进行限制,只允许特定 IP 地址访问。我通过检查它是否已从 csf.conf 上的 TCP_IN 和 TCP_OUT 行中删除并将其插入 csf.allow 来做到这一点。

这似乎不起作用,因为在使用 nmap 扫描端口时,端口似乎是打开的。在进一步调试之后,我发现我现在对 csf.conf 和 csf.allow 文件所做的任何更改都不会影响端口的可用性。

我进一步研究,发现 ufw 防火墙、iptables 和 csf 之间可能存在一些问题,所以我停止了 ufw 防火墙并删除了我所有的 iptables 规则并将它们设置为默认值。

:~$ sudo iptables -L

Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

:~$ sudo service ufw status
ufw stop/waiting

现在我刚刚刷新、停止并启动了 csf 防火墙: csf -f, csf -x, csf -e

重新启动后,似乎 sudo iptables -L 将输出一个巨大的规则列表,其中源为任何地方,目的地为任何地方。我以前没有这方面的经验,所以我不确定我是否能够提取正确的敏感信息,但在阅读了它之后,我认为这不适合我的情况。

另一方面 csf -L 有不同的输出。大多数源和目标 ip 为 0.0.0.0/0。我可以从 csf -L 输出中提取的是存在一个无效链。

Chain INVALID (2 references)
num   pkts bytes target     prot opt in     out     source                      destination
1        0     0 INVDROP    all  --  *      *       0.0.0.0/0               0.0.0.0/0            ctstate INVALID
2        0     0 INVDROP    tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp flags:0x3F/0x00
3        0     0 INVDROP    tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp flags:0x3F/0x3F
4        0     0 INVDROP    tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp flags:0x03/0x03
5        0     0 INVDROP    tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp flags:0x06/0x06
6        0     0 INVDROP    tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp flags:0x05/0x05
7        0     0 INVDROP    tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp flags:0x11/0x01
8        0     0 INVDROP    tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp flags:0x18/0x08
9        0     0 INVDROP    tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp flags:0x30/0x20
10       0     0 INVDROP    tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp flags:!0x17/0x02 ctstate NEW

Chain ALLOWIN (1 references)
num   pkts bytes target     prot opt in     out     source               destination
 1      210 10680 ACCEPT     all  --  !lo    *       [mysship]        0.0.0.0/0

Chain ALLOWOUT (1 references)
num   pkts bytes target     prot opt in     out     source                destination
1      295 41404 ACCEPT     all  --  *      !lo     0.0.0.0/0              [mysship]

MYSSHIP 是我使用 SSH 连接的 IP,我已将其放在 csf.allow 上,并且 ssh 端口位于 csf.conf TCP_IN、TCP_OUT 列表中。

4

2 回答 2

0

我不确定是什么导致了混乱,但我从 iptables 和 csf 中刷新了我以前的所有配置。我重新安装了 csf,而不是一个一个地编写所有配置,使用 nmap 在每一步进行测试。我还将 TESTING_INTERVAL 修改为 15。我认为在保持 TESTING = 1 时,我的防火墙设置被清除得太快;

于 2016-08-31T10:53:57.753 回答
0

Emm,对我来说,我将策略更改为 Drop,然后我允许任何我想要的,看看:

Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ssh

Chain FORWARD (policy DROP)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

您可以使用 -s(对于源)或 -d(对于目标)添加您想要的 IP@!

于 2016-08-31T07:34:53.810 回答