IT_Architect
Verified User
- Joined
- Feb 27, 2006
- Messages
- 1,084
2013-03-13 - Version 1.20 - Important update! - See change log below
Motivation: A couple of users who had simple passwords that had their sites hosed by a bots.
Research: I searched for and spent a lot of time working with scripts that are out there, but they either didn't catch the malware, or did work, but the code was not well thought out, inefficient, or not flexible. While testing a simple script I found at digitalsanctuary, I gained a lot of respect for ClamAV's excellent detection capabilities, not only to find PC e-mail viruses, but also web page exploits. At that point, I decided to use ClamAV's clamscan as the basis for these scripts. Another result of my research was that none of the ?NIX versions, unlike Windows, has an efficient hook to determine when files have been created or changed. Neither iNotify nor kqueue have the potential to form the basis of an efficient filesystem monitor, even though there are some products based on them. That leaves us with crontab to do scheduled scans.
Goals: To provide a framework to maintain ?NIX server’s free of malware, that is efficient, flexible, and easily extensible to leverage the many capabilities of ClamAV’s clamscan. You can see the many useful options available here: http://linux.die.net/man/1/clamscan
Requirements:
- ?NIX
- bash shell
- ClamAV, which includes the requisite clamscan utility
The Scripts: The following three files is supplied.
clamscan_full.sh - Scans the entire system except areas you identify NOT TO scan.
clamscan_delta2.sh - As with clamscan_full.sh, this script scans the entire system except areas you identify NOT TO scan. The key difference is it only scans files that have changed within the last <user defined> minutes. Hence, the delta name. Thus, you could run this script every hour, and set it to look back <user defined> minutes + a few minutes, to scan only the files that have been recently created or changed.
clamscan_delta.sh - As with delta2, it only scans files that have changed within the last <user defined> minutes. Unlike delta2, this script requires you to identify where TO scan. This has a few advantages. It can be easier to limit where you want to scan. Because of that, it can often be much faster, and have less server impact. On large servers, delta2 may impact your server for longer than you want. The reason for the delta naming order is because I tend to use the delta version because it is much quicker, and has less server impact, which is important during normal business hours.
To Deploy
1. Copy scripts to /etc or other suitable location
2. Flag scripts as executable
3. Make sure the bash is available at the link shown on the top of the script. If it's not, create a symlink to its location.
E.G. ln -s /usr/local/bin/bash /bin/bash
Alternatively change the scripts to point to the location of bash.
4. Edit the well-documented parameters in the User Settings area
5. Schedule the files to run in crontab.
- Linux Example:
##### Anti-malware processes
# Scan server with ClamAV 30 minutes after the hour
30 * * * * /etc/clamscan_delta.sh
# Scan server with ClamAV each day
0 2 * * * /etc/clamscan_full.sh
- FreeBSD Example:
##### Anti-malware processes
# Scan server with ClamAV 30 minutes after the hour
30 * * * * root /etc/clamscan_delta.sh
# Scan server with ClamAV each day
0 2 * * * root /etc/clamscan_full.sh
RFC: This is also an RFC. My goal is to have these scripts work in any ?NIX environment. I wouldn't call myself a shell guru, nor have I worked with Linux since 2007, so I don't know if these scripts will work in those environments. I would appreciate comments of a shell script guru to help make these scripts work across all of ?NIX platforms. The reason I have Author in the script is because you're supposed to, and so people know who to ask if they absolutely have to, but not make it too easy.
Motivation: A couple of users who had simple passwords that had their sites hosed by a bots.
Research: I searched for and spent a lot of time working with scripts that are out there, but they either didn't catch the malware, or did work, but the code was not well thought out, inefficient, or not flexible. While testing a simple script I found at digitalsanctuary, I gained a lot of respect for ClamAV's excellent detection capabilities, not only to find PC e-mail viruses, but also web page exploits. At that point, I decided to use ClamAV's clamscan as the basis for these scripts. Another result of my research was that none of the ?NIX versions, unlike Windows, has an efficient hook to determine when files have been created or changed. Neither iNotify nor kqueue have the potential to form the basis of an efficient filesystem monitor, even though there are some products based on them. That leaves us with crontab to do scheduled scans.
Goals: To provide a framework to maintain ?NIX server’s free of malware, that is efficient, flexible, and easily extensible to leverage the many capabilities of ClamAV’s clamscan. You can see the many useful options available here: http://linux.die.net/man/1/clamscan
Requirements:
- ?NIX
- bash shell
- ClamAV, which includes the requisite clamscan utility
The Scripts: The following three files is supplied.
clamscan_full.sh - Scans the entire system except areas you identify NOT TO scan.
clamscan_delta2.sh - As with clamscan_full.sh, this script scans the entire system except areas you identify NOT TO scan. The key difference is it only scans files that have changed within the last <user defined> minutes. Hence, the delta name. Thus, you could run this script every hour, and set it to look back <user defined> minutes + a few minutes, to scan only the files that have been recently created or changed.
clamscan_delta.sh - As with delta2, it only scans files that have changed within the last <user defined> minutes. Unlike delta2, this script requires you to identify where TO scan. This has a few advantages. It can be easier to limit where you want to scan. Because of that, it can often be much faster, and have less server impact. On large servers, delta2 may impact your server for longer than you want. The reason for the delta naming order is because I tend to use the delta version because it is much quicker, and has less server impact, which is important during normal business hours.
To Deploy
1. Copy scripts to /etc or other suitable location
2. Flag scripts as executable
3. Make sure the bash is available at the link shown on the top of the script. If it's not, create a symlink to its location.
E.G. ln -s /usr/local/bin/bash /bin/bash
Alternatively change the scripts to point to the location of bash.
4. Edit the well-documented parameters in the User Settings area
5. Schedule the files to run in crontab.
- Linux Example:
##### Anti-malware processes
# Scan server with ClamAV 30 minutes after the hour
30 * * * * /etc/clamscan_delta.sh
# Scan server with ClamAV each day
0 2 * * * /etc/clamscan_full.sh
- FreeBSD Example:
##### Anti-malware processes
# Scan server with ClamAV 30 minutes after the hour
30 * * * * root /etc/clamscan_delta.sh
# Scan server with ClamAV each day
0 2 * * * root /etc/clamscan_full.sh
RFC: This is also an RFC. My goal is to have these scripts work in any ?NIX environment. I wouldn't call myself a shell guru, nor have I worked with Linux since 2007, so I don't know if these scripts will work in those environments. I would appreciate comments of a shell script guru to help make these scripts work across all of ?NIX platforms. The reason I have Author in the script is because you're supposed to, and so people know who to ask if they absolutely have to, but not make it too easy.
Last edited: