SQL Direct (Medium)

  • Challenge Link: https://play.picoctf.org/practice/challenge/303?category=1&difficulty=2&page=2
  • Challenge Description: Connect to this PostgreSQL server and find the flag!

Solution

This requires us to know a little about PostgreSQL. PostgreSQL is a free, open-source, object-relational database management system which stores, organizes, and lets you query data reliably. It's one of the most reliable open-source databases with many features.

When we launch the instance, we are given these instructions:

Connect to this PostgreSQL server and find the flag!
psql -h saturn.picoctf.net -p 60097 -U postgres pico
Password is postgres

If you don't have postgresql installed you can quickly do so by running:

sudo apt install postgresql
sudo apt install postgresql-client

After that, we can connect to server by running the aforementioned command and using the given password. First, let's list all tables in the current database and schema. Then, we see a table called flag, so let's read it to get our flag:

\dt = view tables (\dt+ gives the structure + storage details)
select * from flags; = reads all columns and returns every row from the table flags.
postgresql

Sources