【问题标题】:DangerousPhp inside phpseclib when checking with YARA [closed]使用 YARA 检查时 phpseclib 中的 DangerousPhp [关闭]
【发布时间】:2021-12-29 03:11:52
【问题描述】:

在使用YARA 在 PHP 应用程序内进行恶意软件扫描时,

yara -r ./php.yar -s /myapp

DangerousPhp /myapp/phpseclib/Net/SSH2.php
0x1140c:$system: system
0x1083a:$: call_user_func
0x1671f:$: call_user_func
0x154:$: EXEC

里面使用的恶意软件查找工具是https://github.com/nbs-system/php-malware-finder/

引发此错误的 phpseclib 库文件是 https://github.com/phpseclib/phpseclib/blob/master/phpseclib/Net/SSH2.php

任何帮助将不胜感激。

【问题讨论】:

  • 询问 phpseclib 的作者,而不是我们。顺便说一句,这些功能不会自动不安全,但如果处理不当,可能会被滥用。 Afaik 没有已知的 phpseclib 漏洞利用..
  • @LarsStegelitz 如果有人遇到过类似问题,请在此处发布。

标签: php phpseclib yara php-malware-scanner


【解决方案1】:

误报。目前尚不清楚您使用的是哪个版本的 phpseclib,但我们假设您使用的是最新的 2.0 版本 (2.0.34)。 call_user_func 仅出现在第 2946 行:

https://github.com/phpseclib/phpseclib/blob/2.0.34/phpseclib/Net/SSH2.php#L2946

                default:
                    if (is_callable($callback)) {
                        if (call_user_func($callback, $temp) === true) {
                            $this->_close_channel(self::CHANNEL_EXEC);
                            return true;
                        }
                    } else {
                        $output.= $temp;
                    }

它在 exec() 方法中。 $callback 是一个参数,其用途在 https://phpseclib.com/docs/commands#callbacks 中讨论。 3.0 分支使用$callback($temp) 而不是callback_user_func($temp),但基本思想相同。 $callback($temp) 可能不适用于旧版本的 PHP,而 callback_user_func($temp) 可以。

call_user_func_array 在 SSH2.php 中被调用了两次。一次是line 2227,一次是line 3375

第 2227 行在 login 方法中。该方法的作用如下:

    function login($username)
    {
        $args = func_get_args();
        $this->auth[] = $args;

        // try logging with 'none' as an authentication method first since that's what
        // PuTTY does
        if (substr($this->server_identifier, 0, 15) != 'SSH-2.0-CoreFTP' && $this->auth_methods_to_continue === null) {
            if ($this->_login($username)) {
                return true;
            }
            if (count($args) == 1) {
                return false;
            }
        }
        return call_user_func_array(array(&$this, '_login'), $args);
    }

在 phpseclib 3.0.11 中,它正在执行 return $this->sublogin($username, ...$args);,但基本思想是它获取 $args 的每个元素并将其作为单独的参数传递给 $this->_login。就像你做了$this->_login($args) 那么_login 只会采用一个参数。 PHP 5.6 introduced the splat (...) operator 但 phpseclib 2 在 PHP 5.3 上运行,因此您必须执行 call_user_func_array 或仅使用单个参数即可。

这是call_user_func_array 的另一个实例:

    function _reconnect()
    {
        $this->_reset_connection(NET_SSH2_DISCONNECT_CONNECTION_LOST);
        $this->retry_connect = true;
        if (!$this->_connect()) {
            return false;
        }
        foreach ($this->auth as $auth) {
            $result = call_user_func_array(array(&$this, 'login'), $auth);
        }
        return $result;
    }

同样的事情。

所以就像我说的,这是一个空无一物的三明治。误报。

【讨论】:

  • 对错误“系统”有何评论?
  • @mujuonly - 知道那是什么意思。 “系统”一词在 SSH2.php 的 v2.0.34 中出现了 42 次。其中绝大多数是cmets。还有use phpseclib\System\SSH\Agentconst CHANNEL_SUBSYSTEM = 3;function startSubsystem($subsystem) 等。这与该文件中出现 1,172 次的字母“k”一样可疑。
  • @mujuonly - 有一个名为 system 但 phpseclib 没有调用它的 PHP 函数:php.net/system 我的猜测是 Yara 没有标记 PHP 文件,而只是进行不区分大小写的字符串搜索.这当然会产生误报。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-05-18
  • 2018-12-09
  • 1970-01-01
  • 1970-01-01
  • 2022-10-19
  • 2021-03-25
  • 1970-01-01
相关资源
最近更新 更多