민감 파일 변경 감지 구현¶
이번에는 Scheck를 사용하여 민감 파일을 검사하는 Lua 스크립트 구현을 보여드립니다.
- 버전: 1.0.7-7-g251eead
- 릴리스 날짜: 2023-04-06 11:17:57
- 지원 OS: linux/arm, linux/arm64, linux/386, linux/amd64
전제 조건¶
- Scheck가 설치되어 있어야 합니다.
개발 단계¶
- 설치 디렉터리로 이동하여 설정 파일
scheck.conf의enable필드를true로 설정합니다.
...
[scoutput]
# ##보안 점검 중 생성된 메시지는 로컬, HTTP, Alibaba Cloud SLS로 전송할 수 있습니다.
# ##원격 서버, 예: http(s)://your.url
[scoutput.http]
enable = true
output = "http://127.0.0.1:9529/v1/write/security"
[scoutput.log]
# ##로컬 저장소를 설정할 수 있습니다.
enable = false
output = "/var/log/scheck/event.log"
...
- 디렉터리
/usr/local/scheck/custom.rules.d(이 디렉터리는 사용자 정의 스크립트 디렉터리입니다)에 매니페스트 파일files.manifest를 생성하고 다음과 같이 편집합니다.
id = 'check-file'
category = 'system'
level = 'warn'
title = '파일 변경 감시'
desc = '파일 {{.File}}이(가) 변경되었습니다.'
cron = '*/10 * * * *' #10초마다 해당 Lua 스크립트를 실행함을 의미합니다.
os_arch = ["Linux"]
- 매니페스트 파일과 동일한 디렉터리에 스크립트 파일
files.lua를 생성하고 다음과 같이 편집합니다.
local files={
'/etc/passwd',
'/etc/group'
}
local function check(file)
local cache_key=file
local hashval = file_hash(file)
local old = get_cache(cache_key)
if not old then
set_cache(cache_key, hashval)
return
end
if old ~= hashval then
trigger({File=file})
set_cache(cache_key, hashval)
end
end
for i,v in ipairs(files) do
check(v)
end
- 민감 파일이 변경된 후 다음 10초가 지나면 감지되어
trigger함수가 실행되고, 이벤트가 파일/var/log/scheck/event.log에 전송되어 한 줄의 데이터가 추가됩니다. 예: