当使用通配符对象时,流量与正确的策略不匹配。
4544
Created On 10/16/23 05:29 AM - Last Modified 01/07/25 02:03 AM
Symptom
流量没有遵循带有通配符对象的预期规则。
鉴于以下配置:
| 对象名称 | 地址 | 意义 | 预期匹配示例 |
|---|---|---|---|
| 通配符-10.128.0.1-0.127.0.0 | 10.128.0.1/0.127.0.0 | 匹配 10.128-255.0.1 |
10.128.0.1 |
| 通配符-10.128.0.1-0.127.255.0 | 10.128.0.1/0.127.255.0 | 匹配 10.128-255.0-255.1 |
10.128.0.1 |
| 通配符-10.128.0.1-0.15.255.0 | 10.128.0.1/0.15.255.0 | 匹配 10.128-143.0-255.1 |
10.128.0.1 |
| 规则库 | 源对象 |
|---|---|
| 规则A | 通配符-10.128.0.1-0.127.0.0 |
| 规则 B | 通配符-10.128.0.1-0.127.255.0 |
| 规则C | 通配符-10.128.0.1-0.15.255.0 |
来自 10.128.0.1 的流量与 3 个通配符对象匹配,但是,它正在由规则C 进行处理。
admin@NGFW> test security-policy-match from Trust to Untrust source 10.128.0.1 destination 8.8.8.8 destination-port 80 protocol 6
"Rule C; index: 3" {
from any;
source none;
source-region none;
to any;
destination any;
destination-region none;
user any;
source-device any;
destination-device any;
category any;
application/service 0:any/any/any/app-default;
action allow;
icmp-unreachable: no
terminal yes;
}
|
Environment
- Palo Alto 防火墙
- 支持的 PAN OS
- 通配符对象
Cause
- 如果通配符对象重叠,则地址将与最长前缀通配符掩码进行匹配(参见附加信息)。
- 在此示例中,
- 对于IP 地址10.128.0.1。
- 匹配的叶子是 10.128.0.1/12(/12 比 /9 长)。
- 然后,该IP 地址与规则 C 中使用的通配符 10.128.0.1-0.15.255.0进行匹配。
Resolution
- 按正确顺序调整规则以获得预期结果
- 请参阅下面上述示例的计算
- 对于上述示例,检查通配符对象,以便前缀长度匹配被中和(步骤 1)。
对于IP 地址10.128.0.1。
由于 10.128.0.1 与叶 10.128.0.1/12 匹配,因此需要编辑其他通配符对象以产生 /12 前缀。
对象wildcard-10.128.0.1-0.127.0.0 - 10.128.0.1/0.127.0.0 需要在通配符中分解如下。
- 10.128.0.1/0.15.0.0
- 10.144.0.1/0.15.0.0
- 10.160.0.1/0.15.0.0
- 10.176.0.1/0.15.0.0
- 10.192.0.1/0.15.0.0
- 10.208.0.1/0.15.0.0
- 10.224.0.1/0.15.0.0
- 10.240.0.1/0.15.0.0
| 对象名称 | 地址 |
|---|---|
| wildcard-10.128.0.1-0.127.0.0 | 10.128.0.1/0.127.0.0 |
| 通配符-10.128.0.1-0.127.255.0 | 10.128.0.1/0.127.255.0 |
| 通配符-10.128.0.1-0.15.255.0 | 10.128.0.1/0.15.255.0 |
| 新-10.128.0.1-0.15.0.0 | 10.128.0.1/0.15.255.0 |
| 新-10.144.0.1-0.15.0.0 | 10.144.0.1/0.15.255.0 |
| 新-10.160.0.1-0.15.0.0 | 10.160.0.1/0.15.255.0 |
| 新-10.176.0.1-0.15.0.0 | 10.176.0.1/0.15.255.0 |
| 新-10.192.0.1-0.15.0.0 | 10.192.0.1/0.15.255.0 |
| 新-10.208.0.1-0.15.0.0 | 10.208.0.1/0.15.255.0 |
| 新-10.224.0.1-0.15.0.0 | 10.224.0.1/0.15.255.0 |
| 新-10.240.0.1-0.15.0.0 | 10.240.0.1/0.15.255.0 |
| 规则库 | 源对象 |
|---|---|
| 规则A |
通配符-10.128.0.1-0.127.0.0 |
| 规则 B | 通配符-10.128.0.1-0.127.255.0 |
| 规则C | 通配符-10.128.0.1-0.15.255.0 |
更改后,规则按预期匹配
admin@NGFW> test security-policy-match from Trust to Untrust source 10.128.0.1 destination 8.8.8.8 destination-port 80 protocol 6
"Rule A; index: 1" {
from any;
source none;
source-region none;
to any;
destination any;
destination-region none;
user any;
source-device any;
destination-device any;
category any;
application/service 0:any/any/any/app-default;
action allow;
icmp-unreachable: no
terminal yes;
}
|
Additional Information
通配符对象存储在树数据结构中。
树的每个叶子都是与匹配的通配符对象相关联的前缀。
通配符-10.128.0.1-0.127.0.0 - 10.128.0.1/0.127.0.0
0.127.0.0 ( 0000 0000.0 111 1111.0.0) 给出 /9 (第bit(位-bit)为 1 之前 9 位为 0)
叶子将是:10.128.0.1/9
通配符-10.128.0.1-0.127.255.0 - 10.128.0.1/0.127.255.0
0.127.255.0 ( 0000 0000.0 111 1111.255.0) 得出 /9 (第 1bit(位-bit)为 1 之前 9 位为 0)
叶子将是:10.128.0.1/9
通配符-10.128.0.1-0.15.255.0 - 10.128.0.1/0.15.255.0
0.15.0.0 ( 0000 0000.0000 1111.255.0) 给出 /9 (第bit(位-bit)为 1 之前 9 位为 0)
叶子将是:10.128.0.1/12
| 叶子 | 关联的通配符对象 |
|---|---|
| 10.128.0.1/9 | 通配符-10.128.0.1-0.127.0.0 通配符-10.128.0.1-0.127.255.0 |
| 10.128.0.1/12 | 通配符-10.128.0.1-0.15.255.0 |
通配符对象匹配分为两个步骤:
- 前缀长度匹配
在此阶段,对于给定的地址,系统将在数据结构上搜索最长的前缀匹配以获取通配符对象列表。 - 关联通配符对象匹配
在此阶段,对于给定的地址,系统将检查与关联的通配符对象是否匹配。
通配符掩码重叠时安全策略规则自上而下的顺序