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

Tip

AWS 해킹 학습 및 실습:HackTricks Training AWS Red Team Expert (ARTE)
GCP 해킹 학습 및 실습: HackTricks Training GCP Red Team Expert (GRTE)
Az 해킹 학습 및 실습: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks 지원하기

VPC & Networking

VPC가 무엇인지와 그 구성요소에 대해 알아보세요:

AWS - VPC & Networking Basic Information

EC2

Amazon EC2는 가상 서버를 시작하는 데 사용됩니다. 보안, 네트워킹 구성과 스토리지 관리를 할 수 있습니다. Amazon EC2의 유연성은 리소스를 상하로 확장할 수 있는 능력에서 드러나며, 이는 요구사항 변화나 인기 급증에 효과적으로 대응할 수 있게 해줍니다. 이 기능은 정확한 트래픽 예측의 필요성을 줄여줍니다.

EC2에서 열거할 만한 항목:

  • 가상 머신
  • SSH 키
  • User Data
  • 기존 EC2s/AMIs/Snapshots
  • 네트워킹
  • 네트워크
  • 서브넷
  • 퍼블릭 IP
  • 열린 포트
  • AWS 외부의 다른 네트워크와의 통합 연결

Instance Profiles

roles를 사용해 EC2 instances에서 실행되는 애플리케이션에 권한을 부여하려면 약간의 추가 구성이 필요합니다. EC2 인스턴스에서 실행되는 애플리케이션은 가상화된 운영체제에 의해 AWS로부터 추상화되어 있습니다. 이러한 추가 분리 때문에 AWS role과 관련 권한을 EC2 인스턴스에 할당하여 애플리케이션에서 사용 가능하게 하려면 추가 단계가 필요합니다.

이 추가 단계는 인스턴스에 연결된 생성 instance profile입니다. 그 instance profile은 role을 포함하며, 인스턴스에서 실행되는 애플리케이션에 역할의 임시 자격증명을 제공할 수 있습니다. 이러한 임시 자격증명은 애플리케이션의 API 호출에서 리소스에 접근하거나 역할이 지정한 리소스에만 접근을 제한하는 데 사용될 수 있습니다. 참고로 한 번에 하나의 role만 EC2 인스턴스에 할당될 수 있으며, 인스턴스의 모든 애플리케이션은 동일한 역할과 권한을 공유합니다.

Metadata Endpoint

AWS EC2 metadata는 런타임에 인스턴스에서 접근 가능한 Amazon Elastic Compute Cloud (EC2) 인스턴스에 관한 정보입니다. 이 메타데이터는 인스턴스 ID, 인스턴스가 실행 중인 가용 영역(availability zone), 인스턴스에 연결된 IAM role, 인스턴스의 호스트명 등 인스턴스에 대한 정보를 제공합니다.

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

인증되지 않은 접근

AWS - EC2 Unauthenticated Enum

Privesc

다음 페이지에서 abuse EC2 permissions to escalate privileges 방법을 확인할 수 있습니다:

AWS - EC2 Privesc

Post-Exploitation

AWS - EC2, EBS, SSM & VPC Post Exploitation

EBS

Amazon EBS (Elastic Block Store) snapshots 는 기본적으로 EBS 볼륨의 정적 백업입니다. 다시 말해, 특정 시점에 EC2 인스턴스에 연결된 디스크복사본입니다. EBS snapshots는 리전과 계정 간에 복사하거나 심지어 다운로드하여 로컬에서 실행할 수도 있습니다.

스냅샷에는 source code or APi keys 와 같은 민감한 정보가 포함될 수 있으므로, 가능하다면 확인해보는 것이 권장됩니다.

Difference AMI & EBS

AMIlaunch an EC2 instance 하는 데 사용되는 반면, EC2 Snapshot은 EBS 볼륨에 저장된 데이터를 backup and recover 하는 데 사용됩니다. EC2 Snapshot으로 새 AMI를 만들 수는 있지만, AMI와 동일한 것은 아니며 운영 체제, application server 또는 애플리케이션 실행에 필요한 다른 소프트웨어에 대한 정보는 포함하지 않습니다.

Privesc

다음 페이지에서 abuse EBS permissions to escalate privileges 방법을 확인할 수 있습니다:

AWS - EBS Privesc

SSM

Amazon Simple Systems Manager (SSM) 는 EC2 인스턴스 집단을 원격으로 관리하여 관리 작업을 훨씬 쉽게 합니다. 이러한 각 인스턴스는 SSM Agent service as the service will be the one getting the actions and performing them 가 실행 중이어야 합니다. 해당 서비스가 AWS API로부터 작업을 받아 이를 수행하기 때문입니다.

SSM Agent 는 Systems Manager가 이러한 리소스를 업데이트, 관리 및 구성할 수 있게 합니다. 에이전트는 processes requests from the Systems Manager service in the AWS Cloud 하고, 요청에 지정된 대로 이를 실행합니다.

The SSM Agent comes preinstalled in some AMIs or you need to manually install them on the instances. 또한, 인스턴스 내에서 사용되는 IAM Role에는 통신을 위해 AmazonEC2RoleforSSM 정책이 연결되어 있어야 합니다.

열거

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은 귀사의 온프레미스 네트워크 (site-to-site VPN) 또는 **작업자 노트북 (Client VPN)**을 AWS VPC에 연결하여 서비스들을 인터넷에 노출할 필요 없이 접근할 수 있게 해줍니다.

Basic AWS VPN Components

  1. Customer Gateway:
  • A Customer Gateway is a resource that you create in AWS to represent your side of a VPN connection.
  • It is essentially a physical device or software application on your side of the Site-to-Site VPN connection.
  • You provide routing information and the public IP address of your network device (such as a router or a firewall) to AWS to create a Customer Gateway.
  • It serves as a reference point for setting up the VPN connection and doesn’t incur additional charges.
  1. Virtual Private Gateway:
  • A Virtual Private Gateway (VPG) is the VPN concentrator on the Amazon side of the Site-to-Site VPN connection.
  • It is attached to your VPC and serves as the target for your VPN connection.
  • VPG is the AWS side endpoint for the VPN connection.
  • It handles the secure communication between your VPC and your on-premises network.
  1. Site-to-Site VPN Connection:
  • A Site-to-Site VPN connection connects your on-premises network to a VPC through a secure, IPsec VPN tunnel.
  • This type of connection requires a Customer Gateway and a Virtual Private Gateway.
  • It’s used for secure, stable, and consistent communication between your data center or network and your AWS environment.
  • Typically used for regular, long-term connections and is billed based on the amount of data transferred over the connection.
  1. Client VPN Endpoint:
  • A Client VPN endpoint is a resource that you create in AWS to enable and manage client VPN sessions.
  • It is used for allowing individual devices (like laptops, smartphones, etc.) to securely connect to AWS resources or your on-premises network.
  • It differs from Site-to-Site VPN in that it is designed for individual clients rather than connecting entire networks.
  • With Client VPN, each client device uses a VPN client software to establish a secure connection.

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

열거

# 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

Local Enumeration

Local Temporary Credentials

AWS VPN Client가 VPN에 연결될 때, 사용자는 일반적으로 VPN에 접근하기 위해 AWS에 로그인합니다. 그 후, VPN 연결을 설정하기 위해 일부 AWS credentials가 생성되어 로컬에 저장됩니다. 해당 자격증명은 $HOME/.config/AWSVPNClient/TemporaryCredentials/<region>/temporary-credentials.txt에 저장되며 AccessKey, SecretKey, Token을 포함합니다.

해당 자격증명은 사용자 arn:aws:sts::<acc-id>:assumed-role/aws-vpn-client-metrics-analytics-access-role/CognitoIdentityCredentials에 속합니다 (TODO: 이 자격증명의 권한에 대해 추가 조사 필요).

opvn config files

VPN 연결이 수립된 경우 시스템에서 .opvn 구성 파일을 찾아보세요. 또한 구성 파일을 찾을 수 있는 위치 중 하나는 **$HOME/.config/AWSVPNClient/OpenVpnConfigs**입니다.

Post Exploitaiton

AWS - VPN Post Exploitation

References

Tip

AWS 해킹 학습 및 실습:HackTricks Training AWS Red Team Expert (ARTE)
GCP 해킹 학습 및 실습: HackTricks Training GCP Red Team Expert (GRTE)
Az 해킹 학습 및 실습: HackTricks Training Azure Red Team Expert (AzRTE)

HackTricks 지원하기