Professional Documents
Culture Documents
Contents
Writing Signatures and Regular Expressions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Writing Signatures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Single Part Signatures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Multi Part Signatures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Absolute Modifiers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Relative Modifiers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Regular Expressions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Regular Expressions in SecureSphere. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Regular Expression Syntax in Brief. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
Brackets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Parentheses. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Character classes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Alternatives. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Escaping. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Anchors. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Using Regular Expressions in Signatures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
SecureSphere comes with a preconfigured database of signatures, which is updated automatically from the Imperva
Web sites on a regular basis. In addition to these preconfigured and automatically downloaded signatures, users can
write their own signatures to detect and block communication consisting of specific information. This appendix
explains the language in which such signatures should be written. The language resembles a Snort™ signature
language, though there are some differences.
• Writing Signatures
• Regular Expressions
Writing Signatures
The following sections describe how to write signatures, including:
The basic signature unit is part, which contains the actual signature text.
Example: The following signature searches for the text "hello world".
part="hello world"
Example: In the following signature the white space is replaced with \x20.
part="hello\x20world"
part="hello\\world"
Note: The length of the text searched for by part must be at least three characters.
SecureSphere does not save signatures containing part lengths less than three characters.
You can include as many parts as required in a signature to search for a sequence of text strings. The ratio between
these parts is AND.
• abcdImpervaSecureSphere
• abcdImpervaabcdSecureSphere
• abcdImpervaabcdSecure---Sphere
• abcdImpeRvaSecUreSPhEre
• abcdimpervasecuresphere
Different parts should be separated by a comma. White spaces are allowed before and after the comma.
Absolute Modifiers
• amin: The absolute position in the stream to start matching this part.
• amax: The absolute position in the stream to stop matching this part.
Example: The following signature searches for the string cmd.exe only from position 10 to position 20 in the stream.
You can include absolute modifiers after any part by using commas. You can either add a single modifier or both
modifiers for each part.
Relative Modifiers
Relative modifiers limit the part to a specific area at the end of the previous part.
• rmin: The position, relative to the end of the previous part to start searching for this part.
• rmax: The position, relative to the end of the previous part to stop searching for this part.
Example: The following signature includes two parts. The second part is searched for in a range of 5 characters from
the first part.
The strings cmd123.exe and cmd12345.exe match this signature. However the string cmd123456.exe does not
match the signature because the ".exe" part starts 6 characters after the end of the "cmd" part.
You can include relative modifiers after any part by using commas. You can either add a single modifier or both
modifiers for each part. You can also include both relative and absolute modifiers for the same part.
Relative modifiers are ignored for the first part, as the part must be relative to the previous part, which in this case
does not exist.
Regular Expressions
The following sections describe how regular expressions, including:
See also
A regular expression is a text string defining the criteria for matching other text strings.
. $ ^ { [ ( | ) ] } * + ? \
match themselves.
• A dot (.) matches almost any character, so .gr.y matches grey or gray or gr#y or gr5y
• ? indicates that the preceding char is optional, so </?script> matches <script> or </script>
• + is a multiplier for 1 or more of what is before, so [0-9]+ matches 1 or 123 or 353435
• * is a multiplier for 0 or many of what is before, so [0-9]*abc matches 123abc and abc
Note:
Brackets
[]
Parentheses
()
• To group items together into a sub-expression, for example, (ab)* matches ababab
• To group blocks of characters or words you want to retain for later use, typically for text replacement, for
example, for reordering a list, as follows:
first second $2 $1
This reverses the sequence of the third and fourth sub-strings in the text, which are denoted by $1 and $2 respectively.
Character classes
Alternatives
Alternatives occur when the expression can match either one subexpression or another. The alternatives are
separated by "|", or "\|".
Note: This behavior is exactly the opposite of that of repeat operators, whose scope is the
smallest previous sub-expression.
Escaping
Binary characters (\x) are also supported, as they are in the basic signature.
Anchors
The use of a regular expression part is optional and only applies to non-stream signatures (that is URL, parameters,
parameter types, and headers). You can only include one regular expression part in a signature. The regular
expression part must be the last part in the signature. One or more non-regular expression parts can precede the
regular expression part. SecureSphere searches for the regular expression only if all the preceding parts are found.
Note: The regular expression is searched for on the entire object (for example URL) and
not on the text following the last part.
For example, if you want to check if the "filename" parameter ends with a ".txt", your signature should be:
'part=".txt", rgxp="filename=[^&]*\.txt(&|$)"