~ubuntu-branches/ubuntu/trusty/clamav/trusty-security

« back to all changes in this revision

Viewing changes to sigtool/sigtool.c

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2014-11-20 14:29:18 UTC
  • mfrom: (0.47.10) (137.1.1 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20141120142918-slpjc6vqq139e49n
Tags: 0.98.5+addedllvm-0ubuntu0.14.04.1
* Updated to 0.98.5 to fix security issues, including CVE-2013-6497.
* Removed patches no longer needed:
  - d/p/0002-Sebastian-Andrzej-Siewior.patch
  - d/p/0003-configure-use-pkg-config-for-check-so-test-is-detect.patch
  - d/p/0004-Stop-using-a-cargo-culted-syscall-table-and-trust-th.patch
  - d/p/0005-configure.ac-patches-to-got-with-autoreconf-and-auto.patch
  - d/p/0006-Fix-STAT64-definition-and-add-missing-includes.patch
* Added patches from vivid to fix FTBFS, .so version and other issues:
  - d/p/0002-Add-an-additional-n-after-the-number-in-the-pidfile.patch
  - d/p/0003-unit_tests-increment-test-timeout-from-40secs-to-5mi.patch
  - d/p/0006-remove-unnecessary-harmful-flags-from-libclamav.pc.patch
  - d/p/0010-hardcode-LLVM-linker-flag-because-llvm-config-return.patch
  - d/p/0017-Bump-.so-version-number.patch
  - d/p/0018-llvm-don-t-use-system-libs.patch
* debian/clamav-docs.docs: use wildcards, as some docs have changed.
* debian/clamav-base.postinst.in: added new options.
* debian/clamav-base.config.in: added new options.
* debian/clamav-base.templates: added new options.
* debian/control: added libssl-dev BuildDepends.
* clamav-testfiles.install: removed rar files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
 
2
 *  Copyright (C) 2014 Cisco Systems, Inc.
2
3
 *  Copyright (C) 2007 - 2013 Sourcefire, Inc.
3
4
 *  Copyright (C) 2002 - 2007 Tomasz Kojm <tkojm@clamav.net>
4
5
 *  CDIFF code (C) 2006 Sensory Networks, Inc.
24
25
#include "clamav-config.h"
25
26
#endif
26
27
 
27
 
#define _GNU_SOURCE
28
 
 
29
28
#include <stdio.h>
30
29
#include <stdlib.h>
31
30
#include <string.h>
59
58
#include "shared/optparser.h"
60
59
#include "shared/misc.h"
61
60
#include "shared/cdiff.h"
62
 
#include "libclamav/sha1.h"
63
 
#include "libclamav/sha256.h"
64
61
#include "shared/tar.h"
65
62
 
66
63
#include "libclamav/clamav.h"
306
303
            return NULL;
307
304
        }
308
305
#endif
309
 
        if(scanf("%as", &pt) == EOF || !pt) {
 
306
        if(scanf("%30s", pass) == EOF || !pt) {
310
307
            mprintf("!getdsig: Can't get password\n");
311
308
#ifdef HAVE_TERMIOS_H
312
309
            tcsetattr(0, TCSAFLUSH, &old);
313
310
#endif
314
311
            return NULL;
315
312
        }
316
 
        strncpy(pass, pt, sizeof(pass));
317
 
        pass[sizeof(pass)-1]='\0';
318
 
        free(pt);
319
313
 
320
314
#ifdef HAVE_TERMIOS_H
321
315
        if(tcsetattr(0, TCSAFLUSH, &old)) {
379
373
            closesocket(sockd);
380
374
            return NULL;
381
375
        } else {
382
 
            mprintf("Signature received (length = %lu)\n", strlen(buff) - 10);
 
376
            mprintf("Signature received (length = %lu)\n", (unsigned long)strlen(buff) - 10);
383
377
        }
384
378
    } else {
385
379
        mprintf("!getdsig: Communication error with remote server\n");
400
394
        unsigned int i, bytes;
401
395
        unsigned char digest[32], buffer[FILEBUFF];
402
396
        char *sha;
403
 
        SHA256_CTX ctx;
404
 
 
405
 
 
406
 
    sha256_init(&ctx);
 
397
        void *ctx;
 
398
 
 
399
    ctx = cl_hash_init("sha256");
 
400
    if (!(ctx))
 
401
        return NULL;
 
402
 
407
403
    if(!(fh = fopen(file, "rb"))) {
408
404
        mprintf("!sha256file: Can't open file %s\n", file);
 
405
    cl_hash_destroy(ctx);
409
406
        return NULL;
410
407
    }
411
408
    if(size)
412
409
        *size = 0;
413
410
    while((bytes = fread(buffer, 1, sizeof(buffer), fh))) {
414
 
        sha256_update(&ctx, buffer, bytes);
 
411
        cl_update_hash(ctx, buffer, bytes);
415
412
        if(size)
416
413
            *size += bytes;
417
414
    }
418
 
    sha256_final(&ctx, digest);
 
415
    cl_finish_hash(ctx, digest);
419
416
    sha = (char *) malloc(65);
420
417
    if(!sha)
421
418
    {
435
432
        unsigned int i, bytes;
436
433
        char file[32], *pt, dbfile[32];
437
434
        unsigned char digest[32], buffer[FILEBUFF];
438
 
        SHA256_CTX ctx;
 
435
        void *ctx;
439
436
 
440
437
    snprintf(file, sizeof(file), "%s.info", dbname);
441
438
    if(!access(file, R_OK)) {
492
489
    }
493
490
    if(!optget(opts, "unsigned")->enabled) {
494
491
        rewind(fh);
495
 
        sha256_init(&ctx);
 
492
    ctx = cl_hash_init("sha256");
 
493
    if (!(ctx)) {
 
494
        fclose(fh);
 
495
        return -1;
 
496
    }
 
497
 
496
498
        while((bytes = fread(buffer, 1, sizeof(buffer), fh)))
497
 
            sha256_update(&ctx, buffer, bytes);
498
 
        sha256_final(&ctx, digest);
 
499
            cl_update_hash(ctx, buffer, bytes);
 
500
        cl_finish_hash(ctx, digest);
499
501
        if(!(pt = getdsig(optget(opts, "server")->strarg, builder, digest, 32, 3))) {
500
502
            mprintf("!writeinfo: Can't get digital signature from remote server\n");
501
503
            fclose(fh);
515
517
{
516
518
        char *cdiff, *pt, buffer[FILEBUFF];
517
519
        unsigned char digest[32];
518
 
        SHA256_CTX ctx;
 
520
        void *ctx;
519
521
        STATBUF sb;
520
522
        FILE *scripth, *cdiffh;
521
523
        gzFile gzh;
599
601
        return -1;
600
602
    }
601
603
 
602
 
    sha256_init(&ctx);
 
604
    ctx = cl_hash_init("sha256");
 
605
    if (!(ctx)) {
 
606
        unlink(cdiff);
 
607
        free(cdiff);
 
608
        fclose(cdiffh);
 
609
        return -1;
 
610
    }
603
611
 
604
612
    while((bytes = fread(buffer, 1, sizeof(buffer), cdiffh)))
605
 
        sha256_update(&ctx, (unsigned char *) buffer, bytes);
 
613
        cl_update_hash(ctx, (unsigned char *) buffer, bytes);
606
614
 
607
615
    fclose(cdiffh);
608
 
    sha256_final(&ctx, digest);
 
616
    cl_finish_hash(ctx, digest);
609
617
 
610
618
    if(!(pt = getdsig(optget(opts, "server")->strarg, builder, digest, 32, 2))) {
611
619
        mprintf("!script2cdiff: Can't get digital signature from remote server\n");
704
712
                        dblist2 = (char **) realloc(dblist2, (dblist2cnt + 1) * sizeof(char *));
705
713
                        if(!dblist2) { /* dblist2 leaked but we don't really care */
706
714
                            mprintf("!build: Memory allocation error\n");
 
715
                            closedir(dd);
707
716
                            return -1;
708
717
                        }
709
718
                        dblist2[dblist2cnt] = strdup(dent->d_name);
793
802
        version = oldcvd->version + 1;
794
803
        oldsigs = oldcvd->sigs;
795
804
        cl_cvdfree(oldcvd);
 
805
    } else if (optget(opts, "cvd-version")->numarg != 0) {
 
806
        version = optget(opts, "cvd-version")->numarg;
796
807
    } else {
797
808
        mprintf("Version number: ");
798
809
        if(scanf("%u", &version) == EOF) {
835
846
        builder[sizeof(builder)-1]='\0';
836
847
    } else {
837
848
        mprintf("Builder name: ");
838
 
        if(scanf("%as", &pt) == EOF || !pt) {
 
849
        if(scanf("%32s", builder) == EOF || !pt) {
839
850
            mprintf("!build: Can't get builder name\n");
 
851
            free(dblist2);
840
852
            return -1;
841
853
        }
842
 
        strncpy(builder, pt, sizeof(builder));
843
 
        builder[sizeof(builder)-1]='\0';
844
 
        free(pt);
845
854
    }
846
855
 
847
856
    /* add builder */
1116
1125
        name[sizeof(name)-1]='\0';
1117
1126
    }
1118
1127
 
 
1128
    if (cl_cvdverify(name) != CL_SUCCESS) {
 
1129
        mprintf("!unpack: %s is not a valid CVD\n", name);
 
1130
        return -1;
 
1131
    }
 
1132
 
1119
1133
    if(cli_cvdunpack(name, ".") == -1) {
1120
1134
        mprintf("!unpack: Can't unpack file %s\n", name);
1121
1135
        return -1;
1509
1523
    }
1510
1524
    if(!(ctx = convenience_ctx(fd))) {
1511
1525
        close(fd);
 
1526
    free(dir);
1512
1527
        return -1;
1513
1528
    }
1514
1529
    if(cli_ole2_extract(dir, ctx, &vba)) {
1515
 
        destroy_ctx(ctx);
 
1530
        destroy_ctx(-1, ctx);
1516
1531
        cli_rmdirs(dir);
1517
1532
        free(dir);
1518
1533
        return -1;
1519
1534
    }
1520
 
    destroy_ctx(ctx);
 
1535
    destroy_ctx(-1, ctx);
1521
1536
    if (vba) 
1522
1537
      sigtool_vba_scandir(dir, hex_output, vba);
1523
1538
    cli_rmdirs(dir);
2522
2537
            case 9:
2523
2538
                mprintf("MACHO\n");
2524
2539
                break;
 
2540
            case 10:
 
2541
                mprintf("PDF\n");
 
2542
                break;
 
2543
            case 11:
 
2544
                mprintf("FLASH\n");
 
2545
                break;
 
2546
            case 12:
 
2547
                mprintf("JAVA CLASS\n");
 
2548
                break;
2525
2549
            default:
2526
2550
                mprintf("!decodesig: Invalid target type\n");
2527
2551
                return -1;
2788
2812
    char * filename = NULL;
2789
2813
    STATBUF sb;
2790
2814
    const char * fmptr;
2791
 
    SHA1Context sha1;
2792
2815
    struct cl_engine *engine;
2793
2816
    cli_ctx ctx;
2794
2817
    int fd, ret;
2869
2892
    }
2870
2893
 
2871
2894
    /* Generate SHA1 */
2872
 
    SHA1Init(&sha1);
2873
 
    SHA1Update(&sha1, fmptr, sb.st_size);
2874
 
    SHA1Final(&sha1, shash1);
 
2895
    cl_sha1(fmptr, sb.st_size, shash1, NULL);
2875
2896
 
2876
 
    ret = cli_checkfp_pe(&ctx, shash1);
 
2897
    ret = cli_checkfp_pe(&ctx, shash1, NULL, CL_CHECKFP_PE_FLAG_AUTHENTICODE);
2877
2898
    
2878
2899
    switch(ret) {
2879
2900
        case CL_CLEAN:
2903
2924
static void help(void)
2904
2925
{
2905
2926
    mprintf("\n");
2906
 
    mprintf("             Clam AntiVirus: Signature Tool (sigtool)  %s\n", get_version());
2907
 
    printf("           By The ClamAV Team: http://www.clamav.net/team\n");
2908
 
    printf("           (C) 2007-2009 Sourcefire, Inc. et al.\n\n");
 
2927
    mprintf("Clam AntiVirus: Signature Tool (sigtool)  %s\n", get_version());
 
2928
    mprintf("       By The ClamAV Team: http://www.clamav.net/team\n");
 
2929
    mprintf("       (C) 2007-2009 Sourcefire, Inc. et al.\n\n");
2909
2930
 
2910
2931
    mprintf("    --help                 -h              show help\n");
2911
2932
    mprintf("    --version              -V              print version number and exit\n");
2925
2946
    mprintf("    --utf16-decode=FILE                    decode UTF16 encoded files\n");
2926
2947
    mprintf("    --info=FILE            -i FILE         print database information\n");
2927
2948
    mprintf("    --build=NAME [cvd] -b NAME             build a CVD file\n");
2928
 
    mprintf("    --max-bad-sigs=NUMBER                  Maximum number of mismatched signatures when building a CVD. Default: 3000\n");
2929
 
    mprintf("    --flevel=FLEVEL                        Specify a custom flevel. Default: %u\n", cl_retflevel());
 
2949
    mprintf("    --max-bad-sigs=NUMBER                  Maximum number of mismatched signatures\n");
 
2950
    mprintf("                                           when building a CVD. Default: 3000\n");
 
2951
    mprintf("    --flevel=FLEVEL                        Specify a custom flevel.\n");
 
2952
    mprintf("                                           Default: %u\n", cl_retflevel());
 
2953
    mprintf("    --cvd-version=NUMBER                   Specify the version number to use for\n");
 
2954
    mprintf("                                           the build. Default is to use the value+1\n");
 
2955
    mprintf("                                           from the current CVD in --datadir.\n");
 
2956
    mprintf("                                           If no datafile is found the default\n");
 
2957
    mprintf("                                           behaviour is to prompt for a version\n");
 
2958
    mprintf("                                           number, this switch will prevent the\n");
 
2959
    mprintf("                                           prompt.  NOTE: If a CVD is found in the\n");
 
2960
    mprintf("                                           --datadir its version+1 is used and\n");
 
2961
    mprintf("                                           this value is ignored.\n");
2930
2962
    mprintf("    --no-cdiff                             Don't generate .cdiff file\n");
2931
2963
    mprintf("    --unsigned                             Create unsigned database file (.cud)\n");
2932
2964
    mprintf("    --print-certs=FILE                     Print Authenticode details from a PE\n");
2933
2965
    mprintf("    --server=ADDR                          ClamAV Signing Service address\n");
2934
 
    mprintf("    --datadir=DIR                          Use DIR as default database directory\n");
 
2966
    mprintf("    --datadir=DIR                          Use DIR as default database directory\n");
2935
2967
    mprintf("    --unpack=FILE          -u FILE         Unpack a CVD/CLD file\n");
2936
2968
    mprintf("    --unpack-current=SHORTNAME             Unpack local CVD/CLD into cwd\n");
2937
2969
    mprintf("    --list-sigs[=FILE]     -l[FILE]        List signature names\n");
2938
2970
    mprintf("    --find-sigs=REGEX      -fREGEX         Find signatures matching REGEX\n");
2939
2971
    mprintf("    --decode-sigs                          Decode signatures from stdin\n");
2940
 
    mprintf("    --test-sigs=DATABASE TARGET_FILE       Test signatures from DATABASE against TARGET_FILE\n");
 
2972
    mprintf("    --test-sigs=DATABASE TARGET_FILE       Test signatures from DATABASE against \n");
 
2973
    mprintf("                                           TARGET_FILE\n");
2941
2974
    mprintf("    --vba=FILE                             Extract VBA/Word6 macro code\n");
2942
2975
    mprintf("    --vba-hex=FILE                         Extract Word6 macro code with hex values\n");
2943
2976
    mprintf("    --diff=OLD NEW         -d OLD NEW      Create diff for OLD and NEW CVDs\n");
2944
 
    mprintf("    --compare=OLD NEW      -c OLD NEW      Show diff between OLD and NEW files in cdiff format\n");
 
2977
    mprintf("    --compare=OLD NEW      -c OLD NEW      Show diff between OLD and NEW files in\n");
 
2978
    mprintf("                                           cdiff format\n");
2945
2979
    mprintf("    --run-cdiff=FILE       -r FILE         Execute update script FILE in cwd\n");
2946
2980
    mprintf("    --verify-cdiff=DIFF CVD/CLD            Verify DIFF against CVD/CLD\n");
2947
2981
    mprintf("\n");
3050
3084
        help();
3051
3085
 
3052
3086
    optfree(opts);
 
3087
    cl_cleanup_crypto();
3053
3088
    return ret ? 1 : 0;
3054
3089
}