CVE-2021-31671

7.5 HIGH

📋 TL;DR

CVE-2021-31671 is an information disclosure vulnerability in pgsync that can expose sensitive database connection parameters. When using --schema-first or --schema-only options, SSL/TLS connection parameters may be lost, potentially transmitting data unencrypted. This affects all users of pgsync versions before 0.6.7 who sync PostgreSQL databases with sensitive data.

💻 Affected Systems

Products:
  • pgsync
Versions: All versions before 0.6.7
Operating Systems: All operating systems running pgsync
Default Config Vulnerable: ⚠️ Yes
Notes: Only affects users who use --schema-first or --schema-only options during database synchronization.

📦 What is this software?

⚠️ Risk & Real-World Impact

🔴

Worst Case

Database credentials and sensitive data transmitted in cleartext over network, leading to full database compromise and data breach.

🟠

Likely Case

Database synchronization occurs without SSL/TLS encryption, exposing data to network sniffing and man-in-the-middle attacks.

🟢

If Mitigated

If network segmentation and encryption are properly implemented, risk is limited to potential credential exposure.

🌐 Internet-Facing: HIGH - If pgsync is used to sync databases across internet connections, all data could be intercepted.
🏢 Internal Only: MEDIUM - Even internal networks can have malicious actors or compromised systems that could intercept unencrypted traffic.

🎯 Exploit Status

Public PoC: ✅ No
Weaponized: LIKELY
Unauthenticated Exploit: ✅ No
Complexity: LOW

Exploitation requires network access to intercept traffic between pgsync and PostgreSQL database. No authentication bypass needed as it's a configuration mishandling issue.

🛠️ Fix & Mitigation

✅ Official Fix

Patch Version: 0.6.7 and later

Vendor Advisory: https://github.com/ankane/pgsync/issues/121

Restart Required: No

Instructions:

1. Update pgsync to version 0.6.7 or later using 'gem update pgsync'. 2. Verify the update with 'pgsync --version'. 3. Test synchronization with --schema-first or --schema-only options to ensure SSL/TLS is maintained.

🔧 Temporary Workarounds

Avoid vulnerable options

all

Do not use --schema-first or --schema-only options until patched

# Use standard sync without vulnerable options
pgsync --from production --to staging

Force SSL in PostgreSQL connection

linux

Configure PostgreSQL to require SSL connections regardless of client settings

# In postgresql.conf:
ssl = on
ssl_cert_file = 'server.crt'
ssl_key_file = 'server.key'
# In pg_hba.conf:
hostssl all all 0.0.0.0/0 md5

🧯 If You Can't Patch

  • Use VPN or encrypted tunnel for all database synchronization traffic
  • Implement network segmentation and monitor for unencrypted database traffic

🔍 How to Verify

Check if Vulnerable:

Run 'pgsync --version' and check if version is below 0.6.7. Also check if you use --schema-first or --schema-only options in your sync commands.

Check Version:

pgsync --version

Verify Fix Applied:

After updating, run 'pgsync --version' to confirm version 0.6.7+. Test a sync with --schema-first option while monitoring network traffic to ensure SSL/TLS is used.

📡 Detection & Monitoring

Log Indicators:

  • Database connection attempts without SSL/TLS
  • pgsync errors related to SSL configuration
  • Unencrypted PostgreSQL protocol traffic in logs

Network Indicators:

  • PostgreSQL traffic on port 5432 without TLS encryption
  • Cleartext database credentials in network captures

SIEM Query:

source="pgsync" AND ("--schema-first" OR "--schema-only") AND version<"0.6.7"

🔗 References

📤 Share & Export