A small toolkit to simulate DNS traffic (including malicious bursts), apply a basic firewalling pipeline (rate-limiting + YARA-based filtering + iptables drop), and visualize results in a Streamlit dashboard.
- Raw DNS traffic generator using Scapy
- Sliding-window rate limiter over DNS queries
- YARA rule matching for domain-based detection
- Automatic
iptablesblocking for matched malicious IPs - Streamlit dashboard with:
- Attack launcher and live log views
- Firewall run + results (logs, metrics, visualizations)
- Comparative analysis (before vs after filtering)
dns-firewall/
dashboard/
app.py # Streamlit entrypoint with tabs
attack.py # Launch raw attack and visualize traffic
firewall.py # Run firewall pipeline and visualize outputs
comparative_analysis.py # Before/After charts and key metrics
simulator/
main.py # Orchestrates full pipeline (attack → rate limit → YARA → drop)
raw_attack.py # Launches only the raw attack
query.py # Generates DNS queries (benign and malicious)
rate_limiter.py # Sliding window rate limiter (logs decisions)
filter.py # YARA match over domains
drop_ip.py # Applies iptables drops, emits to_block/not_blocked
data/
leg_domain.csv # Benign/legitimate domains
mal_dom.csv # Malicious/blacklisted domains
YARA_RULES/
rules.yara # YARA signatures for malicious domains
requirements.txt
LICENSE
README.md
Several scripts reference absolute Linux paths for logs and data (e.g. /mnt/97gb/projects/dns-firewall/...). Adjust these to match your environment:
- Logs directory (expected by dashboard and simulator):
/mnt/97gb/projects/dns-firewall/logs/- Files produced/consumed:
dns_query_log.csv(fromsimulator/query.py)rate_limiter_logs.csv(fromsimulator/rate_limiter.py)yara_matched.csv(fromsimulator/filter.py)to_block.csv,not_blocked.csv(fromsimulator/drop_ip.py)
- Data directory:
/mnt/97gb/projects/dns-firewall/data/leg_domain.csv/mnt/97gb/projects/dns-firewall/data/mal_dom.csv
- YARA rules:
/mnt/97gb/projects/dns-firewall/YARA_RULES/rules.yara
If you are running on Windows or a different Linux path, search the repo for /mnt/97gb/projects/dns-firewall and update to a suitable location. Ensure the logs/ directory exists.
- Python 3.8+
sudoaccess (required for Scapy raw packets andiptables)- Linux is recommended for
iptablescompatibility
python3 -m venv .venv
source .venv/bin/activate # On Windows: .venv\\Scripts\\activate
pip install -r requirements.txt
# Create logs directory expected by the pipeline
mkdir -p /mnt/97gb/projects/dns-firewall/logsIf you are not using the default absolute path, create your own logs directory and update the hard-coded paths inside:
simulator/query.pysimulator/rate_limiter.pysimulator/filter.pysimulator/drop_ip.pydashboard/attack.py,dashboard/firewall.py,dashboard/comparative_analysis.py
Runs: simulate traffic → rate limit → YARA match → block with iptables → write logs
sudo python3 simulator/main.pysudo python3 simulator/raw_attack.pyThe dashboard gives you three tabs: Attack, Firewall, Comparative Analysis.
streamlit run dashboard/app.py-
simulator/main.py- Calls
launch_attack()to generate mixed benign/malicious DNS queries - Runs
rate_limit()to producerate_limiter_logs.csv - Runs
rules_match()to produceyara_matched.csv - Runs
drop_matched_ips()to createto_block.csvandnot_blocked.csvand applyiptablesrules
- Calls
-
Dashboard tabs
- Attack: launches
simulator/raw_attack.pyand visualizesdns_query_log.csv - Firewall: runs the full pipeline and shows logs + charts
- Comparative Analysis: compares
dns_query_log.csv(before) vsnot_blocked.csv(after)
- Attack: launches
- Rate limiter (
simulator/rate_limiter.py):WINDOW_SIZE = 10secondsTHRESHOLD = 10requests/window
- Traffic generator (
simulator/query.py):TOTAL_UNIQUE_IPS,MIN_QUERIES,MAX_QUERIES,QUERY_INTERVAL,QUERY_TYPES
- YARA rules (
YARA_RULES/rules.yara): customize detection logic for domains
sudoandiptableschanges require caution. Consider running in a VM or container. To undo rules, you may need to flush or delete theiptablesentries that were added.- Scapy uses raw sockets and typically needs root privileges.
- Large
requirements.txtincludes many packages not strictly required by the core pipeline; prune as needed.
- "File not found" for logs: ensure the
logs/folder exists at the path referenced in the code. - No charts in dashboard: verify CSVs are generated (run Firewall tab or
simulator/main.py). iptableserrors on non-Linux systems: skipdrop_ip.pyor guard the call for your OS.
See LICENSE.