Amazon InspectorのエージェントをRun Commandでインストールできるようになりました。

2017.10.16

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

中山(順)です。

EC2 Systems ManagerのRun Commandを利用して、EC2インスタンスに対してAmazon Inspectorのエージェントをインストールできるようになりました。

Amazon Inspector agents can now be installed via Run Command, and Amazon Inspector now supports Amazon Linux 2017.09

(同時に、先日提供が開始されたAmazon Linux 2017.09がAmazon Inspectorでサポートされました。 )

このアップデートで、「AmazonInspector-ManageAWSAgent」というドキュメントが新たに追加されています。

f9d7dde8d07bf034de8e3192f7ca0dd8

この記事では、AWS CLIを使ってRun CommandによるInspectorエージェントのインストールからAmazon Inspectorによる評価結果を確認するまでの手順をご紹介します。 今回はWindows Server 2012 R2で試してみます。 評価が完了するまで、RDPによる接続は行いません。

Amazon Inspectorとは?

Amazon Inspectorとは、EC2インスタンスにエージェントを導入し、プラットフォームの脆弱性を診断する、ホスト型診断サービスです。

詳細については、弊社ブログおよびAWSクラウドサービス活用資料集などをご覧ください。

Inspector – 特集カテゴリー –

AWS Black Belt Online Seminar Amazon Inspector

EC2 Systems Manager / Run Commandとは?

EC2 Systems Managerとは、Amazon EC2またはオンプレミスで実行されるWindows/Linuxに対してシステムの自動構成と継続的な管理を可能にする一連の機能です。 Run CommandはEC2 Systems Managerに含まれる機能の一つで、EC2 Systems Managerの管理下にあるシステムに対してリモートから任意のコマンドを実行することが可能となる機能です。

詳細については、弊社ブログおよびAWSクラウドサービス活用資料集などをご覧ください。

EC2 Systems Manager – 特集カテゴリー –

AWS Black Belt Online Seminar 2017 Amazon EC2 Systems Manager

前提条件

以下のEC2インスタンスに対して作業を実施します。

  • "Microsoft Windows Server 2012 R2 Base"のAMIからインスタンスを作成
  • SSM Agent(EC2config)はプリインストール
  • Amazon Inspectorで評価ターゲットを定義するためにタグを設定
  • Key:Name, Value:Inspector
  • インスタンスプロファイル(IAM Role)にはRun CommandおよびAmazon Inspectorによる評価を実行できるポリシーをアタッチ

また、Amazon Inspectorの動作確認は以下の条件で実施しました。

  • Amazon Inspectorのためのサービスロールを作成済み
  • 評価ターゲットを定義済み
  • 以下のタグが設定されたEC2インスタンスが評価対象となるように定義
  • Key:Name, Value:Inspector
  • 評価テンプレートを定義済み
  • 作成した評価ターゲットを指定
  • ルールパッケージに「Common Vulnerabilities and Exposures-1.1」および「CIS Operating System Security Configuration Benchmarks-1.0」を指定

インストール

事前確認

ドキュメントの詳細を確認します。

$ aws ssm describe-document \
--name AmazonInspector-ManageAWSAgent
{
"Document": {
"Status": "Active",
"Hash": "3c6916ac59e7f3e4af11fa1154ea0b036f7e4340158826a42004106942ab76ef",
"Name": "AmazonInspector-ManageAWSAgent",
"Parameters": [
{
"Type": "String",
"Name": "Operation",
"Description": "(Required) The AWS Agent related action to perform. The install operation installs the AWS Agent on the System"
}
],
"Tags": [],
"DocumentType": "Command",
"PlatformTypes": [
"Windows",
"Linux"
],
"DocumentVersion": "1",
"HashType": "Sha256",
"CreatedDate": 1507574293.778,
"Owner": "Amazon",
"SchemaVersion": "2.2",
"DefaultVersion": "1",
"LatestVersion": "1",
"Description": "Manage AWS Agent on EC2 instances"
}
}

インストール先のインスタンスがマネージドインスタンスとして認識されていることを確認します。

$ aws ssm describe-instance-information
{
"InstanceInformationList": [
{
"IsLatestVersion": false,
"ComputerName": "WIN-JA86MKP7TE3.WORKGROUP",
"PingStatus": "Online",
"InstanceId": "i-001c7d5488de02427",
"IPAddress": "172.31.25.181",
"ResourceType": "EC2Instance",
"AgentVersion": "2.0.952.0",
"PlatformVersion": "6.3.9600",
"PlatformName": "Microsoft Windows Server 2012 R2 Standard",
"PlatformType": "Windows",
"LastPingDateTime": 1507889003.426
}
]
}

インストール

コマンドを送信し、エージェントのインストールを開始します。

$ aws ssm send-command \
--instance-ids i-001c7d5488de02427 \
--document-name AmazonInspector-ManageAWSAgent \
--parameters '{"Operation":["Install"]}'
{
"Command": {
"Comment": "",
"Status": "Pending",
"MaxErrors": "0",
"Parameters": {
"Operation": [
"Install"
]
},
"ExpiresAfter": 1507896426.398,
"ServiceRole": "",
"DocumentName": "AmazonInspector-ManageAWSAgent",
"TargetCount": 1,
"OutputS3BucketName": "",
"NotificationConfig": {
"NotificationArn": "",
"NotificationEvents": [],
"NotificationType": ""
},
"CompletedCount": 0,
"Targets": [],
"StatusDetails": "Pending",
"ErrorCount": 0,
"OutputS3KeyPrefix": "",
"RequestedDateTime": 1507889226.398,
"CommandId": "d7e1002e-2dbd-4f4d-a79c-fee95c7c3581",
"InstanceIds": [
"i-001c7d5488de02427"
],
"MaxConcurrency": "50"
}
}

コマンドの実行が成功したことを確認します。 対象のOSによって、プラグイン名を適宜指定してください。

$ aws ssm get-command-invocation \
--command-id "d7e1002e-2dbd-4f4d-a79c-fee95c7c3581" \
--instance-id "i-001c7d5488de02427" \
--plugin-name InstallInspectorOnWindows
{
"Comment": "",
"ExecutionElapsedTime": "PT30.124S",
"ExecutionEndDateTime": "2017-10-13T10:07:37.272Z",
"StandardErrorContent": "",
"InstanceId": "i-001c7d5488de02427",
"StandardErrorUrl": "",
"DocumentName": "AmazonInspector-ManageAWSAgent",
"StandardOutputContent": "Thumbprint: + 8880F2076855F15A17FEEC95651599F3460EDB8B\nSignature validated : 8880F2076855F15A17FEEC95651599F3460EDB8B\nInstallation succeeded\n",
"Status": "Success",
"StatusDetails": "Success",
"PluginName": "InstallInspectorOnWindows",
"ResponseCode": 0,
"ExecutionStartDateTime": "2017-10-13T10:07:07.272Z",
"CommandId": "d7e1002e-2dbd-4f4d-a79c-fee95c7c3581",
"StandardOutputUrl": ""
}

これでインストールは完了です。

動作確認

ついでに評価ができることも確認してみましょう。

評価ターゲット

評価ターゲットの一覧からARNを確認します。

$ aws inspector list-assessment-targets
{
"assessmentTargetArns": [
"arn:aws:inspector:ap-northeast-1:XXXXXXXXXXXX:target/0-A6hw1U3n"
]
}

評価ターゲットのARNから名前などの詳細を確認します。

$ aws inspector describe-assessment-targets \
--assessment-target-arns "arn:aws:inspector:ap-northeast-1:XXXXXXXXXXXX:target/0-A6hw1U3n"
{
"assessmentTargets": [
{
"resourceGroupArn": "arn:aws:inspector:ap-northeast-1:XXXXXXXXXXXX:resourcegroup/0-BHQtnR2W",
"createdAt": 1507868628.947,
"name": "test-target",
"arn": "arn:aws:inspector:ap-northeast-1:XXXXXXXXXXXX:target/0-A6hw1U3n",
"updatedAt": 1507868628.947
}
],
"failedItems": {}
}

評価ターゲットにEC2インスタンスが含まれているか確認します。

$ aws inspector preview-agents \
--preview-agents-arn "arn:aws:inspector:ap-northeast-1:XXXXXXXXXXXX:target/0-A6hw1U3n"
{
"agentPreviews": [
{
"agentId": "i-001c7d5488de02427"
}
]
}

評価テンプレート

定義済みの評価テンプレートを確認します。

まずは、評価テンプレートの一覧を確認します。

$ aws inspector list-assessment-templates
{
"assessmentTemplateArns": [
"arn:aws:inspector:ap-northeast-1:XXXXXXXXXXXX:target/0-A6hw1U3n/template/0-4oWqng8L"
]
}

評価テンプレートの詳細を確認します。 評価時間や評価するルールパッケージが確認できます。

$ aws inspector describe-assessment-templates \
--assessment-template-arns "arn:aws:inspector:ap-northeast-1:XXXXXXXXXXXX:target/0-A6hw1U3n/template/0-4oWqng8L"
{
"assessmentTemplates": [
{
"assessmentTargetArn": "arn:aws:inspector:ap-northeast-1:XXXXXXXXXXXX:target/0-A6hw1U3n",
"name": "test-template",
"createdAt": 1507876994.69,
"durationInSeconds": 900,
"rulesPackageArns": [
"arn:aws:inspector:ap-northeast-1:406045910587:rulespackage/0-7WNjqgGu",
"arn:aws:inspector:ap-northeast-1:406045910587:rulespackage/0-gHP9oWNT"
],
"userAttributesForFindings": [],
"arn": "arn:aws:inspector:ap-northeast-1:XXXXXXXXXXXX:target/0-A6hw1U3n/template/0-4oWqng8L"
}
],
"failedItems": {}
}

評価の実行

評価を実行します。 評価が完了するまでしばらくお待ちください。

$ aws inspector start-assessment-run \
--assessment-template-arn "arn:aws:inspector:ap-northeast-1:XXXXXXXXXXXX:target/0-A6hw1U3n/template/0-4oWqng8L"
{
"assessmentRunArn": "arn:aws:inspector:ap-northeast-1:XXXXXXXXXXXX:target/0-A6hw1U3n/template/0-4oWqng8L/run/0-ZYzzvWoW"
}

評価結果の確認

評価結果の一覧から評価結果のARNを確認します。

$ aws inspector list-assessment-runs
{
"assessmentRunArns": [
"arn:aws:inspector:ap-northeast-1:XXXXXXXXXXXX:target/0-A6hw1U3n/template/0-4oWqng8L/run/0-ZYzzvWoW"
]
}

評価結果の詳細を確認します。 この例では、227件の指摘事項がありました。

$ aws inspector describe-assessment-runs \
--assessment-run-arns "arn:aws:inspector:ap-northeast-1:XXXXXXXXXXXX:target/0-A6hw1U3n/template/0-4oWqng8L/run/0-ZYzzvWoW"
{
"failedItems": {},
"assessmentRuns": [
{
"dataCollected": true,
"name": "test-template/2017-10-13T10:08/5bas",
"completedAt": 1507890399.793,
"userAttributesForFindings": [],
"stateChanges": [
{
"state": "CREATED",
"stateChangedAt": 1507889319.805
},
{
"state": "START_DATA_COLLECTION_PENDING",
"stateChangedAt": 1507889319.879
},
{
"state": "START_DATA_COLLECTION_IN_PROGRESS",
"stateChangedAt": 1507889319.884
},
{
"state": "COLLECTING_DATA",
"stateChangedAt": 1507889319.936
},
{
"state": "STOP_DATA_COLLECTION_PENDING",
"stateChangedAt": 1507890224.439
},
{
"state": "DATA_COLLECTED",
"stateChangedAt": 1507890293.035
},
{
"state": "START_EVALUATING_RULES_PENDING",
"stateChangedAt": 1507890293.277
},
{
"state": "EVALUATING_RULES",
"stateChangedAt": 1507890293.943
},
{
"state": "COMPLETED",
"stateChangedAt": 1507890399.793
}
],
"createdAt": 1507889319.805,
"findingCounts": {
"High": 227,
"Medium": 0,
"Informational": 0,
"Low": 0
},
"notifications": [],
"state": "COMPLETED",
"stateChangedAt": 1507890399.793,
"durationInSeconds": 900,
"rulesPackageArns": [
"arn:aws:inspector:ap-northeast-1:406045910587:rulespackage/0-7WNjqgGu",
"arn:aws:inspector:ap-northeast-1:406045910587:rulespackage/0-gHP9oWNT"
],
"startedAt": 1507889319.936,
"assessmentTemplateArn": "arn:aws:inspector:ap-northeast-1:XXXXXXXXXXXX:target/0-A6hw1U3n/template/0-4oWqng8L",
"arn": "arn:aws:inspector:ap-northeast-1:XXXXXXXXXXXX:target/0-A6hw1U3n/template/0-4oWqng8L/run/0-ZYzzvWoW"
}
]
}

具体的にどのような指摘事項が検出されたのかを確認します。

まずは、一覧を確認します。

$ aws inspector list-findings \
--assessment-run-arns "arn:aws:inspector:ap-northeast-1:XXXXXXXXXXXX:target/0-A6hw1U3n/template/0-4oWqng8L/run/0-ZYzzvWoW"
{
"nextToken": "AAIAAWMoc27n0mzAlxEjwdqdjI2NJfJZpCZ6NWmN-0GnTexEDFfQaGANRbj3NVddLtzFfmWqbRRk-Q1qlPUdYD9jE3uTVwWt1BCiB_FvJeFoQqXduU3V5H1TF5fwJRK2nDW8zKQGnwdhBplSQTdmNXkeSqG6lufSMrr9jhWNfI1gxzOaOD2ty0rZiLB6cjwcnYRfx96l7tk6XxwOMQV8wVdi6o_SvhpuB5GfG9J5y4y0UotzDjf7z0wPCqTpjRN9rjQ7vxMnA0XDQj5SXWWC0e1N753089D0Mw==",
"findingArns": [
"arn:aws:inspector:ap-northeast-1:XXXXXXXXXXXX:target/0-A6hw1U3n/template/0-4oWqng8L/run/0-ZYzzvWoW/finding/0-BR3WlR1c",
"arn:aws:inspector:ap-northeast-1:XXXXXXXXXXXX:target/0-A6hw1U3n/template/0-4oWqng8L/run/0-ZYzzvWoW/finding/0-IPAJmSsJ",
"arn:aws:inspector:ap-northeast-1:XXXXXXXXXXXX:target/0-A6hw1U3n/template/0-4oWqng8L/run/0-ZYzzvWoW/finding/0-ItG2Oo3y",
"arn:aws:inspector:ap-northeast-1:XXXXXXXXXXXX:target/0-A6hw1U3n/template/0-4oWqng8L/run/0-ZYzzvWoW/finding/0-KEtiq9U7",
"arn:aws:inspector:ap-northeast-1:XXXXXXXXXXXX:target/0-A6hw1U3n/template/0-4oWqng8L/run/0-ZYzzvWoW/finding/0-OQrI7hcV",
"arn:aws:inspector:ap-northeast-1:XXXXXXXXXXXX:target/0-A6hw1U3n/template/0-4oWqng8L/run/0-ZYzzvWoW/finding/0-S5ZjUZXs",
"arn:aws:inspector:ap-northeast-1:XXXXXXXXXXXX:target/0-A6hw1U3n/template/0-4oWqng8L/run/0-ZYzzvWoW/finding/0-Ymia1Lcu",
"arn:aws:inspector:ap-northeast-1:XXXXXXXXXXXX:target/0-A6hw1U3n/template/0-4oWqng8L/run/0-ZYzzvWoW/finding/0-bZfU8EjQ",
"arn:aws:inspector:ap-northeast-1:XXXXXXXXXXXX:target/0-A6hw1U3n/template/0-4oWqng8L/run/0-ZYzzvWoW/finding/0-dUld3kVA",
"arn:aws:inspector:ap-northeast-1:XXXXXXXXXXXX:target/0-A6hw1U3n/template/0-4oWqng8L/run/0-ZYzzvWoW/finding/0-gXfnTIxK"
]
}

指摘事項のうち、1つだけ詳細を表示してみます。

$ aws inspector describe-findings \
--finding-arns "arn:aws:inspector:ap-northeast-1:XXXXXXXXXXXX:target/0-A6hw1U3n/template/0-4oWqng8L/run/0-ZYzzvWoW/finding/0-BR3WlR1c"
{
"failedItems": {},
"findings": [
{
"assetType": "ec2-instance",
"confidence": 10,
"numericSeverity": 9.0,
"description": "Description\n\n \nThis setting configures the default action after detection and advanced ROP mitigation.\n\n \nThe recommended state for this setting is:\n\n \nDefault Action and Mitigation Settings - EnabledDeep Hooks - EnabledAnti Detours - EnabledBanned Functions - EnabledExploit Action - User Configured\n \n\n \n\nRationale\n\n \n\n These advanced mitigations for ROP mitigations apply to all configured software in EMET.\n \n Deep Hooks\n protects critical APIs and the subsequent lower level APIs used by the top level critical API.\n \n Anti Detours\n renders ineffective exploits that evade hooks by executing a copy of the hooked function prologue and then jump to the function past the prologue.\n \n Banned Functions\n will block calls to \n ntdll!LdrHotPatchRoutine\n to mitigate potential exploits abusing the API.\n \n\n \n\n",
"service": "Inspector",
"title": "\n Instance i-001c7d5488de02427 is not compliant with rule 18.9.22.2 L1 Ensure Default Action and Mitigation Settings is set to Enabled plus subsettings, 2.2.0 CIS Microsoft Windows Server 2012 R2 Benchmark. \n\n\n Applicable profiles: Level 2 - Domain Controller, Level 1 - Member Server, Level 2 - Member Server, Level 1 - Domain Controller.\n ",
"indicatorOfCompromise": false,
"assetAttributes": {
"schemaVersion": 1,
"agentId": "i-001c7d5488de02427",
"ipv4Addresses": []
},
"userAttributes": [],
"createdAt": 1507890385.995,
"recommendation": "\n \n \n To establish the recommended configuration via GP, set the following UI path to Enabled:\n \n Computer Configuration\\Policies\\Administrative Templates\\Windows Components\\EMET\\Default Action and Mitigation Settings\n Note: This Group Policy path does not exist by default. An additional Group Policy template (EMET.admx/adml) is required - it is included with Microsoft Enhanced Mitigation Experience Toolkit (EMET).\n \n \n \n ",
"updatedAt": 1507890385.995,
"attributes": [
{
"value": "Level 2 - Domain Controller, Level 1 - Member Server, Level 2 - Member Server, Level 1 - Domain Controller",
"key": "CIS_BENCHMARK_PROFILE"
},
{
"value": "18.9.22.2 L1 Ensure Default Action and Mitigation Settings is set to Enabled plus subsettings",
"key": "BENCHMARK_RULE_ID"
},
{
"value": "2.2.0 CIS Microsoft Windows Server 2012 R2 Benchmark",
"key": "BENCHMARK_ID"
},
{
"value": "i-001c7d5488de02427",
"key": "INSTANCE_ID"
}
],
"schemaVersion": 1,
"serviceAttributes": {
"schemaVersion": 1,
"rulesPackageArn": "arn:aws:inspector:ap-northeast-1:406045910587:rulespackage/0-7WNjqgGu",
"assessmentRunArn": "arn:aws:inspector:ap-northeast-1:XXXXXXXXXXXX:target/0-A6hw1U3n/template/0-4oWqng8L/run/0-ZYzzvWoW"
},
"id": "18.9.22.2 (L1) Ensure 'Default Action and Mitigation Settings' is set to 'Enabled' (plus subsettings)",
"arn": "arn:aws:inspector:ap-northeast-1:XXXXXXXXXXXX:target/0-A6hw1U3n/template/0-4oWqng8L/run/0-ZYzzvWoW/finding/0-BR3WlR1c",
"severity": "High"
}
]
}

まとめ

いかがでしょうか?

EC2 Systems Managerが利用できる状態のEC2インスタンスであれば、RDPでログインすることなく、インストールから診断まで完了させることができました。 Linuxに関しても同じ要領で診断することが可能なはずです。

Run CommandはSSHやRDPでの接続なしにインスタンスの操作が可能なため、認証情報の管理が簡素化されたり、作業の証跡を残すのが容易になるなど、多くのメリットがあります。 今後もEC2 Systems Managerのドキュメントが増えてくれると嬉しいなー、と思っています。(もっと楽がしたい!)