フォレンジックツールのSSM Acquireを使ってみた #reinvent

re:Invent2018で紹介されたフォレンジックツールのSSM Acquireのセットアップから動作確認までをやってみます。
2018.11.29

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

こんにちは、岩城です。
私は現地参加ではありませんが、社内チャットの盛り上がりを見て来年は現地参加してみたいと思いました。
時差があるのにいつの時間にもチャットしているので、皆さんちゃんと寝ているのか心配です。

はじめに

臼田さんが参加されたセッションのレポートが以下にまとめられています。
- [レポート]SEC416: AWSのフォレンジックをサーバレスに行う方法 #reinvent
このセッション内で紹介されたフォレンジックツールSSM Acquireについて、セットアップから動作確認までをまとめてみたいと思います。

SSM acquireとは

公式サイト

A python module for orchestrating content acquisitions and analysis via amazon ssm.
Note: This is a pre-release.

  • Free software: MPL 2.0 License
  • Documentation: https://ssm-acquire.readthedocs.io.

Features
- Acquire memory from a linux instance to an S3 bucket using SSM.
- Interrogate an instance for top-10 IOCs using OSQuery and save the jsonified output.
- Analyze a memory sample on a machine using docker.
- Create a rekall profile using an instance as a build target running the Amazon SSM Agent.

Amazon System Manager(以下、SSM)を使用して、分析する情報を取得するPythonモジュールです。2018/11/29時点でプレスリリース版となっています。

機能は大きく4つあります。

  • SSMを使用して、LinuxインスタンスからS3バケットにメモリを取得します。
  • OSQueryを使用してトップ10のIOC(Indicator of Compromise)のインスタンスを調べ、JSON形式で出力し保存します。
  • Dockerを使用してマシン上のメモリサンプルを解析する。
  • SSMエージェントを実行しているビルドターゲットとしてインスタンスを使用してrekallプロファイルを作成します

ssm_acquire --helpのコマンド結果です。

$ ssm_acquire --help
Usage: ssm_acquire [OPTIONS]

  ssm_acquire a rapid evidence preservation tool for Amazon EC2.

Options:
  --instance_id TEXT  The instance you would like to operate on.
  --region TEXT       The aws region where the instance can be found.
  --build             Specify if you would like to build a rekall profile with
                      this capture.
  --acquire           Use linpmem to acquire a memory sample from the system
                      in question.
  --interrogate       Use OSQuery binary to preserve top 10 type queries for
                      rapid forensics.
  --analyze           Use docker and rekall to autoanalyze the memory capture.
  --deploy            Create a lambda function with a handler to take events
                      from AWS GuardDuty.
  --help              Show this message and exit.

やってみた

公式サイトよりは、github上のREADMEをおすすめします。
https://github.com/mozilla/ssm-acquire
書いてあることは同じなのですが、手順内で出てくるcloudformationのテンプレートやconfigがどこに格納されているのか分かりやすいです。

前提

  • SSM Aquireは、Python3系で動作します。今回動作確認環境としてEC2(Amazon Linux2)を利用しますが、起動時はPython2系が利用可能です。このため、Python3系の環境構築が必要になりますが、本ブログでは扱いません。
  • SSM Aquireは、SSMでランコマンドできることが前提のツールです。IAMユーザやインスタンスにはSSMに必須となるロールを割り当てる必要がありますが、本ブログでは扱いません。AWSドキュメントを参照してください。

では、やってきます!

CloudFormationテンプレートを使用してResPonderロールを作成する

こちらからテンプレートを入手してスタックを作成します。
以下のようにIAMロールにSSMAcquireResponderRoleが作成され、ツール実行時に取得した情報を格納するS3バケットが作成されます。後続の手順でロールのARNとバケット名が必要なので控えておいてください。

ツールを実行するユーザのホームディレクトリに設定ファイルを配置する

こちらからsettings.iniを入手して、.threatresponse.iniというファイル名に変更します。ツールを実行するユーザのホームディレクトリに配置します。

$ pwd  
/home/ec2-user
$ ls -la .threatresponse.ini  
-rw-rw-r-- 1 ec2-user ec2-user 206 11月 28 06:20 .threatresponse.ini

ファイル内には3つの必須パラメータを記載します。

[ssm_acquire]
mfa_serial_number=arn:aws:iam::xxxxxxxxxxxx:mfa/ssm-acquire-test
asset_bucket=ssm-acquire-assetbucket-1k5d55ysc5ou4
ssm_acquire_role_arn=arn:aws:iam::xxxxxxxxxxxx:role/SSMAcquireResponderRole

ツールを実行する環境ではMFAデバイスの割り当てが必須です。MFAデバイスのARNを記載します。
私の場合は、ssm-acquire-testユーザです。

SSM Acquireをインストールする

インストールはこれだけです。

$ sudo pip install ssm_acquire
$ which ssm_acquire
/usr/local/bin/ssm_acquire

動作確認

お待たせいたしました。いよいよ動作確認です。
READMEで紹介されているコマンドのうち、以下を実行します。

ssm_acquire --instance_id i-xxxxxxxx --region us-west-2 --build --acquire

実際に実行したコマンド結果がこちらです。インスタンスIDとリージョンの指定は変えてあります。

$ ssm_acquire --instance_id i-0ad93eb9c13ca9665 --region ap-northeast-1 --build --acquire  
INFO:ssm_acquire.cli:Initializing ssm_acquire.
INFO:ssm_acquire.common:Limited scope role generated for assumeRole: {"Version": "2012-10-17", "Statement": [{"Sid": "STMT1", "Effect": "Allow", "Action": ["s3:PutObject", "s3:GetObject", "s3:ListObjects"], "Resource": ["arn:aws:s3:::ssm-acquire-assetbucket-1k5d55ysc5ou4/i-0ad93eb9c13ca9665", "arn:aws:s3:::ssm-acquire-assetbucket-1k5d55ysc5ou4/i-0ad93eb9c13ca9665/*"]}, {"Sid": "STMT2", "Effect": "Allow", "Action": ["ssm:ListDocuments", "ssm:ListDocumentsVersions", "ssm:DescribeDocument", "ssm:GetDocument", "ssm:DescribeInstanceInformation", "ssm:DescribeDocumentParameters", "ssm:DescribeInstanceProperties", "ssm:GetCommandInvocation"], "Resource": "*"}, {"Sid": "STMT3", "Effect": "Allow", "Action": ["ssm:SendCommand", "ec2:DescribeInstanceStatus"], "Resource": ["arn:aws:ssm:*:*:document/*", "arn:aws:ec2:*:*:instance/i-0ad93eb9c13ca9665"]}, {"Sid": "STMT4", "Effect": "Allow", "Action": ["s3:ListBucket"], "Resource": ["arn:aws:s3:::ssm-acquire-assetbucket-1k5d55ysc5ou4", "arn:aws:s3:::ssm-acquire-assetbucket-1k5d55ysc5ou4/*"]}]}
INFO:botocore.credentials:Found credentials in shared credentials file: ~/.aws/credentials
INFO:ssm_acquire.credential:Assuming the response role using mfa. role: arn:aws:iam::xxxxxxxxxxxx:role/SSMAcquireResponderRole, mfa: arn:aws:iam::xxxxxxxxxxxx:mfa/ssm-acquire-test
Please enter your MFA Token: xxxxxx
INFO:ssm_acquire.cli:Memory dump in progress for instance: i-0ad93eb9c13ca9665.  Please wait.
\INFO:ssm_acquire.cli:The task completed with status: Success
INFO:ssm_acquire.cli:Proceeding to copy off the data to the asset store.
INFO:ssm_acquire.cli:Copying the asset to s3 bucket for preservation.
/INFO:ssm_acquire.cli:Transfer sequence complete.
INFO:ssm_acquire.cli:Attempting to build a rekall profile for instance: i-0ad93eb9c13ca9665.
INFO:ssm_acquire.cli:An attempt to build a rekall profile has begun.  Please wait.
\INFO:ssm_acquire.cli:Rekall profile build complete. A .zip has been added to the asset store for instance: i-0ad93eb9c13ca9665
INFO:ssm_acquire.cli:ssm_acquire has completed successfully.

実行すると.threatresponse.iniで記載したS3バケットに取得した情報がアップロードされます。

Kernel ConfigurationやSystem.mapやaff4ファイルが取得されました。

さいごに

先日、AWS IRのやってみたブログを書いていたので、ほんの少しだけフォレンジックツールに馴染みがあり、早速触ってみました。 このブログが誰かの役に立てれば幸いです。