基于GuardDuty发现自动禁用AWS托管Microsoft AD用户的技术实现

本文详细介绍了如何利用Amazon GuardDuty检测安全威胁,并通过EventBridge、Step Functions和Systems Manager Run Command实现自动禁用AWS托管Microsoft AD中可疑用户账户的完整技术方案。

基于GuardDuty发现自动禁用AWS托管Microsoft AD用户

背景

组织面临日益增长的安全威胁,特别是用户账户被盗用的情况。手动监控和响应可疑活动不仅耗时,而且容易出错。缺乏安全事件自动化响应可能导致数据泄露和财务损失等灾难性后果。

本文展示了如何使用Amazon GuardDuty检测可疑事件,并基于这些发现创建自动化流程来禁用AWS Directory Service for Microsoft Active Directory中的用户账户。

解决方案概述

该方案部署测试EC2实例并启用GuardDuty运行时监控。发现结果将触发EventBridge规则,执行Step Functions状态机,运行两个Systems Manager Run Command文档:一个用于发现用户名,另一个使用目录管理EC2实例禁用相应用户。

技术组件详解

Amazon GuardDuty

GuardDuty是一种自动化威胁检测服务,持续监控可疑活动和未授权行为,保护AWS账户、工作负载和Amazon S3中存储的数据。

激活步骤:

  1. 访问AWS管理控制台中的GuardDuty
  2. 首次使用时选择"All Features"并点击"Get Started"
  3. 之前使用过则选择"Runtime Monitoring"并启用

AWS托管Microsoft AD

AWS托管Microsoft AD在AWS云中提供完全托管的Microsoft Active Directory服务。创建目录时,AWS会在不同可用区部署两个专属域控制器以实现高可用性。

部署步骤:

  1. 访问Directory Service控制台
  2. 选择"Set up directory"并选择"AWS Managed Microsoft AD"
  3. 选择标准版,输入目录DNS名称和密码
  4. 选择VPC(本例使用默认VPC)
  5. 创建目录

目录管理EC2实例

该实例用于通过AWS Systems Manager控制Microsoft Active Directory。

部署步骤:

  1. 等待目录状态变为Active(20-45分钟)
  2. 选择目录ID
  3. 通过"Launch directory Administration EC2 Instance"部署管理实例

Systems Manager配置

配置Systems Manager以管理Active Directory:

  1. 在管理实例上打开服务
  2. 找到Amazon SSM Agent,配置登录账户为特权域用户
  3. 重启SSM Agent服务

Systems Manager Run Command

创建两个Run Command文档:

禁用AD用户文档(DisableADUser)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
schemaVersion: "2.2"
description: "Disable AD Users"
parameters:
  UserName:
    type: String
    description: "(Required) The username to disable."
mainSteps:
- action: "aws:runPowerShellScript"
  name: "DisableUser"
  inputs:
    runCommand:
    - "import-module activedirectory"
    - "$disableuser = get-aduser {{ UserName }} | select-object -ExpandProperty DistinguishedName"
    - "dsmod user $disableuser -disabled yes"

从用户ID获取用户名文档(GetUsernameFromID)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
description: "Get Username from Linux"
schemaVersion: "2.2"
parameters:
  UserId:
    type: String
    description: "(Required) The User ID to find."
    default: "1000"
mainSteps:
- action: aws:runShellScript
  name: GetLinuxUsername
  precondition:
    StringEquals:
    - platformType
    - Linux
  inputs:
    timeoutSeconds: 7200
    runCommand:
      - "#!/bin/bash"
      - "#"
      - "UserName=$(id -nu {{ UserId }})"
      - "if [[ $UserName == *'@'* ]]; then"
      - "echo ${UserName%@*} "
      - "else if [[ $UserName == *'\\'* ]]; then"
      - "echo $UserName | sed 's/.*\\\\//g'"
      - "fi"
      - "fi"
  outputs:
    - Name: output
      Selector: $.Payload.output
      Type: String

Step Functions状态机

创建状态机来协调整个流程:

  1. 使用JSONPath作为状态机查询语言
  2. 添加Systems Manager SendCommand操作来查找用户名
  3. 添加等待操作(5秒)
  4. 添加GetCommandInvocation操作获取用户名
  5. 添加SendCommand操作禁用AD用户
  6. 配置选择逻辑基于UserID是否存在

状态机API参数示例:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
{
  "DocumentName": "GetUsernameFromID",
  "Parameters": {
    "UserId.$": "States.Array(States.JsonToString($.detail.service.runtimeDetails.process.euid))"
  },
  "Targets": [
    {
      "Key": "InstanceIds",
      "Values.$": "States.Array($.detail.resource.instanceDetails.instanceId)"
    }
  ]
}

EventBridge规则

创建事件规则触发自动化流程:

事件模式:

1
2
3
4
{
  "source": ["aws.guardduty"],
  "detail-type": ["GuardDuty Finding"]
}

测试验证

  1. 创建域加入的Linux EC2测试实例
  2. 使用测试用户执行可疑命令:curl guarddutyc2activityb.com
  3. GuardDuty在3-5分钟内生成高严重性发现
  4. 验证Active Directory中相应用户已被禁用

扩展应用

该方案可扩展用于:

  • 重置Active Directory密码
  • 禁用计算机账户
  • 通过Amazon SNS通知管理员
  • 使用AWS Lambda添加额外检查
  • 支持本地Active Directory部署

总结

本文提供了完整的自动化安全响应方案,结合了AWS Managed AD、Systems Manager Run Command、EventBridge、Step Functions和GuardDuty等技术组件,实现了对可疑活动的自动检测和响应。

comments powered by Disqus
使用 Hugo 构建
主题 StackJimmy 设计