카테고리 없음

ClamAV :: 안티바이러스 스캔

gamjadori 2026. 8. 12. 17:39
728x90

ClamAV :: 안티바이러스 스캔


* ClamAV: 오픈소스 백신 소프트웨어, 알려진 악성코드 시그니처와 파일을 대조해서 감염 여부 스캔
AIDE(파일이 변조됐는지)나 auditd(누가 접근했는지)와 다르게 파일 내용 자체가 악성인지 직접 판단 가능

설치
sudo apt install clamav clamav-daemon -y
>> ClamAV 본체와 실시간 감시 데몬을 설치하는 명령어


바이러스 정의 업데이트
sudo systemctl stop clamav-freshclam
sudo freshclam
최신 악성코드 시그니처 데이터베이스를 다운로드하는 명령어

업데이트 후 서비스 재시작
sudo systemctl start clamav-freshclam


curl -o ~/eicar_test.txt https://secure.eicar.org/eicar.com.txt
>> EICAR 공식 사이트에서 정본 테스트 파일 다운로드

실제 악성코드는 아니지만모든 백신이 "탐지 테스트용"으로 인식하도록 약속된 표준 문자열을 담은 파일
echo로 직접 문자열을 입력하는 방법도 있지만 따옴표나 특수문자가 편집기에서 변형되기 쉬워 공식 서버에서 받는 방식 사용

홈 디렉토리 스캔 실행
clamscan ~/

bastion@sieun:~$ clamscan ~/
Loading:     4s, ETA:   0s [========================>]    3.63M/3.63M sigs       
Compiling:   1s, ETA:   0s [========================>]       41/41 tasks 

/home/bastion/.bash_logout: OK
/home/bastion/trivy_0.73.0_Linux-ARM64.deb: OK
/home/bastion/vulnerable_login.py: OK
/home/bastion/backup_db.sh: OK
/home/bastion/.mariadb_history: OK
/home/bastion/pod-reader-role.yaml: OK
/home/bastion/pod-reader-binding.yaml: OK
/home/bastion/bastion@sieun:~$: Empty file
/home/bastion/.bashrc: OK
/home/bastion/kubectl: OK
/home/bastion/ssh_capture.pcap: OK
/home/bastion/telnet_capture.pcap: OK
/home/bastion/eicar_test.txt: Eicar-Test-Signature FOUND
/home/bastion/Dockerfile: OK
/home/bastion/practice_db_backup.sql: OK
/home/bastion/backup_error.log: OK
/home/bastion/perm_demo.txt: Empty file
/home/bastion/스캔_IP목록.txt: Empty file
/home/bastion/admin-role.yaml: OK
/home/bastion/실패_IP목록.txt: OK
/home/bastion/.bash_history: OK
/home/bastion/.wget-hsts: OK
/home/bastion/safe_login.py: OK
/home/bastion/auth_log_hash.txt: OK
/home/bastion/.selected_editor: OK
/home/bastion/minikube-linux-arm64: OK
/home/bastion/test.txt: OK
/home/bastion/.profile: OK

----------- SCAN SUMMARY -----------
Known viruses: 3627999
Engine version: 1.5.3
Scanned directories: 1
Scanned files: 25
Infected files: 1
Data scanned: 156.40 MiB
Data read: 222.83 MiB (ratio 0.70:1)
Time: 10.064 sec (0 m 10 s)
Start Date: 2026:08:14 15:59:23
End Date:   2026:08:14 15:59:33
bastion@sieun:~$

결과
>>
Known viruses: 3627999
현재 로드된 시그니처 DB에 등록된 악성코드 종류 수
Engine version: 1.5.3
ClamAV 엔진 버전
Scanned directories: 1
스캔 대상으로 지정한 디렉토리 개수
Scanned files: 25
실제로 검사한 파일 개수
Infected files: 1
감염(탐지)된 파일 개수

Data scanned: 156.40 MiB
바이러스 엔진이 실제로 분석한 데이터 양
Data read: 222.83 MiB (ratio 0.70:1)
디스크에서 읽어들인 원본 데이터 양과, 분석량 대비 읽은 양의 비율
Time: 10.064 sec
전체 스캔 소요 시간
>> eicar_test.txt가 Eicar-Test-Signature로 탐지되어 출력됨


감염 파일 자동 격리까지 해보기
 

clamscan --move=/home/사용자명/quarantine /home/사용자명/
탐지된 파일을 별도의 격리 폴더로 자동 이동시키는 명령어
--move 옵션에 ~ 상대경로를 쓰면 realpath 인식 오류가 발생할 수 있어 절대경로 사용 권장
결과: eicar_test.txt가 quarantine 폴더로 옮겨진 것 확인

bastion@sieun:~$ clamscan --move=/home/bastion/quarantine /home/bastion/
Loading:     4s, ETA:   0s [========================>]    3.63M/3.63M sigs       
Compiling:   1s, ETA:   0s [========================>]       41/41 tasks 

/home/bastion/.bash_logout: OK
/home/bastion/trivy_0.73.0_Linux-ARM64.deb: OK
/home/bastion/vulnerable_login.py: OK
/home/bastion/backup_db.sh: OK
/home/bastion/.mariadb_history: OK
/home/bastion/pod-reader-role.yaml: OK
/home/bastion/pod-reader-binding.yaml: OK
/home/bastion/bastion@sieun:~$: Empty file
/home/bastion/.bashrc: OK
/home/bastion/kubectl: OK
LibClamAV Warning: fmap_readpage: file changed as we read it
/home/bastion/vault_1.17.0_linux_arm64.zip: OK
/home/bastion/ssh_capture.pcap: OK
/home/bastion/telnet_capture.pcap: OK
/home/bastion/eicar_test.txt: Eicar-Test-Signature FOUND
/home/bastion/eicar_test.txt: moved to '/home/bastion/quarantine/eicar_test.txt'
/home/bastion/Dockerfile: OK
/home/bastion/practice_db_backup.sql: OK
/home/bastion/backup_error.log: OK
/home/bastion/perm_demo.txt: Empty file
/home/bastion/스캔_IP목록.txt: Empty file
/home/bastion/admin-role.yaml: OK
/home/bastion/실패_IP목록.txt: OK
/home/bastion/.bash_history: OK
/home/bastion/.wget-hsts: OK
/home/bastion/safe_login.py: OK
/home/bastion/auth_log_hash.txt: OK
/home/bastion/.selected_editor: OK
/home/bastion/minikube-linux-arm64: OK
/home/bastion/test.txt: OK
/home/bastion/.profile: OK

----------- SCAN SUMMARY -----------
Known viruses: 3627999
Engine version: 1.5.3
Scanned directories: 1
Scanned files: 26
Infected files: 1
Data scanned: 254.37 MiB
Data read: 314.83 MiB (ratio 0.81:1)
Time: 14.876 sec (0 m 14 s)
Start Date: 2026:08:14 16:02:19
End Date:   2026:08:14 16:02:33

Loading / Compiling 진행바
시그니처 DB(3.63M개)를 메모리에 로드하고 스캔 규칙을 컴파일하는 초기화 과정, 매 실행마다 발생

LibClamAV Warning: fmap_readpage: file changed as we read it
스캔 도중 vault_1.17.0_linux_arm64.zip 파일이 다른 프로세스에 의해 수정되고 있었다는 경고, 파일이 열려 있거나 쓰기 중일 때 나타날 수 있는 정상적인 경고이고 스캔 자체를 막지는 않음
/home/bastion/eicar_test.txt: Eicar-Test-Signature FOUND
악성코드로 탐지됨
/home/bastion/eicar_test.txt: moved to '/home/bastion/quarantine/eicar_test.txt'
--move 옵션이 실제로 동작해서 탐지 즉시 격리 폴더로 옮겨졌다는 로그
SCAN SUMMARY
Known viruses: 3627999
로드된 시그니처 DB 기준 등록된 악성코드 종류 수 (직전 스캔과 동일)
Engine version: 1.5.3
ClamAV 엔진 버전
Scanned directories: 1
스캔한 디렉토리 수
Scanned files: 26
스캔한 파일 수, 직전 스캔(25개)보다 1개 늘었는데 이건 vault_1.17.0_linux_arm64.zip처럼 스캔 사이에 새로 생기거나 압축 파일 내부까지 풀어서 센 파일이 포함된 것으로 추정
Infected files: 1
감염 파일 수, eicar_test.txt 하나
Data scanned: 254.37 MiB / Data read: 314.83 MiB (ratio 0.81:1)
분석한 데이터량과 읽은 원본 데이터량, 압축 파일 내부 검사 등으로 읽은 양이 더 많음
Time: 14.876 sec
전체 소요 시간, 직전보다 좀 늘어난 건 새로 생긴 zip 파일 검사 때문으로 보임
Start Date / End Date
스캔 시작·종료 시각

탐지된 파일을 별도의 격리 폴더로 자동 이동시키는 명령어
결과: eicar_test.txt가 quarantine 폴더로 옮겨진 것 확인

정기 스캔으로 자동화 (crontab 연결)
crontab -e
0 3 * * * clamscan -r –infected –log=/home/사용자명/clamav_scan.log /home

>> 매일 새벽 3시에 홈 디렉토리를 재귀적으로(-r) 스캔해서, 감염된 파일만(–infected) 로그에 기록하는 자동 스캔 설정

정리 명령어
rm -rf ~/quarantine ~/eicar_test.txt

실습에 쓴 테스트 파일과 격리 폴더를 삭제하는 명령어