# BANDIT

{% hint style="warning" %}
Hay muchas formas de completar los niveles.

Falta describir los últimos niveles.
{% endhint %}

## ¬ Level 0

{% hint style="info" %}
&#x20;The goal of this level is for you to log into the game using SSH. The host to which you need to connect is **bandit.labs.overthewire.org**, on port 2220. The username is **bandit0** and the password is **bandit0**. Once logged in, go to the [Level 1](https://overthewire.org/wargames/bandit/bandit1.html) page to find out how to beat Level 1.
{% endhint %}

## ¬ Level 0 **→ Level 1**

{% hint style="info" %}
&#x20;The password for the next level is stored in a file called **readme** located in the home directory. Use this password to log into bandit1 using SSH. Whenever you find a password for a level, use SSH (on port 2220) to log into that level and continue the game.
{% endhint %}

Lo primero que haremos será conectarnos mediante ssh con las credenciales que nos da la pagina.

* USER: **bandit0**
* PASS: **bandit0**
* PORT: **2220**

```bash
ssh bandit0@bandit.labs.overthewire.org -P 2220
```

Con un simple listado en el propio directorio podremos ver un archivo **README,** que mediante con una **cat** podremos ver la credencial del siguiente nivel.

```bash
cat readme
```

![](/files/-MeB4nB5qvJUj9p9dejQ)

## ¬ Level 1 → Level 2

{% hint style="info" %}
&#x20;The password for the next level is stored in a file called **-** located in the home directory.
{% endhint %}

Ahora tenemos que modificar el usuario de la conexión ssh.

* USER: **bandit1**
* PASS: **boJ9jbbUNNfktd78OOpsqOltutMc3MY1**

Con un listado en el propio directorio vemos un archivo llamado **"-",** para poder ver el contenido del archivo haremos lo siguiente.

```bash
cat $(pwd)/-
```

Con esto podremos ver la credencial del siguiente nivel.

![](/files/-MeB6SIkHZHDXCsNT_oP)

## ¬ Level 2 → Level 3

{% hint style="info" %}
&#x20;The password for the next level is stored in a file called **spaces in this filename** located in the home directory.
{% endhint %}

Modificamos el usuario de la conexión ssh.

* USER: **bandit2**
* PASS: **CV1DtqXWVFXTvM2F0k09SHz0YwRINYA9**

Vemos que en el propio directorio hay un archivo, el nombre del archivo contiene espacios, para ver ese directorio podemos hacer un cat escribir la primeras letras y tabular, y con esto veremos la credencial del siguiente nivel.

```bash
cat spaces\ in\ this\ filename
```

![](/files/-MeB6UQ6IIns8RoZcHOc)

## ¬ Level 3 → Level 4

{% hint style="info" %}
&#x20;The password for the next level is stored in a hidden file in the **inhere** directory.
{% endhint %}

Modificamos el usuario de la conexión ssh.

* USER: **bandit3**
* PASS: **UmHadQclWmgdLOKQ3YNgjWxGoRMb5luK**

Vemos que tenemos un directorio, al ingresar en el vemos que hay un archivo oculto en el.

Para listar el archivo oculto simplemente hacemos un cat con el nombre del archivo completo y nos dará la credencial del siguiente nivel.

```bash
cat .hidden
```

![](/files/-MeB7RcAySfCU1ZNKrlX)

## ¬ Level 4 → Level 5

{% hint style="info" %}
&#x20;The password for the next level is stored in the only human-readable file in the **inhere** directory. Tip: if your terminal is messed up, try the “reset” command.
{% endhint %}

Modificamos el usuario de la conexión ssh.

* USER: **bandit4**
* PASS: **pIwrPrtPN36QITSp3EQaw936yaFoFgAB**

Vemos que contiene un directorio y al ingresar en el vemos que hay varios archivos que comienzan con un **"-",** para no ir uno por uno vamos a realizar el siguiente comando.

```bash
file $(pwd)/*
```

Con esto veremos el archivo en formato ASCII text, donde estará la credencial del siguiente nivel.

```bash
cat $(pwd)/-file07
```

![](/files/-MeB8TOjDOqJ0IiLc5V8)

## ¬ Level 5 → Level 6

{% hint style="info" %}
The password for the next level is stored in a file somewhere under the **inhere** directory and has all of the following properties:

* human-readable
* 1033 bytes in size
* not executable
  {% endhint %}

Modificamos el usuario de la conexión ssh.

* USER: **bandit5**
* PASS: **koReBOKuIDDepwhWk7jZC0RTdopnAYKh**

Vemos que tenemos una carpeta que contiene mas carpetas con archivos, y nos dice que el archivo es leíble, pesa 1033 bytes y no es ejecutable.

```bash
find inthere/ -type f -readable -size 1033c ! -executable 2>/dev/null | xargs cat | tr -d ' '
```

![](/files/-MeG6vKTQtnjtpJquNpV)

## ¬ Level 6 → Level 7

{% hint style="info" %}
The password for the next level is stored **somewhere on the server** and has all of the following properties:

* owned by user bandit7
* owned by group bandit6
* 33 bytes in size
  {% endhint %}

Modificamos el usuario de la conexión ssh.

* USER: **bandit6**
* PASS: **DXjZPULLxYr17uwoI01bNLQbtFemEgo7**

Vemos que no tenemos nada en el directorio, pero nos da los siguientes datos:&#x20;

* Dueño: bandit7
* Grupo: bandit6
* Tamaño: 33 bytes

```bash
find / -type f -user bandit7 -group bandit6 -size 33c 2>/dev/null | xargs cat
```

![](/files/-MeG8Pfk7rLn4pg1M3rG)

## ¬ Level 7 → Level 8

{% hint style="info" %}
&#x20;The password for the next level is stored in the file **data.txt** next to the word **millionth..**
{% endhint %}

Modificamos el usuario de la conexión ssh.

* USER: **bandit7**
* PASS: **HKBPTKQnIay4Fw76bEy8PVxKEDQRKTzs**

Tenemos un archivo .txt y nos dice que la contraseña esta al lado de la palabra **millionth.**

```bash
grep "milionth" data.txt | awk '{print $2}'
```

![](/files/-MeG9N6FIi0EI1mvr033)

## ¬ Level 8 → Level 9

{% hint style="info" %}
&#x20;The password for the next level is stored in the file **data.txt** and is the only line of text that occurs only once.
{% endhint %}

Modificamos el usuario de la conexión ssh.

* USER: **bandit8**
* PASS: **cvX2JJa4CFALtqS87jk27qwqGhBM9plV**

Vemos una archivo donde hay muchas credenciales y y nuestra credencial solo aparece una vez.

```bash
sort data.txt | uniq -u 
```

![](/files/-MeGB8PeDy1V6IVzuxwv)

## ¬ Level 9 → Level 10

{% hint style="info" %}
&#x20;The password for the next level is stored in the file **data.txt** in one of the few human-readable strings, preceded by several ‘=’ characters.
{% endhint %}

Modificamos el usuario de la conexión ssh.

* USER: **bandit9**
* PASS: **UsvVyFSfZZWbi6wgC7dAFyFuR6jQQUhR**

Vemos que tenemos un archivo **data,** y nos dice que un carácter leíble es el **"="**

```bash
strings data | grep "===" | tail -n 1 | awk '{print $2}'
```

![](/files/-MeGET_q27_ZyPDdoxOF)

## ¬ Level 10 → Level 11

{% hint style="info" %}
&#x20;The password for the next level is stored in the file **data.txt**, which contains base64 encoded data
{% endhint %}

Modificamos el usuario de la conexión ssh.

* USER: **bandit10**
* PASS: **truKLdjsbJ5g7yyJ2X2R0o3a5HQJFuLk**

```bash
base64 -d data.txt | awk '{print $4}'
```

![](/files/-MeGFReMvDnNK08w11qN)

## ¬ Level 11 →  Level 12

{% hint style="info" %}
&#x20;The password for the next level is stored in the file **data.txt**, where all lowercase (a-z) and uppercase (A-Z) letters have been rotated by 13 positions.
{% endhint %}

Modificamos el usuario de la conexión ssh.

* USER: **bandit11**
* PASS: **IFukwKGsFW8MOq3IRFqrxE1hxTNEbUPR**

Vemos que esta codificado como **ROT13.**

```bash
cat data.txt | tr 'A-Za-z' 'N-ZA-Mn-za-m' | awk '{print $4}'
```

![](/files/-MeGH_PT7VADuxIPNxCn)

## ¬ Level 12 →  Level 13

{% hint style="info" %}
&#x20;The password for the next level is stored in the file **data.txt**, which is a hexdump of a file that has been repeatedly compressed. For this level it may be useful to create a directory under /tmp in which you can work using mkdir. For example: mkdir /tmp/myname123. Then copy the datafile using cp, and rename it using mv (read the manpages!)
{% endhint %}

Modificamos el usuario de la conexión ssh.

* USER: **bandit12**
* PASS: **5Te8Y4drgCRfCx8ugdwuEX8KFC6k2EUu**

Vemos que tenemos un archivo en **hexadecimal,** copiamos el archivo y lo pegamos en nuestra maquina para analizarlo.

Con la herramienta **xxd** podremos ver que hay un contenido, lo guardamos en otro archivo y vemos que es un **.gzip.** Al descomprimirlo vemos que hay otro comprimible dentro, volvemos a descomprimirlo y hay otro.

Vamos a scriptearlo para mayor comodidad.

```bash
#!/bin/bash

name_compressed=$(7z l $1 | grep "Name" -A 2 | tail -n 1 | awk 'NF{print $NF}')
7z x $1 > /dev/null 2>&1

while true; do
	7z l $name_compressed > /dev/null 2>&1
	
	if [ "$(echo $?)" == "0" ];then
		decompressed_next=$(7z l $name_compressed | grep "Name" -A 2 | tail -n 1 | awk 'NF{print $NF}')
		7z x $name_compressed > /dev/null 2>&1 && name_compressed=$decompressed_next
	else
		cat $name_compressed | awk '{print $4}'; rm data* 2>/dev/null
		exit 1
	fi
done
```

![](/files/-MeQayqQH-YDvxyK_GtS)

## ¬ Level 13 → Level 14

{% hint style="info" %}
&#x20;The password for the next level is stored in **/etc/bandit\_pass/bandit14 and can only be read by user bandit14**. For this level, you don’t get the next password, but you get a private SSH key that can be used to log into the next level. **Note:** **localhost** is a hostname that refers to the machine you are working on.
{% endhint %}

Modificamos el usuario de la conexión ssh.

* USER: **bandit13**
* PASS: **8ZjyCRiBWFYkneahHwxCv3wb2a1ORpYL**

Vemos que tenemos una **id\_rsa**, vamos a conectarnos al usuario **bandit14.**

```bash
ssh -i sshkey.private bandit14@localhost
```

![](/files/-MeQb2bJh4u6bDFjF7bs)

## ¬ Level 14 → Level 15

{% hint style="info" %}
&#x20;The password for the next level can be retrieved by submitting the password of the current level to **port 30000 on localhost**.
{% endhint %}

Modificamos el usuario de la conexión ssh.

* USER: **bandit14**
* PASS: **4wcYUJFw0k0XLShlDzztnTBHiqxU3b3e**

El enunciado nos dice que tenemos que enviar la contraseña al puerto 30000 en localhost.

```bash
nc localhost 30000 <PASSWORD>
```

![](/files/-MeQavMYgqk2nQgh-xMS)

## ¬ Level 15 → Level 16

{% hint style="info" %}
The password for the next level can be retrieved by submitting the password of the current level to **port 30001 on localhost** using SSL encryption.

**Helpful note: Getting “HEARTBEATING” and “Read R BLOCK”? Use -ign\_eof and read the “CONNECTED COMMANDS” section in the manpage. Next to ‘R’ and ‘Q’, the ‘B’ command also works in this version of that command…**
{% endhint %}

Modificamos el usuario de la conexión ssh.

* USER: **bandit15**
* PASS: **BfMYroe26WYalil77FoDi9qh59eK5xNr**

Tenemos que mandar la contraseña usando la encriptación ssl.

```bash
echo <PASSWORD> | openssl s_client -quiet -connect localhost:30001
```

![](/files/-MeQesLTDbyJV5FV-d8V)

## ¬ Level 16 → Level 17

{% hint style="info" %}
&#x20;The credentials for the next level can be retrieved by submitting the password of the current level to **a port on localhost in the range 31000 to 32000**. First find out which of these ports have a server listening on them. Then find out which of those speak SSL and which don’t. There is only 1 server that will give the next credentials, the others will simply send back to you whatever you send to it.
{% endhint %}

Modificamos el usuario de la conexión ssh.

* USER: **bandit16**
* PASS: **cluFn7wTiGryunymYOu4RcffSxQluehd**

Nos dice que tenemos que buscar un puerto abierto en un rango que nos ofrece. Vemos que tenemos nmap para escanear los puertos.

```bash
nmap --open -T5 -v -n localhost
```

Luego nos dice que tenemos que mandarle la contraseña por ssl.

```bash
openssl s_client -connect localhost:31790
```

Y nos da una **id\_rsa,** para conectarnos al usuario **bandit17** y ver la contraseña del mismo.

![](/files/-MeQomRiw50QkQ2_BSpF)

## ¬ Level 17 → Level 18

{% hint style="info" %}
There are 2 files in the homedirectory: **passwords.old and passwords.new**. The password for the next level is in **passwords.new** and is the only line that has been changed between **passwords.old and passwords.new**

**NOTE: if you have solved this level and see ‘Byebye!’ when trying to log into bandit18, this is related to the next level, bandit19**
{% endhint %}

Modificamos el usuario de la conexión ssh.

* USER: **bandit17**
* PASS: **xLYVMN9WE5zQ5vHacb0sZEVqbrp7nBTn**

Con la herramienta diff podemos ver los cambios en los dos archivos, donde podremos ver la contraseña del siguiente nivel.

```bash
diff passwords.new passwords.old
```

![](/files/-MettXxT3CBi22KhTTES)

## &#x20;¬ Level 18 → Level 19

Modificamos el usuario de la conexión ssh.

* USER: **bandit18**
* PASS: **kfBf3eYk5BPBRzwjqutbbfE887SVc5Yd**

Vemos que nos echa de la sesión ssh, intentamos ejecutar comandos con la sesión ssh y vemos que podemos ejecutar comandos, vamos a ver la contraseña.

```bash
ssh bandit18@bandit.labs.overthewire.org -p 2220 cat readme
```

![](/files/-MetuqVeSmvhGV6f2tLZ)

## ¬ Level 19 → Level 20

Modificamos el usuario de la conexión ssh.

* USER: **bandit19**
* PASS: **IueksS7Ubh8G3DCwVzrTd8rAVOwq3M5x**

Vemos un ejecutable, y al ejecutarlo nos pide un comando, vamos a ver la flag.

```bash
./bandit20-do cat /etc/bandit_pass/bandit20
```

![](/files/-MetvkIEiTAsEtkf-HWC)

## ¬ Level 20 →  Level 21

Modificamos el usuario de la conexión ssh.

* USER: **bandit20**
* PASS: **GbKksEFF4yrVs6il55v6gwY5aVje5f0j**

Abriremos dos sesiones de ssh, en una nos pondremos en escucha y en la otra ejecutaremos el ejecutable con el puerto en escucha, pasamos la contraseña en la sesión de escucha y listo&#x20;

![](/files/-MetzadwaKrw-uY_5us8)

## ¬ Level 21 → Level 22

Modificamos el usuario de la conexión ssh.

* USER: **bandit21**
* PASS: **gE269g2h3mw3pwgrj0Ha9Uoqen1c9DGr**

Vemos que hay una tarea cron, al ver la tarea cron vemos que la contraseña esta alojada en una carpeta /tmp.

![](/files/-Meu0jtuGK3qOOOV97TR)

## ¬ Level 22 →  Level 23

Modificamos el usuario de la conexión ssh.

* USER: **bandit22**
* PASS: **Yk7owGAcWjwMVRwrTesJEwB7WVOiILLI**

Vemos otra tarea cron, donde tendremos que pasar md5sum para poder ver la contraseña.

![](/files/-Meu5W6tym80rofEaObG)

![](/files/-Meu5YQ43_LCAIw2sXXu)

## ¬ Level 23 → Level 24

Modificamos el usuario de la conexión ssh.

* USER: **bandit23**
* PASS: **jc1udXuA1tiHqjIsL8yaapX5XIAI6i0n**

Vemos que tenemos un archivo cron, que ejecuta el siguiente scrip.

![](/files/-MeuhTiBXDvd3OPST6n8)

Creamos un script donde copiamos la contraseña y la peguemos a un directorio temporal que creamos.

A continuación copiamos el script a la ruta /var/spool/bandti24 y toca esperar.

## ¬ Level 24 → Level 25

Modificamos el usuario de la conexión ssh.

* USER: **bandit24**
* PASS: **UoMYTrfrBFHyQXmg6gzctqAwOmw1IohZ**

Creamos un directorio temp, y creamos un script para generar el pin code y la contraseña

![](/files/-MfT14StWihT_LOWGeuY)

Y luego lo mandamos por nc para que nos de la siguiente contraseña.

```bash
cat dictionary.txt | nc localhost 30002 | grep -v -E "Wrong|Please"
```

![](/files/-MfT1LDwKhrB3O7fX1Cw)

## ¬ Level 25 → Level 26

Modificamos el usuario de la conexión ssh.

* USER: **bandit25**
* PASS: **uNG9O58gUE7snukf3bvZ0rxhtnjzSGzG**

Nos da una id\_rsa para conectarnos a bandit 26, pero nos echa de la sesion, investigando vemos que reducir la ventana de la shell para que aparezca el "more" y poder sacar una bash.

## ¬ Level 26 → Level 27

Modificamos el usuario de la conexión ssh.

* USER: **bandit26**
* PASS: **5czgV9L3Xx8JPOyRbXh6lQbmIOWvPT6Z**

En el directorio vemos un ejecutable de bandit27, simplemente lanzamos el script con bash -p y nos convertimos en bandit27.

## ¬ Level 27 → Level 28

Modificamos el usuario de la conexión ssh.

* USER: **bandit27**
* PASS: **3ba3118a22e93127a4ed485be72ef5ea**

Nos descargamos un repositorio de github, y dentro esta la contraseña del siguiente nivel.

## ¬ Level 28 → Level 29

Modificamos el usuario de la conexión ssh.

* USER: **bandit28**
* PASS: **0ef186ac70e04ea33b4c1853d2526fa2**

Nos descargamos un repositorio de github, y vemos en los log del git, si han habido cambios

git log -p

## ¬ Level 29 → Level 30

Modificamos el usuario de la conexión ssh.

* USER: **bandit29**
* PASS: **bbc96594b4e001778eee9975372716b2**

Nos descargamos un repositorio de github, y vemos los branch.

git branch -r

git checkout dev

Volvemos a ver los logs&#x20;

git log -p&#x20;

Y tenemos la contraseña

## ¬ Level 30 → Level 31

Modificamos el usuario de la conexión ssh.

* USER: **bandit30**
* PASS: **5b90576bedb2cc04c86a9e924ce42faf**

Nos descargamos un repositorio de github, y vemos que contiene un tag, al verlo vemos la contraseña del siguiente nivel.

git tag

git show secret

## ¬ Level 31 → Level 32

Modificamos el usuario de la conexión ssh.

* USER: **bandit31**
* PASS: **47e603bb428404d265f59c42920d81e5**

Nos descargamos un repositorio de github, y tenemos que subir un archivo al repositorio, pero antes tenemos que borrar un archivo del repo.

git add key.txt

git commit "ALGO"

git push -u origin master

Y vemos la contraseña del siguiente usuario.

## ¬ Level 32 → Level 33

Modificamos el usuario de la conexión ssh.

* USER: **bandit32**
* PASS: **56a9bf19c63d650ce78e6ec0354ee45e**

Para escapar de esta consola, simplemente ponemos $0 y tenemos una bash, ya podremos ver la contraseña del siguiente nivel.

## ¬ Level 33 → Level 34

Modificamos el usuario de la conexión ssh.

* USER: **bandit33**
* PASS: **c9c3199ddf4121b10cf581a98d51caee**

Terminamos todos los niveles.


---

# Agent Instructions: 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:

```
GET https://alerodriguezm99.gitbook.io/bariho/walkthrough/overthewire/bandit.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
