> For the complete documentation index, see [llms.txt](https://hacking-3.gitbook.io/barre/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-3.gitbook.io/barre/write-up/dockerlabs/medio/dance-samba.md).

# Dance-Samba

## Maquina

<figure><img src="/files/z89Pbc95mIkNHAj1WyAj" alt=""><figcaption></figcaption></figure>

## Reconocimiento

### Nmap

```bash
sudo nmap -p- --open -sSCV --min-rate 5000 -vvv -n -Pn 172.17.0.2 -oN nmap.txt
```

```
PORT    STATE SERVICE     REASON         VERSION
21/tcp  open  ftp         syn-ack ttl 64 vsftpd 3.0.5
| ftp-syst: 
|   STAT: 
| FTP server status:
|      Connected to ::ffff:172.17.0.1
|      Logged in as ftp
|      TYPE: ASCII
|      No session bandwidth limit
|      Session timeout in seconds is 300
|      Control connection is plain text
|      Data connections will be plain text
|      At session startup, client count was 3
|      vsFTPd 3.0.5 - secure, fast, stable
|_End of status
| ftp-anon: Anonymous FTP login allowed (FTP code 230)
|_-rw-r--r--    1 0        0              69 Aug 19 19:03 nota.txt
22/tcp  open  ssh         syn-ack ttl 64 OpenSSH 9.6p1 Ubuntu 3ubuntu13.4 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   256 a2:4e:66:7d:e5:2e:cf:df:54:39:b2:08:a9:97:79:21 (ECDSA)
| ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBHAIsNDTAA/0XQjWsHZBAXtCPn1pDRyMrwgY5uPsCW08SIzEJ61AV9NHFoF09tEsl3wOl9R92ZXrHyslcnacApY=
|   256 92:bf:d3:b8:20:ac:76:08:5b:93:d7:69:ef:e7:59:e1 (ED25519)
|_ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBnq5Qj1E5WOsDQlUkhGJ3A5DhC7WSVKpx0LeT1YVXN6
139/tcp open  netbios-ssn syn-ack ttl 64 Samba smbd 4.6.2
445/tcp open  netbios-ssn syn-ack ttl 64 Samba smbd 4.6.2
MAC Address: 02:42:AC:11:00:02 (Unknown)
Service Info: OSs: Unix, Linux; CPE: cpe:/o:linux:linux_kernel

Host script results:
| p2p-conficker: 
|   Checking for Conficker.C or higher...
|   Check 1 (port 21783/tcp): CLEAN (Couldn't connect)
|   Check 2 (port 47237/tcp): CLEAN (Couldn't connect)
|   Check 3 (port 58197/udp): CLEAN (Timeout)
|   Check 4 (port 31957/udp): CLEAN (Failed to receive data)
|_  0/4 checks are positive: Host is CLEAN or ports are blocked
| smb2-time: 
|   date: 2024-09-01T11:53:05
|_  start_date: N/A
|_clock-skew: 0s
| smb2-security-mode: 
|   3:1:1: 
|_    Message signing enabled but not required
```

### FTP

<figure><img src="/files/nUq9YPb9mawmoWyrJFK9" alt=""><figcaption></figcaption></figure>

Vemos que en `nota.txt` nos da lo que pueden ser 1 usuarios y una contraseña

<figure><img src="/files/TgX5e98VIo8Gq35Xg3lI" alt=""><figcaption></figcaption></figure>

```
macarena:donald
```

### SMB

Vamos a ver si podemos listar recursos compartidos en [SMB](/barre/apuntes/general/redes/protocolos/smb.md)

```
smbclient -L //172.17.0.2/
```

<figure><img src="/files/PiHbiw6IrKHiDomgH4wD" alt=""><figcaption></figcaption></figure>

Por ahora vemos que si que podemos listar recursos compartidos, y que `macarane` esta hay por lo que si que parece ser un usuario, ahora usamos la herramienta de [smbmap](/barre/apuntes/red-team/tools/smbmap.md) para ver los permisos en los recursos compartidos que tiene `macarena`, haciendo uso de la contraseña `donald`

```bash
smbmap -H 172.17.0.2 -u macarena -p donald
```

```
    ________  ___      ___  _______   ___      ___       __         _______
   /"       )|"  \    /"  ||   _  "\ |"  \    /"  |     /""\       |   __ "\
  (:   \___/  \   \  //   |(. |_)  :) \   \  //   |    /    \      (. |__) :)
   \___  \    /\  \/.    ||:     \/   /\   \/.    |   /' /\  \     |:  ____/
    __/  \   |: \.        |(|  _  \  |: \.        |  //  __'  \    (|  /
   /" \   :) |.  \    /:  ||: |_)  :)|.  \    /:  | /   /  \   \  /|__/ \
  (_______/  |___|\__/|___|(_______/ |___|\__/|___|(___/    \___)(_______)
-----------------------------------------------------------------------------
SMBMap - Samba Share Enumerator v1.10.4 | Shawn Evans - ShawnDEvans@gmail.com<mailto:ShawnDEvans@gmail.com>
                     https://github.com/ShawnDEvans/smbmap

[*] Detected 1 hosts serving SMB                                                                                                  
[*] Established 1 SMB connections(s) and 1 authenticated session(s)                                                          
                                                                                                                             
[+] IP: 172.17.0.2:445	Name: 172.17.0.2          	Status: Authenticated
	Disk                                                  	Permissions	Comment
	----                                                  	-----------	-------
	print$                                            	READ ONLY	Printer Drivers
	macarena                                          	READ, WRITE	
	IPC$                                              	NO ACCESS	IPC Service (adef937c7fee server (Samba, Ubuntu))
[*] Closed 1 connections
```

Nos conectamos al recurso compartido de `macarena`&#x20;

```bash
smbclient //172.17.0.2/macarena -U macarena
```

Miramos lo que tiene y vemos la flag de `user.txt` y un `.bash_history`

<figure><img src="/files/1neg17sI7Ry9XcX4kXbZ" alt=""><figcaption></figcaption></figure>

No hay nada en `.bash_history`

{% code title="User flag" %}

```
ef65ad731de0ebabcb371fa3ad4972f1
```

{% endcode %}

En este directorio `/macarena` a parte de leer podemos escribir por lo que podemos  subir archivos&#x20;

## Explotación

Vamos a generar un par de **claves ssh** Publica/Privada para poder conectarnos por ssh a el usuario macarena

### Generamos claves ssh

```bash
ssh-keygen -t rsa -b 4096
```

<figure><img src="/files/KEDiMZo1PZ00bEmaCY0D" alt=""><figcaption></figcaption></figure>

Nos copiamos la clave publica a nuestro directorio de 2 formas, con el nombre de `authorized_key` y con el nombre con el que se genera `id_rsa.pub`

<figure><img src="/files/LvuhyliywsXIUWhIsZDL" alt=""><figcaption></figcaption></figure>

### Subimos las claves por SMB

Después simplemente hay que subirlos al directorio .ssh que tendremos que crear previamente

```bash
mkdir .ssh
```

<figure><img src="/files/NHML0XvcLA1alYbRI4RQ" alt=""><figcaption></figcaption></figure>

### Accedemos por ssh

Ahora que ya esta subida la clave publica, podemos usar nuestra clave privada para acceder por ssh desde nuestra maquina como el usuario macarena

```bash
ssh -i /home/barre/.ssh/id_rsa macarena@172.17.0.2
```

<figure><img src="/files/LlQxAtaWEX1E8tL05wSb" alt=""><figcaption></figcaption></figure>

## Escalado de privilegios

Miramos los permisos de este usuario

<figure><img src="/files/b8jb26BQWnCeRrvtBEhg" alt=""><figcaption></figcaption></figure>

Nos falta la contraseña de macarena, miramos que tiene por ahí

<figure><img src="/files/vOPmG9Wa1BG6tic04HjT" alt=""><figcaption></figcaption></figure>

Encontramos un hash que crackeamos con [CyberChef](https://cyberchef.org/)

<figure><img src="/files/utpfuDO0goz3ho8XrRYU" alt=""><figcaption></figcaption></figure>

Ahora ya podemos mirar los permisos que tiene `macarane`

<figure><img src="/files/elZOzfsQxVJof8caG3fz" alt=""><figcaption></figcaption></figure>

Este permiso nos permite leer ficheros, tenemos que buscar el archivo que hay que leer

<figure><img src="/files/MytmoTrrZTE8fV1QKEP4" alt=""><figcaption></figcaption></figure>

Este archivo contiene la contraseña de `root`

```
root:rooteable2
```

<figure><img src="/files/oTf7THlvgEbm8CgLyWYR" alt=""><figcaption></figcaption></figure>

{% code title="Root flag" %}

```
efb6984b9b0eb57451aca3f93c8ce6b7
```

{% endcode %}

## Conclusión

Una maquina muy chula para practicar con SMB, ya que esta muy bien equilibrada en cuanto a su dificultada.
