Yamato-Security / hayabusa

Hayabusa (隼) is a sigma-based threat hunting and fast forensics timeline generator for Windows event logs.
GNU Affero General Public License v3.0
2.26k stars 200 forks source link

Support JSON formatted event log input #386

Closed YamatoSecurity closed 1 year ago

YamatoSecurity commented 2 years ago

Zircoliteのようにhttps://github.com/OTRF/Security-Datasets/blob/master/datasets/compound/apt29/day1/apt29_evals_day1_manual.zip などのJSON形式のログファイルを解析できるようにしたいです。JSON形式しかないAPT EmulationのログファイルがOTRFに提供されているので、JSONに対応していたら、一つの攻撃シナリオを解析できて、ルール作成に助かるし、勉強会等もできそうです。

可能であれば、v1.1に入れたいです。

hitenkoku commented 2 years ago

JSON入力の内容を見て判断します。zipファイルを指定するというより、rulesオプションのようにディレクトリ、JSONファイルを指定して読み込む形にしたほうが良いと思います

YamatoSecurity commented 2 years ago

ユーザが.zipを解凍して、元のJSONファイルに対してスキャンするイメージです。 ファイルサイズが大きいだけで、圧縮されていると思います。

hitenkoku commented 2 years ago

承りました。JSONファイルは司令される場合は1個もしくは、複数個読み込む(ディレクトリ指定時)形を想定します。 また、頂いたURLのデータを確認しました。ひとまず確認はしてみます。

hitenkoku commented 2 years ago

一応確認をしてみましたが、読み込み自体は問題はなさそうですが、evtxとしてよみこんだデータとの比較をしておきます。これが違ってたりすると、別の枠組みが必要になるかもしれないのでv1.1からは外したほうが良さそうです。また、入力値について、jsonの記載内容でvalidationするのは難しいので、jsonデータの形式が合っているかどうかまででよろしいでしょうか。

hitenkoku commented 2 years ago

@YamatoSecurity 同じイベントIDで頂戴したデータとhayabusaで読み込んだ時のserde_jsonの値を比較してみましたが、evtxと指定されたjsonデータで結構大きく構成が違うためjsonデータ側の方で異なった変換をさせないとevtxと同じように解析できないです。

特に各eventkey_alias.txtで紐づけている階層構造と大きく異なるためそこの変換は必要で、JSONを読み込んだ場合のパースを別途作成する必要がありそうです。

例えばjson側にはSystemTimeがないですが以下のどちらなのかなどの細かい対応付けも必要です

{"EventTime":"2020-05-01 22:56:47","port":60737,"Message":"An attempt was made to duplicate a handle to an object.\r\n\r\nSubject:\r\n\tSecurity ID:\t\tS-1-5-18\r\n\tAccount Name:\t\tNEWYORK$\r\n\tAccount Domain:\t\tDMEVALS\r\n\tLogon ID:\t\t0x3E7\r\n\r\nSource Handle Information:\r\n\tSource Handle ID:\t0x40c\r\n\tSource Process ID:\t0x634\r\n\r\nNew Handle Information:\r\n\tTarget Handle ID:\t0x1ca8\r\n\tTarget Process ID:\t0x4","Opcode":"Info","EventID":4690,"TargetProcessId":"0x4","SourceModuleName":"eventlog","tags":["mordorDataset"],"@version":"1","SourceName":"Microsoft-Windows-Security-Auditing","SubjectLogonId":"0x3e7","host":"wec.internal.cloudapp.net","Task":12807,"ThreadID":1740,"EventReceivedTime":"2020-05-01 22:56:48","TargetHandleId":"0x1ca8","Category":"Handle Manipulation","Keywords":-9214364837600034816,"RecordNumber":146503,"SourceProcessId":"0x634","SourceModuleType":"im_msvistalog","@timestamp":"2020-05-02T02:56:48.669Z","SeverityValue":2,"Version":0,"OpcodeValue":0,"SubjectUserSid":"S-1-5-18","Severity":"INFO","Channel":"Security","SubjectUserName":"NEWYORK$","SourceHandleId":"0x40c","SubjectDomainName":"DMEVALS","EventType":"AUDIT_SUCCESS","ProcessId":"0x634","Hostname":"NEWYORK.dmevals.local","ExecutionProcessID":4,"ProviderGuid":"{54849625-5478-4994-A5BA-3E3B0328C30D}"}
data:Object({"Event": Object({"EventData": Object({"AuthenticationPackageName": String("Negotiate"), "IpAddress": String("-"), "IpPort": String("-"), "KeyLength": Number(0), "LmPackageName": String("-"), "LogonGuid": String("00000000-0000-0000-0000-000000000000"), "LogonProcessName": String("Advapi  "), "LogonType": Number(5), "ProcessId": String("0x1dc"), "ProcessName": String("C:\\Windows\\System32\\services.exe"), "SubjectDomainName": String("WORKGROUP"), "SubjectLogonId": String("0x3e7"), "SubjectUserName": String("IE10WIN7$"), "SubjectUserSid": String("S-1-5-18"), "TargetDomainName": String("NT AUTHORITY"), "TargetLogonId": String("0x3e7"), "TargetUserName": String("SYSTEM"), "TargetUserSid": String("S-1-5-18"), "TransmittedServices": String("-"), "WorkstationName": String("")}), "System": Object({"Channel": String("Security"), "Computer": String("IE10Win7"), "Correlation": Null, "EventID": Number(4624), "EventRecordID": Number(4690), "Execution_attributes": Object({"ProcessID": Number(484), "ThreadID": Number(776)}), "Keywords": String("0x8020000000000000"), "Level": Number(0), "Opcode": Number(0), "Provider_attributes": Object({"Guid": String("54849625-5478-4994-A5BA-3E3B0328C30D"), "Name": String("Microsoft-Windows-Security-Auditing")}), "Security": Null, "Task": Number(12544), "TimeCreated_attributes": Object({"SystemTime": String("2016-08-18T14:46:22.359500Z")}), "Version": Number(0)})}), "Event_attributes": Object({"xmlns": String("http://schemas.microsoft.com/win/2004/08/events/event")})})
hitenkoku commented 2 years ago

splunkのデータセットもJSONで提供しているので活用したいが、形式が違うかもしれない……

hitenkoku commented 2 years ago

hayabusaのjsonルールを作って対応するとか?

YamatoSecurity commented 2 years ago

Memo: Splunk Boss of the SOC (BOTS) https://github.com/splunk/securitydatasets

hitenkoku commented 2 years ago

Splunk Boss of the SOCのデータセットを確認しましたが、JSON形式のデータが無かったです…… splunkから読み込んできてjsonで吐き出させて確認するという事でよろしいでしょうか。

YamatoSecurity commented 2 years ago

ほんまですね。。 BOTSv1のデータセットに元々のJSONファイルも提供している:https://github.com/splunk/botsv1 が、v2とv3の最近のコンテストではsplunkのデータしか提供してないですね。(T_T) 取り敢えずv1のJSONを確認しましょうか?

いつかはsplunk/elastic stack等のSIEM -> JSON export -> Hayabusa解析ができたら良いな〜と思ってますが、色々調べた上で考えた方が良いので、時間がかかりそうです。

hitenkoku commented 2 years ago

承りましたー。それではbotsv1のjsonを確認させていただきます。

hitenkoku commented 2 years ago

botsv1のjsonを確認したところ以下の形式でした。

結論から言うと形式自体は異なっています。 問題点としては、jsonでのフィールドでは一部項目で大文字小文字が異なっているなどがあるので、純粋な比較ができないのでその対応のためにはeventkey_alias.txtにJSON用の新たに列を追加して対応をさせる必要があります。一旦この項目については実施するかどうかを相談させてください

xmlの属性値部分の取得などの場合はどの様になっているか、確認をしておきます


{"preview":false,"offset":0,"result":{"ComputerName":"we5201srv.waynecorpinc.local","EventCode":"1000","EventType":"4","Keywords":"None","LogName":"Application","Message":"Performance counters for the WmiApRpl (WmiApRpl) service were loaded successfully. The Record Data in the data section contains the new index values assigned to this service.","OpCode":"Info","RecordNumber":"1096","Sid":"S-1-5-18","SidType":"0","SourceName":"Microsoft-Windows-LoadPerf","TaskCategory":"None","Type":"Information","User":"NOT_TRANSLATED","date_hour":"23","date_mday":"28","date_minute":"54","date_month":"august","date_second":"31","date_wday":"sunday","date_year":"2016","date_zone":"local","dest":"we5201srv.waynecorpinc.local","dvc":"we5201srv","dvc_nt_host":"we5201srv","event_id":"1096","eventtype":["winapp","wineventlog_application","wineventlog_windows"],"host":"we5201srv","id":"1096","index":"botsv1","linecount":"16","punct":"//_::_==--====..==---======_____()____.___________","severity":"Information","severity_id":"4","signature_id":"1000","source":"WinEventLog:Application","sourcetype":"WinEventLog:Application","splunk_server":"kraken.local","tag":["os","windows"],"tag::eventtype":["os","windows"],"timeendpos":"23","timestartpos":"0","_bkt":"botsv1~59~25FE58F7-C438-478E-AC42-625F7A4D81D6","_cd":"59:501441591","_eventtype_color":"none","_indextime":"1473359337","_pre_msg":"08/28/2016 23:54:31 PM\nLogName=Application\nSourceName=Microsoft-Windows-LoadPerf\nEventCode=1000\nEventType=4\nType=Information\nComputerName=we5201srv.waynecorpinc.local\nUser=NOT_TRANSLATED\nSid=S-1-5-18\nSidType=0\nTaskCategory=None\nOpCode=Info\nRecordNumber=1096\nKeywords=None","_raw":"08/28/2016 23:54:31 PM\nLogName=Application\nSourceName=Microsoft-Windows-LoadPerf\nEventCode=1000\nEventType=4\nType=Information\nComputerName=we5201srv.waynecorpinc.local\nUser=NOT_TRANSLATED\nSid=S-1-5-18\nSidType=0\nTaskCategory=None\nOpCode=Info\nRecordNumber=1096\nKeywords=None\nMessage=Performance counters for the WmiApRpl (WmiApRpl) service were loaded successfully. The Record Data in the data section contains the new index values assigned to this service.\n","_serial":"0","_si":["kraken.local","botsv1"],"_sourcetype":"WinEventLog:Application","_time":"2016-08-28 17:54:31.000 MDT"}}
YamatoSecurity commented 2 years ago

確認ありがとうございます! データセットのJSONがそれぞれ違うので、対応するのは大変で広く使えなさそうなので、取り敢えずbotsとOTRF dataset対応なしにしましょうか?

それより、Messageを検索するルールが20件ぐらいありますが、元々のevtxファイルにMessageがないので、Messageが記録されているxmlかjsonファイルにexportしてから、Message検索と出力対応にした方が良さそうです。(アラートを確認する際にMessage情報があると助かるので)

今、良さそうなexport方法を調査中です。残念ながら、Windowsイベントログを書き込むrust crateはあるけど、exportするcrateは無さそうです。 PowershellでGet-WinEvent -LogName system |ConvertTo-JsonGet-WinEvent -LogName system |ConvertTo-Xmlで良い感じに変換できるけど、とても遅いのと、Windows 7のデフォルトPowershellバージョンでは使えないかもしれません。

Event ViewerのGUIからMessageが記録されているXMLをエクスポートできるけど、GUIなので自動化できません。

wevtutil.exeでMessageが無いXMLかテキストのMessageのどちらかをexportできるけど、Event ViewerのようにMessageが含まれているXMLを出力できなさそうなので、もう少し調べてみます。。

これを別のissueにしましょうか?

hitenkoku commented 2 years ago

承りました。#458 に記載した通り、Rustのevtxライブラリのバイナリがexportの機能を持っているので、それを使ってxmlやjsonへ変換してみて、xmlファイルやjsonファイルも読み込み指定にすることができるように変更します

YamatoSecurity commented 2 years ago

了解です。では、こちらのissueを取り敢えずクローズします。

YamatoSecurity commented 1 year ago

@hitenkoku DMでも話しましたが、boss of the SOCはなしで、ワークショップのために https://github.com/OTRF/Security-Datasets/blob/master/datasets/compound/apt29/day1/apt29_evals_day1_manual.zip のJSON形式に対応できるか検討したいです。

hitenkoku commented 1 year ago

提示いただいたJSONについては以下の構造をしていましたboss of the SOCとは異なる形式となっていました。失礼いたしました

{"EventTime":"2020-05-01 22:55:23","port":60737,"Message":"Process accessed:\r\nRuleName: -\r\nUtcTime: 2020-05-02 02:55:23.551\r\nSourceProcessGUID: {6bbf237a-cafb-5eac-1000-000000000400}\r\nSourceProcessId: 900\r\nSourceThreadId: 504\r\nSourceImage: C:\\windows\\system32\\svchost.exe\r\nTargetProcessGUID: {6bbf237a-cb97-5eac-6202-000000000400}\r\nTargetProcessId: 2092\r\nTargetImage: C:\\windows\\System32\\svchost.exe\r\nGrantedAccess: 0x1000\r\nCallTrace: C:\\windows\\SYSTEM32\\ntdll.dll+9c584|C:\\windows\\SYSTEM32\\psmserviceexthost.dll+222a3|C:\\windows\\SYSTEM32\\psmserviceexthost.dll+1a172|C:\\windows\\SYSTEM32\\psmserviceexthost.dll+19e3b|C:\\windows\\SYSTEM32\\psmserviceexthost.dll+19318|C:\\windows\\SYSTEM32\\ntdll.dll+3089d|C:\\windows\\SYSTEM32\\ntdll.dll+34634|C:\\windows\\System32\\KERNEL32.DLL+17bd4|C:\\windows\\SYSTEM32\\ntdll.dll+6ced1","SourceThreadId":"504","EventID":10,"TargetProcessId":"2092","SourceModuleName":"eventlog","tags":["mordorDataset"],"@version":"1","SourceImage":"C:\\windows\\system32\\svchost.exe","SourceName":"Microsoft-Windows-Sysmon","AccountType":"User","TargetImage":"C:\\windows\\System32\\svchost.exe","host":"wec.internal.cloudapp.net","Task":10,"ThreadID":4396,"EventReceivedTime":"2020-05-01 22:55:26","CallTrace":"C:\\windows\\SYSTEM32\\ntdll.dll+9c584|C:\\windows\\SYSTEM32\\psmserviceexthost.dll+222a3|C:\\windows\\SYSTEM32\\psmserviceexthost.dll+1a172|C:\\windows\\SYSTEM32\\psmserviceexthost.dll+19e3b|C:\\windows\\SYSTEM32\\psmserviceexthost.dll+19318|C:\\windows\\SYSTEM32\\ntdll.dll+3089d|C:\\windows\\SYSTEM32\\ntdll.dll+34634|C:\\windows\\System32\\KERNEL32.DLL+17bd4|C:\\windows\\SYSTEM32\\ntdll.dll+6ced1","Domain":"NT AUTHORITY","UtcTime":"2020-05-02 02:55:23.551","Keywords":-9223372036854775808,"RecordNumber":138294,"SourceProcessId":"900","SourceModuleType":"im_msvistalog","@timestamp":"2020-05-02T02:55:26.493Z","SeverityValue":2,"Version":3,"OpcodeValue":0,"Severity":"INFO","Channel":"Microsoft-Windows-Sysmon/Operational","AccountName":"SYSTEM","GrantedAccess":"0x1000","SourceProcessGUID":"{6bbf237a-cafb-5eac-1000-000000000400}","EventType":"INFO","UserID":"S-1-5-18","TargetProcessGUID":"{6bbf237a-cb97-5eac-6202-000000000400}","ProcessId":"900","Hostname":"UTICA.dmevals.local","RuleName":"-","ExecutionProcessID":3496,"ProviderGuid":"{5770385F-C22A-43E0-BF4C-06F5698FFBD9}"}
hitenkoku commented 1 year ago

一旦既存のデータとどのように対応が取れるのかどうかを確認します