hacktricks/forensics/basic-forensic-methodology/malware-analysis.md
2023-07-07 23:42:27 +00:00

16 KiB
Raw Blame History

マルウェア解析

☁️ HackTricks Cloud ☁️ -🐦 Twitter 🐦 - 🎙️ Twitch 🎙️ - 🎥 Youtube 🎥

フォレンジックチートシート

https://www.jaiminton.com/cheatsheet/DFIR/#

オンラインサービス

オフラインのウイルス対策および検出ツール

Yara

インストール

sudo apt-get install -y yara

ルールの準備

このスクリプトを使用して、GitHubからすべてのYARAマルウェアルールをダウンロードしてマージしますhttps://gist.github.com/andreafortuna/29c6ea48adf3d45a979a78763cdc7ce9
rules ディレクトリを作成し、それを実行します。これにより、malware_rules.yar という名前のファイルが作成され、すべてのマルウェアのYARAルールが含まれます。

wget https://gist.githubusercontent.com/andreafortuna/29c6ea48adf3d45a979a78763cdc7ce9/raw/4ec711d37f1b428b63bed1f786b26a0654aa2f31/malware_yara_rules.py
mkdir rules
python malware_yara_rules.py

スキャン

Scanning is the first step in the malware analysis process. It involves examining the suspicious file or program to gather information about its behavior and characteristics. The purpose of scanning is to identify any potential threats and determine the appropriate analysis techniques to use.

There are several scanning techniques that can be used in malware analysis:

  1. Static Analysis: This technique involves examining the file without executing it. It includes analyzing the file's structure, metadata, and code to identify any suspicious or malicious elements.

  2. Dynamic Analysis: In this technique, the file is executed in a controlled environment, such as a virtual machine or sandbox. The behavior of the file is monitored to identify any malicious activities, such as network connections, file modifications, or system changes.

  3. Signature-based Analysis: This technique involves comparing the file's signature or hash value against a database of known malware signatures. If a match is found, it indicates that the file is malicious.

  4. Heuristic Analysis: Heuristic analysis involves using predefined rules or patterns to identify potentially malicious behavior. This technique is useful for detecting new or unknown malware.

  5. Behavioral Analysis: Behavioral analysis focuses on monitoring the file's behavior during execution. It involves capturing system events, such as API calls, registry modifications, and network traffic, to identify any suspicious activities.

  6. Code Analysis: Code analysis involves examining the file's code to identify any vulnerabilities or malicious functions. This technique requires expertise in programming languages and reverse engineering.

By using a combination of these scanning techniques, analysts can gather valuable information about the malware and determine the appropriate course of action for further analysis.

yara -w malware_rules.yar image  #Scan 1 file
yara -w malware_rules.yar folder #Scan the whole folder

YaraGen: マルウェアのチェックとルールの作成

バイナリからyaraルールを生成するために、ツールYaraGenを使用することができます。以下のチュートリアルを参照してください: Part 1, Part 2, Part 3

python3 yarGen.py --update
python3.exe yarGen.py --excludegood -m  ../../mals/

ClamAV

インストール

ClamAVはオープンソースのアンチウイルスエンジンであり、マルウェアの検出と駆除に使用されます。以下の手順に従ってClamAVをインストールします。

  1. ターミナルを開きます。

  2. 次のコマンドを実行して、ClamAVをインストールします。

    sudo apt-get install clamav
    
  3. インストールが完了したら、データベースを更新します。

    sudo freshclam
    
  4. ClamAVが正しくインストールされたかどうかを確認するために、次のコマンドを実行します。

    clamscan --version
    

    インストールされたClamAVのバージョンが表示されれば、インストールは成功しています。

ClamAVはインストールされ、使用準備が整いました。次に、ClamAVを使用してマルウェアのスキャンを実行する方法について学びましょう。

sudo apt-get install -y clamav

スキャン

Scanning is the first step in the malware analysis process. It involves examining the suspicious file or program to gather information about its behavior and characteristics. The purpose of scanning is to identify any potential threats and determine the appropriate analysis techniques to use.

There are several scanning techniques that can be used in malware analysis:

  1. Static Analysis: This technique involves examining the file without executing it. It includes analyzing the file's structure, metadata, and code to identify any suspicious or malicious elements.

  2. Dynamic Analysis: In this technique, the file is executed in a controlled environment, such as a virtual machine or sandbox. The behavior of the file is monitored to identify any malicious activities, such as network connections, file modifications, or system changes.

  3. Signature-based Analysis: This technique involves comparing the file's signature or hash value against a database of known malware signatures. If a match is found, it indicates that the file is malicious.

  4. Heuristic Analysis: Heuristic analysis involves using predefined rules or patterns to identify potentially malicious behavior. This technique is useful for detecting new or unknown malware.

  5. Behavioral Analysis: Behavioral analysis focuses on monitoring the file's behavior during execution. It involves capturing system events, such as API calls, registry modifications, and network traffic, to identify any suspicious activities.

  6. Code Analysis: Code analysis involves examining the file's code to identify any vulnerabilities or malicious functions. This technique requires expertise in programming languages and reverse engineering.

By using a combination of these scanning techniques, analysts can gather valuable information about the malware and determine the appropriate analysis approach.

sudo freshclam      #Update rules
clamscan filepath   #Scan 1 file
clamscan folderpath #Scan the whole folder

Capa

Capaは、実行可能ファイルPE、ELF、.NETで潜在的に悪意のある機能を検出します。Att&ckの戦術や、以下のような疑わしい機能を見つけることができます。

  • OutputDebugStringエラーのチェック
  • サービスとして実行
  • プロセスの作成

Githubリポジトリから入手できます。

IOCIndicator Of Compromise

IOCはCompromiseの指標です。IOCは、潜在的に望ましくないソフトウェアまたは確認されたマルウェアを識別するための条件のセットです。Blue Teamは、これらの定義を使用して、自分たちのシステムやネットワークでこのような悪意のあるファイルを検索します。
これらの定義を共有することは非常に役立ちます。なぜなら、コンピュータでマルウェアが特定され、そのマルウェアのIOCが作成された場合、他のBlue Teamはそれを使用してマルウェアをより速く識別できるからです。

IOCを作成または変更するためのツールは、IOC Editorです。
Redlineなどのツールを使用して、デバイスで定義されたIOCを検索することができます。

Loki

Lokiは、シンプルなCompromiseの指標に基づいてスキャンを行うツールです。
検出は、以下の4つの検出方法に基づいています

1. File Name IOC
Regex match on full file path/name

2. Yara Rule Check
Yara signature matches on file data and process memory

3. Hash Check
Compares known malicious hashes (MD5, SHA1, SHA256) with scanned files

4. C2 Back Connect Check
Compares process connection endpoints with C2 IOCs (new since version v.10)

Linux Malware Detect

Linux Malware Detect (LMD)は、GNU GPLv2ライセンスの下でリリースされたLinux用のマルウェアスキャナです。共有ホスト環境で直面する脅威に基づいて設計されています。LMDは、ネットワークエッジ侵入検知システムからの脅威データを使用して、攻撃で実際に使用されているマルウェアを抽出し、検出のためのシグネチャを生成します。さらに、LMDのチェックアウト機能とマルウェアコミュニティのリソースからも脅威データが派生します。

rkhunter

rkhunterのようなツールは、ファイルシステムをチェックして可能なルートキットとマルウェアを検出するために使用できます。

sudo ./rkhunter --check -r / -l /tmp/rkhunter.log [--report-warnings-only] [--skip-keypress]

FLOSS

FLOSSは、さまざまな技術を使用して実行可能ファイル内の難読化された文字列を検出しようとするツールです。

PEpper

PEpperは、実行可能ファイル内の基本的な情報バイナリデータ、エントロピー、URLとIP、一部のyaraルールをチェックします。

PEstudio

PEstudioは、Windows実行可能ファイルのインポート、エクスポート、ヘッダーなどの情報を取得するだけでなく、ウイルストータルをチェックし、潜在的なAtt&ck技術を見つけることもできるツールです。

Detect It Easy(DiE)

DiEは、ファイルが暗号化されているかどうかを検出し、パッカーを見つけるためのツールです。

NeoPI

NeoPIは、Pythonスクリプトであり、テキスト/スクリプトファイル内の難読化および暗号化されたコンテンツを検出するためにさまざまな統計的手法を使用します。 NeoPIの目的は、隠されたウェブシェルコードの検出を支援することです。

php-malware-finder

php-malware-finderは、難読化/不正なコードを検出するために最善を尽くし、マルウェア/ウェブシェルでよく使用されるPHP関数を使用しているファイルを検出します。

Apple Binary Signatures

マルウェアサンプルをチェックする際には、常にバイナリの署名をチェックする必要があります。署名を行った開発者が既にマルウェアと関連している可能性があるためです。

#Get signer
codesign -vv -d /bin/ls 2>&1 | grep -E "Authority|TeamIdentifier"

#Check if the apps contents have been modified
codesign --verify --verbose /Applications/Safari.app

#Check if the signature is valid
spctl --assess --verbose /Applications/Safari.app

検出技術

ファイルのスタッキング

もし、ウェブサーバーのファイルある日に最後に更新されたことを知っている場合、ウェブサーバーのすべてのファイル作成日と変更日をチェックし、どのファイルが怪しいかを確認します。

ベースライン

あるフォルダのファイルが変更されていないはずの場合、そのフォルダの元のファイルハッシュを計算し、現在のファイルと比較します。変更されたものは怪しいです。

統計分析

情報がログに保存されている場合、ウェブサーバーの各ファイルがアクセスされた回数などの統計情報をチェックすることができます。ウェブシェルがその中の1つである可能性があります。

☁️ HackTricks Cloud ☁️ -🐦 Twitter 🐦 - 🎙️ Twitch 🎙️ - 🎥 Youtube 🎥