[Linux] offline RHEL 7 리눅스에 ClamAV를 설치하기
아래 글을 따라 ClamAV를 설치하면 Old Version이기 때문에 자동으로 정책 데이터베이스를 업데이트할 수 없습니다. 설치는 쉬운데 정책 데이터베이스를 수작업으로 업데이트해줘야 합니다. 최신 ClamAV를 빌드/설치하고자 하시면 다음 블로그를 참고해 주세요
WAS(Web Application Server)의 첨부 파일 기능은 외부 사용자가 시스템 내부로 악성 파일을 주입할 수 있는 가장 직접적인 경로입니다. 따라서 서버가 악성코드 유포지로 악용되거나, 랜섬웨어 감염으로 인해 서버 장악을 당하는 리스크를 방지하려면 리눅스 환경에서도 반드시 안티바이러스 솔루션을 운영해야 합니다. 인터넷 연결이 가능한 테스트 서버와 달리, 보안을 위해 네트워크가 단절된 운영 환경(Air-Gapped)에서는 오프라인 설치 방식이 필수적입니다. 본 가이드에서는 인터넷이 차단된 RHEL 7 서버(이하 offline 운영 서버)에 ClamAV를 설치하고, 최신 보안 정책을 수동으로 업데이트하는 실무 방법을 살펴봅니다.
- 먼저 인터넷이 연결된 RHEL 7 리눅스 서버(이하 online 테스트 서버)에서 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 /opt/clamav_perfect $ repotrack -a x86_64 -p /opt/clamav_perfect clamd clamav clamav-data clamav-devel clamav-lib clamav-milter clamav-update $ cd /opt/clamav_perfect && createrepo . $ vi /etc/yum.repos.d/local_clamav.repo [local-clamav] name=Local ClamAV Repository baseurl=file:///opt/clamav_perfect enabled=1 gpgcheck=0 $ yum clean all && yum makecache
- local-clamav 저장소만을 사용해서 ClamAV가 정상적으로 설치되는지 확인해 봅니다. 패키지 의존성 오류가 발생하면 추가 패키지를 다운로드해야 합니다.
$ yum install -y --disablerepo="*" --enablerepo="local-clamav" clamav clamav-server clamav-update clamd
- 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
- 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
- 첨부 파일이 저장되는 특정 디렉토리만 실시간 감시를 설정합니다.
-- 설정 파일 변경 전 프로세스 확인 $ 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
- 정책 데이터베이스를 자동으로 업데이트하도록 설정합니다.
- 방법1:
freshclam명령어를 직접 실행$ freshclam ClamAV update process started at Thu Apr 30 08:30:41 2026 WARNING: Your ClamAV installation is OUTDATED! WARNING: Local version: 0.103.11 Recommended version: 1.0.9 DON'T PANIC! Read https://docs.clamav.net/manual/Installing.html daily.cvd database is up-to-date (version: 27986, sigs: 355428, f-level: 90, builder: svc.clamav-publisher) main.cvd database is up-to-date (version: 63, sigs: 3287027, f-level: 90, builder: tomjudge) bytecode.cvd database is up-to-date (version: 339, sigs: 80, f-level: 90, builder: nrandolp)
- 방법2: clamav-freshclam 데몬과 /etc/freshclam.conf 설정 파일을 사용해서 자동 업데이트
-- 하루 12번 정책 데이터베이스 업데이트 $ vi /etc/freshclam.conf Checks 12 $ systemctl enable enable --now clamav-freshclam
- 방법3: crontab을 사용해서 2시간마다 자동으로 정책 업데이트 설정
$ crontab -e 0 */2 * * * /usr/bin/freshclam --quiet > /dev/null 2>&1
- 방법1:
- 만일 NFS파일시스템을 감시하려면 실시간 감시보다는
clamscan 명령어를 사용해서 Stand-alone 스캔을 주기적으로 실행하는 것을 권장합니다. clamd 데몬은 실행하지 않아도 되며, 오히려 중지하는 것이 시스템 자원 관리 측면에서 더 효율적입니다.- clamscan 명령어를 사용해서 1회성으로 스캔하는 방법
-- 악성 코드에 감염된 파일에는 "FOUND"라는 문자열이 추가됩니다. -- 스캔이 모두 끝나면 하단에 요약 정보가 출력되는데, 여기서도 감염된 파일의 개수를 확인할 수 있습니다. --
-r 옵션: 하위 디렉토리까지 스캔압니다. ---i 옵션: infected된 파일만 화면에 출력됩니다. $ clamscan -r /path/to/dir1 /path/to/dir2 -i | tee ~/clamscan.result - crontab을 사용해서 주기적으로 스캔하는 방법: 5분마다 스캔하여 탐지된 파일은 /quarantine 디렉토리에 격리됩니다.
-- 감염된 파일를 격리하는 디렉토리 생성 $ mkdir /quarantine --
--no-summary 옵션: 마지막 요약 리포트를 생략합니다. ----move 옵션: 감염된 파일을 지정된 디렉토리로 격리시킵니다. $ crontab -e */5 * * * * find /nfs/path/to -type f -mmin -5 -exec /usr/bin/clamscan -r --no-summary --move=/quarantine {} + > ~/clamscan.result 2>&1
- clamscan 명령어를 사용해서 1회성으로 스캔하는 방법
- online 테스트 서버에서 ClamAV 패키지들을 다운로드한 디렉토리를 압축한 후 offline 운영 서버로 압축 파일을 전송합니다. /etc/yum.repos.d/local_clamav.repo 파일도 전송합니다.
$ tar cvfz ~/clamav_perfect.tar.gz -C /opt/ clamav_perfect $ scp ~/clamav_perfect.tar.gz root@target_host:/opt/ $ scp /etc/yum.repos.d/local_clamav.repo root@target_host:/etc/yum.repos.d/
- offline 운영 서버에서 제대로 전송되었는지 확인 후 압축을 해제하고 ClamAV를 설치합니다. online 테스트 서버에서 진행한 절차를 반복하면 됩니다.
$ tar xvfz clamav_perfect.tar.gz && cd clamav_all/
- offline 운영 서버에서 ClamAV를 설치한 후 정책 데이터베이스 파일들(*.cvd)도 online 테스트 서버에서 offline 운영 서버로 전송합니다.
$ scp /var/lib/clamav/*.cvd root@target_host:/var/lib/clamav/
- online 테스트 서버를 ClamAV 정책의 Private Mirroring 서버로 구축하여 offline 운영 서버의 정책을 업데이트합니다.
- online 테스트 서버에 Nginx 설치 및 설정
$ yum install -y nginx $ systemctl enable --now nginx $ /etc/nginx/conf.d/clamav_mirror.conf server { listen 80; server_name 192.168.x.x; # 마스터 서버의 내부 IP location /clamav/ { alias /var/lib/clamav/; autoindex on; } } $ nginx -t && systemctl restart nginx - offline 운영 서버 설정
-- 정책 데이터베이스 Mirror 서버로 위에서 설정한 서버의 IP주소를 등록 $ vi /etc/freshclam.conf DatabaseMirror http://online.server.ip.address/clamav -- 정상적으로 받아오는지 테스트 $ freshclam -v
- online 테스트 서버에 Nginx 설치 및 설정
