WO2023238240A1 - 検証装置、検証方法及び検証プログラム - Google Patents

検証装置、検証方法及び検証プログラム Download PDF

Info

Publication number
WO2023238240A1
WO2023238240A1 PCT/JP2022/022969 JP2022022969W WO2023238240A1 WO 2023238240 A1 WO2023238240 A1 WO 2023238240A1 JP 2022022969 W JP2022022969 W JP 2022022969W WO 2023238240 A1 WO2023238240 A1 WO 2023238240A1
Authority
WO
WIPO (PCT)
Prior art keywords
regular expression
verification
determination unit
syntax
verification device
Prior art date
Application number
PCT/JP2022/022969
Other languages
English (en)
French (fr)
Inventor
忠賢 千田
Original Assignee
日本電信電話株式会社
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 日本電信電話株式会社 filed Critical 日本電信電話株式会社
Priority to PCT/JP2022/022969 priority Critical patent/WO2023238240A1/ja
Publication of WO2023238240A1 publication Critical patent/WO2023238240A1/ja

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F21/00Security arrangements for protecting computers, components thereof, programs or data against unauthorised activity
    • G06F21/50Monitoring users, programs or devices to maintain the integrity of platforms, e.g. of processors, firmware or operating systems
    • G06F21/57Certifying or maintaining trusted computer platforms, e.g. secure boots or power-downs, version controls, system software checks, secure updates or assessing vulnerabilities

Definitions

  • the present invention relates to a verification device, a verification method, and a verification program.
  • regular expressions are implemented as regular expression engines and used in various situations.
  • a regular expression engine is used in a web application that has a screen for entering an email address to check whether the string entered by the user is an email address.
  • regular expression engines are used for sanitizing data sent from outside, extracting elements, and standard libraries for general-purpose programming languages.
  • Regular Expression Denial of Service is known as a cyber attack that exploits such shortcomings (Reference: "Regular Expression Denial of Service - ReDoS", https://owasp.org/www-community/attacks /Regular_expression_Denial_of_Service_-_ReDoS).
  • non-fragile regular expressions a regular expression that operates in linear time on a regular expression engine, relative to the length of the string to be matched, are referred to as non-fragile regular expressions.
  • a regular expression that operates on a regular expression engine in exponential time, for example, with respect to the length of the character string to be matched is called a weak regular expression.
  • Non-Patent Document 1 which corrects errors in languages accepted by regular expressions, is known as a technology for removing the threat of ReDoS. Furthermore, a method is known in which a pure regular expression is converted once into a deterministic finite automaton (Deterministic Finite Automaton) and then back to obtain a non-fragile regular expression (for example, see Non-Patent Document 2).
  • the conventional technology has a problem in that it may not be possible to verify that the vulnerability of the regular expression has been fixed.
  • the verification device includes a first determination unit that determines whether the regular expression follows a prespecified syntax, and a first determination unit that determines whether the regular expression follows a prespecified syntax; and a second determination unit that determines whether a condition indicating that the processing time is linear with respect to the length of the character string is satisfied.
  • FIG. 1 is a diagram showing a configuration example of a correction device according to a first embodiment.
  • FIG. 2 is a diagram illustrating an example of the syntax of a regular expression.
  • FIG. 3 is a diagram showing examples of Positive Examples and Negative Examples.
  • FIG. 4 is a diagram illustrating a method of generating a set of character strings.
  • FIG. 5 is a diagram illustrating a method for synthesizing regular expressions.
  • FIG. 6 is a flowchart showing the process flow of the correction device according to the first embodiment.
  • FIG. 7 is a flowchart showing the flow of regular expression synthesis processing.
  • FIG. 8 is a diagram illustrating a configuration example of a verification device according to the first embodiment.
  • FIG. 9 is a diagram illustrating a method for determining RWS1U.
  • FIG. 10 is a diagram illustrating a parse tree.
  • FIG. 11 is a diagram showing an example of a path.
  • FIG. 12 is a flowchart showing the processing flow of the verification device according to the first embodiment.
  • FIG. 13 is a flowchart showing the flow of RWS1U inspection processing.
  • FIG. 14 is a diagram illustrating an example of a computer that executes a verification program.
  • the regular expression is targeted for modification by the modification device.
  • the modification device does not need to modify the regular expression.
  • correction device and the verification device are separate devices.
  • verification device may also be implemented as part of the functionality of the modification device.
  • FIG. 1 is a diagram showing an example of the configuration of a correction device according to a first embodiment.
  • the modification device 10 receives an input of a regular expression before modification, modifies the input regular expression, and outputs the modified regular expression.
  • FIG. 2 is a diagram illustrating an example of the syntax of a regular expression.
  • Regular expression r in FIG. 2 is an example of a regular expression in this embodiment. Note that in the following description, " ⁇ " in the regular expression may be replaced with a backslash as appropriate.
  • the correction device 10 includes an interface section 11, a storage section 12, and a control section 13.
  • the interface unit 11 is an interface for data input/output and data communication.
  • the interface unit 11 accepts data input from input devices such as a keyboard and a mouse. Further, for example, the interface unit 11 outputs data to an output device such as a display and a speaker.
  • the interface unit 11 may be a device (for example, a NIC (Network Interface Card)) for communicating via a network.
  • a NIC Network Interface Card
  • the storage unit 12 is a storage device such as an HDD (Hard Disk Drive), an SSD (Solid State Drive), or an optical disc. Note that the storage unit 12 may be a data-rewritable semiconductor memory such as a RAM (Random Access Memory), a flash memory, or an NVSRAM (Non Volatile Static Random Access Memory).
  • the storage unit 12 stores an OS (Operating System) and various programs executed by the modification device 10.
  • the storage unit 12 stores replacement candidate syntax information 121.
  • the replacement candidate syntax information 121 is a set of syntaxes of regular expressions to be replaced with range characters or holes in regular expressions or templates.
  • the replacement candidate syntax information 121 is " ⁇ , ⁇
  • " ⁇ " is a hole. The holes and templates will be described later.
  • the control unit 13 controls the entire correction device 10.
  • the control unit 13 includes, for example, electronic circuits such as a CPU (Central Processing Unit), an MPU (Micro Processing Unit), and a GPU (Graphics Processing Unit), an ASIC (Application Specific Integrated Circuit), and an FPGA (Field Programmable Gate). Array) etc. It is an integrated circuit.
  • control unit 13 has an internal memory for storing programs and control data that define various processing procedures, and executes each process using the internal memory. Further, the control unit 13 functions as various processing units by running various programs. For example, the control unit 13 includes a generation unit 131 and a synthesis unit 132.
  • the generation unit 131 generates Positive Examples, which is a set of character strings accepted by the regular expression before modification, and Negative Examples, which is a set of character strings rejected by the regular expression before modification.
  • Positive Examples is an example of the first set.
  • Negative Examples is an example of the second set.
  • regular expression before modification is an example of the first regular expression.
  • FIG. 3 is a diagram showing examples of Positive Examples and Negative Examples.
  • the generation unit 131 enumerates all character strings that are combinations of characters of a certain length or less, and if each character string is accepted by the regular expression, it is classified as Positive Examples, and if it is rejected, it is classified as Negative Examples. can. Note that the generation unit 131 may generate Positive Examples and Negative Examples using the method described in Non-Patent Document 1.
  • the generation unit 131 may generate the Positive Examples string and the Negative Examples string only from the characters appearing in the regular expression before modification.
  • the generation unit 131 For example, if the regular expression is "ab[c-d]*", the generation unit 131 generates a candidate by combining "a” and “b” and one character randomly selected from "[c,d]”. Generates a string.
  • FIG. 4 is a diagram illustrating a method of generating a set of character strings.
  • the regular expression before modification is ".*.*@example[.]com”.
  • the generation unit 131 generates character strings “@example.com”, “a@example.com”, and “gc@example.com” that are accepted by the regular expression ".*.*@example[.]com”. Classify as Positive Examples.
  • the generation unit 131 generates character strings such as "example.com”, “@.com”, “@examplecom”, “@example.”, etc. that are rejected by the regular expression ".*.*@example[.]com”. Classify as Negative Examples.
  • the synthesis unit 132 is a regular expression that replaces the range characters in the regular expression before modification with a predetermined syntax, and is a regular expression that accepts the string of Positive Examples and rejects the string of Negative Examples. Compose the modified regular expression. Note that the modified regular expression is an example of the second regular expression.
  • the processing by the synthesis unit 132 is broadly divided into a step of creating a template and a step of assigning to the template.
  • the synthesis unit 132 creates a template by replacing range characters in the regular expression with placeholders.
  • the synthesis unit 132 assigns a predetermined syntax to the placeholder and synthesizes a non-fragile regular expression.
  • the placeholder will be referred to as a hole and will be written as " ⁇ ".
  • the synthesis unit 132 performs processing while holding the priority queue. Templates stored in the queue are given priority according to their proximity to the regular expression before modification. For example, a template that is closer to the regular expression before modification is given a higher priority. Further, the closeness to the regular expression may be expressed by the sum of the sizes of different subtrees between ASTs (Abstract Syntax Trees) of the regular expression (for example, see Non-Patent Document 1).
  • the synthesis unit 132 When extracting elements from the queue, the synthesis unit 132 preferentially extracts the one with the highest priority among the stored templates. At the start of the process, the synthesis unit 132 stores the unmodified regular expression in a queue as a template. Note that the regular expression stored in the queue before modification necessarily has the highest priority.
  • the synthesis unit 132 When the template extracted from the queue includes a range character, the synthesis unit 132 replaces the range character included in the template with a hole. Note that the range character is expressed, for example, as "[C]" or ".”. On the other hand, if the template extracted from the queue includes a hole, the synthesis unit 132 may replace any one of the holes with a predetermined syntax.
  • the synthesis unit 132 replaces at least some of the range characters in the regular expression before modification with holes, and synthesizes the regular expression after modification based on the template in which the replaced holes are further replaced with a predetermined syntax. do.
  • the synthesis unit 132 converts holes into “ ⁇ ”, “ ⁇
  • the synthesis unit 132 converts the holes included in the template into predetermined syntaxes including holes such as " ⁇ ", “ ⁇
  • the step of assigning to templates executed by the synthesis unit 132 will be described.
  • the synthesis unit 132 searches for assignment of range characters that satisfy the conditions to the holes included in the template. For example, the synthesis unit 132 performs the search using a Satisfiability Modulo Theories (SMT) solver (for example, Z3 solver).
  • SMT Satisfiability Modulo Theories
  • a regular expression that operates in linear time on a regular expression engine with respect to the length of a character string to be matched is referred to as a non-fragile regular expression.
  • regular expressions that operate in exponential time on a regular expression engine, depending on the length of the string to be matched are called weak regular expressions.
  • the synthesis of non-weak regular expressions by the synthesis unit 132 is based on the strongly one-unambiguous method devised by Koch and Scherzinger et al. (Reference: Christoph Koch and Stefanie Scherzinger. 2007. Attribute Grammars for Scalable Query Processing on XML). Streams. The VLDB Journal 16 , 3 (July 2007), 317-342.), which has been improved to suit the expansion of the real world.
  • Strongly one-unambiguous means that the next operation to be processed by the regular expression engine is uniquely determined once the character currently being analyzed is determined.
  • FIG. 6 is a flowchart showing the process flow of the correction device according to the first embodiment.
  • the modification device 10 receives input of a regular expression (step S10).
  • the modification device 10 generates a set of character strings (Positive Examples) that are accepted according to the input regular expression (Step S20). Furthermore, the modification device 10 generates a set of character strings (Negative Examples) that are rejected by the input regular expression (step S30).
  • the modification device 10 can create an extended automaton from the input regular expression before modification, and generate a set of character strings to cover all the paths of the extended automaton.
  • the modification device 10 generates (synthesizes) a regular expression based on the input regular expression, accepted character strings, and rejected character strings (step S40). Then, the modification device 10 outputs the generated regular expression (step S50).
  • FIG. 7 is a flowchart showing the flow of regular expression synthesis processing.
  • the process in FIG. 7 corresponds to step S40 in FIG.
  • the modification device 10 stores the input regular expression in a queue as a template (step S401).
  • the modification device 10 obtains the template closest to the input regular expression from the queue (step S402).
  • the modification device 10 searches for an assignment of range characters to holes such that the modification device 10 accepts the accepted character strings, rejects the rejected character strings, and satisfies the conditions regarding the vulnerability. (Step S403).
  • the modification device 10 determines whether or not the search result assignment exists (step S404). If the search result assignment does not exist (step S404, No), the modification device 10 replaces the range characters with holes or replaces the holes with a predetermined pattern (step S405).
  • the predetermined patterns are, for example, " ⁇ ”, “ ⁇
  • the modification device 10 stores the template processed in step S405 in a queue (step S406).
  • the processed template here is a template in which range characters are replaced with holes, or a template in which holes are replaced with a predetermined pattern.
  • step S404 if the search result assignment exists (step S404, Yes), the modification device 10 synthesizes a non-fragile regular expression based on the search result assignment (step S407).
  • the generation unit 131 of the correction device 10 generates a first set of character strings that are accepted by the first regular expression, and a first set of character strings that are rejected by the first regular expression.
  • a second set is generated which is a set of .
  • the synthesis unit 132 generates a regular expression in which the range characters in the first regular expression are replaced with a predetermined syntax, and which accepts the strings in the first set and rejects the strings in the second set.
  • a second regular expression, which is a regular expression is synthesized.
  • the modification device 10 performs modification including syntax such as lookahead, lookbehind, and backward reference, which are extensions widely used in the real world. Therefore, according to this embodiment, vulnerabilities in regular expressions used in the real world can be corrected.
  • the generation unit 131 generates a first set of character strings and a second set of character strings from only the characters appearing in the first regular expression.
  • the modification device 10 can efficiently create a set of character strings accepted by the input regular expression (Positive Examples) and a set of character strings rejected by the input regular expression (Negative Examples). can.
  • the synthesis unit 132 replaces at least some of the range characters in the first regular expression with placeholders, and synthesizes a second regular expression based on the template in which the replaced placeholders are further replaced with a predetermined syntax. do.
  • the modification device 10 can eliminate vulnerabilities with the minimum number of replacements.
  • the synthesis unit 132 converts the placeholders included in the template into predetermined syntax including placeholders such as " ⁇ ”, “ ⁇
  • a second regular expression is synthesized based on the first regular expression. Thereby, the modification device 10 can replace the portion of the regular expression that causes vulnerability with a syntax that is free of vulnerability.
  • FIG. 8 is a diagram showing an example of the configuration of the verification device according to the first embodiment.
  • the verification device 20 receives input of a regular expression, and outputs a result of verifying whether the vulnerability of the input regular expression has been corrected.
  • the regular expression input to the verification device 20 does not necessarily follow Backus-Naur notation. Further, it is assumed that it is unknown whether the regular expression input to the verification device 20 has been modified by the modification device 10 or not.
  • the verification device 20 includes an interface section 21, a storage section 22, and a control section 23.
  • the interface unit 21 is an interface for data input/output and data communication.
  • the interface unit 21 accepts data input from input devices such as a keyboard and a mouse. Further, for example, the interface unit 21 outputs data to an output device such as a display and a speaker.
  • the interface unit 21 may be a device (for example, NIC) for communicating via a network.
  • NIC a device for example, NIC
  • the storage unit 22 is a storage device such as an HDD, SSD, or optical disk. Note that the storage unit 22 may be a data-rewritable semiconductor memory such as a RAM, a flash memory, or an NVSRAM.
  • the storage unit 22 stores the OS and various programs executed by the verification device 20.
  • the control unit 23 controls the entire verification device 20.
  • the control unit 23 is, for example, an electronic circuit such as a CPU, MPU, or GPU, or an integrated circuit such as an ASIC or FPGA.
  • control unit 23 has an internal memory for storing programs and control data that define various processing procedures, and executes each process using the internal memory. Further, the control unit 23 functions as various processing units by running various programs. For example, the control unit 23 includes a first determination unit 231 and a second determination unit 232.
  • the first determination unit 231 determines whether the regular expression follows a prespecified syntax. Further, the second determination unit 232 determines whether a condition indicating that the processing time when a regular expression is used to analyze a character string is linear with respect to the length of the character string is satisfied.
  • the verification by the verification device 20 is realized by two-stage determination by the first determination unit 231 and the second determination unit 232. Furthermore, the first determination unit 231 performs a simpler test than the second determination unit 232.
  • the verification device 20 determines that the vulnerability of the regular expression has been fixed (or it is highly likely that it has been corrected).
  • the verification device 20 detects the vulnerability of the regular expression. outputs a verification result that the nature is not corrected (or there is a high possibility that it is not corrected).
  • the first determination unit 231 determines whether the input regular expression is composed of the operators shown in FIG. 2. In this case, the first determination unit 231 can be said to determine whether the regular expression conforms to the regular expression syntax based on Backus-Naur notation.
  • the first determination unit 231 can perform the determination using a known syntax analyzer such as ANTLR (ANother Tool for Language Recognition) (reference document: https://www.antlr.org/).
  • ANTLR ANother Tool for Language Recognition
  • the second determination unit 232 uses the regular expression RWS1U (Reference: "Repairing DoS Vulnerability of Real-World Regexes", https://www.computer.org/csdl/proceedings-article/sp/2022/131600b049/1A4Q3TnrBZK ), it is determined that the condition is satisfied.
  • RWS1U ensures that the processing time when a regular expression parses a string is linear with the length of the string.
  • FIG. 9 is a diagram illustrating a method for determining RWS1U.
  • the second determination unit 232 removes prefetch from the input regular expression (step S1).
  • the second determination unit 232 removes the prefetch by replacing it with a blank character ⁇ .
  • the second determination unit 232 performs bracketing on the regular expression from which look-ahead has been removed (step S2). Specifically, the second determination unit 232 converts the regular expression into a syntactic analysis tree (AST), assigns a unique number i to each vertex of the syntactic analysis tree, and encloses it in brackets "[ i ...] i ". Then convert the parse tree back to a regular expression.
  • AST syntactic analysis tree
  • FIG. 10 is a diagram illustrating a parse tree.
  • the second determination unit 232 converts the regular expression "[abc]* ⁇ 1" from which look-ahead has been removed into a parse tree, and surrounds each vertex with brackets. Then, the second determination unit 232 returns the parse tree to the regular expression "[ 1 [ 2 ([ 3 abc] 3 )*] 2 [ 4 ⁇ 1] 4 ] 1 ".
  • the second determination unit 232 constructs a nondeterministic finite automaton (NFA) from the regular expression with added brackets using a method that extends the Thompson construction method (step S3).
  • NFA nondeterministic finite automaton
  • the second determination unit 232 checks whether there is a vertex on the NFA where there are multiple different paths that can reach the same character through only brackets and ⁇ transitions (empty character transitions). . If such a vertex exists, the second determination unit 232 determines that the regular expression does not satisfy RWS1U.
  • FIG. 11 is a diagram showing an example of a path.
  • the second determination unit 232 converts the regular expression with the look-ahead removed and the brackets added into a non-deterministic finite automaton, and converts the regular expression into a non-deterministic finite automaton by passing only the transition between the brackets and the empty string. If there are no vertices for which there are different paths that can reach the character, it is determined that the condition is satisfied.
  • FIG. 12 is a flowchart showing the process flow of the verification device according to the first embodiment. As shown in FIG. 12, first, the verification device 20 receives input of a regular expression (step S11).
  • the verification device 20 performs a simple check on the input regular expression (step S12).
  • the simple test corresponds to determination processing by the first determination unit 231.
  • step S13 the verification device 20 outputs that the vulnerability of the regular expression has not been fixed (step S17). For example, if the input regular expression does not follow the regular expression syntax based on Backus-Naur notation, the verification device 20 determines No in step S13, and otherwise determines Yes in step S13.
  • the verification device 20 performs the RWS1U check (Step S14).
  • the RWS1U inspection corresponds to determination processing by the second determination unit 232.
  • the verification device 20 outputs that the vulnerability of the regular expression has not been corrected (Step S17). For example, if there is a vertex with multiple paths that reach the same character as shown in FIG. 11, the verification device 20 determines No in step S15, and otherwise determines Yes in step S15.
  • Step S15 if the regular expression satisfies RWS1U (Step S15, Yes), the verification device 20 outputs that the vulnerability of the regular expression has been corrected (Step S16).
  • FIG. 13 is a flowchart showing the flow of RWS1U inspection processing.
  • the verification device 20 performs prefetch removal of the regular expression (step S141).
  • the verification device 20 performs syntax analysis and bracketing of the regular expression with the look-ahead removed (step S142).
  • the verification device 20 constructs an NFA from the parse tree (step S143).
  • the verification device 20 determines whether a specific path exists on the NFA (step S144). For example, a particular path is a plurality of different paths that can reach the same character from a certain vertex.
  • step S144 If the specific path exists (step S144, Yes), the verification device 20 determines that the regular expression does not satisfy RWS1U (step S145).
  • step S146 determines that the regular expression satisfies RWS1U (step S146).
  • the first determination unit 231 of the verification device 20 determines whether the regular expression follows a prespecified syntax. Further, the second determination unit 232 determines whether a condition indicating that the processing time when a regular expression is used to analyze a character string is linear with respect to the length of the character string is satisfied. This allows you to verify whether the regular expression vulnerability has been fixed.
  • the second determination unit 232 determines that the condition is satisfied if the regular expression satisfies RWS1U. For example, the second determination unit 232 converts the regular expression that has removed look-ahead and added brackets into a non-deterministic finite automaton, and converts the same character into a non-deterministic finite automaton by passing only the bracket and empty character transitions. If there are no vertices for which different reachable paths exist, it is determined that the condition is satisfied.
  • the modification system includes a modification device 10 and a verification device 20.
  • the verification device 20 includes a first determination unit 231 that determines whether the first regular expression follows a prespecified syntax, and a processing time when the first regular expression analyzes a character string. and a second determination unit 232 that determines whether a condition indicating that the length is linear with respect to the length of is satisfied. If the first determining unit 231 determines that the first regular expression does not follow the specified syntax, or the first determining unit 231 determines that the first regular expression follows the specified syntax.
  • the first regular expression is not accepted.
  • a generation unit 131 that generates a first set of character strings rejected by the first regular expression, and a second set of character strings rejected by the first regular expression;
  • a synthesis unit that synthesizes a second regular expression that is a regular expression substituted with a predetermined syntax and that accepts character strings in the first set and rejects character strings in the second set; 132.
  • each component of each device shown in the drawings is functionally conceptual, and does not necessarily need to be physically configured as shown in the drawings.
  • the specific form of distributing and integrating each device is not limited to what is shown in the diagram, and all or part of the devices may be functionally or physically distributed or integrated in arbitrary units depending on various loads and usage conditions. Can be integrated and configured.
  • each processing function performed by each device is realized in whole or in part by a CPU (Central Processing Unit) and a program that is analyzed and executed by the CPU, or by hardware using wired logic. It can be realized as Note that the program may be executed not only by the CPU but also by another processor such as a GPU.
  • a CPU Central Processing Unit
  • the verification device 20 can be implemented by installing a verification program that executes the above verification process on a desired computer as packaged software or online software. For example, by causing the information processing device to execute the above verification program, the information processing device can be made to function as the verification device 20.
  • the information processing device referred to here includes a desktop or notebook personal computer.
  • information processing devices include mobile communication terminals such as smartphones, mobile phones, and PHSs (Personal Handyphone Systems), as well as slate terminals such as PDAs (Personal Digital Assistants).
  • the verification device 20 can also be implemented as a verification server device that uses a terminal device used by a user as a client and provides services related to the above verification process to the client.
  • the verification server device is implemented as a server device that provides a verification service that receives regular expressions as input and outputs verification results indicating whether vulnerabilities in the regular expression have been fixed.
  • the verification server device may be implemented as a web server, or may be implemented as a cloud that provides services related to the above-mentioned verification processing through outsourcing.
  • FIG. 14 is a diagram showing an example of a computer that executes the verification program.
  • Computer 1000 includes, for example, a memory 1010 and a CPU 1020.
  • the computer 1000 also includes a hard disk drive interface 1030, a disk drive interface 1040, a serial port interface 1050, a video adapter 1060, and a network interface 1070. These parts are connected by a bus 1080.
  • the memory 1010 includes a ROM (Read Only Memory) 1011 and a RAM (Random Access Memory) 1012.
  • the ROM 1011 stores, for example, a boot program such as BIOS (Basic Input Output System).
  • Hard disk drive interface 1030 is connected to hard disk drive 1090.
  • Disk drive interface 1040 is connected to disk drive 1100.
  • Serial port interface 1050 is connected to, for example, mouse 1110 and keyboard 1120.
  • Video adapter 1060 is connected to display 1130, for example.
  • the hard disk drive 1090 stores, for example, an OS 1091, an application program 1092, a program module 1093, and program data 1094. That is, a program that defines each process of the verification device 20 is implemented as a program module 1093 in which computer-executable code is written.
  • Program module 1093 is stored in hard disk drive 1090, for example.
  • a program module 1093 for executing processing similar to the functional configuration of the verification device 20 is stored in the hard disk drive 1090.
  • the hard disk drive 1090 may be replaced by an SSD (Solid State Drive).
  • the setting data used in the processing of the embodiment described above is stored as program data 1094 in, for example, the memory 1010 or the hard disk drive 1090. Then, the CPU 1020 reads out the program module 1093 and program data 1094 stored in the memory 1010 and the hard disk drive 1090 to the RAM 1012 as necessary, and executes the processing of the embodiment described above.
  • program module 1093 and the program data 1094 are not limited to being stored in the hard disk drive 1090, but may be stored in a removable storage medium, for example, and read by the CPU 1020 via the disk drive 1100 or the like.
  • the program module 1093 and the program data 1094 may be stored in another computer connected via a network (LAN (Local Area Network), WAN (Wide Area Network), etc.). The program module 1093 and program data 1094 may then be read by the CPU 1020 from another computer via the network interface 1070.
  • LAN Local Area Network
  • WAN Wide Area Network

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Hardware Design (AREA)
  • General Engineering & Computer Science (AREA)
  • Computer Security & Cryptography (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Document Processing Apparatus (AREA)

Abstract

実施形態に係る検証装置は、第1の判定部と、第2の判定部と、を有する。第1の判定部は、正規表現があらかじめ指定された構文(例えば、バッカスナウア記法による正規表現の構文)に従うか否かを判定する。第2の判定部は、正規表現が文字列を解析するときの処理時間が、文字列の長さに対して線形であることを示す条件(例えば、RWS1U(real-world strong 1-unambiguity))が満たされるか否かを判定する。

Description

検証装置、検証方法及び検証プログラム
 本発明は、検証装置、検証方法及び検証プログラムに関する。
 実世界において正規表現は正規表現エンジンとして実装され、様々な場面で利用されている。例えば、正規表現エンジンは、emailアドレスを入力する画面を持つウェブアプリケーションにおいて、ユーザが入力した文字列がemailアドレスかどうかを確認するために用いられている。また、例えば、正規表現エンジンは、外部から送られてきたデータのサニタイズや要素の抽出、汎用的なプログラミング言語の標準ライブラリ等に採用されている。
 ここで、多くの正規表現エンジンに採用されているバックトラッキング法に基づいた解析アルゴリズムは、解析対象のデータと正規表現の組み合わせによっては処理に膨大な時間を要するという欠点がある。そのような欠点を悪用したサイバー攻撃としてRegular Expression Denial of Service(ReDoS)が知られている(参考文献:"Regular expression Denial of Service - ReDoS", https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS)。
 なお、マッチさせる文字列の長さに対して、正規表現エンジン上で線形時間で動作するような正規表現を脆弱でない正規表現と呼ぶものとする。逆に、マッチさせる文字列の長さに対して、正規表現エンジン上で例えば指数関数時間で動作するような正規表現を脆弱な正規表現と呼ぶものとする。
 従来、ReDoSの脅威を取り除くための技術として、正規表現の受理する言語の誤りを修正するRFixer(例えば、非特許文献1を参照)が知られている。また、純粋な正規表現を決定性有限オートマトン(Deterministic Finite Automaton)に一度変換して戻すことで脆弱でない正規表現を得る方法(例えば、非特許文献2を参照)が知られている。
Rong Pan, Qinheping Hu, Gaowei Xu, and Loris D’Antoni. 2019. Automatic Repair of Regular Expressions. Proc. ACM Program. Lang. 3, OOPSLA, Article 139 (Oct. 2019), 29 pages. Brink van der Merwe, Nicolaas Weideman, and Martin Berglund. 2017. Turning Evil Regexes Harmless. In Proceedings of the South African Institute of Computer Scientists and Information Technologists (SAICSIT’17). Association for Computing Machinery, New York, NY, USA, Article 38, 10 pages.
 しかしながら、従来の技術には、正規表現の脆弱性が修正済みであることの確からしさを検証することができない場合があるという問題がある。
 上述した課題を解決し、目的を達成するために、検証装置は、正規表現があらかじめ指定された構文に従うか否かを判定する第1の判定部と、前記正規表現が文字列を解析するときの処理時間が、前記文字列の長さに対して線形であることを示す条件が満たされるか否かを判定する第2の判定部と、を有することを特徴とする。
 本発明によれば、正規表現の脆弱性が修正済みであることの確からしさを検証することができる。
図1は、第1の実施形態に係る修正装置の構成例を示す図である。 図2は、正規表現の構文の例を示す図である。 図3は、Positive ExamplesとNegative Examplesの例を示す図である。 図4は、文字列の集合の生成方法を説明する図である。 図5は、正規表現の合成方法を説明する図である。 図6は、第1の実施形態に係る修正装置の処理の流れを示すフローチャートである。 図7は、正規表現の合成処理の流れを示すフローチャートである。 図8は、第1の実施形態に係る検証装置の構成例を示す図である。 図9は、RWS1Uの判定方法を説明する図である。 図10は、構文解析木を説明する図である。 図11は、パスの例を示す図である。 図12は、第1の実施形態に係る検証装置の処理の流れを示すフローチャートである。 図13は、RWS1U検査処理の流れを示すフローチャートである。 図14は、検証プログラムを実行するコンピュータの一例を示す図である。
 以下に、本願に係る検証装置、検証方法及び検証プログラムの実施形態を図面に基づいて詳細に説明する。なお、本発明は、以下に説明する実施形態により限定されるものではない。
[第1の実施形態の修正装置]
 まず、正規表現の脆弱性を修正する修正装置について説明する。検証装置は、正規表現が修正装置によって修正済みであることの確からしさを検証する。
 例えば、検証装置による検証結果が、正規表現の脆弱性が修正済みでない可能性が高いことを示している場合、当該正規表現は修正装置による修正の対象とされる。
 一方、例えば、検証装置による検証結果が、正規表現の脆弱性が修正済みである可能性が高いことを示している場合、当該正規表現の修正装置による修正は不要と判断される。
 実施形態では、修正装置と検証装置は別の装置であるものとする。ただし、検証装置は、修正装置の機能の一部として実現されてもよい。
 まず、図1を用いて、第1の実施形態に係る修正装置の構成について説明する。図1は、第1の実施形態に係る修正装置の構成の一例を示す図である。図1に示すように、修正装置10は、修正前の正規表現の入力を受け付け、入力された正規表現の修正を行い、修正後の正規表現を出力する。
 ここで、修正装置10に入力される正規表現は、実世界の拡張を施した正規表現であって、バッカスナウア記法(BNF:Backus-Naur form)で定義された構文に従うものとする。図2は、正規表現の構文の例を示す図である。図2の正規表現rは、本実施形態における正規表現の一例である。なお、以降の説明において、正規表現中の「\」は適宜バックスラッシュに置き換えられてもよい。
 図2の「C」は文字の集合であり、「x」は文字列、「i」は自然数である。図2の構文は既存の正規表現エンジンで利用されているものである(参考文献:"Perldoc Browser", https://perldoc.perl.org/perlre.html)。
 また、「.」は任意の1文字を表す記号である。つまり、「.」は図2の範囲文字「[C]」と糖衣構文である。また、範囲文字「[C]」にマッチしない文字の集合は、「[^C]」と書ける。また、空集合は「[]」と表記され、任意の文字にマッチしないことを意味する。
 図1に戻り、修正装置10の各部について説明する。図1に示すように、修正装置10は、インタフェース部11、記憶部12及び制御部13を有する。
 インタフェース部11は、データの入出力及びデータの通信を行うためのインタフェースである。例えば、インタフェース部11は、キーボード及びマウス等の入力装置からデータの入力を受け付ける。また、例えば、インタフェース部11は、ディスプレイ及びスピーカ等の出力装置にデータを出力する。
 また、インタフェース部11は、ネットワークを介して通信を行うための装置(例えばNIC(Network Interface Card))であってもよい。
 記憶部12は、HDD(Hard Disk Drive)、SSD(Solid State Drive)、光ディスク等の記憶装置である。なお、記憶部12は、RAM(Random Access Memory)、フラッシュメモリ、NVSRAM(Non Volatile Static Random Access Memory)等のデータを書き換え可能な半導体メモリであってもよい。記憶部12は、修正装置10で実行されるOS(Operating System)や各種プログラムを記憶する。
 記憶部12は、置換候補構文情報121を記憶する。置換候補構文情報121は、正規表現又はテンプレートの、範囲文字又はホールと置換される正規表現の構文の集合である。
 例えば、置換候補構文情報121は、「□□, □|□, □*, (□), \i, (?=□), (?!□), (?<=□), (?<!□)」である。ただし、「□」はホールである。ホール及びテンプレートについては後述する。
 制御部13は、修正装置10全体を制御する。制御部13は、例えば、CPU(Central Processing Unit)、MPU(Micro Processing Unit)、GPU(Graphics Processing Unit)等の電子回路や、ASIC(Application Specific Integrated Circuit)、FPGA(Field Programmable Gate Array)等の集積回路である。
 また、制御部13は、各種の処理手順を規定したプログラムや制御データを格納するための内部メモリを有し、内部メモリを用いて各処理を実行する。また、制御部13は、各種のプログラムが動作することにより各種の処理部として機能する。例えば、制御部13は、生成部131及び合成部132を有する。
 生成部131は、修正前の正規表現によって受理される文字列の集合であるPositive Examples、及び、修正前の正規表現によって拒否される文字列の集合であるNegative Examplesを生成する。
 なお、Positive Examplesは第1の集合の一例である。また、Negative Examplesは第2の集合の一例である。また、修正前の正規表現は第1の正規表現の一例である。
 図3は、Positive ExamplesとNegative Examplesの例を示す図である。ここでは、修正前の正規表現が「.*.*=.*」であるものとする。このとき、Positive Examplesに含まれる「=」、「abcd==」、「==abcd」及び「ab=c」は正規表現「.*.*=.*」にマッチする(受理される)。一方、Negative Examplesに含まれる「abc」は正規表現「.*.*=.*」にマッチしない(拒否される)。
 生成部131は、特定の長さ以下の文字を組み合わせた文字列を全列挙し、各文字列が正規表現に受理されるならPositive Examplesに分類し、拒否されるならNegative Examplesに分類することができる。なお、生成部131は、非特許文献1に記載の方法を用いてPositive ExamplesとNegative Examplesを生成してもよい。
 ここで、文字列を素直に全列挙すると、爆発的に例が生成されてしまう。これを回避するために、生成部131は、修正前の正規表現の中に現れる文字のみからPositive Examplesの文字列及びNegative Examplesの文字列を生成してもよい。
 例えば、正規表現が「ab[c-d]*」である場合、生成部131は、「a」及び「b」と、「[c,d]」からランダムに選択した1文字と、を組み合わせて候補の文字列を生成する。
 図4は、文字列の集合の生成方法を説明する図である。図4の例では、修正前の正規表現は「.*.*@example[.]com」である。この場合、生成部131は、正規表現「.*.*@example[.]com」によって受理される文字列「@example.com」、「a@example.com」、「gc@example.com」をPositive Examplesに分類する。一方、生成部131は、正規表現「.*.*@example[.]com」によって拒否される文字列「example.com」、「@.com」、「@examplecom」、「@example.」等をNegative Examplesに分類する。
 合成部132は、修正前の正規表現における範囲文字を所定の構文に置換した正規表現であって、Positive Examplesの文字列を受理し、かつNegative Examplesの文字列を拒否するような正規表現である修正後の正規表現を合成する。なお、修正後の正規表現は第2の正規表現の一例である。
 合成部132による処理は大きく、テンプレートを作成するステップと、テンプレートへの割り当てを行うステップと、に分けられる。
 テンプレートを作成するステップでは、合成部132は、正規表現における範囲文字をプレースホルダを使って置換することによりテンプレートを作成する。
 テンプレートへの割り当てを行うステップでは、合成部132は、プレースホルダへ所定の構文を割り当てて、脆弱でない正規表現を合成する。以降、プレースホルダをホールと呼び、「□」と表記する。
 合成部132は、優先度付きキューを保持しつつ処理を行う。キューに格納されたテンプレートには、修正前の正規表現への近さに応じて優先度が付与される。例えば、修正前の正規表現に近いテンプレートほど高い優先度が付与される。また、正規表現への近さは、正規表現のAST(Abstract Syntax Tree)間の違う部分木のサイズの総和によって表されてもよい(例えば、非特許文献1を参照)。
 合成部132は、キューから要素を取り出す際には、格納されているテンプレートのうち優先度が最も高いものを優先して取り出す。処理の開始時点では、合成部132は、修正前の正規表現をテンプレートとしてキューに格納する。なお、キューに格納された修正前の正規表現の優先度は必然的に最高になる。
 まず、合成部132によって実行されるテンプレートを作成するステップについて説明する。合成部132は、キューから取り出したテンプレートが範囲文字を含む場合、当該テンプレートに含まれる当該範囲文字をホールに置換する。なお、範囲文字は、例えば「[C]」又は「.」のように表される。一方、合成部132は、キューから取り出したテンプレートがホールを含む場合、当該ホールのうちいずれか1つを、所定の構文に置換してもよい。
 例えば、合成部132は、テンプレートとしてキューに格納されている修正前の正規表現「.*.*=.*」の範囲文字を置換したテンプレート「□*.*=.*」、「.*□*=.*」「.*.*=□*」を作成し、キューに格納する。なお、一度取り出されたテンプレートは破棄されるものとする。
 このように、合成部132は、修正前の正規表現における範囲文字の少なくとも一部をホールに置換し、当該置換したホールをさらに所定の構文に置換したテンプレートを基に修正後の正規表現を合成する。
 さらに、合成部132は、ホールを、置換候補構文情報121に含まれる「□□」、「□|□」、「□*」、「(□)」、「\i」、「(?=□)」、「(?!□)」、「(?<=□)」、「(?<!□)」といった構文に置換することができる。この場合、合成部132は、テンプレートに含まれるホールを、ホールを含む所定の構文である「□□」、「□|□」、「□*」、「(□)」、「\i」、「(?=□)」、「(?!□)」、「(?<=□)」、「(?<!□)」のいずれかに置換したテンプレート(ただし、□はホール)を基に修正後の正規表現を合成する。
 続いて、合成部132によって実行されるテンプレートへの割り当てを行うステップについて説明する。ここでは、合成部132がテンプレートを作成するステップを繰り返し、例えばテンプレート「□*□*=.*」を作成しキューに格納したものとする。例えば、合成部132は、テンプレート「□*.*=.*」の左辺の範囲文字「.」をホールに置換することでテンプレート「□*□*=.*」を得る。
 合成部132は、テンプレートが含むホールに対する、条件を満たす範囲文字の割り当てを探索する。例えば、合成部132は、Satisfiability Modulo Theories(SMT) solver(例えば、Z3 solver)等を用いて探索を行う。
 合成部132は、テンプレートが「□*□*=.*」であり、Positive Examples及びNegative Examplesが図3の通りであれば、「[]*[^=]*=.*」という割り当てを探索により得ることができる。合成部132は、空集合である「[]」を取り除き、正規表現「[^=]*=.*」を得る。
 正規表現「[^=]*=.*」は、図3のPositive Examplesを受理し、Negative Examplesを拒否する。また、正規表現「[^=]*=.*」は、同じ文字にマッチする箇所を高々1つしか含まないため、脆弱でない性質を持っているということができる。
 本実施形態では、前述の通り、マッチさせる文字列の長さに対して、正規表現エンジン上で線形時間で動作するような正規表現を脆弱でない正規表現と呼ぶ。逆に、マッチさせる文字列の長さに対して、正規表現エンジン上で例えば指数関数時間で動作するような正規表現を脆弱な正規表現と呼ぶ。
 合成部132による脆弱でない正規表現の合成は、KochとScherzingerらにより考案されたstrongly one-unambiguous(参考文献:Christoph Koch and Stefanie Scherzinger. 2007. Attribute Grammars for Scalable Query Processing on XML Streams. The VLDB Journal 16, 3 (July 2007), 317-342.)という性質を実世界の拡張にも合わせて改良した性質を用いたものである。
 Strongly one-unambiguousとは、正規表現エンジンが次に処理する演算は現在解析中の文字が何か定まれば一意に定まるという性質である。
 同様に、修正前の正規表現が「.*.*@example[.]com」である場合、図5に示すように、合成部132は、脆弱でない正規表現「[^@]*@example[.]com」を得ることができる。
[修正装置の処理の流れ]
 図6は、第1の実施形態に係る修正装置の処理の流れを示すフローチャートである。まず、修正装置10は、正規表現の入力を受け付ける(ステップS10)。
 次に、修正装置10は、入力された正規表現によって受理される文字列の集合(Positive Examples)を生成する(ステップS20)。また、修正装置10は、入力された正規表現によって拒否される文字列の集合(Negative Examples)を生成する(ステップS30)。
 例えば、修正装置10は、入力された修正前の正規表現から拡張オートマトンを作成し、当該拡張オートマトンのパスを全てカバーするように文字列の集合を生成することができる。
 続いて、修正装置10は、入力された正規表現、受理される文字列及び拒否される文字列を基に正規表現を生成(合成)する(ステップS40)。そして、修正装置10は、生成した正規表現を出力する(ステップS50)。
 図7は、正規表現の合成処理の流れを示すフローチャートである。図7の処理は、図6のステップS40に相当する。まず、修正装置10は、入力された正規表現を、テンプレートとしてキューに格納する(ステップS401)。
 次に、修正装置10は、入力された正規表現に最も近いテンプレートをキューから取得する(ステップS402)。
 続いて、修正装置10は、修正装置10は、受理される文字列を受理し、拒否される文字列を拒否し、かつ脆弱性に関する条件を満たすような、ホールへの範囲文字の割り当てを探索する(ステップS403)。
 修正装置10は、探索結果の割り当てが存在するか否かを判定する(ステップS404)。探索結果の割り当てが存在しない場合(ステップS404、No)、修正装置10は、範囲文字をホールに置換するか、又はホールを所定のパターンに置換する(ステップS405)。所定のパターンは、例えば「□□」、「□|□」、「□*」、「(□)」、「\i」、「(?=□)」、「(?!□)」、「(?<=□)」、「(?<!□)」といった構文である。なお、ステップS401でキューに格納された、入力された正規表現がステップS403での探索の対象となった場合、ステップS404では割り当てが存在しないもの(No)とみなされる。
 そして、修正装置10は、ステップS405で処理済みのテンプレートをキューに格納する(ステップS406)。ここでの処理済みのテンプレートは、範囲文字がホールに置換されたテンプレート、又はホールが所定のパターンに置換されたテンプレートである。
 一方、探索結果の割り当てが存在する場合(ステップS404、Yes)、修正装置10は、探索結果の割り当てを基に脆弱でない正規表現を合成する(ステップS407)。
[修正装置による効果]
 これまで説明してきたように、修正装置10の生成部131は、第1の正規表現によって受理される文字列の集合である第1の集合、及び、第1の正規表現によって拒否される文字列の集合である第2の集合を生成する。合成部132は、第1の正規表現における範囲文字を所定の構文に置換した正規表現であって、第1の集合の文字列を受理し、かつ第2の集合の文字列を拒否するような正規表現である第2の正規表現を合成する。このように、修正装置10は、実世界で広く利用されている拡張である先読み、後読み及び後方参照といった構文を含めた修正を行う。このため、本実施形態によれば、実世界で利用されている正規表現の脆弱性を修正することができる。
 さらに、本実施形態によれば、Webサービス等で利用される正規表現に対して脆弱でないことを保証できるようになり、ReDoSの脅威からサービスを守ることができるようになる。
 また、生成部131は、第1の正規表現の中に現れる文字のみから、第1の集合の文字列及び第2の集合の文字列を生成する。これにより、修正装置10は、入力された正規表現によって受理される文字列の集合(Positive Examples)及び入力された正規表現によって拒否される文字列の集合(Negative Examples)を効率良く作成することができる。
 また、合成部132は、第1の正規表現における範囲文字の少なくとも一部をプレースホルダに置換し、当該置換したプレースホルダをさらに所定の構文に置換したテンプレートを基に第2の正規表現を合成する。これにより、修正装置10は、最低限の置換により脆弱性を解消することができる。
 また、合成部132は、テンプレートに含まれるプレースホルダを、プレースホルダを含む所定の構文である「□□」、「□|□」、「□*」、「(□)」、「\i」、「(?=□)」、「(?!□)」、「(?<=□)」、「(?<!□)」のいずれかに置換したテンプレート(ただし、□はプレースホルダ)を基に第2の正規表現を合成する。これにより、修正装置10は、正規表現において脆弱性の原因になっている部分を、脆弱性のない構文に置換していくことができる。
[第1の実施形態の検証装置]
 続いて、正規表現の脆弱性が修正済みであるか否かを検証する検証装置について説明する。
 まず、図8を用いて、第1の実施形態に係る検証装置の構成について説明する。図8は、第1の実施形態に係る検証装置の構成の一例を示す図である。図8に示すように、検証装置20は、正規表現の入力を受け付け、入力された正規表現の脆弱性が修正済みであるか否かを検証した結果を出力する。
 ここで、検証装置20に入力される正規表現は、バッカスナウア記法に従うとは限らない。また、検証装置20に入力される正規表現が修正装置10によって修正済みであるか否かは未知であるものとする。
 図8に示すように、検証装置20は、インタフェース部21、記憶部22及び制御部23を有する。
 インタフェース部21は、データの入出力及びデータの通信を行うためのインタフェースである。例えば、インタフェース部21は、キーボード及びマウス等の入力装置からデータの入力を受け付ける。また、例えば、インタフェース部21は、ディスプレイ及びスピーカ等の出力装置にデータを出力する。
 また、インタフェース部21は、ネットワークを介して通信を行うための装置(例えばNIC)であってもよい。
 記憶部22は、HDD、SSD、光ディスク等の記憶装置である。なお、記憶部22は、RAM、フラッシュメモリ、NVSRAM等のデータを書き換え可能な半導体メモリであってもよい。記憶部22は、検証装置20で実行されるOSや各種プログラムを記憶する。
 制御部23は、検証装置20全体を制御する。制御部23は、例えば、CPU、MPU、GPU等の電子回路や、ASIC、FPGA等の集積回路である。
 また、制御部23は、各種の処理手順を規定したプログラムや制御データを格納するための内部メモリを有し、内部メモリを用いて各処理を実行する。また、制御部23は、各種のプログラムが動作することにより各種の処理部として機能する。例えば、制御部23は、第1の判定部231及び第2の判定部232を有する。
 第1の判定部231は、正規表現があらかじめ指定された構文に従うか否かを判定する。また、第2の判定部232は、正規表現が文字列を解析するときの処理時間が、文字列の長さに対して線形であることを示す条件が満たされるか否かを判定する。
 つまり、検証装置20による検証は、第1の判定部231と第2の判定部232による2段階の判定によって実現される。また、第1の判定部231は、第2の判定部232と比べて簡易な検査を行う。
 第1の判定部231によって指定された構文に従うと判定され、かつ第2の判定部232によって条件が満たされると判定された場合、検証装置20は、正規表現の脆弱性が修正済みである(又は修正済みである可能性が高い)という検証結果を出力する。
 逆に、第1の判定部231によって指定された構文に従わないと判定された場合、又は第2の判定部232によって条件が満たされないと判定された場合、検証装置20は、正規表現の脆弱性が未修正である(又は未修正である可能性が高い)という検証結果を出力する。
 第1の判定部231は、入力された正規表現が、図2に示す演算子から構成されるものであるか否かを判定する。この場合、第1の判定部231は、正規表現がバッカスナウア記法による正規表現の構文に従うか否かを判定するということができる。
 なお、第1の判定部231は、ANTLR(ANother Tool for Language Recognition)(参考文献:https://www.antlr.org/)等の既知の構文解析器により判定を行うことができる。
 第2の判定部232は、正規表現がRWS1U(参考文献:"Repairing DoS Vulnerability of Real-World Regexes",https://www.computer.org/csdl/proceedings-article/sp/2022/131600b049/1A4Q3TnrBZK)を満たす場合、条件が満たされると判定する。
 RWS1Uは、正規表現が文字列を解析するときの処理時間が、文字列の長さに対して線形であることを保証する。
 正規表現に対して、任意の入力とともに正規表現エンジンに入力されたとしても必ず処理時間が入力長に対して線形になることを保証するための十分条件である。
 図9を用いて、正規表現がRWS1Uを満たすか否かを判定する方法を説明する。図9は、RWS1Uの判定方法を説明する図である。
 まず、図9に示すように、第2の判定部232は、入力された正規表現に対し、先読みの除去を行う(ステップS1)。第2の判定部232は、先読みを空文字εに置換することで除去を行う。
 ここでは、入力された正規表現は、「[abc]*(?=a)\1」であるものとする。また、先読みは、図2に示す肯定先読み「(?=r)」及び否定先読み「(?!r)」を含む。
 次に、第2の判定部232は、先読みを除去した正規表現に対しブラケティングを行う(ステップS2)。具体的には、第2の判定部232は、正規表現を構文解析木(AST)に変換し、構文解析木の各頂点にユニークな番号iを割り振り、ブラケット「[i…]i」で囲んだ上で、構文解析木を正規表現に戻す。
 図10は、構文解析木を説明する図である。図10に示すように、第2の判定部232は、先読みが除去された正規表現「[abc]*\1」を構文解析木に変換し、各頂点をブラケットで囲む。そして、第2の判定部232は、構文解析木を正規表現「[1[2([3abc]3)*]2[4\1]4]1」に戻す。
 そして、第2の判定部232は、Thompson構成法を拡張した手法により、ブラケットを追加した正規表現から非決定性有限オートマトン(NFA:Nondeterministic Finite Automaton)を構築する(ステップS3)。
 ここで、第2の判定部232は、NFA上にブラケットとε遷移(空文字の遷移)のみを通って同じ文字に到達可能な異なる複数のパスが存在するような頂点があるかどうかを確認する。第2の判定部232は、そのような頂点が存在すれば、正規表現がRWS1Uを満たさないと判定する。
 図11は、パスの例を示す図である。図11のNFAは、図9のステップ3で構築されたものである。図11に示すように、左端の頂点から「a」に到達するためのパスが2つ存在する。そのため、第2の判定部232は、正規表現「[abc]*(?=a)\1」がRWS1Uを満たさないと判定する。
 このように、第2の判定部232は、先読みの除去及びブラケットの追加を行った正規表現を、非決定性有限オートマトンに変換し、非決定性有限オートマトン上にブラケットと空文字の遷移のみを通って同じ文字に到達可能な異なるパスが存在するような頂点が存在しない場合、条件が満たされると判定する。
 図12は、第1の実施形態に係る検証装置の処理の流れを示すフローチャートである。図12に示すように、まず、検証装置20は、正規表現の入力を受け付ける(ステップS11)。
 次に、検証装置20は、入力された正規表現に対して簡易検査を実施する(ステップS12)。簡易検査は、第1の判定部231による判定処理に相当する。
 簡易検査の結果、正規表現が既定の構文でなければ(ステップS13、No)、検証装置20は、正規表現の脆弱性が未修正であることを出力する(ステップS17)。例えば、入力された正規表現がバッカスナウア記法による正規表現の構文に従うものでない場合、検証装置20は、ステップS13においてNoと判定し、そうでない場合はステップS13においてYesと判定する。
 一方、正規表現が既定の構文であれば(ステップS13、Yes)、検証装置20は、RWS1U検査を実施する(ステップS14)。RWS1U検査は、第2の判定部232による判定処理に相当する。
 RWS1U検査の結果、正規表現がRWS1Uを満たさない場合(ステップS15、No)、検証装置20は、正規表現の脆弱性が未修正であることを出力する(ステップS17)。例えば、図11のように同じ文字に到達する複数のパスを持つ頂点が存在する場合、検証装置20は、ステップS15においてNoと判定し、そうでない場合はステップS15においてYesと判定する。
 一方、正規表現がRWS1Uを満たす場合(ステップS15、Yes)、検証装置20は、正規表現の脆弱性が修正済みであることを出力する(ステップS16)。
 図13を用いて、RWS1U検査(図12のステップ14に相当)の流れを詳細に説明する。図13は、RWS1U検査処理の流れを示すフローチャートである。
 まず、検証装置20は、正規表現の先読み除去を行う(ステップS141)。次に、検証装置20は、先読みを除去した正規表現の構文解析及びブラケティングを行う(ステップS142)。
 ここで、検証装置20は、構文解析木からNFAを構築する(ステップS143)。そして、検証装置20は、NFA上に特定のパスが存在するか否かを判定する(ステップS144)。例えば、特定のパスは、ある頂点から同じ文字に到達可能な異なる複数のパスである。
 特定のパスが存在する場合(ステップS144、Yes)、検証装置20は、正規表現がRWS1Uを満たさないと判定する(ステップS145)。
 一方、特定のパスが存在しない場合(ステップS144、No)、検証装置20は、正規表現がRWS1Uを満たすと判定する(ステップS146)。
[検証装置による効果]
 これまで説明してきたように、検証装置20の第1の判定部231は、正規表現があらかじめ指定された構文に従うか否かを判定する。また、第2の判定部232は、正規表現が文字列を解析するときの処理時間が、文字列の長さに対して線形であることを示す条件が満たされるか否かを判定する。これにより、正規表現の脆弱性が修正済みであることの確からしさを検証することができる。
 さらに、実施形態によれば、正規表現の脆弱性の修正案、又は修正のための技術の有効性を評価し、脆弱な正規表現の回避に寄与することができる。
 また、第2の判定部232は、正規表現がRWS1Uを満たす場合、条件が満たされると判定する。例えば、第2の判定部232は、先読みの除去及びブラケットの追加を行った正規表現を、非決定性有限オートマトンに変換し、非決定性有限オートマトン上にブラケットと空文字の遷移のみを通って同じ文字に到達可能な異なるパスが存在するような頂点が存在しない場合、条件が満たされると判定する。
 これにより、修正装置10による修正が必要な正規表現を絞り込み、処理を効率化することができる。なお、修正装置10によって修正済みの正規表現はRWS1Uを満たすものとする。
 修正装置10と検証装置20を組み合わせることで、より効率的に正規表現の脆弱性の修正に関する処理を行うことができる。上記の実施形態を基に、修正装置10と検証装置20を組み合わせた修正システムが実施可能である。
 すなわち、修正システムは、修正装置10と、検証装置20と、を有する。検証装置20は、第1の正規表現があらかじめ指定された構文に従うか否かを判定する第1の判定部231と、第1の正規表現が文字列を解析するときの処理時間が、文字列の長さに対して線形であることを示す条件が満たされるか否かを判定する第2の判定部232と、を有する。修正装置10は、第1の判定部231によって第1の正規表現が指定された構文に従わないと判定された場合、または第1の判定部231によって第1の正規表現が指定された構文に従うと判定され、かつ第2の判定部232によって第1の正規表現について条件が満たされないと判定された場合(例えば第1の正規表現がRWS1Uを満たさない場合)、第1の正規表現によって受理される文字列の集合である第1の集合、及び、第1の正規表現によって拒否される文字列の集合である第2の集合を生成する生成部131と、第1の正規表現における範囲文字を所定の構文に置換した正規表現であって、第1の集合の文字列を受理し、かつ第2の集合の文字列を拒否するような正規表現である第2の正規表現を合成する合成部132と、を有する。
[システム構成等]
 また、図示した各装置の各構成要素は機能概念的なものであり、必ずしも物理的に図示のように構成されていることを要しない。すなわち、各装置の分散及び統合の具体的形態は図示のものに限られず、その全部又は一部を、各種の負荷や使用状況等に応じて、任意の単位で機能的又は物理的に分散又は統合して構成することができる。さらに、各装置にて行われる各処理機能は、その全部又は任意の一部が、CPU(Central Processing Unit)及び当該CPUにて解析実行されるプログラムにて実現され、あるいは、ワイヤードロジックによるハードウェアとして実現され得る。なお、プログラムは、CPUだけでなく、GPU等の他のプロセッサによって実行されてもよい。
 また、本実施形態において説明した各処理のうち、自動的に行われるものとして説明した処理の全部又は一部を手動的に行うこともでき、あるいは、手動的に行われるものとして説明した処理の全部又は一部を公知の方法で自動的に行うこともできる。この他、上記文書中や図面中で示した処理手順、制御手順、具体的名称、各種のデータやパラメータを含む情報については、特記する場合を除いて任意に変更することができる。
[プログラム]
 一実施形態として、検証装置20は、パッケージソフトウェアやオンラインソフトウェアとして上記の検証処理を実行する検証プログラムを所望のコンピュータにインストールさせることによって実装できる。例えば、上記の検証プログラムを情報処理装置に実行させることにより、情報処理装置を検証装置20として機能させることができる。ここで言う情報処理装置には、デスクトップ型又はノート型のパーソナルコンピュータが含まれる。また、その他にも、情報処理装置にはスマートフォン、携帯電話機やPHS(Personal Handyphone System)等の移動体通信端末、さらには、PDA(Personal Digital Assistant)等のスレート端末等がその範疇に含まれる。
 また、検証装置20は、ユーザが使用する端末装置をクライアントとし、当該クライアントに上記の検証処理に関するサービスを提供する検証サーバ装置として実装することもできる。例えば、検証サーバ装置は、正規表現を入力とし、正規表現の脆弱性が修正済みであるか否かを示す検証結果を出力とする検証サービスを提供するサーバ装置として実装される。この場合、検証サーバ装置は、Webサーバとして実装することとしてもよいし、アウトソーシングによって上記の検証処理に関するサービスを提供するクラウドとして実装することとしてもかまわない。
 図14は、検証プログラムを実行するコンピュータの一例を示す図である。コンピュータ1000は、例えば、メモリ1010、CPU1020を有する。また、コンピュータ1000は、ハードディスクドライブインタフェース1030、ディスクドライブインタフェース1040、シリアルポートインタフェース1050、ビデオアダプタ1060、ネットワークインタフェース1070を有する。これらの各部は、バス1080によって接続される。
 メモリ1010は、ROM(Read Only Memory)1011及びRAM(Random Access Memory)1012を含む。ROM1011は、例えば、BIOS(Basic Input Output System)等のブートプログラムを記憶する。ハードディスクドライブインタフェース1030は、ハードディスクドライブ1090に接続される。ディスクドライブインタフェース1040は、ディスクドライブ1100に接続される。例えば磁気ディスクや光ディスク等の着脱可能な記憶媒体が、ディスクドライブ1100に挿入される。シリアルポートインタフェース1050は、例えばマウス1110、キーボード1120に接続される。ビデオアダプタ1060は、例えばディスプレイ1130に接続される。
 ハードディスクドライブ1090は、例えば、OS1091、アプリケーションプログラム1092、プログラムモジュール1093、プログラムデータ1094を記憶する。すなわち、検証装置20の各処理を規定するプログラムは、コンピュータにより実行可能なコードが記述されたプログラムモジュール1093として実装される。プログラムモジュール1093は、例えばハードディスクドライブ1090に記憶される。例えば、検証装置20における機能構成と同様の処理を実行するためのプログラムモジュール1093が、ハードディスクドライブ1090に記憶される。なお、ハードディスクドライブ1090は、SSD(Solid State Drive)により代替されてもよい。
 また、上述した実施形態の処理で用いられる設定データは、プログラムデータ1094として、例えばメモリ1010やハードディスクドライブ1090に記憶される。そして、CPU1020は、メモリ1010やハードディスクドライブ1090に記憶されたプログラムモジュール1093やプログラムデータ1094を必要に応じてRAM1012に読み出して、上述した実施形態の処理を実行する。
 なお、プログラムモジュール1093やプログラムデータ1094は、ハードディスクドライブ1090に記憶される場合に限らず、例えば着脱可能な記憶媒体に記憶され、ディスクドライブ1100等を介してCPU1020によって読み出されてもよい。あるいは、プログラムモジュール1093及びプログラムデータ1094は、ネットワーク(LAN(Local Area Network)、WAN(Wide Area Network)等)を介して接続された他のコンピュータに記憶されてもよい。そして、プログラムモジュール1093及びプログラムデータ1094は、他のコンピュータから、ネットワークインタフェース1070を介してCPU1020によって読み出されてもよい。
 10 修正装置
 11、21 インタフェース部
 12、22 記憶部
 13、23 制御部
 20 検証装置
 121 置換候補構文情報
 131 生成部
 132 合成部
 231 第1の判定部
 232 第2の判定部

Claims (5)

  1.  正規表現があらかじめ指定された構文に従うか否かを判定する第1の判定部と、
     前記正規表現が文字列を解析するときの処理時間が、前記文字列の長さに対して線形であることを示す条件が満たされるか否かを判定する第2の判定部と、
     を有することを特徴とする検証装置。
  2.  前記第2の判定部は、前記正規表現がRWS1Uを満たす場合、前記条件が満たされると判定することを特徴とする請求項1に記載の検証装置。
  3.  前記第2の判定部は、先読みの除去及びブラケットの追加を行った前記正規表現を、非決定性有限オートマトンに変換し、前記非決定性有限オートマトン上にブラケットと空文字の遷移のみを通って同じ文字に到達可能な異なるパスが存在するような頂点が存在しない場合、前記条件が満たされると判定することを特徴とする請求項1に記載の検証装置。
  4.  検証装置によって実行される検証方法であって、
     正規表現があらかじめ指定された構文に従うか否かを判定する第1の判定工程と、
     前記正規表現が文字列を解析するときの処理時間が、前記文字列の長さに対して線形であることを示す条件が満たされるか否かを判定する第2の判定工程と、
     を含むことを特徴とする検証方法。
  5.  正規表現があらかじめ指定された構文に従うか否かを判定する第1の判定ステップと、
     前記正規表現が文字列を解析するときの処理時間が、前記文字列の長さに対して線形であることを示す条件が満たされるか否かを判定する第2の判定ステップと、
     をコンピュータに実行させることを特徴とする検証プログラム。
PCT/JP2022/022969 2022-06-07 2022-06-07 検証装置、検証方法及び検証プログラム WO2023238240A1 (ja)

Priority Applications (1)

Application Number Priority Date Filing Date Title
PCT/JP2022/022969 WO2023238240A1 (ja) 2022-06-07 2022-06-07 検証装置、検証方法及び検証プログラム

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/JP2022/022969 WO2023238240A1 (ja) 2022-06-07 2022-06-07 検証装置、検証方法及び検証プログラム

Publications (1)

Publication Number Publication Date
WO2023238240A1 true WO2023238240A1 (ja) 2023-12-14

Family

ID=89118093

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/JP2022/022969 WO2023238240A1 (ja) 2022-06-07 2022-06-07 検証装置、検証方法及び検証プログラム

Country Status (1)

Country Link
WO (1) WO2023238240A1 (ja)

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2022113308A1 (ja) * 2020-11-27 2022-06-02 日本電信電話株式会社 修正装置、修正方法及び修正プログラム

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2022113308A1 (ja) * 2020-11-27 2022-06-02 日本電信電話株式会社 修正装置、修正方法及び修正プログラム

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
TAKAHASHI, KAZUYA, MINAMIDE, YASUHIKO: "Computational analysis of extended regular expression matching", COMPUTER SOFTWARE, JAPAN SOCIETY FOR SOFTWARE SCIENCE AND TECHNOLOGY, vol. 38, no. 2, 23 April 2021 (2021-04-23), pages 53 - 70, XP009550921, ISSN: 0289-6540 *

Similar Documents

Publication Publication Date Title
US9305116B2 (en) Dual DFA decomposition for large scale regular expression matching
CN108140091B (zh) 漏洞发现装置、漏洞发现方法以及存储介质
WO2022113308A1 (ja) 修正装置、修正方法及び修正プログラム
US8626786B2 (en) Dynamic language checking
US20040205411A1 (en) Method of detecting malicious scripts using code insertion technique
Song et al. Mab-malware: A reinforcement learning framework for attacking static malware classifiers
KR102006245B1 (ko) 바이너리 파일에 기초하여 오픈소스 소프트웨어 패키지를 식별하는 방법 및 시스템
US7739100B1 (en) Emulation system, method and computer program product for malware detection by back-stepping in program code
CN107615240B (zh) 用于分析二进制文件的基于生物序列的方案
US10339319B2 (en) Method and apparatus for identifying vulnerability information using keyword analysis for banner of open port
KR20180081053A (ko) 도메인 생성 알고리즘(dga) 멀웨어 탐지를 위한 시스템 및 방법들
US11916937B2 (en) System and method for information gain for malware detection
JPWO2016194909A1 (ja) アクセス分類装置、アクセス分類方法、及びアクセス分類プログラム
JP7409197B2 (ja) ソフトウェアプログラムにおける静的分析違反の修復パターンの精緻化
JP7231664B2 (ja) 脆弱性特徴の取得方法、装置及び電子機器
WO2023238240A1 (ja) 検証装置、検証方法及び検証プログラム
US20080222149A1 (en) Collation Regression Testing
WO2023238239A1 (ja) 修正装置、修正方法及び修正プログラム
CN112711424A (zh) 应用程序的风险问题确定方法、装置及存储介质
CN113688240B (zh) 威胁要素提取方法、装置、设备及存储介质
WO2021166271A1 (ja) 解析装置、解析方法及び解析プログラム
WO2023238259A1 (ja) 修正装置、修正方法及び修正プログラム
CN108664792A (zh) 一种Android恶意软件的溯源方法
JP7315023B2 (ja) ルール生成装置およびルール生成プログラム
US11550910B2 (en) Creating generic rules in a high dimensional sparse feature space using negative feedback

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22945748

Country of ref document: EP

Kind code of ref document: A1