hack のためのネタ帳, etc,,,

状況

knockd を仕掛けている Debian に knock しても port が開かなくなった。
ps ax|grep knockd
みたいにすると knockd 自体は立ち上がっているので
/etc/knockd.conf を確認してみると
[options]
	UseSyslog
...
となっていたので、/var/log/syslog を確認してみると、
Nov 10 00:42:17 xxxxxxx knockd: xxx.xx.xxx.xxx: openSSH: Stage 1
Nov 10 00:42:17 efleat1 knockd: xxx.xx.xxx.xxx: openSSH: Stage 2
Nov 10 00:42:17 efleat1 knockd: xxx.xx.xxx.xxx: openSSH: Stage 3
Nov 10 00:42:17 efleat1 knockd: xxx.xx.xxx.xxx: openSSH: OPEN SESAME
Nov 10 00:42:17 efleat1 knockd: openSSH: running command: /sbin/iptables -I INPUT 2 -s xxx.xx.xxx.xxx -p tcp --dport 22 -j ACCEPT
Nov 10 00:42:17 efleat1 knockd[1432]: iptables: Index of insertion too big.
Nov 10 00:42:17 efleat1 knockd[1432]: openSSH: command returned non-zero status code (1)
みたいな事になっている。
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         
# Warning: iptables-legacy tables present, use iptables-legacy to see them

ルールが空なのに加えて、iptables-legacy とかいう見慣れないコマンドが。
そう言えば、最近 firewall 周りが新しくなったとか言うはなしがあったなーと思い、
言われるがままに iptables-legacy を試してみると
$ sudo iptables-legacy -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     tcp  --  xxxxxxxx.xxx.xxxxxxxxxxx.xx.xx  anywhere             tcp dpt:ssh
DROP       all  --  anywhere             anywhere             state INVALID,NEW

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
DROP       all  --  anywhere             anywhere             state INVALID,NEW
TCPMSS     tcp  --  anywhere             anywhere             tcp flags:SYN,RST/SYN TCPMSS clamp to PMTU

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
REJECT     tcp  --  anywhere             anywhere             tcp dpt:auth reject-with tcp-reset
のような状況。
iptables 野実態を確認してみると
$ ls -l /sbin/iptables
lrwxrwxrwx 1 root root 18 12月  1  2018 /sbin/iptables -> /usr/sbin/iptables*
みたいな状況。

どうもパケットフィルタ周りが旧来の getsockopt/setsockopt-based kernel api から新しく nftables kernel api に変わった事に伴い、iptables が iptables-ntf と iptables-legacy に分かれて並立しているようだ。

解決方法

nftables の方に移行した方が良さそうな気はしたんだが、とりあえずという事で、/etc/knockd の /sbin/iptables を /usr/sbin/iptables-legacy に書き換えて knockd を再起動してみたところ、knock が通るようになった。

コメントをかく


「http://」を含む投稿は禁止されています。

利用規約をご確認のうえご記入下さい

Wiki内検索

フリーエリア

管理人/副管理人のみ編集できます