nflog 使用
  WNX8ZrUuErM5 2023年11月02日 52 0

  xx产品有个功能是对任何端口的访问都会被记录。它的实现原理是iptables的NFLOG

NFLOG是什么

它是一个target,就像ACCEPT、DROP等可以作为iptables -j后的参数值

iptables -A INPUT -p tcp -m tcp --dport 80 -j NFLOG --nflog-group 40 --nflog-prefix TCPDUMP-PCAP-IN
tcpdump -i nflog:40 -v -w nf40.pcap
// 此时tcpdump必须使用 -w 参数报文报文

 tcpdump  -i nflog:40 -v -w nf40.pcap
tcpdump: listening on nflog:40, link-type NFLOG (Linux netfilter log messages), capture size 262144 bytes

示例:

Can I log and drop packets with nflog in one iptables rule?

-N log_and_drop
-A log_and_drop -j NFLOG --nflog-prefix "shared prefix"
-A log_and_drop -j DROP
-A INPUT -p tcp --sport 1234 -g log_and_drop
-A INPUT -p udp --sport 4321 -g log_and_drop

Is there any way to put NFLOG (--nflog-prefix) inside the iptables rule so that there is only one line left?

NFLOG:https://ipset.netfilter.org/iptables-extensions.man.html#lbDG

 

内核代码为:

static struct xt_target ebt_nflog_tg_reg __read_mostly = {
	.name       = "nflog",
	.revision   = 0,
	.family     = NFPROTO_BRIDGE,
	.target     = ebt_nflog_tg,
	.checkentry = ebt_nflog_tg_check,
	.targetsize = sizeof(struct ebt_nflog_info),
	.me         = THIS_MODULE,
};
ebt_nflog_tg(struct sk_buff *skb, const struct xt_action_param *par)
{
	const struct ebt_nflog_info *info = par->targinfo;
	struct net *net = xt_net(par);
	struct nf_loginfo li;

	li.type = NF_LOG_TYPE_ULOG;
	li.u.ulog.copy_len = info->len;
	li.u.ulog.group = info->group;
	li.u.ulog.qthreshold = info->threshold;
	li.u.ulog.flags = 0;

	nf_log_packet(net, PF_BRIDGE, xt_hooknum(par), skb, xt_in(par),
		      xt_out(par), &li, "%s", info->prefix);
	return EBT_CONTINUE;
}

 

http代理服务器(3-4-7层代理)-网络事件库公共组件、内核kernel驱动 摄像头驱动 tcpip网络协议栈、netfilter、bridge 好像看过!!!! 但行好事 莫问前程 --身高体重180的胖子



【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
WNX8ZrUuErM5
作者其他文章 更多