지니언 EDR 로그에서 CHM 파일 반입 뒤 키보드 훅 키로깅과 클립보드 수집이 한 단말에서 이어지는 Kimsuky CHM형 입력 정보 탈취를 탐지합니다.
Overview
Query
1table duration=30m EDR_GENIAN
2| search (_schema == "genian-edr-file" and in(event_subtype, "FileCopy", "FileCreate", "FileDelete", "FileMove"))
3 or (_schema == "genian-edr-network" and event_subtype == "NetworkConnect")
4 or (_schema == "genian-edr-process" and event_subtype == "ProcessStart")
5 or (_schema == "genian-edr-reg" and event_subtype == "RegSetValue")
6| search len(trim(hostname)) > 0
7| eval psrc = if(len(trim(image_path)) > 0, trim(image_path), trim(image))
8| eval proc = lower(substr(psrc, lastindexof(psrc, "\\") + 1)), ipath = lower(psrc), cmd_l = lower(nvl(cmd_line, "")),
9 i_dir = if(lastindexof(psrc, "\\") >= 0, lower(substr(psrc, 0, lastindexof(psrc, "\\"))), ""),
10 par = lower(nvl(substr(parent_image, lastindexof(parent_image, "\\") + 1), "")), hostname = lower(trim(hostname))
11| 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)
12| 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)
13| eval fpath = lower(nvl(file_path, "")), f_dir = if(lastindexof(file_path, "\\") >= 0, lower(substr(file_path, 0, lastindexof(file_path, "\\"))), "")
14| eval rkey = lower(nvl(reg_key_path, "")), vname = lower(nvl(reg_value_name, "")), rval = lower(nvl(reg_value, ""))
15| eval grp = case(
16 _schema == "genian-edr-file" and in(event_subtype, "FileCreate", "FileCopy", "FileMove") and (match(fpath, "\\.chm$") and match(fpath, "(?:c:\\\\users\\\\public|c:\\\\perflogs|c:\\\\programdata|c:\\\\windows\\\\temp|\\\\appdata\\\\local\\\\temp|\\\\appdata\\\\roaming|\\\\downloads)\\\\") and not(in(proc, "msiexec.exe", "trustedinstaller.exe", "tiworker.exe"))), "chm",
17 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and ((in(proc, "powershell.exe", "pwsh.exe") and match(ps_text, "wh_keyboard_ll|getasynckeystate|setwindowshookex[\\s\\S]{0,300}\\b13\\b")) or match(proc, "keylog|keystroke") or (proc == "taskkill.exe" and match(cmd_l, "keylog"))), "keylog",
18 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and ((in(proc, "powershell.exe", "pwsh.exe") and match(ps_text, "\\bget-clipboard\\b|\\bgcb\\b|clipboard\\]::get(?:text|data|dataobject|filedroplist|image)\\b|getclipboarddata")) or (proc == "cmd.exe" and match(cmd_l, "powershell[^&|]*get-clipboard"))), "clip",
19 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and (proc == "mshta.exe" and (match(cmd_l, "mshta(?:\\.exe)?\"?\\s+\"?(?:https?://|\\\\\\\\|vbscript:|javascript:|about:)") or match(cmd_l, "(?:c:\\\\users\\\\public|c:\\\\perflogs|c:\\\\programdata|c:\\\\windows\\\\temp|\\\\appdata\\\\local\\\\temp|\\\\appdata\\\\roaming|\\\\downloads)\\\\|%(?:temp|tmp|appdata|public|programdata)%"))), "mshta",
20 _schema == "genian-edr-reg" and event_subtype == "RegSetValue" and (match(rkey, "\\\\software\\\\(?:wow6432node\\\\)?microsoft\\\\windows\\\\currentversion\\\\(?:run|runonce|runonceex|runservices|runservicesonce|policies\\\\explorer\\\\run)$") and match(rval, "c:\\\\users\\\\public\\\\|c:\\\\perflogs\\\\|\\\\windows\\\\temp\\\\|\\\\appdata\\\\local\\\\temp\\\\|%temp%|%public%|https?://|(?:^|\\\\|\")(?:powershell|pwsh|mshta|wscript|cscript|rundll32|regsvr32)(?:\\.exe)?\"?\\s")), "runkey",
21 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and ((proc == "wmic.exe" and match(cmd_l, "\\bprocess\\b[\\s\\S]*\\bcall\\s+create\\b")) or (in(proc, "powershell.exe", "pwsh.exe") and match(ps_text, "invoke-(?:wmi|cim)method\\b[\\s\\S]*win32_process\\b[\\s\\S]*create|win32_process\\b[\\s\\S]*invoke-(?:wmi|cim)method\\b[\\s\\S]*create|\\[wmiclass\\][\\s\\S]*win32_process[\\s\\S]*\\.create\\("))), "wmiexec",
22 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and (((proc == "certutil.exe" or (proc == "cmd.exe" and match(cmd_l, "/[ck]\\s+(?:.*&\\s*)?\"?certutil(?:\\.exe)?\"?\\s"))) and match(cmd_l, "(?:^|\\s)[-/]decode(?:hex)?\\s+\\S+\\s+\\S+")) or (in(proc, "powershell.exe", "pwsh.exe") and match(ps_text, "frombase64string[\\s\\S]*(?:writeallbytes|set-content|out-file)"))), "decode",
23 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and ((in(proc, "powershell.exe", "pwsh.exe") and (match(ps_text, "(?:compress|expand)-archive\\b[^\\r\\n]*(?:c:\\\\users\\\\public|c:\\\\perflogs|c:\\\\windows\\\\temp|c:\\\\programdata\\\\[^\\\\\"]+\\.zip)") or (match(ps_text, "compress-archive\\b") and match(ps_text, "(?:c:\\\\users\\\\public|c:\\\\perflogs|c:\\\\windows\\\\temp|c:\\\\programdata)\\\\[^\\\\\"]+\\.zip")))) or (in(proc, "7z.exe", "7za.exe", "7zr.exe", "rar.exe", "winrar.exe", "tar.exe", "makecab.exe") and match(cmd_l, "(?:c:\\\\users\\\\public|c:\\\\perflogs|c:\\\\programdata|c:\\\\windows\\\\temp|\\\\appdata\\\\local\\\\temp|\\\\appdata\\\\roaming|\\\\downloads)\\\\") and not(par == "tiworker.exe"))), "archive",
24 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and ((in(proc, "powershell.exe", "pwsh.exe") and match(ps_text, "(?:invoke-(?:webrequest|restmethod)|\\biwr\\b|\\birm\\b)[\\s\\S]*-method\\s+['\"]?(?:post|put)\\b[\\s\\S]*-(?:infile|body)\\b|(?:invoke-(?:webrequest|restmethod)|\\biwr\\b|\\birm\\b)[\\s\\S]*-(?:infile|body)\\b[\\s\\S]*-method\\s+['\"]?(?:post|put)\\b|\\.upload(?:file|data|string)(?:async)?\\s*\\(")) or (proc == "curl.exe" and match(cmd_l, "(?:^|\\s)(?:-t|--upload-file)\\s+\\S|(?:^|\\s)(?:-f|--form)\\s+['\"]?[^\\s'\"]*=@|(?:^|\\s)(?:--data-binary|-d|--data)\\s+['\"]?@")) or (proc == "bitsadmin.exe" and match(cmd_l, "/transfer\\b[\\s\\S]*/upload\\b"))), "exfil",
25 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and (in(proc, "powershell.exe", "pwsh.exe", "cmd.exe") and (match(ps_text, "\\b(?:copy|copy-item|cp|cpi|move|move-item|xcopy)\\s[^\\r\\n]*c:\\\\windows\\\\system32\\\\[\\s\\S]*(?:get-filehash|certutil[^\\r\\n]*-hashfile)") or match(ps_text, "\\b(?:copy|copy-item|cp|cpi|xcopy)\\s[^\\r\\n]*(?:c:\\\\users\\\\public|c:\\\\perflogs|c:\\\\programdata|c:\\\\windows\\\\temp|\\\\appdata\\\\local\\\\temp|\\\\appdata\\\\roaming|\\\\downloads)\\\\[\\s\\S]*(?:get-filehash|certutil[^\\r\\n]*-hashfile)[\\s\\S]*(?:get-filehash|certutil[^\\r\\n]*-hashfile)[\\s\\S]*-eq\\b"))), "evasioncheck",
26 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and ((in(proc, "tasklist.exe", "qprocess.exe") and not(contains(cmd_line, "/?"))) or (proc == "query.exe" and match(cmd_l, "\\bquery(?:\\.exe)?\"?\\s+process\\b")) or (proc == "wmic.exe" and match(cmd_l, "\\bprocess\\b[\\s\\S]*\\b(?:get|list)\\b") and not(match(cmd_l, "\\bcall\\b"))) or (in(proc, "powershell.exe", "pwsh.exe") and match(ps_text, "get-process|\\bgps\\b") and match(ps_text, "(?:msmpeng|mssense|sentinelagent|csfalconservice|cylancesvc|mcshield|bdservicehost|savservice|sophos|ekrn|avp\\.exe|ntrtscan|tmbmsrv|cbdefense|repmgr|xagt|elastic-endpoint|vsserv|ccsvchst|avastsvc|v3svc|ayagent)[\\s\\S]*(?:msmpeng|mssense|sentinelagent|csfalconservice|cylancesvc|mcshield|bdservicehost|savservice|sophos|ekrn|avp\\.exe|ntrtscan|tmbmsrv|cbdefense|repmgr|xagt|elastic-endpoint|vsserv|ccsvchst|avastsvc|v3svc|ayagent)"))), "proclist",
27 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and (in(proc, "powershell.exe", "pwsh.exe") and match(ps_text, "add-type[\\s\\S]*dllimport|dllimport[\\s\\S]*add-type")), "nativeapi",
28 _schema == "genian-edr-file" and event_subtype == "FileCreate" and ((match(fpath, "\\.(?:exe|dll|sys|scr|cpl|bat|cmd|ps1|vbs|vbe|js|jse|wsf|hta)$") or (nvl(file_type, "") == "PE" and not(match(fpath, "\\.[a-z0-9]{2,4}$")))) and (indexof(fpath, "c:\\users\\public\\") == 0 or indexof(fpath, "c:\\perflogs\\") == 0 or in(f_dir, "c:\\programdata", "c:\\windows\\temp")) and not(match(fpath, "\\\\__psscriptpolicytest_[^\\\\]+\\.ps1$")) and not(in(proc, "msiexec.exe", "trustedinstaller.exe", "tiworker.exe", "mpsigstub.exe", "mpcmdrun.exe", "msmpeng.exe", "dismhost.exe", "system"))), "drop",
29 _schema == "genian-edr-file" and event_subtype == "FileCreate" and (match(fpath, "\\.(?:zip|7z|rar)$") and (indexof(fpath, "c:\\users\\public\\") == 0 or indexof(fpath, "c:\\perflogs\\") == 0 or in(f_dir, "c:\\programdata", "c:\\windows\\temp")) and not(in(proc, "msiexec.exe", "trustedinstaller.exe", "tiworker.exe", "mpsigstub.exe", "mpcmdrun.exe", "msmpeng.exe", "dismhost.exe", "system", "svchost.exe"))), "archdrop",
30 _schema == "genian-edr-file" and event_subtype == "FileDelete" and (match(proc, "^(?:msmpeng|mssense|sentinelagent|csfalconservice|cylancesvc|mcshield|bdservicehost|savservice|sophos|ekrn|avp\\.exe|ntrtscan|tmbmsrv|cbdefense|repmgr|xagt|elastic-endpoint|vsserv|ccsvchst|avastsvc|v3svc|ayagent)") and match(fpath, "(?:c:\\\\users\\\\public|c:\\\\perflogs|c:\\\\programdata|c:\\\\windows\\\\temp|\\\\appdata\\\\local\\\\temp|\\\\appdata\\\\roaming|\\\\downloads)\\\\") and match(fpath, "\\.(?:exe|dll|scr|com|pif|cpl|sys|swf|jar|js|jse|vbs|vbe|wsf|hta|ps1|bat|cmd|lnk|docm|xlsm|zip|rar|7z|iso|img|txt)$") and not(match(fpath, "^c:\\\\programdata\\\\microsoft\\\\"))), "avquar",
31 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and ((in(proc, "powershell.exe", "pwsh.exe") and match(ps_text, "remove-item|\\bdel\\b|\\bri\\b|\\brm\\b") and match(ps_text, "(?:c:\\\\users\\\\public|c:\\\\perflogs|c:\\\\windows\\\\temp|c:\\\\programdata)\\\\[^\\r\\n\"']*\\.(?:exe|dll|sys|ps1|bat|cmd|vbs|js|jse|hta|cs|bin|zip|7z|rar)\\b")) or (proc == "cmd.exe" and match(cmd_l, "\\b(?:del|erase)\\b[^&|]*(?:c:\\\\users\\\\public|c:\\\\perflogs|c:\\\\windows\\\\temp|c:\\\\programdata|%temp%|\\\\appdata\\\\local\\\\temp)\\\\[^&|\"]*\\.(?:exe|dll|sys|ps1|bat|cmd|vbs|js|jse|hta|bin)\\b")) or in(proc, "sdelete.exe", "sdelete64.exe")), "wipe",
32 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and (in(proc, "powershell.exe", "pwsh.exe") and match(cmd_line, "(?i)(?:^|\\s)\"?-(?:ep|ex|exe|exec|execu|execut|executi|executio|execution|executionp|executionpo|executionpol|executionpoli|executionpolic|executionpolicy)\"?\\s+\"?bypass\"?(?:\\s|$)") and (isnotnull(b64) or match(cmd_l, "(?:^|\\s)\"?-(?:f|fi|fil|file)\"?\\s+\"?(?:c:\\\\users\\\\public|c:\\\\perflogs|c:\\\\windows\\\\temp|c:\\\\programdata|c:\\\\users\\\\[^\\\\]+\\\\appdata\\\\local\\\\temp)\\\\"))), "psbypass",
33 _schema == "genian-edr-network" and event_subtype == "NetworkConnect" and (in(proc, "powershell.exe", "pwsh.exe", "mshta.exe", "wscript.exe", "cscript.exe", "rundll32.exe", "regsvr32.exe", "certutil.exe", "bitsadmin.exe") and isnotnull(remote_ip) and not(match(remote_ip, "^(?:10\\.|127\\.|192\\.168\\.|172\\.(?:1[6-9]|2\\d|3[01])\\.|169\\.254\\.|0\\.|::1|fe80)"))), "webc2")
34| search isnotnull(grp)
35| eval tech = case(grp == "chm", "T1105", grp == "keylog", "T1056.001", grp == "clip", "T1115", grp == "mshta", "T1218.005", grp == "runkey", "T1547.001", grp == "wmiexec", "T1047", grp == "decode", "T1140", grp == "archive", "T1560", grp == "exfil", "T1041", grp == "evasioncheck", "T1497", grp == "proclist", "T1057", grp == "nativeapi", "T1106", grp == "drop", "T1105", grp == "archdrop", "T1105", grp == "avquar", "T1587.001", grp == "wipe", "T1070.004", grp == "psbypass", "T1059.001", grp == "webc2", "T1071.001")
36| eval anchor_g = if(in(grp, "chm", "keylog", "clip"), grp, null)
37| 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
38| search anchor_cnt >= 2 and grp_cnt >= 6
39| eval groups = strjoin(", ", groups), techs = strjoin(", ", techs),
40 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)를 집계합니다. 사용자 쓰기 위치 CHM 파일 반입·PowerShell 저수준 키보드 훅 키로깅·클립보드 내용 수집 중 2개 이상이 있고(필수 행위군), 서로 다른 행위군이 6개 이상이면 탐지합니다. 탐지 결과에는 관찰된 행위군 목록(groups)과 기법 목록(techs), 첫 발생 시각(first_seen)과 마지막 발생 시각(last_seen)을 함께 제공합니다.
Threat analysis
도움말 파일(CHM)은 내부 스크립트를 실행할 수 있어 스피어피싱 첨부로 악용됩니다. 실행 후 mshta와 Run 키로 지속성을 확보하고 PowerShell 저수준 키보드 훅으로 키 입력을 기록하는 것은 계정과 암호를 직접 노리는 행위입니다. 클립보드 수집과 압축이 이어지면 수집한 입력 정보가 C2로 전송되는 단계입니다.
False positives
화면 캡처·매크로·입력기 보조 프로그램이 키보드 훅과 클립보드 접근을 사용하는 경우가 있으나, PowerShell에서 직접 훅을 거는 형태는 드뭅니다. 확인된 업무용 자동화 스크립트는 경로 기준으로 예외 조건을 추가하여 조정합니다.
Response actions
키 입력·클립보드가 기록된 파일과 압축 파일을 확보하여 수집된 내용을 확인합니다. Run 키에 등록된 스크립트와 CHM 파일을 확보하고 유입 메일을 추적합니다. 정탐으로 확인되면 단말을 격리하고, 수집 구간에 사용자가 입력한 모든 계정의 암호를 변경합니다.