Skip to content

cumakurt/forti_rule_police

Repository files navigation

forti_rule_police

License: AGPL v3 Python 3.9+ Version

FortiGate Firewall Configuration Security Analyzer

🇹🇷 Türkçe dokümantasyon için README_tr.md

A production-grade Python tool that automatically parses FortiGate configuration files (.conf and YAML export format), performs comprehensive security analysis on all firewall policies, zones, and services, and generates professional HTML, PDF, and JSON security reports.


Developer


Features

  • Dual Format Parser — Supports both .conf (config/edit/set) and YAML export format; auto-detects format
  • FortiOS Parser — Full support for FortiOS 6.x and 7.x config syntax (including multi-line values: certificates, HTML)
  • Risk Scoring Engine — Weighted scoring with multiplier methodology
  • Zone Isolation Analysis — Zone-to-zone traffic matrix and violation detection
  • Internet Exposure — Identifies all Internet-accessible services and VIP/DNAT mappings
  • Target IP Analysis — Bidirectional access analysis for specified IPs (target.txt)
  • --only-target Mode — Filter reports to only rules matching target IPs/subnets (PCI scope, audit focus)
  • MITRE ATT&CK Mapping — Findings mapped to ATT&CK techniques
  • HTML Report — Dark-themed, interactive SOC-style report with Plotly charts and DataTables
  • PDF Report — Professional, printable A4 report with executive summary and findings
  • Traffic Flow Graphs — NetworkX-based zone connectivity analysis

Screenshots

CLI Analysis HTML Report Risk Findings
CLI Analysis HTML Report Risk Findings
Zone Matrix PDF Report Target Analysis
Zone Matrix PDF Report Target Analysis
Duplicate Rules Executive Summary
Duplicate Rules Executive Summary

Project Structure

forti_rule_police/
├── forti_rule_police.py           # CLI entry point (Click + Rich)
├── requirements.txt               # Dependencies
├── target.txt                     # Target IPs for bidirectional analysis
├── img/                           # Screenshots for documentation
│
├── config/
│   └── settings.py                # Application constants and configuration
│
├── models/                        # Data models (dataclasses)
│   ├── policy.py                  # FirewallPolicy
│   ├── zone.py                    # Interface, Zone
│   ├── address.py                 # Address, AddressGroup
│   ├── service.py                 # Service, ServiceGroup, VirtualIP
│   └── risk.py                    # RiskFinding, RiskLevel
│
├── utils/                         # Shared utilities
│   ├── logger.py                  # Structured JSON logger (SIEM-compatible)
│   ├── ip_utils.py                # IP/CIDR helpers
│   └── port_utils.py              # Port/service reference database
│
├── parser/                        # FortiOS config parsers
│   ├── config_parser.py           # Core FortiOS block parser
│   ├── policy_parser.py           # Firewall policy extractor
│   ├── zone_parser.py             # Interface/zone extractor
│   ├── address_parser.py          # Address object extractor
│   ├── service_parser.py          # Service object extractor
│   └── nat_parser.py              # VIP/NAT rule extractor
│
├── analyzer/                      # Analysis engines
│   ├── risk_analyzer.py           # Risk scoring engine
│   ├── zone_analyzer.py           # Zone isolation analysis
│   ├── traffic_flow_analyzer.py   # NetworkX traffic flow graphs
│   ├── internet_exposure_analyzer.py  # Internet exposure analysis
│   └── target_analyzer.py         # Target IP bidirectional analysis
│
├── reporter/                      # Report generators
│   ├── html_reporter.py           # Jinja2 + Plotly HTML report
│   ├── pdf_reporter.py            # ReportLab PDF report
│   └── templates/
│       └── report_base.html       # Dark SOC-theme HTML template
│
└── output/                        # Generated reports
    └── *.html / *.pdf

Installation

git clone https://github.com/cumakurt/forti_rule_police.git
cd forti_rule_police

python3 -m venv venv
source venv/bin/activate      # Linux/macOS
# venv\Scripts\activate       # Windows

pip install -r requirements.txt

Usage

# Basic analysis — both HTML and PDF
python forti_rule_police.py --config firewall.conf

# With target IP analysis
python forti_rule_police.py --config firewall.conf --targets target.txt

# Report only for rules matching target IPs/subnets (requires --targets)
python forti_rule_police.py --config firewall.conf --targets target.txt --only-target

# Custom output directory
python forti_rule_police.py --config firewall.conf --targets target.txt --output ./reports/

# HTML only
python forti_rule_police.py --config firewall.conf --format html

# PDF only
python forti_rule_police.py --config firewall.conf --format pdf

# JSON only (machine-readable, SIEM/API)
python forti_rule_police.py --config firewall.conf --format json

# All formats (default: html + pdf + json)
python forti_rule_police.py --config firewall.conf --format all

# Specific VDOM (multi-VDOM environments)
python forti_rule_police.py --config firewall.conf --vdom production

# Verbose logging
python forti_rule_police.py --config firewall.conf --verbose

# Full help
python forti_rule_police.py --help

Target IP Analysis (target.txt)

Copy target.txt.example to target.txt and add IP addresses or CIDR subnets — one per line. Comments start with #.

# Web Servers
192.168.10.10
192.168.10.11

# Database Subnet
10.20.30.0/24

# Management Host
172.16.1.100

The analyzer will determine for each target:

  • Inbound traffic — which rules allow access to this IP, from where, on which ports
  • Outbound traffic — which rules allow this IP to reach other destinations
  • Internet accessibility — whether the host is reachable from WAN
  • Lateral movement risk — whether DMZ or other untrusted zones can reach this host

--only-target Mode

When --only-target is used together with --targets, the tool produces a filtered report that includes only firewall rules whose source or destination overlaps with the IPs/subnets in the target file. All findings, zone violations, exposed services, duplicates, and traffic flows are restricted to these rules.

python forti_rule_police.py --config firewall.conf --targets target.txt --only-target

Use this when you need a focused security assessment for specific hosts or subnets (e.g., critical servers, PCI scope, or audit targets).


Risk Scoring Methodology

Risk_Score = base_weight × Σ(multipliers)

Base Weights:
  ANY-ANY Accept:               9.0
  Management Internet Exposure: 9.5
  Internet → Internal (no UTM): 7.0
  DMZ → LAN:                    7.5
  DMZ → Management:             9.0
  No Logging:                   5.0
  Insecure Protocol:            4.0

Multipliers:
  srcaddr = all:       ×2.0
  dstaddr = all:       ×1.5
  service = ALL:       ×1.8
  logtraffic = off:    ×1.4
  No UTM (Internet):   ×1.2

Score → Level:
  0.0 – 2.9   → INFO
  3.0 – 4.9   → LOW
  5.0 – 6.9   → MEDIUM
  7.0 – 8.9   → HIGH
  9.0+        → CRITICAL

Security Checks Performed

Check Description
ANY-ANY rule detection Catches unrestricted bypass rules
Internet → Management Management interface exposure
Internet → Internal Direct WAN to LAN access
DMZ → LAN isolation Zone isolation violations
No logging Visibility gaps
No UTM/IPS Unprotected Internet traffic
Insecure protocols Telnet, FTP, HTTP, SNMPv1/v2
VIP/DNAT resolution Real internal IP exposure mapping
Disabled rules Residual attack surface

MITRE ATT&CK Coverage

Finding Technique
Internet RDP access T1021.001, T1133
Internet SSH access T1021.004, T1133
DMZ → LAN T1021, T1210
ANY-ANY rule T1190
Logging disabled T1562.004
Telnet/FTP use T1040
HTTP management T1040, T1557

Supported FortiOS Versions

  • FortiOS 6.x
  • FortiOS 7.x (including 7.4)
  • Multi-VDOM configurations supported

Changelog

v1.1.0 (March 2026)

  • --only-target — Filter reports to only rules matching target file IPs/subnets; excludes all/any wildcards
  • WAN detection fix — Removed hardcoded port1 as WAN; now uses config role field only
  • .conf multi-line parsing — Correctly parses certificates, HTML buffers, and other multi-line quoted values
  • Parser robustness — Resolved shlex fallback warnings when parsing .conf files

v1.0.0 (March 2026)

  • Initial release: risk scoring, zone isolation, internet exposure, target analysis, HTML/PDF/JSON reports

Contributing

Contributions are welcome. Please open an Issue or submit a Pull Request. See CONTRIBUTING.md for guidelines.


References



License

This project is licensed under the GNU Affero General Public License v3.0 (AGPL-3.0).
See the LICENSE file for details.

  • You may use, modify, and distribute this software
  • You must disclose source code of modified versions when providing network services
  • You must preserve license and copyright notices

Version: 1.1.0 | March 2026

About

A production-grade Python tool that automatically parses FortiGate `.conf` files, performs comprehensive security analysis on all firewall policies, zones, and services, and generates professional HTML and PDF security reports.

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors