LoginSignup
4
7

More than 3 years have passed since last update.

BlueTeamを勉強したいんじゃ!~Covenantハンティング編~

Last updated at Posted at 2020-11-20

第三弾:BlueTeamを勉強したいんじゃ!シリーズ

前回の記事でLABを作りました。今回はCovenantを使ってWin10に侵入してコマンドを実行するまでを行い、SecurityOnionでどの様にしてハンティングさせるかまでをやっていきます。

注意事項

  • 自分環境以外には絶対に攻撃しないでください(本記事はハンティングが目的なので・・・)

全体の流れ(ざっくりレベル)

  1. マリシャスなWordを作成
  2. powershell起動&C2に接続
  3. SecurityOnionでハンティング

見つけたいもの

親プロセスがWordで子プロセスがpowershellの怪しい挙動をしているものをハンティングしたいと思います。
Blueteam.png

Covenant

Covenantは.NETで作成されたコマンドアンドコントロールフレームワークです。
Covenantのインストール方法はここを参考にしてください。

1. Listenertsの作成

  • 「Listeners」 > 「Create」 を押下
    スクリーンショット 2020-10-21 223506.png

  • 「ConnectPort」および「ConnectAddress」を設定する
    スクリーンショット 2020-10-21 223614.png

2. PowerShell Launchersの作成

  • 「Launchers」 > 「PowerShell」を押下
    スクリーンショット 2020-10-21 223731.png

  • デフォルト設定のまま「Generate」を押下
    スクリーンショット 2020-10-21 223813.png

  • URLにファイル名を入力して「host」を押下
    スクリーンショット 2020-10-21 224158.png

- エンコードされたPowershellのコマンドをコピーします。

3. Wordに挿入

  • Wordの開発者ボックにチェックをいれて開発者タブを表示させます。
    スクリーンショット 2020-10-21 224420.png

  • 「開発者」タブの「VisualBasic」を選択します。

  • VisualBasicエディターに以下のコマンドを記述します。

Sub AutoOpen()    
        Call Shell("エンコードされたPowershellのコマンド")
End Sub
  • 保存します。

4. コマンド実行

  • マクロ入りWordをやられWindowsに送り実行します。 スクリーンショット 2020-10-21 225411.png

SecurityOnionでハンティング

1. NIDSでの検知

Suricata

ET OPENルールではCovenant Frameworkの検知ルールがあり、以下の4つがアラートとして検知します。

  • ET MALWARE Covenant Framework Default HTTP Beacon
  • ET MALWARE Covenant Framework HTTP Beacon
  • ET MALWARE Covenant Framework HTTP Hello World Server Response
  • ET MALWARE Possible Covenant Framework Grunt PowerShell Stager HTTP Download

2. SIEMでの検知

SIEMの検知ルールを自分で作成するのはとても大変です。
今回は検知ルール作成にSigmaというものを使い検知させていきます。

Sigma

SigmaとはSIEMのYARAみたいなものになります。
Sigmaのルールを作成して使用することで、さまざまなターゲット(SIEMなど)に対して共有して実行できる汎用的なルールを持つことができます。
詳細はgithubを参照してください。
ルールは下記のように記述していきます。
チュートリアルはここにあるので詳しく知りたい人は参照してください。

title:タイトルは検出ルール
id [optional]:一意の識別子
description [optional]:ルールと悪意のあるアクティビティについて説明します。
author [optional]:ルールの作成者
references [optional]:ルールを導出するための情報源を提供先など
logsource:ログソース
   category [optional]:この属性を使用すると、製品のグループに属するすべてのログファイルを選択できます。
   product [optional]:すべてのルールに一致する製品
   ...
detection:ログデータの特定のフィールドの検索値が選択範囲に一覧表示されます。
   {search-identifier} [optional]
      {string-list} [optional]
      {field: value} [optional]
   etc・・・

Detection属性について

  • リストとマップという2つの異なるデータ構造から定義します。
  • リスト
    • リストには、完全なログメッセージに適用される文字列が含まれており、論理的な「OR」でリンクされています。
    • 例「EvilService」OR「svchost.exe -n evil」を検出するルール
detection:
  keywords:
    - EVILSERVICE
    - svchost.exe -n evil
  • マップ
    • マップ(または辞書)は、キーと値のペアで構成され、キーはログデータのフィールドで、値は文字列または整数値です。マップのリストは、論理的な 'OR' で結合されます。マップのすべての要素は、論理的な「AND」で結合されます。
    • 例イベントログ「セキュリティ」AND ( イベントID 517 またはイベントID 1102 ) を検出するルール
detection:
  selection:
    - EventLog: Security
      EventID:
        - 517
        - 1102
condition: selection

イメージ

Sigmaルールをコンバーターで各SIEMの検知ルール又は検索クエリに変更して分析する。
プレゼンテーション1.jpg

サポートされているSIEM

  • Splunk (plainqueries and dashboards)
  • ElasticSearch Query Strings
  • ElasticSearch Query DSL
  • Kibana
  • Elastic X-Pack Watcher
  • Logpoint
  • Microsoft Defender Advanced Threat Protection (MDATP)
  • Azure Sentinel / Azure Log Analytics
  • Sumologic
  • ArcSight
  • QRadar
  • Qualys
  • RSA NetWitness
  • PowerShell
  • Grep with Perl-compatible regular expression support
  • LimaCharlie
  • ee-outliers
  • Structured Threat Information Expression (STIX)

Playbook

今回使用するルールは親プロセスがOffice系のアプリケーション且つ、子プロセスがシェル、スクリプトインタープリターなどを検知するのSigmaルールです。

title: Microsoft Office Product Spawning Windows Shell
id: 438025f9-5856-4663-83f7-52f878a70a50
status: experimental
description: Detects a Windows command line executable started from Microsoft Word, Excel, Powerpoint, Publisher and Visio.
references:
    - https://www.hybrid-analysis.com/sample/465aabe132ccb949e75b8ab9c5bda36d80cf2fd503d52b8bad54e295f28bbc21?environmentId=100
    - https://mgreen27.github.io/posts/2018/04/02/DownloadCradle.html
tags:
    - attack.execution
    - attack.defense_evasion
    - attack.t1059
    - attack.t1202
    - car.2013-02-003
    - car.2014-04-003
author: Michael Haag, Florian Roth, Markus Neis
date: 2018/04/06
logsource:
    category: process_creation
    product: windows
detection:
    selection:
        ParentImage:
            - '*\WINWORD.EXE'
            - '*\EXCEL.EXE'
            - '*\POWERPNT.exe'
            - '*\MSPUB.exe'
            - '*\VISIO.exe'
            - '*\OUTLOOK.EXE'
        Image:
            - '*\cmd.exe'
            - '*\powershell.exe'
            - '*\wscript.exe'
            - '*\cscript.exe'
            - '*\sh.exe'
            - '*\bash.exe'
            - '*\scrcons.exe'
            - '*\schtasks.exe'
            - '*\regsvr32.exe'
            - '*\hh.exe'
            - '*\wmic.exe' # https://app.any.run/tasks/c903e9c8-0350-440c-8688-3881b556b8e0/
            - '*\mshta.exe'
            - '*\rundll32.exe'
            - '*\msiexec.exe'
            - '*\forfiles.exe'
            - '*\scriptrunner.exe'
            - '*\mftrace.exe'
            - '*\AppVLP.exe'
            - '*\svchost.exe' # https://www.vmray.com/analyses/2d2fa29185ad/report/overview.html
    condition: selection
fields:
    - CommandLine
    - ParentCommandLine
falsepositives:
    - unknown
level: high

このSIGMAルールをコンバーターにかけてElasticsearchの検索クエリに変換したいと思います。
コンバーターはPlaybook又はSocprime(検知ルールなどマーケットプレイスや検出ルールを作成して、報奨金がもらえたりするプラットフォーム)のuncoder.ioで変換可能です。

Sigma Editor
Screenshot from 2020-11-19 23-02-44.png

PlaybookのSigma Editorで変換したクエリがしたになります。

(event.code.security:"1" AND winlog.channel.security:"Microsoft\-Windows\-Sysmon\/Operational" AND process.parent.executable.security:("*\\WINWORD.EXE" OR "*\\EXCEL.EXE" OR "*\\POWERPNT.exe" OR "*\\MSPUB.exe" OR "*\\VISIO.exe" OR "*\\OUTLOOK.EXE") AND process.executable.security:("*\\cmd.exe" OR "*\\powershell.exe" OR "*\\wscript.exe" OR "*\\cscript.exe" OR "*\\sh.exe" OR "*\\bash.exe" OR "*\\scrcons.exe" OR "*\\schtasks.exe" OR "*\\regsvr32.exe" OR "*\\hh.exe" OR "*\\wmic.exe" OR "*\\mshta.exe" OR "*\\rundll32.exe" OR "*\\msiexec.exe" OR "*\\forfiles.exe" OR "*\\scriptrunner.exe" OR "*\\mftrace.exe" OR "*\\AppVLP.exe" OR "*\\svchost.exe"))

このままでは上手く検索できないので修正します。
修正ポイントは下記の2点になります。
1. process.parent.executable.security ⇒ process.parent.executable
2. process.executable.security ⇒ process.executable
Elasticsearchのドキュメントの項目には〜.securityはないので(おそらくバグ?)手動で修正します。
修正したクエリをkibanaで検索すると以下のように検出することができます。
フィニッシュ!(マリパ風)

(event.code:"1" AND winlog.channel:"Microsoft\-Windows\-Sysmon\/Operational" AND process.parent.executable:("*\\WINWORD.EXE" OR "*\\EXCEL.EXE" OR "*\\POWERPNT.exe" OR "*\\MSPUB.exe" OR "*\\VISIO.exe" OR "*\\OUTLOOK.EXE") AND process.executable.:("*\\cmd.exe" OR "*\\powershell.exe" OR "*\\wscript.exe" OR "*\\cscript.exe" OR "*\\sh.exe" OR "*\\bash.exe" OR "*\\scrcons.exe" OR "*\\schtasks.exe" OR "*\\regsvr32.exe" OR "*\\hh.exe" OR "*\\wmic.exe" OR "*\\mshta.exe" OR "*\\rundll32.exe" OR "*\\msiexec.exe" OR "*\\forfiles.exe" OR "*\\scriptrunner.exe" OR "*\\mftrace.exe" OR "*\\AppVLP.exe" OR "*\\svchost.exe"))

Screenshot from 2020-11-19 23-10-14.png

参考サイト

次回

BlueTeamを勉強したいんじゃ!~osqueryでマルウェアハンティング編~

4
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
7