You are on page 1of 8

Efficient Regular Expression Pattern Matching for Network

Intrusion Detection Systems using Modified Word-based


Automata

Pawan Kumar Virendra Singh


Supercomputer Education and Research Center Department of Electrical Engineering
Indian Institute of Science Indian Institute of Technology Bombay
Bangalore, India Mumbai, India
pawan@ssl.serc.iisc.in viren@ee.iitb.ac.in

ABSTRACT Keywords
Network Intrusion Detection Systems (NIDS) intercept the Regular Expressions, DPI, NIDS, Pattern Matching, DFA,
traffic at an organization’s network periphery to thwart in- NFA
trusion attempts. Signature-based NIDS compares the in-
tercepted packets against its database of known vulnerabil-
ities and malware signatures to detect such cyber attacks.
1. INTRODUCTION
These signatures are represented using Regular Expressions With our increased reliance on the Internet for commerce,
(REs) and strings. Regular Expressions, because of their social networking, information acquisition, and information
higher expressive power, are preferred over simple strings to exchange; intruders have found financial, political, and mil-
write these signatures. We present Cascaded Automata Ar- itary motives for their actions. Signature/Rule-based NIDS
chitecture to perform memory efficient Regular Expression [1, 18] matches the network traffic against its signature set
pattern matching using existing string matching solutions. and offers good protection against previously known attacks.
The proposed architecture performs two stage Regular Ex- However, with growing set of exploits and increasing wire-
pression pattern matching. We replace the substring and speeds, inspecting the network traffic becomes a challenging
character class components of the Regular Expression with task. The emergence of sophisticated cyber attacks have led
new symbols. We address the challenges involved in this to the adoption of regular expressions, over simple strings,
approach. We augment the Word-based Automata, obtained as the language of these signatures [21]. The comparison of
from the re-written Regular Expressions, with counter-based traffic payload against regular expressions, known as Deep
states and length bound transitions to perform Regular Ex- Packet Inspection (DPI), is compute intensive task. The
pression pattern matching. We evaluated our architecture profiling of NIDS software’s run time estimates the payload
on Regular Expressions taken from Snort rulesets. We were inspection time to be as high as 75% of the total time [8].
able to reduce the number of automata states between 50% Regular expression matching can be performed by con-
to 85%. Additionally, we could reduce the number of tran- structing Nondeterministic Finite Automaton (NFA) or De-
sitions by a factor of 3 leading to further reduction in the terministic Finite Automaton (DFA). For a given regular
memory requirements. expression with n symbols, an equivalent NFA can be con-
structed with at most 2n states (O(n)). However, NFA en-
gine has polynomial time matching complexity (O(n2 )) per
Categories and Subject Descriptors input symbol consumed. On the other hand, DFAs have
fast matching speed (O(1)) per symbol consumed. However,
E.3 [Data]: Data Encryption; C.2.0 [Computer Systems DFAs suffer from exponential space complexity (O(2n )) [11].
Organization]: Security and Protection; H.2.7 [Information The NIDS detection should have fast matching speed and
Systems]: Security, Integrity, and Protection low memory requirements. Hence a DFA like engine is pre-
ferred. The DFA state space blows up exponentially be-
cause of the presence of wild-card (.), character classes ([a-z],
General Terms etc.) and kleene star operator (∗) in the regular expressions.
Cyber Attacks, Intrusion Detection , Memory Footprint, When multiple such expressions are combined into a single
Performance DFA, state space blows up because of replication of smaller
state machines for each wild-card boundary. These patterns
appear frequently in the NIDS signature sets. The state
space blowup problem can be tackled by using two stage
Permission to make digital or hard copies of all or part of this work for detection [13, 4, 5, 16, 17]. We present a two stage “Cas-
personal or classroom use is granted without fee provided that copies are caded Automata Architecture” for efficiently matching such
not made or distributed for profit or commercial advantage and that copies regular expression signatures. In particular, we make the
bear this notice and the full citation on the first page. To copy otherwise, to
following contributions:
republish, to post on servers or to redistribute to lists, requires prior specific
permission and/or a fee.
SIN ’12, October 25-27, 2012, Jaipur, Rajasthan, India • We propose the “Cascaded Automata Architecture” for
Copyright � c 2012 ACM 978-1-4503-1668-2/12/10 ...$15.00. a class of regular expressions called Signature Expres-

103
sions, that appear frequently in the NIDS signatures. Baker et al. [4] proposed the use of “software-decelerated”
approach, where they utilize a small custom microcontroller
• We present the challenges involved in two-stage regular linked to each regular expression matching engine to provide
expression matching complex pattern matching functionality. Becchi and Crow-
ley [6] presented a hybrid-FA (H-FA) based approach target-
• We propose Modified Word-based Automata to ad- ing the state-space explosion problem. Lin and Hsiao [16]
dress these challenges. proposed a “Hierarchical state machine” using “master” and
• We present efficient implementations of our architec- “slave” state machines. Their “master” state machine identi-
ture to help reduce the memory footprint. fies the substrings of regular expressions and the “slave” state
machine keeps track of the regular expression. Bando et al.
The rest of the paper is organized as follows: We present [5] proposed Look ahead FA which performs out-of-sequence
a survey of recent pattern matching techniques in Section 2. detection of different components of regular expression, viz.
We formally introduce the “Cascaded Automata Architec- “substrings”, “character classes”, and “bounded/unbounded
ture” in Section 3. We present an efficient implementation repetitions” using specialized detectors. Tang et al. [22] ad-
and evaluation of our architecture in Section 4. The scope dressed the DFA state explosion. They proposed “fcq-FA”
of future work and conclusion are presented in Section 5. (flag/counter and queue FA) which uses pipelined queues
and counters for remembering matching history.
2. RELATED WORK
3. CASCADED AUTOMATA ARCHITECTURE
2.1 Hardware-based Techniques
Sidhu and Prasanna presented NFA implementation of 3.1 Key idea
regular expressions on FPGA logic components [19]. They Consider few regular expressions taken from Snort rule
exploited the hardware Flip Flops to store active NFA states. set:
Brodie et al. [7] presented a pipelined architecture incorpo-
rating run length coding and alphabet encoding compres-
sion techniques to achieve single-cycle transitions. Divyas- %3f\s+url=[^\n\r]*httpUser-Agent\x3A (1a)
ree et al. [9] proposed an NFA based implementation of e2give\.com.*Host\x3A.*Host\x3A (1b)
regular expressions with “extended1 ” regular expression syn- e2give\.com.*Redirector\x3A.*Host\x3A (1c)
tax. Kaneta et al. [12] presented “Dynamic reconfigurable
bit-parallel NFA architecture” for a sub-class2 of regular ex- FILESIZE\x3E[^\n\r]*\x3E\d+ (1d)
pressions. They encode the given NFA in “bit-masks” that We observe that a significant number of regular expres-
are stored in a collection of registers and block RAM. Naka- sions appearing in the NIDS signatures are of the form sub1
hara et al. [17] proposed regular expression matching cir- β op sub2 β op . . . (∈ SigRE); where subi is a substring, β(⊆
cuit based on a decomposed “Modular NFA with Unbounded Σ, alphabet) is a character class (CC) and op ∈ {?, ∗, +}. We
string transition” obtained from an NFA by replacing a series consider only such regular expressions in our design. Many
of states with a single transition string. of these substring components are common, or share pre-
fixes. Matching these substrings can be optimally imple-
2.2 Generic Compression Techniques mented using existing string matching algorithms. We sub-
Yu et al. [24] presented regular expression re-writing and stitute these substrings and character classes by a new sym-
grouping techniques to reduce the memory usage. Kumar bol and perform pattern matching using these new symbols.
et al. [14] introduced the terms “insomnia”, “amnesia”, and The presence of wild-cards with repetitions (e.g. .∗, .+, etc.)
“acalculia” to describe the deficiencies of traditional DFA. causes the states corresponding to substrings to be repli-
They augmented the DFA with history buffer and counters cated leading to state-space explosion. By replacing the sub-
to address these limitations. Smith et al. [20] target the string components (subi ) with new symbols (Si ), we could
state-space blowup problem of the DFAs. The paper intro- avoid state-space explosion and reduce the memory foot-
duces XFA which augment the Finite Automata (FA) with print. Replacing character classes (βi ) with a single symbol
finite scratch memory and instruction to manipulate this (Ci ) also helps reduce the total number of state transitions
memory. Ficara et al. [10] introduced δFA where they store in the new automata.
only the differences between adjacent states. Wang et al.
[23] proposed a length-based matching scheme which con- 3.2 Overview
verts the original byte-stream into a shorter integer stream In “Cascaded Automata Architecture”, we propose to com-
and then matches it with a variant of DFA, called StriD2 FA. pile substring (subi ) and character class (β) components into
Kumar et al. [15] introduced D 2 F A that is constructed first stage automata. This automata reads a character from
from a DFA via incrementally replacing several of its transi- the input stream and generates a symbol on every clock cy-
tions with a single default transition. Zhang et al. [25] pro- cle. Each substring or character class, when matched at the
posed a regular expression matching algorithm using tran- first stage, generates a unique symbol for the second stage
sition merging, called TM-DFA. Their algorithm is based automata. A special symbol ‘0’ is generated if the first stage
on the observation that in most cases the adjacent states automata doesn’t find any match. This stage can be imple-
have common destination states when consuming the same mented as an Aho-Corasick state machine [3] or a DFA. We
character. focus on the design and implementation of the second stage
1
Including counting constraints automata. Figure 1 presents our architecture.
2
same as the class targeted by our architecture

104
���������������������� ����������� ������������
������������������ ��� ������� ����� ���������� state ‘0’ is the start state, and double circled states repre-
�� ���������������� ������������������������
sent matching state with the label ‘Ri ’ indicating matched
����������� �

�� �������� regular expression. The label of a state contains the state
� � �����������
�� � �� �� ����
number and its depth from the start state, separated by ‘-’.
� � � � �

3.3 Challenges
��
� � ��

Replacing substring (subi ) and character class (βi ) com-


�� �� �� �� ������� ����� ponents with new symbols Si and Ci , respectively is not
�������������������� ������������ �������� straight-forward. The regular DFA’s states store the infor-
mation about partial matches of different regular expressions
Figure 1: Cascaded Automata Architecture at any point of time. This information is not present in the
W-NFA. In this Section, we present the challenges in cas-
caded automata approach.
The second stage automata consumes the symbol gen-
erated from the first stage. In order to maintain equiva- 3.3.1 Timing Information
lence with the original NFA, transitions corresponding to The state of W-NFA is not capable of storing timing in-
substrings are stored with length information. This length formation. For example, the state number ‘5’ of Figure 2
information is stored along with a counter array in a small doesn’t contain any information about when to expect the
global table that can validate a substring based transition to symbol ‘S2 ’ (corresponding to substring “url=”). For this
another state. This global table counter is updated when- W-NFA, state ‘5’ is activated upon receiving symbol ‘C1 ’
ever a state with length-bound transition is entered or left. (corresponding to character class “\s”). Hence, symbol ‘S2 ’
is expected exactly after three cycles (i.e. on fourth cycle) of
ORIGINAL RE REWRITTEN RE
state ‘5’ being activated. We need to associate this “timing
%3f\s+url=[^\n\r]*httpUser-Agent\x3A S1 C1 + S2 C2 ∗ S 3
e2give\.com.*Host\x3A.*Host\x3A S4 C3 ∗ S 5 C3 ∗ S 5
information” with certain4 states as and when required.
e2give\.com.*Redirector\x3A.*Host\x3A S4 C3 ∗ S 6 C3 ∗ S 5
FILESIZE\x3E[\^\n\r]*\x3E\d+ S7 C2 ∗ S 8 C4 + 3.3.2 Multiple Instances
It is easy to observe that for the state ‘5’, only one instance
Table 1: Re-written Regular expressions
can remain active at any instance because it is activated by
receiving symbol ‘C1 ’ from state ‘1’. Upon receiving symbol
‘C1 ’, the already active instances of the state ‘5’ can not
remain active any longer (because ‘S2 ’ doesn’t contain any
�����
����

symbol belonging to class ‘C1 ’). However, there will be sit-
���
uations when a state can be entered multiple times. Hence,
we need to keep track of multiple instances of an active state.
��� ���������� ������������ ����������
This is important because “timing information” is associated
with each active instance of a state.
��� �� ��� ���
� ��� ������� ��� ���

3.3.3 Overlapping Issue


�� �������������� ���� �������� Consider a regular expression “abc. ∗ bcd”. The W-NFA
corresponding to this expression is shown in Figure 3. For
��� ��� ���
� ��� �� ��� ���
� this W-NFA, state ‘1’ is activated from state ‘0’ upon re-
ceiving “abc”. However, if the input stream is “abcd”, the
���� �������� �� �������� first stage will generate symbol corresponding to “abc” upon
reading first three characters. Upon reading next character,
���� ���� ���� it will generate symbol corresponding to “bcd”. However,
��� �������
�� �� �� state ‘1’ has no information to distinguish this symbol gen-
erated by using suffix of previously generated symbol. This
������������������ will lead to false match. We need to augment W-NFA with
overlapping information to avoid false match.
����
��

� �
Figure 2: Word-based NFA for re-written RE
����� ��� ��� ���
���
���� ��

The state machine operating upon the rewritten regular


expression of Table 1 can be obtained by generating the
NFA of re-written regular expressions. We term this ma- Figure 3: W-NFA illustrating the overlapping issue
chine as Word3 -based NFA (W-NFA). W-NFA for regular
expressions of Table 1 is shown in Figure 2. In Figure 2,
3 4
here, Word refers to substring component not all states require this timing information

105
3.3.4 Overlapping Component Symbol Generation Definition 4. Incoming language LI of a state q ∈ Q
Some character classes might partially overlap with each of W-NFA M is defined as the set of all substrings, that
other leading to the issue of simultaneous generation of mul- are proper prefix of some element of SST R , that might be
tiple symbols. For example, for character classes β1 = {a, b, c} matched in the first-stage string matching automata when
and β2 = {c, d, e}, both character classes will be simulta- the state q is just5 activated.
neously active for β1 ∩ β2 = {c}. Similarly, some character
Definition 5. Partial language LP of a state q ∈ Q
classes will be be superset of others. In addition, sometimes,
of W-NFA M is defined as the set of all substrings, that
both, a character class as well as some substring, might be
are proper prefix of some element of SST R , that might be
active simultaneously. For example, substring ‘home’ and
matched in the first-stage string matching automata while
β2 will be active simultaneously upon receiving the last al-
phabet of ‘home’. We need to be able to efficiently encode the state q is active
such information to be passed on to second stage automata. The states in the W-NFA are traversed after receiving
Our aim is to generate only one symbol (substring or “word” symbols. These states, however, contain implicit in-
character class) per clock cycle from the first stage formation about the possible partial matches at that state.
to the second stage. This ensures performance against The incoming language of a state determines the set of par-
maliciously crafted flows. tial matches that can be active in the first stage automata
In the next Section, we introduce W-NFA. We augment when this state is activated in the second stage automata.
the W-NFA with required information to address the chal- The partial language of a state determines the set of par-
lenges in cascaded automata architecture. tial matches that can be active in the first stage automata
3.4 W-NFA and Proposed Enhancements while this state is active in the second state automata. The
incoming language of starting state is empty set ‘∅’. The in-
coming language of other states can be obtained recursively
Definition 1. Modified Alphabet (Σm ): A finite set of from the partial language of their preceding6 states. Algo-
symbols representing substring (subi ) and character class rithm 1 shows our pseudo-code to compute LI and LP for
components (βi ) of the signature set S W-NFA states.
Definition 2. Substring Set SST R : A finite set of all the
Algorithm 1 Pseudo-code to compute LI and LP
substring components (subi ) present in the signature set S
1: procedure ComputeLanguage(M ) � M : Input W-NFA
2: for all q ∈ M.Q do
Definition 3. A Word-based NFA is a quintuple 3: M.q.LI ← ∅ � Initialize the incoming language
M = (Q, Σm , Δ, s, F ), where 4: Queue ← Breadth first traversal of W-NFA states M.Q
5: while Queue.N otEmpty() do
• Q is a finite set of states 6: Current ← Queue.F irst() � Pop front element
7: Current.LP ← Substrings of str ∈ SST R , generated
• Σm is modified alphabet 8: using Current.self loop transitions and Current.LI
9: for all Symbol ∈ Σm do
10: for all T arget ∈ M.Δ(Current, Symbol) do
• s ∈ Q is the initial state 11: T arget.LI ∪ ← Substrings of str ∈ SST R that
12: can be generated using Current.LP and Symbol
• F ⊆ Q is the set of final states, and

• Δ : Q × Σm → 2Q , the transition function 3.4.2 Overlapping Component Symbol Generation


The SigRE components may have some relation with each
Example: Figure 2 and 3
other. For example, S1 = “terServer”, S2 = “Server”, and
A Word-based NFA corresponding to signature set S is the β1 = {a, b, . . . , z} are interrelated. A generation of sym-
combined �-free NFA obtained from the elements of S, with bol S1 guarantee the occurrence of symbols S2 and β1 , but
not vice-versa. Similarly, the character classes may have
modified alphabet Σm , using Thompson’s NFA construction
algorithm. non-empty intersection with each other. However, we don’t
want to generate multiple symbols at any stage. Therefore,
3.4.1 Language of a state we provide a solution to efficiently map this information to
modified alphabet set Σm in a lossless way.
The substring components and character classes may not
Substring overlapping issue:
always be independent. While a symbol for substring or
If the detection of a substring component Si implies the
character class is generated, another substring match might
presence of some smaller substring Sj or character class com-
be in progress. For example, for strings “root” and “other”,
ponent βk , only symbol corresponding to Si is produced. To
a match for “root” means a partial match for “other”. Thus
maintain the equivalence with the original state ma-
the state which becomes active after receiving symbol cor-
chine, we pre-compute the additional possible transitions
responding to “root” partially matches the symbol “other”.
(with label Si ) for each state along with possibly existing
Hence, in that state, we may receive symbol correspond-
transitions with label Sj and βk . These newly computed
ing to “other” ‘3’ clock cycles after activation of that state.
transitions ensure that those state traversals take place with
This information about partial matches need to be associ-
Si , in case there is a transition with label Sj or βk . Pseudo-
ated with W-NFA states to validate transitions. We term
code to compute this information is presented in Algorithm
the set of all possible partial matches (i.e. strings that are
2. Consider the regular expression set:
prefix of some member of SST R ) that are reachable at a
5
state as “language” of that state. Formally, we define two the state is not reactivated using a self-loop from itself
6
type of languages associated with the states. states that have an outgoing transition to this state

106
���� ���� ����� ������
���
���������� ��� �������� ���
abc[\d]def (2a)
����
����
kabc[a-z]*bcdef (2b) ����

���� ���� ����� ������


��� ���
Figure 4 shows the W-NFA with additional transitions for �������� ���

regular expression set 2. �� ���

��� ��� �����


Algorithm 2 Pseudo-code to compute additional transi- ������

tions for W-NFA states ����� �������

1: procedure AdditionalTransitions(M ) � M : Input W-NFA ��� ���


2: Queue ← Breadth first traversal of W-NFA states M.Q �� ��
3: while Queue.N otEmpty() do
4: Current ← Queue.F irst()
5: Δ� ∪ ← {(Current, Sstr ), Current}, where Sstr are
6: symbols for str ∈ SST R that can be generated using
7: Current.self loop transitions and Current.LP Figure 5: W-NFA with cb-state and lb-transitions
8: for all Symbol ∈ Σm do
9: for all T arget ∈ M.Δ(Current, Symbol) do
10: Δ� ∪ ← {(Current, Sstr ), T arget}, where Sstr are • βi ∩ βj �= ∅ and βi �⊆ βj and βj �⊆ βi , i.e. some symbol
11: symbols for str ∈ SST R that can be generated
12: using Current.LP and Symbol will generate only Ci , some only Cj , some both Ci and
13: M.Δ∪ ← Δ� � Update the transitions Cj , while remaining will generate neither Ci nor Cj

For the first case, there is no issue. For the second case,
we can partition βj into βi and βj − βi . For the last case, we
need to generate three character class symbols corresponding
to character classes, βi − βj , βj − βi , and βi ∩ βj respectively.
���
���� ���� ����� ������ Then, we need to modify the transition information associ-
����� ������ ����� ����
ated with states. For example, for the second case, each
����
���� transition with label βj is replaced with a transition with
����
the same start and destination states but new labels βi and
��� ���
���� ���� ����� ������
�����
β j − βi .
This approach can be extended for the p character class
���� �����
components, β1 , . . . , βp , of the signature expression set S.
���
���
�� 3.4.3 Length-bound Transitions
���
The ‘length-bound’ (lb) transitions compliment the ‘counter-
based’ states to augment ‘timing information’ with them.
��� The length information associated with such transitions,
��
along with the qualifying label, is used to determine if this
transition is taken.

Figure 4: W-NFA with pre-computed additional struct length_bound_transition {


transitions symbol label;
state *target;
Character class overlapping issue: int length; // Timing Info
After consuming an input symbol, the first stage automata };
check it for the possible generation of symbol for character
class components. If the input symbol belong to multiple The normal word transition is represented as a transition
character classes, multiple character class components will with ‘label’ tag in the W-NFA. We represent the length-
be generated simultaneously. However, we want to generate bound transition with ‘length#label’ tag in the W-NFA graph.
only one symbol per cycle. Therefore, we present a solution
to form new character classes (and corresponding symbols)
so that a symbol can match utmost one character class. 3.4.4 Counter-based States
For any pair of new character class symbols Ci and Cj , States that require “timing information” about when to
their corresponding character classes, βi and βj , will be re- expect word transitions can be associated with a “counter
lated in one of the following three ways: array”. The number of elements in this “counter array” is
equal to the number of maximum possible active instances
• βi ∩ βj = ∅, i.e. either none7 of them, or only one of of a state. Each “active instance” of the counter corre-
symbol Ci and Cj can occur sponds to an active instance of the state. Upon receiving
the corresponding word symbol, the length information as-
• βi ⊆ βj , i.e. occurrence of symbol Ci implies occur- sociated with such word labels is matched against the active
rence of Cj instances of “counter array”. A transition is made iff the
length matches with the count of one of the counter of the
7
because input symbol may not belong to any of βi or βj “counter array”. The length of word labels determines the

107
maximum count of the corresponding counter before deac- the state with transitions on ‘Sab11cd ’ and ‘C[a−z] ’. Here,
tivating it. A counter-based state has only length-bound upon receiving the partial match ‘ab1’, the self-loop symbol,
transitions. ‘C[a−z] ’ will not be generated8 . Hence, we need to have tim-
For example, state ‘5’ of Figure 2 can be associated with ing information after this point to perform exact matching.
a single counter. Since, at any time, only one instance of
this state can be active, only a single counter is sufficient 3.5 Modified Word-based NFA
to accommodate the “timing information”. Since the word So far we have seen the challenges faced in using two phase
transition out of this state is “4” characters long, the counter detection engine. We introduced the counter-based states,
can be deactivated if symbol ‘S2 ’ is not received at the 4th counter-arrays, length-bound transitions, and precomputed
cycle. A “counter array” can also be deactivated if some languages associated with states, to solve these issues. Now,
symbol is received that leads to automatic expiry of this we present a formal model of our Modified W-NFA.
state. Figure 5 represents the W-NFA, with cb-state and lb-
transitions, corresponding to regular expression set 2. The Definition 9. A Modified W-NFA (M-WNFA) obtained
counter arrays have associated operations to activate, de- from the W-NFA M is a sextuple Mm = (Qm , Σm , CA, Δm , s, F ),
activate, remove, and update an instance. Additionally, where
they support enquiry function to validate a lb-transition.
• Qm (= Q ∪ Qcb ) is the set of W-NFA states along with
counter-based states introduced to augment the W-
Definition 6. A counter-based (cb) state, qcb ∈ Qcb , has
NFA with timing information (using counter-arrays)
an associated “counter array” to maintain the “timing in-
formation”. All transitions associated with such states are • Σm is set of modified symbols (Definition 1)
length-bound transitions.
• CA is the set of counter-array (2N ) associated with
Counter-based State for Overlapping Issue: counter-based states
As seen in Section 3.3.3, the “overlapping issue” occurs
if at any state, there exists a transition that can be gener- • s ∈ Qm is the initial state
ated using partial substring from a transition that leads to • F ⊆ Qm is the set of final states, and
this state. Because of the “overlapping issue”, there might
length N
be a false match if this transition is generated using par- • Δm : (Qcb × 2N ) × Σm −−−−→ 2(Qcb ×2 )
tial substring which was already received upon entering this
state. Such a transition should not be acted upon. However, Definition 10. The configuration of a state machine with
without augmenting “timing information”, it is not possi- counter-based state is defined as (qcb , ca(qcb )) ∈ Qcb × 2N .
ble to differentiate between the transition generated using
partially matched substring from previous state, and the The transition is taken iff the state configuration has an
transition generated upon obtaining the entire string after entry corresponding to “length”. The transition function up-
reaching the current state. Formally, dates the configuration of a state machine’s source state as
well as destination state. The updation of the source state
Definition 7. The Overlapping issue is said to occur at configuration is required as it includes updating the timing
a state q, if ∃str ∈ LI (q) such that str is prefix of some information stored in the counter-array. The destination
word-transition out of state q. state, similarly needs to be updated with timing informa-
tion, such as adding an instance of active state, updating
Definition 8. The Front Symbol of a (non-null) string the current active state counters, etc. The normal states
‘str’ is its leftmost symbol (without any associated counter-array) may be considered as
FrontSymbol(a0 a1 . . . an ) = a0 a special class of counter-based states with empty counter-
array. The transitions without any associated length infor-
Due to its nature, “overlapping issue” exists only for word- mation, may similarly be considered as the special case of
based transitions. This problem can be solved by introduc- lb-transitions that can match any length.
ing a new state between the state that suffers from over- Example: Figure 6 presents M-WNFA for regular expres-
lapping issue and the target state of the word-based tran- sion set 2. State ‘q2 ’ has associated counter-array ‘ca(q2 )’.
sition that caused overlapping issue. The new state, just State ‘q5 ’ is another counter-based state with counter-array
introduced, is reached from this state upon receiving Front ‘ca(q5 )’. The action associated with transitions related to
Symbol of the word-based transition that caused overlap- counter-based states has been highlighted along with the
ping issue. transitions. In addition, the counter-arrays are updated ev-
Counter-based State for Timing Information: ery cycle. Also, if a counter-based state receives a symbol
If there is no “overlapping issue” at a particular state, we (other than character class) not shown in the state graph,
may still need to augment timing information. If a state has the counter-array corresponding to that state is deactivated.
only word-based transitions, we need to augment “timing
information” to it. Similarly, if a state has self-loop transi-
tions on character class symbol, we will need to check if it is 4. EVALUATION
required to add timing information, or not. For example, if
The second-stage automata of our architecture is modeled
a state with no-overlapping issue has transitions on ‘Sbcdef ’
as M-WNFA. However, for fast matching speed, we convert
and ‘C[a−z] ’, there is no need to add timing information to
M-WNFA to its deterministic counterpart, Modified Word-
this state. Its reason is that while a match for ‘Sbcdef ’ is
based DFA, (M-WDFA) using slight modification in subset
in progress, the symbol ‘C[a−z] ’ will be generated every cy-
8
cle and keep this state active. On the contrary, consider 1 �∈ [a − z]

108
��
����� ����� ������ ������� RE DFA M- % Red- new cb- counter
����������� ���� ��������� ����
num States WDFA uction symbol State array
����� States in states num num (bits)
�����
�����
37 32512 4814 85 81 20 126
����� ����� ������ �������
�� �� ��������� ���� 16 79210 37776 53 95 59 257
���������������� ����
40 98151 20022 80 86 27 224
��� ����������������
22 22230 10952 51 55 27 274
�������
������ �� �� ������
������ Table 2: DFA and M-WDFA memory requirements
����������������� ������ ��������
�����������������
for different regular expression sets
�� ��
�� �� Signature DFA M-WDFA H-FA D2 F A
Set (#RE) (MB) (MB) (MB) (MB)
Snort1 (37) 15.9 2.3 10.6 0.9
Figure 6: M-WNFA corresponding to regular ex- 85.6% 33.4% 94.3%
pression set 2 Snort2 (16) 77.4 8.0 10.8 6.4
89.7% 86.0% 91.7%
construction algorithm to take care of cb-states. The transi- Snort3 (40) 95.8 15.9 19.7 7.0
tion, in this M-WDFA depends upon both the input symbol 83.4% 79.4% 92.7%
as well the qualifing values from the counter-array associ- Snort4 (22) 21.7 7.5 8.0 1.8
ated with cb-states. Those states, whose subset consisted of 65.5% 63.1% 91.7%
cb-states, needs pointers to corresponding counter arrays.
Table 3: Memory requirements of DFA, M-WDFA,
Definition 11. A M-WDFA obtained from the M-WNFA H-FA, and D 2 F A for different regular expression sets
Mm is a sextuple MD = (QD , Σm , CAD , ΔD , s, F ), where
• QD is the set of M-WDFA states along with associated The main memory compression comes from the reduction
counter-arrays corresponding to the counter-based M- of number of states in the proposed M-WDFA. Also, the
WNFA states associated with them reduction of the alphabet size reduces the memory required
to store the state transition table by a factor of about 3.
• Σm is set of modified symbols (Definition 1) The overhead is the pointers that each state need to link to
• CAD is the set of counter-array (2N ) associated with the counter-based states. Our experiments showed that any
counter-based states of Mm MWDFA state had at most two counter-arrays associated
to them. One counter array can be addressed using 6 bits
• s ∈ QD is the initial state (assuming maximum number of counter-based state to be
59). Hence a total of 12 bits need to be associated with each
• F ⊆ QD is the set of final states, and state. Also, the counter-array can be implemented as bit
• ΔD : QD × Σm × CAD → QD × CAD , the transition vector. The total number of bits required to implement such
function arrays are very small. The table doesn’t show the memory
requirement of the f irst stage automata because it is linear
Counter array implementation as bit vectors: in the size of the signature set and is quite small compared
The counter-arrays associated with states can implemented to the size of DFA and M-WDFA.
as bit-vectors of width equal to the maximum possible counter Table 3 shows that the memory compression obtained
value. The value of an instance is associated with the bit- from M-WDFA is superior to that from H-FA. The com-
position and the effect of incrementing the counter-arrays is pression obtained is lesser than D 2 F A construction. This is
achieved using left shift operator on the bit-vector. The ac- expected as D 2 F A is a graph based compression technique
tivation of a state instance corresponds to setting the right- where compression in the DFA graph is obtained by shar-
most bit of the bit-vector. The instance expires when it ing transitions between different states using default transi-
shifts out of the bit-vector from the leftmost position. tions. However, M-WDFA has very small run time overhead
We implemented our architecture using the “Regular Ex- compared to D 2 F A. Table 4 shows the run time results of
pression Processor [2]”.We modified the tool to generate the M-WDFA compared to standard DFA and D 2 F A. The run
M-WDFA. Also, we implemented the f irst stage of the ar- time is obtained by parsing traces of 4MB size. The traces
chitecture using Aho-Corasick algorithm as our aim was to consisted of roughly 5% malicious content. The system used
consider the memory requirements. We evaluated our ar- for the test is Intel Core 2 Duo, 2.50 GHz processor with
chitecture on regular expressions extracted from the recent 4GB RAM. The run time results show that DFA performs
(mid 2011) Snort ruleset. In the experiments which we fol- the fastest matching. D 2 F A requires 5 to 6 times more time
low, the expressions has been grouped so as to obtain DFA compared to DFA on a general purpose PC. Whereas M-
with reasonable size. The dataset consisted of regular ex- WDFA has a matching overhead of roughly 12% compared
pressions of the type SigRE. Some of the expressions were to standard DFA. The overhead is because of updation and
slightly rewritten to make them of the class SigRE. A repre- enquiry on Counter-Arrays associated with counter based
sentative of different types of regular expressions have been states.
taken. We compare our design with the baseline DFA re-
sults. Table 2 presents the results. 4.1 Comparison with Related Work

109
Signature RE DFA M-WDFA D2 F A Pattern Matching. ISCA, 2006.
Set num (ms) (ms) (ms) [8] J. Cabrera, J. Gosar, W. Lee, and R. K. Mehra. On
Snort 1 37 60 64 299 the Statistical Distribution of Processing Times in
Snort 2 16 50 56 288 Network Intrusion Detection. IEEE Conference on
Snort 3 40 66 74 319 Decision and Control, December 2004.
Snort 4 22 50 54 330 [9] J. Divyasree, H. Rajashekar, and K. Varghese.
Dynamically Reconfigurable Regular Expression
Table 4: Run time results of DFA, M-WDFA, and Matching Architecture. Application-Specific Systems,
D 2 F A for different regular expression sets Architectures and Processors, 2008.
[10] D. Ficara, S. Giordano, G. Procissi, F. Vitucci,
G. Antichi, and A. D. Pietro. An Improved DFA for
Lin and Hsiao [16] proposed to divide the state machine
Fast Regular Expression Matching. SIGCOMM, 2008.
into “master” and “slave” components. However, they tar-
[11] J. E. Hopcroft, R. Motwani, and J. D. Ullman.
geted the regular expressions of the form “.∗S1 .∗S1� ”, “.∗S2 .∗
Introduction to Automata Theory, Languages, and
S2� ” (where Sk represents a string), etc. They also identify
Computation. Addison-Wesley, 2000.
the exception problem, where the substrings overlapping
within the same expression (i.e. the suffix of S1 is a prefix [12] Y. Kaneta, S. Yoshizawa, S. ichi Minato, H. Arimura,
of S1� ) cause false match. However, they don’t provide any and Y. Miyanaga. Dynamic Reconfigurable
solution for the exception problem. We discussed all the is- Bit-Parallel Architecture for Large-Scale Regular
sues involved in using a two level design. Also, we considered Expression Matching. FPT, 2010.
broader class of regular expressions. [13] P. Kumar and V. Singh. Efficient Regular Expression
Other proposals like [4, 5, 22, 12] rely on vast hardware Pattern Matching using Cascaded Automata
resources present on the FPGAs, whereas we propose a DFA Architecture for Network Intrusion Detection System.
based solution, suitable on both FPGAs as well as General 9th IEEE EWDTS, September 2011.
Purpose Computers. Our architecture is orthogonal to some [14] S. Kumar, B. Chandrasekaran, J. Turner, and
proposals like [15, 25, 20, 10]. G. Varghese. Curing Regular Expressions Matching
Algorithms from Insomnia, Amnesia, and Acalculia.
ACM/IEEE ANCS, 2007.
5. FUTURE WORK AND CONCLUSION
[15] S. Kumar, S. Dharmapurikar, F. Yu, P. Crowley, and
Our architecture doesn’t consider regular expressions with J. Turner. Algorithms to Accelerate Multiple Regular
counting constraints. However, like other proposals [14, 20], Expressions Matching for Deep Packet Inspection.
we also use counters for tracking information. Extending SIGCOMM, October 2006.
our work for a wider class of regular expressions present an
[16] C.-H. Lin and H.-S. Hsiao. Hierarchical State Machine
interesting future direction. Also, with some modifications,
Architecture for Regular Expression Pattern
the first-stage of our design can be used to quickly filter out
Matching. ACM GLSVLSI, 2009.
traffic to decrease the traffic load for the second stage.
We have presented “Cascaded Automata Architecture” that [17] H. Nakahara, T. Sasao, and M. Matsuura. A Regular
can efficiently utilize the existing research done on string Expression Matching Circuit Based on a Decomposed
matching problem for NIDS applications. We addressed the Automaton. Applied Reconfigurable Computing, 2011.
issues related to using string matching solutions for regu- [18] V. Paxson. Bro: A System for Detecting Network
lar expression pattern matching and proposed their solution Intruders in Real-Time. In Computer Networks,
with our “Modified Word-based Automata”. Our prelimi- 31:2435–2463, 1999. http://bro-ids.org/.
nary evaluation shows significant memory savings. With ef- [19] R. Sidhu and V. K. Prasanna. Fast Regular
ficient FPGA implementation of our architecture, we expect Expression Matching Using FPGAs. FCCM, 2001.
to be able to accelerate the NIDS detection engines. [20] R. Smith, C. Estan, and S. Jha. XFA: Faster
Signature Matching with Extended Automata. IEEE
6. REFERENCES Symposium on Security and Privacy, May 2008.
[21] R. Sommer and V. Paxson. Enhancing Byte-level
[1] http://www.snort.org/.
Network Intrusion Detection Signatures with Context.
[2] http://regex.wustl.edu/index.php/Main_Page. ACM CCS, 2003.
[3] A. V. Aho and M. J. Corasick. Efficient string [22] Y. Tang, J. Jiang, C. Hu, and B. Liu. Managing DFA
matching: An aid to bibliographic search. History with Queue for Deflation DFA. Information
Communications of the ACM, June 1975. Security Conference, January 2011.
[4] Z. K. Baker, H.-J. Jung, and V. K. Prasanna. Regular [23] X. Wang, J. Jiang, Y. Tang, B. Liu, and X. Wang.
Expression Software Deceleration for Intrusion StriD 2 FA: Scalable Regular Expression Matching for
Detection Systems. FPL, 2006. Deep Packet Inspection. IEEE ICC, 2011.
[5] M. Bando, N. S. Artan, and H. J. Chao. LaFA: [24] F. Yu, Z. Chen, Y. Diao, T. V. Lakshman, and R. H.
Lookahead Finite Automata for Scalable Regular Katz. Fast and Memory-Efficient Regular Expression
Expression Detection. ACM/IEEE ANCS, 2009. Matching for Deep Packet Inspection. ANCS, 2006.
[6] M. Becchi and P. Crowley. A Hybrid Finite [25] J. Zhang, D. Zhang, and K. Huang. A Regular
Automaton for Practical Deep Packet Inspection. Expression Matching Algorithm using Transition
ACM CoNEXT Conference, December 2007. Merging. IEEE Pacific Rim International Symposium
[7] B. Brodie, R. Cytron, and D. Taylor. A Scalable on Dependable Computing, 2009.
Architecture for High-Throughput Regular-Expression

110

You might also like