More Info:
Port obfuscation is as an additional layer of defense against non-targeted attacks. In order to leverage this, your Amazon RDS databases instances should not use their default ports (MySQL/Aurora port 3306, SQL Server port 1433, PostgreSQL port 5432)Risk Level
LowAddress
SecurityCompliance Standards
PCIDSSRemediation
How to ensure RDS Database Instances do not use default ports.Using AWS Console
- Identify the Amazon RDS database instances for which you want to ensure that default ports are not used. (In the Cloudanix Console, navigate to “Misconfig” page and look for Affected Assets for “RDS Database Instances Should Not Use Default Ports” Policy.)
- Determine the default ports associated with the database engine you are using. Here are some common default ports:
- MySQL: 3306
- PostgreSQL: 5432
- Oracle Database: 1521
- SQL Server: 1433
- Open the AWS Management Console and navigate to the Amazon RDS service.
- Click on the name of the RDS instance for which you want to modify the port.
- In the instance details page, click on the “Configuration” tab.
- Under the “Connectivity & security” section, locate the “Endpoint & port” information.
- Click on the “Modify” button next to the “Endpoint & port” information.
- In the “Modify DB instance” window, locate the “Port” field.
- Change the value in the “Port” field to a non-default port that you want to use for the RDS instance. Ensure that the new port is not already used by any other service or application.
- Click on the “Apply immediately” checkbox to apply the changes immediately. If you don’t select this option, the changes will be applied during the next maintenance window for the RDS instance.
- Click on the “Modify DB instance” button to save the changes and modify the port.
- Repeat these steps for each Amazon RDS database instance that you want to ensure is not using the default port.
Triage and Remediation
- Remediation
Remediation
Using Console
Using Console
Below are the console-based steps to move an RDS instance off its default port (e.g., 3306 for MySQL, 5432 for PostgreSQL, 1433 for SQL Server, 1521 for Oracle):
1. Plan the New Port
- Choose a non-default, unused port in the allowed range for your engine:
- MySQL/MariaDB/PostgreSQL: 1150–65535 (except ports reserved by AWS)
- SQL Server: 1150–65535
- Oracle: 1150–65535
- Ensure your network/security team approves the port.
2. Update the RDS Instance Port
- Sign in to the AWS Management Console.
- Open RDS service.
- In the left menu, select Databases.
- Click the DB instance you want to change.
- Click Modify (top-right).
- In the Connectivity or Additional configuration section (varies by engine), find Port.
- Change it from the default (e.g., 3306/5432/1433/1521) to your chosen custom port.
- At the bottom:
- Under Scheduling of modifications, choose:
- Apply immediately (causes a brief downtime)
or - Apply during the next scheduled maintenance window (less disruptive but delayed).
- Apply immediately (causes a brief downtime)
- Under Scheduling of modifications, choose:
- Click Continue, review changes, then click Modify DB instance.
3. Update the Security Group Rules
- Still in the RDS instance details page, in the Connectivity & security tab, find Security group rules.
- Click the linked VPC security group name to open it in the EC2 console.
- On the Inbound rules tab:
- Edit the rule that allowed the old port (e.g., 3306).
- Either:
- Change the Port range to the new port, or
- Add a new rule for the new port and remove the old port rule afterward.
- Keep the same Source (CIDR, security group, etc.) so the same clients can still connect.
- Save the inbound rule changes.
4. Update Application Configurations
- Find all applications, scripts, and tools that connect to this RDS instance.
- Update their DB connection strings:
- Change the
portvalue to the new port. - Hostname (endpoint) stays the same; only the port changes (unless you also changed anything else).
- Change the
- Redeploy or restart applications if needed so they use the new configuration.
5. Validate Connectivity
- Use a DB client (e.g.,
psql,mysql, SQL Server Management Studio, etc.) and specify the new port:- Example (MySQL):
- Example (MySQL):
- Confirm that applications can successfully connect and operate.
- Once confirmed, verify that the old port is:
- No longer open in security groups.
- No longer referenced in any configs or scripts.
6. (Optional) Enforce via Baseline/Standards
- Document the required non-default port in your internal standards.
- Use AWS Config or a security tool to:
- Detect RDS instances using default ports.
- Alert or block non-compliant deployments.
Using CLI
Using CLI
Below are concise, CLI-focused steps to move RDS off default ports.
(Optional) Filter by a specific default port, e.g. MySQL’s 3306:
For each security group, add an inbound rule for the new port (example: 13306/TCP, CIDR 10.0.0.0/16):After cutover, you can remove the old-port rule.
If you prefer to apply during the next maintenance window, omit Confirm new port:
Repeat for all instances in the cluster.
Verify via:
Repeat for all affected SGs.
1. Identify RDS instances using default ports
Common default ports (AWS RDS engines):- MySQL / MariaDB / Aurora MySQL:
3306 - PostgreSQL / Aurora PostgreSQL:
5432 - Oracle:
1521 - SQL Server:
1433
2. Choose a non-default port
Pick a port that:- Is not in use by other services in your environment.
- Is allowed by your organization’s security policy.
Example:
13306for MySQL,15432for PostgreSQL, etc.
3. Update security groups before changing the port
Find the security groups used by the instance:4. Change the RDS instance port
Changing--db-port causes a reboot/outage. Schedule a maintenance window.--apply-immediately.Check status until it’s available:5. For Aurora (cluster) setups
For Aurora, you typically change each instance:Verify via:
6. Update application configurations
Update application connection strings to use the new port:- JDBC:
jdbc:mysql://host:13306/dbname - psql:
psql -h host -p 15432 -d dbname -U user - Any connection libraries: adjust
portfield.
7. Remove old port from security groups
Once apps successfully use the new port, remove the old-port inbound rules:Using Python
Using Python
Below is one way to do this programmatically using Python and boto3:You also must pick non-default target ports (coordinate with your app & security teams first):
1. Decide which ports are “default” and what to change them to
Common default ports (per engine):Adjust the target ports to your standards and ensure corresponding security group rules and client configs will be updated.
2. Python script to find and remediate RDS instances on default ports
3. Operational steps to follow
- Test in non-production first.
- Ensure security groups allow the new port:
- Add inbound rules for the new port before changing RDS.
- Optionally remove old port after app migration.
- Update application connection strings:
- Most drivers accept
host:portor a separateportparameter. - Coordinate a maintenance window if
ApplyImmediately=Falseis used or if app restart is required.
- Most drivers accept
- Monitor after change:
- Check RDS instance status until it becomes
available. - Test app connectivity and logs.
- Check RDS instance status until it becomes
- Only target specific tags/instances.
- Write changes to a “dry-run” report instead of modifying.
Using Terraform
Using Terraform
port on an existing aws_db_instance forces replacement of the database instance, which causes downtime and requires updating all clients to use the new port.For verification, terraform plan should show the port argument on the aws_db_instance (and matching security group rules) changing from the default (for example, ~ port: "5432" => "5433") and planning to replace the instance if it already exists.
