git-svn: trunk@3570
Tomasz Kojm authored on 2008/02/01 09:17:44... | ... |
@@ -1,3 +1,8 @@ |
1 |
+Fri Feb 1 00:58:05 CET 2008 (tk) |
|
2 |
+--------------------------------- |
|
3 |
+ * libclamav: ndb sigs: add new target type (7) for ASCII files; handle |
|
4 |
+ sigs for targets 2..7 with A-C only |
|
5 |
+ |
|
1 | 6 |
Thu Jan 31 17:44:35 EET 2008 (edwin) |
2 | 7 |
------------------------------------ |
3 | 8 |
* libclamav/phishcheck.c, docs/phishsigs_howto.tex: ignore invalid URLs |
... | ... |
@@ -1,4 +1,7 @@ |
1 | 1 |
/* |
2 |
+ * Copyright (C) 2007 - 2008 Sourcefire, Inc. |
|
3 |
+ * Author: Tomasz Kojm <tkojm@clamav.net> |
|
4 |
+ * |
|
2 | 5 |
* Copyright (C) 2002 - 2007 Tomasz Kojm <tkojm@clamav.net> |
3 | 6 |
* |
4 | 7 |
* This program is free software; you can redistribute it and/or modify |
... | ... |
@@ -42,7 +45,6 @@ |
42 | 42 |
#include "str.h" |
43 | 43 |
#include "cltypes.h" |
44 | 44 |
|
45 |
-static cli_file_t targettab[CL_TARGET_TABLE_SIZE] = { 0, CL_TYPE_MSEXE, CL_TYPE_MSOLE2, CL_TYPE_HTML, CL_TYPE_MAIL, CL_TYPE_GRAPHICS, CL_TYPE_ELF }; |
|
46 | 45 |
|
47 | 46 |
int cli_scanbuff(const unsigned char *buffer, uint32_t length, const char **virname, const struct cl_engine *engine, cli_file_t ftype) |
48 | 47 |
{ |
... | ... |
@@ -60,8 +62,8 @@ int cli_scanbuff(const unsigned char *buffer, uint32_t length, const char **virn |
60 | 60 |
groot = engine->root[0]; /* generic signatures */ |
61 | 61 |
|
62 | 62 |
if(ftype) { |
63 |
- for(i = 1; i < CL_TARGET_TABLE_SIZE; i++) { |
|
64 |
- if(targettab[i] == ftype) { |
|
63 |
+ for(i = 1; i < CLI_MTARGETS; i++) { |
|
64 |
+ if(cli_mtargets[i].target == ftype) { |
|
65 | 65 |
troot = engine->root[i]; |
66 | 66 |
break; |
67 | 67 |
} |
... | ... |
@@ -266,8 +268,8 @@ int cli_scandesc(int desc, cli_ctx *ctx, uint8_t otfrec, cli_file_t ftype, uint8 |
266 | 266 |
groot = ctx->engine->root[0]; /* generic signatures */ |
267 | 267 |
|
268 | 268 |
if(ftype) { |
269 |
- for(i = 1; i < CL_TARGET_TABLE_SIZE; i++) { |
|
270 |
- if(targettab[i] == ftype) { |
|
269 |
+ for(i = 1; i < CLI_MTARGETS; i++) { |
|
270 |
+ if(cli_mtargets[i].target == ftype) { |
|
271 | 271 |
troot = ctx->engine->root[i]; |
272 | 272 |
break; |
273 | 273 |
} |
... | ... |
@@ -1,4 +1,7 @@ |
1 | 1 |
/* |
2 |
+ * Copyright (C) 2007 - 2008 Sourcefire, Inc. |
|
3 |
+ * Author: Tomasz Kojm <tkojm@clamav.net> |
|
4 |
+ * |
|
2 | 5 |
* Copyright (C) 2002 - 2007 Tomasz Kojm <tkojm@clamav.net> |
3 | 6 |
* |
4 | 7 |
* This program is free software; you can redistribute it and/or modify |
... | ... |
@@ -43,6 +46,7 @@ struct cli_matcher { |
43 | 43 |
uint8_t *bm_shift; |
44 | 44 |
struct cli_bm_patt **bm_suffix; |
45 | 45 |
uint32_t *soff, soff_len; /* for PE section sigs */ |
46 |
+ uint32_t bm_patterns; |
|
46 | 47 |
|
47 | 48 |
/* Extended Aho-Corasick */ |
48 | 49 |
uint32_t ac_partsigs, ac_nodes, ac_patterns; |
... | ... |
@@ -61,7 +65,24 @@ struct cli_meta_node { |
61 | 61 |
unsigned int crc32, fileno, encrypted, maxdepth; |
62 | 62 |
}; |
63 | 63 |
|
64 |
-#define CL_TARGET_TABLE_SIZE 7 |
|
64 |
+struct cli_mtarget { |
|
65 |
+ cli_file_t target; |
|
66 |
+ const char *name; |
|
67 |
+ uint8_t idx; /* idx of matcher */ |
|
68 |
+ uint8_t ac_only; |
|
69 |
+}; |
|
70 |
+ |
|
71 |
+#define CLI_MTARGETS 8 |
|
72 |
+static const struct cli_mtarget cli_mtargets[CLI_MTARGETS] = { |
|
73 |
+ { 0, "GENERIC", 0, 0 }, |
|
74 |
+ { CL_TYPE_MSEXE, "PE", 1, 0 }, |
|
75 |
+ { CL_TYPE_MSOLE2, "OLE2", 2, 1 }, |
|
76 |
+ { CL_TYPE_HTML, "HTML", 3, 1 }, |
|
77 |
+ { CL_TYPE_MAIL, "MAIL", 4, 1 }, |
|
78 |
+ { CL_TYPE_GRAPHICS, "GRAPHICS", 5, 1 }, |
|
79 |
+ { CL_TYPE_ELF, "ELF", 6, 1 }, |
|
80 |
+ { CL_TYPE_TEXT_ASCII, "ASCII", 7, 1 } |
|
81 |
+}; |
|
65 | 82 |
|
66 | 83 |
struct cli_target_info { |
67 | 84 |
off_t fsize; |
... | ... |
@@ -1,4 +1,7 @@ |
1 | 1 |
/* |
2 |
+ * Copyright (C) 2007 - 2008 Sourcefire, Inc. |
|
3 |
+ * Author: Tomasz Kojm <tkojm@clamav.net> |
|
4 |
+ * |
|
2 | 5 |
* Copyright (C) 2002 - 2007 Tomasz Kojm <tkojm@clamav.net> |
3 | 6 |
* |
4 | 7 |
* This program is free software; you can redistribute it and/or modify |
... | ... |
@@ -294,7 +297,7 @@ int cli_initengine(struct cl_engine **engine, unsigned int options) |
294 | 294 |
|
295 | 295 |
(*engine)->refcount = 1; |
296 | 296 |
|
297 |
- (*engine)->root = cli_calloc(CL_TARGET_TABLE_SIZE, sizeof(struct cli_matcher *)); |
|
297 |
+ (*engine)->root = cli_calloc(CLI_MTARGETS, sizeof(struct cli_matcher *)); |
|
298 | 298 |
if(!(*engine)->root) { |
299 | 299 |
/* no need to free previously allocated memory here */ |
300 | 300 |
cli_errmsg("Can't allocate memory for roots!\n"); |
... | ... |
@@ -321,7 +324,7 @@ static int cli_initroots(struct cl_engine *engine, unsigned int options) |
321 | 321 |
struct cli_matcher *root; |
322 | 322 |
|
323 | 323 |
|
324 |
- for(i = 0; i < CL_TARGET_TABLE_SIZE; i++) { |
|
324 |
+ for(i = 0; i < CLI_MTARGETS; i++) { |
|
325 | 325 |
if(!engine->root[i]) { |
326 | 326 |
cli_dbgmsg("Initializing engine->root[%d]\n", i); |
327 | 327 |
root = engine->root[i] = (struct cli_matcher *) cli_calloc(1, sizeof(struct cli_matcher)); |
... | ... |
@@ -330,10 +333,8 @@ static int cli_initroots(struct cl_engine *engine, unsigned int options) |
330 | 330 |
return CL_EMEM; |
331 | 331 |
} |
332 | 332 |
|
333 |
- if(options & CL_DB_ACONLY) { |
|
334 |
- cli_dbgmsg("cli_initroots: Only using AC pattern matcher.\n"); |
|
333 |
+ if(cli_mtargets[i].ac_only || (options & CL_DB_ACONLY)) |
|
335 | 334 |
root->ac_only = 1; |
336 |
- } |
|
337 | 335 |
|
338 | 336 |
cli_dbgmsg("Initialising AC pattern matcher of root[%d]\n", i); |
339 | 337 |
if((ret = cli_ac_init(root, cli_ac_mindepth, cli_ac_maxdepth))) { |
... | ... |
@@ -570,7 +571,7 @@ static int cli_loadndb(FILE *fs, struct cl_engine **engine, unsigned int *signo, |
570 | 570 |
} |
571 | 571 |
target = (unsigned short) atoi(pt); |
572 | 572 |
|
573 |
- if(target >= CL_TARGET_TABLE_SIZE) { |
|
573 |
+ if(target >= CLI_MTARGETS) { |
|
574 | 574 |
cli_dbgmsg("Not supported target type in signature for %s\n", virname); |
575 | 575 |
sigs--; |
576 | 576 |
continue; |
... | ... |
@@ -1509,7 +1510,7 @@ void cl_free(struct cl_engine *engine) |
1509 | 1509 |
#endif |
1510 | 1510 |
|
1511 | 1511 |
if(engine->root) { |
1512 |
- for(i = 0; i < CL_TARGET_TABLE_SIZE; i++) { |
|
1512 |
+ for(i = 0; i < CLI_MTARGETS; i++) { |
|
1513 | 1513 |
if((root = engine->root[i])) { |
1514 | 1514 |
if(!root->ac_only) |
1515 | 1515 |
cli_bm_free(root); |
... | ... |
@@ -1580,10 +1581,13 @@ int cl_build(struct cl_engine *engine) |
1580 | 1580 |
if((ret = cli_loadft(NULL, &engine, 0, 1, NULL, 0))) |
1581 | 1581 |
return ret; |
1582 | 1582 |
|
1583 |
- for(i = 0; i < CL_TARGET_TABLE_SIZE; i++) |
|
1584 |
- if((root = engine->root[i])) |
|
1585 |
- cli_ac_buildtrie(root); |
|
1586 |
- /* FIXME: check return values of cli_ac_buildtree */ |
|
1583 |
+ for(i = 0; i < CLI_MTARGETS; i++) { |
|
1584 |
+ if((root = engine->root[i])) { |
|
1585 |
+ if((ret = cli_ac_buildtrie(root))) |
|
1586 |
+ return ret; |
|
1587 |
+ cli_dbgmsg("matcher[%u]: %s: AC sigs: %u BM sigs: %u %s\n", i, cli_mtargets[i].name, root->ac_patterns, root->bm_patterns, root->ac_only ? "(ac_only mode)" : ""); |
|
1588 |
+ } |
|
1589 |
+ } |
|
1587 | 1590 |
|
1588 | 1591 |
cli_dconf_print(engine->dconf); |
1589 | 1592 |
|