Postgresql注入研究三两事
环境搭建
很简单,但是为了众弟兄方便,偶还是啰嗦下。
1. 安装apache postgresql 8.3
2. 进入postgresql shell 输入如下语句:
Create database test;
c test;
Create table test(str varchar(2000),id int);
Insert into test(str,id) values(‘sss’,1);
q
3. 保存如下php文件到apache web目录,注意,为了演示全部功能,把php的magic调节成off。
<?php
$id = $_GET[id];
$db = pg_connect("host=localhost dbname=test user=postgres password=test");
$query = SELECT * FROM test where id=.$id;
$result = pg_query($query) or die(Query failed: . pg_last_error());
echo "<table> ";
while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
echo " <tr> ";
foreach ($line as $col_value) {
echo " <td>$col_value</td> ";
}
echo " </tr> ";
}
echo "</table> ";
pg_free_result($result);
pg_close($db);
?>
好了,访问xxx.php?id=1 ,这就是注入点了。嘎嘎。
开始注入
不知道pgsql是从什么版本开始支持information_schema这样的东西,相信大家很熟悉他的结构。我仔细比对了他和mysql5的这个库的区别,请放心使用!呵呵。
要注意的问题是,在pgsql里information_schema的存在形式并非一个真正的数据库,比如,我们在test库里建立了一个叫test的表,那么在pshell里进入其他数据库输入select table_name from information_schema.tables是找不到资料的。但是c test连接到test数据库里输入上面的查询语句却能找到test的记录,另外,pgsql里跨库查询也很困难,目前没有找到好的办法。另外pgsql不支持mysql的limit x,y这个语法,取而代之的是limit 1 offset n。这样说很空洞。请看:
Union字段探测不提,还有就是pgsql要先用null匹配,然后慢慢找到可以显示的字段。
浏览起返回a
浏览器返回第一个表的名字,其他的不提。
另外,实战中发现版本问题可能并不支持information_schema,但是pg丰富的系统表能提供我们想要的东西,做到通杀pgsql,这也是本文的重点之一。
我把我们需要的东西都提取出来,一一对应一下:
Table pg_class.oid 对应 pg_attribute.attrelid
我用查询来说明问题,
Select relname from pg_class /*得到表名
Select oid from pg_class where relname=’xxx’/*得到表xxx的oid,如为2
Select attname from pg_arrribute where attrelid=2 /*得到表xxx的所有字段列表
必须使用oid,这是表的唯一标示符。以免出错。
上一篇:007博客网再暴XSS漏洞
下一篇:国外一Blog程序0day