This series of posts captures the footprints of my journey to Capture The Flag on The Big IAM Challenge – Round 2
Challenge 2
![](https://blog.hinsonli.com/wp-content/uploads/2024/03/image-1024x581.png)
Upon above iam policy, the IAM policy applied to the SQS queue is very permissive in terms of the principal ("Principal": "*"
) allowed to perform actions on the queue.
Upon checking the page source code, I find below script
<script>
// Initialize the Amazon Cognito credentials provider
AWS.config.region = 'us-east-1';
AWS.config.credentials = new AWS.CognitoIdentityCredentials({IdentityPoolId: 'us-east-1:c6f3eb2e-3cb5-404e-93bc-f0bdf7ad042e'});
// Set the region
AWS.config.update({region: 'us-east-1'});
// Create an SQS service object for Web Analytics.
// Log trafic from all users into SQS.
var sqs = new AWS.SQS({apiVersion: '2012-11-05'});
var params = {
DelaySeconds: 0,
MessageBody: JSON.stringify({"URL": document.location.href, "User-Agent": navigator.userAgent, "IsAdmin": false}),
QueueUrl: "https://sqs.us-east-1.amazonaws.com/092297851374/wiz-tbic-analytics-sqs-queue-ca7a1b2"
};
sqs.sendMessage(params, function(err, data) {
if (err) {
console.log("Error", err);
} else {
console.log("Success", data.MessageId);
}
});
</script>
This script instructs to use AWS Cognito to initialize a temporary authenticated access to AWS SQS, and the script exposes the Identity pool ID to authenticate.
Hence, I can use aws cli aws cognito-identity get-id --identity-pool-id "us-east-1:c6f3eb2e-3cb5-404e-93bc-f0bdf7ad042e"
to retrieve Cognito identity id.
![](https://blog.hinsonli.com/wp-content/uploads/2024/03/image-2-1024x182.png)
Next step is to use this identitly id to retrieve temporary AWS crendentials by command aws cognito-identity get-credentials-for-identity --identity-id "<cognito-identity-id>"
![](https://blog.hinsonli.com/wp-content/uploads/2024/03/image-3-1024x240.png)
With the access credential retrieved, I am trying to add it to an AWS profile, but it seems this website does not provide a way to add credentials to AWS configuration.
![](https://blog.hinsonli.com/wp-content/uploads/2024/03/image-4-1024x331.png)
Instead, I export those credentials as Linux environment variables
![](https://blog.hinsonli.com/wp-content/uploads/2024/03/image-5-1024x197.png)
I tried to write a message “Hinson captures the FLAG!” to the sqs queue and it seems to be working!
![](https://blog.hinsonli.com/wp-content/uploads/2024/03/image-6-1024x133.png)
Next, I try to receive any messages from sqs to see if I am presented with flag by command "aws sqs receive-message --queue-url https://sqs.us-east-1.amazonaws.com/092297851374/wiz-tbic-analytics-sqs-queue-ca7a1b2 --region us-east-1"
I can see there is a URL presented, and I can see the flag presented on the page.
![](https://blog.hinsonli.com/wp-content/uploads/2024/03/image-7-1024x264.png)
![](https://blog.hinsonli.com/wp-content/uploads/2024/03/image-8-1024x134.png)
Happily cracked the second challenge!
![](https://blog.hinsonli.com/wp-content/uploads/2024/03/success.jpg)