시스템 사용자 변경 모니터링¶
이번에는 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로 전송할 수 있습니다.
# ##원격 server, 예: 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 = 'users-checker'
category = 'system'
level = 'warn'
title = '시스템 사용자 변경 모니터링'
desc = '{{.Content}}'
cron = '*/10 * * * *'
instanceId = 'id-xxx'
os_arch = ["Linux"]
- 매니페스트 파일과 동일한 디렉터리에 스크립트 파일
users.lua를 생성하고 다음과 같이 편집합니다.
local function check()
local cache_key="current_users"
local currents=users()
local old=get_cache(cache_key)
if not old then
set_cache(cache_key, currents)
return
end
local adds={}
for i,v in ipairs(currents) do
local exist=false
for ii,vv in ipairs(old) do
if vv["username"] == v["username"] then
exist = true
break
end
end
if not exist then
table.insert(adds, v["username"])
end
end
local dels={}
for i,v in ipairs(old) do
local exist=false
for ii,vv in ipairs(currents) do
if vv["username"] == v["username"] then
exist = true
break
end
end
if not exist then
table.insert(dels, v["username"])
end
end
local content=''
if #adds > 0 then
content=content..'새 사용자: '..table.concat(adds, ',')
end
if #dels > 0 then
if content ~= '' then content=content..'; ' end
content=content..'삭제된 사용자: '..table.concat(dels, ',')
end
if content ~= '' then
trigger({Content=content})
set_cache(cache_key, currents)
end
end
check()
- 사용자가 추가되면 다음 10초 후에 감지하여
trigger함수를 실행하고, 이벤트를 파일/var/log/scheck/event.log로 전송합니다. 예를 들어 다음과 같은 한 줄의 데이터가 추가됩니다.