Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CmsWing-v1.3.8 存在模板登录后台RCE #64

Open
m0unta1ner opened this issue May 10, 2023 · 0 comments
Open

CmsWing-v1.3.8 存在模板登录后台RCE #64

m0unta1ner opened this issue May 10, 2023 · 0 comments

Comments

@m0unta1ner
Copy link

模板注入 src/controller/admin/template.js
/**

  • 网站首页模版编辑

  • @returns {*}
    */
    async homeAction() {
    const gid = await this.model('temp_group').where({isdefault: 1}).getField('gid', true);
    const map = {
    module: 'home',
    controller: 'index',
    action: 'index',
    type: this.para('type') || 1,
    gid: gid
    };
    const temp = await this.model('temp').where(map).find();
    let temppath;
    if (temp.type == 2) {
    temppath = ${think.ROOT_PATH}/view/${temp.module}/mobile/;
    } else {
    temppath = ${think.ROOT_PATH}/view/${temp.module}/;
    }
    const templateFile = ${temppath}${temp.controller}${this.config('view.nunjucks.sep')}${temp.action}${this.config('view.nunjucks.extname')};
    if (this.isPost) {
    const data = this.post();
    data.id = temp.id;
    data.module = map.module;
    data.controller = map.container;
    data.action = map.action;
    data.name = temp.name;
    data.type = temp.type;
    data.gid = temp.gid;
    console.log(data);
    // await this.model("temp").add(data);
    temp.pid = temp.id;
    delete temp.id;
    temp.baktime = new Date().getTime();
    temp.lastuser = this.user.uid;
    console.log(temp);
    // return false;
    // 修改前先备份
    if (data.html != temp.html) {
    const bak = await this.model('temp_bak').add(temp);
    const res = await this.model('temp').update(data);
    if (!think.isEmpty(res)) {
    fs.writeFileSync(templateFile, data.html);
    return this.success({name: '添加成功!'});
    }
    } else {
    return this.fail('请先修改模板!');
    }
    } else {
    // 首页网站编辑
    // console.log(this.adminmenu["10"]);
    this.meta_title = '首页模板';

    if (think.isFile(templateFile)) {
    const tempcon = fs.readFileSync(templateFile, 'utf8');
    temp.html = tempcon;
    }
    // console.log(temp);
    this.assign('temp', temp);
    return this.display();
    }
    }
    可以看到通过nunjucks模板对前端进行渲染,对传入的post请求的html参数只有判空校验,所以可以通过模板注入命令执行来进行RCE,直接构造调用child_process的命令执行,我们这里进行弹计算器演示
    image
    image
    然后访问首页进行渲染
    image
    成功弹出计算器,其他的模板也存在该注入问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant