~ubuntu-branches/ubuntu/vivid/clamav/vivid-updates

« back to all changes in this revision

Viewing changes to examples/fileprop_analysis/notpdf_sample.c

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2015-05-04 11:32:16 UTC
  • mfrom: (0.47.16) (154.1.2 vivid-proposed)
  • Revision ID: package-import@ubuntu.com-20150504113216-3q2p3lp7gviir53h
Tags: 0.98.7+dfsg-0ubuntu0.15.04.1
* Updated to 0.98.7 to fix multiple issues
  - CVE-2015-2170
  - CVE-2015-2221
  - CVE-2015-2222
  - CVE-2015-2305
  - CVE-2015-2668
* Refreshed patches for 0.98.7:
  - d/p/0005-libclamav-use-libmspack.patch
  - d/p/0007-fix-ssize_t-size_t-off_t-printf-modifier.patch
  - d/p/0008-hardcode-LLVM-linker-flag-because-llvm-config-return.patch
  - d/p/0015-llvm-don-t-use-system-libs.patch
* Removed upstreamed patches:
  - d/p/0012-remove-AC_CONFIG_SRCDIR-llvm-configure-from-libclama.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
VIRUSNAME_PREFIX("SUBMIT.NotPDF")
2
2
VIRUSNAMES("InActive", "Submit")
3
3
 
4
 
/* Target type is 13, internal JSON properties */
5
 
TARGET(13)
 
4
/* Target type is 0, all relevant files */
 
5
TARGET(0)
 
6
 
 
7
/* Declares to run bytecode only for preclassification (affecting only preclass files) */
 
8
PRECLASS_HOOK_DECLARE
6
9
 
7
10
/* JSON API call will require FUNC_LEVEL_098_5 = 78 */
8
 
FUNCTIONALITY_LEVEL_MIN(FUNC_LEVEL_098_5)
9
 
 
10
 
SIGNATURES_DECL_BEGIN
11
 
DECLARE_SIGNATURE(sig1)
12
 
DECLARE_SIGNATURE(sig2)
13
 
SIGNATURES_DECL_END
14
 
 
15
 
SIGNATURES_DEF_BEGIN
16
 
/* search @offset 0 : '{ "Magic": "CLAMJSON' */
17
 
/* this can be readjusted for specific filetypes */
18
 
DEFINE_SIGNATURE(sig1, "0:7b20224d61676963223a2022434c414d4a534f4e")
19
 
/* search '"RootFileType": "CL_TYPE_PDF"' */
20
 
DEFINE_SIGNATURE(sig2, "22526f6f7446696c6554797065223a2022434c5f545950455f50444622")
21
 
SIGNATURES_END
22
 
 
23
 
bool logical_trigger(void)
24
 
{
25
 
    return matches(Signatures.sig1) && !matches(Signatures.sig2);
26
 
}
 
11
/* PRECLASS_HOOK_DECLARE will require FUNC_LEVEL_098_7 = 80 */
 
12
FUNCTIONALITY_LEVEL_MIN(FUNC_LEVEL_098_7)
27
13
 
28
14
#define STR_MAXLEN 256
29
15
 
30
16
int entrypoint ()
31
17
{
32
 
    foundVirus("Submit");
 
18
    int32_t type, obj, strlen;
 
19
    char str[STR_MAXLEN];
 
20
 
 
21
    /* check is json is available, alerts on inactive (optional) */
 
22
    if (!json_is_active()) {
 
23
        return -1;
 
24
    }
 
25
 
 
26
    /* acquire array of internal contained objects */
 
27
    obj = json_get_object("FileType", 8, 0);
 
28
    if (obj <= 0) return -1;
 
29
 
 
30
    /* acquire and check type */
 
31
    type = json_get_type(obj);
 
32
    if (type == JSON_TYPE_STRING) {
 
33
        /* acquire string length, note +1 is for the NULL terminator */
 
34
        strlen = json_get_string_length(obj)+1;
 
35
        /* prevent buffer overflow */
 
36
        if (strlen > STR_MAXLEN)
 
37
            strlen = STR_MAXLEN;
 
38
        /* acquire string data, note strlen includes NULL terminator */
 
39
        if (json_get_string(str, strlen, obj)) {
 
40
            /* debug print str (with '\n' and prepended message */
 
41
            debug_print_str(str,strlen);
 
42
 
 
43
            /* check the contained object's type */
 
44
            if (!(strlen == 12) || !memcmp(str, "CL_TYPE_PDF", 12)) {
 
45
                foundVirus("Submit");
 
46
            }
 
47
        }
 
48
    }
 
49
 
33
50
    return 0;
34
51
}