지니언 EDR의 리눅스 호스트 로그에서 cron 지속성 등록이 base64 드로퍼 실행·임시 경로 실행 파일 반입·sshpass 측면 이동과 겹치는 Hadooken형 크립토마이너 침투 체인을 탐지합니다.
Overview
Query
1table duration=30m EDR_GENIAN
2| search (_schema == "genian-edr-file" and in(event_subtype, "FileCreate", "FileMove"))
3 or (_schema == "genian-edr-network" and event_subtype == "NetworkConnect")
4 or (_schema == "genian-edr-process" and event_subtype == "ProcessStart")
5| search len(trim(hostname)) > 0
6| eval psrc = if(len(trim(image_path)) > 0, trim(image_path), trim(image))
7| eval proc = lower(substr(psrc, lastindexof(psrc, "\\") + 1)), ipath = lower(psrc), cmd_l = lower(nvl(cmd_line, "")),
8 i_dir = if(lastindexof(psrc, "\\") >= 0, lower(substr(psrc, 0, lastindexof(psrc, "\\"))), ""),
9 par = lower(nvl(substr(parent_image, lastindexof(parent_image, "\\") + 1), "")), hostname = lower(trim(hostname))
10| 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)
11| 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)
12| eval fpath = lower(nvl(file_path, "")), f_dir = if(lastindexof(file_path, "\\") >= 0, lower(substr(file_path, 0, lastindexof(file_path, "\\"))), "")
13| eval grp = case(
14 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and (indexof(ipath, "/") == 0 and ((match(ipath, "/crontab$") and match(cmd_l, "\\bcrontab\\b[^\\n|]*\\s-\\s*(?:$|\\|)") and not(match(cmd_l, "\\s-l\\s*$"))) or (match(ipath, "/(?:tee|cp|mv|install|dd|ln)$") and match(cmd_l, "/(?:etc/cron(?:tab|\\.d|\\.hourly|\\.daily|\\.weekly|\\.monthly)?|var/spool/cron)(?:/|\\s|$)")) or match(cmd_l, ">>?\\s*/(?:etc/cron|var/spool/cron)"))), "cron",
15 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and (indexof(ipath, "/") == 0 and ((match(ipath, "/base64$") and match(cmd_l, "\\s(?:-d|--decode)\\b")) or (match(ipath, "/xxd$") and match(cmd_l, "\\s-r\\b")) or (match(ipath, "/openssl$") and match(cmd_l, "\\senc\\b[^\\n]*\\s-d\\b")))), "base64",
16 _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",
17 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and (match(ipath, "^/(?:tmp|var/tmp|dev/shm)/")), "lx_tmpexec",
18 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and (indexof(ipath, "/") == 0 and (match(ipath, "/sshpass$") or (match(ipath, "/ssh$") and match(cmd_l, "stricthostkeychecking=no|userknownhostsfile=/dev/null") and match(cmd_l, "@(?:10\\.|192\\.168\\.|172\\.(?:1[6-9]|2[0-9]|3[01])\\.)")))), "lx_sshpass",
19 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and (indexof(ipath, "/") == 0 and (match(cmd_l, "(?:curl|wget)\\b[^\\n|]*\\|\\s*(?:sudo\\s+)?(?:ba|da|z)?sh\\b") or match(cmd_l, "/dev/(?:tcp|udp)/[0-9a-z]") or match(cmd_l, "python[0-9.]*\\s+-c\\s[^\\n]*(?:urllib|requests|socket)[^\\n]*(?:subprocess|os\\.system|exec\\(|memfd|pty\\.spawn)"))), "lx_oneliner",
20 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and (match(ipath, "/(?:curl|wget)$") and match(cmd_l, "(?:\\s-o|--output(?:-document)?)[= ]?\\s*\\S?/(?:tmp|var/tmp|dev/shm)/|\\|\\s*(?:sudo\\s+)?(?:ba|da|z)?sh\\b")), "lx_dl",
21 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and (match(ipath, "/(?:curl|wget)$") and (match(cmd_l, "(?:\\s-t\\s|--upload-file\\b|--data-binary\\b|\\s-d\\s+@|\\s--data\\s+@)") or match(cmd_l, "x-amz-(?:algorithm|credential|signature)\\b") or (match(cmd_l, "https?://[^\\s/]+:[0-9]{4,5}/") and not(match(cmd_l, ":443/|:80/|:8080/"))))), "lx_exfil",
22 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and (indexof(ipath, "/") == 0 and match(ipath, "/(?:ba|da|z|k)?sh$") and match(cmd_l, "(?:^|\\s)(?:ba|da|z|k)?sh\\s+/(?:tmp|var/tmp|dev/shm)/[a-z0-9_]+\\.sh\\b") and not(match(cmd_l, "/tmp/[0-9]+\\.[a-z0-9]+\\.sh|apt-key|gpghome|/gpg\\.[0-9]"))), "lx_disc",
23 _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",
24 _schema == "genian-edr-network" and event_subtype == "NetworkConnect" and (lower(psrc) == "/usr/sbin/sshd" and direction == "IN" and match(string(remote_ip), "^(?:10\\.|192\\.168\\.|172\\.(?:1[6-9]|2[0-9]|3[01])\\.)")), "lx_sshin",
25 _schema == "genian-edr-file" and in(event_subtype, "FileCreate", "FileMove") and (match(concat(fpath, " ", lower(nvl(file_path2, ""))), "(?:^|\\s)(?:/(?:etc|usr/lib|lib)/systemd/(?:system|user)/|/home/[^/\\s]+/\\.config/systemd/user/|/root/\\.config/systemd/user/)[^/\\s]+\\.(?:service|timer|socket|path)(?:\\s|$)") and not(match(lower(psrc), "^/usr/bin/(?:dpkg|apt|apt-get|rpm|yum|dnf|snap|systemctl|deb-systemd-helper)$|^/usr/lib/snapd/|^/(?:usr/)?lib/systemd/"))), "lx_systemd")
26| search isnotnull(grp)
27| eval tech = case(grp == "cron", "T1053.003", grp == "base64", "T1140", grp == "lx_tmpdrop", "T1105", grp == "lx_tmpexec", "T1204.002", grp == "lx_sshpass", "T1021.004", grp == "lx_oneliner", "T1059.004", grp == "lx_dl", "T1105", grp == "lx_exfil", "T1041", grp == "lx_disc", "T1082", grp == "lx_wipe", "T1070.004", grp == "lx_sshin", "T1021.004", grp == "lx_systemd", "T1543.002")
28| eval anchor_g = if(in(grp, "cron"), grp, null), has_cron_v = if(grp == "cron", 1, 0)
29| stats dc(grp) as grp_cnt, dc(anchor_g) as anchor_cnt, max(has_cron_v) as has_cron, values(grp) as groups, values(tech) as techs, min(_time) as first_seen, max(_time) as last_seen by hostname, host_ip
30| search has_cron == 1 and grp_cnt >= 4
31| eval groups = strjoin(", ", groups), techs = strjoin(", ", techs),
32 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)를 집계합니다. cron 작업 등록(crontab 표준 입력 설치 또는 /etc/cron·/var/spool/cron 기록)이 반드시 있고(필수 행위군), 서로 다른 행위군이 4개 이상이면 탐지합니다. 탐지 결과에는 관찰된 행위군 목록(groups)과 기법 목록(techs), 첫 발생 시각(first_seen)과 마지막 발생 시각(last_seen)을 함께 제공합니다.
Threat analysis
Hadooken은 취약한 서버 애플리케이션을 침해한 뒤 base64로 인코딩한 Python 드로퍼를 메모리에서 실행하고 크립토마이너 파일을 임시 경로에 생성하는 리눅스 악성코드입니다. cron에 주기 실행을 등록해 삭제해도 다시 내려받으며, SSH 개인 키를 찾아 다른 서버로 이동합니다. 채굴로 인한 자원 소모 외에 추가 악성코드의 유입 경로가 될 수 있습니다.
False positives
운영 스크립트가 crontab에 작업을 등록하면서 임시 경로에 파일을 내려받아 실행하는 경우 탐지될 수 있습니다. 확인된 설치·배포 스크립트는 실행 경로와 내려받기 주소 기준으로 예외 조건을 추가하여 조정합니다.
Response actions
등록된 cron 항목과 임시 경로의 실행 파일을 확보하고, base64 명령줄을 디코딩하여 내려받기 주소를 확인합니다. 실행 중인 채굴 프로세스를 종료하고 SSH 접속 대상 서버에서 같은 행위를 조회합니다. 정탐으로 확인되면 cron 항목을 제거하고 주소를 차단하며, 최초 침해 지점인 서버 애플리케이션의 취약점을 패치합니다.