Dangling Dns in Dynamodb
How Dangling DNS Manifests in DynamoDB
Dangling DNS in a DynamoDB context occurs when a DNS record (like a CNAME or A record) that previously pointed to a legitimate DynamoDB-related resource is deleted or reconfigured, but the DNS record itself remains in your domain's zone. An attacker can then create a new resource (e.g., an EC2 instance, S3 bucket, or even a malicious DynamoDB table with a similar name) and register the orphaned DNS name to point to it. For APIs that interact with DynamoDB, this often manifests through custom endpoints or VPC endpoint configurations.
DynamoDB-Specific Attack Patterns:
- Custom DynamoDB Endpoints: Applications sometimes use a custom domain (e.g.,
api.example.com) that resolves to a DynamoDB table's regional endpoint (e.g.,dynamodb.us-east-1.amazonaws.com) via a CNAME. If the CNAME record is removed from your DNS zone but the application's configuration still references it, an attacker who registers that subdomain can intercept traffic intended for DynamoDB. - DynamoDB Accelerator (DAX) Clusters: DAX clusters have a unique DNS endpoint (e.g.,
mycluster.dax-clusters.us-east-1.amazonaws.com). If a DAX cluster is deleted but the DNS record persists in a parent domain's CNAME (e.g., a corporatedax.example.comCNAME pointing to the DAX endpoint), an attacker can create a new DAX cluster with a similar name and hijack the CNAME to route traffic to their cluster. - VPC Interface Endpoints: AWS PrivateLink creates interface VPC endpoints for DynamoDB with DNS names like
dynamodb.us-east-1.vpce.amazonaws.com. Organizations sometimes create private DNS zones to override these with custom names (e.g.,dynamodb.internal). If the VPC endpoint is deleted but the private DNS record remains, an attacker with access to create VPC endpoints in your account could recreate an endpoint and capture traffic via the dangling DNS name. - Application-Layer Misconfigurations: An API might construct DynamoDB table names or partition keys based on user input and use DNS to resolve service endpoints. If the API uses a hardcoded or configurable base domain that becomes dangling, an attacker could manipulate DNS to redirect DynamoDB operations to a malicious endpoint, leading to data exfiltration or corruption.
Real Code Example (Vulnerable):
// Node.js (AWS SDK v3) - VULNERABLE: Hardcoded custom endpoint that could become dangling
const { DynamoDBClient } = require("@aws-sdk/client-dynamodb");
const client = new DynamoDBClient({
region: "us-east-1",
endpoint: "https://dynamodb.custom-domain.example.com" // If this CNAME is dangling, attacker controls it
});
// Subsequent operations (PutItem, GetItem) route to attacker's endpoint
await client.send(new PutItemCommand({
TableName: "users",
Item: { userId: { S: "123" }, data: { S: "secret" } }
}));DynamoDB-Specific Detection
Detecting dangling DNS specific to DynamoDB requires examining both DNS configurations and API runtime behavior. middleBrick's scanning approach focuses on the unauthenticated attack surface, testing how your API resolves and interacts with DynamoDB endpoints.
- DNS Resolution Analysis: The scanner queries DNS records for any custom domains used by your API's DynamoDB interactions (e.g., endpoints in configuration, redirects, or links in responses). It checks if these records resolve to IPs outside of AWS's official ranges or to recently registered domains, which are indicators of hijacking.
- Endpoint Validation: middleBrick sends test requests to the API's DynamoDB-related endpoints (including any custom hostnames) and inspects TLS certificates, HTTP headers, and response bodies. A certificate not issued to an AWS service, or an unexpected HTTP server banner (e.g., nginx instead of AWS), suggests the DNS points to a non-AWS server.
- SSRF & Data Exposure Correlation: Dangling DNS often results in Server-Side Request Forgery (SSRF) vulnerabilities. middleBrick's SSRF check (one of its 12 parallel tests) will attempt to make the API fetch a unique URL from a controlled domain. If the API's DynamoDB requests are routed through the dangling DNS, the scanner may see the unique token in external logs, confirming redirection.
- OpenAPI/Spec Analysis: If your API provides an OpenAPI spec, middleBrick resolves
$refs to find anyx-amazon-apigateway-integrationor customserversentries pointing to DynamoDB endpoints. It then cross-references these with runtime DNS findings.
Using middleBrick for Detection:
Scan your API endpoint with middleBrick. The report will flag dangling DNS issues under categories like SSRF or Data Exposure. For example, a finding might read: "API resolves DynamoDB endpoint to non-AWS IP 192.0.2.1. Custom domain 'dynamodb.api.example.com' CNAME points to abandoned resource." The CLI provides machine-readable output:
middlebrick scan https://api.example.com/v1/users --format json
# Output includes: "categories": { "ssrf": { "risk": 9, "findings": [{"title": "Dangling DNS for DynamoDB endpoint", ...}] } }Pro plan users can set up continuous monitoring to alert on new dangling DNS issues via Slack or Teams.
DynamoDB-Specific Remediation
Remediation focuses on eliminating single points of failure in DNS and enforcing strict endpoint validation. Use DynamoDB's native AWS features to avoid custom DNS where possible.
- Use AWS SDK Default Endpoints: Never hardcode custom DynamoDB endpoints unless absolutely necessary. The SDK automatically uses the correct regional endpoint. If you must use a custom domain (e.g., for VPC endpoints), ensure it's managed within AWS (like a Private DNS zone) and tightly controlled.
- Implement VPC Interface Endpoints with Private DNS: For private API-to-DynamoDB communication, create a VPC interface endpoint for DynamoDB and enable Private DNS. This creates a private, AWS-managed DNS entry (e.g.,
dynamodb.us-east-1.amazonaws.com) that resolves to the endpoint within your VPC. Avoid creating custom DNS names that could become dangling. - Validate Endpoints at Runtime: In your API code, verify that the resolved DynamoDB endpoint belongs to AWS. You can check the hostname against a list of valid AWS service domains or ensure the TLS certificate's subject matches
*.amazonaws.com. - IAM Conditions for DynamoDB: Use IAM policy conditions to restrict DynamoDB operations to specific endpoints or VPC endpoints. For example, require requests to come only from your VPC endpoint ID.
- DNS Hygiene: regularly audit DNS zones for CNAMEs pointing to AWS resources that may have been deleted. Use AWS Config rule
dynamodb-table-point-in-time-recovery-enabledor custom scripts to track resource lifecycle and DNS dependencies.
Fixed Code Example (Node.js AWS SDK v3):
// SECURE: Use default endpoint, or validate custom endpoint
const { DynamoDBClient } = require("@aws-sdk/client-dynamodb");
const dns = require('dns').promises;
async function createSecureClient(customEndpoint) {
// If a custom endpoint is provided, validate it
if (customEndpoint) {
const hostname = new URL(customEndpoint).hostname;
const records = await dns.resolveCname(hostname);
// Ensure CNAME chain eventually points to an AWS domain
const isAwsEndpoint = records.some(r => r.endsWith('.amazonaws.com'));
if (!isAwsEndpoint) {
throw new Error(`Invalid DynamoDB endpoint: ${hostname}`);
}
}
return new DynamoDBClient({
region: process.env.AWS_REGION,
endpoint: customEndpoint // Only set if validated
});
}
// Usage
const client = await createSecureClient(process.env.DYNAMODB_ENDPOINT);Infrastructure-as-Code Fix (AWS CloudFormation):
Resources:
DynamoDBVpcEndpoint:
Type: AWS::EC2::VPCEndpoint
Properties:
ServiceName: !Sub "com.amazonaws.${AWS::Region}.dynamodb"
VpcId: !Ref MyVPC
PrivateDnsEnabled: true # Critical: AWS manages private DNS
SecurityGroupIds:
- !Ref EndpointSecurityGroupBy using Private DNS, you avoid creating custom DNS names that could become dangling. The VPC endpoint's DNS name is managed by AWS and tied to the endpoint's lifecycle.