[Linux] offline RHEL 7 리눅스에 clamAV를 설치하기

WAS(Web Application Server)의 첨부 파일 기능은 외부 사용자가 시스템 내부로 악성 파일을 주입할 수 있는 가장 직접적인 경로입니다. 따라서 서버가 악성코드 유포지로 악용되거나, 랜섬웨어 감염으로 인해 서버 장악을 당하는 리스크를 방지하려면 리눅스 환경에서도 반드시 안티바이러스 솔루션을 운영해야 합니다. 인터넷 연결이 가능한 테스트 서버와 달리, 보안을 위해 네트워크가 단절된 운영 환경(Air-Gapped)에서는 오프라인 설치 방식이 필수적입니다. 본 가이드에서는 인터넷이 차단된 RHEL 7 서버에 ClamAV를 설치하고, 최신 보안 정책을 수동으로 업데이트하는 실무 방법을 살펴봅니다.

  1. 먼저 인터넷이 연결된 RHEL 7 리눅스 서버에서 clamAV 관련 패키지를 다운로드합니다. 의존성 패키지까지 다운로드하기 위해 repotrack 명령어를 사용합니다. ClamAV Documentation 페이지를 참고하세요.
    • clamd – The Clam AntiVirus Daemon
    • clamav – End-user tools for the Clam Antivirus scanner
    • clamav-data – Virus signature data for the Clam Antivirus scanner
    • clamav-devel – Header files and libraries for the Clam Antivirus scanner
    • clamav-lib – Dynamic libraries for the Clam Antivirus scanner
    • clamav-milter – Milter module for the Clam Antivirus scanner
    • clamav-update – Auto-updater for the Clam Antivirus scanner data-files
    $ rpm -Uvh https://archives.fedoraproject.org/pub/archive/epel/7/x86_64/Packages/e/epel-release-7-14.noarch.rpm
    Retrieving https://archives.fedoraproject.org/pub/archive/epel/7/x86_64/Packages/e/epel-release-7-14.noarch.rpm
    warning: /var/tmp/rpm-tmp.Ydd6xB: Header V4 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
    Preparing...                          ################################# [100%]
    Updating / installing...
       1:epel-release-7-14                warning: /etc/yum.repos.d/epel.repo created as /etc/yum.repos.d/epel.repo.rpmnew
    $ vi /etc/yum.repos.d/epel.repo
    enabled=1
    $ yum clean all && yum makecache
    $ yum install yum-utils
    $ mkdir ~/clamav_perfect
    $ yumdownloader --resolve --destdir=/home/root/clamav_perfect clamd clamav clamav-data clamav-devel clamav-lib clamav-milter clamav-update
    $ repotrack -a x86_64 -p /home/root/clamav_perfect clamd clamav clamav-data clamav-devel clamav-lib clamav-milter clamav-update
    $ cd /home/root/clamav_perfect && createrepo .
    $ vi /etc/yum.repos.d/local_clamav.repo
    [local-clamav]
    name=Local ClamAV Repository
    baseurl=file:///home/root/clamav_perfect
    enabled=1
    gpgcheck=0
    $ yum clean all && yum makecache
    
  2. local-clamav 저장소만을 사용해서 clamAV가 정상적으로 설치되는지 확인해 봅니다. 패키지 의존성 오류가 발생하면 추가 패키지를 다운로드해야 합니다.
    $ yum remove -y clamav clamav-filesystem clamav-lib clamav-update
    $ yum install -y --disablerepo="*" --enablerepo="local-clamav" clamav clamav-server clamav-update clamd
    
  3. freshclam 명령어로 시그니처(정책)을 업데이트할 수 있으나 저는 오류가 발생해서, 수작업으로 정책을 업데이트하는 방법으로 진행하겠습니다.
    $ cd /var/lib/clamav
    $ curl -L -A "Mozilla/5.0" -O https://database.clamav.net/main.cvd
    $ curl -L -A "Mozilla/5.0" -O https://database.clamav.net/daily.cvd
    $ curl -L -A "Mozilla/5.0" -O https://database.clamav.net/bytecode.cvd
    $ chown clamupdate:clamupdate *.cvd
    $ ls -lh
    total 108M
    -rw-r--r--. 1 clamupdate clamupdate 276K Apr 29 15:24 bytecode.cvd
    -rw-r--r--. 1 clamupdate clamupdate  23M Apr 29 15:24 daily.cvd
    -rw-r--r--. 1 clamupdate clamupdate  85M Apr 29 15:30 main.cvd
    
  4. clamAV 엔진을 실행하고 특정 디렉토리를 스캔해 봅니다.
    -- 설정 파일(scan.conf) 수정: 주석 제거
    $ vi /etc/clamd.d/scan.conf
    LocalSocket /run/clamd.scan/clamd.sock
    FixStaleSocket yes
    
    -- 소켓 디렉토리 생성 및 권한 부여
    $ mkdir -p /run/clamd.scan
    $ chown clamscan:clamscan /run/clamd.scan
    
    -- 서비스 시작 및 활성화
    $ systemctl enable --now clamd@scan
    
    -- 스캔 시작
    $ clamscan -r /path/to | tee -a ~/clamscan.result
    
  5. 첨부 파일이 저장되는 특정 디렉토리만 실시간 감시를 설정합니다.
    -- 변경 전 프로세스 확인
    $ ps -ef | grep clamd
    clamscan 28797     1  0 15:38 ?        00:00:13 /usr/sbin/clamd -c /etc/clamd.d/scan.conf
    
    -- 서비스 파일 보완 및 리로드: 추가 사항
    $ systemctl edit --full clamd@scan.service
    [Service]
    User=root
    Group=root
    
    -- 실시간 감시를 위한 설정 파일 수정: 주석 제거 등
    $ vi /etc/clamd.d/scan.conf
    LogFile /var/log/clamd.scan
    LogFileMaxSize 10M
    LogTime yes
    LogVerbose yes
    LogRotate yes
    OnAccessMaxFileSize 100M
    OnAccessMaxThreads 10
    OnAccessCurlTimeout 10000
    OnAccessIncludePath /path/to
    OnAccessPrevention yes
    OnAccessExtraScanning yes
    User root
    
    -- 서비스 재실행
    $ systemctl restart clamd@scan
    
    -- 프로세스 확인
    $ ps -ef | grep clamd
    root     21164     1 75 16:08 ?        00:00:15 /usr/sbin/clamd -c /etc/clamd.d/scan.conf
    
  6. 다운로드 디렉토리를 압축한 후 인터넷망이 차단된 서버로 압축 파일을 전송합니다.
    $ tar cvfz ~/clamav_perfect.tar.gz -C /home/root/ clamav_perfect
    $ scp ~/clamav_perfect.tar.gz root@target_host:~/
    
  7. 제대로 전송되었는지 확인 후 압축을 해제하고 clamAV 설치 디렉토리로 이동한 후 설치를 진행합니다. 테스트 서버에서 진행한 절차를 반복하면 됩니다.
    $ tar xvfz clamav_perfect.tar.gz && cd clamav_all/
    

You may also like...

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다