Centralizing Vulnerability Management: A Practical Guide to DefectDojo, Trivy, and Semgrep

Security tutorial - IT technology blog
Security tutorial - IT technology blog

Centralizing Security: From Log Chaos to a Single Pane of Glass

I learned the hard way that running security tools isn’t the same as being secure. After a midnight SSH brute-force attack hit one of my production nodes, I realized my ‘security stack’ was just a pile of unread logs. If you use Trivy for Docker images, Semgrep for code, and Nmap for networking, you are likely staring at three incompatible report formats spread across your CI/CD pipelines. Tracking what is fixed and what is still a threat becomes a massive logistical mess.

DefectDojo bridges this gap. It acts as a sophisticated clearinghouse, supporting over 150 security scanners out of the box. Instead of auditing 15 different microservices individually, you see your entire infrastructure’s risk profile on one screen. It turns raw data into a prioritized to-do list.

Quick start (5 min)

Docker Compose is the most reliable way to spin up DefectDojo without wrestling with PostgreSQL or Redis configurations. You can have the environment ready in under five minutes.

1. Clone and Launch

git clone https://github.com/DefectDojo/django-DefectDojo
cd django-DefectDojo
# Execute the setup scripts
./dc-build.sh
./dc-up.sh postgres-redis

Give the system a moment to complete database migrations. Watch the logs using docker-compose logs -f initializer. When the process finishes, it will display a randomly generated admin password. Copy this immediately; you will need it for the first login.

2. Access the Dashboard

Point your browser to http://localhost:8080. Use admin as the username and the password you just saved. You now have an enterprise-grade vulnerability management platform running on your machine.

Deep dive: Integrating Your Scanners

DefectDojo thrives on data. Let’s look at how to export results from three essential tools so they can be ingested correctly.

Step 1: Code Scanning with Semgrep

Semgrep identifies insecure patterns, like hardcoded credentials or SQL injection risks, in your source code. You must output the results as JSON for a smooth import.

# Scan your repository and save the JSON output
semgrep scan --json -o semgrep_results.json .

Step 2: Container Scanning with Trivy

Trivy is the gold standard for container security. It flags outdated OS packages and vulnerable dependencies (like a buggy version of OpenSSL).

# Scan a container image and generate a JSON report
trivy image --format json -o trivy_results.json my-app:latest

Step 3: Network Scanning with Nmap

Nmap reveals which ports are exposed to the public internet. DefectDojo processes Nmap’s XML output to help you track unauthorized service changes.

# Scan a specific IP range and save as XML
nmap -sV -oX nmap_results.xml 192.168.1.0/24

Step 4: Importing Findings

DefectDojo uses a simple hierarchy: Product TypeProductEngagement. Think of a ‘Product’ as your application and an ‘Engagement’ as a specific test cycle, such as a ‘Weekly Sprint Scan’.

  • Product: The project name (e.g., “Fintech-API-v2”).
  • Engagement: The context (e.g., “Q2 Security Audit”).
  • Test: The container for specific scanner outputs.

Inside your Engagement, click the Plus (+) icon and choose Import Scan Results. Select the corresponding scanner type—such as “Trivy Scan”—upload your file, and the dashboard will automatically categorize findings by severity.

Advanced usage: Automating the Pipeline

Manual uploads are fine for a one-off audit, but they don’t scale. Effective engineers use the DefectDojo API to push results automatically during the CI/CD process. This ensures every merge request is checked for new vulnerabilities.

Automating with Python

Retrieve your API Key from the ‘User’ section in the UI. The following Python script demonstrates how to programmatically upload a Semgrep report to a specific engagement.

import requests

DD_URL = "http://localhost:8080/api/v2/import-scan/"
API_KEY = "your_api_key_here"
ENGAGEMENT_ID = 1 

headers = {"Authorization": f"Token {API_KEY}"}
files = {'file': open('semgrep_results.json', 'rb')}
data = {
    'scan_type': 'Semgrep JSON Report',
    'engagement': ENGAGEMENT_ID,
    'active': True,
    'verified': False
}

response = requests.post(DD_URL, headers=headers, data=data, files=files)
print("Success!" if response.status_code == 201 else f"Error: {response.text}")

GitHub Actions Integration

Integrate security directly into your workflow. The snippet below runs Trivy and pushes the results to your dashboard every time you push code.

- name: Run Trivy Scan
  run: trivy image --format json -o trivy-results.json my-image:latest

- name: Upload to DefectDojo
  run: |
    curl -X POST "$DD_URL/api/v2/import-scan/" \
    -H "Authorization: Token $DD_API_KEY" \
    -F "[email protected]" \
    -F "scan_type=Trivy Scan" \
    -F "engagement=$DD_ENGAGEMENT_ID"

Practical Tips for Long-Term Success

A vulnerability dashboard is only useful if it remains clean. Here is how to manage the noise.

Leverage Deduplication

Deduplication is DefectDojo’s most powerful feature. If you scan the same image daily, you don’t need 30 identical tickets for the same bug. Enable deduplication in the system settings to consolidate these into a single finding that tracks when the issue was first and last seen. This can reduce your manual review load by up to 90%.

Establishing a Review Workflow

Scanners often produce false positives. When a report is imported, findings are ‘Active’ but unverified. A security lead should review ‘High’ and ‘Critical’ items, marking legitimate threats as ‘Verified.’ If a finding is irrelevant to your environment, mark it as a ‘False Positive’ to remove it from your metrics.

Enforce SLAs

Use DefectDojo to track Service Level Agreements (SLAs). You might mandate that ‘Critical’ vulnerabilities are patched within 24 hours, while ‘Medium’ issues have a 14-day window. The system will highlight overdue items, making it easy to see which teams need support. This data-driven approach keeps security standards high without causing team burnout.

Prioritize High-Impact Fixes

Ignore the ‘Low’ findings until the ‘Critical’ ones are gone. Use the dashboard to find common vulnerabilities across multiple products. Fixing one shared library vulnerability often resolves security debt across five or six microservices simultaneously.

Share: