在另一个主机上装了WordPress和自己写的Blog,一天早上收到某个搜索引擎的邮件,提醒说站点被挂马了。
打开网页NOD32立马提示病毒,上网一看说WordPress存在着XSS漏洞,对WordPress不熟悉只好通过升级安装到最新版本搞定这个问题。
接着顺便访问下自己写的Blog,居然同样被挂马了,感到杯具之余正好分析下这马的调用方式。拖下所有文件,查找和首页挂马代码相似的代码:
1. 发现所有目录index.php最开始处都被挂了一段代码,基本能说明挂马操作是程序自动处理的。
2. 内容被PHP base64编码和JS fromCharCode混淆过。
3. 如果访问者是搜索引擎的爬虫,则不执行挂马操作,这样不会让搜索引擎将网站标识为恶意网站(这次知道被挂马,是一个不在这个列表里的搜索引擎提醒的)。
顺便附上相应代码,知己知彼,百战不殆。
阅读全文 "杯具!网站被挂马了~" »
最近买了IXWebHostings,要将另外一个站迁移到新空间。完成后进行测试,前台没有问题,后台登录后显示为空白页面。
折腾了半天,发现是插件问题。将wp-content目录下的“plugins目录”改名,然后重新登录进行测试,成功后进入插件管理页面,将“改名后的plugins目录”改回来,刷新页面后一个插件一个插件的启用,看是问题出现在哪个插件,重装下即可。
// --------------- 分隔线飘过 ------------ //
说说IXWebHostings,几天用下来,感觉国内访问速度不是很快,虽然网上说比以前快了很多,但相比原来的空间还是慢了那么一点点。但客服方面比较好,有中文客服,解决问题比较及时。
(一)中讲到了wordpress是如何读取系统中所有插件的。
现在我们来看看她是如何激活及停用插件的。
激活及停用插件
wordpress的当前使用的插件列表存放在数据库中,wp_options表,字段option_name值为active_plugins的列存放的就是当前系统中使用的插件。
a:2:{i:0;s:9:"hello.php";i:1;s:16:"wp-db-backup.php";}
就是当前系统中使用的两个插件Hello Dolly、WordPress Database Backup。
这个字段原有类型是array,经过serialize后存放在数据库中,读出时unserialize。
取得当前系统中使用的插件 functions.php | 273行 | function get_settings($setting) {}
-
-
- $row = $wpdb->get_row("SELECT option_value FROM $wpdb->options WHERE option_name = '$setting' LIMIT 1");
-
-
-
- if( is_object( $row) ) {
- $value = $row->option_value;
-
- wp_cache_set($setting, $value, 'options');
- }
-
-
- return apply_filters( 'option_' . $setting, maybe_unserialize($value) );
-
-
-
-
-
-
-
-
-
-
-
-
激活插件
通过链接plugins.php?action=activate&plugin=hello.php
wp-admin/plugins.php | 5行左右 |
-
- $current = get_settings('active_plugins');
-
- if (!in_array($_GET['plugin'], $current)) {
-
- $current[] = trim( $_GET['plugin'] );
- sort($current);
-
-
- update_option('active_plugins', $current);
-
-
- }
停用插件
通过链接plugins.php?action=deactivate&plugin=hello.php
wp-admin/plugins.php | 16行左右 |
-
- $current = get_settings('active_plugins');
-
- array_splice($current, array_search( $_GET['plugin'], $current), 1 );
-
-
- update_option('active_plugins', $current);
-
-
wordpress目前非常流行一款开放源代码基于php,mysql的blog系统,尤其是她的插件机制更让人着迷。有很多wordpress插件的相关网站。
让我们来一起剖析她的插件机制的实现吧。
wordpress是怎么读取当前所有插件的?
wordpress的插件存放在wp-content\plugins目录下,可以直接存放在plugins或plugins的二级目录下。
登录后台进入Plugins栏目可以查看当前所有存在的插件相关信息。
以Hello Dolly插件为例。
wp的插件相关描述存放在php文件内容开始的地方
读取当前系统中插件文件夹中的文件 admin-functions.php | 1516行 | function get_plugins() {}
-
-
- $plugins_dir = @ dir($plugin_root);
- if ($plugins_dir) {
- while (($file = $plugins_dir->read()) !== false) {
-
- if (preg_match('|^\.+$|', $file))
- continue;
-
- if (is_dir($plugin_root.'/'.$file)) {
- $plugins_subdir = @ dir($plugin_root.'/'.$file);
- if ($plugins_subdir) {
- while (($subfile = $plugins_subdir->read()) !== false) {
-
- if (preg_match('|^\.+$|', $subfile))
- continue;
-
- if (preg_match('|\.php$|', $subfile))
- $plugin_files[] = "$file/$subfile";
- }
- }
- } else {
-
- if (preg_match('|\.php$|', $file))
- $plugin_files[] = $file;
- }
- }
- }
-
- foreach ($plugin_files as $plugin_file) {
- if ( !is_readable("$plugin_root/$plugin_file"))
- continue;
-
-
- $plugin_data = get_plugin_data("$plugin_root/$plugin_file");
-
- if (emptyempty ($plugin_data['Name'])) {
- continue;
- }
-
- $wp_plugins[plugin_basename($plugin_file)] = $plugin_data;
- }
-
-
-
-
- return $wp_plugins;
分析每个插件的相关描述信息 admin-functions.php | 1486行 | function get_plugin_data($plugin_file) {}
-
- $plugin_data = implode('', file($plugin_file));
-
- preg_match("|Plugin Name:(.*)|i", $plugin_data, $plugin_name);
- preg_match("|Plugin URI:(.*)|i", $plugin_data, $plugin_uri);
- preg_match("|Description:(.*)|i", $plugin_data, $description);
- preg_match("|Author:(.*)|i", $plugin_data, $author_name);
- preg_match("|Author URI:(.*)|i", $plugin_data, $author_uri);
- if (preg_match("|Version:(.*)|i", $plugin_data, $version))
- $version = trim($version[1]);
- else
- $version = '';
-
-
-
- return array ('Name' => $name, 'Title' => $plugin, 'Description' => $description, 'Author' => $author, 'Version' => $version, 'Template' => $template[1]);
wp-admin/plugins.php 调用 get_plugins() {} 方法显示所有插件,读取完毕。