clamav程序的研究总结

一、clamav-0.100.1的整体的目录如下:

|-Clamav-milter
  |-Clambc
  |-Clamconf
  |-Clamdscan
  |-Clamdtop
  |-Clamscan
  |-Clamsubmit
  |-Config
  |-Database
  |-Docs
  |-Etc
  |-Examples
  |-Freshclam
  |-Libclamav     //重要目录
    |-7z
    |-c++
    |-jsparse
    |-libmspack-0.5alpha
    |-lzw
    |-nsis
    |-regex
    |-tomsfastmath
  |-Libclamunrar  //关于解压缩文件的
  |-Libclamunrar_iface  //同上
  |-Libfreshclam
  |-Libltdl   //This is GNU libltdl, a system independent dlopen wrapper for GNU libtool.
  |-M4
  |-Shared
  |-Sigtool
  |-Test
  |-Unit_tests
  |-Win32
  1.1 libclamav中的文件列表(关于具体后缀名的相关api处理有的比较难理解,这里没有往下测试):
    |-7z-iface.c   //7z压缩文件的相关api
    |-adc.c       //adc后缀文件的相关api
    |-apm.c       //apm后缀文件的相关api
    |-arc4.c
    |-asn1.c      
    |-aspack.c
    |-autoit.c   //编辑器产生的默认后缀?
    |-binhex.c   
    |-blob.c
      |->fileblobScan(const fileblob *fb)
        |->cli_matchmeta()
        |->cli_magic_scandesc()   //此函数在其他的后缀名文件中也出现过
          |->cli_base_scandesc()  //定义在scanners.c中
            |->magic_scandesc()  //具体的调用都在这个函数中
    |-bytecode.c                 //Load, and verify ClamAV bytecode.
    |-bytecode_api.c
    |-bytecode_api_decl.c
    |-bytecode_detect.c
    |-bytecode_nojit.c
    |-bytecode_vm.c
    |-cache.c
    |-conv.c
    |-cpio.c
    |-crtmgr.c
    |-crypto.c
    |-cvd.c
    |-dconf.c
    |-disasm.c
    |-dlp.c
    |-dmg.c
    |-dsig.c
    |-elf.c
    |-entconv.c
    |-events.c
    |-explode.c
    |-filetypes.c    //其中列举了一些文件类型放在ftmap[]结构体中
    |-filtering.c
    |-fmap.c
    |-fpu.c
    |-fsg.c
    |-gpt.c
    |-hashtab.c
    |-hfsplus.c
    |-hostid.c
    |-htmlnorm.c
    |-hwp.c
    |-inflate64.c
    |-iowrap.c
    |-ishield.c
    |-iso9669.c
    |-is_tar.c
    |-jpeg.c
    |-json_api.c
    |-libmspack.c
    |-line.c
    |-lzma_iface.c
    |-macho.c
    |-matcher-ac.c
    |-matcher-bm.c
    |-matcher-hash.c
    |-matcher-pcre.c
    |-matcher.c   //这里仅列举一下文件所包含的函数名
      |-cli_scanbuf()
      |-cli_scandesc()
      |-cli_fmap_scandesc()
      |-cli_exp_eval()
      |-cli_caloff()
      |-cli_checkfp()
      |-cli_checkfp_virus()
      |-cli_matchmeta()
      |-void cli_targetinfo()
    |-mbox.c
    |-mbr.c
    |-message.c
    |-mew.c
    |-mpool.c
    |-msdoc.c
    |-msexpand.c
    |-msxml.c
    |-msxml_parser.c
    |-ole2_extract.c
    |-ooxml.c
    |-openioc.c
    |-others.c
    |-packlibs.c
    |-pdf.c
    |-pdfdecode.c
    |-pdfng.c
    |-pe.c
    |-perflogging.c
    |-petite.c
    |-pe_icons.c
    |-phishcheck.c
    |-phish_domaincheck_db.c
    |-phish_whitelist.c
    |-png.c
    |-prtn_intxn.c
    |-qsort.c
    |-readdb.c
    |-rebuildpe.c
    |-regex_list.c
    |-regex_pcre.c
    |-regex_suffix.c
    |-rijndael.c
    |-rtf.c
    |-scanners.c
    |-sf_base64decode.c
    |-sis.c
    |-special.c
    |-spin.c
    |-stats.c
    |-stats_json.c
    |-str.c
    |-strlcat.c
    |-swf.c
    |-table.c
    |-text.c
    |-textdet.c
    |-textnorm.c
    |-tiff.c
    |-unarj.c
    |-uniq.c
    |-unsp.c
    |-untar.c
    |-unzip.c
    |-upack.c
    |-upx.c
    |-uuencode.c
    |-vba_extract.c
    |-version.c
    |-wwunpack.c
    |-www.c
    |-xar.c
    |-xdp.c
    |-xz_iface.c
    |-yara_arena.c
    |-yara_compiler.c
    |-yara_exec.c
    |-yara_grammar.y  //yara规则文件后缀
    |-yara_hash.c
    |-yara_lexer.c
    |-yara_parser.c   //yara的github地址:https://github.com/VirusTotal/yara,
    |-yc.c


  1.2 yara的相关使用
     参考链接:https://blog.csdn.net/m0_37552052/article/details/79012453
二、安装及测试
   2.1 参考链接:

    https://github.com/Cisco-Talos/clamav-faq/blob/master/manual/Installation_guide-ClamAV%200.99.2%2B_rhel%26centos.md
  按照文档中的步骤,最终的成功截图如下:

  2.2 clamav的官方pdf文档介绍

      链接: https://github.com/Cisco-Talos/clamav-faq/blob/master/manual/clamdoc.pdf

  2.3 libclamav库API提供了病毒扫描的各种函数接口。libclamav库使用的是病毒扫描法。从病毒中提取的特征字符串被用一定的格式组织在一起并加上签名保护就形成了病毒库,clamav使用的病毒库一般后缀为.cvd文件。

       2.3.1 在使用libclamav之前,必须调用cl_init()函数来初始化,初始化成功以后,可以调用cl_engine_new()函数来创建一个新的扫描引擎。扫描结束以后,需要调用cl_engine_free()这个函数来释放这个引擎结构。截图如下(可以参考examples/ex1.c文件):

        

      

           上述三个函数的原型如下:

int cl_init(unsigned int options);
struct cl_engine *cl_engine_new(void);
int cl_engine_free(struct cl_engine *engine);

             cl_init()和cl_engine_free()两个函数如果调用成功,将返回CL_SUCCESS,如果返回其他code,说明函数调用失败。

             cl_init函数的实参传入CL_INIT_DEFAULT即可。

             cl_engine_new()如果调用成功将返回一个指向struct cl_engine结构体的指针,如果失败将返回NULL.

         2.3.2 得到新的扫描引擎以后,需要进行特征库的加载,clamav提供了两个函数:

const char *cl_retdbdir(void);
int cl_load(const char *path, struct cl_engine *engine,
            unsigned int *signo, unsigned int options);

             

                 cl_retdbdir返回CLamav特征库的默认路径。

                 cl_load函数根据给出的具体特征库路径,加载单个特征文件,或者加载几个特征文件(给出的实参是文件夹)。第二个参数传入cl_engine_new得到的engine,第三个参数传入加载的特征码的条数,最后一个参数为加载的选项,一般传入CL_DB_STDOPT即可。

       2.3.3 以上的步骤完成以后,需要调用cl_engine_compile()函数做最后的文件扫描前的准备,函数原型为:

int cl_engine_compile(struct cl_engine *engine);

      2.3.4 现在可以扫描文件了

         

           函数的原型为:

|->int cl_scanfile(const char *filename, const char **virname, 
                unsigned long int *scanned, const struct cl_engine *engine,
                unsigned int options);
  |->cl_scandesc_callback()
    |->scan_common()
      |->cli_map_scandesc()    //for map scans that are not forced to disk
      |->cli_mem_scandesc()     
        |->cli_map_scan()
          |->cli_base_scandesc(fd, ctx, type); //多处调用了此函数,库函数中的重要函数
            |->magic_scandesc(ctx, type); //此函数中处理各种不同接口函数,不再往下分析

            该函数需要注意的一点是,virname在函数中指向了engine结构体的表示目标扫描文件名称的内存,不能被直接释放。

三、相关链接

    链接:http://outstandingcandy.blog.163.com/blog/static/1627591192010101962351249/

    上面链接主要是分析了clamav代码。

猜你喜欢

转载自blog.csdn.net/zhangge3663/article/details/81506938