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

创建自定义IPS规则 - CreateCustomerIps

功能介绍

创建自定义IPS规则

调用方法

请参见如何调用API。

授权信息

账号具备所有API的调用权限,如果使用账号下的IAM用户调用当前API,该IAM用户需具备调用API所需的权限。

  • 如果使用角色与策略授权,具体权限要求请参见权限和授权项。
  • 如果使用身份策略授权,当前API调用无需身份策略权限。

URI

POST /v1/{project_id}/ips/custom-rule

表1 路径参数

参数

是否必选

参数类型

描述

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获取方式获取

约束限制:

不涉及

取值范围:

36位UUID

默认取值:

不涉及

object_id

否

String

参数解释:

防护对象ID,字段废弃

约束限制:

不涉及

取值范围:

36位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,用户创建防火墙实例后产生的唯一ID,配置后可区分不同防火墙,可通过防火墙ID获取方式获取

取值范围:

不涉及

状态码:400

表7 响应Body参数

参数

参数类型

描述

error_code

String

参数解释:

错误码

取值范围:

不涉及

error_msg

String

参数解释:

错误描述

取值范围:

不涉及

请求示例

创建自定义IPS规则,项目ID为28f403ddd3f141daa6e046e85cb15519,防火墙ID为d06dad70-b3be-4480-86bc-b3d139e9938b,规则名称为IPS_test,攻击类型为访问控制,影响软件为ADOBE,操作系统为WINDOWS,方向为服务器到客户端,协议类型为HTTP,源类型为包括端口1,目的类型排除目的端口2,动作为观察,内容为content:"test;"distance:0;within:65535;nocase;

https://{Endpoint}/v1/28f403ddd3f141daa6e046e85cb15519/ips/custom-rule

{
  "protocol" : 9,
  "fw_instance_id" : "d06dad70-b3be-4480-86bc-b3d139e9938b",
  "ips_name" : "IPS_test",
  "direction" : 1,
  "src_port" : {
    "port_type" : 0,
    "ports" : "1"
  },
  "dst_port" : {
    "port_type" : 1,
    "ports" : "2"
  },
  "contents" : [ {
    "content" : "test",
    "is_hex" : false,
    "is_ignore" : true,
    "is_uri" : false,
    "relative_position" : 0,
    "offset" : 0,
    "depth" : 65535
  } ],
  "action_type" : 0,
  "severity" : 1,
  "attack_type" : 1,
  "software" : 1,
  "affected_os" : 1
}

响应示例

状态码:200

OK

{
  "data" : {
    "id" : "bc11e773-35cc-478c-a91c-772ed077e06e"
  }
}

状态码:400

Bad Request

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

SDK代码示例

SDK代码示例如下。

创建自定义IPS规则,项目ID为28f403ddd3f141daa6e046e85cb15519,防火墙ID为d06dad70-b3be-4480-86bc-b3d139e9938b,规则名称为IPS_test,攻击类型为访问控制,影响软件为ADOBE,操作系统为WINDOWS,方向为服务器到客户端,协议类型为HTTP,源类型为包括端口1,目的类型排除目的端口2,动作为观察,内容为content:"test;"distance:0;within:65535;nocase;

 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
80
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 CreateCustomerIpsSolution {

    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();
        CreateCustomerIpsRequest request = new CreateCustomerIpsRequest();
        CustomerIpsSaveDto body = new CustomerIpsSaveDto();
        Port srcPortbody = new Port();
        srcPortbody.withPortType(0)
            .withPorts("1");
        Port dstPortbody = new Port();
        dstPortbody.withPortType(1)
            .withPorts("2");
        List<IpsContent> listbodyContents = new ArrayList<>();
        listbodyContents.add(
            new IpsContent()
                .withContent("test")
                .withDepth(65535)
                .withIsHex(false)
                .withIsIgnore(true)
                .withIsUri(false)
                .withOffset(0)
                .withRelativePosition(0)
        );
        body.withSrcPort(srcPortbody);
        body.withSoftware(1);
        body.withSeverity(1);
        body.withProtocol(9);
        body.withIpsName("IPS_test");
        body.withFwInstanceId("d06dad70-b3be-4480-86bc-b3d139e9938b");
        body.withDstPort(dstPortbody);
        body.withDirection(1);
        body.withContents(listbodyContents);
        body.withAttackType(1);
        body.withAffectedOs(CustomerIpsSaveDto.AffectedOsEnum.NUMBER_1);
        body.withActionType(CustomerIpsSaveDto.ActionTypeEnum.NUMBER_0);
        request.withBody(body);
        try {
            CreateCustomerIpsResponse response = client.createCustomerIps(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());
        }
    }
}

创建自定义IPS规则,项目ID为28f403ddd3f141daa6e046e85cb15519,防火墙ID为d06dad70-b3be-4480-86bc-b3d139e9938b,规则名称为IPS_test,攻击类型为访问控制,影响软件为ADOBE,操作系统为WINDOWS,方向为服务器到客户端,协议类型为HTTP,源类型为包括端口1,目的类型排除目的端口2,动作为观察,内容为content:"test;"distance:0;within:65535;nocase;

 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
# 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 = CreateCustomerIpsRequest()
        srcPortbody = Port(
            port_type=0,
            ports="1"
        )
        dstPortbody = Port(
            port_type=1,
            ports="2"
        )
        listContentsbody = [
            IpsContent(
                content="test",
                depth=65535,
                is_hex=False,
                is_ignore=True,
                is_uri=False,
                offset=0,
                relative_position=0
            )
        ]
        request.body = CustomerIpsSaveDto(
            src_port=srcPortbody,
            software=1,
            severity=1,
            protocol=9,
            ips_name="IPS_test",
            fw_instance_id="d06dad70-b3be-4480-86bc-b3d139e9938b",
            dst_port=dstPortbody,
            direction=1,
            contents=listContentsbody,
            attack_type=1,
            affected_os=1,
            action_type=0
        )
        response = client.create_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)

创建自定义IPS规则,项目ID为28f403ddd3f141daa6e046e85cb15519,防火墙ID为d06dad70-b3be-4480-86bc-b3d139e9938b,规则名称为IPS_test,攻击类型为访问控制,影响软件为ADOBE,操作系统为WINDOWS,方向为服务器到客户端,协议类型为HTTP,源类型为包括端口1,目的类型排除目的端口2,动作为观察,内容为content:"test;"distance:0;within:65535;nocase;

 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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, err := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        WithProjectId(projectId).
        SafeBuild()

    if err != nil {
        fmt.Println(err)
        return
    }

    hcClient, err := cfw.CfwClientBuilder().
         WithRegion(region.ValueOf("<YOUR REGION>")).
         WithCredential(auth).
         SafeBuild()


    if err != nil {
        fmt.Println(err)
        return
    }

    client := cfw.NewCfwClient(hcClient)

    request := &model.CreateCustomerIpsRequest{}
	portTypeSrcPort:= int32(0)
	portsSrcPort:= "1"
	srcPortbody := &model.Port{
		PortType: &portTypeSrcPort,
		Ports: &portsSrcPort,
	}
	portTypeDstPort:= int32(1)
	portsDstPort:= "2"
	dstPortbody := &model.Port{
		PortType: &portTypeDstPort,
		Ports: &portsDstPort,
	}
	contentContents:= "test"
	depthContents:= int32(65535)
	isHexContents:= false
	isIgnoreContents:= true
	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(1),
		Severity: int32(1),
		Protocol: int32(9),
		IpsName: "IPS_test",
		FwInstanceId: "d06dad70-b3be-4480-86bc-b3d139e9938b",
		DstPort: dstPortbody,
		Direction: int32(1),
		Contents: listContentsbody,
		AttackType: int32(1),
		AffectedOs: model.GetCustomerIpsSaveDtoAffectedOsEnum().E_1,
		ActionType: model.GetCustomerIpsSaveDtoActionTypeEnum().E_0,
	}
	response, err := client.CreateCustomerIps(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

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

状态码

状态码

描述

200

OK

400

Bad Request

错误码

请参见错误码。

相关文档