
UDPペイロードの末尾にある2バイト4を一致させ、0x001cと比較して確認する必要があります。 UDPペイロードに可変長がない場合、これは簡単です。 UDPペイロードの長さを取得し、ペイロードの終わりに基づいてバイトに移動するにはどうすればよいですか?
iptables -t raw -A OUTPUT -p udp --dport 53 -m u32 --u32 "$foo" -j AAAA
$foo
発信AAAAクエリと一致し、iptablesターゲットに移動するために何を入力する必要があるかを知りたいですAAAA
。
答え1
xt_u32
私はこれが仕事に適したツールだとは思わない。次のコマンドを使用すると、これを簡単に実行できますxt_bpf
。
iptables -t raw -A OUTPUT -p udp --dport 53 -m bpf --bytecode "7,128 0 0 0,20 0 0 4,7 0 0 0,72 0 0 0,21 0 1 28,6 0 0 65535,6 0 0 0" -j AAAA
バイトコードは次のBPFアセンブリから来ます。
ld #len ; get the total length of the packet
sub #4 ; subtract 4 to get the offset of the Type code
tax ; transfer the contents of register A to register X
ldh [x + 0] ; load the Type code (a half-word) into register A
jneq #0x001c, fail ; check if Type == AAAA
ret #65535 ; return success (match)
fail: ret #0 ; return failure (no match)
BPF について詳しく説明します。もう一つの答え。