Arp Spoofing in Postgresql
How Arp Spoofing Manifests in Postgresql
Arp Spoofing in Postgresql environments typically occurs when an attacker manipulates the Address Resolution Protocol (ARP) table to intercept or redirect network traffic between a client and the database server. In Postgresql deployments, this often targets the default port 5432, allowing attackers to capture authentication credentials, query data, or inject malicious commands.
The attack vector is particularly dangerous because Postgresql's wire protocol is unencrypted by default. When an attacker successfully performs ARP spoofing on a network segment, they can intercept the clear-text PostgreSQL connection, capturing the username and password sent during the authentication phase. This is especially problematic in development environments or shared hosting scenarios where network isolation is weak.
Common Postgresql-specific attack patterns include:
- Capturing MD5-authenticated passwords, which can be cracked offline since the protocol sends the MD5 hash of the password concatenated with the username
- Intercepting COPY commands to extract bulk data during import/export operations
- Modifying query results in transit to manipulate application behavior
- Capturing prepared statement parameters to extract sensitive data
The attack typically begins with ARP poisoning using tools like arpspoof or ettercap, redirecting traffic through the attacker's machine. Once positioned as a man-in-the-middle, the attacker can use tcpdump or wireshark to capture the PostgreSQL protocol traffic, which follows a specific binary format that includes authentication messages, query execution, and result sets.
Postgresql-Specific Detection
Detecting ARP spoofing in Postgresql environments requires monitoring both network and database layers. At the network level, watch for duplicate MAC addresses appearing for your PostgreSQL server's IP, unexpected ARP replies, or sudden changes in network latency that might indicate traffic interception.
For Postgresql-specific indicators, monitor these patterns:
SELECT datname, usename, client_addr, backend_start, state
FROM pg_stat_activity
WHERE state = 'active' AND client_addr != expected_ip;
This query helps identify unexpected client connections. Additionally, enable log_connections and log_disconnections in postgresql.conf to track connection patterns that might reveal MITM attacks.
middleBrick's API security scanner includes network protocol analysis that can detect ARP spoofing indicators when scanning Postgresql endpoints. The scanner tests for:
- Unencrypted PostgreSQL connections on port 5432
- Authentication mechanisms that transmit credentials in recoverable formats
- Missing TLS/SSL configuration that would otherwise protect against traffic interception
- Weak or default authentication settings that make credential capture more valuable
The scanner provides a security risk score (A–F) with specific findings about unencrypted connections and authentication weaknesses that ARP spoofing could exploit. For Postgresql endpoints, middleBrick tests the runtime behavior of the database connection, not just the API specification, ensuring findings reflect actual security posture.
Network monitoring tools can also help detect ARP spoofing by watching for ARP table inconsistencies or using static ARP entries for critical servers. Tools like arpwatch can alert on MAC address changes for known IP addresses.
Postgresql-Specific Remediation
Securing Postgresql against ARP spoofing requires defense in depth. The primary mitigation is encrypting all database connections using TLS/SSL. In postgresql.conf, configure:
# Enable SSL
ssl = on
ssl_cert_file = 'server.crt'
ssl_key_file = 'server.key'
ssl_ca_file = 'root.crt'
Require SSL connections in pg_hba.conf:
# TYPE DATABASE USER ADDRESS METHOD
hostssl all all 0.0.0.0/0 md5
hostnossl all all 127.0.0.1/32 md5
This configuration ensures all external connections use SSL, making ARP spoofing ineffective since the attacker cannot decrypt the traffic without the server's private key.
For applications connecting to Postgresql, use SSL parameters in connection strings:
const { Client } = require('pg');
const client = new Client({
host: 'db.example.com',
user: 'app_user',
password: process.env.DB_PASSWORD,
database: 'app_db',
ssl: {
rejectUnauthorized: true,
Additionally, implement certificate validation to prevent man-in-the-middle attacks even if ARP spoofing succeeds. Store the database certificate fingerprint in your application configuration and verify it matches the server's certificate.
Network-level defenses complement database encryption:
- Use static ARP entries for database servers on critical infrastructure
- Implement port security on switches to limit MAC address learning
- Use VLANs to isolate database traffic from general network segments
- Deploy 802.1X authentication for network access control
For highly sensitive Postgresql deployments, consider using IPsec in transport mode to encrypt all database traffic at the network layer, providing protection even for applications that cannot use SSL connections.