CN113489737A - 一种基于netfilter的包过滤器的实现方法 - Google Patents

一种基于netfilter的包过滤器的实现方法 Download PDF

Info

Publication number
CN113489737A
CN113489737A CN202110797863.6A CN202110797863A CN113489737A CN 113489737 A CN113489737 A CN 113489737A CN 202110797863 A CN202110797863 A CN 202110797863A CN 113489737 A CN113489737 A CN 113489737A
Authority
CN
China
Prior art keywords
data packet
netfilter
byte
rule
filter
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110797863.6A
Other languages
English (en)
Inventor
杨振力
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Xinhe Semiconductor Technology Wuxi Co Ltd
Original Assignee
Xinhe Semiconductor Technology Wuxi Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Xinhe Semiconductor Technology Wuxi Co Ltd filed Critical Xinhe Semiconductor Technology Wuxi Co Ltd
Priority to CN202110797863.6A priority Critical patent/CN113489737A/zh
Publication of CN113489737A publication Critical patent/CN113489737A/zh
Pending legal-status Critical Current

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L63/00Network architectures or network communication protocols for network security
    • H04L63/02Network architectures or network communication protocols for network security for separating internal from external traffic, e.g. firewalls
    • H04L63/0227Filtering policies
    • H04L63/0263Rule management
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L63/00Network architectures or network communication protocols for network security
    • H04L63/02Network architectures or network communication protocols for network security for separating internal from external traffic, e.g. firewalls
    • H04L63/0227Filtering policies
    • H04L63/0236Filtering by address, protocol, port number or service, e.g. IP-address or URL

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • Computer Security & Cryptography (AREA)
  • Computing Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Business, Economics & Management (AREA)
  • General Business, Economics & Management (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

本发明公开了一种基于netfilter的包过滤器的实现方法,包括以下步骤:加载数据包过滤模块到Linux内核中,挂载HOOK函数;用户态通过proc文件系统向内核态添加过滤规则;Linux内核netfilter的HOOK模块接收网络数据包;过滤模块进行规则匹配,丢弃匹配成功的数据包,放行匹配失败的数据包。本发明能对通过网关的任意包的指定字节进行精准过滤,对二层三层和应用层数据包都能进行过滤,过滤规则具有灵活性,增加通信过程中的安全性,以此达到更好的保护效果;适用于各种需要过滤数据包的网关系统中,也适用于各种需要过滤数据包的测试系统中。

Description

一种基于netfilter的包过滤器的实现方法
技术领域
本发明涉及数据包过滤技术领域,具体是一种基于netfilter的包过滤器的实现方法。
背景技术
在数据通信领域,经常要对数据包进行过滤,以实现特定的功能或安全特性。目前Iptable防火墙可以对通过系统的数据包的指定字节进行过滤,但却只能过滤三层数据包,对二层数据包没有办法。Ebtable防火墙可以过滤二层数据包,但却做不到针对指定字节进行精准过滤。但是这两种方法都无法做到对任意包的任意字节进行过滤。
发明内容
本发明的目的在于提供一种基于netfilter的包过滤器的实现方法,对经过系统的数据包进行针对性的过滤,理论上可以对任意数据包的任意字节进行过滤;过滤规则通过proc文件系统进行增加或删除,以尾队列的形式存储在linux内核模块中,以解决上述背景技术中提出的问题。
为实现上述目的,本发明提供如下技术方案:
一种基于netfilter的包过滤器的实现方法,包括以下步骤:
S1:加载数据包过滤模块到Linux内核中,挂载HOOK函数。
S2:用户态通过proc文件系统向内核态添加过滤规则。
S3:Linux内核netfilter的HOOK模块接收网络数据包。
S4:过滤模块进行规则匹配,丢弃匹配成功的数据包,放行匹配失败的数据包。
作为本发明的进一步方案:S1中的注册点为NF_BR_PRE_ROUTING。
作为本发明的进一步方案:S2中过滤规则由一个或多个三元组组成,每个三元组包括字节偏移、类型和值;
字节偏移:要过滤字节相对数据包第一个字节的位置偏移;
类型:匹配字节的类型,一个字节或两个字节或四个字节;
值:匹配字节的值。
作为本发明的进一步方案:每个三元组通过“,”间隔,每个规则之间通过“;”间隔。
作为本发明的进一步方案:匹配规则在内核态中以尾队列的方式存储,每个规则是尾队列的一个元素,每个元素又是另一个尾队列,其元素是三元组。
作为本发明的再进一步方案:步骤S4中遍历尾队列,将数据包与每个规则进行匹配,匹配成功就丢弃该数据包,否则就放行数据包。
与现有技术相比,本发明的优点是:
1.发明对任意数据包的任意字节都能进行精准的过滤;对二层三层和应用层数据包都能进行过滤;过滤规则具有灵活性。
2.本发明提供的一种基于netfilter的包过滤器的实现方法,适用于各种需要过滤数据包的网关系统中;也适用于各种需要过滤数据包的测试系统中。
附图说明
图1为一种基于netfilter的包过滤器的实现方法中内核态过滤规则存储数据结构。
图2为一种基于netfilter的包过滤器的实现方法的工作过程图。
具体实施方式
下面结合具体实施方式对本专利的技术方案作进一步详细地说明。
请参阅图1-2,一种基于netfilter的包过滤器的实现方法,包括下述步骤:
S1:加载数据包过滤模块到Linux内核中,挂载HOOK函数。
S2:用户态通过proc文件系统向内核态添加过滤规则。
S3:Linux内核netfilter的HOOK模块接收网络数据包。
S4:过滤模块进行规则匹配,丢弃匹配成功的数据包,放行匹配失败的数据包。
S01中的注册点为NF_BR_PRE_ROUTING。
S02中过滤规则由一个或多个三元组组成,每个三元组包括字节偏移、类型和值;
字节偏移:要过滤字节相对数据包第一个字节的位置偏移;
类型:匹配字节的类型,一个字节或两个字节或四个字节;
值:匹配字节的值。
每个三元组通过“,”间隔,每个规则之间通过“;”间隔。
匹配规则在内核态中以尾队列的方式存储,每个规则是尾队列的一个元素,每个元素又是另一个尾队列,其元素是三元组,如附图1所示。
步骤S04中遍历尾队列,将数据包与每个规则进行匹配,匹配成功就丢弃该数据包,否则就放行数据包。
例如添加以下规则可以过滤DHCP request包:
“1220x0800,2310x11,3440x00440043,4210x01”
其含义如下:
“1220x0800”:IPv4协议
“2310x11”:UDP协议
“3440x00440043”:源端口68,目的端口67
“4210x01”:DHCP Message type:Boot Request
这个规则仅过滤DHCP request包,对DHCP discover,DHCP offer和DHCP ack包仍然是放行的。
本发明提供的一种基于netfilter的包过滤器的实现方法,能对通过网关的任意包的指定字节进行精准过滤,增加通信过程中的安全性,以此达到更好的保护效果。
上面对本专利的较佳实施方式作了详细说明,但是本专利并不限于上述实施方式,在本领域的普通技术人员所具备的知识范围内,还可以在不脱离本专利宗旨的前提下作出各种变化。

Claims (6)

1.一种基于netfilter的包过滤器的实现方法,其特征在于,包括以下步骤:
S1:加载数据包过滤模块到Linux内核中,挂载HOOK函数;
S2:用户态通过proc文件系统向内核态添加过滤规则;
S3:Linux内核netfilter的HOOK模块接收网络数据包;
S4:过滤模块进行规则匹配,丢弃匹配成功的数据包,放行匹配失败的数据包。
2.根据权利要求1所述的一种基于netfilter的包过滤器的实现方法,其特征在于,所述步骤S1中的注册点为NF_BR_PRE_ROUTING。
3.根据权利要求1所述的一种基于netfilter的包过滤器的实现方法,其特征在于,所述步骤S2中过滤规则由一个或多个三元组组成,每个三元组包括字节偏移、类型和值,其中:
字节偏移:要过滤字节相对数据包第一个字节的位置偏移;
类型:匹配字节的类型,一个字节或两个字节或四个字节;
值:匹配字节的值。
4.根据权利要求3所述的一种基于netfilter的包过滤器的实现方法,其特征在于,所述每个三元组通过“,”间隔,每个规则之间通过“;”间隔。
5.根据权利要求1所述的一种基于netfilter的包过滤器的实现方法,其特征在于,所述匹配规则在内核态中以尾队列的方式存储,每个规则是尾队列的一个元素,每个元素又是另一个尾队列,其元素是三元组。
6.根据权利要求1-5任一所述的一种基于netfilter的包过滤器的实现方法,其特征在于,所述步骤S4中遍历尾队列,将数据包与每个规则进行匹配,匹配成功就丢弃该数据包,否则就放行数据包。
CN202110797863.6A 2021-07-14 2021-07-14 一种基于netfilter的包过滤器的实现方法 Pending CN113489737A (zh)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110797863.6A CN113489737A (zh) 2021-07-14 2021-07-14 一种基于netfilter的包过滤器的实现方法

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110797863.6A CN113489737A (zh) 2021-07-14 2021-07-14 一种基于netfilter的包过滤器的实现方法

Publications (1)

Publication Number Publication Date
CN113489737A true CN113489737A (zh) 2021-10-08

Family

ID=77939516

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110797863.6A Pending CN113489737A (zh) 2021-07-14 2021-07-14 一种基于netfilter的包过滤器的实现方法

Country Status (1)

Country Link
CN (1) CN113489737A (zh)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115883255A (zh) * 2023-02-02 2023-03-31 中信证券股份有限公司 数据过滤方法、设备以及计算机可读介质

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20090034519A1 (en) * 2007-08-01 2009-02-05 International Business Machines Corporation Packet filterting by applying filter rules to a packet bytestream
US8549135B1 (en) * 2007-05-18 2013-10-01 Raytheon Company Method and apparatus for performing quality of service in secure networks
WO2015074324A1 (zh) * 2013-11-22 2015-05-28 上海斐讯数据通信技术有限公司 一种数据包快速转发方法及装置
CN108632113A (zh) * 2018-05-07 2018-10-09 上海市共进通信技术有限公司 基于Linux内核的数据流监控方法及系统
CN109450893A (zh) * 2018-11-05 2019-03-08 南京壹进制信息技术股份有限公司 一种基于linux内核的网络防护软件方法和系统

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8549135B1 (en) * 2007-05-18 2013-10-01 Raytheon Company Method and apparatus for performing quality of service in secure networks
US20090034519A1 (en) * 2007-08-01 2009-02-05 International Business Machines Corporation Packet filterting by applying filter rules to a packet bytestream
WO2015074324A1 (zh) * 2013-11-22 2015-05-28 上海斐讯数据通信技术有限公司 一种数据包快速转发方法及装置
CN108632113A (zh) * 2018-05-07 2018-10-09 上海市共进通信技术有限公司 基于Linux内核的数据流监控方法及系统
CN109450893A (zh) * 2018-11-05 2019-03-08 南京壹进制信息技术股份有限公司 一种基于linux内核的网络防护软件方法和系统

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
申玲钰,朱振乾: "防火墙与 IPsec 协同实现 L3/L2 一体化 VPN", 《通信技术》 *

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115883255A (zh) * 2023-02-02 2023-03-31 中信证券股份有限公司 数据过滤方法、设备以及计算机可读介质

Similar Documents

Publication Publication Date Title
US7360245B1 (en) Method and system for filtering spoofed packets in a network
EP3076612B1 (en) Packet processing methods and nodes
US8995453B2 (en) Systems and methods for providing a VPN solution
CA2287813C (en) System and method for network load balancing
US7107609B2 (en) Stateful packet forwarding in a firewall cluster
EP1632063B1 (en) Method and appartus for packet claasification and rewriting
US20050268332A1 (en) Extensions to filter on IPv6 header
US7181612B1 (en) Facilitating IPsec communications through devices that employ address translation in a telecommunications network
CN105323259B (zh) 一种防止同步包攻击的方法和装置
CN103763194A (zh) 一种报文转发方法及装置
US8650632B2 (en) Scalable transparent proxy
CN113489737A (zh) 一种基于netfilter的包过滤器的实现方法
US9667650B2 (en) Anti-replay checking with multiple sequence number spaces
CN112118258B (zh) 在蜜罐场景下获取攻击者信息的系统及方法
WO2016202377A1 (en) Avb frame forwarding
Cisco Transparent Bridging Commands
Cisco Configuring Transparent Bridging
Cisco Transparent Bridging Commands
Cisco Transparent Bridging Commands
Cisco Configuring Transparent Bridging
Cisco Configuring Transparent Bridging
Cisco Configuring Transparent Bridging
Cisco Transparent Bridging Commands
Cisco Transparent Bridging Commands
Cisco Transparent Bridging Commands

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20211008