지니언 EDR 로그에서 PowerShell의 Win32 API 호출을 통한 디버거·시스템 언어·국가 확인과 섀도 복사본 삭제·암호화가 한 단말에서 함께 나타나는 랜섬웨어 실행 준비를 탐지합니다.
개요
쿼리
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 or (_schema == "genian-edr-reg" and event_subtype == "RegSetValue")
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 rkey = lower(nvl(reg_key_path, "")), vname = lower(nvl(reg_value_name, "")), rval = lower(nvl(reg_value, ""))
14| eval grp = case(
15 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and (in(proc, "powershell.exe", "pwsh.exe") and match(ps_text, "isdebuggerpresent|checkremotedebuggerpresent|ntqueryinformationprocess|outputdebugstring|debugger\\]::isattached")), "antidebug",
16 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and ((in(proc, "powershell.exe", "pwsh.exe") and match(ps_text, "getuserdefaultlcid|getsystemdefaultlcid|getuserdefaultlocalename|getsystemdefaultlocalename|getuserdefaultuilanguage|getsystemdefaultuilanguage|getkeyboardlayoutlist|get-winsystemlocale|get-winuserlanguagelist")) or (proc == "reg.exe" and match(cmd_l, "\\bquery\\b[\\s\\S]*(?:\\\\nls\\\\language|\\\\keyboard layout)"))), "language",
17 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and (in(proc, "powershell.exe", "pwsh.exe") and match(ps_text, "getlocaleinfo|getgeoinfo|getusergeoid|get-winhomelocation|ipinfo\\.io|ip-api\\.com|ipapi\\.co|geoplugin|ipwho\\.is|freegeoip")), "geo",
18 _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",
19 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and ((proc == "vssadmin.exe" and match(cmd_l, "\\bdelete\\s+shadows\\b|\\bresize\\s+shadowstorage\\b")) or (proc == "wmic.exe" and match(cmd_l, "shadowcopy[\\s\\S]*\\bdelete\\b")) or (proc == "bcdedit.exe" and match(cmd_l, "recoveryenabled\\s+no|bootstatuspolicy\\s+ignoreallfailures")) or (proc == "wbadmin.exe" and match(cmd_l, "\\bdelete\\s+(?:catalog|systemstatebackup|backup)\\b")) or (in(proc, "powershell.exe", "pwsh.exe") and match(ps_text, "win32_shadowcopy[\\s\\S]*(?:\\.delete\\(\\)|remove-(?:cim|wmi)(?:instance|object))|remove-(?:cim|wmi)(?:instance|object)[\\s\\S]*win32_shadowcopy|vssadmin[^\\r\\n]*delete\\s+shadows"))), "shadow",
20 _schema == "genian-edr-file" and in(event_subtype, "FileCreate", "FileMove") and (match(fpath, "\\.(?:conti|vanhelsing|vanlocker|locked|lockbit|encrypted|crypted|ryk|babyk|akira|royal|basta|hive|clop|medusa|rhysida|8base|phobos|makop|djvu)$") or match(fpath, "\\\\(?:how[_-]?to[_-]?(?:decrypt|restore|recover)|restore[_-]?(?:my[_-]?)?files|decrypt[_-]?(?:my[_-]?)?files|readme[_-]?(?:for[_-]?)?decrypt|_readme_|ransom)[^\\\\]*\\.(?:txt|html?|hta)$")), "encrypt",
21 _schema == "genian-edr-reg" and event_subtype == "RegSetValue" and (match(rkey, "\\\\control panel\\\\desktop$|\\\\policies\\\\system$|\\\\policies\\\\activedesktop$") and vname == "wallpaper" and not(in(proc, "explorer.exe", "systemsettings.exe", "systemsettingsadminflows.exe", "svchost.exe"))), "deface",
22 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and (in(proc, "nmap.exe", "masscan.exe", "portqry.exe", "advanced_ip_scanner.exe", "netscan.exe", "ipscan.exe") or (in(proc, "powershell.exe", "pwsh.exe") and match(ps_text, "test-netconnection[\\s\\S]*-port\\b|\\btnc\\b[\\s\\S]*-port\\b|net\\.sockets\\.tcpclient[\\s\\S]*\\.(?:connect|beginconnect|connectasync)\\("))), "portscan",
23 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and (((proc == "net.exe" or (proc == "net1.exe" and par != "net.exe")) and match(cmd_l, "\\bnet1?(?:\\.exe)?\"?\\s+(?:view\\s+\\\\\\\\|share\\s*$)")) or (proc == "wmic.exe" and match(cmd_l, "\\bshare\\b[\\s\\S]*\\b(?:get|list)\\b|\\bshare\\s*$")) or (in(proc, "powershell.exe", "pwsh.exe") and match(ps_text, "get-smbshare\\b|win32_share\\b|netshareenum|get-netshare|invoke-sharefinder"))), "share",
24 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and (in(proc, "systeminfo.exe", "hostname.exe") or (proc == "wmic.exe" and match(cmd_l, "\\b(?:os|computersystem|bios|qfe|csproduct|path\\s+win32_(?:operatingsystem|bios|baseboard|computersystemproduct))\\b[\\s\\S]*\\b(?:get|list)\\b")) or (in(proc, "powershell.exe", "pwsh.exe") and match(ps_text, "getnativesysteminfo|getsysteminfo\\b|get-computerinfo|win32_operatingsystem|\\.partofdomain\\b|dllimport[\\s\\S]*\\b(?:getlogicaldrivestringsw?|getdrivetypew?|getlogicaldrives)\\b"))), "sysinfo",
25 _schema == "genian-edr-process" and event_subtype == "ProcessStart" and (in(proc, "whoami.exe", "quser.exe") or (proc == "query.exe" and match(cmd_l, "\\bquery(?:\\.exe)?\"?\\s+(?:user|session)\\b")) or (in(proc, "powershell.exe", "pwsh.exe") and match(ps_text, "windowsidentity\\]::getcurrent\\(\\)[\\s\\S]*isinrole|isinrole\\([\\s\\S]*administrator")) or (in(proc, "wmic.exe", "powershell.exe", "pwsh.exe") and match(ps_text, "\\b(?:win32_logonsession|win32_loggedonuser)\\b"))), "user",
26 _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",
27 _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")
28| search isnotnull(grp)
29| eval tech = case(grp == "antidebug", "T1622", grp == "language", "T1614.001", grp == "geo", "T1614", grp == "nativeapi", "T1106", grp == "shadow", "T1490", grp == "encrypt", "T1486", grp == "deface", "T1491", grp == "portscan", "T1046", grp == "share", "T1135", grp == "sysinfo", "T1082", grp == "user", "T1033", grp == "drop", "T1105", grp == "evasioncheck", "T1497")
30| eval anchor_g = if(in(grp, "antidebug", "language", "geo", "nativeapi", "shadow", "encrypt", "deface"), grp, null), has_lang_v = if(grp == "language", 1, 0)
31| stats dc(grp) as grp_cnt, dc(anchor_g) as anchor_cnt, max(has_lang_v) as has_lang, values(grp) as groups, values(tech) as techs, min(_time) as first_seen, max(_time) as last_seen by hostname, host_ip
32| search has_lang == 1 and anchor_cnt >= 3 and grp_cnt >= 4
33| eval groups = strjoin(", ", groups), techs = strjoin(", ", techs),
34 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)를 집계합니다. 시스템 언어 조회가 반드시 있고, 디버거 탐지·언어 확인·국가 확인·Win32 API 직접 호출·섀도 복사본 삭제·암호화 파일 생성·배경화면 변경 중 3개 이상이 있으며(필수 행위군), 서로 다른 행위군이 4개 이상이면 탐지합니다. 탐지 결과에는 관찰된 행위군 목록(groups)과 기법 목록(techs), 첫 발생 시각(first_seen)과 마지막 발생 시각(last_seen)을 함께 제공합니다.
위협 분석
랜섬웨어는 암호화 전에 디버거 유무와 시스템 언어·국가를 확인하여 분석 환경이나 특정 지역 단말에서는 실행을 멈춥니다. 이 점검 뒤에 섀도 복사본 삭제와 파일 암호화, 배경화면 변경이 이어지면 암호화가 이미 진행 중일 수 있습니다. 공유·포트 탐색이 함께 관찰되면 다른 단말로 확산할 가능성이 있으므로 즉시 대응합니다.
오탐 유형
다국어 지원 소프트웨어나 설치 스크립트가 PowerShell에서 Win32 API로 언어·지역 정보를 조회하는 경우가 있고, 백업 소프트웨어가 섀도 복사본을 정리하는 경우가 있습니다. 필수 행위군 3개가 함께 요구되어 단독으로는 탐지되지 않으며, 반복 탐지되는 정상 스크립트는 경로 기준으로 예외 조건을 추가합니다.
대응 방안
해당 단말을 우선 네트워크에서 격리하고, 암호화된 파일의 확장자·범위와 섀도 복사본 상태를 확인합니다. API를 호출한 PowerShell 명령줄과 부모 프로세스로 유입 경로를 확인하고, 공유·포트 탐색 대상이 된 단말에서 같은 행위가 있는지 조회합니다. 정탐으로 확인되면 백업에서 복구하고 유입에 쓰인 파일을 차단합니다.