BLOG main image
분류 전체보기 (17)
궁시렁 (1)
리버싱 (0)
컴쟁이의 연구실 (11)
배워보자 (2)
좋은 곳 (0)
여행 (0)
독서 (1)
idea (0)
Visitors up to today!
Today hit, Yesterday hit
daisy rss
^0^range.net
2022. 8. 6. 11:21

EQL 정리

sysmon이벤트에 대해서 다양한 조건으로 손쉽게 검색하기 위해 만들어진 것 같다.
https://github.com/endgameinc/eql 에서 복제한 후 설치하면 된다.

Endgame사가 Elastic에 인수된 이후, EQL을 Elasticsearch에서 통합되어 사용가능하다고 한다.

단점은 eql 프로그램이 직접 evtx를 로드할 수 없고, 꼭 json형태로 변환해서 사용해야 한다.

evtx를 json으로 변환해주는 툴을 사용했지만, 에러만 나고 변환이 안되었다.
https://github.com/vavarachen/evtx2json
사용예) python evtx2json.py process_files --files sysmon.evtx

그래서 EQL홈페이지에 나온방법으로 JSON형태로 변환시킬 수 밖에 없었다.

Get-WinEvent -filterhashtable @{logname="Microsoft-Windows-Sysmon/Operational"} -Oldest | Get-EventProps | ConvertTo-Json | Out-File -Encoding ASCII -FilePath sysmon.json

중간에 Get-EventProps는 별도 작성된 함수이기 떄문에 다음을 참조하여 먼저 Import 시켜주어야 한다
https://github.com/endgameinc/eqllib/blob/master/utils/scrape-events.ps1 


위와 같이 sysmon.json을 추출하면, 이 파일을 대상으로 eql을 이용하여 쿼리할 수 있다.

예) eql query -f sysmon.json "generic where CommandLine == '*powershell*'"

그런대 홈페이지에서 제공하는 예제들은 Sysmon의 데이터필드명에 대해 Normalized을 수행하여 필드명이
조금씩 다르고 새롭게 추가된 부분도 있다. 
eql 명령어으로 Nomalized을 처리해주는 방법을 찾을 수 없어, eqllib을 다시 설치했다.

git clone https://github.com/endgameinc/eqllib.git
python setup.py build
python setup.py install
eqllib -h
eqllib query -f sysmon.json --source "Microsoft Sysmon" "process where process_name in ('ipconfig.exe', 'netstat.exe', 'systeminfo.exe', 'route.exe')"

eqllib의 명령행 인자를 찾아보니 convert-data 라는 부분이 있어 도움말을 확인했다

$ eqllib convert-data -h                                                                          
usage: eqllib convert-data [-h] [--encoding ENCODING] [--format {json,jsonl,json.gz,jsonl.gz}] [--source {security,MITRE Cyber Analytics Repository,Endgame Platform,Microsoft Sysmon}] input-file output-file

positional arguments:
  input-file            Input JSON file
  output-file           Output JSON file

options:
  -h, --help            show this help message and exit
  --encoding ENCODING, -e ENCODING
                        Encoding of input file
  --format {json,jsonl,json.gz,jsonl.gz}
  --source {security,MITRE Cyber Analytics Repository,Endgame Platform,Microsoft Sysmon}, -s {security,MITRE Cyber Analytics Repository,Endgame Platform,Microsoft Sysmon}
                        Data source

컨버팅 해보니 컨버팅도 잘 되었다.

$ eqllib convert-data --source "Microsoft Sysmon" --format json sysmon.json sysmon_normalized.json
Found 11565 events
Converted 11547 events
                                                                                                                                                                                                                                            
$ eql query -f sysmon_normalized.json '| count event_type' 
{"count": 4407, "key": "network", "percent": 0.3816575733956872}
{"count": 7140, "key": "process", "percent": 0.6183424266043128}
$

이제 eql을 이용하여 궁극적인 아토믹블루 쿼리를 해볼 수 있다.
https://eqllib.readthedocs.io/en/latest/atomicblue.html

 

process where process_name in ('powershell.exe', 'cmd.exe', 'wmic.exe', 'wscript.exe') and descendant of [process where process_name in ('excel.exe', 'winword.exe', 'powerpnt.exe', 'outlook.exe', 'hwp.exe')]


eql> search process where process_name="hwp.exe"
=============================================================================================================================================
 pid    ppid   process_name   command_line                                                                                                   
=============================================================================================================================================
 5804   5064   Hwp.exe        "C:\Program Files (x86)\Hnc\Hwp80\Hwp.exe" "C:\Users\Kim\Documents\3??-???-????.hwp" 
 5804          Hwp.exe         
 7440   5064   Hwp.exe        "C:\Program Files (x86)\Hnc\Hwp80\Hwp.exe" "C:\Users\Kim\Documents\2021.09.06 ????? ???(??).hwp" 
 7440          Hwp.exe         
 6768   5064   Hwp.exe        "C:\Program Files (x86)\Hnc\Hwp80\Hwp.exe" "C:\Users\Kim\Documents\????_??_?_???_??_??_??_????_????.hwp" 
 6768          Hwp.exe         
 3960   5064   Hwp.exe        "C:\Program Files (x86)\Hnc\Hwp80\Hwp.exe" "C:\Users\Kim\Documents\????+??+??+??+?+???+??+??+??+????_????.hwp" 
 3960          Hwp.exe         
=============================================================================================================================================
8 results found
eql> search process where ppid in (5804, 7440, 6768, 3960)
========================================================================================================================================================================================================================
 pid    ppid   process_name      command_line                                                                                                                                                                           
========================================================================================================================================================================================================================
 1456   5804   msiexec.exe       C:\Windows\System32\MsiExec.exe -Embedding F353968286C344C5C813D596B5823AF5 E Global\MSI0000 
 6680   5804   msiexec.exe       C:\Windows\syswow64\MsiExec.exe -Embedding A580338B47C3ECA6C027595877571259 E Global\MSI0000 
 4944   5804   msiexec.exe       C:\Windows\syswow64\MsiExec.exe -Embedding 94E5B8CD4FD39B745DCFD3CBAD6C788B E Global\MSI0000 
 5880   5804   msiexec.exe       C:\Windows\syswow64\MsiExec.exe -Embedding E55FED014CB3A2074462C9998210212B E Global\MSI0000 
 6672   6768   conhost.exe       \??\C:\Windows\system32\conhost.exe 0xffffffff -ForceV1 
  760   3960   conhost.exe       \??\C:\Windows\system32\conhost.exe 0xffffffff -ForceV1 
 5820   5804   msiexec.exe       c:\Windows\syswow64\MsiExec.exe -Embedding 716F7153F5ABB0E570A58E155D1A2820 E Global\MSI0000 
 4464   5804   msiexec.exe       C:\Windows\syswow64\MsiExec.exe -Embedding BEF7ABDDF77959BA25985587CDC3B5E2 E Global\MSI0000 
 4224   5804   msiexec.exe       C:\Windows\syswow64\MsiExec.exe -Embedding 4318E41F08BBA4BD29BF42960F782EEF 
 4936   5804   HimTrayIcon.exe   "C:\Program Files (x86)\Hnc\Common80\HimTrayIcon.exe" 
 1872   5804   gbb.exe           "C:\Program Files (x86)\Hnc\Common80\ImgFilters\gs\gs8.60\bin\gbb.exe" "C:\Users\Kim\AppData\Local\Temp\Hnc\BinData\EMB00001f0c32a9.eps" "C:\Users\Kim\AppData\Local\Temp\gsb21CF.tmp" 
 3476   5804   gswin32c.exe      "C:\Program Files (x86)\Hnc\Common80\ImgFilters\gs\gs8.60\bin\gswin32c.exe" @C:\Users\Kim\AppData\Local\Temp\gsa21CF.tmp 
  924   7440   HimTrayIcon.exe   "C:\Program Files (x86)\Hnc\Common80\HimTrayIcon.exe" 
 4088   6768   HimTrayIcon.exe   "C:\Program Files (x86)\Hnc\Common80\HimTrayIcon.exe" 
 4912   3960   HimTrayIcon.exe   "C:\Program Files (x86)\Hnc\Common80\HimTrayIcon.exe" 
========================================================================================================================================================================================================================
15 results found

 

근대, 이제는 detection_rule 로 넘어갔다고 한다.
ELK 에서 EQL, KQL을 이용한 탐지규칙을 적용한 것이다.

 

그러나 간단하게 쿼리를 통한 조사할때에는 여전히 유용한 도구이다.


Process 생성관계를 Tree구조로 보고 싶어서 찾아보니, 
파워쉘로 구현된 소스가 있었다.

https://github.com/gtworek/PSBits/blob/master/DFIR/GetSysmonTree.ps1





참고: https://www.elastic.co/kr/blog/getting-started-eql
Introducing Event Query Language | Elastic Blog
The No Hassle Guide to Event Query Language (EQL) for Threat Hunting (varonis.com)