지니언 EDR 로그에서 리눅스 /dev/shm에 시스템 데몬 이름으로 위장한 파일이 반입되거나 다수의 파일이 생성되고 실행·삭제가 이어지는 BPFDoor 백도어 반입을 탐지합니다.
개요
쿼리
1table duration=30m EDR_GENIAN
2| search (_schema == "genian-edr-file" and in(event_subtype, "FileCreate", "FileMove"))
3 or (_schema == "genian-edr-process" and event_subtype == "ProcessStart")
4| search len(trim(hostname)) > 0
5| eval psrc = if(len(trim(image_path)) > 0, trim(image_path), trim(image))
6| eval proc = lower(substr(psrc, lastindexof(psrc, "\\") + 1)), ipath = lower(psrc), cmd_l = lower(nvl(cmd_line, "")),
7 i_dir = if(lastindexof(psrc, "\\") >= 0, lower(substr(psrc, 0, lastindexof(psrc, "\\"))), ""),
8 par = lower(nvl(substr(parent_image, lastindexof(parent_image, "\\") + 1), "")), hostname = lower(trim(hostname))
9| eval b64 = if(in(proc, "powershell.exe", "pwsh.exe"), valueof(groups(cmd_line, "(?i)(?:^|\\s)\"?-(?:e|ec|en|enc|enco|encod|encode|encoded|encodedc|encodedco|encodedcom|encodedcomm|encodedcomma|encodedcomman|encodedcommand)\"?\\s+\"?([a-z0-9+/]{20,}={0,2})\"?(?:\\s|$)"), 0), null)
10| eval ps_text = if(in(proc, "powershell.exe", "pwsh.exe"), lower(concat(cmd_line, " ", nvl(decode(frombase64(substr(b64, 0, len(b64) - mod(len(b64), 4))), "UTF-16LE"), ""))), cmd_l)
11| eval fpath = lower(nvl(file_path, "")), f_dir = if(lastindexof(file_path, "\\") >= 0, lower(substr(file_path, 0, lastindexof(file_path, "\\"))), "")
12| eval grp = case(
13 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and (indexof(ipath, "/") == 0 and (match(ipath, "/[^/]*bpfdoor[^/]*$") or match(ipath, "^/(?:dev/shm|tmp|var/tmp)/[^/]*(?:kdmtmpflush|kdumpflush|kdumpdb|smartadm|hpasmmld|dbus-srv|hald-addon-volume|ndlaunchag|console-kit|inode262394)[^/]*$") or (match(ipath, "/(?:(?:ba|da|z)?sh|nohup|setsid)$") and match(cmd_l, "(?:^|[;&(]\\s*|(?:nohup|setsid|exec)\\s+|-c\\s+[\"']?)/(?:dev/shm|tmp|var/tmp)/[^/\\s]*bpfdoor[^/\\s]*(?:\\s|&|$)")))), "bpfexec",
14 _schema == "genian-edr-file" and in(event_subtype, "FileCreate", "FileMove") and (match(fpath, "^/(?:dev/shm|tmp|var/tmp)/[^/]*(?:kdmtmpflush|kdumpflush|kdumpdb|smartadm|hpasmmld|dbus-srv|hald-addon-volume|ndlaunchag|console-kit|inode262394|bpfdoor)") or match(fpath, "^/(?:var/)?run/(?:haldrund|kdevrund)\\.pid$")), "bpfname",
15 _schema == "genian-edr-file" and in(event_subtype, "FileCreate", "FileMove") and ((indexof(fpath, "/dev/shm/") == 0 or indexof(lower(nvl(file_path2, "")), "/dev/shm/") == 0) and not(match(fpath, "^/dev/shm/(?:sem\\.|\\.org\\.chromium\\.|\\.com\\.google\\.chrome\\.|pulse-shm-|postgresql\\.|snap\\.|lttng-|mono\\.|qb-|libpod|byobu-|\\.nfs)"))), "shmdrop",
16 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and (match(ipath, "/(?:df|findmnt)$") and contains(cmd_l, "/dev/shm")), "shmdisc",
17 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and (indexof(ipath, "/") == 0 and ((match(ipath, "/(?:rm|shred|unlink|truncate)$") and match(cmd_l, "\\s/(?:usr/)?s?bin/\\.[^/\\s]+|\\s/dev/shm/[^/\\s]+|\\.(?:bash|zsh)_history|/var/log/(?:auth\\.log|secure|wtmp|btmp|lastlog|syslog|messages|audit/)|^shred\\b|/shred\\s")) or match(cmd_l, "\\bhistory\\s+-c\\b|unset\\s+histfile|histfile=/dev/null") or (match(ipath, "/(?:cp|mv)$") and match(cmd_l, "\\.(?:bash|zsh)_history")))), "lx_wipe",
18 _schema == "genian-edr-file" and in(event_subtype, "FileCreate", "FileMove") and (match(concat(fpath, " ", lower(nvl(file_path2, ""))), "(?:^|\\s)/(?:tmp|var/tmp|dev/shm)/[^\\s]+") and file_type == "EXEC" and not(match(lower(psrc), "^/usr/bin/(?:dpkg|apt|apt-get|snap)$|^/usr/lib/snapd/"))), "lx_tmpdrop",
19 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and (match(ipath, "^/(?:tmp|var/tmp|dev/shm)/")), "lx_tmpexec")
20| search isnotnull(grp)
21| eval tech = case(grp == "bpfexec", "T1205.002", grp == "bpfname", "T1036.005", grp == "shmdrop", "T1105", grp == "shmdisc", "T1082", grp == "lx_wipe", "T1070.004", grp == "lx_tmpdrop", "T1105", grp == "lx_tmpexec", "T1204.002")
22| eval anchor_g = if(in(grp, "bpfexec", "bpfname", "shmdrop"), grp, null), has_bpfname_v = if(grp == "bpfname", 1, 0), has_bpfexec_v = if(grp == "bpfexec", 1, 0), shm_files_v = if(grp == "shmdrop", fpath, null)
23| stats dc(grp) as grp_cnt, dc(anchor_g) as anchor_cnt, max(has_bpfname_v) as has_bpfname, max(has_bpfexec_v) as has_bpfexec, dc(shm_files_v) as shm_files, values(grp) as groups, values(tech) as techs, min(_time) as first_seen, max(_time) as last_seen by hostname, host_ip
24| search (grp_cnt >= 3 and (has_bpfname == 1 or shm_files >= 5)) or (has_bpfexec == 1 and grp_cnt >= 2)
25| eval groups = strjoin(", ", groups), techs = strjoin(", ", techs),
26 first_seen = string(first_seen, "yyyy-MM-dd HH:mm:ss"), last_seen = string(last_seen, "yyyy-MM-dd HH:mm:ss")
10분마다 직전 30분의 지니언 EDR 프로세스·파일 로그를 조회하여, 각 이벤트를 조건에 따라 행위군(grp)으로 분류하고 해당하는 MITRE 기법 번호(tech)를 붙입니다. 이후 hostname·host_ip별로 서로 다른 행위군 수(grp_cnt)와 필수 행위군 수(anchor_cnt)를 집계합니다. 임시 경로에 BPFDoor의 알려진 위장 파일명이 생성되거나 /dev/shm에 서로 다른 파일이 5개 이상 생성되고(shm_files) 서로 다른 행위군이 3개 이상이거나, BPFDoor 이름의 실행 파일이 실행되고 서로 다른 행위군이 2개 이상이면 탐지합니다. 탐지 결과에는 관찰된 행위군 목록(groups)과 기법 목록(techs), 첫 발생 시각(first_seen)과 마지막 발생 시각(last_seen)을 함께 제공합니다.
위협 분석
BPFDoor는 BPF 필터로 특정 패킷에만 반응해 포트를 열지 않고 동작하는 리눅스 백도어로, 네트워크 스캔으로는 발견하기 어렵습니다. 메모리 기반 경로인 /dev/shm에 kdmtmpflush·dbus-srv처럼 시스템 데몬으로 보이는 이름으로 반입되며, 실행 후 파일을 지워 디스크 흔적을 없앱니다. 실행 단계가 탐지되면 백도어가 메모리에 상주 중일 수 있습니다.
오탐 유형
일부 데이터베이스와 브라우저, 컨테이너 런타임이 /dev/shm에 공유 메모리 파일을 다수 생성합니다. 해당 소프트웨어가 설치된 서버에서 탐지되면 생성 주체 프로세스 기준으로 예외 조건을 추가하여 조정합니다.
대응 방안
/dev/shm과 임시 경로의 파일을 확보하고, 삭제된 실행 파일로 동작 중인 프로세스와 원시 소켓을 연 프로세스를 확인합니다. 파일 반입 경로와 실행 계정을 확인합니다. 정탐으로 확인되면 호스트를 격리하고 메모리 덤프를 확보한 뒤, 같은 파일명이 생성된 다른 서버를 조회합니다.