tcpdump -z postrotate-commandとシェルスクリプト

tcpdump -z postrotate-commandとシェルスクリプト

私はtcpdumpの-zフラグを使ってシェルスクリプトを実行しようとしたときに何が間違っているのかを調べようとしています。このフラグを使用する例はあまりありません。マニュアルページでは、gzipをコマンドとして使用することを強調していますが、これは私にとってうまくいきます。 tcpdumpの-zのマニュアルページは次のとおりです。

-z postrotate-command
Used in conjunction with the -C or -G options, this will make tcpdump run " postrotate-command file " where file is the savefile being closed after each rotation. For example, specifying -z gzip or -z bzip2 will compress each savefile using gzip or bzip2.
Note that tcpdump will run the command in parallel to the capture, using the lowest priority so that this doesn't disturb the capture process.
And in case you would like to use a command that itself takes flags or different arguments, you can always write a shell script that will take the savefile name as the only argument, make the flags & arguments arrangements and execute the command that you want.

私の現在のシェルスクリプトは非常に基本的です...何が間違っているのかを調べようとしているようです。

test.sh - 権限の問題ではないことを確認するために、ファイルは777です。

#!/bin/sh

cp $1 $1.BAK

最初の試み:

tcpdump port 53 -i any -U -G 60 -z test.sh -Z root -w tcpdump_files/tcpdump_%M.pcap
...
compresss_savefile: execlp(test.sh, tcpdump_files/tcpdump_02.pcap) failed: No such file or directory.

このファイルを実行するには、tcpdumpに指示する必要があるようです:

tcpdump port 53 -i any -U -G 60 -z ./test.sh -Z root -w tcpdump_files/tcpdump_%M.pcap
...
compresss_savefile: execlp(./test.sh, tcpdump_files/tcpdump_02.pcap) failed: Permission denied.

おそらくスクリプトを完全に正規化したのでしょうか?いいえ..

tcpdump port 53 -i any -U -G 60 -z /home/me/test.sh -Z root -w tcpdump_files/tcpdump_%M.pcap
...
compresss_savefile: execlp(/home/me/test.sh, tcpdump_files/tcpdump_02.pcap) failed: Permission denied.

-zフラグのパラメータとバックグラウンドで実行されるexeclpの動作方法を誤解しているようです。私もこれを試しましたが、-z '/bin/sh, test.sh'No such file or dirエラーが発生します。

ベストアンサー1

解決策を見つけました:tcpdump PostScript 権限が拒否されました。

結論として:

#if this says enforce then change it to complain
grep tcpdump /sys/kernel/security/apparmor/profiles
#change to complain
aa-complain /usr/sbin/tcpdump

私の場合、箱に服はありません。しかし、sudo apt install apparmor-utils上記の手順を実行すると、権限拒否の問題が解決されました。

おすすめ記事