# Passive Information Gathering

## WHOIS

[WHOIS](https://en.wikipedia.org/wiki/WHOIS) es un protocolo que utiliza el puerto 43 TCP para realizar consultas a una base de datos que contiene información de dominios, IP o sistemas autónomos.

{% tabs %}
{% tab title="WHOIS web site" %}
Podemos consumir este servicio mediante múltiples sitios web, como [whois.domaintools.com](https://whois.domaintools.com/):

<figure><img src="/files/SFScYlfiyDixLmhRLkfv" alt=""><figcaption><p>WHOIS web site</p></figcaption></figure>
{% endtab %}

{% tab title="WHOIS CLI" %}

> En caso de querer usar whois en sistemas Windows, este se debe descargar desde [Sysinternals WHOIS](https://learn.microsoft.com/en-gb/sysinternals/downloads/whois).

Para ejecutar consultas desde sistemas Linux, podemos usar los siguientes comandos:

```bash
export TARGET="target.com"
whois $TARGET
```

En Windows, el comando sería como el siguiente:

```batch
whois.exe target.co
```

{% endtab %}
{% endtabs %}

## Registros DNS

Para mayor información, revisar el siguiente [enlace](https://www.cloudflare.com/es-es/learning/dns/dns-records/).

{% tabs %}
{% tab title="Registros del tipo A" %}

```bash
# Records del tipo A para un dominio
export TARGET="target.com"
nslookup $TARGET
dig $TARGET @1.1.1.1
# Records del tipo A para un subdominio
nslookup -query=A $TARGET
dig a $TARGET @1.1.1.1
```

{% endtab %}

{% tab title="Registros del tipo PTR" %}

```bash
nslookup -query=PTR 1.1.1.1
dig -x 1.1.1.1 @1.1.1.1
```

{% endtab %}

{% tab title="Cualquier registro existente" %}

```bash
export TARGET="target.com"
nslookup -query=ANY $TARGET
dig any $TARGET @8.8.8.8
```

{% endtab %}
{% endtabs %}

{% tabs %}
{% tab title="Registros del tipo TXT" %}

```bash
export TARGET="target.com"
nslookup -query=TXT $TARGET
dig txt $TARGET @1.1.1.1
```

{% endtab %}

{% tab title="Registros del tipo MX" %}

```bash
export TARGET="target.com"
nslookup -query=MX $TARGET
dig mx $TARGET @1.1.1.1
```

{% endtab %}
{% endtabs %}

## Enumeración pasiva de subdominios

Obtener información de los subdominios a través de servicios de terceros.

### VirusTotal

Podemos obtener información relacionada con un dominio cuando lo analizamos. En la pestaña `RELATIONS` podemos obtener registros DNS:

<figure><img src="/files/iLdR5WWGTQiBMPu7Wiv9" alt=""><figcaption><p>VirusTotal</p></figcaption></figure>

### Certificados

Es posible obtener subdominios mediante los certificados SSL/TLS. Esto se puede mediante el `Certificate Transparency` (CT).

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

* [URL](https://search.censys.io/certificates?q=)

<figure><img src="/files/c3TeHSNPG7RPU1YF3ZcX" alt=""><figcaption><p>Censys</p></figcaption></figure>
{% endtab %}

{% tab title="Crtsh" %}

* [URL](https://crt.sh/)

<figure><img src="/files/PHBdratWwC04IKic9Xy8" alt=""><figcaption><p>Crtsh</p></figcaption></figure>
{% endtab %}

{% tab title="Certificate Transparency" %}
Esto lo podemos consumir desde la CLI mediante un `cURL`:

```bash
export TARGET="facebook.com"
curl -s "https://crt.sh/?q=${TARGET}&output=json" | jq -r '.[] | "\(.name_value)\n\(.common_name)"' | sort -u > "${TARGET}_crt.sh.txt"
```

* `curl -s` realiza un cURL especificando que muestre lo menos posible en el output
* `https://crt.sh/?q=${TARGET}&output=json` se indica que buscaremos el dominio definido en la variable `TARGET` en un formato json
* `jq -r '.[]' "\(.name_value)\n\(.common_name)"'` procesar la salida en formato json e imprime el valor `name value` y `common name`
* `sort -u` ordenar la salida de forma alfabética y remueve los duplicados

En caso de usar HTTPS, la comunicación se debe realizar mediante OpenSSL:

```bash
export TARGET="facebook.com"
export PORT="443"
openssl s_client -ign_eof 2>/dev/null <<<$'HEAD / HTTP/1.0\r\n\r' -connect "${TARGET}:${PORT}" | openssl x509 -noout -text -in - | grep 'DNS' | sed -e 's|DNS:|\n|g' -e 's|^\*.*||g' | tr -d ',' | sort -u
```

{% endtab %}
{% endtabs %}

### Google Dorks

```
site:google.com -inurl:www
site:google.com -site:www.google.com
```

* Para no incluir un subdominio, podemos usar el operador `-`

### Automatización de enumeración pasiva de subdominios

Esto se puede automatizar utilizando múltiples herramientas, como [theHarvester](https://github.com/laramies/theHarvester).

{% tabs %}
{% tab title="theHarvester" %}
Esta herramienta recolecta:

* Emails
* Nombres
* Subdominios
* Direcciones IP
* URL

Utiliza múltiples origenes para recolectar la información:

* [**Baidu**](https://www.baidu.com/)**:** buscador Baidu
* **Bufferoverun:** usa datos desde el [Rapid7's Project Sonar](https://www.rapid7.com/research/project-sonar/)
* [**Crtsh**](https://crt.sh/)**:** búsqueda de certificados
* [**Hackertarget**](https://hackertarget.com/)**:** escáner de vulnerabilidades online y network intelligence para ayudar a organizaciones
* **Otx:** [AlientVault Open Threat Exchange](https://otx.alienvault.com/)
* [**Rapiddns**](https://rapiddns.io/)**:** herramienta de consulta de DNS, que facilita la consulta de subdominios o sitios que utilizan la misma IP
* [**Sublist3r**](https://github.com/aboul3la/Sublist3r)**:** herramienta rápida de enumeración de subdominios
* [**Threatcrowd**](http://www.threatcrowd.org/)**:** herramienta open source de threat intelligence
* **\[Threatmine]:** minería de datos para threat intelligence
* **Trello:** busca en Trello boards (utiliza google)
* [**Urlscan**](https://urlscan.io/)**:** un sandbox para la web que es un escáner de URL y sitios web
* **vhost:** buscar virtual hosts
* [**VirusTotal**](https://www.virustotal.com/gui/home/search)**:** buscador de dominio
* [**Zoomeye**](https://www.zoomeye.org/)**:** shodan versión chino

Lo primero es crear un archivo `source.txt` para agrupar todos estos orígenes:

```
baidu
bufferoverun
crtsh
hackertarget
otx
projecdiscovery
rapiddns
sublist3r
threatcrowd
trello
urlscan
vhost
virustotal
zoomeye
```

Ejecutamos `theHarvester` usando el siguiente comando:

```bash
export TARGET="facebook.com"
cat sources.txt | while read source; do theHarvester -d "${TARGET}" -b $source -f "${source}_${TARGET}";done
```

Para extraer todos los subdominios, se utiliza el siguiente comando:

```bash
cat *.json | jq -r '.hosts[]' 2>/dev/null | cut -d':' -f 1 | sort -u > "${TARGET}_theHarvester.txt"
```

{% endtab %}
{% endtabs %}

## Identificación pasiva de infraestructura

### Netcraft

Con [Netcraft](https://sitereport.netcraft.com/?url=) podemos obtener información del servidor sin tener que interactuar con él directamente:

<figure><img src="/files/3iToXrr2plDP6hcXRRkG" alt=""><figcaption><p>Netcraft</p></figcaption></figure>

### Wayback Machine

{% tabs %}
{% tab title="Web Site" %}
[Internet Archive](https://archive.org/) posee la opción [Wayback Machine](https://web.archive.org/), con la cual, podemos encontrar versiones anteriores de un sitio web:

<figure><img src="/files/UXMFBj2BFGpiKNMLywgs" alt=""><figcaption><p>Archive - Wayback Machine</p></figcaption></figure>
{% endtab %}

{% tab title="CLI" %}
Podemos usar Wayback Machine mediante la herramienta [waybackurls](https://github.com/tomnomnom/waybackurls). Para poder instalar esta herramienta, podemos usar el siguiente comando:

```bash
go install github.com/tomnomnom/waybackurls@latest
```

Para poder usarla, podemos usar los siguientes comandos:

```bash
waybackurls -dates https://facebook.com > waybackurls.txt
cat domains.txt | waybackurls > urls
```

{% endtab %}
{% endtabs %}


---

# 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://w0lf-f4ng.gitbook.io/cheat-sheet/pentesting-web/information-gathering/passive-information-gathering.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.
