iptables最近需要一个有时间限制的--set选项,或者我还能如何解决这个问题?

时间:2016-05-14 02:29:24

标签: iptables

对于端口敲门方案,我想知道如何临时(仅几秒钟)列出名称匹配的源地址的iptables最新模块。我的直觉告诉我,我需要最近模块的--set函数来接受--seconds选项,使列表赋值临时,但我只能看到将列表名称永久分配给地址并拥有另一个规则仅在收到稍后的数据包时删除列表名称分配。不适合我的心理概念的原因是因为列表中的地址的删除(--reap或--remove)只会在收到未来的数据包时发生,而我的直觉想要在某个时间到期时删除地址,而不管是否有任何数据包到达以触发所述名称删除。我可以看到做一些与此模糊相似的事情的唯一方法对我来说非常不直观,因此我怀疑我缺少一些关于它如何工作的东西:我需要一个最近的模块规则和--rcheck选项为了确保列出的数据包的名称匹配,并且它已在前一个x秒内分配并使用跳转目标将其删除,该跳转目标中的规则是将下一个列表名称分配给源地址。与此同时,列表的长度不断增长(不是吗?),填满了从未完成爆震序列的杂散源地址[s]。对于最近的模块来说,使用--set接受--seconds选项是多么简单的解决方案!谁能帮助我更清楚地看到这个?

(我已经看过使用iptables的其他敲门解决方案了,但它们仅限于使用每个端口协议组合进行序列中的一次敲击,而一个好的敲门解决方案应该,恕我直言,允许相同的端口协议组合可以在敲门序列中多次使用,因为用户希望它被使用。敲门具有相同的限制,以及表现出可怕的非稳健操作。我试图获得iptables的pknock模块,但它似乎并非所有组件都存在[特别是文档中提到的两个shell脚本,knock.sh和knock-orig.sh,据说是“在doc / pknock / util中找到”,无论在哪里......当然不是SF,Github,也不是在我能看到的任何其他地方],让我对使用它非常怀疑。)

编辑:我看到规则集需要比描述的更复杂 - 编号为2的敲门步骤首先需要先按名称匹配数据包,然后将其跳转到自己的链中删除名称,确定正确的时序和端口协议是否匹配,然后将其跳转到另一个链以重命名,或者如果时间或敲门关闭而不属于丢弃规则则不跳转。呼

1 个答案:

答案 0 :(得分:0)

我的初步解决方案如下所示。这个例子中的敲门碰巧是独特的,但非独特的敲击也会很好。正如你所看到的,我让每一个敲击包都收获每个列表,因为我不知道这些列表是否会限制他们以其他方式保留条目的时间长度。这似乎是确保没有列表可以变得太长的唯一方法。

$ - > iptables -wnvL

Chain INPUT (policy DROP)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     tcp  --  $internal_net_interface   *       0.0.0.0/0            0.0.0.0/0            tcp dpt:22 ctstate RELATED,ESTABLISHED /* extract ssh for knock testg frm private side in ssh */
    0     0 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: REMOVE name: authorized side: source mask: 255.255.255.255 ctstate NEW /* 1-packet pass: 1 chance to establish or then knock higher */
    0     0 knockerstest  all  --  $internal_net_interface   *       0.0.0.0/0            0.0.0.0/0            recent: CHECK seconds: 200 name: knocker side: source mask: 255.255.255.255 /* for knock capability */
    0     0 knockstage1  tcp  --  $internal_net_interface   *       0.0.0.0/0            0.0.0.0/0            tcp dpt:1 flags:0x17/0x02 recent: SET name: knocker side: source mask: 255.255.255.255 /* for knock capability, 1st port */
    0     0 knockers   all  --  $external_net_interface  *       0.0.0.0/0            0.0.0.0/0            recent: CHECK seconds: 200 name: knocker side: source mask: 255.255.255.255 ctstate NEW /* for port knock capability */
    0     0 knockstage1  tcp  --  $external_net_interface  *       0.0.0.0/0            0.0.0.0/0            ctstate NEW tcp dpt:1 flags:0x17/0x02 recent: SET name: knocker side: source mask: 255.255.255.255 /* for port knock capability, 1st port */

Chain knockerreap (10 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0            all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: CHECK seconds: 60 reap name: knocker side: source mask: 255.255.255.255
    0     0            all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: SET name: knockstage1 side: source mask: 255.255.255.255
    0     0            all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: SET name: knockstage2 side: source mask: 255.255.255.255
    0     0            all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: SET name: knockstage3 side: source mask: 255.255.255.255
    0     0            all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: SET name: knockstage4 side: source mask: 255.255.255.255
    0     0            all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: SET name: knockstage5 side: source mask: 255.255.255.255
    0     0            all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: SET name: knockstage6 side: source mask: 255.255.255.255
    0     0            all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: SET name: knockstage7 side: source mask: 255.255.255.255
    0     0            all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: SET name: knockstage8 side: source mask: 255.255.255.255
    0     0            all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: CHECK seconds: 12 reap name: knockstage1 side: source mask: 255.255.255.255
    0     0            all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: CHECK seconds: 12 reap name: knockstage2 side: source mask: 255.255.255.255
    0     0            all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: CHECK seconds: 12 reap name: knockstage3 side: source mask: 255.255.255.255
    0     0            all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: CHECK seconds: 12 reap name: knockstage4 side: source mask: 255.255.255.255
    0     0            all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: CHECK seconds: 12 reap name: knockstage5 side: source mask: 255.255.255.255
    0     0            all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: CHECK seconds: 12 reap name: knockstage6 side: source mask: 255.255.255.255
    0     0            all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: CHECK seconds: 12 reap name: knockstage7 side: source mask: 255.255.255.255
    0     0            all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: CHECK seconds: 12 reap name: knockstage8 side: source mask: 255.255.255.255
    0     0            all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: REMOVE name: knockstage1 side: source mask: 255.255.255.255
    0     0            all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: REMOVE name: knockstage2 side: source mask: 255.255.255.255
    0     0            all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: REMOVE name: knockstage3 side: source mask: 255.255.255.255
    0     0            all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: REMOVE name: knockstage4 side: source mask: 255.255.255.255
    0     0            all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: REMOVE name: knockstage5 side: source mask: 255.255.255.255
    0     0            all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: REMOVE name: knockstage6 side: source mask: 255.255.255.255
    0     0            all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: REMOVE name: knockstage7 side: source mask: 255.255.255.255
    0     0            all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: REMOVE name: knockstage8 side: source mask: 255.255.255.255

Chain knockers (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 knockerreap  all  --  *      *       0.0.0.0/0            0.0.0.0/0            ! ctstate NEW /* for port knock capability */
    0     0 knockersort  all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate NEW /* for port knock capability */
    0     0 LOG        all  --  *      *       0.0.0.0/0            0.0.0.0/0            LOG flags 0 level 4 prefix "pktfail:knock|late|ctstate "
    0     0            all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: CHECK seconds: 60 reap name: knocker side: source mask: 255.255.255.255
    0     0            all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: REMOVE name: knocker side: source mask: 255.255.255.255
    0     0 knockerreap  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain knockersort (2 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 knockstage2  tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:2 flags:0x17/0x02 recent: CHECK seconds: 12 name: knockstage2 side: source mask: 255.255.255.255 /* knock to stage 2 successful */
    0     0 knockstage3  tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:3 flags:0x17/0x02 recent: CHECK seconds: 12 name: knockstage3 side: source mask: 255.255.255.255 /* knock to stage 3 successful */
    0     0 knockstage4  tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:4 flags:0x17/0x02 recent: CHECK seconds: 12 name: knockstage4 side: source mask: 255.255.255.255 /* knock to stage 4 successful */
    0     0 knockstage5  tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:5 flags:0x17/0x02 recent: CHECK seconds: 12 name: knockstage5 side: source mask: 255.255.255.255 /* knock to stage 5 successful */
    0     0 knockstage6  tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:6 flags:0x17/0x02 recent: CHECK seconds: 12 name: knockstage6 side: source mask: 255.255.255.255 /* knock to stage 6 successful */
    0     0 knockstage7  tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:7 flags:0x17/0x02 recent: CHECK seconds: 12 name: knockstage7 side: source mask: 255.255.255.255 /* knock to stage 7 successful */

Chain knockerstest (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 knockersort  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 LOG        all  --  *      *       0.0.0.0/0            0.0.0.0/0            LOG flags 0 level 4 prefix "knockertest fail "
    0     0            all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: CHECK seconds: 60 reap name: knocker side: source mask: 255.255.255.255
    0     0            all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: REMOVE name: knocker side: source mask: 255.255.255.255
    0     0 knockerreap  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain knockstage1 (2 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 knockerreap  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 LOG        all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: SET name: knockstage2 side: source mask: 255.255.255.255 /* Entry in log makes blacklisting get delayed until after knocking time window expires */ LOG flags 0 level 4 prefix "knocked: Stage1 "
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain knockstage2 (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 knockerreap  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 LOG        all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: SET name: knockstage3 side: source mask: 255.255.255.255 /* Entry in log makes blacklisting get delayed until after knocking time window expires */ LOG flags 0 level 4 prefix "knocked: Stage2 "
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain knockstage3 (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 knockerreap  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 LOG        all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: SET name: knockstage4 side: source mask: 255.255.255.255 /* Entry in log makes blacklisting get delayed until after knocking time window expires */ LOG flags 0 level 4 prefix "knocked: Stage3 "
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain knockstage4 (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 knockerreap  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 LOG        all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: SET name: knockstage5 side: source mask: 255.255.255.255 /* Entry in log makes blacklisting get delayed until after knocking time window expires */ LOG flags 0 level 4 prefix "knocked: Stage4 "
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain knockstage5 (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 knockerreap  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 LOG        all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: SET name: knockstage6 side: source mask: 255.255.255.255 /* Entry in log makes blacklisting get delayed until after knocking time window expires */ LOG flags 0 level 4 prefix "knocked: Stage5 "
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain knockstage6 (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 knockerreap  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 LOG        all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: SET name: knockstage7 side: source mask: 255.255.255.255 /* Entry in log makes blacklisting get delayed until after knocking time window expires */ LOG flags 0 level 4 prefix "knocked: Stage6 "
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain knockstage7 (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 knockerreap  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 LOG        all  --  *      *       0.0.0.0/0            0.0.0.0/0            recent: SET name: authorized side: source mask: 255.255.255.255 /* allows time-limited access */ LOG flags 0 level 4 prefix "knock full success "
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0