WO2022113308A1 - 修正装置、修正方法及び修正プログラム - Google Patents

修正装置、修正方法及び修正プログラム Download PDF

Info

Publication number
WO2022113308A1
WO2022113308A1 PCT/JP2020/044381 JP2020044381W WO2022113308A1 WO 2022113308 A1 WO2022113308 A1 WO 2022113308A1 JP 2020044381 W JP2020044381 W JP 2020044381W WO 2022113308 A1 WO2022113308 A1 WO 2022113308A1
Authority
WO
WIPO (PCT)
Prior art keywords
regular expression
modification
template
correction device
character string
Prior art date
Application number
PCT/JP2020/044381
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/JP2020/044381 priority Critical patent/WO2022113308A1/ja
Publication of WO2022113308A1 publication Critical patent/WO2022113308A1/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/55Detecting local intrusion or implementing counter-measures

Definitions

  • the present invention relates to a modification device, a modification method, and a modification program.
  • regular expressions are implemented as regular expression engines and are used in various situations.
  • a regular expression engine is used in a web application that has a screen for inputting an email address to check whether the character string input by the user is an email address.
  • a regular expression engine is adopted for sanitization of data sent from the outside, extraction of elements, a standard library of a general-purpose programming language, and the like.
  • 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).
  • a regular expression that operates in linear time on the regular expression engine for the length of the character string to be matched is called a non-vulnerable regular expression.
  • a regular expression that operates on the regular expression engine, for example, in exponential time is called a vulnerable regular expression.
  • Non-Patent Document 1 As a technique for removing the threat of ReDoS, RFixer (see, for example, Non-Patent Document 1) that corrects an error in a language that accepts regular expressions is known. Further, a method of obtaining a non-vulnerable regular expression by converting a pure regular expression into a deterministic finite automaton (Deterministic Finite Automaton) once and returning it (see, for example, Non-Patent Document 2) is known.
  • Deterministic Finite Automaton Deterministic Finite Automaton
  • the conventional technique has a problem that it may be difficult to fix the vulnerability of the regular expression used in the real world.
  • Non-Patent Document 1 corrects an error in a regular expression, not a vulnerability.
  • the technique described in Non-Patent Document 2 does not correspond to the modification of the syntax such as look-ahead, look-behind, and back-reference, which are extensions widely used in the real world.
  • the correction device is rejected by the first set, which is a set of character strings accepted by the first normal expression, and the first normal expression.
  • a generator that generates a second set, which is a set of character strings, and a normal expression in which the range characters in the first normal expression are replaced with a predetermined syntax, and the character string of the first set is accepted. It is characterized by having a compositing unit for synthesizing a second normal expression, which is a normal expression that rejects the character string of the second set.
  • FIG. 1 is a diagram showing a configuration example of a correction device according to the first embodiment.
  • FIG. 2 is a diagram showing an example of the regular expression syntax.
  • 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 of synthesizing regular expressions.
  • FIG. 6 is a flowchart showing a processing flow of the correction device according to the first embodiment.
  • FIG. 7 is a flowchart showing the flow of the regular expression composition process.
  • FIG. 8 is a diagram showing an example of a computer that executes a patch.
  • FIG. 1 is a diagram showing an example of the configuration of the correction device according to the first embodiment.
  • the correction device 10 accepts the input of the regular expression before the correction, corrects the input regular expression, and outputs the corrected regular expression.
  • the regular expression in this embodiment is an extended regular expression in the real world, and follows the syntax defined in Backus-Naur form (BNF).
  • FIG. 2 is a diagram showing an example of the regular expression syntax.
  • the regular expression r in FIG. 2 is an example of a regular expression in this embodiment.
  • the correction device 10 includes an interface unit 11, a storage unit 12, and a control unit 13.
  • the interface unit 11 is an interface for inputting / outputting data and communicating data.
  • the interface unit 11 receives data input from an input device 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. Further, for example, the interface unit 11 may be a NIC (Network Interface Card).
  • NIC Network Interface Card
  • the storage unit 12 is a storage device for an HDD (Hard Disk Drive), SSD (Solid State Drive), optical disk, or the like.
  • the storage unit 12 may be a semiconductor memory in which data such as RAM (Random Access Memory), flash memory, NVSRAM (Non Volatile Static Random Access Memory) can be rewritten.
  • the storage unit 12 stores an OS (Operating System) and various programs executed by the correction device 10.
  • the storage unit 12 stores the template information 121.
  • Template information 121 is a set of regular expression syntax that is replaced with a range character or hole in a regular expression or template.
  • the template information 121 is " ⁇ , ⁇
  • " ⁇ " is a hall. The holes and templates will be described later.
  • the control unit 13 controls the entire correction device 10.
  • the control unit 13 is, for example, an electronic circuit such as a CPU (Central Processing Unit), an MPU (Micro Processing Unit), a GPU (Graphics Processing Unit), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array), or the like. It is an integrated circuit.
  • the control unit 13 has an internal memory for storing programs and control data that specify various processing procedures, and executes each process using the internal memory. Further, the control unit 13 functions as various processing units by operating various programs.
  • the control unit 13 has 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 are an example of the first set. Negative Examples is an example of the second set.
  • the 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 the character strings that combine characters of a specific length or less, classifies them into Positive Examples if each character string is accepted by the regular expression, and classifies it into Negative Examples if it is rejected. can.
  • the generation unit 131 may generate Positive Examples and Negative Examples by using the method described in Non-Patent Document 1.
  • the generation unit 131 may generate the character string of Positive Examples and the character string of Negative Examples only from the characters appearing in the regular expression before modification. For example, when the regular expression is "ab [c-d] *", the generation unit 131 is a candidate by combining "a” and "b” with one character randomly selected from " ⁇ c, d ⁇ ". Generate a string of.
  • FIG. 4 is a diagram illustrating a method of generating a set of character strings.
  • the regular expression before modification is ". *. * @ Example [.] Com".
  • the generator 131 is the character string "@ example.com”, “a@example.com”, “gc@example.com” accepted by the regular expression ". *. * @ Example [.] Com”. Is classified as Positive Examples.
  • the generation unit 131 may use the character strings "example.com”, “@ .com”, “@examplecom”, “@example.”, Etc., which are rejected by the regular expression ". *. * @ Example [.] Com". Is classified as Negative Examples.
  • the compositing unit 132 is a regular expression in which the range character in the regular expression before modification is replaced with a predetermined syntax, and is a regular expression that accepts the character string of Positive Examples and rejects the character string of Negative Examples. Synthesize the modified regular expression.
  • the modified regular expression is an example of the second regular expression.
  • the processing by the synthesis unit 132 is largely divided into a step of creating a template and a step of assigning to the template.
  • the composition unit 132 creates a template by replacing the range characters in the regular expression with placeholders.
  • the synthesizer 132 assigns a predetermined syntax to the placeholder and synthesizes a non-vulnerable regular expression.
  • the placeholder is called a hole and is described 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 unmodified regular expression. 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 the different subtrees between the ASTs (Abstract Syntax Trees) of the regular expression (see, for example, Non-Patent Document 1).
  • the compositing unit 132 When retrieving an element from the queue, the compositing unit 132 preferentially retrieves the stored template having the highest priority. At the start of processing, the synthesizer 132 stores the unmodified regular expression as a template in the queue. The priority of the unmodified regular expression stored in the queue is inevitably the highest.
  • the synthesizing unit 132 replaces the range character included in the template with a hole.
  • the range character is represented by, for example, "[C]" or ". *".
  • the synthesis unit 132 replaces any one of the holes with a predetermined syntax.
  • the compositing unit 132 replaces at least a part of the range characters in the regular expression before the modification with holes, and synthesizes the modified regular expression based on the template in which the replaced holes are further replaced with a predetermined syntax. do.
  • the compositing unit 132 sets the holes as “ ⁇ ”, “ ⁇
  • ⁇ ", “ ⁇ *”, “( ⁇ )”, “ ⁇ i”, “(? ⁇ )", “(?) ⁇ )", “(?) ⁇ ! ⁇ )”.
  • the composition unit 132 uses the holes included in the template as " ⁇ ”, “ ⁇
  • the synthesis unit 132 searches for the assignment of range characters that satisfy the conditions for the holes included in the template. For example, the synthesis unit 132 performs a search using Satisfiability Modulo Theories (SMT) solver (for example, Z3 solver) or the like.
  • SMT Satisfiability Modulo Theories
  • a regular expression that operates in linear time on the regular expression engine with respect to the length of the character string to be matched is called a non-vulnerable regular expression.
  • a regular expression that operates on the regular expression engine, for example, in exponential time is called a vulnerable regular expression with respect to the length of the string to be matched.
  • the composition unit 132 sets the holes as “ ⁇ ”, “ ⁇
  • the synthesizer 132 will use the non-vulnerable regular expression "[ ⁇ @] * @ example [" as shown in FIG. You can get ".] com”.
  • FIG. 6 is a flowchart showing a processing flow of the correction device according to the first embodiment.
  • the correction device 10 accepts the input of the regular expression (step S10).
  • the correction device 10 generates a set of character strings (Positive Examples) accepted by the input regular expression (step S20).
  • the correction device 10 generates a set of character strings (Negative Examples) rejected by the input regular expression (step S30).
  • the correction device 10 can create an extended automaton from the input regular expression before correction, and can generate a set of character strings so as to cover all the paths of the extended automaton.
  • the correction device 10 generates (synthesizes) a regular expression based on the input regular expression, the accepted character string, and the rejected character string (step S40). Then, the correction device 10 outputs the generated regular expression (step S50).
  • FIG. 7 is a flowchart showing the flow of the regular expression composition process.
  • the process of FIG. 7 corresponds to step S40 of FIG.
  • the correction device 10 stores the input regular expression in the queue as a template (step S401).
  • the correction device 10 acquires the template closest to the input regular expression from the queue (step S402).
  • the correction device 10 determines whether or not the template includes holes (step S403).
  • the correction device 10 replaces the range character of the template with a hole (step S404). Then, the correction device 10 stores the processed template in the queue (step S408).
  • the processed template here is a template in which the range character is replaced with a hole.
  • the correction device 10 accepts the character string to be accepted, rejects the rejected character string, and satisfies the condition regarding the vulnerability. Such as, the assignment to the range character to the hole is searched (step S405).
  • the correction device 10 determines whether or not the search result assignment exists (step S406). If the search result assignment does not exist (step S406, No), the correction device 10 replaces the holes with a predetermined pattern (step S407). Predetermined patterns are, for example, " ⁇ ”, “ ⁇
  • the correction device 10 stores the processed template in the queue (step S408).
  • the processed template here is a template in which holes are replaced with a predetermined pattern.
  • step S406 if there is a search result assignment (step S406, Yes), the modifier 10 synthesizes a non-vulnerable regular expression based on the search result assignment (step S409).
  • the generation unit 131 is a first set that is a set of character strings accepted by the first regular expression, and a set of character strings rejected by the first regular expression. Generate a second set.
  • the synthesizing unit 132 is a regular expression in which the range characters in the first regular expression are replaced with a predetermined syntax, and accepts the character string of the first set and rejects the character string of the second set. Synthesize a second regular expression that is a regular expression.
  • the correction device 10 makes corrections including syntaxes such as look-ahead, look-behind, and back-reference, which are extensions widely used in the real world. Therefore, according to the present embodiment, it is possible to fix the vulnerability of the regular expression used in the real world.
  • the generation unit 131 generates the character string of the first set and the character string of the second set only from the characters appearing in the first regular expression.
  • the correction 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.
  • composition unit 132 synthesizes the second regular expression based on the template in which at least a part of the range characters in the first regular expression is replaced with a placeholder, and the replaced placeholder is further replaced with a predetermined syntax. do.
  • the repair device 10 can eliminate the vulnerability with a minimum of replacement.
  • composition unit 132 uses the placeholders included in the template as " ⁇ ”, “ ⁇
  • each component of each of the illustrated devices is a functional concept, and does not necessarily have to be physically configured as shown in the figure. That is, the specific forms of distribution and integration of each device are not limited to those shown in the figure, and all or part of them may be functionally or physically dispersed or physically distributed in arbitrary units according to various loads and usage conditions. Can be integrated and configured. Further, each processing function performed by each device is realized by a CPU (Central Processing Unit) and a program that is analyzed and executed by the CPU, or hardware by wired logic. Can be realized as. The program may be executed not only by the CPU but also by another processor such as a GPU.
  • CPU Central Processing Unit
  • the modification device 10 can be implemented by installing a modification program that executes the above modification process as package software or online software on a desired computer.
  • the information processing apparatus can function as the modification device 10.
  • the information processing device referred to here includes a desktop type or notebook type personal computer.
  • the information processing device includes a smartphone, a mobile communication terminal such as a mobile phone and a PHS (Personal Handyphone System), and a slate terminal such as a PDA (Personal Digital Assistant).
  • the modification device 10 can be implemented as a modification server device in which the terminal device used by the user is a client and the service related to the above modification process is provided to the client.
  • the modification server device is implemented as a server device that provides a modification service that inputs a regular expression before modification and outputs a regular expression after modification.
  • the modification server device may be implemented as a Web server, or may be implemented as a cloud that provides services related to the modification process by outsourcing.
  • FIG. 8 is a diagram showing an example of a computer that executes a patch.
  • the computer 1000 has, for example, a memory 1010 and a CPU 1020.
  • the computer 1000 also has 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. Each of these parts is 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 a BIOS (Basic Input Output System).
  • BIOS Basic Input Output System
  • the hard disk drive interface 1030 is connected to the hard disk drive 1090.
  • the disk drive interface 1040 is connected to the disk drive 1100.
  • a removable storage medium such as a magnetic disk or an optical disk is inserted into the disk drive 1100.
  • the serial port interface 1050 is connected to, for example, a mouse 1110 and a keyboard 1120.
  • the video adapter 1060 is connected to, for example, the display 1130.
  • the hard disk drive 1090 stores, for example, the OS 1091, the application program 1092, the program module 1093, and the program data 1094. That is, the program that defines each process of the modifying device 10 is implemented as a program module 1093 in which a code that can be executed by a computer is described.
  • the program module 1093 is stored in, for example, the hard disk drive 1090.
  • the program module 1093 for executing the same processing as the functional configuration in the correction device 10 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 above-described embodiment is stored as program data 1094 in, for example, a memory 1010 or a hard disk drive 1090. Then, the CPU 1020 reads the program module 1093 and the program data 1094 stored in the memory 1010 and the hard disk drive 1090 into the RAM 1012 as needed, and executes the process of the above-described embodiment.
  • the program module 1093 and the program data 1094 are not limited to those stored in the hard disk drive 1090, but may be stored in, for example, a removable storage medium and read by the CPU 1020 via the disk drive 1100 or the like. Alternatively, 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.). Then, the program module 1093 and the program data 1094 may be read from another computer by the CPU 1020 via the network interface 1070.
  • LAN Local Area Network
  • WAN Wide Area Network

Abstract

修正装置(10)は、第1の正規表現によって受理される文字列の集合である第1の集合、及び、第1の正規表現によって拒否される文字列の集合である第2の集合を生成する。修正装置(10)は、第1の正規表現における範囲文字を所定の構文に置換した正規表現であって、第1の集合の文字列を受理し、かつ第2の集合の文字列を拒否するような正規表現である第2の正規表現を合成する。

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の集合、及び、前記第1の正規表現によって拒否される文字列の集合である第2の集合を生成する生成部と、前記第1の正規表現における範囲文字を所定の構文に置換した正規表現であって、前記第1の集合の文字列を受理し、かつ前記第2の集合の文字列を拒否するような正規表現である第2の正規表現を合成する合成部と、を有することを特徴とする。
 本発明によれば、実世界で利用されている正規表現の脆弱性を修正することができる。
図1は、第1の実施形態に係る修正装置の構成例を示す図である。 図2は、正規表現の構文の例を示す図である。 図3は、Positive ExamplesとNegative Examplesの例を示す図である。 図4は、文字列の集合の生成方法を説明する図である。 図5は、正規表現の合成方法を説明する図である。 図6は、第1の実施形態に係る修正装置の処理の流れを示すフローチャートである。 図7は、正規表現の合成処理の流れを示すフローチャートである。 図8は、修正プログラムを実行するコンピュータの一例を示す図である。
 以下に、本願に係る修正装置、修正方法及び修正プログラムの実施形態を図面に基づいて詳細に説明する。なお、本発明は、以下に説明する実施形態により限定されるものではない。
[第1の実施形態の構成]
 まず、図1を用いて、第1の実施形態に係る修正装置の構成について説明する。図1は、第1の実施形態に係る修正装置の構成の一例を示す図である。図1に示すように、修正装置10は、修正前の正規表現の入力を受け付け、入力された正規表現の修正を行い、修正後の正規表現を出力する。
 ここで、本実施形態における正規表現は、実世界の拡張を施した正規表現であって、バッカスナウア記法(BNF:Backus-Naur form)で定義された構文に従うものとする。図2は、正規表現の構文の例を示す図である。図2の正規表現rは、本実施形態における正規表現の一例である。
 図2の「C」は文字の集合であり、「x」は文字列、「i」は自然数である。図2の構文は既存の正規表現エンジンで利用されているものである(参考文献: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は、ホールを「□□」、「□|□」、「□*」、「(□)」、「\i」、「(?=□)」、「(?!□)」、「(?<=□)」、「(?<!□)」といった構文に置換する。このように、合成部132は、テンプレートに含まれるホールを、ホールを含む所定の構文である「□□」、「□|□」、「□*」、「(□)」、「\i」、「(?=□)」、「(?!□)」、「(?<=□)」、「(?<!□)」のいずれかに置換したテンプレート(ただし、□はホール)を基に修正後の正規表現を合成する。
 続いて、合成部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とは、正規表現エンジンが次に処理する演算は現在解析中の文字が何か定まれば一意に定まるという性質である。例えば、合成部132はホールを「□□」、「□|□」、「□*」、「(□)」、「\i」、「(?=□)」、「(?!□)」、「(?<=□)」、「(?<!□)」といった構文に置換する。
 同様に、修正前の正規表現が「.*.*@example[.]com」である場合、図5に示すように、合成部132は、脆弱でない正規表現「[^@]*@example[.]com」を得ることができる。
[第1の実施形態の処理]
 図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は、テンプレートがホールを含むか否かを判定する(ステップS403)。
 テンプレートがホールを含まない場合(ステップS403、No)、修正装置10は、テンプレートの範囲文字をホールに置換する(ステップS404)。そして、修正装置10は、処理済みのテンプレートをキューに格納する(ステップS408)。ここでの処理済みのテンプレートは、範囲文字がホールに置換されたテンプレートである。
 一方、テンプレートがホールを含む場合(ステップS403、Yes)、修正装置10は、修正装置10は、受理される文字列を受理し、拒否される文字列を拒否し、かつ脆弱性に関する条件を満たすような、ホールへの範囲文字への割り当てを探索する(ステップS405)。
 修正装置10は、探索結果の割り当てが存在するか否かを判定する(ステップS406)。探索結果の割り当てが存在しない場合(ステップS406、No)、修正装置10は、ホールを所定のパターンに置換する(ステップS407)。所定のパターンは、例えば「□□」、「□|□」、「□*」、「(□)」、「\i」、「(?=□)」、「(?!□)」、「(?<=□)」、「(?<!□)」といった構文である。
 そして、修正装置10は、処理済みのテンプレートをキューに格納する(ステップS408)。ここでの処理済みのテンプレートは、ホールが所定のパターンに置換されたテンプレートである。
 一方、探索結果の割り当てが存在する場合(ステップS406、Yes)、修正装置10は、探索結果の割り当てを基に脆弱でない正規表現を合成する(ステップS409)。
[第1の実施形態の効果]
 これまで説明してきたように、生成部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は、正規表現において脆弱性の原因になっている部分を、脆弱性のない構文に置換していくことができる。
[システム構成等]
 また、図示した各装置の各構成要素は機能概念的なものであり、必ずしも物理的に図示のように構成されていることを要しない。すなわち、各装置の分散及び統合の具体的形態は図示のものに限られず、その全部又は一部を、各種の負荷や使用状況等に応じて、任意の単位で機能的又は物理的に分散又は統合して構成することができる。さらに、各装置にて行われる各処理機能は、その全部又は任意の一部が、CPU(Central Processing Unit)及び当該CPUにて解析実行されるプログラムにて実現され、あるいは、ワイヤードロジックによるハードウェアとして実現され得る。なお、プログラムは、CPUだけでなく、GPU等の他のプロセッサによって実行されてもよい。
 また、本実施形態において説明した各処理のうち、自動的に行われるものとして説明した処理の全部又は一部を手動的に行うこともでき、あるいは、手動的に行われるものとして説明した処理の全部又は一部を公知の方法で自動的に行うこともできる。この他、上記文書中や図面中で示した処理手順、制御手順、具体的名称、各種のデータやパラメータを含む情報については、特記する場合を除いて任意に変更することができる。
[プログラム]
 一実施形態として、修正装置10は、パッケージソフトウェアやオンラインソフトウェアとして上記の修正処理を実行する修正プログラムを所望のコンピュータにインストールさせることによって実装できる。例えば、上記の修正プログラムを情報処理装置に実行させることにより、情報処理装置を修正装置10として機能させることができる。ここで言う情報処理装置には、デスクトップ型又はノート型のパーソナルコンピュータが含まれる。また、その他にも、情報処理装置にはスマートフォン、携帯電話機やPHS(Personal Handyphone System)等の移動体通信端末、さらには、PDA(Personal Digital Assistant)等のスレート端末等がその範疇に含まれる。
 また、修正装置10は、ユーザが使用する端末装置をクライアントとし、当該クライアントに上記の修正処理に関するサービスを提供する修正サーバ装置として実装することもできる。例えば、修正サーバ装置は、修正前の正規表現を入力とし、修正後の正規表現を出力とする修正サービスを提供するサーバ装置として実装される。この場合、修正サーバ装置は、Webサーバとして実装することとしてもよいし、アウトソーシングによって上記の修正処理に関するサービスを提供するクラウドとして実装することとしてもかまわない。
 図8は、修正プログラムを実行するコンピュータの一例を示す図である。コンピュータ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を記憶する。すなわち、修正装置10の各処理を規定するプログラムは、コンピュータにより実行可能なコードが記述されたプログラムモジュール1093として実装される。プログラムモジュール1093は、例えばハードディスクドライブ1090に記憶される。例えば、修正装置10における機能構成と同様の処理を実行するためのプログラムモジュール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 インタフェース部
 12 記憶部
 13 制御部
 121 テンプレート情報
 131 生成部
 132 合成部

Claims (6)

  1.  第1の正規表現によって受理される文字列の集合である第1の集合、及び、前記第1の正規表現によって拒否される文字列の集合である第2の集合を生成する生成部と、
     前記第1の正規表現における範囲文字を所定の構文に置換した正規表現であって、前記第1の集合の文字列を受理し、かつ前記第2の集合の文字列を拒否するような正規表現である第2の正規表現を合成する合成部と、
     を有することを特徴とする修正装置。
  2.  前記生成部は、前記第1の正規表現の中に現れる文字のみから、前記第1の集合の文字列及び前記第2の集合の文字列を生成することを特徴とする請求項1に記載の修正装置。
  3.  前記合成部は、前記第1の正規表現における範囲文字の少なくとも一部をプレースホルダに置換し、当該置換したプレースホルダをさらに所定の構文に置換したテンプレートを基に前記第2の正規表現を合成することを特徴とする請求項1又は2に記載の修正装置。
  4.  前記合成部は、前記テンプレートに含まれる前記プレースホルダを、前記プレースホルダを含む所定の構文である「□□」、「□|□」、「□*」、「(□)」、「\i」、「(?=□)」、「(?!□)」、「(?<=□)」、「(?<!□)」のいずれかに置換したテンプレート(ただし、□はプレースホルダ)を基に前記第2の正規表現を合成することを特徴とする請求項3に記載の修正装置。
  5.  修正装置によって実行される修正方法であって、
     第1の正規表現によって受理される文字列の集合である第1の集合、及び、前記第1の正規表現によって拒否される文字列の集合である第2の集合を生成する生成工程と、
     前記第1の正規表現における範囲文字を所定の構文に置換した正規表現であって、前記第1の集合の文字列を受理し、かつ前記第2の集合の文字列を拒否するような正規表現である第2の正規表現を合成する合成工程と、
     を含むことを特徴とする修正方法。
  6.  コンピュータを、請求項1から4のいずれか1項に記載の修正装置として機能させるための修正プログラム。
PCT/JP2020/044381 2020-11-27 2020-11-27 修正装置、修正方法及び修正プログラム WO2022113308A1 (ja)

Priority Applications (1)

Application Number Priority Date Filing Date Title
PCT/JP2020/044381 WO2022113308A1 (ja) 2020-11-27 2020-11-27 修正装置、修正方法及び修正プログラム

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/JP2020/044381 WO2022113308A1 (ja) 2020-11-27 2020-11-27 修正装置、修正方法及び修正プログラム

Publications (1)

Publication Number Publication Date
WO2022113308A1 true WO2022113308A1 (ja) 2022-06-02

Family

ID=81755432

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/JP2020/044381 WO2022113308A1 (ja) 2020-11-27 2020-11-27 修正装置、修正方法及び修正プログラム

Country Status (1)

Country Link
WO (1) WO2022113308A1 (ja)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2023238259A1 (ja) * 2022-06-07 2023-12-14 日本電信電話株式会社 修正装置、修正方法及び修正プログラム
WO2023238240A1 (ja) * 2022-06-07 2023-12-14 日本電信電話株式会社 検証装置、検証方法及び検証プログラム
WO2023238239A1 (ja) * 2022-06-07 2023-12-14 日本電信電話株式会社 修正装置、修正方法及び修正プログラム

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7779049B1 (en) * 2004-12-20 2010-08-17 Tw Vericept Corporation Source level optimization of regular expressions
KR101645874B1 (ko) * 2015-04-23 2016-08-05 연세대학교 산학협력단 정규 표현식을 이용하는 문자열 또는 악성 패킷 검출 방법 및 시스템

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7779049B1 (en) * 2004-12-20 2010-08-17 Tw Vericept Corporation Source level optimization of regular expressions
KR101645874B1 (ko) * 2015-04-23 2016-08-05 연세대학교 산학협력단 정규 표현식을 이용하는 문자열 또는 악성 패킷 검출 방법 및 시스템

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
MERWE ET AL.: "Turning Evil Regexes Harmless", PROCEEDINGS OF THE SOUTH AFRICAN INSTITUTE OF COMPUTER SCIENTISTS AND INFORMATION TECHNOLOGIES, 2017, pages 1 - 10, XP055942027, Retrieved from the Internet <URL:https://dl.acm.org/doi/pdf/10.1145/3129416.3129440> [retrieved on 20210309] *

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
WO2023238259A1 (ja) * 2022-06-07 2023-12-14 日本電信電話株式会社 修正装置、修正方法及び修正プログラム
WO2023238240A1 (ja) * 2022-06-07 2023-12-14 日本電信電話株式会社 検証装置、検証方法及び検証プログラム
WO2023238239A1 (ja) * 2022-06-07 2023-12-14 日本電信電話株式会社 修正装置、修正方法及び修正プログラム

Similar Documents

Publication Publication Date Title
WO2022113308A1 (ja) 修正装置、修正方法及び修正プログラム
CN106919555B (zh) 用于日志流内包含的数据的字段提取的系统和方法
CN107563201B (zh) 基于机器学习的关联样本查找方法、装置及服务器
US20200074080A1 (en) Malware clustering based on function call graph similarity
JP2014186407A (ja) テストケース生成方法、テストケース生成装置およびプログラム
CN111176717B (zh) 生成安装包的方法、装置及电子设备
US20210240829A1 (en) Malware Clustering Based on Analysis of Execution-Behavior Reports
CN110209766B (zh) 数据展示方法、电子装置及存储介质
JP5971338B2 (ja) テンプレート生成プログラム、テンプレート生成方法およびテンプレート生成装置
CN107577943B (zh) 基于机器学习的样本预测方法、装置及服务器
CN114995878A (zh) 一种自动生成网络数据转发面驱动代码的方法
CN110784553B (zh) 报文封装方法、设备及域名解析系统
JP5157534B2 (ja) 動作合成装置、および、プログラム
WO2023238240A1 (ja) 検証装置、検証方法及び検証プログラム
US9201982B2 (en) Priority search trees
WO2023238259A1 (ja) 修正装置、修正方法及び修正プログラム
CN107317892B (zh) 一种网络地址的处理方法、计算设备及可读存储介质
CN107480479B (zh) 应用程序的加固方法及装置、计算设备、计算机存储介质
WO2023238239A1 (ja) 修正装置、修正方法及び修正プログラム
CN108664792A (zh) 一种Android恶意软件的溯源方法
JP2019008799A (ja) ソースアプリケーションからのソースデータをターゲットアプリケーションのターゲットデータへとマージするためのシステムおよび方法
Najam-ul-Islam et al. Auto implementation of parallel hardware architecture for Aho-Corasick algorithm
WO2020070916A1 (ja) 算出装置、算出方法及び算出プログラム
EP3920022A1 (en) Information processing device, method, and program
WO2021166271A1 (ja) 解析装置、解析方法及び解析プログラム

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: 20963572

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 20963572

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: JP