ClamAV를 사용하여 사용자가 업로드하는 바이러스 검사 파일 방법

Clamav은 널리 사용되는 오픈 소스 바이러스 검색 솔루션입니다. 서버 응용 프로그램의 일부는 몇 기가의 바이러스 정의 파일입니다. 이것과 우리의 마이크로 서비스 아키텍처 때문에 ClamAV를 호스트하기 위한 전용 서버를 설정하는 것이 가장 합리적이었습니다. 또한 바이러스 검색 기능이 필요한 여러 솔루션에서 이 ClamAV 인스턴스 하나를 공유할 수 있습니다.
  • 만들기 Linode with docker
  • 구성에서 모든 고급 도커 옵션을 비워 둡니다.
  • Linode를 만들려면 클릭하십시오
  • .
  • 프로비저닝된 후 콘솔을 엽니다
  • .
  • 루트 사용자로 로그인
  • 다음을 실행합니다(latest ClamAV docker container versions 확인).

  • docker pull clamav/clamav:0.105.1
    docker volume create clam_db
    docker run --interactive  --tty --restart=always --name "clam_container_01" --publish 3310:3310 \
        --publish 7357:7357 \
     --mount source=clam_db,target=/var/lib/clamav \
        --env 'CLAMAV_NO_FRESHCLAMD=true' \
     clamav/clamav:0.105.1
    


    이렇게 하면 ClamAV 도커 컨테이너를 가져오고, 영구 도커 볼륨을 생성하고, 포트 7357 및 3310이 노출된 ClamAV 도커 컨테이너를 실행하고, Linode가 다시 시작될 때 도커 컨테이너가 자동으로 다시 시작되도록 설정하고, clam_db라는 영구 도커 볼륨에 바이러스 정의를 유지합니다. .

    이 작업을 완료한 후 패키지를 사용하여 nodejs에서 바이러스를 검색했습니다.
    https://www.npmjs.com/package/clamscan

    예를 들어 여기에 나를 위해 일한 것이 있습니다.
  • 달리다 npm install clamscan
  • virus_scan.js라는 파일을 만듭니다.

  • const NodeClam = require(‘clamscan’)
    const ClamScan = new NodeClam().init({
      removeInfected: true, // If true, removes infected files
      debugMode: false, // Whether or not to log info/debug/error msgs to the console
      scanRecursively: true, // If true, deep scan folders recursively
      clamdscan: {
        host: ‘111.111.111.11’, // IP of host to connect to TCP interface
        port: 3310, // Port of host to use when connecting via TCP interface
        timeout: 60000, // Timeout for scanning files
        localFallback: false, // Use local preferred binary to scan if socket/tcp fails
        multiscan: true, // Scan using all available cores! Yay!
        active: true, // If true, this module will consider using the clamdscan binary
        bypassTest: false, // Check to see if socket is available when applicable
      },
      preference: ‘clamdscan’, // If clamdscan is found and active, it will be used by default
    })
    
    // Get instance by resolving ClamScan promise object
    ClamScan.then(async (clamscan) => {
      try {
        // You can re-use the `clamscan` object as many times as you want
        const version = await clamscan.getVersion()
        console.log(`ClamAV Version: ${version}`)
        const { isInfected, file, viruses } = await clamscan.isInfected(‘./lib/virus.txt’)
        if (isInfected) console.log(`${file} is infected with ${viruses}!`)
      } catch (err) {
        // Handle any errors raised by the code in the try block
        throw err
      }
    }).catch(console.error)
    
    
    virus.txt의 내용에는 모든 것이 제대로 작동하는지 확인하는 데 도움이 되는 바이러스 서명이 포함되어 있습니다.

    X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*
    


    실행할 때node virus_scan.js 표시되어야 합니다.

    null is infected with Eicar-Signature!
    


    여기에서 사용자가 업로드한 파일을 스캔하는 방법을 상상할 수 있어야 합니다. 귀하의 사용 사례에 상당히 고유하기 때문에 자세히 설명하지 않겠습니다.

    좋은 웹페이지 즐겨찾기