No description
Find a file
Tarjei Husøy bb107c9074 Buffer reads/writes to server
Now ensures entire packet is sent by using .sendall() on the socket,
and actually reads the auth request packet properly.

Also quits earlier, after sending the auth response we now connect
the socket directly, letting the server reply success to the client.
2016-06-02 09:01:11 -07:00
.editorconfig Add editorconfig 2016-05-30 23:34:24 -07:00
.gitignore Initial commit 2016-05-30 07:28:19 -07:00
LICENSE Initial commit 2016-05-30 07:28:19 -07:00
postgres_mitm.py Buffer reads/writes to server 2016-06-02 09:01:11 -07:00
README.md Add mitigation steps to readme 2016-05-30 20:07:25 -07:00
server.cert Add first draft of script 2016-05-30 07:31:26 -07:00
server.key Add first draft of script 2016-05-30 07:31:26 -07:00

postgres-mitm

Test whether your Postgres connections are vulnerable to MitM attacks.

Steps to test your exposure

  • Run the script with the IP of the database you want to impersonate: postgres_mitm.py <IP of actual database>
  • Replace your database hostname with the IP of the machine running the script
  • See if your app works.

If your app successfully connects to the database, it didn't validate certficates and accepted whatever was presented. The credentials for the database will be printed by the script. If you're seeing connection errors that's good, and means you're probably not vulnerable.

If you're vulnerable

If you only have one database you can add its certificate to your trust store to prevent attacks like this one. The default trust store is ~/.postgresql/root.crt, but you can customize this with the connection parameter sslrootcert.

If you're connecting to a database pool or are hosting many databases you should probably create your own Certificate Authority (CA) that can sign certificates for each database. Then the clients only need to trust the CA certificate and will have a secure connection to any of the databases signed by the CA.

As always, consult the excellent documentation for details.