Security Testing: OWASP, Penetration Testing e SAST/DAST

Testes Automatizados · 6 de julho de 2026

📖 2 min de leitura

Tipos de Security Testing

Tipo Descrição Automação
SAST Análise estática de código ✅ Alta
DAST Teste dinâmico de aplicação ✅ Alta
SCA Análise de composição de software ✅ Alta
IAST Teste interativo ⚠️ Média
Pentest Teste manual de penetração ❌ Baixa

OWASP Top 10 (2021)

A01 – Broken Access Control

# VULNERÁVEL
@app.route('/pedido/')
def get_pedido(id):
    # Não verifica ownership!
    return Pedido.query.get(id)

# SEGURO
@app.route('/pedido/')
@login_required
def get_pedido(id):
pedido = Pedido.query.filter_by(
id=id,
usuario_id=current_user.id
).first_or_404()
return pedido

A02 – Cryptographic Failures

# VULNERÁVEL
senha = "senha123"  # Texto puro!

# SEGURO
from cryptography.fernet import Fernet

key = Fernet.generate_key() # Armazenar em vault!
cipher = Fernet(key)
senha_hash = bcrypt.hashpw(senha.encode(), bcrypt.gensalt())

A03 – Injection

-- VULNERÁVEL (SQL Injection)
query = f"SELECT * FROM users WHERE email = '{email}'"

-- SEGURO (Parameterized)
cursor.execute("SELECT * FROM users WHERE email = {6727d158e4474b0847515bd23a8ee4bebd5f1aac7a18bc968e51d8985dccb442}s", (email,))


SAST – Static Application Security Testing

SonarQube

# GitHub Actions
  • name: SonarCloud Scan
  • uses: SonarSource/sonarcloud-github-action@master env: SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

    # sonar-project.properties
    sonar.projectKey=myproject
    sonar.sources=src
    sonar.tests=tests
    sonar.python.coverage.reportPaths=coverage.xml
    sonar.security Risks=high,critical

Semgrep

# Install
pip install semgrep

# Run
semgrep --config=auto .

# Custom rule
rules:
- id: hardcoded-secret
pattern: $SECRET = "$VALUE"
message: Hardcoded secret found
severity: ERROR
languages: [python]


DAST – Dynamic Application Security Testing

OWASP ZAP

# CLI scan
docker run -t owasp/zap2docker-stable 
  zap-baseline.py 
  -t https://example.com 
  -J zap-report.json

# GitHub Actions

  1. name: OWASP ZAP Scan

uses: zaproxy/[email protected]
with:
target: 'https://staging.example.com'
rules_rules_name: 'api-scan'


SCA – Software Composition Analysis

Snyk

# Install
npm install -g snyk

# Test
snyk test

# Monitor
snyk monitor

# GitHub Action

  1. name: Snyk Security Scan

uses: snyk/actions/node@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}


Conclusão

Security testing deve ser integrado ao pipeline. As chaves são:

  1. Automação – SAST, DAST, SCA no CI/CD
  2. OWASP – Conheça as vulnerabilidades principais
  3. Pentests – Regular, para complementar automação
  4. Remediação – Não é só detectar, é corrigir
  5. Cultura – Segurança é responsabilidade de todos