AWS - EC2, EBS, ELB, SSM, VPC & VPN Enum

Tip

学んで実践する AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
学んで実践する GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
学んで実践する Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks をサポートする

VPC & ネットワーキング

Learn what a VPC is and about its components in:

AWS - VPC & Networking Basic Information

EC2

Amazon EC2 is utilized for initiating virtual servers. It allows for the configuration of security and networking and the management of storage. The flexibility of Amazon EC2 is evident in its ability to scale resources both upwards and downwards, effectively adapting to varying requirement changes or surges in popularity. This feature diminishes the necessity for precise traffic predictions.

Interesting things to enumerate in EC2:

  • 仮想マシン
  • SSHキー
  • ユーザーデータ
  • 既存の EC2/AMIs/Snapshots
  • ネットワーキング
  • ネットワーク
  • サブネット
  • パブリックIP
  • 開いているポート
  • AWS外のネットワークとの接続

Instance Profiles

EC2インスタンス上で実行されるアプリケーションに権限を付与するためにロールを使用するには、少し追加の設定が必要です。EC2インスタンス上で動作するアプリケーションは、仮想化されたオペレーティングシステムによってAWSから抽象化されています。この追加の分離のため、AWSロールとその関連する権限をEC2インスタンスに割り当て、アプリケーションが利用できるようにするために追加の手順が必要です。

この追加手順は、インスタンスにアタッチされたinstance profileの作成です。インスタンスプロファイルはロールを含み、そのロールの一時的な認証情報をインスタンス上で実行されるアプリケーションに提供できます。それらの一時認証情報はアプリケーションのAPIコールでリソースにアクセスするために使用でき、ロールが指定するリソースのみにアクセスを限定することができます。1つのEC2インスタンスに割り当てられるロールは同時に1つだけであり、インスタンス上のすべてのアプリケーションは同じロールと権限を共有する点に注意してください。

Metadata Endpoint

AWS EC2 metadataは、ランタイム時にインスタンスから利用可能なAmazon Elastic Compute Cloud (EC2) インスタンスに関する情報です。このメタデータは、インスタンスID、稼働しているアベイラビリティゾーン、インスタンスに関連付けられたIAMロール、インスタンスのホスト名など、インスタンスに関する情報を提供するために使用されます。

Cloud SSRF - HackTricks

Enumeration

# Get EC2 instances
aws ec2 describe-instances
aws ec2 describe-instance-status #Get status from running instances

# Get user data from each ec2 instance
for instanceid in $(aws ec2 describe-instances --profile <profile> --region us-west-2 | grep -Eo '"i-[a-zA-Z0-9]+' | tr -d '"'); do
echo "Instance ID: $instanceid"
aws ec2 describe-instance-attribute --profile <profile> --region us-west-2 --instance-id "$instanceid" --attribute userData | jq ".UserData.Value" | tr -d '"' | base64 -d
echo ""
echo "-------------------"
done

# Instance profiles
aws iam list-instance-profiles
aws iam list-instance-profiles-for-role --role-name <name>

# Get tags
aws ec2 describe-tags

# Get volumes
aws ec2 describe-volume-status
aws ec2 describe-volumes

# Get snapshots
aws ec2 describe-snapshots --owner-ids self

# Scheduled instances
aws ec2 describe-scheduled-instances

# Get custom images
aws ec2 describe-images --owners self

# Get Elastic IPs
aws ec2 describe-addresses

# Get current output
aws ec2 get-console-output --instance-id [id]

# Get a JPG-format screenshot of a running instance
aws ec2 get-console-screenshot --instance [id]

# Get VPN customer gateways
aws ec2 describe-customer-gateways
aws ec2 describe-vpn-gateways
aws ec2 describe-vpn-connections

# List conversion tasks to upload/download VMs
aws ec2 describe-conversion-tasks
aws ec2 describe-import-image-tasks

# Get Bundle Tasks
aws ec2 describe-bundle-tasks

# Get Classic Instances
aws ec2 describe-classic-link-instances

# Get Dedicated Hosts
aws ec2 describe-hosts

# Get SSH Key Pairs
aws ec2 describe-key-pairs

# Get Internet Gateways
aws ec2 describe-internet-gateways

# Get NAT Gateways
aws ec2 describe-nat-gateways

# Get subnetworks
aws ec2 describe-subnets

# Get FW rules
aws ec2 describe-network-acls

# Get security groups
aws ec2 describe-security-groups

# Get interfaces
aws ec2 describe-network-interfaces

# Get routes table
aws ec2 describe-route-tables

# Get VPCs
aws ec2 describe-vpcs
aws ec2 describe-vpc-peering-connections

Unauthenticated Access

AWS - EC2 Unauthenticated Enum

Privesc

In the following page you can check how to abuse EC2 permissions to escalate privileges:

AWS - EC2 Privesc

Post-Exploitation

AWS - EC2, EBS, SSM & VPC Post Exploitation

EBS

Amazon EBS (Elastic Block Store) の スナップショット は基本的に AWS EBS ボリュームの静的な バックアップ です。言い換えれば、特定の時点で EC2 インスタンスに接続されている ディスクコピー です。EBS スナップショットはリージョンやアカウント間でコピーしたり、ダウンロードしてローカルで実行することもできます。

スナップショットには 機密情報ソースコードやAPIキー など)が含まれている場合があるため、機会があれば確認することをお勧めします。

Difference AMI & EBS

An AMI is used to launch an EC2 instance, while an EC2 Snapshot is used to backup and recover data stored on an EBS volume. While an EC2 Snapshot can be used to create a new AMI, it is not the same thing as an AMI, and it does not include information about the operating system, application server, or other software required to run an application.

Privesc

In the following page you can check how to abuse EBS permissions to escalate privileges:

AWS - EBS Privesc

SSM

Amazon Simple Systems Manager (SSM) は、EC2 インスタンスのフリートをリモートで管理し、運用を容易にします。これらの各インスタンスは、AWS API からの操作を受け取りそれを実行するために、SSM Agent service as the service will be the one getting the actions and performing them を実行している必要があります。

SSM Agent により、Systems Manager はこれらのリソースを更新、管理、構成できるようになります。エージェントは processes requests from the Systems Manager service in the AWS Cloud, そしてリクエストに指定されたとおりに実行します。

SSM Agent comes preinstalled in some AMIs or you need to manually install them on the instances. また、インスタンス内で使用される IAM Role には通信を行うために AmazonEC2RoleforSSM ポリシーがアタッチされている必要があります。

Enumeration

aws ssm describe-instance-information
aws ssm describe-parameters
aws ssm describe-sessions --state [Active|History]
aws ssm describe-instance-patches --instance-id <id>
aws ssm describe-instance-patch-states --instance-ids <id>
aws ssm describe-instance-associations-status --instance-id <id>

EC2 インスタンスで Systems Manager が実行されているかどうかは、次のコマンドを実行するだけで確認できます:

ps aux | grep amazon-ssm

Privesc

次のページでは、abuse SSM permissions to escalate privileges の方法を確認できます:

AWS - SSM Privesc

Perssistence

次のページでは、abuse SSM permissions to achieve persistence の方法を確認できます:

AWS - SSM Perssitence

ELB

Elastic Load Balancing (ELB) は、load-balancing service for Amazon Web Services (AWS) のデプロイで使用されるサービスです。ELB は自動的に受信するアプリケーショントラフィックを配分し、トラフィックの需要に応じてリソースをスケールします。

Enumeration

# List internet-facing ELBs
aws elb describe-load-balancers
aws elb describe-load-balancers | jq '.LoadBalancerDescriptions[]| select( .Scheme | contains("internet-facing"))|.DNSName'

# DONT FORGET TO CHECK VERSION 2
aws elbv2 describe-load-balancers
aws elbv2 describe-load-balancers | jq '.LoadBalancers[].DNSName'
aws elbv2 describe-listeners --load-balancer-arn <load_balancer_arn>

Launch Templates & Autoscaling Groups

列挙

# Launch templates
aws ec2 describe-launch-templates
aws ec2 describe-launch-templates --launch-template-id <launch_template_id>
## Get details, like user data
aws ec2 describe-launch-template-versions --launch-template-id <launch_template_id>

# Autoscaling
aws autoscaling describe-auto-scaling-groups
aws autoscaling describe-auto-scaling-instances
aws autoscaling describe-launch-configurations
aws autoscaling describe-load-balancer-target-groups
aws autoscaling describe-load-balancers

Nitro

AWS Nitro は、AWS EC2 インスタンスの基盤を成す革新的なテクノロジー群です。Amazon によって導入され、セキュリティ、パフォーマンス、信頼性を向上させるために、Nitro はカスタムのハードウェアコンポーネントと軽量なハイパーバイザーを活用します。従来の仮想化機能の多くを専用ハードウェアとソフトウェアへ抽象化し、攻撃対象領域を最小化するとともにリソース効率を改善します。仮想化機能をオフロードすることで、Nitro は EC2 インスタンスにほぼベアメタルに近いパフォーマンスを提供し、リソース集約型アプリケーションに特に有利になります。さらに、Nitro Security Chip はハードウェアとファームウェアのセキュリティを特に確保し、その堅牢なアーキテクチャをさらに強化します。

Get more information and how to enumerate it from:

AWS - Nitro Enum

VPN

VPN は、on-premise network (site-to-site VPN)workers laptops (Client VPN)AWS VPC に接続し、サービスをインターネットに公開することなくアクセスできるようにします。

Basic AWS VPN Components

  1. Customer Gateway:
  • A Customer Gateway は、VPN 接続のあなた側を表すために AWS に作成するリソースです。
  • これは実質的に、Site-to-Site VPN 接続のあなた側にある物理デバイスまたはソフトウェアアプリケーションです。
  • Customer Gateway を作成する際に、ルーティング情報とネットワーク機器(例: router や firewall)のパブリック IP アドレスを AWS に提供します。
  • VPN 接続の設定の参照点として機能し、追加料金は発生しません。
  1. Virtual Private Gateway:
  • A Virtual Private Gateway (VPG) は、Site-to-Site VPN 接続の Amazon 側の VPN コンセントレーターです。
  • VPC にアタッチされ、VPN 接続のターゲットとして機能します。
  • VPG は VPN 接続の AWS 側エンドポイントです。
  • VPC とオンプレミスネットワーク間のセキュアな通信を処理します。
  1. Site-to-Site VPN Connection:
  • Site-to-Site VPN 接続は、IPsec VPN トンネルを通じてオンプレミスネットワークを VPC に接続します。
  • このタイプの接続には Customer Gateway と Virtual Private Gateway が必要です。
  • データセンターやネットワークと AWS 環境間のセキュアで安定した一貫した通信に使用されます。
  • 通常は定期的かつ長期的な接続に使用され、接続を通じて転送されたデータ量に基づいて課金されます。
  1. Client VPN Endpoint:
  • Client VPN endpoint は、クライアント VPN セッションを有効化および管理するために AWS に作成するリソースです。
  • 個々のデバイス(laptops、smartphones など)が AWS リソースやオンプレミスネットワークにセキュアに接続するために使用されます。
  • Site-to-Site VPN とは異なり、ネットワーク全体を接続するのではなく個々のクライアント向けに設計されています。
  • Client VPN では、各クライアントデバイスが VPN クライアントソフトウェアを使用してセキュアな接続を確立します。

You can find more information about the benefits and components of AWS VPNs here.

Enumeration

# VPN endpoints
## Check used subnetwork, authentication, SGs, connected...
aws ec2 describe-client-vpn-endpoints

## Get AWS network info related to the vpn endpoint
aws ec2 describe-client-vpn-target-networks --client-vpn-endpoint-id <id>

## Get AWS subnet & ip range the VPN iconnected to
aws ec2 describe-client-vpn-routes --client-vpn-endpoint-id <id>

## Check authorization rules
aws ec2 describe-client-vpn-authorization-rules --client-vpn-endpoint-id <id>

## Get current connections to the VPN endpoint
aws ec2 describe-client-vpn-connections --client-vpn-endpoint-id <id>

# Get VPN gateways and check with which VPC each is connected
aws ec2 describe-vpn-gateways

# Get VPN site-to-site connections
aws ec2 describe-vpn-connections

ローカル列挙

ローカル一時認証情報

When AWS VPN Client is used to connect to a VPN, the user will usually login in AWS to get access to the VPN. Then, some AWS credentials are created and stored locally to establish the VPN connection. These credentials are stored in $HOME/.config/AWSVPNClient/TemporaryCredentials/<region>/temporary-credentials.txt and contains an AccessKey, a SecretKey and a Token.

これらの資格情報はユーザー arn:aws:sts::<acc-id>:assumed-role/aws-vpn-client-metrics-analytics-access-role/CognitoIdentityCredentials に属します(TODO: これらの資格情報の権限についてさらに調査する)。

opvn 設定ファイル

もし VPN 接続が確立されている 場合、システム上で .opvn 設定ファイルを検索すべきです。さらに、設定が見つかる場所のひとつは $HOME/.config/AWSVPNClient/OpenVpnConfigs です。

Post Exploitaiton

AWS - VPN Post Exploitation

参考

Tip

学んで実践する AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
学んで実践する GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)
学んで実践する Az Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks をサポートする