Yo, Hello Hello @everyone. It's been a good week to bring back Hackwekend. Continuously, today we will learn and solve challenge CTF of Wiz.io about Cloud Security, Target today is IAM. Let digest bruh :smiling_face_with_smiling_eyes_and_hand_covering_mouth:
Challenge Link: BigIAMChallenge
Description: We all know that public buckets are risky. But can you find the flag?
At first, let talk about the challenge. Base on the description and IAM Policy we know about the flag will stay on Bucket, therefore we need to know about Bucket, How the Bucket work, digest inside that.
Learn more about S3 with What is S3 ?
(TL;DR) Amazon Simple Storage Service (Amazon S3) is an object storage service that offers industry-leading scalability, data availability, security, and performance.Use Amazon S3 to store and protect any amount of data for a range of use cases, such as data lakes, websites, mobile applications, backup and restore, archive, enterprise applications, IoT devices, and big data analytics. Amazon S3 provides management features so that you can optimize, organize, and configure access to your data to meet your specific business, organizational, and compliance requirements.
I can brief about the S3
, It's kind simple location for put your file, data and anything into that and It's totally on AWS
. It means on this challenge you just figure out how to get the data from bucket
You will need some help about aws s3 documentaion
Base on the IAM Policy, you have role to get
and list
the bucket, it mean you need to do
First of all, you need to list s3 objects for find the what flag file you want, and you can see we have additions end point files
. Do trigger s3 ls
command and you will know flag file
The flag1.txt is exposing, next step is reading contents inside flag1.txt
, use cp
command to take others work :smiling_face_with_smiling_eyes_and_hand_covering_mouth:
Flag: {wiz:exposed-xxxxxxxxx-as-usual}
With first challenge, It looks basicly, you can learn how to list and get contents inside bucket object. So with S3 you expose to Internet and not protect anything, your secret can be leaked. Thus, you need to apply the policy into s3 for secure what access can perform
Learn more about that with Security best practices for Amazon S3
Description: We created our own analytics system specifically for this challenge. We think it's so good that we even used it on this page. What could go wrong? Join our queue and get the secret flag.
Next stage, on this challenge you need to know about sqs
, Message queue service of AWS.
(TL;DR) Amazon Simple Queue Service (Amazon SQS) offers a secure, durable, and available hosted queue that lets you integrate and decouple distributed software systems and components. Amazon SQS offers common constructs such as dead-letter queues and cost allocation tags. It provides a generic web services API that you can access using any programming language that the AWS SDK supports.
Simplely, you need to figure out what sqs
working, receive message in the queue and read the contents inside, Flag will expose
I just read couple walkthrough, you can find the hard way to play this challenge via this write-up
With me, i just solve this challenge kind simple way, but you need to know about IAM policy we have send-message
& receive-message
. Googling about this stuff, you will have documentation
First of all, I try to retrive what message we got from queue, maybe interesting is inside and right expectation you will found the hidden URL, with receive-message
command (FACT: This command is finding inside the documentation of receive-message
command, guess and truth :smile:)
Access Body URL for doing access bucket to reach flag contents
Flag: {wiz:you-are-xxxxxxx-of-the-queue}
Through this challenge, you will learn how about
sqs
service of AWS, maybereceive
is enough for this challenge but you can try another to create queue message withsend
. And another meaning, you need to secure and put IAM for your service on AWS, It will best practice for securing any service
Learn more about with Security in Amazon SQS
Description: We got a message for you. Can you get it?
On this challenge, we will learn about a new service SNS
, Simple Notification Service of AWS
(TL;DR) Amazon Simple Notification Service (Amazon SNS) is a managed service that provides message delivery from publishers to subscribers (also known as producers and consumers). Publishers communicate asynchronously with subscribers by sending messages to a topic, which is a logical access point and communication channel. Clients can subscribe to the SNS topic and receive published messages using a supported endpoint type, such as Amazon Data Firehose, Amazon SQS, AWS Lambda, HTTP, email, mobile push notifications, and mobile text messages (SMS).
It requires you submit publisher for topic and send it to your server, and maybe contents is staying on this messsage return.
To do the job like expectation, you need to know about manipulation the request, It means you make a mock server where you can receive GET
and POST
request to server. Some application which you can use on situation like
On this situaion, I don't know why i can use webhook.site
to receive message submit from subscribe, so Beeceeptor
come like coincident instead for webhooksite
To subscribe endpoint for topic, you can figure out the method with documentation, it use sns subscribe
and submit nofication can be beeceptor
or webhook.site
Subscribe with webhook.site
(Very long to receive message confirmation)
Subscribe with beeceptor
(Sorry not have image because of the broken of beeceptor in written process)
Wait some few second, you will receive this message with request about subscription confirmation
Use subcribe URL to apply the confirm
Wait some few second, message return the flag on your webhook
or beeceptor
site
Flag: {wiz:always-xxxxxxx-asterisks}
Through this challenge, you will learn and figure out how the
sns
work, how can you subscribe the topic and get the message return withmock-site
orwebhook-site
.
Learn more about how to protect Amazon SNS security best practices
We learned from our mistakes from the past. Now our bucket only allows access to one specific admin user. Or does it?
This challenge ask you about list and get the contents in S3
but more secure, You can learn about s3
on first challenge
When check the condition, you have additional ARN with ForAllValues
, and you need to bypass and list the bucket
After focus about the additional ARN, I figure out we need to bypas over s3 authentication, and solution can be Diving Deeply into IAM Policy Evaluation – Highlights from AWS re:Inforce IAM433
The problem is the usage of the ForAllValues operator! When the key is absent from the authorization context (as with a role that is not tagged with the key “Team”), the condition evaluates to true. Formally speaking this is because the empty set is a subset of all sets. “For all values in A x is true” is true if the group A is the empty set.
It mean when we not set the sign request, credential is not submit with --no-sign-request
flag, and luckyly s3
bucket support to bypass this situation :smiling_face_with_smiling_eyes_and_hand_covering_mouth:
Get the name file, submit the cp
command to getting the contents
Flag: {wiz:principal-arn-xxx-xxx-xxx-you-think}
Through this challenge, not anything is very secure, you can make misconfiguration and mistake will occur, very carefully when use
ForAllValues
.
To secure that, you need to read Authorization context: Principal evaluation to understand how IAM should be apply or not, figure out the different and find the best match condition which require for your service
Description: We configured AWS Cognito as our main identity provider. Let's hope we didn't make any mistakes.
On this challenge, you will work with new service identity cognito
of AWS
(TL;DR) Amazon Cognito is an Amazon Web Services product that controls user authentication and access for mobile applications on internet-connected devices. The service saves and synchronizes end-user data, which enables an application developer to focus on writing code instead of building and managing the back-end infrastructure. This can accelerate the mobile application development process.
It mean you need to use cognito
to authentication your shell or get identity for access to private bucket
First of all, you need to check out the raw of script, IDK about it but it's CTF challenge and why you need to do this work, and some thing indentity hide in background. Use F12 to view that or viewsource://
. The identity-pool-id
will expose
After view policy, you know you have full role of aws cognito it mean you need to use cognito for escalate permission, and yeah to get identity with cognito you can use get-id
to read the IdentityID
Get the IdentityID, It's really a good new. Reaching to next step to get full profile to authentication applications, it mean use can use IdentityID
for get credentials
for cognito user, with command get-credentials-for-identity
You can save this credential into shell or overwrite environment to apply this role for current shell, but not like dream, you must be run configure
to set this up :laughing: :laughing: :laughing:
It tough to said that you will need aws on your shell to perform this command because you will not allow to run this command on that shell, IDK (Couple day ago i can but currently it not, waste much time for figure out the reaso )
Easily, Save some the token and export them to environment for authentication, very easily read about that on documentation
After export env variable for authentication AWS-cli, you can check about aws role with sts
command
So other works is pretty easily, you can list bucket contents and read that flag
Flag: {wiz:incognito-xxxx-xxx-suspicious}
Awesome challenge, you learn about how the mobile or external can authentication with
cognito
of aws, learn about how we can usecongito
to create the variables for connectAWS
Learn more about how to secure cognito
with Security in Amazon Cognito
Description: Anonymous access no more. Let's see what can you do now. Now try it with the authenticated role: arn:aws:iam::092297851374:role/Cognito_s3accessAuth_Role
On this challenge, It's a level up of Challenge 5, you need to figure out the way to assume webidentity - another way to authentication aws with sepecify role
First of all, with word of challenge how to assume the role, you need to figure out this challenge that kind same as challenge 5. Easily, you have the identity-pool-id
in IAM Policy, Just need to get-id
from cognito
Next step, get open-id
for assume role with web-identity
instead of get the credentials, because you will not have permission (I think so :smile:) like challenge 5
Experiment: Walkthrough step like challenge 5, and you will get the identity
like this
You will sad and disappointed about that situation, you will fail to authentication with get-credentials-for-identity
, it require web-identity
First of all, you need to know requirement of assume role commmand, assume-role-with-web-identity
It require, --role-arn <value> --role-session-name <value> --web-identity-token <value>
arn:aws:iam::092297851374:role/Cognito_s3accessAuth_Role
<base-on-decision>
So It mean you can use 0Auth 2.0 token
or openid connect id token
to provide webidentity. It mean you can use cognito-identity to provide your openid token
. You will use get-open-id-token
to generate openid token for your shell
Done, next step we will assume currently shell to role with web-identity
token
(Warning) I make it but at least, format is terrible so you need to careful about that, one more thing you need to concern because
IdentityID
andToken
have limit time
Like chal5, export env for authentication your aws-cli. after that you will assume role completely
After export env variable, use sts
to check your authentication
Completely all step above, you need to define what s3 to open and contents of bucket, easily like challenge 1
Access and read content of flag inside the last challenge
Flag: {wiz:open-sesame-xxx-xxx-xxx-say-openid}
Through this challenge, you can learn a new way to authentication you account with assume role with
web-identity
, cool methodology and easily to understand.
That all for today, I hope you and me learn a newthing about IAM, Policy and methodology for authentication your application. AWS is very cool stuff cloud environment with unique technical, with me AWS can bring you more knowledge about Identity, Authentication, Service and new awesome theory. :smoking:
What a hackwekend is ending, and can be on next session we will continue learning Cloud security with Wiz.io about K8s Networking. See you again on that, Stay safe and enjoy hacking, be back soon :smiling_face_with_smiling_eyes_and_hand_covering_mouth: