지니언 EDR의 리눅스 호스트 로그에서 Log4Shell JNDI 악용, 데이터베이스 열거·추출, Evil-WinRM 원격 접속이 포트 스캔·압축·유출과 겹치는 Log4j 악용 내부 침투를 탐지합니다.
개요
쿼리
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 (match(cmd_l, "\\$\\{jndi:|jndi:(?:ldaps?|rmi|dns|iiop)://|jndi[-_]?exploit|jndi-injection|marshalsec|rogue-jndi|log4shell|cve-2021-44228")), "log4shell",
14 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and (indexof(ipath, "/") == 0 and match(cmd_l, "(?<![a-z_.-])(?:mysql|mariadb|mysqldump|psql|pg_dump|mongodump|mongoexport)\\s") and match(cmd_l, "show\\s+(?:databases|tables)|select\\s[^\\n]*\\sfrom\\s|information_schema|into\\s+outfile|(?<![a-z_.-])(?:mysqldump|pg_dump|mongodump|mongoexport)\\s")), "dbdump",
15 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and (indexof(ipath, "/") == 0 and match(cmd_l, "evil-winrm|(?<![a-z_.-])(?:crackmapexec|cme|nxc|netexec)\\s+winrm\\b|pywinrm|winrm\\.session\\(")), "evilwinrm",
16 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and (indexof(ipath, "/") == 0 and (match(ipath, "/(?:nmap|masscan|zmap|rustscan|naabu|unicornscan)$") or match(cmd_l, "(?<![a-z_.-])(?:nmap|masscan|rustscan|naabu)\\s+(?:-|[0-9])"))), "portscan",
17 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and (indexof(ipath, "/") == 0 and (match(cmd_l, "(?<![a-z_.-])find\\s[^\\n]*-i?name\\s+[\"']?\\*?[^\\s\"']*\\.(?:docx?|xlsx?|pptx?|pdf|hwpx?|ovpn)\\b") or match(cmd_l, "wp-content/uploads|word/document\\.xml"))), "docsearch",
18 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and (indexof(ipath, "/") == 0 and (match(cmd_l, "(?<![a-z_.-])(?:zip|7z|7za|rar)\\s[^\\n]*/(?:tmp|var/tmp|dev/shm)/\\S+\\.(?:zip|7z|rar)\\b") or match(cmd_l, "(?<![a-z_.-])tar\\s+-?[a-z]*c[a-z]*\\s[^\\n]*/(?:tmp|var/tmp|dev/shm)/\\S+\\.(?:tar|tgz|tar\\.gz|tar\\.bz2|tar\\.xz)\\b"))), "archive",
19 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and (indexof(ipath, "/") == 0 and (match(cmd_l, "(?<![a-z_.-])unzip\\s[^\\n]*/(?:tmp|var/tmp|dev/shm)/") or match(cmd_l, "(?<![a-z_.-])tar\\s+-?[a-z]*x[a-z]*\\s[^\\n]*/(?:tmp|var/tmp|dev/shm)/\\S+\\.(?:tar|tgz|tar\\.gz|tar\\.bz2|tar\\.xz)\\b") or match(cmd_l, "(?<![a-z_.-])(?:7z|7za)\\s+[ex]\\s[^\\n]*/(?:tmp|var/tmp|dev/shm)/"))), "unpack",
20 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and (match(cmd_l, "hashcat(?:64)?(?:\\.exe|\\.bin)?\\s+-[a-z]") or match(cmd_l, "(?:^|[\\s/\\\\])john(?:\\.exe)?\\s+[^\\r\\n]*--(?:wordlist|format|show|rules)\\b") or match(cmd_l, "hashcat\\.(?:txt|out|log|potfile)\\b|\\.potfile\\b|john\\.pot\\b")), "pwcrack",
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 (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",
23 _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",
24 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and (match(ipath, "^/(?:tmp|var/tmp|dev/shm)/")), "lx_tmpexec",
25 _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")
26| search isnotnull(grp)
27| eval tech = case(grp == "log4shell", "T1190", grp == "dbdump", "T1005", grp == "evilwinrm", "T1021.006", grp == "portscan", "T1046", grp == "docsearch", "T1083", grp == "archive", "T1560.001", grp == "unpack", "T1140", grp == "pwcrack", "T1110.002", grp == "lx_exfil", "T1041", grp == "lx_dl", "T1105", grp == "lx_tmpdrop", "T1105", grp == "lx_tmpexec", "T1204.002", grp == "lx_wipe", "T1070.004")
28| eval anchor_g = if(in(grp, "log4shell", "dbdump", "evilwinrm"), grp, null)
29| stats dc(grp) as grp_cnt, dc(anchor_g) as anchor_cnt, values(grp) as groups, values(tech) as techs, min(_time) as first_seen, max(_time) as last_seen by hostname, host_ip
30| search anchor_cnt >= 1 and grp_cnt >= 3
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)를 집계합니다. Log4Shell JNDI 악용·DB 클라이언트 열거와 추출·리눅스 WinRM 클라이언트 원격 접속 중 1개 이상이 있고(필수 행위군), 서로 다른 행위군이 3개 이상이면 탐지합니다. 탐지 결과에는 관찰된 행위군 목록(groups)과 기법 목록(techs), 첫 발생 시각(first_seen)과 마지막 발생 시각(last_seen)을 함께 제공합니다.
위협 분석
Log4Shell은 JNDI 조회 문자열 하나로 원격 코드 실행이 가능한 취약점으로, 침해된 서버는 내부 침투의 출발점이 됩니다. 공격자는 서버의 데이터베이스에서 계정 정보를 추출해 암호를 풀고, 그 계정으로 WinRM을 통해 Windows 서버에 접속하여 문서를 가져가거나 랜섬웨어를 실행합니다. 세 단계는 서로 다른 호스트에서 진행될 수 있어 단계마다 고유 행위 1개를 필수로 둡니다.
오탐 유형
데이터베이스 관리자가 DB 클라이언트로 테이블을 조회해 파일로 내보내거나, 관리자가 리눅스에서 WinRM 클라이언트로 Windows 서버를 관리하는 경우 탐지될 수 있습니다. 관리용 호스트는 hostname과 실행 계정 기준으로 예외 조건을 추가하여 조정합니다.
대응 방안
JNDI 문자열이 전송된 대상 서버의 Log4j 버전을 확인하고 패치합니다. 추출된 데이터베이스 파일의 내용과 외부 전송 여부를 확인하며, 포함된 계정의 암호를 변경합니다. 정탐으로 확인되면 호스트를 격리하고 WinRM 접속 대상 Windows 서버의 로그온 이력과 파일 접근 이력을 조회합니다.