Browse code

add support for CL_SCAN_ALGO

git-svn: trunk@1781

Tomasz Kojm authored on 2005/12/13 03:44:37
Showing 12 changed files
... ...
@@ -1,3 +1,10 @@
1
+Mon Dec 12 19:34:00 CET 2005 (tk)
2
+---------------------------------
3
+  * libclamav: add support for CL_SCAN_ALGO (to control algorithmic detection)
4
+	       Requested by Tomasz Papszun
5
+  * clamscan: --no-algo
6
+  * clamd: ScanAlgo
7
+
1 8
 Sat Dec 10 19:45:48 CET 2005 (tk)
2 9
 ---------------------------------
3 10
   * fix some compiler warnings, patch by Stefan Huehner <stefan*huehner.org>
... ...
@@ -326,6 +326,13 @@ int acceptloop_th(int *socketds, int nsockets, struct cl_node *root, const struc
326 326
 	logg("Archive support disabled.\n");
327 327
     }
328 328
 
329
+    if(cfgopt(copt, "ScanAlgo")->enabled) {
330
+	logg("Algorithmic detection enabled.\n");
331
+	options |= CL_SCAN_ALGO;
332
+    } else {
333
+	logg("Algorithmic detection disabled.\n");
334
+    }
335
+
329 336
     if(cfgopt(copt, "ScanPE")->enabled) {
330 337
 	logg("Portable Executable support enabled.\n");
331 338
 	options |= CL_SCAN_PE;
... ...
@@ -227,6 +227,7 @@ void help(void)
227 227
     mprintf("\n");
228 228
     mprintf("    --no-mail                            Disable mail file support\n");
229 229
     mprintf("    --no-phishing                        Disable phishing detection\n");
230
+    mprintf("    --no-algo                            Disable algorithmic detection\n");
230 231
     mprintf("    --no-pe                              Disable PE analysis\n");
231 232
     mprintf("    --no-ole2                            Disable OLE2 support\n");
232 233
     mprintf("    --no-html                            Disable HTML support\n");
... ...
@@ -191,6 +191,11 @@ int scanmanager(const struct optstruct *opt)
191 191
 #endif
192 192
     }
193 193
 
194
+    if(optl(opt, "no-algo"))
195
+	options &= ~CL_SCAN_ALGO;
196
+    else
197
+	options |= CL_SCAN_ALGO;
198
+
194 199
 #ifdef C_LINUX
195 200
     procdev = (dev_t) 0;
196 201
     if(stat("/proc", &sb) != -1 && !sb.st_size)
... ...
@@ -1,5 +1,5 @@
1 1
 /*
2
- *  Copyright (C) 2001-2002 Tomasz Kojm <zolw@konarski.edu.pl>
2
+ *  Copyright (C) 2001 - 2005 Tomasz Kojm <tkojm@clamav.net>
3 3
  *
4 4
  *  This program is free software; you can redistribute it and/or modify
5 5
  *  it under the terms of the GNU General Public License as published by
... ...
@@ -105,6 +105,7 @@ int main(int argc, char **argv)
105 105
 	    {"no-mail", 0, 0, 0},
106 106
 	    {"mail-follow-urls", 0, 0, 0},
107 107
 	    {"no-phishing", 0, 0, 0},
108
+	    {"no-algo", 0, 0, 0},
108 109
 	    {"unzip", 2, 0, 0},
109 110
 	    {"unrar", 2, 0, 0},
110 111
 	    {"unace", 2, 0, 0}, /* not used */
... ...
@@ -189,10 +189,10 @@ Limit data port range.
189 189
 .br 
190 190
 Default: 2048
191 191
 .TP 
192
-\fBDisableDefaultScanOptions\fR
193
-By default clamd uses scan options recommended by libclamav. This option disables recommended options and allows you to enable selected options. DO NOT ENABLE IT unless you know what you are doing.
192
+\fBScanAlgo\fR
193
+In some cases (eg. complex malware, exploits in graphic files, and others), ClamAV uses special algorithms to provide accurate detection. This option controls the algorithmic detection.
194 194
 .br 
195
-Default: disabled
195
+Default: yes
196 196
 .TP 
197 197
 \fBScanPE\fR
198 198
 PE stands for Portable Executable \- it's an executable file format used in all 32\-bit versions of Windows operating systems. This option allows ClamAV to perform a deeper analysis of executable files and it's also required for decompression of popular executable packers such as UPX.
... ...
@@ -73,6 +73,9 @@ Disable scanning of mail files.
73 73
 \fB\-\-no\-phishing\fR
74 74
 Disable detection of phishing messages.
75 75
 .TP 
76
+\fB\-\-no\-algo\fR
77
+In some cases (eg. complex malware, exploits in graphic files, and others), ClamAV uses special algorithms to provide accurate detection. This option disables the algorithmic detection.
78
+.TP 
76 79
 \fB\-\-no\-pe\fR
77 80
 PE stands for Portable Executable \- it's an executable file format used in all 32\-bit versions of Windows operating systems. By default ClamAV performs deeper analysis of executable files and attempts to decompress popular executable packers such as UPX, Petite, and FSG. This option \fBdisables\fR PE support and should be used with care!
78 81
 .TP 
... ...
@@ -162,6 +162,12 @@ LocalSocket /tmp/clamd
162 162
 # Default: no
163 163
 #LeaveTemporaryFiles yes
164 164
 
165
+# In some cases (eg. complex malware, exploits in graphic files, and others),
166
+# ClamAV uses special algorithms to provide accurate detection. This option
167
+# controls the algorithmic detection.
168
+# Default: yes
169
+#ScanAlgo yes
170
+
165 171
 ##
166 172
 ## Executable files
167 173
 ##
... ...
@@ -78,9 +78,10 @@ extern "C"
78 78
 #define CL_SCAN_BLOCKBROKEN	64
79 79
 #define CL_SCAN_MAILURL		128
80 80
 #define CL_SCAN_BLOCKMAX	256
81
+#define CL_SCAN_ALGO		512
81 82
 
82 83
 /* recommended options */
83
-#define CL_SCAN_STDOPT		(CL_SCAN_ARCHIVE | CL_SCAN_MAIL | CL_SCAN_OLE2 | CL_SCAN_HTML | CL_SCAN_PE) 
84
+#define CL_SCAN_STDOPT		(CL_SCAN_ARCHIVE | CL_SCAN_MAIL | CL_SCAN_OLE2 | CL_SCAN_HTML | CL_SCAN_PE | CL_SCAN_ALGO) 
84 85
 
85 86
 /* aliases for backward compatibility */
86 87
 #define CL_RAW		CL_SCAN_RAW
... ...
@@ -52,6 +52,7 @@
52 52
 
53 53
 #define DETECT_BROKEN		    (options & CL_SCAN_BLOCKBROKEN)
54 54
 #define BLOCKMAX		    (options & CL_SCAN_BLOCKMAX)
55
+#define SCAN_ALGO		    (options & CL_SCAN_ALGO)
55 56
 
56 57
 #define UPX_NRV2B "\x11\xdb\x11\xc9\x01\xdb\x75\x07\x8b\x1e\x83\xee\xfc\x11\xdb\x11\xc9\x11\xc9\x75\x20\x41\x01\xdb"
57 58
 #define UPX_NRV2D "\x83\xf0\xff\x74\x78\xd1\xf8\x89\xc5\xeb\x0b\x01\xdb\x75\x07\x8b\x1e\x83\xee\xfc\x11\xdb\x11\xc9"
... ...
@@ -567,7 +568,7 @@ int cli_scanpe(int desc, const char **virname, long int *scanned, const struct c
567 567
     /* Attempt to detect some popular polymorphic viruses */
568 568
 
569 569
     /* W32.Parite.B */
570
-    if(!dll && ep == EC32(section_hdr[nsections - 1].PointerToRawData)) {
570
+    if(SCAN_ALGO && !dll && ep == EC32(section_hdr[nsections - 1].PointerToRawData)) {
571 571
 	lseek(desc, ep, SEEK_SET);
572 572
 	if(read(desc, buff, 4096) == 4096) {
573 573
 		const char *pt = cli_memstr(buff, 4040, "\x47\x65\x74\x50\x72\x6f\x63\x41\x64\x64\x72\x65\x73\x73\x00", 15);
... ...
@@ -585,7 +586,7 @@ int cli_scanpe(int desc, const char **virname, long int *scanned, const struct c
585 585
     }
586 586
 
587 587
     /* W32.Magistr.A/B */
588
-    if(!dll && (EC32(section_hdr[nsections - 1].Characteristics) & 0x80000000)) {
588
+    if(SCAN_ALGO && !dll && (EC32(section_hdr[nsections - 1].Characteristics) & 0x80000000)) {
589 589
 	    uint32_t rsize, vsize;
590 590
 
591 591
 	rsize = EC32(section_hdr[nsections - 1].SizeOfRawData);
... ...
@@ -96,6 +96,7 @@ extern int cli_mbox(const char *dir, int desc, unsigned int options); /* FIXME *
96 96
 #define SCAN_OLE2	    (options & CL_SCAN_OLE2)
97 97
 #define SCAN_HTML	    (options & CL_SCAN_HTML)
98 98
 #define SCAN_PE		    (options & CL_SCAN_PE)
99
+#define SCAN_ALGO 	    (options & CL_SCAN_ALGO)
99 100
 #define DETECT_ENCRYPTED    (options & CL_SCAN_BLOCKENCRYPTED)
100 101
 #define BLOCKMAX	    (options & CL_SCAN_BLOCKMAX)
101 102
 
... ...
@@ -1599,11 +1600,13 @@ int cli_magic_scandesc(int desc, const char **virname, long int *scanned, const
1599 1599
 	    break;
1600 1600
 
1601 1601
 	case CL_TYPE_RIFF:
1602
-	    ret = cli_scanriff(desc, virname);
1602
+	    if(SCAN_ALGO)
1603
+		ret = cli_scanriff(desc, virname);
1603 1604
 	    break;
1604 1605
 
1605 1606
 	case CL_TYPE_GRAPHICS:
1606
-	    ret = cli_scanjpeg(desc, virname);
1607
+	    if(SCAN_ALGO)
1608
+		ret = cli_scanjpeg(desc, virname);
1607 1609
 	    break;
1608 1610
 
1609 1611
 	case CL_TYPE_PDF:
... ...
@@ -58,6 +58,7 @@ struct cfgstruct *getcfg(const char *cfgfile, int verbose)
58 58
 	    {"ScanMail", OPT_BOOL, 1, NULL, 0},
59 59
 	    {"MailFollowURLs", OPT_BOOL, 0, NULL, 0},
60 60
 	    {"DetectPhishing", OPT_BOOL, 1, NULL, 0},
61
+	    {"ScanAlgo", OPT_BOOL, 1, NULL, 0},
61 62
 	    {"ScanHTML", OPT_BOOL, 1, NULL, 0},
62 63
 	    {"ScanOLE2", OPT_BOOL, 1, NULL, 0},
63 64
 	    {"ScanArchive", OPT_BOOL, 1, NULL, 0},