2003-07-29 15:48:06 +00:00
|
|
|
/*
|
2006-04-07 19:22:21 +00:00
|
|
|
* Copyright (C) 2002 - 2006 Tomasz Kojm <tkojm@clamav.net>
|
2003-07-29 15:48:06 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2007-03-31 20:31:04 +00:00
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
2003-07-29 15:48:06 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2006-04-09 19:59:28 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
* MA 02110-1301, USA.
|
2003-07-29 15:48:06 +00:00
|
|
|
*/
|
|
|
|
|
2004-02-06 13:46:08 +00:00
|
|
|
#if HAVE_CONFIG_H
|
|
|
|
#include "clamav-config.h"
|
|
|
|
#endif
|
|
|
|
|
2003-07-29 15:48:06 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2008-07-30 15:20:30 +00:00
|
|
|
#include <signal.h>
|
|
|
|
|
2007-02-25 02:54:38 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2003-07-29 15:48:06 +00:00
|
|
|
#include <unistd.h>
|
2007-02-25 02:54:38 +00:00
|
|
|
#endif
|
|
|
|
#ifdef C_WINDOWS
|
|
|
|
#include <fcntl.h>
|
|
|
|
#else
|
2003-07-29 15:48:06 +00:00
|
|
|
#include <sys/time.h>
|
2007-02-25 02:54:38 +00:00
|
|
|
#endif
|
2003-07-29 15:48:06 +00:00
|
|
|
#include <time.h>
|
2007-01-30 21:11:32 +00:00
|
|
|
#ifdef C_LINUX
|
|
|
|
#include <sys/resource.h>
|
|
|
|
#endif
|
2003-07-29 15:48:06 +00:00
|
|
|
|
|
|
|
#include "others.h"
|
2007-01-30 21:11:32 +00:00
|
|
|
#include "global.h"
|
2003-07-29 15:48:06 +00:00
|
|
|
#include "manager.h"
|
2004-03-29 00:00:58 +00:00
|
|
|
|
2007-01-30 21:11:32 +00:00
|
|
|
#include "shared/misc.h"
|
|
|
|
#include "shared/output.h"
|
2009-02-12 15:14:12 +00:00
|
|
|
#include "shared/actions.h"
|
2008-12-30 10:33:43 +00:00
|
|
|
#include "shared/optparser.h"
|
2003-11-09 19:26:44 +00:00
|
|
|
|
2008-02-08 17:50:44 +00:00
|
|
|
#include "libclamav/str.h"
|
2008-06-10 16:59:19 +00:00
|
|
|
#include "libclamav/clamav.h"
|
2008-02-08 17:50:44 +00:00
|
|
|
|
2003-07-29 15:48:06 +00:00
|
|
|
void help(void);
|
|
|
|
|
2007-02-25 02:54:38 +00:00
|
|
|
#if defined(C_WINDOWS) && defined(CL_DEBUG)
|
|
|
|
#include <crtdbg.h>
|
|
|
|
#endif
|
|
|
|
|
2007-01-30 21:11:32 +00:00
|
|
|
struct s_info info;
|
2004-03-30 21:11:25 +00:00
|
|
|
short recursion = 0, printinfected = 0, bell = 0;
|
|
|
|
|
2006-05-15 18:30:18 +00:00
|
|
|
int main(int argc, char **argv)
|
2003-07-29 15:48:06 +00:00
|
|
|
{
|
|
|
|
int ds, dms, ret;
|
|
|
|
double mb;
|
|
|
|
struct timeval t1, t2;
|
2007-02-25 02:54:38 +00:00
|
|
|
#ifndef C_WINDOWS
|
2003-07-29 15:48:06 +00:00
|
|
|
struct timezone tz;
|
2008-07-30 15:20:30 +00:00
|
|
|
sigset_t sigset;
|
2007-02-25 02:54:38 +00:00
|
|
|
#endif
|
2008-12-30 10:33:43 +00:00
|
|
|
struct optstruct *opts;
|
|
|
|
const struct optstruct *opt;
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2008-05-05 19:27:28 +00:00
|
|
|
#if defined(C_WINDOWS) && defined(CL_THREAD_SAFE)
|
|
|
|
if(!pthread_win32_process_attach_np()) {
|
|
|
|
mprintf("!Can't start the win32 pthreads layer\n");
|
|
|
|
return 72;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-08-06 13:06:01 +00:00
|
|
|
#if !defined(C_WINDOWS) && !defined(C_BEOS)
|
2008-07-30 15:20:30 +00:00
|
|
|
sigemptyset(&sigset);
|
|
|
|
sigaddset(&sigset, SIGXFSZ);
|
|
|
|
sigprocmask(SIG_SETMASK, &sigset, NULL);
|
|
|
|
#endif
|
|
|
|
|
2008-12-30 10:33:43 +00:00
|
|
|
|
2008-12-30 21:16:02 +00:00
|
|
|
if((opts = optparse(NULL, argc, argv, 1, OPT_CLAMSCAN, 0, NULL)) == NULL) {
|
2008-12-30 10:33:43 +00:00
|
|
|
mprintf("!Can't parse command line options\n");
|
2006-05-15 18:30:18 +00:00
|
|
|
return 40;
|
|
|
|
}
|
|
|
|
|
2008-12-30 10:33:43 +00:00
|
|
|
if(optget(opts, "verbose")->enabled) {
|
2004-03-29 00:00:58 +00:00
|
|
|
mprintf_verbose = 1;
|
|
|
|
logg_verbose = 1;
|
|
|
|
}
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2008-12-30 10:33:43 +00:00
|
|
|
if(optget(opts, "quiet")->enabled)
|
2004-03-30 21:11:25 +00:00
|
|
|
mprintf_quiet = 1;
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2008-12-30 10:33:43 +00:00
|
|
|
if(optget(opts, "stdout")->enabled)
|
2004-03-30 21:11:25 +00:00
|
|
|
mprintf_stdout = 1;
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2006-05-15 18:30:18 +00:00
|
|
|
|
2008-12-30 10:33:43 +00:00
|
|
|
if(optget(opts, "debug")->enabled) {
|
2003-11-09 19:26:44 +00:00
|
|
|
#if defined(C_LINUX)
|
|
|
|
/* njh@bandsman.co.uk: create a dump if needed */
|
|
|
|
struct rlimit rlim;
|
|
|
|
|
|
|
|
rlim.rlim_cur = rlim.rlim_max = RLIM_INFINITY;
|
|
|
|
if(setrlimit(RLIMIT_CORE, &rlim) < 0)
|
|
|
|
perror("setrlimit");
|
|
|
|
#endif
|
|
|
|
cl_debug(); /* enable debug messages */
|
|
|
|
}
|
2003-08-02 22:37:52 +00:00
|
|
|
|
2008-12-30 10:33:43 +00:00
|
|
|
if(optget(opts, "version")->enabled) {
|
|
|
|
print_version(optget(opts, "database")->strarg);
|
|
|
|
optfree(opts);
|
2004-03-13 20:08:10 +00:00
|
|
|
return 0;
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
|
2008-12-30 10:33:43 +00:00
|
|
|
if(optget(opts, "help")->enabled) {
|
|
|
|
optfree(opts);
|
2003-07-29 15:48:06 +00:00
|
|
|
help();
|
2006-05-15 18:30:18 +00:00
|
|
|
return 0;
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
|
2008-12-30 10:33:43 +00:00
|
|
|
if(optget(opts, "recursive")->enabled)
|
2004-03-30 21:11:25 +00:00
|
|
|
recursion = 1;
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2008-12-30 10:33:43 +00:00
|
|
|
if(optget(opts, "infected")->enabled)
|
2004-03-30 21:11:25 +00:00
|
|
|
printinfected = 1;
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2008-12-30 10:33:43 +00:00
|
|
|
if(optget(opts, "bell")->enabled)
|
2004-03-30 21:11:25 +00:00
|
|
|
bell = 1;
|
2004-01-09 01:10:52 +00:00
|
|
|
|
2003-07-29 15:48:06 +00:00
|
|
|
/* initialize logger */
|
2008-12-30 10:33:43 +00:00
|
|
|
if((opt = optget(opts, "log"))->enabled) {
|
|
|
|
logg_file = opt->strarg;
|
2005-06-12 09:27:00 +00:00
|
|
|
if(logg("#\n-------------------------------------------------------------------------------\n\n")) {
|
2003-07-29 15:48:06 +00:00
|
|
|
mprintf("!Problem with internal logger.\n");
|
2008-12-30 10:33:43 +00:00
|
|
|
optfree(opts);
|
2005-05-11 00:54:14 +00:00
|
|
|
return 62;
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
} else
|
2004-03-29 00:00:58 +00:00
|
|
|
logg_file = NULL;
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2009-02-12 15:14:12 +00:00
|
|
|
if(actsetup(opts)) {
|
|
|
|
optfree(opts);
|
|
|
|
logg_close();
|
|
|
|
exit(2);
|
|
|
|
}
|
2006-05-15 18:30:18 +00:00
|
|
|
|
2007-01-30 21:11:32 +00:00
|
|
|
memset(&info, 0, sizeof(struct s_info));
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2007-02-25 02:54:38 +00:00
|
|
|
#ifdef C_WINDOWS
|
|
|
|
_set_fmode(_O_BINARY);
|
|
|
|
#ifdef CL_DEBUG
|
|
|
|
{
|
|
|
|
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
|
|
|
|
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
gettimeofday(&t1, NULL);
|
|
|
|
#else
|
2003-07-29 15:48:06 +00:00
|
|
|
gettimeofday(&t1, &tz);
|
2007-02-25 02:54:38 +00:00
|
|
|
#endif
|
|
|
|
|
2008-12-30 10:33:43 +00:00
|
|
|
ret = scanmanager(opts);
|
2003-07-29 15:48:06 +00:00
|
|
|
|
2008-12-30 10:33:43 +00:00
|
|
|
if(!optget(opts, "no-summary")->enabled) {
|
2007-02-25 02:54:38 +00:00
|
|
|
#ifdef C_WINDOWS
|
|
|
|
gettimeofday(&t2, NULL);
|
|
|
|
#else
|
2003-07-29 15:48:06 +00:00
|
|
|
gettimeofday(&t2, &tz);
|
2007-02-25 02:54:38 +00:00
|
|
|
#endif
|
2003-07-29 15:48:06 +00:00
|
|
|
ds = t2.tv_sec - t1.tv_sec;
|
|
|
|
dms = t2.tv_usec - t1.tv_usec;
|
|
|
|
ds -= (dms < 0) ? (1):(0);
|
|
|
|
dms += (dms < 0) ? (1000000):(0);
|
2005-06-07 01:40:08 +00:00
|
|
|
logg("\n----------- SCAN SUMMARY -----------\n");
|
2007-01-30 21:11:32 +00:00
|
|
|
logg("Known viruses: %u\n", info.sigs);
|
2008-08-04 10:38:24 +00:00
|
|
|
logg("Engine version: %s\n", get_version());
|
2007-01-30 21:11:32 +00:00
|
|
|
logg("Scanned directories: %u\n", info.dirs);
|
|
|
|
logg("Scanned files: %u\n", info.files);
|
|
|
|
logg("Infected files: %u\n", info.ifiles);
|
2009-02-12 15:14:12 +00:00
|
|
|
if(notremoved) {
|
|
|
|
logg("Not removed: %u\n", notremoved);
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
2009-02-12 15:14:12 +00:00
|
|
|
if(notmoved) {
|
|
|
|
logg("Not %s: %u\n", optget(opts, "copy")->enabled ? "moved" : "copied", notmoved);
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
2007-01-30 21:11:32 +00:00
|
|
|
mb = info.blocks * (CL_COUNT_PRECISION / 1024) / 1024.0;
|
2005-06-07 01:40:08 +00:00
|
|
|
logg("Data scanned: %2.2lf MB\n", mb);
|
2007-01-30 21:11:32 +00:00
|
|
|
logg("Time: %u.%3.3u sec (%u m %u s)\n", ds, dms/1000, ds/60, ds%60);
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
|
2008-12-30 10:33:43 +00:00
|
|
|
optfree(opts);
|
2007-02-25 02:54:38 +00:00
|
|
|
|
2008-05-05 19:27:28 +00:00
|
|
|
#if defined(C_WINDOWS) && defined(CL_THREAD_SAFE)
|
|
|
|
if(!pthread_win32_process_detach_np()) {
|
|
|
|
logg("!Can't stop the win32 pthreads layer\n");
|
|
|
|
return 72;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2004-03-13 20:08:10 +00:00
|
|
|
return ret;
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void help(void)
|
|
|
|
{
|
|
|
|
|
|
|
|
mprintf_stdout = 1;
|
|
|
|
|
|
|
|
mprintf("\n");
|
2008-08-04 10:38:24 +00:00
|
|
|
mprintf(" Clam AntiVirus Scanner %s\n", get_version());
|
2007-02-12 21:02:29 +00:00
|
|
|
mprintf(" (C) 2002 - 2007 ClamAV Team - http://www.clamav.net/team\n\n");
|
2003-11-11 22:10:27 +00:00
|
|
|
|
2004-08-18 15:22:48 +00:00
|
|
|
mprintf(" --help -h Print this help screen\n");
|
|
|
|
mprintf(" --version -V Print version number\n");
|
2003-11-11 22:10:27 +00:00
|
|
|
mprintf(" --verbose -v Be verbose\n");
|
2004-08-18 15:22:48 +00:00
|
|
|
mprintf(" --debug Enable libclamav's debug messages\n");
|
|
|
|
mprintf(" --quiet Only output error messages\n");
|
2003-11-11 22:10:27 +00:00
|
|
|
mprintf(" --stdout Write to stdout instead of stderr\n");
|
2004-08-18 15:22:48 +00:00
|
|
|
mprintf(" --no-summary Disable summary at end of scanning\n");
|
|
|
|
mprintf(" --infected -i Only print infected files\n");
|
|
|
|
mprintf(" --bell Sound bell on virus detection\n");
|
2003-07-29 15:48:06 +00:00
|
|
|
mprintf("\n");
|
2004-07-05 23:50:55 +00:00
|
|
|
mprintf(" --tempdir=DIRECTORY Create temporary files in DIRECTORY\n");
|
2008-12-30 10:33:43 +00:00
|
|
|
mprintf(" --leave-temps[=yes/no(*)] Do not remove temporary files\n");
|
2003-11-11 22:10:27 +00:00
|
|
|
mprintf(" --database=FILE/DIR -d FILE/DIR Load virus database from FILE or load\n");
|
2008-12-30 10:33:43 +00:00
|
|
|
mprintf(" all supported db files from DIR\n");
|
2004-02-20 15:49:29 +00:00
|
|
|
mprintf(" --log=FILE -l FILE Save scan report to FILE\n");
|
2008-12-30 10:33:43 +00:00
|
|
|
mprintf(" --recursive[=yes/no(*)] -r Scan subdirectories recursively\n");
|
|
|
|
mprintf(" --remove[=yes/no(*)] Remove infected files. Be careful!\n");
|
2003-11-11 22:10:27 +00:00
|
|
|
mprintf(" --move=DIRECTORY Move infected files into DIRECTORY\n");
|
2006-10-29 14:37:20 +00:00
|
|
|
mprintf(" --copy=DIRECTORY Copy infected files into DIRECTORY\n");
|
2004-05-09 22:11:30 +00:00
|
|
|
#ifdef HAVE_REGEX_H
|
|
|
|
mprintf(" --exclude=REGEX Don't scan file names matching REGEX\n");
|
2005-03-01 01:32:53 +00:00
|
|
|
mprintf(" --exclude-dir=REGEX Don't scan directories matching REGEX\n");
|
2004-05-09 22:11:30 +00:00
|
|
|
mprintf(" --include=REGEX Only scan file names matching REGEX\n");
|
2005-03-01 01:32:53 +00:00
|
|
|
mprintf(" --include-dir=REGEX Only scan directories matching REGEX\n");
|
2004-05-09 22:11:30 +00:00
|
|
|
#else
|
2003-11-11 22:10:27 +00:00
|
|
|
mprintf(" --exclude=PATT Don't scan file names containing PATT\n");
|
2005-03-01 01:32:53 +00:00
|
|
|
mprintf(" --exclude-dir=PATT Don't scan directories containing PATT\n");
|
2003-11-11 22:10:27 +00:00
|
|
|
mprintf(" --include=PATT Only scan file names containing PATT\n");
|
2005-03-01 01:32:53 +00:00
|
|
|
mprintf(" --include-dir=PATT Only scan directories containing PATT\n");
|
2006-04-07 19:22:21 +00:00
|
|
|
#endif
|
2003-07-29 15:48:06 +00:00
|
|
|
mprintf("\n");
|
2008-12-30 10:33:43 +00:00
|
|
|
mprintf(" --detect-pua[=yes/no(*)] Detect Possibly Unwanted Applications\n");
|
2008-07-31 16:26:50 +00:00
|
|
|
mprintf(" --exclude-pua=CAT Skip PUA sigs of category CAT\n");
|
|
|
|
mprintf(" --include-pua=CAT Load PUA sigs of category CAT\n");
|
2008-12-30 10:33:43 +00:00
|
|
|
mprintf(" --detect-structured[=yes/no(*)] Detect structured data (SSN, Credit Card)\n");
|
2008-05-07 10:51:23 +00:00
|
|
|
mprintf(" --structured-ssn-format=X SSN format (0=normal,1=stripped,2=both)\n");
|
|
|
|
mprintf(" --structured-ssn-count=N Min SSN count to generate a detect\n");
|
|
|
|
mprintf(" --structured-cc-count=N Min CC count to generate a detect\n");
|
2008-12-30 10:33:43 +00:00
|
|
|
mprintf(" --scan-mail[=yes(*)/no] Scan mail files\n");
|
|
|
|
mprintf(" --phishing-sigs[=yes(*)/no] Signature-based phishing detection\n");
|
|
|
|
mprintf(" --phishing-scan-urls[=yes(*)/no] URL-based phishing detection\n");
|
|
|
|
mprintf(" --heuristic-scan-precedence[=yes/no(*)] Stop scanning as soon as a heuristic match is found\n");
|
|
|
|
mprintf(" --phishing-ssl[=yes/no(*)] Always block SSL mismatches in URLs (phishing module)\n");
|
|
|
|
mprintf(" --phishing-cloak[=yes/no(*)] Always block cloaked URLs (phishing module)\n");
|
|
|
|
mprintf(" --algorithmic-detection[=yes(*)/no] Algorithmic detection\n");
|
|
|
|
mprintf(" --scan-pe[=yes(*)/no] Scan PE files\n");
|
|
|
|
mprintf(" --scan-elf[=yes(*)/no] Scan ELF files\n");
|
|
|
|
mprintf(" --scan-ole2[=yes(*)/no] Scan OLE2 containers\n");
|
|
|
|
mprintf(" --scan-pdf[=yes(*)/no] Scan PDF files\n");
|
|
|
|
mprintf(" --scan-html[=yes(*)/no] Scan HTML files\n");
|
|
|
|
mprintf(" --scan-archive[=yes(*)/no] Scan archive files (supported by libclamav)\n");
|
|
|
|
mprintf(" --detect-broken[=yes/no(*)] Try to detect broken executable files\n");
|
|
|
|
mprintf(" --block-encrypted[=yes/no(*)] Block encrypted archives\n");
|
|
|
|
mprintf(" --mail-follow-urls[=yes/no(*)] Download and scan URLs\n");
|
2004-08-18 15:22:48 +00:00
|
|
|
mprintf("\n");
|
2008-02-13 02:06:19 +00:00
|
|
|
mprintf(" --max-filesize=#n Files larger than this will be skipped and assumed clean\n");
|
2008-12-30 10:33:43 +00:00
|
|
|
mprintf(" --max-scansize=#n The maximum amount of data to scan for each container file (**)\n");
|
|
|
|
mprintf(" --max-files=#n The maximum number of files to scan for each container file (**)\n");
|
|
|
|
mprintf(" --max-recursion=#n Maximum archive recursion level for container file (**)\n");
|
2005-03-25 22:23:57 +00:00
|
|
|
mprintf(" --max-dir-recursion=#n Maximum directory recursion level\n");
|
2008-06-10 16:59:19 +00:00
|
|
|
|
|
|
|
mprintf("\n");
|
2008-12-30 10:33:43 +00:00
|
|
|
mprintf("(*) Default scan settings\n");
|
|
|
|
mprintf("(**) Certain files (e.g. documents, archives, etc.) may in turn contain other\n");
|
|
|
|
mprintf(" files inside. The above options ensure safe processing of this kind of data.\n\n");
|
2003-07-29 15:48:06 +00:00
|
|
|
}
|