SNS_Secrets (Cloudgoat): API Key Exposure via SNS Topic Subscription

In this CloudGoat scenario (sns_secrets), I demonstrated how a misconfigured AWS SNS topic can lead to the exposure of a sensitive API Gateway key. With that key, I accessed a protected API endpoint containing hardcoded secrets, including a flag. I approached the challenge using two methods: A manual enumeration process using the AWS CLI, and an automated path using PACU, an AWS exploitation tool.


Before diving in, here’s a quick overview of AWS SNS and API Gateway. If you’re looking for a deeper technical breakdown, the official AWS documentation is a great place to explore further.

What is Amazon SNS?

Amazon SNS (Simple Notification Service) is a managed publish/subscribe messaging service that allows applications to send messages to multiple subscribers. A publisher sends a message to a topic, which acts as a central channel. SNS then pushes that message to all subscribed endpoints without needing them to poll for updates. Subscribers can be other AWS services like Lambda and SQS, as well as other systems via HTTPS, email, SMS, or mobile push notifications. Typical use cases include sending system alerts, triggering automated workflows, or notifying users across different platforms all from a single message source.

What is an API Gateway?

Think of Amazon API Gateway as the front door to your application it accepts incoming requests, verifies them, and routes them to the right backend, whether that’s a Lambda function, a container, or an EC2 instance. You can build a REST API which is Ideal for HTTP-based services and serverless backends. API Gateway integrates with other AWS services, especially Lambda for serverless apps. When you create an API in API Gateway, it automatically generates a public URL for each endpoint. That URL looks like similar to this: “https://{api-id}.execute-api.{region}.amazonaws.com/{stage}/{resource}”. With this endpoint your front end or any client can call it to interact with your backend logic. You can define different HTTP methods (GET, POST, etc.) on each resource, set up authentication, or manage traffic.


Manual Enumeration (AWS CLI)

  • Used low-privileged IAM credentials to authenticate via AWS CLI.
  • Enumerated SNS topics using aws sns list-topics.
  • Retrieved SNS topic policy with get-topic-attributes; it allowed public Subscribe access.
  • Subscribed to the topic using aws sns subscribe --protocol email.
  • Received an API key via email from the SNS topic.

API Gateway Enumeration (AWS CLI)

  • Listed API Gateway IDs with aws apigateway get-rest-apis.
  • Identified the stage name using get-stages.
  • Discovered resource path /user-data using get-resources --embed methods.
  • The endpoint used a MOCK integration returning hardcoded secrets and a flag.
  • We also retrieved the flag using curl and the API key:

PACU Automation

  • Imported same low-privileged credentials into PACU.
  • Ran sns__enum to list SNS topics.
  • Used sns__subscribe to register email to the topic.
  • Received same API key via email.
  • Switched back to AWS CLI to enumerate API Gateway and extract secrets.

Takeaways

  • SNS topics with public subscription policies are dangerous.
  • API keys can be leaked through notifications and misconfigured debug messages.
  • Enumeration of API Gateway stages, resources, and paths reveals hidden endpoints.
  • PACU streamlines AWS enumeration and exploitation, but manual CLI gave deeper visibility.

Detailed steps:

SNS Secrets – (Manual – AWS CLI)

Initial Access

User Identity

Listing SNS topics

Getting the SNS attributes

Using the SNS topic ARN we are able to register our email to receive notifications

  • We received a debug message with an API

Enumerating the API key

  • API Key: 45a3da610dc64703b10e273a4db135bf
  • What we are looking for here is the ID and Name.

Getting the stage details.

  • This looks to be the PROD stage.

Getting the path of the API.

  • We need to call the resources to get details.
  • We see our path is “/user-data”
  • We also reveled the application details exposing user, email, password, and the FLAG.

Now we can build URL to get the flag using a Curl request.

  • We can build the URL with the API Key, API ID, Stage Name, and Path

SNS Secrets Enumeration – (using PACU)

We start with Initial Access

After importing keys for sns-user in Pacu we search for sns related modules.

  • We will start with sns__enum.

SNS Enumeration

  • We now have the arn for our SNS topic.

Subscribing to the SNS topic

  • We will us the sns__subscribe module in Pacu to register our email with this SNS toipic.

We received an API Gateway key after subscribing our email in the SNS topic.

Enumerating the API Gateway Key.

  • We continue this enumeration using the AWS CLI.
  • See the steps we took during the “Manual” enumeration process above.

List of commands:

Leave a Reply

Your email address will not be published. Required fields are marked *