SlideShare a Scribd company logo
Securing PostgreSQL From External Attack
BRUCE MOMJIAN
Database systems are rich with attack vectors to exploit. This presentation explores the
many potential PostgreSQL external vulnerabilities and shows how they can be secured.
Includes concepts from Magnus Hagander
https://momjian.us/presentations Creative Commons Attribution License
Last updated: August, 2021
1 / 32
Attack Vectors
https://www.flickr.com/photos/twalmsley/
2 / 32
External Attack Vectors
• ’Trust’ security
• Passwords / authentication theft
• Network snooping
• Network pass-through spoofing
• Server / backup theft
• Administrator access
3 / 32
Internal Attack Vectors (Not Covered)
• Database object permissions
• SQL injection attacks
• Application vulnerability
• Operating system compromise
4 / 32
Authentication Security
https://www.flickr.com/photos/brookward/
5 / 32
Avoid “Trust” Security in pg_hba.conf
# TYPE DATABASE USER CIDR-ADDRESS METHOD
# "local" is for Unix domain socket connections only
local all all trust
# IPv4 local connections:
host all all 127.0.0.1/32 trust
# IPv6 local connections:
host all all ::1/128 trust
Solution: Use the initdb -A flag, i.e., you don’t want to see this:
WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the -A option the
next time you run initdb.
6 / 32
Password Snooping
Vulnerable to snooping
Client
Database
PostgreSQL
Database
Server
md5(password+username)
md5(password+username)
md5(password+username)
md5(password+username)
Using ’username’ in the MD5
string prevents the same password
used by different users from
appearing the same. It also adds
some randomness to the md5
checksums.
Connection Request
Need Password
Password Sent
7 / 32
MD5 Authentication Prevents Password Snooping
Client
Database
PostgreSQL
Database
Server
md5(password+username)
md5(password+username)
md5(password+username)
md5(password+username)
Connection request
Need md5, sent random salt
md5(md5(password+username) + salt)
8 / 32
MD5 Authentication Prevents Password Replay
X
OK
Client
Database
Client
Database
Malicious
PostgreSQL
Database
Server
md5(password+username)
md5(password+username)
md5(password+username)
md5(password+username)
Connection request
Need md5, sent random salt0
md5(md5(password+username) + salt0)
Connection request
Need md5, sent random salt1
md5(md5(password+username) + salt0)
replay
salt is a random four-byte integer so millions of connection attempts might allow the
reuse of an old authentication reply.
9 / 32
SCRAM Authentication
scram-sha-256, available in Postgres 10, eliminates less-secure MD5, and avoids the risk
of duplicate salt values being replayed. SCRAM with channel binding, available in
Postgres 13, allows authentication, similar to certificate authentication. scram-sha-256 is
the default in Postgres 14.
10 / 32
SCRAM-SHA-256 Authentication
Client
Database
PostgreSQL
Database
Server
sha256(password+salt)
sha256(password+salt)
sha256(password+salt)
sha256(password+salt)
Connection request
Client nonce, server nonce, salt
Client nonce, server nonce, client proof
Need scram−sha−256
Username, client nonce
https://en.wikipedia.org/wiki/Salted_Challenge_Response_Authentication_Mechanism
11 / 32
Password Attacks
• Weak passwords
• Reuse of old passwords
• Brute-force password attacks
None of these vulnerabilities is prevented by Postgres directly, but external
authentication methods, like LDAP
, PAM, and SSPI, can prevent them. Some authentication
methods are difficult to use with connection pooling.
12 / 32
Queries and Data Still Vulnerable to Network Snooping
Queries and data vulnerable to snooping
Client
Database
PostgreSQL
Database
Server
Barr Bearings | $10230 | James Akel
SELECT * FROM customer;
Password changes are also vulnerable to snooping.
13 / 32
SSL Prevents Snooping By Encrypting Queries and Data
Queries and data encrypted by SSL
Client
Database
PostgreSQL
Database
Server
AES256(Barr Bearings | $10230 | James Akel)
AES256(SELECT * FROM customer);
14 / 32
Preventing Spoofing
https://www.flickr.com/photos/tomhickmore/
15 / 32
Localhost Spoofing While the Database Server Is Down
X
Client
Database
Fake PostgreSQL
Database
Server
use with the real server
Records passwords for later
Uses a fake socket or binds to
and 5432 is not a root−only port.
port 5432 while the real server
is down. (/tmp is world−writable
libpq’s "requirepeer" helps here.)
Connection Request
Need Plain Password
Password Sent
The server controls the choice of ’password’ instead of ’md5’.
16 / 32
Network Spoofing
X
Client
Database
Fake PostgreSQL
Database
Server
use with the real server
Records passwords for later
Without SSL ’root’ certificates
there is no way to know if the
server you are connecting
to is a legitimate server.
Connection Request
Need Plain Password
Password Sent
17 / 32
Network Spoofing Pass-Through
OK
Client
Database Database
Server
PostgreSQL
Fake PostgreSQL
Database
Server
Records passwords for later
use with the real server. It
can also capture queries,
queries.
data, and inject its own
Without SSL ’root’ certificates
there is no way to know if the
server you are connecting
to is a legitimate server.
Query
Result
Connection Request
Need Plain Password
Password Sent
Query
Result
18 / 32
SSL ’Prefer’ Is Not Secure
OK
Client
Database Database
Server
PostgreSQL
Fake PostgreSQL
Database
Server
Records passwords for later
use with the real server. It
can also capture queries,
queries.
data, and inject its own
Without SSL ’root’ certificates
there is no way to know if the
server you are connecting
to is a legitimate server.
Query
Result
SSL or
Non−SSL
No SSL
Prefer SSL
Non−SSL
Query
Result
19 / 32
SSL ’Require’ Is Not Secure From Spoofing
OK
Client
Database Database
Server
PostgreSQL
Fake PostgreSQL
Database
Server
Records passwords for later
use with the real server. It
can also capture queries,
queries.
data, and inject its own
Without SSL ’root’ certificates
there is no way to know if the
server you are connecting
to is a legitimate server.
Query
Result
SSL or
Non−SSL
Require SSL
OK SSL
SSL
Query
Result
20 / 32
SSL ’Verify-CA’ Is Secure From Spoofing
X
root.crt
server.crt
Fake PostgreSQL
Database
Server
Client
Database Database
Server
PostgreSQL
Invalid certificate
SSL verify−ca
(no CA signature)
21 / 32
Channel Binding
is hashed with the password hash to prove the TLS peer knows the password hash.
Certificates are sent to peers as part of the TLS handshake. Later the certificate hash
This is tls−server−end−point channel binding.
Client
Database
PostgreSQL
Database
Server
sha256(password+salt)
sha256(password+salt)
sha256(password+salt)
sha256(password+salt)
Connection request, need SSL
Client nonce, server nonce, salt
Client nonce, server nonce, client proof
Server proof
Channel binding req., username, client nonce
Need scram−sha−256
server.crt
22 / 32
SSL Certificates for Authentication
root.crt
server.crt
Client
Database Database
Server
PostgreSQL
Request for SSL certificate
SSL certificate with CN
23 / 32
Data Encryption To Avoid Data Theft
https://www.flickr.com/photos/debarshiray/
24 / 32
Disk Volume Encryption
This helps prevent stolen storage devices from being read, and helps with secure media
destruction. https://www.flickr.com/photos/icebrkr/
25 / 32
Column Encryption
id | name | credit_card_number
--------+--------------------+------------------------------
428914 | Piller Plaster Co. | xc30d04070302254dc045353f28
; 456cd241013e2d421e198f3320e8
; 41a7e4f751ebd9e2938cb6932390
; 5c339c02b5a8580663d6249eb24f
; 192e226c1647dc02536eb6a79a65
; 3f3ed455ffc5726ca2b67430d5
Encryption methods are decryptable (e.g., AES), while hashes are one-way (e.g., MD5).
A one-way hash is best for data like passwords that only need to be checked for a match,
rather than decrypted.
26 / 32
Where to Store the Key? On the Server
Decrypted data
key
Client
Database
PostgreSQL
Database
Server
Barr Bearings | $10230 | James Akel
SELECT * FROM customer;
27 / 32
Store the Key on an Intermediate Server
key
Decrypted Encrypted
SELECT SELECT
Client
Database
Cryptographic
Server
PostgreSQL
Database
Server
Barr Bearings V#ja20a
28 / 32
Store the Key on the Client and Encrypt/Decrypt on the Server
key
Decrypted data
Client
Database
PostgreSQL
Database
Server
Barr Bearings | $10230 | James Akel
SELECT decrypt(col, key) FROM customer;
29 / 32
Encrypt/Decrypt on the Client
key
Encrypted data
Client
Database
PostgreSQL
Database
Server
V#aei32ok3
SELECT * FROM customer;
This prevents server administrators from viewing sensitive data.
30 / 32
Store the Key on a Client Hardware Token
key Encrypted data
Client
Database
PostgreSQL
Database
Server
V#aei32ok3
SELECT * FROM customer;
This prevents problems caused by client hardware theft.
31 / 32
Conclusion
https://momjian.us/presentations https://www.flickr.com/photos/stevensnodgrass/
32 / 32

More Related Content

What's hot

BlueHat v17 || Where, how, and why is SSL traffic on mobile getting intercept...
BlueHat v17 || Where, how, and why is SSL traffic on mobile getting intercept...BlueHat v17 || Where, how, and why is SSL traffic on mobile getting intercept...
BlueHat v17 || Where, how, and why is SSL traffic on mobile getting intercept...
BlueHat Security Conference
 
Proper passwordhashing
Proper passwordhashingProper passwordhashing
Proper passwordhashing
fangjiafu
 
Security Features in MongoDB 2.4
Security Features in MongoDB 2.4Security Features in MongoDB 2.4
Security Features in MongoDB 2.4
MongoDB
 

What's hot (20)

Kieon secure passwords theory and practice 2011
Kieon secure passwords theory and practice 2011Kieon secure passwords theory and practice 2011
Kieon secure passwords theory and practice 2011
 
Understanding Active Directory Enumeration
Understanding Active Directory EnumerationUnderstanding Active Directory Enumeration
Understanding Active Directory Enumeration
 
BlueHat v17 || Where, how, and why is SSL traffic on mobile getting intercept...
BlueHat v17 || Where, how, and why is SSL traffic on mobile getting intercept...BlueHat v17 || Where, how, and why is SSL traffic on mobile getting intercept...
BlueHat v17 || Where, how, and why is SSL traffic on mobile getting intercept...
 
URL to HTML
URL to HTMLURL to HTML
URL to HTML
 
Intrigue Core: Scaling Assessment Automation
Intrigue Core: Scaling Assessment AutomationIntrigue Core: Scaling Assessment Automation
Intrigue Core: Scaling Assessment Automation
 
Rooted2020 stefano maccaglia--_the_enemy_of_my_enemy
Rooted2020 stefano maccaglia--_the_enemy_of_my_enemyRooted2020 stefano maccaglia--_the_enemy_of_my_enemy
Rooted2020 stefano maccaglia--_the_enemy_of_my_enemy
 
Secure Coding for NodeJS
Secure Coding for NodeJSSecure Coding for NodeJS
Secure Coding for NodeJS
 
Understanding Windows Lateral Movements
Understanding Windows Lateral MovementsUnderstanding Windows Lateral Movements
Understanding Windows Lateral Movements
 
Proper passwordhashing
Proper passwordhashingProper passwordhashing
Proper passwordhashing
 
Waf.js: How to Protect Web Applications using JavaScript
Waf.js: How to Protect Web Applications using JavaScriptWaf.js: How to Protect Web Applications using JavaScript
Waf.js: How to Protect Web Applications using JavaScript
 
Iam r31 a (2)
Iam r31 a (2)Iam r31 a (2)
Iam r31 a (2)
 
Security Features in MongoDB 2.4
Security Features in MongoDB 2.4Security Features in MongoDB 2.4
Security Features in MongoDB 2.4
 
The DNS Tunneling Blindspot
The DNS Tunneling BlindspotThe DNS Tunneling Blindspot
The DNS Tunneling Blindspot
 
[DevDay2018] Hacking for fun and profit - By: Dennis Stötzel, Head of Securit...
[DevDay2018] Hacking for fun and profit - By: Dennis Stötzel, Head of Securit...[DevDay2018] Hacking for fun and profit - By: Dennis Stötzel, Head of Securit...
[DevDay2018] Hacking for fun and profit - By: Dennis Stötzel, Head of Securit...
 
MongoDB Security Introduction - Presentation
MongoDB Security Introduction - PresentationMongoDB Security Introduction - Presentation
MongoDB Security Introduction - Presentation
 
Stu r33 b (2)
Stu r33 b (2)Stu r33 b (2)
Stu r33 b (2)
 
Présentation et démo ELK/SIEM/Wazuh
Présentation et démo ELK/SIEM/Wazuh Présentation et démo ELK/SIEM/Wazuh
Présentation et démo ELK/SIEM/Wazuh
 
Pentest Expectations
Pentest ExpectationsPentest Expectations
Pentest Expectations
 
Webinar: Securing your data - Mitigating the risks with MongoDB
Webinar: Securing your data - Mitigating the risks with MongoDBWebinar: Securing your data - Mitigating the risks with MongoDB
Webinar: Securing your data - Mitigating the risks with MongoDB
 
My Bro The ELK
My Bro The ELKMy Bro The ELK
My Bro The ELK
 

Similar to Securing PostgreSQL from External Attack

Andrews whitakrer lecture18-security.ppt
Andrews whitakrer lecture18-security.pptAndrews whitakrer lecture18-security.ppt
Andrews whitakrer lecture18-security.ppt
SilverGold16
 

Similar to Securing PostgreSQL from External Attack (20)

Training Slides: 302 - Securing Your Cluster With SSL
Training Slides: 302 - Securing Your Cluster With SSLTraining Slides: 302 - Securing Your Cluster With SSL
Training Slides: 302 - Securing Your Cluster With SSL
 
Anatomy of a Cloud Hack
Anatomy of a Cloud HackAnatomy of a Cloud Hack
Anatomy of a Cloud Hack
 
How to Bulletproof Your Scylla Deployment
How to Bulletproof Your Scylla DeploymentHow to Bulletproof Your Scylla Deployment
How to Bulletproof Your Scylla Deployment
 
Basics of ssl
Basics of sslBasics of ssl
Basics of ssl
 
Pulsar Summit Asia - Running a secure pulsar cluster
Pulsar Summit Asia -  Running a secure pulsar clusterPulsar Summit Asia -  Running a secure pulsar cluster
Pulsar Summit Asia - Running a secure pulsar cluster
 
Improving password-based authentication
Improving password-based authenticationImproving password-based authentication
Improving password-based authentication
 
How to Secure Your Scylla Deployment: Authorization, Encryption, LDAP Authent...
How to Secure Your Scylla Deployment: Authorization, Encryption, LDAP Authent...How to Secure Your Scylla Deployment: Authorization, Encryption, LDAP Authent...
How to Secure Your Scylla Deployment: Authorization, Encryption, LDAP Authent...
 
SSL Checklist for Pentesters (BSides MCR 2014)
SSL Checklist for Pentesters (BSides MCR 2014)SSL Checklist for Pentesters (BSides MCR 2014)
SSL Checklist for Pentesters (BSides MCR 2014)
 
Securing Your MongoDB Deployment
Securing Your MongoDB DeploymentSecuring Your MongoDB Deployment
Securing Your MongoDB Deployment
 
Securing data and preventing data breaches
Securing data and preventing data breachesSecuring data and preventing data breaches
Securing data and preventing data breaches
 
Securing data and preventing data breaches
Securing data and preventing data breachesSecuring data and preventing data breaches
Securing data and preventing data breaches
 
SSL overview
SSL overviewSSL overview
SSL overview
 
1000 to 0
1000 to 01000 to 0
1000 to 0
 
ION Santiago - DNSSEC and DANE Based Security for TLS
ION Santiago - DNSSEC and DANE Based Security for TLSION Santiago - DNSSEC and DANE Based Security for TLS
ION Santiago - DNSSEC and DANE Based Security for TLS
 
DockerCon Live 2020 - Securing Your Containerized Application with NGINX
DockerCon Live 2020 - Securing Your Containerized Application with NGINXDockerCon Live 2020 - Securing Your Containerized Application with NGINX
DockerCon Live 2020 - Securing Your Containerized Application with NGINX
 
Ciphers
CiphersCiphers
Ciphers
 
Securing Your APIs against the Recent Vulnerabilities in SSLv2/SSLv3
Securing Your APIs against the Recent Vulnerabilities in SSLv2/SSLv3 Securing Your APIs against the Recent Vulnerabilities in SSLv2/SSLv3
Securing Your APIs against the Recent Vulnerabilities in SSLv2/SSLv3
 
Database Security Threats - MariaDB Security Best Practices
Database Security Threats - MariaDB Security Best PracticesDatabase Security Threats - MariaDB Security Best Practices
Database Security Threats - MariaDB Security Best Practices
 
RedisConf 2016 - Redis usage and ecosystem
RedisConf 2016 - Redis usage and ecosystemRedisConf 2016 - Redis usage and ecosystem
RedisConf 2016 - Redis usage and ecosystem
 
Andrews whitakrer lecture18-security.ppt
Andrews whitakrer lecture18-security.pptAndrews whitakrer lecture18-security.ppt
Andrews whitakrer lecture18-security.ppt
 

More from All Things Open

Open Source and Public Policy
Open Source and Public PolicyOpen Source and Public Policy
Open Source and Public Policy
All Things Open
 
Weaving Microservices into a Unified GraphQL Schema with graph-quilt - Ashpak...
Weaving Microservices into a Unified GraphQL Schema with graph-quilt - Ashpak...Weaving Microservices into a Unified GraphQL Schema with graph-quilt - Ashpak...
Weaving Microservices into a Unified GraphQL Schema with graph-quilt - Ashpak...
All Things Open
 
How to Write & Deploy a Smart Contract
How to Write & Deploy a Smart ContractHow to Write & Deploy a Smart Contract
How to Write & Deploy a Smart Contract
All Things Open
 
Scaling Web Applications with Background
Scaling Web Applications with BackgroundScaling Web Applications with Background
Scaling Web Applications with Background
All Things Open
 
Build Developer Experience Teams for Open Source
Build Developer Experience Teams for Open SourceBuild Developer Experience Teams for Open Source
Build Developer Experience Teams for Open Source
All Things Open
 
Sudo – Giving access while staying in control
Sudo – Giving access while staying in controlSudo – Giving access while staying in control
Sudo – Giving access while staying in control
All Things Open
 
Fortifying the Future: Tackling Security Challenges in AI/ML Applications
Fortifying the Future: Tackling Security Challenges in AI/ML ApplicationsFortifying the Future: Tackling Security Challenges in AI/ML Applications
Fortifying the Future: Tackling Security Challenges in AI/ML Applications
All Things Open
 
Securing Cloud Resources Deployed with Control Planes on Kubernetes using Gov...
Securing Cloud Resources Deployed with Control Planes on Kubernetes using Gov...Securing Cloud Resources Deployed with Control Planes on Kubernetes using Gov...
Securing Cloud Resources Deployed with Control Planes on Kubernetes using Gov...
All Things Open
 

More from All Things Open (20)

Building Reliability - The Realities of Observability
Building Reliability - The Realities of ObservabilityBuilding Reliability - The Realities of Observability
Building Reliability - The Realities of Observability
 
Modern Database Best Practices
Modern Database Best PracticesModern Database Best Practices
Modern Database Best Practices
 
Open Source and Public Policy
Open Source and Public PolicyOpen Source and Public Policy
Open Source and Public Policy
 
Weaving Microservices into a Unified GraphQL Schema with graph-quilt - Ashpak...
Weaving Microservices into a Unified GraphQL Schema with graph-quilt - Ashpak...Weaving Microservices into a Unified GraphQL Schema with graph-quilt - Ashpak...
Weaving Microservices into a Unified GraphQL Schema with graph-quilt - Ashpak...
 
The State of Passwordless Auth on the Web - Phil Nash
The State of Passwordless Auth on the Web - Phil NashThe State of Passwordless Auth on the Web - Phil Nash
The State of Passwordless Auth on the Web - Phil Nash
 
Total ReDoS: The dangers of regex in JavaScript
Total ReDoS: The dangers of regex in JavaScriptTotal ReDoS: The dangers of regex in JavaScript
Total ReDoS: The dangers of regex in JavaScript
 
What Does Real World Mass Adoption of Decentralized Tech Look Like?
What Does Real World Mass Adoption of Decentralized Tech Look Like?What Does Real World Mass Adoption of Decentralized Tech Look Like?
What Does Real World Mass Adoption of Decentralized Tech Look Like?
 
How to Write & Deploy a Smart Contract
How to Write & Deploy a Smart ContractHow to Write & Deploy a Smart Contract
How to Write & Deploy a Smart Contract
 
Spinning Your Drones with Cadence Workflows, Apache Kafka and TensorFlow
 Spinning Your Drones with Cadence Workflows, Apache Kafka and TensorFlow Spinning Your Drones with Cadence Workflows, Apache Kafka and TensorFlow
Spinning Your Drones with Cadence Workflows, Apache Kafka and TensorFlow
 
DEI Challenges and Success
DEI Challenges and SuccessDEI Challenges and Success
DEI Challenges and Success
 
Scaling Web Applications with Background
Scaling Web Applications with BackgroundScaling Web Applications with Background
Scaling Web Applications with Background
 
Supercharging tutorials with WebAssembly
Supercharging tutorials with WebAssemblySupercharging tutorials with WebAssembly
Supercharging tutorials with WebAssembly
 
Using SQL to Find Needles in Haystacks
Using SQL to Find Needles in HaystacksUsing SQL to Find Needles in Haystacks
Using SQL to Find Needles in Haystacks
 
Configuration Security as a Game of Pursuit Intercept
Configuration Security as a Game of Pursuit InterceptConfiguration Security as a Game of Pursuit Intercept
Configuration Security as a Game of Pursuit Intercept
 
Scaling an Open Source Sponsorship Program
Scaling an Open Source Sponsorship ProgramScaling an Open Source Sponsorship Program
Scaling an Open Source Sponsorship Program
 
Build Developer Experience Teams for Open Source
Build Developer Experience Teams for Open SourceBuild Developer Experience Teams for Open Source
Build Developer Experience Teams for Open Source
 
Deploying Models at Scale with Apache Beam
Deploying Models at Scale with Apache BeamDeploying Models at Scale with Apache Beam
Deploying Models at Scale with Apache Beam
 
Sudo – Giving access while staying in control
Sudo – Giving access while staying in controlSudo – Giving access while staying in control
Sudo – Giving access while staying in control
 
Fortifying the Future: Tackling Security Challenges in AI/ML Applications
Fortifying the Future: Tackling Security Challenges in AI/ML ApplicationsFortifying the Future: Tackling Security Challenges in AI/ML Applications
Fortifying the Future: Tackling Security Challenges in AI/ML Applications
 
Securing Cloud Resources Deployed with Control Planes on Kubernetes using Gov...
Securing Cloud Resources Deployed with Control Planes on Kubernetes using Gov...Securing Cloud Resources Deployed with Control Planes on Kubernetes using Gov...
Securing Cloud Resources Deployed with Control Planes on Kubernetes using Gov...
 

Recently uploaded

Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 

Recently uploaded (20)

Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Connector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a buttonConnector Corner: Automate dynamic content and events by pushing a button
Connector Corner: Automate dynamic content and events by pushing a button
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
UiPath New York Community Day in-person event
UiPath New York Community Day in-person eventUiPath New York Community Day in-person event
UiPath New York Community Day in-person event
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
Le nuove frontiere dell'AI nell'RPA con UiPath Autopilot™
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 

Securing PostgreSQL from External Attack

  • 1. Securing PostgreSQL From External Attack BRUCE MOMJIAN Database systems are rich with attack vectors to exploit. This presentation explores the many potential PostgreSQL external vulnerabilities and shows how they can be secured. Includes concepts from Magnus Hagander https://momjian.us/presentations Creative Commons Attribution License Last updated: August, 2021 1 / 32
  • 3. External Attack Vectors • ’Trust’ security • Passwords / authentication theft • Network snooping • Network pass-through spoofing • Server / backup theft • Administrator access 3 / 32
  • 4. Internal Attack Vectors (Not Covered) • Database object permissions • SQL injection attacks • Application vulnerability • Operating system compromise 4 / 32
  • 6. Avoid “Trust” Security in pg_hba.conf # TYPE DATABASE USER CIDR-ADDRESS METHOD # "local" is for Unix domain socket connections only local all all trust # IPv4 local connections: host all all 127.0.0.1/32 trust # IPv6 local connections: host all all ::1/128 trust Solution: Use the initdb -A flag, i.e., you don’t want to see this: WARNING: enabling "trust" authentication for local connections You can change this by editing pg_hba.conf or using the -A option the next time you run initdb. 6 / 32
  • 7. Password Snooping Vulnerable to snooping Client Database PostgreSQL Database Server md5(password+username) md5(password+username) md5(password+username) md5(password+username) Using ’username’ in the MD5 string prevents the same password used by different users from appearing the same. It also adds some randomness to the md5 checksums. Connection Request Need Password Password Sent 7 / 32
  • 8. MD5 Authentication Prevents Password Snooping Client Database PostgreSQL Database Server md5(password+username) md5(password+username) md5(password+username) md5(password+username) Connection request Need md5, sent random salt md5(md5(password+username) + salt) 8 / 32
  • 9. MD5 Authentication Prevents Password Replay X OK Client Database Client Database Malicious PostgreSQL Database Server md5(password+username) md5(password+username) md5(password+username) md5(password+username) Connection request Need md5, sent random salt0 md5(md5(password+username) + salt0) Connection request Need md5, sent random salt1 md5(md5(password+username) + salt0) replay salt is a random four-byte integer so millions of connection attempts might allow the reuse of an old authentication reply. 9 / 32
  • 10. SCRAM Authentication scram-sha-256, available in Postgres 10, eliminates less-secure MD5, and avoids the risk of duplicate salt values being replayed. SCRAM with channel binding, available in Postgres 13, allows authentication, similar to certificate authentication. scram-sha-256 is the default in Postgres 14. 10 / 32
  • 11. SCRAM-SHA-256 Authentication Client Database PostgreSQL Database Server sha256(password+salt) sha256(password+salt) sha256(password+salt) sha256(password+salt) Connection request Client nonce, server nonce, salt Client nonce, server nonce, client proof Need scram−sha−256 Username, client nonce https://en.wikipedia.org/wiki/Salted_Challenge_Response_Authentication_Mechanism 11 / 32
  • 12. Password Attacks • Weak passwords • Reuse of old passwords • Brute-force password attacks None of these vulnerabilities is prevented by Postgres directly, but external authentication methods, like LDAP , PAM, and SSPI, can prevent them. Some authentication methods are difficult to use with connection pooling. 12 / 32
  • 13. Queries and Data Still Vulnerable to Network Snooping Queries and data vulnerable to snooping Client Database PostgreSQL Database Server Barr Bearings | $10230 | James Akel SELECT * FROM customer; Password changes are also vulnerable to snooping. 13 / 32
  • 14. SSL Prevents Snooping By Encrypting Queries and Data Queries and data encrypted by SSL Client Database PostgreSQL Database Server AES256(Barr Bearings | $10230 | James Akel) AES256(SELECT * FROM customer); 14 / 32
  • 16. Localhost Spoofing While the Database Server Is Down X Client Database Fake PostgreSQL Database Server use with the real server Records passwords for later Uses a fake socket or binds to and 5432 is not a root−only port. port 5432 while the real server is down. (/tmp is world−writable libpq’s "requirepeer" helps here.) Connection Request Need Plain Password Password Sent The server controls the choice of ’password’ instead of ’md5’. 16 / 32
  • 17. Network Spoofing X Client Database Fake PostgreSQL Database Server use with the real server Records passwords for later Without SSL ’root’ certificates there is no way to know if the server you are connecting to is a legitimate server. Connection Request Need Plain Password Password Sent 17 / 32
  • 18. Network Spoofing Pass-Through OK Client Database Database Server PostgreSQL Fake PostgreSQL Database Server Records passwords for later use with the real server. It can also capture queries, queries. data, and inject its own Without SSL ’root’ certificates there is no way to know if the server you are connecting to is a legitimate server. Query Result Connection Request Need Plain Password Password Sent Query Result 18 / 32
  • 19. SSL ’Prefer’ Is Not Secure OK Client Database Database Server PostgreSQL Fake PostgreSQL Database Server Records passwords for later use with the real server. It can also capture queries, queries. data, and inject its own Without SSL ’root’ certificates there is no way to know if the server you are connecting to is a legitimate server. Query Result SSL or Non−SSL No SSL Prefer SSL Non−SSL Query Result 19 / 32
  • 20. SSL ’Require’ Is Not Secure From Spoofing OK Client Database Database Server PostgreSQL Fake PostgreSQL Database Server Records passwords for later use with the real server. It can also capture queries, queries. data, and inject its own Without SSL ’root’ certificates there is no way to know if the server you are connecting to is a legitimate server. Query Result SSL or Non−SSL Require SSL OK SSL SSL Query Result 20 / 32
  • 21. SSL ’Verify-CA’ Is Secure From Spoofing X root.crt server.crt Fake PostgreSQL Database Server Client Database Database Server PostgreSQL Invalid certificate SSL verify−ca (no CA signature) 21 / 32
  • 22. Channel Binding is hashed with the password hash to prove the TLS peer knows the password hash. Certificates are sent to peers as part of the TLS handshake. Later the certificate hash This is tls−server−end−point channel binding. Client Database PostgreSQL Database Server sha256(password+salt) sha256(password+salt) sha256(password+salt) sha256(password+salt) Connection request, need SSL Client nonce, server nonce, salt Client nonce, server nonce, client proof Server proof Channel binding req., username, client nonce Need scram−sha−256 server.crt 22 / 32
  • 23. SSL Certificates for Authentication root.crt server.crt Client Database Database Server PostgreSQL Request for SSL certificate SSL certificate with CN 23 / 32
  • 24. Data Encryption To Avoid Data Theft https://www.flickr.com/photos/debarshiray/ 24 / 32
  • 25. Disk Volume Encryption This helps prevent stolen storage devices from being read, and helps with secure media destruction. https://www.flickr.com/photos/icebrkr/ 25 / 32
  • 26. Column Encryption id | name | credit_card_number --------+--------------------+------------------------------ 428914 | Piller Plaster Co. | xc30d04070302254dc045353f28 ; 456cd241013e2d421e198f3320e8 ; 41a7e4f751ebd9e2938cb6932390 ; 5c339c02b5a8580663d6249eb24f ; 192e226c1647dc02536eb6a79a65 ; 3f3ed455ffc5726ca2b67430d5 Encryption methods are decryptable (e.g., AES), while hashes are one-way (e.g., MD5). A one-way hash is best for data like passwords that only need to be checked for a match, rather than decrypted. 26 / 32
  • 27. Where to Store the Key? On the Server Decrypted data key Client Database PostgreSQL Database Server Barr Bearings | $10230 | James Akel SELECT * FROM customer; 27 / 32
  • 28. Store the Key on an Intermediate Server key Decrypted Encrypted SELECT SELECT Client Database Cryptographic Server PostgreSQL Database Server Barr Bearings V#ja20a 28 / 32
  • 29. Store the Key on the Client and Encrypt/Decrypt on the Server key Decrypted data Client Database PostgreSQL Database Server Barr Bearings | $10230 | James Akel SELECT decrypt(col, key) FROM customer; 29 / 32
  • 30. Encrypt/Decrypt on the Client key Encrypted data Client Database PostgreSQL Database Server V#aei32ok3 SELECT * FROM customer; This prevents server administrators from viewing sensitive data. 30 / 32
  • 31. Store the Key on a Client Hardware Token key Encrypted data Client Database PostgreSQL Database Server V#aei32ok3 SELECT * FROM customer; This prevents problems caused by client hardware theft. 31 / 32