Mailing List Archive

[clamav-users] Kindly help in create unofficial signature
Dear Clamav users,

Today I got a spam email, containing .xz file in its attachment. I downloaded it, and unzipped it, then I found .exe file inside the file.

I am still learning to help create signatures for clamav here, so please be kind and help me.

My question is, what kind of signature type would be best to fit for this kind of file? Is it a .hdb or .ndb, or maybe both of them, or other file type? And why?

I have checked this file in virustotal and yes, it is a virus: https://www.virustotal.com/gui/file/0321f0286c254311930639a237888351d9423fd08d2b71fbe5fbcd9d71c584c2/detection

And, I also have created a signature Returned_Swift Copy.ndb, kindly help me to review my signature attached here, whether I created the signature correctly or incorrectly?

Thank you,
Dismas

Sent with [ProtonMail](https://protonmail.com) Secure Email.
Re: [clamav-users] Kindly help in create unofficial signature [ In reply to ]
Hi there,

On Sun, 20 Sep 2020, Dismas Axel (Thomas) via clamav-users wrote:

> Today I got a spam email, containing .xz file in its attachment. I
> downloaded it, and unzipped it, then I found .exe file inside ...

If a malicious attachment is not currently detected you could submit
it to the ClamAV team at https://www.clamav.net/reports/malware.

> My question is, what kind of signature type would be best to fit for
> this kind of file? Is it a .hdb or .ndb, or maybe both of them, or
> other file type? And why?

It is not clear to me whether by "this kind of file" you mean the .xz
(archive) type or the .exe (Portable Executable, PE) type. I guess
you mean PE because that's what your signature is for.

The .hdb and .ndb extensions refer to database files which contain
hash signatures and extended signatures respectively. If you write a
hash signature (for a complete file) you would put it in a .hdb file
in the ClamAV database, and if you write an extended signature (as you
have in your sample) you would put it in a ClamAV database .hdb file.

It is up to you to choose which kind of signature to write and you can
create several if you wish. Be aware that one of the many ways in
which malware authors try to avoid detection is by making changes in
the malware, which do not affect its operation, but which will defeat
detection using a hash-based signature for an entire file. Last week
I was looking at about sixty thousand extended signatures for a single
malware (called 'Emotet') in the daily database, so even if you don't
try to match an entire file you still have to consider the issue. You
may need to be perspicacious and creative when writing signatures. It
is something of an art to write good signatures. If you have trouble
expressing exactly what you want with extended signatures, you might
want to consider using Yara rules - although there are limitations in
the ClamAV implementation.

> And, I also have created a signature Returned_Swift Copy.ndb, kindly
> help me to review my signature attached here, whether I created the
> signature correctly or incorrectly?

When I load your signature manually it does not appear to cause any
problem for clamscan. Of course I do not have a sample of the malware
to test if it will match. Your signature is for target type 1, a PE,
so ClamAV will need to (a) uncompress the file if it is compressed and
(b) recognize it as a PE type. If in testing you use target type 0 it
will only need to uncompress the file. To avoid even that you can run
clamscan against the file after you have manually extracted it. Do be
aware that it may need large amounts of memory to decompress a file in
some compressed formats. If ClamAV has to extract it during scanning,
that may be an issue. There are other limits to be aware of, and you
can scan with limits at different settings - see the documentation.
If for example you want to scan mail in your inbox without extracting
or recognizing files you might use type 4 (of course with a completely
different signature).

Look at "Important rules of the naming convention".

Look at "Testing rules with clamscan", in particular the suggestion

clamscan --debug --verbose

which you can for example run using the 'script' utility to record its
(rather extensive) output.

Where did the original email come from?

--

73,
Ged.

_______________________________________________

clamav-users mailing list
clamav-users@lists.clamav.net
https://lists.clamav.net/mailman/listinfo/clamav-users


Help us build a comprehensive ClamAV guide:
https://github.com/vrtadmin/clamav-faq

http://www.clamav.net/contact.html#ml
Re: [clamav-users] Kindly help in create unofficial signature [ In reply to ]
Dear Ged,

Thanks for your reply and explanation, it appears there is still a lot I need to learn in order to start contributing the signature to the community.

Yes, I was referring to by "this kind of file" for .xz file types (Sorry, I was not clear before).

Here is the header of the spam email and attached is the screenshot of the fake email containing this .xz file:

Return-Path: <y.safary@kums.ac.ir>
Delivered-To: y.safary@kums.ac.ir
Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=5.63.15.95; helo=server507.dnslake.com; envelope-from=y.safary@kums.ac.ir; receiver=y.safary@kums.ac.ir
Received: from Server507.dnslake.com (webmail.kums.ac.ir [5.63.15.95])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(No client certificate requested)

From: "UCO Bank" <y.safary@kums.ac.ir>
To: y.safary@kums.ac.ir
Subject: Draft Swift copy of returning funds to your company account!!
Date: Sun, 20 Sep 2020 11:46:16 +0430
Reply-To: y.safary@kums.ac.ir
Message-ID: &lt;038d86257de64701bf789ca685f0fcaa@kums.ac.ir&gt;
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=148533ebca0643218b0bdbb74ec262b0

So, I finally do the following:

I created .ndb signature previously using this command:

1) I extracted the Returned_Swift Copy,PDF.tar.xz
2) I found Returned_Swift Copy.exe inside it.
3) I ran the command:

cat Returned_Swift Copy,PDF.tar.xz | sigtool --hex-dump | head -c 2048 &gt; Returned_Swift_Copy.ndb

4) This gave me the output of the signature previously attached.
5) I tested the .ndb using this command:

clamscan -d Returned_Swift_Copy.ndb Returned_Swift Copy,PDF.tar.xz

6) And here is the summary:

----------- SCAN SUMMARY -----------
Known viruses: 1
Engine version: 0.102.4
Scanned directories: 0
Scanned files: 1
Infected files: 1
Data scanned: 0.12 MB
Data read: 0.18 MB (ratio 0.71:1)
Time: 0.102 sec (0 m 0 s)

7) However, I also created the .hdb file just in case though by running this command:

sigtool --sha256 Returned_Swift Copy.exe &gt; Returned_Swift_Copy.hdb

8) Also, I tested the .hdb file againts the .xz file and here is the summary:

----------- SCAN SUMMARY -----------
Known viruses: 1
Engine version: 0.102.4
Scanned directories: 0
Scanned files: 1
Infected files: 1
Data scanned: 0.55 MB
Data read: 0.18 MB (ratio 3.13:1)
Time: 0.025 sec (0 m 0 s)



Thank you,
Dismas


Sent with ProtonMail Secure Email.

??????? Original Message ???????
On Sunday, September 20, 2020 10:23 PM, G.W. Haywood via clamav-users <clamav-users@lists.clamav.net> wrote:

&gt; Hi there,
&gt;
&gt; On Sun, 20 Sep 2020, Dismas Axel (Thomas) via clamav-users wrote:
&gt;
&gt; &gt; Today I got a spam email, containing .xz file in its attachment. I
&gt; &gt; downloaded it, and unzipped it, then I found .exe file inside ...
&gt;
&gt; If a malicious attachment is not currently detected you could submit
&gt; it to the ClamAV team at https://www.clamav.net/reports/malware.
&gt;
&gt; &gt; My question is, what kind of signature type would be best to fit for
&gt; &gt; this kind of file? Is it a .hdb or .ndb, or maybe both of them, or
&gt; &gt; other file type? And why?
&gt;
&gt; It is not clear to me whether by "this kind of file" you mean the .xz
&gt; (archive) type or the .exe (Portable Executable, PE) type. I guess
&gt; you mean PE because that's what your signature is for.
&gt;
&gt; The .hdb and .ndb extensions refer to database files which contain
&gt; hash signatures and extended signatures respectively. If you write a
&gt; hash signature (for a complete file) you would put it in a .hdb file
&gt; in the ClamAV database, and if you write an extended signature (as you
&gt; have in your sample) you would put it in a ClamAV database .hdb file.
&gt;
&gt; It is up to you to choose which kind of signature to write and you can
&gt; create several if you wish. Be aware that one of the many ways in
&gt; which malware authors try to avoid detection is by making changes in
&gt; the malware, which do not affect its operation, but which will defeat
&gt; detection using a hash-based signature for an entire file. Last week
&gt; I was looking at about sixty thousand extended signatures for a single
&gt; malware (called 'Emotet') in the daily database, so even if you don't
&gt; try to match an entire file you still have to consider the issue. You
&gt; may need to be perspicacious and creative when writing signatures. It
&gt; is something of an art to write good signatures. If you have trouble
&gt; expressing exactly what you want with extended signatures, you might
&gt; want to consider using Yara rules - although there are limitations in
&gt; the ClamAV implementation.
&gt;
&gt; &gt; And, I also have created a signature Returned_Swift Copy.ndb, kindly
&gt; &gt; help me to review my signature attached here, whether I created the
&gt; &gt; signature correctly or incorrectly?
&gt;
&gt; When I load your signature manually it does not appear to cause any
&gt; problem for clamscan. Of course I do not have a sample of the malware
&gt; to test if it will match. Your signature is for target type 1, a PE,
&gt; so ClamAV will need to (a) uncompress the file if it is compressed and
&gt; (b) recognize it as a PE type. If in testing you use target type 0 it
&gt; will only need to uncompress the file. To avoid even that you can run
&gt; clamscan against the file after you have manually extracted it. Do be
&gt; aware that it may need large amounts of memory to decompress a file in
&gt; some compressed formats. If ClamAV has to extract it during scanning,
&gt; that may be an issue. There are other limits to be aware of, and you
&gt; can scan with limits at different settings - see the documentation.
&gt; If for example you want to scan mail in your inbox without extracting
&gt; or recognizing files you might use type 4 (of course with a completely
&gt; different signature).
&gt;
&gt; Look at "Important rules of the naming convention".
&gt;
&gt; Look at "Testing rules with clamscan", in particular the suggestion
&gt;
&gt; clamscan --debug --verbose
&gt;
&gt; which you can for example run using the 'script' utility to record its
&gt; (rather extensive) output.
&gt;
&gt; Where did the original email come from?
&gt;
&gt; ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
&gt;
&gt; 73,
&gt; Ged.
&gt;
&gt; clamav-users mailing list
&gt; clamav-users@lists.clamav.net
&gt; https://lists.clamav.net/mailman/listinfo/clamav-users
&gt;
&gt; Help us build a comprehensive ClamAV guide:
&gt; https://github.com/vrtadmin/clamav-faq
&gt;
&gt; http://www.clamav.net/contact.html#ml

</clamav-users@lists.clamav.net></y.safary@kums.ac.ir></y.safary@kums.ac.ir>
Re: [clamav-users] Kindly help in create unofficial signature [ In reply to ]
Dismas Axel (Thomas) via clamav-users wrote:
> 3) I ran the command:
>
> cat Returned_Swift Copy,PDF.tar.xz | sigtool --hex-dump | head -c 2048 &gt; Returned_Swift_Copy.ndb

If you don't have multiple similar but not quite identical samples, and
you're not familiar with the structure of Windows executables, I'd
advise against this. It's likely to either trigger false positives, or
match so little live traffic you'd be no better off if you had just
created a hash signature.

Locally, I generally just create hash signatures unless I have a couple
of samples that look to be similar.

I use the attached Perl script to read a set of files and spit out the
hex dump with wildcards in place of the bytes that are different between
files at that exact byte position. Adjust the $baseoffset and
$fromstart variables to shift the starting point forward and back
through the file, or to work from the end of the file instead of the
beginning. (I originally created it to automate signature creation on
files that had variable chunks of different data starting ~30-60 bytes
or so in, but had big long runs of identical bytes starting from the end.)

Note that many sets of files will quickly turn into one giant wildcard,
or a generic match on any Windows executable. It also does no checking
for whether the result is actually an acceptable ClamAV signature. You
may want to use clamscan --leave-temps to extract whatever extractable
subsections it can, and build signatures based on those (I sometimes do
this with sets of Office documents).

If you're looking to be more aggressive about blocking "possibely
malicious things in archive files", I'd suggest the Sanesecurity
"Foxhole" signatures. They simply match on the filename extension of
the file inside the archive or disk image. If you're sure you'll never
need to send or receive Windows executables or a couple of document file
types wrapped in an archive file, they'll block a lot of 0-day junk.

-kgd
Re: [clamav-users] Kindly help in create unofficial signature [ In reply to ]
Hi Dismas,

First of all a disclaimer, for everyone else who happens to read this.
This is all going to be about handling email. That's more or less all
I do with ClamAV. Depending on your source of information, emails are
implicated in around 80% to 90% of all network compromises so it might
be relevant to people not scanning emails. But if you're mainly into
scanning filesystems then I guess that this won't be much use to you.
In my view if you find something nasty in the filesystem in some place
that it's not supposed to be (in my case that's anywhere other than in
one of the directories under /var/ where mail gets processed) then you
have a compromise, and you can stop scanning and start re-installing.

Another one of my hobby-horses is looking at metadata. Things one can
find out about things; in this case things one can find out about mail
by e.g. looking at the headers, and doing some investigation into what
is found in there. That will be what the rest of this post is about.

The MTA feeds clamd with mail as it comes in on the wire via a milter.
A milter is provided with ClamAV but we don't use it, we use our own.
It does some other things that aren't especially relevant to scanning,
there's nothing wrong with clamav-milter.

On Mon, 21 Sep 2020, Dismas Axel (Thomas) via clamav-users wrote:

> Yes, I was referring to by "this kind of file" for .xz file types

IF I were going to do this perhaps I'd say to myself, "Well, as far as
I can remember, nobody has ever sent me a compressed file unless I've
asked them to do that. So if one arrives unannounced I'll reject it."
Then I'd look in the message body, and as it's MIME I'd see something
like the extract below (this is in fact your last mail to me but it was
a .png file. I've edited it, to pretend that it was a .xz file):

8<----------------------------------------------------------------------
--b1_mar5aAkWHbYN3D3ZO4yFNHayVn6P2W1zCHleNR1cro
Content-Type: image/png; name=thespam.xz
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=thespam.xz

iVBORw0KGgoAAAANSUhEUgAAAzYAAAJNCAYAAADj3eD3AAAfSHpUWHRSYXcgcHJvZmlsZSB0eXBl
....
....
8<----------------------------------------------------------------------

Then I might write signatures which blocked things like the above.
Below I'm using simple Perl regexes to explain. The '/' characters
quote the patterns. The variable text is in the two strings ".*" in
each pattern, meaning "any string of text including the empty string".
Later on I'll do something similar with Yara rules.

Signature 1:

/Content-Type:.*name=.*xz/i

and

Signature 2:

/Content-Disposition:.*name=.*xz/i

These signatures don't care what's in the .xz file although they would
need to be exercised because there are probably very many ways which I
haven't thought of for malicious senders to get around them. If your
system doesn't do Perl Compatible Regular Expressions (PCRE) then you
might have to come up with a completely different kind of pattern, I'm
just showing these as an example of what might be done with what I'm
calling metadata. Not looking at the content itself (unless you take
the word 'content' in a very literal way) but at something about the
content. In this case the content is a compressed file, and what I'll
call the MIME meta-information says the content is a compressed file.
It also says what its name will be when the dumb mail client extracts
it from the message and saves it somewhere to the filesystem so that
its hapless user can then uncompress the file and run it, thus having
his computer join some botnet and perpetuate the problem. All I've
done here is look at the line giving the name. Obviously if a malware
author lied about that, just looking at the name might not work.

There are other ways to see what you're dealing with which I won't go
into. ClamAV offers things like the detection of 'PUA's or 'Possibly
Unwanted Applications'. It's all in the documentation, do spend some
quality time with it.

> Here is the header of the spam email and attached is the screenshot
> of the fake email containing this .xz file:

It's mail from a genuine user's computer which has unfortunately been
compromised, and is being used by a criminal to send mail which will
pass SPF forgery tests. But note that, earlier in this mail, I said

"IF I were going to do this ..."

That's a big IF. In fact I wouldn't have done anything like that. I
wouldn't have had to do _anything_ to block that message. To see why,
first let's look at the headers in the mail you received. There are
four headers below and I've broken the two long ones using backslash-\
escaped newlines:

> Return-Path: <y.safary@kums.ac.ir>
> Delivered-To: y.safary@kums.ac.ir
> Received-SPF: Pass (sender SPF authorized) identity=mailfrom; \
> client-ip=5.63.15.95; helo=server507.dnslake.com; \
> envelope-from=y.safary@kums.ac.ir; receiver=y.safary@kums.ac.ir
> Received: from Server507.dnslake.com \
> (webmail.kums.ac.ir [5.63.15.95]) \
> (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 \
> (256/256 bits)) (No client certificate requested)

The headers tell me that the message came from IP address 5.63.15.95.
That's about the only thing I trust thus far (*). If the headers are
to be believed this is a server in Iran. Let's see if we believe that
by looking in our GeoIP database. Here's the output exactly as I saw
it when I typed the SQL query on our GeoIP server:

milter=> SELECT * FROM xm_geo2 WHERE network && '5.63.15.95' ;
network | asnet | geonet | asnum | as_name | geoname_id | country_iso_code
--------------+--------------+-------------+-------+-------------------------------------------------------------+------------+------------------
5.63.15.0/24 | 5.63.15.0/24 | 5.63.8.0/21 | 16292 | Kermanshah University of Medical Science and Health Service | 112931 | IR
(1 row)

We use the excellent MaxMind data service. Here is the query output
again, this time edited to give shorter lines in case your mail reader
wraps the long lines above and makes a mess:

milter=> SELECT * FROM xm_geo2 WHERE network && '5.63.15.95' ;
network 5.63.15.0/24
asnet 5.63.15.0/24
geonet 5.63.8.0/21
asnum 16292
as_name "Kermanshah University of Medical Science and Health Service"
geoname_id 112931
country_iso_code IR
(1 row)

So yes, it looks like the server is in Iran, which amongst the email
sources in my experience is a shining paragon of virtue (**).

Let's, er, dig into this a bit more:

laptop3:~$ >>> dig +short -x 5.63.15.95
webmail.kums.ac.ir.
laptop3:~$ >>> dig +short server507.dnslake.com
5.63.15.95
laptop3:~$ >>> dig +short -t txt kums.ac.ir
"v=spf1 mx a a:dns.kums.ac.ir a:dns2.kums.ac.ir ~all"
laptop3:~$ >>> dig +short -t mx kums.ac.ir
10 mail.kums.ac.ir.
laptop3:~$ >>> dig +short mail.kums.ac.ir
5.63.15.95

A lot happened there at the shell prompt. I'll explain it a little.
For clarity I'll edit the laptop's prompts to make them a single '$'
symbol, instead of what I usually see on the laptop. I work remotely
on a lot of machines at once, and I need to see some information in
the prompts so I don't accidentally do things on the wrong machine!

First I did a reverse DNS lookup on the IP address using 'dig'.

$ dig +short -x 5.63.15.95
webmail.kums.ac.ir.

The reply came back with the name of the server, webmail.kums.ac.ir.
That agrees well with the mail headers. Probably because that's how
the mail headers were generated. :/

Then I did a forward lookup on the 'helo' name which it used when it
opened the SMTP conversation with your server (or maybe it was your
mail provider's server) to send the message - again using 'dig'.

laptop3:~$ >>> dig +short -t a server507.dnslake.com
5.63.15.95

The mail server probably didn't do that - so it's new information.
The IP address for that name is also 5.63.15.95. All makes sense so
far, I'm starting to think I might even believe some of it. I won't
do more DNS queries for that name right now, do them in your own time
later if you wish. Count the nameservers. Same for the KUMS domain.
Consider what will happen if they have a single-point network failure,
and whether you think the administrators are doing a good job of work.

Back to digging: I saw that there is a "Received-SPF:" header in the
message. The SPF result was 'pass' although whatever utility actually
added the header wasn't very helpful. By way of explanation it says
only "sender SPF authorized". It doesn't say which part of the SPF
record it's used to get that authorization, and I want to find out.
As luck is on my side it doesn't take too long - three DNS queries.

The first query I make is

$ dig +short -t txt kums.ac.ir
"v=spf1 mx a a:dns.kums.ac.ir a:dns2.kums.ac.ir ~all"

which says "show me all the TXT records for the domain 'kums.ac.ir'".

There's only one, and it's the SPF record I'm looking for. It starts
with "v=spf1 mx a ..." which is my first (and only) bit of bad luck.
The people who wrote this record don't really know what they're doing
(as we could have guessed, because they're letting their compromised
machines send fraudulent mail all over the planet) so they've used an
obviously inefficient mechanism for the first term in the SPF record,
which means I have to do two more DNS queries to find what I want.

So we keep digging. The SPF record says that any MX for the domain is
authorized to send mail on its behalf. So my next DNS lookup is

$ dig +short -t mx kums.ac.ir
10 mail.kums.ac.ir.

Which says "show me the MX records for "kums.ac.ir". It tells us that
there's one MX for the domain, "mail.kums.ac.ir". Let's see what IPs
we can find for it:

$ dig +short mail.kums.ac.ir
5.63.15.95

That's an 'A' lookup (dig does those by default if you don't tell it)
and that's the IP which sent the message. Everything hangs together
really well here. It doesn't always do that, and then you might have
to do some serious digging. :(

Now I'm in a position to say that If this message had been sent to us,
I'd never have seen it unless I looked for it in the logs or database
for rejected messages (yes, we write them to a database).

Our filter rules block all mail from Iran:

mail6:~$ >>> grep IR /etc/mail/.../extensible-milter_country_blacklist
ID => 4, IL => 4, IN => 4, IQ => 4, IR => 4, IS => 1, IT => 1,

These are configuration values for a Perl hash, which can effectively
block mail from countries which are never expected to send mail to us.
The 'ISO' two-letter country code for Iran is 'IR'. It gets a score
of '4' in this configuration. The meaning (to our Sendmail milter) is

"Don't accept any mail from IPs associated with this country code".

Here's why I block all mail from Iran:

Every time a connection comes in, the server looks up the IP in about
a dozen DNS Block Lists (DNSBLs). Each list has an unique policy for
listing, and we give any listing a 'weight' which ranges from 1 to 3.
The weights are all added together to reach a score. The server will
reject outright any connection from a server which scores 3 or more in
the this calculation. A listing at Spamhaus for example has a weight
of 3. If your IP is listed by Spamhaus, we'll never accept mail from
you. When we get a connection, the milter writes stuff to a database
for perusal at our whim. Now let's see the average DNSBL score for
all connections _ever_ made to our servers from Iranian IPs:

milter=> SELECT avg(bl_score) FROM connections WHERE country_code='IR';
avg
---------------------
10.8538205980066445
(1 row)

I could have calculated something like a standard deviation as well
but you get the idea. The average DNSBL score for connections from
IPs listed in the GeoIP database as being in Iran is just under 11.
We don't do business in Iran and the average DNSBL score is about 11
so we don't accept mail from Iran - it will undoubtedly be malicious.

All that goes for Indonesia, Israel, India and Iraq as well. Their
average scores are 12.5, 9.7, 11.0 and 13.8 respectively. Italy (9.7)
and Iceland (4.3) get the benefit of the rather considerable doubt in
our config as we might occasionally do business there. Italy is quite
a big spam source in my experience so it gets a score, Iceland is not
such a problem but we're less likely to be doing business there. You
might want to think about writing ClamAV signatures to match headers.

A quick whois on the IP 5.63.15.95 shows they just have a /24. Using
the very useful 'valli.org' I looked up the sending IP in quite a lot
of DNS block lists:

http://multirbl.valli.org/lookup/5.63.15.95.html

It seems the IP range is relatively well managed, by comparison with
some I that see. There was only one list hit there, and it's a list
that we don't use. So although a GeoIP country code check would have
caught this one, our DNSBL score check would not. That's the problem
with DNSBLs when it's a very recent compromise. The spam traps have
not yet seen a lot of traffic from the IP or IP range. If Kermanshah
University's mail administrator gets on top of it quickly, their IPs
might not even be listed at all.

Summary:

For the majority of mail the IP is *much* easier to use for blocking,
and more reliable, than writing expressions to match on body content.

If you can relatively easily cut out the vast majority of the trash
you can concentrate your efforts more effectively on what remains.

You can write ClamAV signatures for more than just the content, and it
can be easier to target the metadata than to target the actual content
(which is totally controlled by the malware authors so it's easier for
them to obfuscate than is much of the metadata).

You shouldn't overlook the obvious. Here's another header from the
malicious mail which was sent to you:

> From: "UCO Bank" <y.safary@kums.ac.ir>

This is a phishing thing. We reject any mail with the word 'bank' in
a 'From:' header using a Perl regex in the (extensible-)milter. I'd
think that a Yara pattern to do that could work well. If you must,
you could exclude your own bank from the pattern - but we don't even
do that.

Here are some Yara matches that I cobbled together to match some of
this afternoon's spam, and one to match a 'From:' header with "bank"
in it. None of the afternoon spam would have got through anyway, so I
wouldn't normally bother doing this - it's just for example.

8<----------------------------------------------------------------------
pi4b530214:/EXPORTS/clamav/databases# >>> cat My_Spam.yara
rule My_Spam_Rule // block some random spam
{
strings:
$mymatcha = /\r\nSubject:[\W\w]*B2B marketing/ nocase ascii
$mymatchb = /\r\nSubject:[\W\w]*Free SEO Audit/ nocase ascii
$mymatchc = /\r\nFrom:[\W\w]*bank/ nocase ascii
$mymatchd = "Summ Now" nocase ascii
condition:
$mymatcha or $mymatchb or $mymatchc or $mymatchd
}
8<----------------------------------------------------------------------

As we're scanning mail using clamd and a milter, all I have to do is
drop the file into the clamav database directory and issue a RELOAD
command to clamd. Using clamdscan the setup behaves much the same.
Below you can see clamd logging the database reload and then the spam
that it's finding:

8<----------------------------------------------------------------------
Sep 21 17:26:35 clamd[31759]: Reading databases from /EXPORTS/clamav/databases
Sep 21 17:27:39 clamd[31759]: Database correctly reloaded (11319285 signatures)
Sep 21 17:27:39 clamd[31759]: Activating the newly loaded database...
Sep 21 17:28:50 clamd[31759]: instream(192.168.44.11@34538): YARA.My_Spam_rule.UNOFFICIAL FOUND
Sep 21 17:29:48 clamd[31759]: instream(192.168.44.11@34552): Sanesecurity.Jurlbl.0fddc2.UNOFFICIAL FOUND
Sep 21 17:29:57 clamd[31759]: instream(192.168.44.11@34556): YARA.My_Spam_Rule.UNOFFICIAL FOUND
Sep 21 17:30:35 clamd[31759]: instream(192.168.44.11@34572): OK
Sep 21 17:31:47 clamd[31759]: instream(192.168.44.11@34586): YARA.My_Spam_rule.UNOFFICIAL FOUND
Sep 21 17:42:51 clamd[31759]: instream(192.168.44.11@34712): OK
Sep 21 17:46:18 clamd[31759]: instream(192.168.44.11@34746): YARA.My_Spam_rule.UNOFFICIAL FOUND
Sep 21 17:50:49 clamd[31759]: instream(192.168.44.11@34798): YARA.My_Spam_rule.UNOFFICIAL FOUND
Sep 21 17:50:57 clamd[31759]: instream(192.168.44.11@34812): YARA.My_Spam_Rule.UNOFFICIAL FOUND
Sep 21 18:03:25 clamd[31759]: instream(192.168.44.11@34946): OK
Sep 21 18:03:40 clamd[31759]: instream(192.168.44.11@34950): Heuristics.Phishing.Email.SSL-Spoof FOUND
Sep 21 18:03:50 clamd[31759]: instream(192.168.44.11@34954): YARA.My_Spam_Rule.UNOFFICIAL FOUND
8<----------------------------------------------------------------------

Check ClamAV's limitations for Yara rules, and test a few before you
write lots of them. Watch out for efficiency issues, you don't want
to DOS your own machines. This applies to all regex-type matching.
Of course I had to remove those Yara rules to send this message. :/
Sorry, no time for more now, have to run.

HTH

--

73,
Ged.
(*) I don't really trust that yet.
(**) If you'll believe that you'll believe anything.

_______________________________________________

clamav-users mailing list
clamav-users@lists.clamav.net
https://lists.clamav.net/mailman/listinfo/clamav-users


Help us build a comprehensive ClamAV guide:
https://github.com/vrtadmin/clamav-faq

http://www.clamav.net/contact.html#ml