Tuesday, August 26, 2014

For the past several months we've been working diligently on a complete refresh of several Open Source websites, designs and logos.  The first website we rolled out a refresh of was Snort.org back in June.

At the same time, we've been working hard on ClamAV.net.  When the ClamAV project was acquired in 2007 by Sourcefire (now a part of Cisco), we retained the original website and hosting provider the website was built on, but we took this opportunity to start from scratch.

As with Snort.org, this wasn't just a facelift for the website, this was a complete rewrite.  Much of the content you are looking for is the same, for instance the virus submission forms are still on the site, but we've build some improvements:
  • Simple Navigation
    • Much like we tried to do with Snort.org, almost all content on ClamAV.net is one or two clicks away.
  • Faster
    • Not only is the site faster to load on the browser, but it is less load on the server side too.
  • Documentation
    • We now dynamically load the ClamAV FAQ from Github onto the site.  If someone would like to contribute to the FAQ, they may do so by submitting a pull request (at https://github.com/vrtadmin/clamav-faq.  Which, once accepted, will be rendered on the main clamav.net site for all to see.
  • Elimination of dead links and pages
We really hope that you enjoy on the new ClamAV.net, and are looking forward to hearing your feedback at snort-site@cisco.com

Please take a look at the new website over at: http://www.clamav.net

Tuesday, July 29, 2014

ClamAV Community,

This notice is to inform you that effective immediately ClamAV 0.96 (and all minor versions) is no longer supported in accordance with ClamAV's EOL policy which can be found here:

http://www.clamav.net/documents/end-of-life-policy-eol

While the current CVD's being distributed will still work on ClamAV 0.96, we are enabling the functionality to actually make those versions no longer be able to update.  There is detection that we have written that cannot be shipped to the 0.96 branch.

Thank you for using ClamAV!

Wednesday, July 9, 2014

Introduction

In order to support more advanced features planned in future releases, ClamAV has switched to using OpenSSL for hashing. The ClamAV Visual Studio project included with ClamAV's source code requires the OpenSSL distributables to be placed in a specific directory. This article will teach you how to compile OpenSSL on a Microsoft Windows system and how to link ClamAV against OpenSSL.

This blog article is based on another article.


Prerequisites


You will need ActiveState ActivePerl installed. OpenSSL uses Perl-based Makefiles. You will also need Visual Studio 2010 or later.


Download OpenSSL


You can find OpenSSL's source here. Download the latest version. When this article was first authored, the latest version of OpenSSL was 1.0.1h. This article will reference that version throughout.

We will be using separate build and installation directories for 32bit and 64bit compilations. We'll extract the source code twice, to C:\openssl-src-32 and C:\openss-src-64. We'll then create two directories to hold the OpenSSL installation: C:\openssl-build-32 and C:\openssl-build-64.


Compiling OpenSSL


We will first build the 32bit libraries. You will need to open a Visual Studio 32bit command prompt. Please note that you cannot build OpenSSL 64bit from a 32bit Visual Studio command prompt and vice-versa.

We'll run these commands in the command prompt:
  1. C:
  2. cd \openssl-src-32
  3. perl Configure VC-WIN32 --prefix=C:\openssl-build-32
  4. ms\do_ms
  5. nmake -f ms\ntdll.mak
  6. nmake -f ms\ntdll.mak install
Once those commands have run, you'll need to create the 64bit OpenSSL distributables in a Visual Studio x64 comamnd prompt:
  1. C:
  2. cd \openssl-src-64
  3. perl Configure VC-WIN64A --prefix=C:\openssl-build-64
  4. ms\do_win64a
  5. nmake -f ms\ntdll.mak
  6. nmake -f ms\ntdll.mak install
You now have both the 32bit and 64bit builds of OpenSSL compiled and installed in their respective build directories.


ClamAV Dependencies Directory


Now that you have distributables for both 32bit and 64bit, we'll now need to create the directories where the ClamAV Visual Studio project expects the OpenSSL dependencies to be.

Create these directories:
  1. C:\clamdeps
  2. C:\clamdeps\win32
  3. C:\clamdeps\win32\openssl
  4. C:\clamdeps\win32\openssl\lib
  5. C:\clamdeps\win64
  6. C:\clamdeps\win64\openssl
  7. C:\clamdeps\win64\openssl\lib

Copy the 32bit directories and files over:
  1. C:\openssl-build-32\include to C:\clamdeps\win32\openssl
  2. C:\openssl-build-32\lib\libeay32.lib to C:\clamdeps\win32\openssl\lib
  3. C:\openssl-build-32\lib\ssleay32.lib to C:\clamdeps\win32\openssl\lib
  4. C:\openssl-build-32\bin\libeay32.dll to C:\clamdeps\win32\openssl\lib
  5. C:\openssl-build-32\bin\ssleay32.dll to C:\clamdeps\win32\openssl\lib
Now copy the 64bit directories and files over:
  • C:\openssl-build-64\include to C:\clamdeps\win64\openssl
  • C:\openssl-build-64\lib\libeay32.lib to C:\clamdeps\win64\openssl\lib
  • C:\openssl-build-64\lib\ssleay32.lib to C:\clamdeps\win64\openssl\lib
  • C:\openssl-build-64\bin\libeay32.dll to C:\clamdeps\win64\openssl\lib
  • C:\openssl-build-64\bin\ssleay32.dll to C:\clamdeps\win64\openssl\lib


Conclusion


We've now built the OpenSSL libraries that ClamAV now depends on. ClamAV requires them to be in C:\clamdeps\win{32,64}\openssl.

Tuesday, July 8, 2014

The ClamAV team is proud to announce the availability of ClamAV 0.98.5 beta ready for testing!

0.98.5
------

Welcome to ClamAV 0.98.5 beta! ClamAV 0.98.5 will include important new features for collecting and analyzing file properties. Software developers and analysts may collect file properties using the ClamAV API and then analyze them with ClamAV bytecode programs. Using the new features will require that libjson-c is installed.

Look for our upcoming series of blog posts to learn more about using the ClamAV API and bytecode facilities for collecting and analyzing file properties.

The release can be downloaded from http://sourceforge.net/projects/clamav/files/beta/.  Please download, test and provide any feedback via the mailing lists.


--
The ClamAV team (http://www.clamav.net/team)

Monday, June 16, 2014

The ClamAV team is pleased to announce the release of ClamAV 0.98.4!  Below are the release notes for 0.98.4:


0.98.4
------

ClamAV 0.98.4 is a bug fix release. The following issues are now resolved:

- Various build problems on Solaris, OpenBSD, AIX.
- Crashes of clamd on Windows and Mac OS X platforms when reloading the virus signature database.
- Infinite loop in clamdscan when clamd is not running.
- Freshclam failure on Solaris 10.
- Buffer underruns when handling multi-part MIME email attachments.
- Configuration of OpenSSL on various platforms.
- Name collisions on Ubuntu 14.04, Debian sid, and Slackware 14.1.
- Linking issues with libclamunrar
Thanks to the following individuals for testing, writing patches, and
initiating quality improvements in this release:

Tuomo Soini
Scott Kitterman
Jim Klimov
Curtis Smith
Steve Basford
Martin Preen
Lars Hecking
Stuart Henderson
Ismail Paruk
Larry Rosenbaum
Dave Simonson
Sebastian Andrzej Siewior


The newest release can be downloaded from the following link: http://www.clamav.net/download/sources

Please download this release, and provide us any feedback on our mailing lists.


Friday, May 16, 2014

ClamAV 0.98.4rc1 is now available for download.  Shown below are the notes concerning this release:


0.98.4rc1
------

ClamAV 0.98.4 is a bug fix release. The following issues are now resolved:

- Various build problems on Solaris, OpenBSD, AIX.

- Crashes of clamd on Windows and Mac OS X platforms when reloading
the virus signature database.

- Infinite loop in clamdscan when clamd is not running.

- Freshclam failure on Solaris 10.

- Buffer underruns when handling multi-part MIME email attachments.

- Configuration of OpenSSL on various platforms.

----

ClamAV 0.98.4rc1 is available for download here: http://sourceforge.net/projects/clamav/files/RC/clamav-0.98.4-rc1/.  Please download, test, and provide feedback to the mailing list here:

http://lists.clamav.net/mailman/listinfo/clamav-users


--
The ClamAV team (http://www.clamav.net/team)

Wednesday, May 7, 2014

ClamAV 0.98.3 has been released, and is available here: http://sourceforge.net/projects/clamav/files/clamav/0.98.3/, below are the highlighted changes and fixes from this release!


0.98.3
------

Here are the new features and improvements in ClamAV 0.98.3:

- Support for common raw disk image formats using 512 byte sectors,
specifically GPT, APM, and MBR partitioning.

- Experimental support of OpenIOC files. ClamAV will now extract file
hashes from OpenIOC files residing in the signature database location,
and generate ClamAV hash signatures. ClamAV uses no other OpenIOC
features at this time. No OpenIOC files will be delivered through
freshclam. See openioc.org and iocbucket.com for additional information
about OpenIOC.

- All ClamAV sockets (clamd, freshclam, clamav-milter, clamdscan, clamdtop)
now support IPV6 addresses and configuration parameters.

- Use OpenSSL file hash functions for improved performance. OpenSSL
is now prerequisite software for ClamAV 0.98.3.

- Improved detection of malware scripts within image files. Issue reported
by Maarten Broekman.

- Change to circumvent possible denial of service when processing icons within
specially crafted PE files. Icon limits are now in place with corresponding
clamd and clamscan configuration parameters. This issue was reported by
Joxean Koret.

- Improvements to the fidelity of the ClamAV pattern matcher, an issue
reported by Christian Blichmann.

- Opt-in collection of statistics. Statistics collected are: sizes and MD5
hashes of files, PE file section counts and section MD5 hashes, and names
and counts of detected viruses. Enable statistics collection with the
--enable-stats clamscan flag or StatsEnabled clamd configuration
parameter.

- Improvements to ClamAV build process, unit tests, and platform support with
assistance and suggestions by Sebastian Andrzej Siewior, Scott Kitterman,
and Dave Simonson.

- Patch by Arkadiusz Miskiewicz to improve error handling in freshclam.

- ClamAV 0.98.3 also includes miscellaneous bug fixes and documentation
improvements.

Thanks to the following ClamAV community members for sending patches or reporting
bugs and issues that are addressed in ClamAV 0.98.3:

Sebastian Andrzej Siewior
Scott Kitterman
Joxean Koret
Arkadiusz Miskiewicz
Dave Simonson
Maarten Broekman
Christian Blichmann

--

REGARDING OPENSSL

In addition, as a special exception, the copyright holders give
permission to link the code of portions of this program with the
OpenSSL library under certain conditions as described in each
individual source file, and distribute linked combinations
including the two.

You must obey the GNU General Public License in all respects
for all of the code used other than OpenSSL. If you modify
file(s) with this exception, you may extend this exception to your
version of the file(s), but you are not obligated to do so. If you
do not wish to do so, delete this exception statement from your
version. If you delete this exception statement from all source
files in the program, then also delete it here.

Wednesday, April 23, 2014

Congratulations to Mark Allan, developer of the ClamXav project (the OSX GUI front-end to ClamAV) for making the top ten list in the free App section of the OSX App Store!

It's great to see a free tool and great contribution by the community being used by thousands of users and being recognized!

Great work Mark!



Friday, March 28, 2014

ClamAV Community,

This notice is to inform you that effective immediately ClamAV 0.95 (and all minor versions) is no longer supported in accordance with ClamAV's EOL policy which can be found here:

http://www.clamav.net/documents/end-of-life-policy-eol

While the current CVD's being distributed will still work on ClamAV 0.95, and we are not enabling the functionality to actually make those versions be able to update, this does serve as notice that we are no longer going to be testing against that version in our regression tests.

We will also be EOL'ing 0.96 in coming months, so if either of those versions is currently in use, it is highly suggested that you upgrade to the most current version.

Thank you for using ClamAV!

Wednesday, March 5, 2014

ClamAV uses boolean logic in its LDB signatures. Each LDB signature has a set of subsignatures that, when present, evaluate to True in its logical statement. When the logical statement evaluates to True, the signature alerts. My goal was to create something to clean up the logical statement in these signatures.

Logical & (and) and logical | (or) are the primary operators in ClamAV LDB signatures. An example representative of most LDB logical blocks would look something like 0&(1|2). This would indicate that for this virus, subsignature 0 must be present, and one of subsignature 1 or subsignature 2 must also be present for an alert to be triggered. ClamAV does allow you to specify how many times a subsignature can alert with the operators =, <, and >. For example, 0=0&1 would indicate that subsignature 0 should occur zero times in a file and subsignature 1 must be present. These conditional statements (example, 0>3) are treated in the same manner as a single subsignature (example, 0) in that they evaluate to True or not. This simplifies our problem because negations (N=0) are treated as positive matches and can simply be substituted with a dummy variable. For a more detailed description of ClamAV LDB signatures, please refer to signatures.pdf.

My goal starting out was to take a boolean equation and represent it in a form with minimal bytes. This means that unnecessary logic would need to be eliminated, as well, any boolean identity to reduce the number of bytes used should be applied. Some examples:

    Original              Reduced
    0|(0&1)               0 
    (0&1)|(0&2)           0&(1|2)

Over some months, I kept seeing cases where this capability would be useful. For example, if you had some set of subsignatures and some set of files, automatically construct an LDB signature that alerts on all those files. Another situation would be when LDB signatures are submitted. With an algorithm like this, a tool to could be written to automatically verify that the logical block is in a minimal representation. Signature verification and improvement is what I will focus on in this post.

Algorithms

With the utility for this growing, I began. The biggest difficulty I had starting out was that I had two assumptions. First, that there would be a single algorithm able to achieve this. That was incorrect. As well, I thought that the method for doing this would be available online. That was also incorrect.

The first step was to parse the logical block into something that is more easily manipulated programmatically. For this I implemented the Shunting Yard Algorithm to parse the equation into polish notation. Instead of rebuilding a prefix string, the logical block is translated into an expression tree. This program was implemented in Python, so the expression tree consisted of dicts and lists. For example:

    Statement:
    0&1&(2|3)

    Python:
    {'&':[0, {'&': [1, {'|': [2, 3]}]}]}

Once the expression tree is built, it is converted to disjunctive normal form. This makes the statement an "or (|) of ands (&)". If that description is hard to digest, it can be thought of as the boolean equivalent of a sum of products. This form is reached by recursively applying the boolean identity for distribution in order to expand the equation. The algorithm for this is to identify a the situation where an and (&) sub-tree has an or (|) child. You then expand and distribute the children. The difficult thing to figure out with this part was that once a branch was changed, the algorithm must be run again on that branch until it stops changing. An example of the input and output:

    Statement:
    0&(1|0)&2

    Distributed:
    (0&1&2)|(0&0&2)

Any duplicate and (&) sub-statement is eliminated. This prepares the logical block for the Quine-McCluskey algorithm. This algorithm is the programmatic equivalent of a Karnaugh Map. That is, it will minimize a boolean expression. However, it will only do this minimization in a logical sense. In terms of representation, the equation will likely still not be optimized. In the Quine-McCluskey algorithm, a truth table is constructed. This was represented by a list of lists in Python. Using the above example, we would get:

    Truth table:
    | 0 1 2 |
    | ===== |
    | 1 1 1 |    // 0&1&2 
    | 1 0 1 |    // 0&2

    Python:
    [[1,1,1], [1,0,1]]

Already, the redundant 0&0 has been reduced to a single 0 in the second statement. The algorithm then sorts the truth table entries based on their count of 1s. Any two terms that differ only by one digit can have that digit marked with a dash (-) to indicate that the term does not matter. For instance:
    Truth table:
    | 0 1 2 |
    | ===== |
    | 1 - 1 |
    | 1 - 1 |
I used 2 in place of a dash, since this was a list of integers it would keep processing simple.
    Python:
    [[1,2,1], [1,2,1]]
This shows that we can actually eliminate subsignature 1. Since the full signature will fire with or without that subsignature, it is not necessary to keep. Since this simple example does not demonstrate it, I will skip over the selection portion of Quine-McCluskey. The full algorithm is detailed on Wikipedia (linked above). We now have deleted subsignature 1 and have changed subsignature 2 to 1, leaving us with:

    Result: 
    0&1 

Now that we have a logically efficient equation we must minimize it. For this, the script recursively applies boolean identity for distribution. However, this time, it applies it in a way that extracts common terms from statements. If the current key is or (|), the function finds the most common value in this branch at a depth of 1. This means that it will return if it reaches another or (|) after passing an and (&).

The previous case is completely reduced, so I will use a different example here.

    Statement:
    (0&1&2)|(0&1&3)

                 |
             /       \
            &         &
          /   \     /   \
         &     0   0     &
       /   \           /   \
      3     1         1     2

It would start at the root node (|), then find the most common value in its subtree. Both 0 and 1 occur twice in the subtree, so it selects whichever it saw first. It then extracts that value and rebuilds the tree.

              &
          /       \
         1         |
               /       \
              &         &
            /   \     /   \
           3     0   0     2 

It continues to do this until no more values can be extracted.

    Result:
    0&1&(2|3)


This algorithm was not producing the results I wanted on larger equations until I added the capability for it to select subtrees as the most common value in addition to integers (leaf nodes).

The program then rebuilds the logical statement in prefix notation from the expression tree. It checks the difference in length between the original and simplified signature. If there is an improvement, the original and simplified equations are converted to a form that Z3 Python can read and equivalence is verified. Z3 has a slightly different syntax, but the biggest consideration is that ClamAV's method of representing variables as number is incompatible, so each number must be converted to a letter.

    slvr.add(Not(simp_z3 == orig_z3))
    
    if slvr.check() == unsat:
        if opt_demo:
            print 'Equivalence proven!'
        return True
    else:
        if opt_demo:
            print 'Not equivalent!'
            print 'Counterexample:'
            print s.model()
        return False

You ask Z3 to prove that the simplified equation does not equal the original equation. If this request is unsatisfiable, then you have proven the two equations are equivalent. Once equivalence is verified, the LDB signature is reconstructed with the improved logic and printed out.

Examples


This first example demonstrates the scripts ability to extract common values and reduce a signature via the distribution identity.

    ====================
    Test.Signature;Engine:51-255,Target:0;(0&2&3&4)|(1&2&3&4);41414141;42424242;43434343;45454545;46464646
    
    ORIG:  (0&2&3&4)|(1&2&3&4)
    SIMP:  (0|1)&2&3&4
    Equivalence proven!
    Reduced size by 8 bytes.
    
    Test.Signature;Engine:51-255,Target:0;(0|1)&2&3&4;41414141;42424242;43434343;45454545;46464646
    ====================

In this example the script combines terms to simplify the final signature.

    ====================
    Test.Signature;Engine:51-255,Target:0;0&(1|2)&((3&(5|6))|(4&(5|6)));41414141;42424242;43434343;45454545;46464646;47474747;48484848
    
    ORIG:  0&(1|2)&((3&(5|6))|(4&(5|6)))
    SIMP:  0&(1|2)&(3|4)&(5|6)
    Equivalence proven!
    Reduced size by 10 bytes.

    Test.Signature;Engine:51-255,Target:0;0&(1|2)&(3|4)&(5|6);41414141;42424242;43434343;45454545;46464646;47474747;48484848
    ====================

A simple situation would be eliminating redundant logic.

    ====================
    Test.Signature;Engine:51-255,Target:0;((0&1)|(1&0));41414141;42424242
    
    ORIG:  ((0&1)|(1&0))
    SIMP:  0&1
    Equivalence proven!
    Reduced size by 10 bytes.
    
    Test.Signature;Engine:51-255,Target:0;0&1;41414141;42424242
    ====================

As well, there are situations where the logic can make a subsignature unnecessary. When a subsignature is deleted, there is a little bookkeeping that needs to be done to make sure Z3 still verifies it. When building the Z3 equations it is important to note that subsignature 1 in the simplified equation is subsignature 2 in the original.

    ====================
    Test.Signature;Engine:51-255,Target:0;0&(1|0)&2;41414141;42424242;43434343
 
    Removing subsig 1 

    ORIG:  0&(1|0)&2
    SIMP:  0&1
    Equivalence proven!
    Reduced size by 15 bytes.
    Test.Signature;Engine:51-255,Target:0;0&1;41414141;43434343
    ====================

ClamAV Signature Set

The next question is what happens if we run this against the ClamAV LDB signature set. As of writing this, there are currently 615 LDB signatures in daily.cld. If this tool were to have been used on all the LDB signatures prior to publishing, it would have saved 712 bytes. A large portion of these savings comes from parentheses around the outside of the equation that are dropped. The tool would take something like (0&1) and produce 0&1.

If we were to update all the signatures with this tool there is an additional factor to consider. The first time a signature is updated a number is appended to the end of the signature name. For example, if you were to update the signature Win.Trojan.Agent it would be renamed Win.Trojan.Agent-1. That is a cost of 2 bytes. Any additional update increments the number on the end of the signature name. If the signature ended in -9, -99, etc., then there would be a cost of one byte when it is updated. Considering this, an update to the signature database would save 446 bytes. The fact that this is a relatively low number is reassuring to me - it means that we are writing pretty good signatures.

Conclusion

This problem was a lot of fun to solve since the solution was not available anywhere online. In future research, having this functionality will enable me to generate robust LDBs to cover clusters of malware with a single signature. On a functional level, this tool will save space and improve the overall quality of signatures published in the future. Thanks for reading.