文档首页/ 云防火墙 CFW/ API参考/ API/ IPS管理/ 更新自定义IPS规则
更新时间:2025-08-28 GMT+08:00
分享

更新自定义IPS规则

功能介绍

更新自定义IPS规则

调用方法

请参见如何调用API

URI

PUT /v1/{project_id}/ips/custom-rule/{ips_cfw_id}

表1 路径参数

参数

是否必选

参数类型

描述

ips_cfw_id

String

参数解释

cfw侧自定义IPS规则id

约束限制

不涉及

取值范围

32位UUID

默认取值

不涉及

project_id

String

参数解释

项目ID,用于明确项目归属,配置后可通过该ID查询项目下资产,可以从调API处获取,也可以从控制台获取。项目ID获取方式

约束限制

不涉及

取值范围

32位UUID

默认取值

不涉及

请求参数

表2 请求Body参数

参数

是否必选

参数类型

描述

action_type

Integer

参数解释

自定义IPS规则执行动作,仅更新自定义IPS规则场景下需要设置,其他场景无需设置

约束限制

不涉及

取值范围

0:只记录日志

1:重置/拦截

默认取值

不涉及

affected_os

Integer

参数解释

影响操作系统

约束限制

不涉及

取值范围

0:ANY

1:Windows

2:Linux

3:FreeBSD

4:Solaris

5:Other Unix

6:网络设备

7:Mac OS

8:IOS

9:Android

10:Others

默认取值

不涉及

attack_type

Integer

参数解释

攻击类型

约束限制

不涉及

取值范围

1:访问控制

2:漏洞扫描

3:邮件攻击

4:漏洞攻击

5:Web攻击

6:密码攻击

7:劫持攻击

8:协议异常

9:特洛伊木马

10:蠕虫

11:缓冲区溢出

12:黑客工具

13:间谍软件

14:DDos泛洪

15:应用层DDos攻击

16:其他可疑行为

17:可疑DNS活动

18:网络钓鱼

19:垃圾邮件

20:其他攻击

默认取值

不涉及

contents

Array of IpsContent objects

参数解释

匹配IPS攻击的报文内容

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

direction

Integer

参数解释

方向

约束限制

不涉及

取值范围

-1:Any

0:客户端到服务端

1:服务端到客户端

默认取值

不涉及

dst_port

Port object

参数解释

端口信息

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

fw_instance_id

String

参数解释

防火墙ID,用户创建防火墙实例后产生的唯一ID,配置后可区分不同防火墙,可通过防火墙ID获取方式获取

约束限制

不涉及

取值范围

32位UUID

默认取值

不涉及

object_id

String

参数解释

防护对象ID,字段废弃

约束限制

不涉及

取值范围

32位UUID

默认取值

不涉及

ips_name

String

参数解释

ips规则名称

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

protocol

Integer

参数解释

协议类型

约束限制

不涉及

取值范围

1:FTP

2:TELNET

3:SMTP

4:DNS_TCP

5:DNS_UDP

6:DHCP

7:TFTP

8:FINGER

9:HTTP

10:POP3

11:SUNRPC_TCP

12:SUNRPC_UDP

13:NNTP

14:MSRPC_TCP

15:MSRPC_UDP

16:NETBIOS_NAME_TCP

17:NETBIOS_NAME_UDP

18:NETBIOS_SMB

19:NETBIOS_DATAGRAM

20:IMAP4

21:SNMP

22:LDAP

23:MSSQL

24:ORACLE

默认取值

不涉及

severity

Integer

参数解释

严重程度

约束限制

不涉及

取值范围

0:致命

1:高危

2:中危

3:低危

默认取值

不涉及

software

Integer

参数解释

影响软件

约束限制

不涉及

取值范围

0:ANY

1:ADOBE

2:APACHE

3:APPLE

4:CA

5:CISCO

6:GOOGLE_CHROME

7:HP

8:IBM

9:IE

10:IIS

11:MC_AFEE

12:MEDIA_PLAYER

13:MICROSOFT_NET

14:MICROSOFT_EDGE

15:MICROSOFT_EXCHANGE

16:MICROSOFT_OFFICE

17:MICROSOFT_OUTLOOK

18:MICROSOFT_SHARE_POINT

19:MICROSOFT_WINDOWS

20:MOZILLA

21:MSSQL

22:MYSQL

23:NOVELL

24:ORACLE

25:SAMBA

26:SAMSUNG

27:SAP

28:SCADA

29:SQUID

30:SUN

31:SYMANTEC

32:TREND_MICRO

33:VMWARE

34:WORD_PRESS

35:Others

默认取值

不涉及

src_port

Port object

参数解释

端口信息

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

表3 IpsContent

参数

是否必选

参数类型

描述

content

String

参数解释

内容

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

depth

Integer

参数解释

匹配特征时,截止匹配的位置

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

is_hex

Boolean

参数解释

报文内容是否为十六进制

约束限制

不涉及

取值范围

true: 是十六进制

false: 不是十六进制

默认取值

不涉及

is_ignore

Boolean

参数解释

是否忽略大小写

约束限制

不涉及

取值范围

true: 忽略

false: 不忽略

默认取值

不涉及

is_uri

Boolean

参数解释

是否匹配URL中跟“内容”一致的字段

约束限制

不涉及

取值范围

true: 匹配

false: 不匹配

默认取值

不涉及

offset

Integer

参数解释

匹配特征时开始的位置

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

relative_position

Integer

参数解释

匹配特征时,指定开始的位置

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

表4 Port

参数

是否必选

参数类型

描述

port_type

Integer

参数解释

端口操作类型

约束限制

不涉及

取值范围

-1:Any

0:包含

1:排除

默认取值

不涉及

ports

String

参数解释

端口

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

响应参数

状态码:200

表5 响应Body参数

参数

参数类型

描述

data

data object

参数解释

更新自定义IPS规则响应数据

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

表6 data

参数

参数类型

描述

id

String

参数解释

防火墙id

约束限制

不涉及

取值范围

不涉及

默认取值

不涉及

状态码:400

表7 响应Body参数

参数

参数类型

描述

error_code

String

参数解释

错误码

取值范围

不涉及

error_msg

String

参数解释

错误描述

取值范围

不涉及

请求示例

更新项目id为3d84b4755b39476997c9f7b5a95c25ed,ips_cfw_id为cd74e74a-310f-4558-a4bf-da4215c820f8的自定义IPS规则

https://{Endpoint}/v1/3d84b4755b39476997c9f7b5a95c25ed/ips/custom-rule/cd74e74a-310f-4558-a4bf-da4215c820f8

{
  "fw_instance_id" : "d6e0a4d0-8b16-47fe-98b6-e1b0a7a14788",
  "ips_name" : "test_操作系统linux",
  "direction" : -1,
  "src_port" : {
    "port_type" : -1
  },
  "dst_port" : {
    "port_type" : -1
  },
  "contents" : [ {
    "content" : "ab",
    "is_hex" : false,
    "is_ignore" : false,
    "is_uri" : false,
    "relative_position" : 0,
    "offset" : 0,
    "depth" : 65535
  } ],
  "action_type" : 1,
  "severity" : 0,
  "attack_type" : 1,
  "software" : 0,
  "affected_os" : 1,
  "protocol" : 9
}

响应示例

状态码:200

OK

{
  "data" : {
    "id" : "64b8978e-20c0-4b43-b178-885e3cbb380d"
  }
}

状态码:400

Bad Request

{
  "error_code" : "CFW.00200003",
  "error_msg" : "参数错误"
}

SDK代码示例

SDK代码示例如下。

更新项目id为3d84b4755b39476997c9f7b5a95c25ed,ips_cfw_id为cd74e74a-310f-4558-a4bf-da4215c820f8的自定义IPS规则

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.cfw.v1.region.CfwRegion;
import com.huaweicloud.sdk.cfw.v1.*;
import com.huaweicloud.sdk.cfw.v1.model.*;

import java.util.List;
import java.util.ArrayList;

public class UpdateCustomerIpsSolution {

    public static void main(String[] args) {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        String ak = System.getenv("CLOUD_SDK_AK");
        String sk = System.getenv("CLOUD_SDK_SK");
        String projectId = "{project_id}";

        ICredential auth = new BasicCredentials()
                .withProjectId(projectId)
                .withAk(ak)
                .withSk(sk);

        CfwClient client = CfwClient.newBuilder()
                .withCredential(auth)
                .withRegion(CfwRegion.valueOf("<YOUR REGION>"))
                .build();
        UpdateCustomerIpsRequest request = new UpdateCustomerIpsRequest();
        request.withIpsCfwId("{ips_cfw_id}");
        CustomerIpsSaveDto body = new CustomerIpsSaveDto();
        Port srcPortbody = new Port();
        srcPortbody.withPortType(-1);
        Port dstPortbody = new Port();
        dstPortbody.withPortType(-1);
        List<IpsContent> listbodyContents = new ArrayList<>();
        listbodyContents.add(
            new IpsContent()
                .withContent("ab")
                .withDepth(65535)
                .withIsHex(false)
                .withIsIgnore(false)
                .withIsUri(false)
                .withOffset(0)
                .withRelativePosition(0)
        );
        body.withSrcPort(srcPortbody);
        body.withSoftware(0);
        body.withSeverity(0);
        body.withProtocol(9);
        body.withIpsName("test_操作系统linux");
        body.withFwInstanceId("d6e0a4d0-8b16-47fe-98b6-e1b0a7a14788");
        body.withDstPort(dstPortbody);
        body.withDirection(-1);
        body.withContents(listbodyContents);
        body.withAttackType(1);
        body.withAffectedOs(CustomerIpsSaveDto.AffectedOsEnum.NUMBER_1);
        body.withActionType(CustomerIpsSaveDto.ActionTypeEnum.NUMBER_1);
        request.withBody(body);
        try {
            UpdateCustomerIpsResponse response = client.updateCustomerIps(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}

更新项目id为3d84b4755b39476997c9f7b5a95c25ed,ips_cfw_id为cd74e74a-310f-4558-a4bf-da4215c820f8的自定义IPS规则

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# coding: utf-8

import os
from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkcfw.v1.region.cfw_region import CfwRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkcfw.v1 import *

if __name__ == "__main__":
    # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak = os.environ["CLOUD_SDK_AK"]
    sk = os.environ["CLOUD_SDK_SK"]
    projectId = "{project_id}"

    credentials = BasicCredentials(ak, sk, projectId)

    client = CfwClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(CfwRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = UpdateCustomerIpsRequest()
        request.ips_cfw_id = "{ips_cfw_id}"
        srcPortbody = Port(
            port_type=-1
        )
        dstPortbody = Port(
            port_type=-1
        )
        listContentsbody = [
            IpsContent(
                content="ab",
                depth=65535,
                is_hex=False,
                is_ignore=False,
                is_uri=False,
                offset=0,
                relative_position=0
            )
        ]
        request.body = CustomerIpsSaveDto(
            src_port=srcPortbody,
            software=0,
            severity=0,
            protocol=9,
            ips_name="test_操作系统linux",
            fw_instance_id="d6e0a4d0-8b16-47fe-98b6-e1b0a7a14788",
            dst_port=dstPortbody,
            direction=-1,
            contents=listContentsbody,
            attack_type=1,
            affected_os=1,
            action_type=1
        )
        response = client.update_customer_ips(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

更新项目id为3d84b4755b39476997c9f7b5a95c25ed,ips_cfw_id为cd74e74a-310f-4558-a4bf-da4215c820f8的自定义IPS规则

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    cfw "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cfw/v1"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cfw/v1/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/cfw/v1/region"
)

func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")
    projectId := "{project_id}"

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        WithProjectId(projectId).
        Build()

    client := cfw.NewCfwClient(
        cfw.CfwClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.UpdateCustomerIpsRequest{}
	request.IpsCfwId = "{ips_cfw_id}"
	portTypeSrcPort:= int32(-1)
	srcPortbody := &model.Port{
		PortType: &portTypeSrcPort,
	}
	portTypeDstPort:= int32(-1)
	dstPortbody := &model.Port{
		PortType: &portTypeDstPort,
	}
	contentContents:= "ab"
	depthContents:= int32(65535)
	isHexContents:= false
	isIgnoreContents:= false
	isUriContents:= false
	offsetContents:= int32(0)
	relativePositionContents:= int32(0)
	var listContentsbody = []model.IpsContent{
        {
            Content: &contentContents,
            Depth: &depthContents,
            IsHex: &isHexContents,
            IsIgnore: &isIgnoreContents,
            IsUri: &isUriContents,
            Offset: &offsetContents,
            RelativePosition: &relativePositionContents,
        },
    }
	request.Body = &model.CustomerIpsSaveDto{
		SrcPort: srcPortbody,
		Software: int32(0),
		Severity: int32(0),
		Protocol: int32(9),
		IpsName: "test_操作系统linux",
		FwInstanceId: "d6e0a4d0-8b16-47fe-98b6-e1b0a7a14788",
		DstPort: dstPortbody,
		Direction: int32(-1),
		Contents: listContentsbody,
		AttackType: int32(1),
		AffectedOs: model.GetCustomerIpsSaveDtoAffectedOsEnum().E_1,
		ActionType: model.GetCustomerIpsSaveDtoActionTypeEnum().E_1,
	}
	response, err := client.UpdateCustomerIps(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

OK

400

Bad Request

错误码

请参见错误码

相关文档