[go: up one dir, main page]

CN106330601A - Test case generation method and device - Google Patents

Test case generation method and device Download PDF

Info

Publication number
CN106330601A
CN106330601A CN201610697317.4A CN201610697317A CN106330601A CN 106330601 A CN106330601 A CN 106330601A CN 201610697317 A CN201610697317 A CN 201610697317A CN 106330601 A CN106330601 A CN 106330601A
Authority
CN
China
Prior art keywords
field
data
test case
fields
variable
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
CN201610697317.4A
Other languages
Chinese (zh)
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.)
Beijing Kuang En Network Technology Co Ltd
Original Assignee
Beijing Kuang En Network Technology 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 Beijing Kuang En Network Technology Co Ltd filed Critical Beijing Kuang En Network Technology Co Ltd
Priority to CN201610697317.4A priority Critical patent/CN106330601A/en
Publication of CN106330601A publication Critical patent/CN106330601A/en
Pending legal-status Critical Current

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L43/00Arrangements for monitoring or testing data switching networks
    • H04L43/18Protocol analysers
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L43/00Arrangements for monitoring or testing data switching networks
    • H04L43/50Testing arrangements

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

The invention provides a test case generating method and device. The method comprises the steps of firstly, selecting a function code corresponding to a certain function of a MODBUS protocol, then acquiring the definition of each field included in a data packet with the function, and selecting a field for controlling MODBUS protocol communication from the fields as an invariable field, wherein the remaining fields are variable fields; and varying at least one variable field, thereby generating a test case not in conformity with the definitions of the varied fields or data setting. Understandably, the method and the device for generating the test case based on the MODBUS protocol are more specific; and in the method, the field for controlling MODBUS protocol communication is regarded as an invariable field, and the variable fields are specifically varied, so that invalid redundant test cases can be prevented from being generated and the test efficiency is effectively improved.

Description

测试用例生成方法及装置Test case generation method and device

技术领域technical field

本发明属于软件技术领域,特别涉及一种测试用例生成方法及装置。The invention belongs to the technical field of software, and in particular relates to a test case generation method and device.

背景技术Background technique

随着网络技术的发展,工业控制领域的设备与设备之间依托着强大的互联网也变得越来越紧密。各个工控设备之间一般地基于互联网协议进行数据交互与通信。例如,Modbus/TCP协议在工控行业得到了广泛的应用,它已不仅仅是一个PLC的通讯协议,在智能仪表、变频器等许多智能设备都有相当广泛的应用。虽然将工业控制设备连接到网络能够较为方便的实现远程管理和监控,但在通信的同时也暴露了控制设备本身,从而使得控制设备容易受到恶意软件和黑客的恶意攻击,一旦工业控制网络信息安全出现漏洞,将对工业生产运行造成重大隐患。因此,如何减少工控网络通信协议的安全隐患是一个亟待解决的问题。With the development of network technology, the equipment in the field of industrial control relies on the powerful Internet and becomes more and more closely connected. Data interaction and communication between various industrial control devices are generally based on the Internet protocol. For example, the Modbus/TCP protocol has been widely used in the industrial control industry. It is not only a PLC communication protocol, but also widely used in many smart devices such as smart instruments and frequency converters. Although it is convenient to connect industrial control equipment to the network to achieve remote management and monitoring, the communication also exposes the control equipment itself, making the control equipment vulnerable to malware and malicious attacks from hackers. Once the industrial control network information security Loopholes will cause major hidden dangers to industrial production and operation. Therefore, how to reduce the security risks of the industrial control network communication protocol is an urgent problem to be solved.

目前对于协议安全的测试主要采用的方法为模糊测试方法。模糊测试是一种黑盒测试技术或随机测试技术,是协议安全测试的一种方式,它的基本原理是将大量的畸形数据输入到目标程序中,并监视目标程序执行过程中产生的任何异常,记录下导致异常的输入数据,从而定位目标程序中缺陷的位置,发现可能存在的安全漏洞。At present, the main method used for protocol security testing is the fuzzy testing method. Fuzz testing is a black-box testing technique or random testing technique. It is a method of protocol security testing. Its basic principle is to input a large amount of malformed data into the target program and monitor any abnormalities generated during the execution of the target program. , and record the input data that caused the exception, so as to locate the position of the defect in the target program and discover possible security holes.

模糊测试中最为关键的是生成模糊测试数据的阶段,也即测试用例的生成。然而,由于模糊测试具有盲目性,现有的模糊测试在生成测试用例时是在输入数据空间内任意取值,自动产生和发送大量随机的值,这样产生的测试用例很大一部分在还没有进入到目标程序内部就被拒绝了,也即产生了许多无用的测试用例,导致随机测试产生的测试时间长,大量冗余测试输入,测试效率较低。此外,现有的模糊测试生成的测试用例大多是针对互联网网络协议的测试用例,对于工控协议,例如Modbus/TCP协议,并没有专用的测试用例生成方法,使得Modbus/TCP协议的测试不具有针对性,测试效率较低。The most critical part of fuzz testing is the stage of generating fuzz test data, that is, the generation of test cases. However, due to the blindness of fuzz testing, the existing fuzz testing takes arbitrary values in the input data space when generating test cases, automatically generates and sends a large number of random values, and a large part of the test cases generated in this way have not entered It is rejected within the target program, that is, many useless test cases are generated, resulting in long test time generated by random tests, a large number of redundant test inputs, and low test efficiency. In addition, most of the test cases generated by existing fuzz tests are test cases for Internet network protocols. For industrial control protocols, such as Modbus/TCP protocol, there is no dedicated test case generation method, so that the test of Modbus/TCP protocol does not have specific , and the test efficiency is low.

发明内容Contents of the invention

本发明提供了一种测试用例生成方法及装置,用以解决现有技术中在采用模糊测试方法对Modbus协议进行测试时,测试用例盲目性大,不具有针对性,测试效率低的缺陷。The invention provides a method and device for generating test cases, which are used to solve the defects in the prior art that the test cases are blind, not targeted, and have low test efficiency when using a fuzzy testing method to test the Modbus protocol.

第一方面,本发明提供了一种测试用例生成方法,用于生成针对Modbus协议的测试用例,所述方法包括:First aspect, the present invention provides a kind of test case generation method, is used for generating the test case for Modbus agreement, and described method comprises:

在预存的若干个功能码中选取一个作为目标功能码;其中,所述若干个功能码,为Modbus协议规定的执行不同功能操作的数据包所对应的若干个功能码;Select one as the target function code in several pre-stored function codes; wherein, the several function codes are several function codes corresponding to data packets that perform different functional operations as stipulated by the Modbus protocol;

根据Modbus协议规定,获取与所述目标功能码对应的数据包中各个字段的定义;According to the Modbus protocol, obtain the definition of each field in the data packet corresponding to the target function code;

选取功能码字段以及各个字段中用于控制测试用例通信功能的字段作为不可变字段,将其余字段作为可变字段;将所述不可变字段设置为预设值,以使所述测试用例支持基于Modbus协议进行通信;对所述可变字段中的至少一个字段进行随机变异,以生成与所述至少一个字段的定义不符或数据设置不符的测试用例。Select the function code field and the field used to control the communication function of the test case in each field as an immutable field, and use the rest of the fields as variable fields; set the immutable field as a preset value so that the test case supports based on The Modbus protocol is used for communication; at least one field in the variable fields is randomly mutated to generate a test case inconsistent with the definition or data setting of the at least one field.

可选地,所述对所述可变字段中的至少一个字段进行随机变异,以生成与所述至少一个字段的定义不符或数据设置不符的测试用例的步骤,包括:Optionally, the step of randomly mutating at least one of the variable fields to generate a test case inconsistent with the definition or data setting of the at least one field includes:

对所有可变字段的数据进行随机变异,以生成与所述可变字段数据的定义不符的测试用例。Randomly mutate the data of all variable fields to generate test cases that do not conform to the definition of said variable field data.

可选地,所述对所述可变字段中的至少一个字段进行随机变异,以生成与所述至少一个字段的定义不符或数据设置不符的测试用例的步骤,包括:Optionally, the step of randomly mutating at least one of the variable fields to generate a test case inconsistent with the definition or data setting of the at least one field includes:

将所述可变字段中的一部分字段的数据逐一地或组合地设置为预设值,所述预设值包括所述字段定义的取值范围内的最大值、最小值或中间值;Setting the data of a part of the variable fields as a preset value one by one or in combination, the preset value including a maximum value, a minimum value or an intermediate value within the value range defined by the fields;

对所述可变字段中的另一部分字段的数据进行随机取值变异,以生成与所述另一部分字段数据的定义不符的测试用例。Randomly mutating the data of another part of the variable fields to generate a test case inconsistent with the definition of the other part of the field data.

可选地,所述对所述可变字段中的至少一个字段进行随机变异,以生成与所述至少一个字段的定义不符或数据设置不符的测试用例的步骤,包括:Optionally, the step of randomly mutating at least one of the variable fields to generate a test case inconsistent with the definition or data setting of the at least one field includes:

将所述可变字段中用于表示单元标识符字段、功能码字段以及数据域长度的长度字段设置为预设值,对所述单元标识符字段、功能码字段以及数据域中的任一项或其组合进行变异而加长或者压缩实际长度,以生成实际长度与所述长度字段的预设值不匹配的测试用例。Set the length field used to represent the unit identifier field, the function code field and the length of the data field in the variable field to a preset value, and any one of the unit identifier field, the function code field and the data field or a combination thereof to lengthen or compress the actual length, so as to generate a test case whose actual length does not match the preset value of the length field.

可选地,所述随机变异包括数据元素删除变异,数据元素重复变异,有效值变异,或在各字段定义的数值范围内的数值边界变异。Optionally, the random variation includes data element deletion variation, data element repetition variation, effective value variation, or numerical boundary variation within the numerical range defined by each field.

第二方面,本发明提供了一种测试用例生成装置,用于生成针对Modbus协议的测试用例,所述装置包括:Second aspect, the present invention provides a kind of test case generating device, is used for generating the test case for Modbus agreement, and described device comprises:

功能码选择单元,用于在预存的若干个功能码中选取一个作为目标功能码;其中,所述若干个功能码,为Modbus协议规定的执行不同功能操作的数据包所对应的若干个功能码;The function code selection unit is used to select one of the pre-stored function codes as the target function code; wherein, the several function codes are the corresponding function codes of the data packets that perform different functional operations specified by the Modbus protocol ;

获取单元,用于根据Modbus协议规定,获取与所述目标功能码对应的数据包中各个字段的定义;The acquisition unit is used to obtain the definition of each field in the data packet corresponding to the target function code according to the Modbus protocol;

字段选择变异单元,用于选取功能码字段以及各个字段中用于控制测试用例通信功能的字段作为不可变字段,将其余字段作为可变字段;将所述不可变字段设置为预设值,以使所述测试用例支持基于Modbus协议进行通信;对所述可变字段中的至少一个字段进行随机变异,以生成与所述至少一个字段的定义不符或数据设置不符的测试用例。The field selection mutation unit is used to select the function code field and the field used to control the communication function of the test case in each field as an immutable field, and use the rest of the fields as variable fields; set the immutable fields as preset values to Making the test case support communication based on the Modbus protocol; randomly mutating at least one of the variable fields to generate a test case inconsistent with the definition or data setting of the at least one field.

可选地,所述字段选择变异单元,还用于对所有可变字段的数据进行随机变异,以生成与所述可变字段数据的定义不符的测试用例。Optionally, the field selection mutation unit is further configured to randomly mutate the data of all variable fields, so as to generate test cases inconsistent with the definition of the variable field data.

可选地,所述字段选择变异单元,还用于:Optionally, the field selection mutation unit is also used for:

将所述可变字段中的一部分字段的数据逐一地或组合地设置为预设值,所述预设值包括所述字段定义的取值范围内的最大值、最小值或中间值;Setting the data of a part of the variable fields as a preset value one by one or in combination, the preset value including a maximum value, a minimum value or an intermediate value within the value range defined by the fields;

对所述可变字段中的另一部分字段的数据进行随机取值变异,以生成与所述另一部分字段数据的定义不符的测试用例。Randomly mutating the data of another part of the variable fields to generate a test case inconsistent with the definition of the other part of the field data.

可选地,所述字段选择变异单元,还用于:Optionally, the field selection mutation unit is also used for:

将所述可变字段中用于表示单元标识符字段、功能码字段以及数据域长度的长度字段设置为预设值,对所述单元标识符字段、功能码字段以及数据域中的任一项或其组合进行变异而加长或者压缩实际长度,以生成实际长度与所述长度字段的预设值不匹配的测试用例。Set the length field used to represent the unit identifier field, the function code field and the length of the data field in the variable field to a preset value, and any one of the unit identifier field, the function code field and the data field or a combination thereof to lengthen or compress the actual length, so as to generate a test case whose actual length does not match the preset value of the length field.

可选地,所述随机变异包括数据元素删除变异,数据元素重复变异,有效值变异,或在各字段定义的数值范围内的数值边界变异。Optionally, the random variation includes data element deletion variation, data element repetition variation, effective value variation, or numerical boundary variation within the numerical range defined by each field.

本发明提供了一种测试用例生成方法及装置,该方法中,首先选择MODBUS协议的某一功能对应的功能码,再获取具有该功能的数据包中包含的各个字段的定义,在各个字段中选择控制MODBUS协议通信的字段作为不可变字段,其余为可变字段,并对至少一个可变字段进行变异,从而生成与这些发生变异的字段定义不符或数据设置不符的测试用例。可以理解的是,由于本发明提供的方法中将控制MODBUS协议通信的字段作为不可变字段,只对可变字段进行变异,从而能够避免生成无法基于MODBUS协议进行通信的无效的冗余测试用例,有效提高测试效率,此外本发明提供的方法生成的是针对MODBUS协议的测试用例,因此更具有针对性,进一步提高测试的效率。The invention provides a test case generation method and device. In the method, first select a function code corresponding to a certain function of the MODBUS protocol, and then obtain the definition of each field contained in a data packet with the function. In each field Select the field that controls MODBUS protocol communication as an immutable field, and the rest are variable fields, and mutate at least one variable field to generate test cases that do not match the definition or data settings of these mutated fields. It can be understood that, since the field controlling MODBUS protocol communication is used as an immutable field in the method provided by the present invention, only the variable field is mutated, thereby avoiding generation of invalid redundant test cases that cannot communicate based on the MODBUS protocol, The test efficiency is effectively improved. In addition, the method provided by the invention generates test cases aimed at the MODBUS protocol, so it is more targeted and further improves the test efficiency.

附图说明Description of drawings

为了更清楚地说明本发明实施例或现有技术中的技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本发明的一些示例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following will briefly introduce the accompanying drawings that need to be used in the description of the embodiments. Obviously, the accompanying drawings in the following description are only of the present invention. For some examples, those of ordinary skill in the art can also obtain other drawings based on these drawings on the premise of not paying creative efforts.

图1为本发明提供的一种测试用例生成方法流程图;Fig. 1 is a kind of test case generating method flowchart provided by the present invention;

图2为本发明提供的被测设备正常抓包示意图;Fig. 2 is a schematic diagram of normal packet capture of the device under test provided by the present invention;

图3为本发明提供的被测设备在接收到测试用例后异常抓包示意图;Fig. 3 is a schematic diagram of abnormal packet capture of the device under test provided by the present invention after receiving the test case;

图4(a)-4(b)为本发明提供的被测设备在接收测试用例前后的TCP通讯连接状态示意图。4(a)-4(b) are schematic diagrams of the TCP communication connection status of the device under test before and after receiving the test cases provided by the present invention.

图5为本发明提供的一种测试用例生成装置结构示意图。FIG. 5 is a schematic structural diagram of a test case generation device provided by the present invention.

具体实施方式detailed description

下面将结合本发明实施例中的附图,对本发明实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本发明一部分实施例,而不是全部的实施例。基于本发明中的实施例,本领域普通技术人在没有作出创造性劳动前提下所获得的所有其他实施例,都属于本发明保护的范围。The following will clearly and completely describe the technical solutions in the embodiments of the present invention with reference to the accompanying drawings in the embodiments of the present invention. Obviously, the described embodiments are only some, not all, embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by persons of ordinary skill in the art without creative efforts fall within the protection scope of the present invention.

为便于理解,首先对本发明中涉及的Modbus总线协议以及该协议规定的数据格式进行详细说明。For ease of understanding, the Modbus bus protocol involved in the present invention and the data format specified by the protocol will be described in detail at first.

Modbus/TCP为应用层报文传输协议,主要应用于在不同类型的总线或网络连接下的客户机与服务器之间的通信。Modbus/TCP数据帧包含报文头、功能码域和数据域三个部分。Modbus/TCP is an application layer message transmission protocol, which is mainly used for communication between clients and servers under different types of buses or network connections. Modbus/TCP data frame includes three parts: message header, function code field and data field.

其中,这里的功能码用于在客户端向服务器设备发送报文时,指示服务器执行的操作类型。功能码具体可以分为公共功能码、用户定义功能码和保留功能码,表1列出了部分常用的公共功能码。Wherein, the function code here is used to indicate the type of operation performed by the server when the client sends a message to the server device. Function codes can be divided into public function codes, user-defined function codes and reserved function codes. Table 1 lists some commonly used public function codes.

表1Modbus协议中部分公共功能码的定义Table 1 Definition of some public function codes in the Modbus protocol

基于上述内容,第一方面,本发明提供了一种测试用例生成方法,用于生成测试Modbus协议的测试用例,如图1所示,包括:Based on the foregoing, in the first aspect, the present invention provides a method for generating a test case, which is used to generate a test case for testing the Modbus protocol, as shown in Figure 1, including:

S101、在预存的若干个功能码中选取一个作为目标功能码;其中,所述若干个功能码,为Modbus协议规定的执行不同功能操作的数据包所对应的若干个功能码;S101. Select one of the pre-stored function codes as the target function code; wherein, the several function codes are the corresponding function codes of the data packets that perform different functional operations specified by the Modbus protocol;

S102、根据Modbus协议规定,获取与所述目标功能码对应的数据包中各个字段的定义;S102. Obtain the definition of each field in the data packet corresponding to the target function code according to the Modbus protocol;

S103、选取功能码字段以及各个字段中用于控制测试用例通信功能的字段作为不可变字段,将其余字段作为可变字段;将所述不可变字段设置为预设值,以使所述测试用例支持基于Modbus协议进行通信;对所述可变字段中的至少一个字段进行随机变异,以生成与所述至少一个字段的定义不符或数据设置不符的测试用例。S103. Select the function code field and the field used to control the communication function of the test case in each field as an immutable field, and use the remaining fields as variable fields; set the immutable field as a preset value, so that the test case Supporting communication based on the Modbus protocol; randomly mutating at least one of the variable fields to generate a test case inconsistent with the definition or data setting of the at least one field.

本发明提供的测试用例生成方法,首先选择MODBUS协议的某一功能对应的功能码,再获取具有该功能的数据包中包含的各个字段的定义,在各个字段中选择控制MODBUS协议通信的字段作为不可变字段,其余为可变字段,并对至少一个可变字段进行变异,从而生成与这些发生变异的字段定义不符或数据设置不符的测试用例。可以理解的是,由于本发明提供的方法中将控制MODBUS协议通信的字段作为不可变字段,只对可变字段进行变异,从而能够避免生成无法基于MODBUS协议进行通信的无效的冗余测试用例,有效提高测试效率,此外本发明提供的方法生成的是针对MODBUS协议的测试用例,因此更具有针对性,进一步提高测试的效率。The test case generation method provided by the present invention first selects the function code corresponding to a certain function of the MODBUS protocol, then obtains the definition of each field contained in the data packet with this function, and selects the field of controlling MODBUS protocol communication in each field as Immutable fields, the rest are variable fields, and at least one variable field is mutated, so as to generate test cases that do not conform to the definitions of these mutated fields or data settings. It can be understood that, since the field controlling MODBUS protocol communication is used as an immutable field in the method provided by the present invention, only the variable field is mutated, thereby avoiding generation of invalid redundant test cases that cannot communicate based on the MODBUS protocol, The test efficiency is effectively improved. In addition, the method provided by the invention generates test cases aimed at the MODBUS protocol, so it is more targeted and further improves the test efficiency.

可以理解的是,在具体实施时,上述方法实施例的步骤S103可以通过多种方式来实现,下面对其中几个可选的实施例进行详细说明。It can be understood that, during specific implementation, step S103 in the foregoing method embodiment may be implemented in various ways, and several optional embodiments thereof will be described in detail below.

示例一、对所有可变字段的数据进行随机变异,以生成与可变字段数据的定义不符的测试用例。Example 1. Randomly mutate the data of all variable fields to generate test cases that do not match the definition of variable field data.

具体来说,功能码字段是用于当从客户机向服务器设备发送报文时,指示服务器将执行哪种功能操作的字段,由于本发明主要针对Modbus的各个功能进行测试,因此在这里需要保持功能码字段。下面以功能码字段为0x17的读写多寄存器功能的测试用例生成方法为例,详细说明本发明提供的方法如何生成读写多寄存器功能的测试用例。Specifically, the function code field is used to indicate the field of which function operation the server will perform when sending a message from the client computer to the server device. Since the present invention is mainly tested for each function of Modbus, it is necessary to keep Function code field. Taking the test case generation method of the read/write multi-register function with the function code field as 0x17 as an example, how to generate the test case for the read/write multi-register function by the method provided by the present invention is described in detail below.

表2中示出了功能码字段为0x17时数据包的应用数据单元ADU各个字段的定义(包括报文头、功能码域和数据域)。Table 2 shows the definition of each field of the application data unit ADU of the data packet (including message header, function code field and data field) when the function code field is 0x17.

表2读写多寄存器功能应用数据单元ADU字段定义Table 2 Field definition of the application data unit ADU for reading and writing multi-register functions

在表2的这些字段中,这里的协议标识符是不可变的,因为协议标识符通过0值识别Modbus协议。当然特殊地,也可以生成将协议标识符设置为非零值的测试用例,在本发明中先暂时不考虑这一类特殊的测试用例。In these fields of Table 2, the protocol identifier here is immutable, because the protocol identifier identifies the Modbus protocol by 0 value. Of course, in particular, a test case in which the protocol identifier is set to a non-zero value can also be generated, and this type of special test case is not considered in the present invention.

这里的单元标识符对模糊测试结果影响不大,因此设置为可变不可变均可。由于TCP/IP利用IP地址寻址Modbus服务器,因此将单元标识符设置为固定值,例如,可以设置为使用值0xFF,当然也可以设置为其它值。The unit identifier here has little effect on the fuzz test results, so it can be set to be variable or immutable. Since TCP/IP utilizes IP address to address the Modbus server, set the unit identifier to a fixed value, for example, it can be set to use the value 0xFF, and of course it can also be set to other values.

事务处理标识符与单元表示符类似,同样对模糊测试结果影响不大,因此设置为可变不可变均可。事务处理标识符用于在请求与响应之间建立联系,在同一时刻标识符必须是唯一的。由于Modbus/Tcp中可以向同一个服务器发送多个请求而不需等待服务器的证实,服务器接收的请求数量取决于其容量,因此,这里可以根据设备的类型,将事务处理标识符设置为1~16中的某一值。另外,事务处理标识符也可以设置为递增的形式,从而形成多个测试用例。The transaction identifier is similar to the unit identifier, and it also has little effect on the fuzz test results, so it can be set to be variable or not. The transaction identifier is used to establish a link between the request and the response, and the identifier must be unique at the same time. Since Modbus/Tcp can send multiple requests to the same server without waiting for the confirmation of the server, the number of requests received by the server depends on its capacity. Therefore, the transaction identifier can be set to 1~ according to the type of the device. One of 16 values. In addition, the transaction identifier can also be set in an incremental form, thereby forming multiple test cases.

基于上述对于这几个字段的定义的叙述,在这里我们认为上述字段可以用于控制Modbus/Tcp协议的通信,因此本实施例中,将上述几个字段设置为不可变字段,并为这些不可变字段分别赋予相应的预设值,以使生成的测试用例能够基于Modbus/Tcp协议进行正常的通信。再将表2中除这些字段以外的字段全部进行随机变异,从而能够生成与可变字段的定义不符的测试用例,用于对Modbus/Tcp协议的读写多寄存器功能进行测试。Based on the narration of the above-mentioned definitions for these fields, here we think that the above-mentioned fields can be used to control the communication of the Modbus/Tcp protocol, so in this embodiment, the above-mentioned fields are set as immutable fields, and these fields cannot The variable fields are assigned corresponding preset values, so that the generated test cases can communicate normally based on the Modbus/Tcp protocol. Then all the fields in Table 2 except these fields are randomly mutated, so that test cases that do not match the definition of the variable fields can be generated to test the read and write multi-register function of the Modbus/Tcp protocol.

示例二、将可变字段中的一部分字段的数据逐一地或组合地设置为预设值,预设值包括字段定义的取值范围内的最大值、最小值或中间值;对可变字段中的另一部分字段的数据进行随机取值变异,以生成与另一部分字段数据的定义不符的测试用例。Example 2: Set the data of some fields in the variable field to the preset value one by one or in combination, and the preset value includes the maximum value, minimum value or intermediate value within the value range defined by the field; for the variable field The data of another part of the field is randomly mutated to generate a test case that does not match the definition of another part of the field data.

具体来说,还以读写多寄存器功能的测试用例生成方法为例,首先,与示例一类似的是,先从表2中选择功能码字段、协议标识符字段、单元标识符字段以及事务处理标识符字段作为不可变字段,将其设置为预设值,从而保证生成的测试用例能够基于Modbus/Tcp协议进行正常的通信。再表2中n个可变字段中选出m个字段,然后将这m个字段逐一地或组合地设置为预设值,其中,这里的预设值可以为该字段在取值范围内具有代表性的值,例如最大值、最小值或中间值。最后对另外n-m个字段进行随机取值变异,从而以生成与这n-m个字段数据的定义不符的测试用例。其中,这里可以将m个字段中各个字段取不同的预设值,然后进行排列组合,从而可以生成多个测试用例。例如,若m=2,则被选择的两个字段分别在取值范围内取最大值、最小值或中间值,则排列组合就是9种情况,生成9个测试用例。Specifically, the test case generation method for reading and writing multi-register functions is taken as an example. First, similar to Example 1, select the function code field, protocol identifier field, unit identifier field, and transaction processing from Table 2. As an immutable field, the identifier field is set to a preset value, so as to ensure that the generated test cases can communicate normally based on the Modbus/Tcp protocol. Select m fields from the n variable fields in Table 2, and then set these m fields as preset values one by one or in combination, wherein the preset value here can be that the field has within the value range Representative values, such as maximum, minimum, or median. Finally, random value mutation is performed on the other n-m fields, so as to generate test cases that do not match the definition of the n-m field data. Here, each field in the m fields can take different preset values, and then arrange and combine them, so that multiple test cases can be generated. For example, if m=2, the two selected fields take the maximum value, minimum value or intermediate value within the range of values respectively, then there are 9 cases of permutation and combination, and 9 test cases are generated.

不难理解的是,对于示例一提供的方法来说,对于某一字段包含的内容进行随机变异时,只有很小的概率才能将该字段内容变异为取值范围内具有代表性的值,例如最大值、最小值或中间值。这样就很难对字段内容为代表性值的情况进行测试。因此,示例二提供的生成方法可以作为示例一方法的一种补充,使得本发明提供的方法测试的覆盖范围更大,从而提高测试的有效性。It is not difficult to understand that, for the method provided in Example 1, when the content contained in a field is randomly mutated, there is only a small probability that the content of the field can be mutated into a representative value within the value range, for example Maximum, minimum, or median. This makes it difficult to test cases where the field contents are representative values. Therefore, the generation method provided by Example 2 can be used as a supplement to the method of Example 1, so that the test coverage of the method provided by the present invention is larger, thereby improving the effectiveness of the test.

示例三、将可变字段中用于表示单元标识符字段、功能码字段以及数据域长度的长度字段设置为预设值,对单元标识符字段、功能码字段以及数据域中的任一项或其组合进行变异而加长或者压缩实际长度,以生成实际长度与长度字段的预设值不匹配的测试用例。这里仍然以读写多寄存器的功能码为例,如表2所示,对于读写多寄存器的功能码来说,单元标识符、功能码和数据域长度的长度值为11+N*2个字节。这里的长度值的作用在于指示报文的长度,即使将报文分成多个信息包来传输,长度信息能够使接收者识别报文边界。如果对单元标识符字段、功能码字段以及数据域中的任一项或其组合进行变异而加长或者压缩实际长度,使实际长度与上述设置的长度值不符,则即可生成长度异常的测试用例。在这种情况下,接收者无法正确识别实际的报文边界,就会出现接收异常,从而可以对长度异常的情况进行测试。Example 3: Set the length field used to indicate the length of the unit identifier field, function code field and data field in the variable field to a preset value, and set any of the unit identifier field, function code field and data field or The combination is mutated to lengthen or compress the actual length to generate test cases whose actual length does not match the preset value of the length field. Here still take the function code of reading and writing multiple registers as an example, as shown in Table 2, for the function code of reading and writing multiple registers, the length value of unit identifier, function code and data field length is 11+N*2 byte. The function of the length value here is to indicate the length of the message. Even if the message is divided into multiple information packets for transmission, the length information can enable the receiver to identify the boundary of the message. If any one or combination of the unit identifier field, function code field, and data field is mutated to lengthen or compress the actual length, so that the actual length does not match the length value set above, a test case with abnormal length can be generated . In this case, the receiver cannot correctly identify the actual packet boundary, and a reception exception will occur, so that the abnormal length can be tested.

可以理解的是,上述这种方法主要是针对有约束条件的情况,例如数据包中的长度字段在Modbus协议规约中是指后续字节的长度,需要根据字节长度计算结果才能确定,而当故意加长或缩短Modbus数据包并且长度字段的值固定时,目标程序中如果没有对约束条件进行容错,就容易出问题,从而可以对这样的情况进行测试。It can be understood that the above-mentioned method is mainly for situations with constraints. For example, the length field in the data packet refers to the length of the subsequent byte in the Modbus protocol specification, which needs to be determined according to the calculation result of the byte length. When When the Modbus data packet is deliberately lengthened or shortened and the value of the length field is fixed, if there is no fault tolerance for the constraint conditions in the target program, it is easy to go wrong, so that such a situation can be tested.

综上所述,本发明关于如何选择出其余至少一部分字段变异,即到底选哪部分字段进行变异:To sum up, the present invention is about how to select at least some of the remaining fields to mutate, that is, which part of the fields to mutate:

功能码作为第一级分类,不同的功能码后续跟的字段不同;The function code is the first-level classification, and different function codes follow different fields;

对于每一种功能码,后续跟的字段不同,再具体确定哪些字段不可变和可变;不可变字段保持不变,而对于可变的字段:For each function code, the following fields are different, and then specifically determine which fields are immutable and variable; immutable fields remain unchanged, and for variable fields:

可以全部变异,即第二级分类,优点是测试全面,如示例一所述;It can be fully mutated, that is, the second-level classification. The advantage is that the test is comprehensive, as described in Example 1;

也可以选择某些字段在其取值范围内取预设值,如示例二所述;You can also select certain fields to take preset values within their value range, as described in Example 2;

也可以选择某些字段根据约束性关系取预设值,例如长度。具体选哪些字段设预设值就是第三级分类。You can also choose some fields to take preset values according to the constraint relationship, such as length. Which fields are selected to set the default value is the third-level classification.

所以测试用例会根据这三级分类呈现出像树形结构一样的分布。Therefore, the test cases will be distributed like a tree structure according to the three-level classification.

具体的说,10个功能码就有10个一级子节点,对每个一级子节点,根据第二级分类,都会有可变字段全部变异的测试用例;Specifically, there are 10 first-level child nodes for 10 function codes, and for each first-level child node, according to the second-level classification, there will be test cases in which all variable fields are mutated;

对每个一级子节点,根据第三级分类,都会有可变字段中某些字段取预设值的测试用例,且预设值可以是在其取值范围内取预设值,也可以根据约束性关系取预设值。For each first-level child node, according to the third-level classification, there will be test cases in which some fields in the variable fields take preset values, and the preset values can be preset values within its value range, or Take the default value according to the constraint relationship.

需要说明的是,上述方法实施例中的变异均可以通过多种随机算法来实现,随机算法可以包括数值边界变异,数据元素删除变异,数据元素重复变异,有效值变异等。对于特殊的字符还可以有特殊的变异方式。例如,对于数据帧中含有字符类字段的,除了纯粹的数值变异,还可以构造字符类型的变异数据,也就是说畸形数据生成策略具体包括:整数型字段通过设置不同的特殊数值构造整数溢出类型畸形数据包;字符型字段通过设置不同的特殊字符构造畸形数据包,包括使用超长字符串用来检测字符串溢出、NULL结束符缺失的非法串、格式化字符串等。当然,还可以包括其他变异类型,本发明对此不作具体限定。It should be noted that the mutations in the above method embodiments can be realized by various random algorithms, and the random algorithms can include numerical boundary mutations, data element deletion mutations, data element repetition mutations, effective value mutations, and the like. There can also be special variants for special characters. For example, for data frames containing character fields, in addition to pure numerical variation, you can also construct character-type variable data, that is to say, the malformed data generation strategy specifically includes: Integer fields construct integer overflow types by setting different special values Malformed data packets; character-type fields construct malformed data packets by setting different special characters, including using super long strings to detect string overflow, illegal strings with missing NULL terminators, formatted strings, etc. Of course, other variation types may also be included, which is not specifically limited in the present invention.

不难理解的是,上述方法实施例中的举例说明只是为了便于更好地理解本发明实施例提供的测试用例的生成方法,并不能构成对本发明的具体限定。且上述的各个优选实施方式之间不会相互影响,各个优选实施方式之间的任意组合所得到的方案均应该落入本发明的保护范围。It is not difficult to understand that the illustrations in the above method embodiments are only for better understanding of the method for generating test cases provided by the embodiments of the present invention, and cannot constitute a specific limitation of the present invention. Moreover, the above-mentioned preferred implementation modes will not affect each other, and the solution obtained by any combination of the preferred implementation modes shall fall within the scope of protection of the present invention.

此外,在具体实施时,本实施例提供的测试用例的生成方法均可以使用模糊测试框架生成对于某一功能的测试用例数据定义的文件。优选地,测试用例是包含以下标签域的xml文件:In addition, during specific implementation, the methods for generating test cases provided in this embodiment may use a fuzzy testing framework to generate a file defining test case data for a certain function. Preferably, the test case is an xml file containing the following tag fields:

其中,in,

1)第一级标签<Peach></Peach>包括整个文件,用于版本介绍等。1) The first-level tag <Peach></Peach> includes the entire file and is used for version introduction, etc.

2)第二级标签包括Include,DataModel,StateModel,Agent,Test,Run,其中:2) The second-level tags include Include, DataModel, StateModel, Agent, Test, Run, where:

3)Include标签域用于包含外部文件,含有模糊测试框架的基本方法,类,数据类型等。3) The Include tag field is used to include external files, including basic methods, classes, data types, etc. of the fuzzing framework.

4)DataModel标签域用于定义数据结构,此标签下还可以有若干级、若干种下级标签。使用这些子标签可以比较容易的定义数据的类型,大小,各个数据块之间的关系,以及CRC校验和等。此外,可以定义多个DataModel,多个DataModel之间可以有关系也可以没有关系。4) The DataModel tag domain is used to define the data structure, and there may be several levels and several kinds of lower-level tags under this tag. Using these subtags can easily define the data type, size, relationship between each data block, and CRC checksum, etc. In addition, multiple DataModels can be defined, and there may or may not be a relationship between multiple DataModels.

5)StateModel标签域用于定义测试的逻辑,实际上相当于一个状态机。下级标签包括State用于表示一个状态,每个State中又可以包含若干个Action标签,用于执行发送数据包之类的命令。5) The StateModel tag field is used to define the logic of the test, which is actually equivalent to a state machine. Subordinate tags include State to represent a state, and each State can contain several Action tags, which are used to execute commands such as sending data packets.

6)Agent标签域用于检测exception,crash等,即用来监测被测目标的反应。6) The Agent tag field is used to detect exception, crash, etc., that is, to monitor the reaction of the measured target.

7)Test标签域用于指定将要使用到的state,Agent,publisher等,用什么方法发数据,还可指定使用什么方法加工数据。7) The Test tag field is used to specify the state, Agent, publisher, etc. to be used, the method to send data, and the method to process data.

8)Run标签域用于指定模糊测试执行的进入点,即当前这次模糊测试使用哪个Test。8) The Run tag field is used to specify the entry point of the fuzz test execution, that is, which Test is used for the current fuzz test.

当然,上述数据定义文件的生成方法只是一种可选的实施例,还可以通过其他方式生成,本发明对此不作具体限定。Certainly, the method for generating the above data definition file is only an optional embodiment, and may also be generated in other ways, which is not specifically limited in the present invention.

为证明本发明的优越性,本发明做了一系列测试实验。在这里仍然以读写多寄存器的功能码为例,基于示例一提供的方法,保持功能码不变,保持读数量字段、写起始地址字段、写数量字段、写字节数字段包含的内容不变,将读起始地址字段以及写入值字段的属性为变异为真,被测设备在接收到测试用例前和接收到测试用例后的状态可以如图2-图4所示。In order to prove the superiority of the present invention, the present invention has done a series of test experiments. Here still take the function code of reading and writing multiple registers as an example, based on the method provided in Example 1, keep the function code unchanged, and keep the contents contained in the read quantity field, write start address field, write quantity field, and write byte number field Unchanged, the attributes of the read start address field and the write value field are mutated to true, and the state of the device under test before and after receiving the test case can be shown in Figure 2-Figure 4.

显然,如图2所示,被测设备在没有接受到测试用例时,能够正常建立TCP连接,处于正常的抓包状态。一旦接受到测试用例时,就会如图3所示出现异常,无法建立TCP连接,且服务器端也没有响应TCP连接。相应的,TCP的通讯连通状态也由图4(a)示出的ON变为图4(b)示出的OFF,从而可以对这一功能进行有效的漏洞测试。Obviously, as shown in Figure 2, when the device under test does not receive the test case, it can normally establish a TCP connection and is in a normal packet capture state. Once the test case is received, an exception will occur as shown in Figure 3, the TCP connection cannot be established, and the server does not respond to the TCP connection. Correspondingly, the communication connection status of TCP is also changed from ON shown in Figure 4(a) to OFF shown in Figure 4(b), so that this function can be effectively tested for vulnerabilities.

需要说明的是,为了能生成覆盖率高的测试用例,除了上述读写多寄存器的功能码,还可以基于上述方法实施例提供的方法对其他功能码进行分析,生成其他功能码的测试用例。同时还可以针对每种功能码的不同的感兴趣字段进行测试,发现可能的漏洞,这里不一一列举,表3为不同功能码测试不同字段后会引起错误的统计表。It should be noted that, in order to generate test cases with high coverage, in addition to the above-mentioned function codes for reading and writing multiple registers, other function codes can also be analyzed based on the methods provided by the above method embodiments to generate test cases for other function codes. At the same time, it is also possible to test different fields of interest for each function code to find possible loopholes, which are not listed here. Table 3 is a statistical table of errors caused by different function codes testing different fields.

表3不同功能码测试不同字段后引起错误的统计表Table 3 Statistical table of errors caused by testing different fields with different function codes

第二方面,本发明提供了一种测试用例生成装置,与本发明第一方面提供的方法对应,用于生成测试Modbus协议规约的测试用例,如图5所示,包括:In a second aspect, the present invention provides a test case generation device, corresponding to the method provided in the first aspect of the present invention, for generating a test case for testing the Modbus protocol protocol, as shown in Figure 5, including:

功能码选择单元501,用于在预存的若干个功能码中选取一个作为目标功能码;其中,若干个功能码,为Modbus协议规定的执行不同功能操作的数据包所对应的若干个功能码;The function code selection unit 501 is used to select one as the target function code in several prestored function codes; wherein, the several function codes are corresponding several function codes for the data packets that perform different functional operations specified by the Modbus protocol;

获取单元502,用于根据Modbus协议规定,获取与目标功能码对应的数据包中各个字段的定义;Obtaining unit 502, for obtaining the definition of each field in the data packet corresponding to the target function code according to the Modbus protocol;

字段选择变异单元503,用于选取功能码字段以及各个字段中用于控制测试用例通信功能的字段作为不可变字段,将其余字段作为可变字段;将不可变字段设置为预设值,以使测试用例支持基于Modbus协议进行通信;对可变字段中的至少一个字段进行随机变异,以生成与至少一个字段的定义不符或数据设置不符的测试用例。The field selection variation unit 503 is used to select the function code field and the field used to control the communication function of the test case in each field as an immutable field, and use the remaining fields as a variable field; the immutable field is set to a preset value, so that The test case supports communication based on the Modbus protocol; at least one field in the variable field is randomly mutated to generate a test case that does not match the definition or data setting of at least one field.

在具体实施时,字段选择变异单元503,还用于:对所有可变字段的数据进行随机变异,以生成与可变字段数据的定义不符的测试用例。During specific implementation, the field selection mutation unit 503 is further configured to randomly mutate the data of all variable fields, so as to generate test cases inconsistent with the definition of variable field data.

在具体实施时,字段选择变异单元503,还用于:将可变字段中的一部分字段的数据逐一地或组合地设置为预设值,预设值包括字段定义的取值范围内的最大值、最小值或中间值;对可变字段中的另一部分字段的数据进行随机取值变异,以生成与另一部分字段数据的定义不符的测试用例。In a specific implementation, the field selection variation unit 503 is also used to: set the data of some fields in the variable fields as preset values one by one or in combination, and the preset value includes the maximum value within the value range defined by the field , the minimum value or the median value; the data in another part of the variable field is randomly mutated to generate a test case that does not match the definition of another part of the field data.

在具体实施时,字段选择变异单元503,还用于:将可变字段中用于表示单元标识符字段、功能码字段以及数据域长度的长度字段设置为预设值,对单元标识符字段、功能码字段以及数据域中的任一项或其组合进行变异而加长或者压缩实际长度,以生成实际长度与长度字段的预设值不匹配的测试用例。During specific implementation, the field selection variation unit 503 is also used to: set the length field used to represent the unit identifier field, function code field and data field length in the variable field as a preset value, and set the unit identifier field, Any one or combination of the function code field and the data field is mutated to lengthen or compress the actual length, so as to generate a test case whose actual length does not match the preset value of the length field.

在具体实施时,这里的随机变异包括数据元素删除变异,数据元素重复变异,有效值变异,或在各字段定义的数值范围内的数值边界变异。During specific implementation, the random variation here includes data element deletion variation, data element repetition variation, effective value variation, or numerical boundary variation within the numerical range defined by each field.

由于本实施例所介绍的测试用例生成装置为可以执行本发明实施例中的测试用例生成方法的装置,故而基于本发明实施例中所介绍的测试用例生成的方法,本领域所属技术人员能够了解本实施例的测试用例生成装置的具体实施方式以及其各种变化形式,所以在此对于该测试用例生成装置如何实现本发明实施例中的测试用例生成方法不再详细介绍。只要本领域所属技术人员实施本发明实施例中测试用例生成方法所采用的装置,都属于本申请所欲保护的范围。Since the test case generation device introduced in this embodiment is a device that can execute the test case generation method in the embodiment of the present invention, based on the test case generation method described in the embodiment of the present invention, those skilled in the art can understand The specific implementation of the test case generating device in this embodiment and its various variants, so how the test case generating device implements the test case generating method in the embodiment of the present invention will not be described in detail here. As long as a person skilled in the art implements the device used by the test case generation method in the embodiment of the present invention, it all belongs to the protection scope of the present application.

在此提供的算法和显示不与任何特定计算机、虚拟系统或者其它设备固有相关。各种通用系统也可以与基于在此的示教一起使用。根据上面的描述,构造这类系统所要求的结构是显而易见的。此外,本发明也不针对任何特定编程语言。应当明白,可以利用各种编程语言实现在此描述的本发明的内容,并且上面对特定语言所做的描述是为了披露本发明的最佳实施方式。The algorithms and displays presented herein are not inherently related to any particular computer, virtual system, or other device. Various generic systems can also be used with the teachings based on this. The structure required to construct such a system is apparent from the above description. Furthermore, the present invention is not specific to any particular programming language. It should be understood that various programming languages can be used to implement the contents of the present invention described herein, and the above description of specific languages is for disclosing the best mode of the present invention.

在此处所提供的说明书中,说明了大量具体细节。然而,能够理解,本发明的实施例可以在没有这些具体细节的情况下实践。在一些实例中,并未详细示出公知的方法、结构和技术,以便不模糊对本说明书的理解。In the description provided herein, numerous specific details are set forth. However, it is understood that embodiments of the invention may be practiced without these specific details. In some instances, well-known methods, structures and techniques have not been shown in detail in order not to obscure the understanding of this description.

类似地,应当理解,为了精简本公开并帮助理解各个发明方面中的一个或多个,在上面对本发明的示例性实施例的描述中,本发明的各个特征有时被一起分组到单个实施例、图、或者对其的描述中。然而,并不应将该公开的方法解释成反映如下意图:即所要求保护的本发明要求比在每个权利要求中所明确记载的特征更多的特征。更确切地说,如下面的权利要求书所反映的那样,发明方面在于少于前面公开的单个实施例的所有特征。因此,遵循具体实施方式的权利要求书由此明确地并入该具体实施方式,其中每个权利要求本身都作为本发明的单独实施例。Similarly, it should be appreciated that in the foregoing description of exemplary embodiments of the invention, in order to streamline this disclosure and to facilitate an understanding of one or more of the various inventive aspects, various features of the invention are sometimes grouped together in a single embodiment, figure, or its description. This method of disclosure, however, is not to be interpreted as reflecting an intention that the claimed invention requires more features than are expressly recited in each claim. Rather, as the following claims reflect, inventive aspects lie in less than all features of a single foregoing disclosed embodiment. Thus, the claims following the Detailed Description are hereby expressly incorporated into this Detailed Description, with each claim standing on its own as a separate embodiment of this invention.

本领域那些技术人员可以理解,可以对实施例中的设备中的模块进行自适应性地改变并且把它们设置在与该实施例不同的一个或多个设备中。可以把实施例中的模块或单元或组件组合成一个模块或单元或组件,以及此外可以把它们分成多个子模块或子单元或子组件。除了这样的特征和/或过程或者单元中的至少一些是相互排斥之外,可以采用任何组合对本说明书(包括伴随的权利要求、摘要和附图)中公开的所有特征以及如此公开的任何方法或者设备的所有过程或单元进行组合。除非另外明确陈述,本说明书(包括伴随的权利要求、摘要和附图)中公开的每个特征可以由提供相同、等同或相似目的的替代特征来代替。Those skilled in the art can understand that the modules in the device in the embodiment can be adaptively changed and arranged in one or more devices different from the embodiment. Modules or units or components in the embodiments may be combined into one module or unit or component, and furthermore may be divided into a plurality of sub-modules or sub-units or sub-assemblies. All features disclosed in this specification (including accompanying claims, abstract and drawings) and any method or method so disclosed may be used in any combination, except that at least some of such features and/or processes or units are mutually exclusive. All processes or units of equipment are combined. Each feature disclosed in this specification (including accompanying claims, abstract and drawings) may be replaced by alternative features serving the same, equivalent or similar purpose, unless expressly stated otherwise.

此外,本领域的技术人员能够理解,尽管在此的一些实施例包括其它实施例中所包括的某些特征而不是其它特征,但是不同实施例的特征的组合意味着处于本发明的范围之内并且形成不同的实施例。例如,在下面的权利要求书中,所要求保护的实施例的任意之一都可以以任意的组合方式来使用。Furthermore, those skilled in the art will understand that although some embodiments herein include some features included in other embodiments but not others, combinations of features from different embodiments are meant to be within the scope of the invention. And form different embodiments. For example, in the following claims, any of the claimed embodiments may be used in any combination.

本发明的各个部件实施例可以以硬件实现,或者以在一个或者多个处理器上运行的软件模块实现,或者以它们的组合实现。本领域的技术人员应当理解,可以在实践中使用微处理器或者数字信号处理器(DSP)来实现根据本发明实施例的网关、代理服务器、系统中的一些或者全部部件的一些或者全部功能。本发明还可以实现为用于执行这里所描述的方法的一部分或者全部的设备或者装置程序(例如,计算机程序和计算机程序产品)。这样的实现本发明的程序可以存储在计算机可读介质上,或者可以具有一个或者多个信号的形式。这样的信号可以从因特网网站上下载得到,或者在载体信号上提供,或者以任何其他形式提供。The various component embodiments of the present invention may be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. Those skilled in the art should understand that a microprocessor or a digital signal processor (DSP) can be used in practice to implement some or all functions of some or all components in the gateway, proxy server, and system according to the embodiments of the present invention. The present invention can also be implemented as an apparatus or an apparatus program (for example, a computer program and a computer program product) for performing a part or all of the methods described herein. Such a program for realizing the present invention may be stored on a computer-readable medium, or may be in the form of one or more signals. Such a signal may be downloaded from an Internet site, or provided on a carrier signal, or provided in any other form.

应该注意的是上述实施例对本发明进行说明而不是对本发明进行限制,并且本领域技术人员在不脱离所附权利要求的范围的情况下可设计出替换实施例。在权利要求中,不应将位于括号之间的任何参考符号构造成对权利要求的限制。单词“包含”不排除存在未列在权利要求中的元件或步骤。位于元件之前的单词“一”或“一个”不排除存在多个这样的元件。本发明可以借助于包括有若干不同元件的硬件以及借助于适当编程的计算机来实现。在列举了若干装置的单元权利要求中,这些装置中的若干个可以是通过同一个硬件项来具体体现。单词第一、第二、以及第三等的使用不表示任何顺序。可将这些单词解释为名称。It should be noted that the above-mentioned embodiments illustrate rather than limit the invention, and that those skilled in the art will be able to design alternative embodiments without departing from the scope of the appended claims. In the claims, any reference signs placed between parentheses shall not be construed as limiting the claim. The word "comprising" does not exclude the presence of elements or steps not listed in a claim. The word "a" or "an" preceding an element does not exclude the presence of a plurality of such elements. The invention can be implemented by means of hardware comprising several distinct elements, and by means of a suitably programmed computer. In a unit claim enumerating several means, several of these means can be embodied by one and the same item of hardware. The use of the words first, second, and third, etc. does not indicate any order. These words can be interpreted as names.

Claims (10)

1.一种测试用例生成方法,其特征在于,用于生成针对Modbus协议的测试用例,所述方法包括:1. a test case generation method, is characterized in that, for generating the test case for Modbus agreement, described method comprises: 在预存的若干个功能码中选取一个作为目标功能码;其中,所述若干个功能码,为Modbus协议规定的执行不同功能操作的数据包所对应的若干个功能码;Select one as the target function code in several pre-stored function codes; wherein, the several function codes are several function codes corresponding to data packets that perform different functional operations as stipulated by the Modbus protocol; 根据Modbus协议规定,获取与所述目标功能码对应的数据包中各个字段的定义;According to the Modbus protocol, obtain the definition of each field in the data packet corresponding to the target function code; 选取功能码字段以及各个字段中用于控制测试用例通信功能的字段作为不可变字段,将其余字段作为可变字段;将所述不可变字段设置为预设值,以使所述测试用例支持基于Modbus协议进行通信;对所述可变字段中的至少一个字段进行随机变异,以生成与所述至少一个字段的定义不符或数据设置不符的测试用例。Select the function code field and the field used to control the communication function of the test case in each field as an immutable field, and use the rest of the fields as variable fields; set the immutable field as a preset value so that the test case supports based on The Modbus protocol is used for communication; at least one field in the variable fields is randomly mutated to generate a test case inconsistent with the definition or data setting of the at least one field. 2.根据权利要求1所述的方法,其特征在于,所述对所述可变字段中的至少一个字段进行随机变异,以生成与所述至少一个字段的定义不符或数据设置不符的测试用例的步骤,包括:2. The method according to claim 1, wherein the at least one field in the variable field is randomly mutated to generate a test case inconsistent with the definition or data setting of the at least one field steps, including: 对所有可变字段的数据进行随机变异,以生成与所述可变字段数据的定义不符的测试用例。Randomly mutate the data of all variable fields to generate test cases that do not conform to the definition of said variable field data. 3.根据权利要求1所述的方法,其特征在于,所述对所述可变字段中的至少一个字段进行随机变异,以生成与所述至少一个字段的定义不符或数据设置不符的测试用例的步骤,包括:3. The method according to claim 1, wherein the at least one field in the variable field is randomly mutated to generate a test case inconsistent with the definition or data setting of the at least one field steps, including: 将所述可变字段中的一部分字段的数据逐一地或组合地设置为预设值,所述预设值包括所述字段定义的取值范围内的最大值、最小值或中间值;Setting the data of a part of the variable fields as a preset value one by one or in combination, the preset value including a maximum value, a minimum value or an intermediate value within the value range defined by the fields; 对所述可变字段中的另一部分字段的数据进行随机取值变异,以生成与所述另一部分字段数据的定义不符的测试用例。Randomly mutating the data of another part of the variable fields to generate a test case inconsistent with the definition of the other part of the field data. 4.根据权利要求1所述的方法,其特征在于,所述对所述可变字段中的至少一个字段进行随机变异,以生成与所述至少一个字段的定义不符或数据设置不符的测试用例的步骤,包括:4. The method according to claim 1, wherein the at least one field in the variable field is randomly mutated to generate a test case inconsistent with the definition or data setting of the at least one field steps, including: 将所述可变字段中用于表示单元标识符字段、功能码字段以及数据域长度的长度字段设置为预设值,对所述单元标识符字段、功能码字段以及数据域中的任一项或其组合进行变异而加长或者压缩实际长度,以生成实际长度与所述长度字段的预设值不匹配的测试用例。Set the length field used to represent the unit identifier field, the function code field and the length of the data field in the variable field to a preset value, and any one of the unit identifier field, the function code field and the data field or a combination thereof to lengthen or compress the actual length, so as to generate a test case whose actual length does not match the preset value of the length field. 5.根据权利要求1-4任一所述的方法,其特征在于,所述随机变异包括数据元素删除变异,数据元素重复变异,有效值变异,或在各字段定义的数值范围内的数值边界变异。5. The method according to any one of claims 1-4, wherein the random variation includes data element deletion variation, data element repetition variation, effective value variation, or numerical boundaries within the numerical range defined by each field Mutations. 6.一种测试用例生成装置,其特征在于,用于生成针对Modbus协议的测试用例,所述装置包括:6. A test case generating device, characterized in that, for generating a test case for the Modbus protocol, the device comprises: 功能码选择单元,用于在预存的若干个功能码中选取一个作为目标功能码;其中,所述若干个功能码,为Modbus协议规定的执行不同功能操作的数据包所对应的若干个功能码;The function code selection unit is used to select one of the pre-stored function codes as the target function code; wherein the several function codes are the corresponding several function codes of the data packets that perform different functional operations specified by the Modbus protocol ; 获取单元,用于根据Modbus协议规定,获取与所述目标功能码对应的数据包中各个字段的定义;The acquisition unit is used to obtain the definition of each field in the data packet corresponding to the target function code according to the Modbus protocol; 字段选择变异单元,用于选取功能码字段以及各个字段中用于控制测试用例通信功能的字段作为不可变字段,将其余字段作为可变字段;将所述不可变字段设置为预设值,以使所述测试用例支持基于Modbus协议进行通信;对所述可变字段中的至少一个字段进行随机变异,以生成与所述至少一个字段的定义不符或数据设置不符的测试用例。The field selection mutation unit is used to select the function code field and the field used to control the communication function of the test case in each field as an immutable field, and use the remaining fields as variable fields; set the immutable field as a preset value to Making the test case support communication based on the Modbus protocol; randomly mutating at least one of the variable fields to generate a test case inconsistent with the definition or data setting of the at least one field. 7.根据权利要求6所述的装置,其特征在于,7. The device of claim 6, wherein: 所述字段选择变异单元,还用于对所有可变字段的数据进行随机变异,以生成与所述可变字段数据的定义不符的测试用例。The field selection mutation unit is also used to randomly mutate the data of all variable fields to generate test cases that do not conform to the definition of the variable field data. 8.根据权利要求6所述的装置,其特征在于,所述字段选择变异单元,还用于:8. The device according to claim 6, wherein the field selection mutation unit is further configured to: 将所述可变字段中的一部分字段的数据逐一地或组合地设置为预设值,所述预设值包括所述字段定义的取值范围内的最大值、最小值或中间值;Setting the data of a part of the variable fields as a preset value one by one or in combination, the preset value including a maximum value, a minimum value or an intermediate value within the value range defined by the fields; 对所述可变字段中的另一部分字段的数据进行随机取值变异,以生成与所述另一部分字段数据的定义不符的测试用例。Randomly mutating the data of another part of the variable fields to generate a test case inconsistent with the definition of the other part of the field data. 9.根据权利要求6所述的装置,其特征在于,所述字段选择变异单元,还用于:9. The device according to claim 6, wherein the field selection variation unit is further used for: 将所述可变字段中用于表示单元标识符字段、功能码字段以及数据域长度的长度字段设置为预设值,对所述单元标识符字段、功能码字段以及数据域中的任一项或其组合进行变异而加长或者压缩实际长度,以生成实际长度与所述长度字段的预设值不匹配的测试用例。In the variable field, the length field used to represent the unit identifier field, the function code field and the length of the data field is set to a preset value, and any one of the unit identifier field, the function code field and the data field or a combination thereof to lengthen or compress the actual length, so as to generate a test case whose actual length does not match the preset value of the length field. 10.根据权利要求6-9任一所述的装置,其特征在于,所述随机变异包括数据元素删除变异,数据元素重复变异,有效值变异,或在各字段定义的数值范围内的数值边界变异。10. The device according to any one of claims 6-9, wherein the random variation includes data element deletion variation, data element repetition variation, effective value variation, or numerical boundaries within the numerical range defined by each field Mutations.
CN201610697317.4A 2016-08-19 2016-08-19 Test case generation method and device Pending CN106330601A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201610697317.4A CN106330601A (en) 2016-08-19 2016-08-19 Test case generation method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201610697317.4A CN106330601A (en) 2016-08-19 2016-08-19 Test case generation method and device

Publications (1)

Publication Number Publication Date
CN106330601A true CN106330601A (en) 2017-01-11

Family

ID=57741152

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201610697317.4A Pending CN106330601A (en) 2016-08-19 2016-08-19 Test case generation method and device

Country Status (1)

Country Link
CN (1) CN106330601A (en)

Cited By (17)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106788480A (en) * 2017-03-20 2017-05-31 上海资誉电子科技有限公司 The winged control signal testing method and system of unmanned plane
CN107193731A (en) * 2017-05-12 2017-09-22 北京理工大学 Use the fuzz testing coverage rate improved method of control variation
CN107404487A (en) * 2017-08-07 2017-11-28 浙江国利信安科技有限公司 A kind of industrial control system safety detection method and device
CN107517199A (en) * 2017-07-14 2017-12-26 国家电网公司 A kind of method for generating test case and system for being used for 376.1 protocol security defects detections
CN109922063A (en) * 2019-03-05 2019-06-21 南方电网科学研究院有限责任公司 Pollution data generation method for fuzz testing of multi-function meter communication protocol
CN110597734A (en) * 2019-09-23 2019-12-20 电子科技大学 A fuzzy test case generation method suitable for industrial control private protocol
CN112055003A (en) * 2020-08-26 2020-12-08 上海电力大学 A method for generating private protocol fuzzing test cases based on byte length classification
CN112104634A (en) * 2020-09-08 2020-12-18 中国电力科学研究院有限公司 Data message processing method, system, equipment and readable storage medium
CN112422485A (en) * 2019-08-23 2021-02-26 北京东土科技股份有限公司 Communication method and device of transmission control protocol
CN113179274A (en) * 2021-04-29 2021-07-27 哈尔滨工程大学 Modbus protocol vulnerability mining method based on dynamic taint analysis
CN113986712A (en) * 2021-09-10 2022-01-28 深圳开源互联网安全技术有限公司 Fuzzy test method and device based on HTTP/2
CN114063606A (en) * 2022-01-13 2022-02-18 浙江大学 PLC protocol fuzzy test method and device, electronic equipment and storage medium
CN115659907A (en) * 2022-11-04 2023-01-31 北京晟芯网络科技有限公司 Method for verifying register coverage rate, computer storage medium and terminal
CN115766541A (en) * 2022-11-15 2023-03-07 合众新能源汽车有限公司 Device testing method, device, computer equipment and storage medium
CN117216772A (en) * 2023-11-09 2023-12-12 中兴通讯股份有限公司 Fuzz test case optimization methods, devices, equipment and readable media
CN117792967A (en) * 2024-02-26 2024-03-29 南京邮电大学 A camera fuzz testing method based on difference feedback
WO2024240100A1 (en) * 2023-05-19 2024-11-28 北京字跳网络技术有限公司 Test case generation method and apparatus, device and storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2010287034A (en) * 2009-06-11 2010-12-24 Koyo Electronics Ind Co Ltd Address display system of modbus protocol communication between external equipment and plc
CN102437952A (en) * 2012-01-29 2012-05-02 山东黄金矿业(莱州)有限公司焦家金矿 Management method of multi-variant Modbus protocol message
CN103853650A (en) * 2012-11-28 2014-06-11 西门子公司 Test case generating method and device for fuzz testing
CN105721230A (en) * 2014-11-30 2016-06-29 中国科学院沈阳自动化研究所 Modbus protocol-oriented fuzz testing method
CN105827469A (en) * 2014-12-29 2016-08-03 国家电网公司 MODBUS TCP implementation defect tester and detection method thereof

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP2010287034A (en) * 2009-06-11 2010-12-24 Koyo Electronics Ind Co Ltd Address display system of modbus protocol communication between external equipment and plc
CN102437952A (en) * 2012-01-29 2012-05-02 山东黄金矿业(莱州)有限公司焦家金矿 Management method of multi-variant Modbus protocol message
CN103853650A (en) * 2012-11-28 2014-06-11 西门子公司 Test case generating method and device for fuzz testing
CN105721230A (en) * 2014-11-30 2016-06-29 中国科学院沈阳自动化研究所 Modbus protocol-oriented fuzz testing method
CN105827469A (en) * 2014-12-29 2016-08-03 国家电网公司 MODBUS TCP implementation defect tester and detection method thereof

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
万明;尚文利;曾鹏;赵剑明;: "基于功能码深度检测的Modbus/TCP通信访问控制方法", 信息与控制, no. 02, 15 April 2016 (2016-04-15), pages 124 - 132 *
李航;董伟;朱广宇;: "基于Fuzzing测试的工业控制协议漏洞挖掘技术研究", 电子技术应用, no. 07, 12 July 2016 (2016-07-12), pages 85 - 88 *

Cited By (27)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106788480A (en) * 2017-03-20 2017-05-31 上海资誉电子科技有限公司 The winged control signal testing method and system of unmanned plane
CN107193731B (en) * 2017-05-12 2020-10-27 北京理工大学 Fuzzy test coverage improvement method using control variation
CN107193731A (en) * 2017-05-12 2017-09-22 北京理工大学 Use the fuzz testing coverage rate improved method of control variation
CN107517199A (en) * 2017-07-14 2017-12-26 国家电网公司 A kind of method for generating test case and system for being used for 376.1 protocol security defects detections
CN107404487B (en) * 2017-08-07 2020-07-21 浙江国利网安科技有限公司 Industrial control system safety detection method and device
CN107404487A (en) * 2017-08-07 2017-11-28 浙江国利信安科技有限公司 A kind of industrial control system safety detection method and device
CN109922063A (en) * 2019-03-05 2019-06-21 南方电网科学研究院有限责任公司 Pollution data generation method for fuzz testing of multi-function meter communication protocol
CN112422485A (en) * 2019-08-23 2021-02-26 北京东土科技股份有限公司 Communication method and device of transmission control protocol
CN112422485B (en) * 2019-08-23 2023-05-26 北京东土科技股份有限公司 Communication method and device of transmission control protocol
CN110597734A (en) * 2019-09-23 2019-12-20 电子科技大学 A fuzzy test case generation method suitable for industrial control private protocol
CN110597734B (en) * 2019-09-23 2021-06-01 电子科技大学 Fuzzy test case generation method suitable for industrial control private protocol
CN112055003B (en) * 2020-08-26 2022-12-23 上海电力大学 Method for generating private protocol fuzzy test case based on byte length classification
CN112055003A (en) * 2020-08-26 2020-12-08 上海电力大学 A method for generating private protocol fuzzing test cases based on byte length classification
CN112104634A (en) * 2020-09-08 2020-12-18 中国电力科学研究院有限公司 Data message processing method, system, equipment and readable storage medium
CN113179274A (en) * 2021-04-29 2021-07-27 哈尔滨工程大学 Modbus protocol vulnerability mining method based on dynamic taint analysis
CN113179274B (en) * 2021-04-29 2022-05-20 哈尔滨工程大学 A Modbus protocol vulnerability mining method based on dynamic taint analysis
CN113986712A (en) * 2021-09-10 2022-01-28 深圳开源互联网安全技术有限公司 Fuzzy test method and device based on HTTP/2
CN114063606A (en) * 2022-01-13 2022-02-18 浙江大学 PLC protocol fuzzy test method and device, electronic equipment and storage medium
CN115659907A (en) * 2022-11-04 2023-01-31 北京晟芯网络科技有限公司 Method for verifying register coverage rate, computer storage medium and terminal
CN115659907B (en) * 2022-11-04 2025-11-04 北京晟芯网络科技有限公司 A method for verifying register coverage, a computer storage medium, and a terminal.
CN115766541A (en) * 2022-11-15 2023-03-07 合众新能源汽车有限公司 Device testing method, device, computer equipment and storage medium
CN115766541B (en) * 2022-11-15 2024-05-07 合众新能源汽车股份有限公司 Device testing method, device, computer equipment and storage medium
WO2024240100A1 (en) * 2023-05-19 2024-11-28 北京字跳网络技术有限公司 Test case generation method and apparatus, device and storage medium
CN117216772A (en) * 2023-11-09 2023-12-12 中兴通讯股份有限公司 Fuzz test case optimization methods, devices, equipment and readable media
CN117216772B (en) * 2023-11-09 2024-03-08 中兴通讯股份有限公司 Fuzz test case optimization method, device, equipment and readable medium
CN117792967A (en) * 2024-02-26 2024-03-29 南京邮电大学 A camera fuzz testing method based on difference feedback
CN117792967B (en) * 2024-02-26 2024-05-10 南京邮电大学 Camera fuzzy test method based on difference feedback

Similar Documents

Publication Publication Date Title
CN106330601A (en) Test case generation method and device
US12323443B2 (en) Attack behavior detection method and apparatus, and attack detection device
US8607351B1 (en) Modeling cyberspace attacks
JP2012094161A (en) Merging multi-line log entries
WO2013143403A1 (en) Method and system for accessing website
CN110209583A (en) Safety detecting method, device, system, equipment and storage medium
JP2025023927A (en) System and method for security surveillance processing - Patents.com
CN110879891A (en) Vulnerability detection method and device based on web fingerprint information
CN115190047A (en) Server health monitoring method and system and computing equipment
CN112804263A (en) Vulnerability scanning method, system and equipment for Internet of things
CN110011875A (en) Dial-testing method, apparatus, device and computer-readable storage medium
CN114465741B (en) Abnormality detection method, abnormality detection device, computer equipment and storage medium
You et al. Fuzzdocs: An automated security evaluation framework for iot
CN106911649A (en) A kind of method and apparatus for detecting network attack
CN105528230A (en) Method and device for setting configuration parameters
CN103856373B (en) Web system robustness testing method based on HTTP mutation
JP6785360B2 (en) Attack string generation method and device
CN104219219A (en) Method, server and system for handling data
CN116170357B (en) Fuzzy test method and device for block chain consensus protocol
CN115208671B (en) Firewall configuration method, device, electronic device and storage medium
CN116048798A (en) Resource traversal method and computing device
CN110620682B (en) Resource information acquisition method and device, storage medium, terminal
CN116962246A (en) Gateway fault detection method, device, equipment and readable storage medium
CN112217770B (en) Security detection method, security detection device, computer equipment and storage medium
CN107105046B (en) Method and system for remote access to big data

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
C10 Entry into 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: 20170111