### [修复整理ecshop漏洞](https://www.prosaas.cn/article/590) **Published:** 2021-03-11T02:06:48 **Author:** 5201314 **Excerpt:** 1、ECShop存在一个盲注漏洞,问题存在于/api/client/api.php文件中,提交特制的恶意POS… ![](//zhiqipro.oss-cn-beijing.aliyuncs.com/2023/12/20231212114853710.jpg) **1、**ECShop存在一个盲注漏洞,问题存在于/api/client/api.php文件中,提交特制的恶意POST请求可进行SQL注入攻击,可获得敏感信息或操作数据库。 路径:/api/client/includes/lib\_api.php 参照以下修改: **推荐(免费):eschop** function API\_UserLogin($post) {     /\* SQL注入过滤 \*/     if (get\_magic\_quotes\_gpc())      {              $post\['UserId'\] = $post\['UserId'\];     }      else      {              $post\['UserId'\] = addslashes($post\['UserId'\]);          }     /\* end \*/     $post\['username'\] = isset($post\['UserId'\]) ? trim($post\['UserId'\]) : ''; **2、**ecshop的后台编辑文件/admin/shopinfo.php中,对输入参数id未进行正确类型转义,导致整型注入的发生。 路径: /admin/shopinfo.php 参照以下修改(53-71-105-123行): 源代码: admin\_priv('shopinfo\_manage'); 改为: admin\_priv('shopinfo\_manage'); $\_REQUEST\['id'\] = intval($\_REQUEST\['id'\]); **3、**文件/admin/affiliate\_ck.php中,对输入参数auid未进行正确类型转义,导致整型注入的发生。 参照以下修改(31行和51行): 源代码: $logdb = get\_affiliate\_ck(); 改成: $\_GET\['auid'\] = intval($\_GET\['auid'\]); $logdb = get\_affiliate\_ck(); 注:好像按上面改了阿里云还是会提示这个漏洞,然后我在文件顶部处添加以下代码就可以了: $\_GET\['auid'\] = intval($\_GET\['auid'\]); **4、**ecshop的/admin/comment\_manage.php中,对输入参数sort\_by、sort\_order未进行严格过滤,导致SQL注入。 参照以下修改: $filter\['sort\_by'\]      = empty($\_REQUEST\['sort\_by'\]) ? 'add\_time' : trim(htmlspecialchars($\_REQUEST\['sort\_by'\]));   $filter\['sort\_order'\]   = empty($\_REQUEST\['sort\_order'\]) ? 'DESC' : trim(htmlspecialchars($\_REQUEST\['sort\_order'\])); **5、**ecshop没有对会员注册处的username过滤,保存重的用户信息时,可以直接写入shell。 路径:/admin/integrate.php 大概109行,参照以下修改: $code = empty($\_GET\['code'\]) ? '' : trim(addslashes($\_GET\['code'\])); 大概601行,参照以下修改: 源代码: @file\_put\_contents(ROOT\_PATH . 'data/repeat\_user.php', $json->encode($repeat\_user)); 修改成: @file\_put\_contents(ROOT\_PATH.'data/repeat\_user.php',''.$json->encode($repeat\_user)); 注:好像按上面改了阿里云还是会提示这个漏洞,然后我在文件顶部处添加以下代码就可以了: $\_GET\['code'\] = empty($\_GET\['code'\]) ? '' : trim(addslashes($\_GET\['code'\])); **6、**ecshop后台模版编译导致黑客可插入任意恶意代码。 路径:/admin/edit\_languages.php 大概在第120行 $dst\_items\[$i\] = $\_POST\['item\_id'\]\[$i\] .' = '. '"' .$\_POST\['item\_content'\]\[$i\]. '";'; 修改为 $dst\_items\[$i\] = $\_POST\['item\_id'\]\[$i\] .' = '. '\\'' .$\_POST\['item\_content'\]\[$i\]. '\\';'; **7、**ecshop过滤不严导致SQL注入漏洞。 路径:/category.php 、 /ecsapi/category.php 修改方法:https://www.cnblogs.com/LittleHann/p/4524161.html **8、**ecshop的/includes/lib\_insert.php文件中,对输入参数未进行正确类型转义,导致整型注入的发生。 有`$arr['num'] 、$arr['id']、$arr['type']`这些参数的,在函数开头加上: 大概289行加上: $arr\['num'\] = intval($arr\['num'\]); $arr\['id'\] = intval($arr\['id'\]); 大概454行加上: $arr\['id'\] = intval($arr\['id'\]); $arr\['type'\] = addslashes($arr\['type'\]); 大概495行加上: $arr\['id'\] = intval($arr\['id'\]); **9、**ECSHOP支付插件存在SQL注入漏洞,此漏洞存在于/includes/modules/payment/alipay.php文件中,该文件是ECshop的支付宝插件。由于ECShop使用了str\_replace函数做字符串替换,黑客可绕过单引号限制构造SQL注入语句。只要开启支付宝支付插件就能利用该漏洞获取网站数据,且不需要注册登入。 搜索代码: $order\_sn = str\_replace($\_GET\['subject'\], '', $\_GET\['out\_trade\_no'\]); 将下面一句改为: $order\_sn = trim(addslashes($order\_sn)); **Ecshop后台模版编辑漏洞** 详情描述参考:https://www.cnblogs.com/LittleHann/p/4272255.html 漏洞文件:/admin/mail\_template.php 和 /includes/cls\_template.php /admin/mail\_template.php文件添加以下代码(过滤了部分php关键词) /\*------------------------------------------------------ \*/ //-- 保存模板内容 /\*------------------------------------------------------ \*/ elseif ($\_REQUEST\['act'\] == 'save\_template') {      if (empty($\_POST\['subject'\]))     {        sys\_msg($\_LANG\['subject\_empty'\], 1, array(), false);     }     else     {         $subject = trim($\_POST\['subject'\]);     }     if (empty($\_POST\['content'\]))     {        sys\_msg($\_LANG\['content\_empty'\], 1, array(), false);     }     else     {         $content = trim($\_POST\['content'\]);     }     $type   = intval($\_POST\['is\_html'\]);     $tpl\_id = intval($\_POST\['tpl'\]);     /\*过滤了部分php关键词\*/         $temp\_check = preg\_replace("/(\[^a-zA-Z0-9\_\]{1,1})+(extract|parse\_str|str\_replace|unserialize|ob\_start|require|include|array\_map|preg\_replace|copy|fputs|fopen|file\_put\_contents|file\_get\_contents|fwrite|eval|phpinfo|assert|base64\_decode|create\_function|call\_user\_func)+( |\\()/is", "", $content);     $temp\_check = preg\_replace("/<\\?\[^><\]+(\\?>){0,1}|<\\%\[^><\]+(\\%>){0,1}|<\\%=\[^><\]+(\\%>){0,1}|\]+language\[^>\]\*=\[^>\]\*php\[^>\]\*>\[^><\]\*(<\\/script\\s\*>){0,1}/iU", "", $temp\_check);      $content = $temp\_check;     /\*过滤了部分php关键词\*/     $sql = "UPDATE " .$ecs->table('mail\_templates'). " SET ".                 "template\_subject = '" .str\_replace('\\\\\\'\\\\\\'', '\\\\\\'', $subject). "', ".                 "template\_content = '" .str\_replace('\\\\\\'\\\\\\'', '\\\\\\'', $content).  "', ".                 "is\_html = '$type', ".                 "last\_modify = '" .gmtime(). "' ".             "WHERE template\_id='$tpl\_id'";     if ($db->query($sql, "SILENT"))     {         $link\[0\]=array('href' => 'mail\_template.php?act=list', 'text' => $\_LANG\['update\_success'\]);         sys\_msg($\_LANG\['update\_success'\], 0, $link);     }     else     {          sys\_msg($\_LANG\['update\_failed'\], 1, array(), false);     } } /includes/cls\_template.php文件替换函数(fetch\_str()): function fetch\_str($source)     {          if (!defined('ECS\_ADMIN'))         {             $source = $this->smarty\_prefilter\_preCompile($source);         }         $source=preg\_replace("/(\[^a-zA-Z0-9\_\]{1,1})+(copy|fputs|fopen|file\_put\_contents|fwrite|eval|phpinfo)+( |\\()/is", "", $source);         $source=preg\_replace("/<\\?\[^><\]+\\?>|<\\%\[^><\]+\\%>|\]+language\[^>\]\*=\[^>\]\*php\[^>\]\*>\[^><\]\*<\\/script\\s\*>/iU", "", $source);         return preg\_replace("/{(\[^\\}\\{\\n\]\*)}/e", "\\$this->select('\\\\1');", $source);         //return preg\_replace\_callback("/{(\[^\\}\\{\\n\]\*)}/", function($r) { return $this->select($r\[1\]); }, $source);//修饰符 /e 在 PHP5.5.x 中已经被弃用了     } 以上就是修复整理ecshop漏洞的详细内容,更多请关注知企PROSAAS其它相关文章! **Categories:** ECShop ---