这里我需要说明一下echsop具备全局的一个安全转义
全局文件:/includes/init.php
if (!get_magic_quotes_gpc())
{
if (!empty($_GET))
{
$_GET = addslashes_deep($_GET);
}
if (!empty($_POST))
{
$_POST = addslashes_deep($_POST);
}
$_COOKIE = addslashes_deep($_COOKIE);
$_REQUEST = addslashes_deep($_REQUEST);
}
当未开启gpc后进入addslashes_deep函数内容,php在高版本后gpc处于默认关闭状态
function addslashes_deep($value)
{
if (empty($value))
{
return $value;
}
else
{
return is_array($value) ? array_map('addslashes_deep', $value) : addslashes($value);
}
}
addslashes_deep当string时直接进行安全转义,数组时递归转义,这便是ecshop的全局安全。
漏洞文件:user.php
$post_data = json_decode(str_replace('\\','',$_POST['JSON']),1);
//判断是否经过验证码验证
if((!isset($_SESSION['v_code']) || $_SESSION['v_code']!='true') && !isset($post_data['no_need_vcode']) ){
make_json_result('v_code fail');exit;
}
$_SESSION['v_code'] = 'false';
$mobile = $post_data['mobile'] ? $post_data['mobile'] : false;
$is_send = 'fail';
POST获取JSON值并进行json_decode而json_decode具备绕过全局转义以及gpc的特点,也就是会吞并反斜杠。当我们提交’时会被转义成\’而这里再经过一次json_decode则因吞并反斜杠导致还原单引号所以导致我们可以输入危害内容,但下面还存在一个if的判断
if((!isset($_SESSION['v_code']) || $_SESSION['v_code']!='true') && !isset($post_data['no_need_vcode']) ){make_json_result('v_code fail');exit;}判断SESSION的v_code值是否为true与no_need_vcode是否定义,因为这里用的是&&所以我们满足其中一个条件即可绕过判断,post_data是由我们json_decode后赋值的变量所以这里no_need_vcode可控绕过判断
$_SESSION['v_code'] = 'false';
$mobile = $post_data['mobile'] ? $post_data['mobile'] : false;
$is_send = 'fail';
if($mobile){
// 找回密码验证输入的手机号是否已注册
if (isset($post_data['action']) && $post_data['action'] == 'sms_get_password') {
$is_reg = $user->check_user($mobile);
if (!$is_reg) {
make_json_result($_LANG['phone_number_reg_check_fail']);
exit();
}
}
将post_data中的mobile赋予$mobile并一下判断action是否指定为sms_get_password方法,当指定时则进入check_user方法
function check_user($username, $password = null)
{
if ($this->charset != 'UTF8')
{
$post_username = ecs_iconv('UTF8', $this->charset, $username);
}
else
{
$post_username = $username;
}
if ($password === null)
{
$sql = "SELECT " . $this->field_id .
" FROM " . $this->table($this->user_table).
" WHERE " . $this->field_name . "='" . $post_username . "'";
return $this->db->getOne($sql);
}
```
username为我们提交的mobile内容,password未带入所以这里为NULL故进入password===null条件中执行
```mysql
$sql = "SELECT " . $this->field_id .
" FROM " . $this->table($this->user_table).
" WHERE " . $this->field_name . "='" . $post_username . "'";
期间未再经过转义所以导致存在注入但ecshop在新版本后存在安全防护
安全防护文件:/includes/safety.php
$url_arr=array(
'xss'=>"\\=\\+\\/v(?:8|9|\\+|\\/)|\\%0acontent\\-(?:id|location|type|transfer\\-encoding)",
);
$args_arr=array(
'xss'=>"[\\'\\\"\\;\\*\\].*\\bon[a-zA-Z]{3,15}[\\s\\r\\n\\v\\f]*\\=|\\b(?:expression)\\(|\\
'other'=>"\\.\\.[\\\\\\/].*\\%00([^0-9a-fA-F]|$)|%00[\\'\\\"\\.]");
if( !function_exists('filterData') ){
function filterData(&$data,$type){
$dataand filterArray($data,$type);
}
以上为安全防护的正则内容,一看就输入可以绕过的,因为们有json_decode所以可以打乱关键字导致绕过