Table of Contents - PhishSigs - Database file format - PDB format - GDB format - WDB format - Hints - Examples of PDB signatures - Examples of WDB signatures - Example for how the URL extractor works - How matching works - RealURL, displayedURL concatenation - What happens when a match is found - Extraction of realURL, displayedURL from HTML tags - Example - Simple patterns - Regular expressions - Flags - Introduction to regular expressions - Special characters - Character classes - Escaping - Alternation - Optional matching, and repetition - Groups - How to create database files - How to create and maintain the whitelist (daily.wdb) - How to create and maintain the domainlist (daily.pdb) - Dealing with false positives, and undetected phishing mails - False positives - Undetected phish mails
This file contains urls/hosts that are target of phishing attempts. It contains lines in the following format:
regular expression, for the concatenated URL
DisplayedHostname as a simple pattern (literally, no regular expression)
the pattern can match either the full hostname
or a subdomain of the specified hostname
to avoid false matches in case of subdomain matches, the engine checks that there is a dot(
.) or a space(
is ignored for R and H for compatibility reasons
is the URL the user is sent to, example: href attribute of an html anchor (<a> tag)
is the URL description displayed to the user, where its claimed they are sent, example: contents of an html anchor (<a> tag)
is the hostname portion of the DisplayedURL
an (optional) functionality level, 2 formats are possible:
minlevel all engines having functionality level >=
minlevel will load this line
minlevel-maxlevel engines with functionality level (>=)
minlevel, and (<)
maxlevel will load this line
This file contains URL hashes in the following format:
S:P:HostPrefix[:FuncLevelSpec] S:F:Sha256hash[:FuncLevelSpec] S1:P:HostPrefix[:FuncLevelSpec] S1:F:Sha256hash[:FuncLevelSpec] S2:P:HostPrefix[:FuncLevelSpec] S2:F:Sha256hash[:FuncLevelSpec] S:W:Sha256hash[:FuncLevelSpec]
These are hashes for Google Safe Browsing - malware sites, and should not be used for other purposes.
These are hashes for Google Safe Browsing - phishing sites, and should not be used for other purposes.
Hashes for blacklisting phishing sites. Virus name: Phishing.URL.Blacklisted
Locally whitelisted hashes.
4-byte prefix of the sha256 hash of the last 2 or 3 components of the hostname. If prefix doesn’t match, no further lookups are performed.
sha256 hash of the canonicalized URL, or a sha256 hash of its prefix/suffix according to the Google Safe Browsing “Performing Lookups” rules. There should be a corresponding
:P:HostkeyPrefix entry for the hash to be taken into consideration.
To see which hash/URL matched, look at the
clamscan --debug output, and look for the following strings:
Looking up hash,
prefix matched, and
Hash matched. Local whitelisting of .gdb entries can be done by creating a local.gdb file, and adding a line
This file contains whitelisted url pairs It contains lines in the following format:
regular expression, for the entire URL, not just the hostname
The regular expression is by default anchored to start-of-line and end-of-line, as if you have used
/ is automatically added both to the regex, and the input string to avoid false matches
The regular expression matches the concatenation of the RealURL, a colon(
:), and the DisplayedURL as a single string. It doesn’t separately match RealURL and DisplayedURL!
matches hostname, or subdomain of it, see notes for H above
empty lines are ignored
the colons are mandatory
Don’t leave extra spaces on the end of a line!
if any of the lines don’t conform to this format, clamav will abort with a Malformed Database Error
see section Extraction-of-realURL for more details on realURL/displayedURL
To check for phishing mails that target amazon.com, or subdomains of amazon.com:
To do the same, but for amazon.co.uk:
To limit the signatures to certain engine versions:
H:amazon.co.uk:20-30 H:amazon.co.uk:20- H:amazon.co.uk:0-20
First line: engine versions 20, 21, …, 29 can load it
Second line: engine versions >= 20 can load it
Third line: engine versions < 20 can load it
In a real situation, you’d probably use the second form. A situation like that would be if you are using a feature of the signatures not available in earlier versions, or if earlier versions have bugs with your signature. Its neither case here, the above examples are for illustrative purposes only.
To allow amazon’s country specific domains and amazon.com, to mix domain names in DisplayedURL, and RealURL:
Explanation of this signature:
this is a regular expression
load signature only for engines with functionality level >= 17 (recommended for type X)
The regular expression is the following (X:, :17- stripped, and a / appended)
Explanation of this regular expression (note that it is a single regular expression, and not 2 regular expressions splitted at the :).
any subdomain of
domain we are whitelisting (RealURL part)
country-domains: at, ca, co.uk, co.jp, de, fr
recomended way to end real url part of whitelist, this protects against embedded URLs (evilurl.example.com/amazon.co.uk/)
RealURL and DisplayedURL are concatenated via a :, so match a literal : here
any subdomain of
recommended way to end displayed url part, to protect against embedded URLs
automatically added to further protect against embedded URLs
When you whitelist an entry make sure you check that both domains are owned by the same entity. What this whitelist entry allows is: Links claiming to point to amazon.com (DisplayedURL), but really go to country-specific domain of amazon (RealURL).
Consider the following HTML file:
The phishing engine extract the following RealURL/DisplayedURL pairs from it:
http://1.realurl.example.com/ 1.displayedurl.example.com http://2.realurl.example.com 2displayedurl.example.com http://3.realurl.example.com 3.nested.example.com http://4.realurl.example.com 4.displayedurl.example.com http://5.realurl.example.com http://5.displayedurl.example.com/img0.gif http://5.realurl.example.com http://5.form.nested.displayedurl.example.com http://5.form.nested.displayedurl.example.com 5.form.nested.link-displayedurl.example.com http://6.realurl.example.com 6.displayedurl.example.com http://6.realurl.example.com 6.displayedurl.example.com/img1.gif
The phishing detection module processes pairs of RealURL/DisplayedURL. Matching against daily.wdb is done as follows: the realURL is concatenated with a
:, and with the DisplayedURL, then that line is matched against the lines in daily.wdb/daily.pdb
So if you have this line in daily.wdb:
and this href:
<a href='http://www.google.ro'>www.google.com</a> then it will be whitelisted, but:
<a href='http://images.google.com'>www.google.com</a> will not.
In the case of the whitelist, a match means that the RealURL/DisplayedURL combination is considered clean, and no further checks are performed on it.
In the case of the domainlist, a match means that the RealURL/displayedURL is going to be checked for phishing attempts.
Furthermore you can restrict what checks are to be performed by specifying the 3-digit hexnumber.
The html parser extracts pairs of realURL/displayedURL based on the following rules.
In version 0.93: After URLs have been extracted, they are normalized, and cut after the hostname.
(anchor) the href is the realURL, its contents is the displayedURL
nesting another <a> tag withing an <a> tag (besides being invalid html) is treated as a </a><a..
the action attribute is the realURL, and a nested <a> tag is the displayedURL
if nested within an <a> tag, the realURL is the href of the a tag, and the src/dynsrc/area is the displayedURL of the img
if nested withing a form tag, then the action attribute of the form tag is the realURL
if nested withing an <a> tag the src attribute is the displayedURL, and the href of its parent a tag is the realURL
if nested withing a form tag, then the action attribute of the form tag is the realURL
Consider this html file:
` <a href=”evilurl2” title=”www.ebay.com”\>click here to sign`
` <form action=”evilurl_form”>
The resulting realURL/displayedURL pairs will be (note that one tag can generate multiple pairs):
evilurl / www.paypal.com
evilurl2 / click here to sign in
evilurl2 / www.ebay.com
evilurl_form / cgi.ebay.com
cgi.ebay.com / Ebay
evilurl / image.paypal.com/secure.jpg
Simple patterns are matched literally, i.e. if you say:
it is going to match www.google.com, and only that. The . (dot) character has no special meaning (see the section on regexes [sec:Regular-expressions] for how the .(dot) character behaves there)
POSIX regular expressions are supported, and you can consider that internally it is wrapped by ^, and $. In other words, this means that the regular expression has to match the entire concatenated (see section RealURL,-displayedURL-concatenation for details on concatenation) url.
It is recomended that you read section Introduction-to-regular to learn how to write regular expressions, and then come back and read this for hints.
Be advised that clamav contains an internal, very basic regex matcher to reduce the load on the regex matching core. Thus it is recomended that you avoid using regex syntax not supported by it at the very beginning of regexes (at least the first few characters).
Currently the clamav regex matcher supports:
. (dot) character
\(\backslash\) (escaping special characters)
| (pipe) alternatives
\[\] (character classes)
() (parenthesis for grouping, but no group extraction is performed)
other non-special characters
Thus the following are not supported:
other “advanced” features not listed in the supported list ;)
This however shouldn’t discourage you from using the “not directly supported features “, because if the internal engine encounters unsupported syntax, it passes it on to the POSIX regex core (beginning from the first unsupported token, everything before that is still processed by the internal matcher). An example might make this more clear:
Everything till ([a-zA-Z])+ is processed internally, that parenthesis (and everything beyond) is processed by the posix core.
Examples of url pairs that match:
Example of url pairs that don’t match:
Flags are a binary OR of the following numbers:
| Flag | Value | |----------------------|-------| | HOST_SUFFICIENT | 1 | | DOMAIN_SUFFICIENT | 2 | | DO_REVERSE_LOOKUP | 4 | | CHECK_REDIR | 8 | | CHECK_SSL | 16 | | CHECK_CLOAKING | 32 | | CLEANUP_URL | 64 | | CHECK_DOMAIN_REVERSE | 128 | | CHECK_IMG_URL | 256 | | DOMAINLIST_REQUIRED | 512 |
The names of the constants are self-explanatory.
These constants are defined in libclamav/phishcheck.h, you can check there for the latest flags.
There is a default set of flags that are enabled, these are currently:
( CLEANUP_URL | CHECK_SSL | CHECK_CLOAKING | CHECK_IMG_URL )
ssl checking is performed only for a tags currently.You must decide for each line in the domainlist if you want to filter any flags (that is you don’t want certain checks to be done), and then calculate the binary OR of those constants, and then convert it into a 3-digit hexnumber. For example you devide that domain_sufficient shouldn’t be used for ebay.com, and you don’t want to check images either, so you come up with this flag number: (2 256\Rightarrow)258((decimal)\Rightarrow102(hexadecimal))
So you add this line to daily.wdb:
regex(7) man-page: http://www.tin.org/bin/man.cgi?section=7\&topic=regex
the opening square bracket - it marks the beginning of a character class, see sectionCharacter-classes
the backslash - escapes special characters, see section Escaping
the caret - matches the beginning of a line (not needed in clamav regexes, this is implied)
the dollar sign - matches the end of a line (not needed in clamav regexes, this is implied)
the period or dot - matches any character
the vertical bar or pipe symbol - matches either of the token on its left and right side, see section Alternation
the question mark - matches optionally the left-side token, see sectionOptional-matching,-and
the asterisk or star - matches 0 or more occurences of the left-side token, see section Optional-matching,-and
the plus sign - matches 1 or more occurences of the left-side token, see section Optional-matching,-and
the opening round bracket - marks beginning of a group, see section Groups
the closing round bracket - marks end of a group, see sectionGroups
Escaping has two purposes:
it allows you to actually match the special characters themselves, for example to match the literal +, you would write (\backslash)+
it also allows you to match non-printable characters, such as the tab ((\backslash)t), newline ((\backslash)n), ..
However since non-printable characters are not valid inside an url, you won’t have a reason to use them.
Groups can also be used to extract substring, but this is not supported by the clam engine, and not needed either in this case.
If the phishing code claims that a certain mail is phishing, but its not, you have 2 choices:
examine your rules daily.pdb, and fix them if necessary (see: sectionHow-to-create)
add it to the whitelist (discussed here)
Lets assume you are having problems because of links like this in a mail:
After investigating those sites further, you decide they are no threat, and create a line like this in daily.wdb:
R http://www\(\backslash\).bcentral\(\backslash\).it/.+ http://69\(\backslash\).0\(\backslash\).241\(\backslash\).57/bCentral/L\(\backslash\).asp?L=.+
Note: urls like the above can be used to track unique mail recipients, and thus know if somebody actually reads mails (so they can send more spam). However since this site required no authentication information, it is safe from a phishing point of view.
When not using –phish-scan-alldomains (production environments for example), you need to decide which urls you are going to check.
Although at a first glance it might seem a good idea to check everything, it would produce false positives. Particularly newsletters, ads, etc. are likely to use URLs that look like phishing attempts.
Lets assume that you’ve recently seen many phishing attempts claiming they come from Paypal. Thus you need to add paypal to daily.pdb:
R .+ .+\(\backslash\).paypal\(\backslash\).com
The above line will block (detect as phishing) mails that contain urls that claim to lead to paypal, but they don’t in fact.
Be carefull not to create regexes that match a too broad range of urls though.
Whenever you see a false positive (mail that is detected as phishing, but its not), you need to examine why clamav decided that its phishing. You can do this easily by building clamav with debugging (./configure –enable-experimental –enable-debug), and then running a tool:
This will show the url that triggers the phish verdict, and a reason why that url is considered phishing attempt.
Once you know the reason, you might need to modify daily.pdb (if one of yours rules inthere are too broad), or you need to add the url to daily.wdb. If you think the algorithm is incorrect, please file a bug report on bugzilla.clamav.net, including the output of why.py.
Using why.py doesn’t help here unfortunately (it will say: clean), so all you can do is:
$clamscan/clamscan –phish-scan-alldomains undetected.eml
And see if the mail is detected, if yes, then you need to add an appropriate line to daily.pdb (see section How-to-create).
If the mail is not detected, then try using:
$clamscan/clamscan –debug undetected.eml|less
Then see what urls are being checked, see if any of them is in a whitelist, see if all urls are detected, etc. `