https://github.com/oussamaelmessaoudi/securing-mqtt
Security Audit and Hardening of MQTT Protocol using Mosquitto Broker on Ubuntu/WSL. This repository documents vulnerabilities, exploitation, and secure configuration of MQTT with authentication, ACLs, TLS/SSL, and firewall rules.
https://github.com/oussamaelmessaoudi/securing-mqtt
acl firewall iot mosquitto mqtt security ssl tls ubuntu wsl
Last synced: 7 months ago
JSON representation
Security Audit and Hardening of MQTT Protocol using Mosquitto Broker on Ubuntu/WSL. This repository documents vulnerabilities, exploitation, and secure configuration of MQTT with authentication, ACLs, TLS/SSL, and firewall rules.
- Host: GitHub
- URL: https://github.com/oussamaelmessaoudi/securing-mqtt
- Owner: oussamaelmessaoudi
- Created: 2025-11-26T18:14:28.000Z (8 months ago)
- Default Branch: main
- Last Pushed: 2025-11-27T10:29:12.000Z (8 months ago)
- Last Synced: 2025-11-29T15:12:29.848Z (8 months ago)
- Topics: acl, firewall, iot, mosquitto, mqtt, security, ssl, tls, ubuntu, wsl
- Language: Shell
- Homepage:
- Size: 17.6 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# π MQTT Security Audit & Hardening Project



**A comprehensive security assessment and hardening guide for Mosquitto MQTT Broker**
*From vulnerable to fortress: Securing IoT communication one topic at a time*
[π Report](#-project-report) β’ [π― Demo](#-live-demonstration) β’ [π οΈ Setup](#-quick-start) β’ [π Results](#-security-improvements)
---
## π― Project Overview
This project exposes critical vulnerabilities in default MQTT broker configurations and demonstrates professional-grade hardening techniques to secure IoT communications. Through systematic penetration testing and defense implementation, we transform an insecure message broker into a production-ready secure system.
### π¨ The Problem
```
β Anonymous access enabled β
Password-based authentication
β Unencrypted communications β
TLS 1.3 encryption
β No access control β
Topic-based ACL
β Exposed to network attacks β
Firewall-protected
```
### π Academic Context
- **Course**: CyberSecurity - Computer Engineering & Embedded Systems
- **Institution**: UniversitΓ© Ibn Zohr, FacultΓ© des Sciences d'Agadir
- **Program**: IISE (Ingénierie Informatique et Systèmes Embarqués)
- **Professor**: Monsef Boughrous
- **Academic Year**: 2025/2026
---
## π Table of Contents
- [Project Phases](#-project-phases)
- [Attack Surface](#-attack-surface-discovered)
- [Arsenal](#-security-arsenal)
- [Quick Start](#-quick-start)
- [Exploitation Demo](#-exploitation--defense)
- [Results](#-security-improvements)
- [Documentation](#-documentation)
- [Team](#-team)
---
## π Project Phases
### Phase 1οΈβ£ : Reconnaissance & Setup
```bash
π Network scanning with Nmap
π‘ Service enumeration
π Traffic baseline analysis
π Default configuration audit
```
### Phase 2οΈβ£ : Vulnerability Assessment
```bash
πͺ Authentication bypass testing
π Encryption analysis
π― Access control evaluation
β οΈ Security misconfiguration identification
```
### Phase 3οΈβ£ : Exploitation & Proof of Concept
```bash
π₯ Anonymous connection attacks
π΅οΈ Credential interception
π¨ Unauthorized message publishing
π Man-in-the-middle demonstrations
```
### Phase 4οΈβ£ : Hardening & Verification
```bash
π Password authentication implementation
π TLS/SSL certificate deployment
π‘οΈ Access Control Lists (ACL) configuration
π§± Firewall rule enforcement
β
Post-hardening validation
```
---
## π― Attack Surface Discovered
| Vulnerability | Severity | CVSS Score | Status |
|--------------|----------|------------|---------|
| Anonymous Access | π΄ **CRITICAL** | 9.8 | β
Fixed |
| Plaintext Communication | π΄ **CRITICAL** | 8.2 | β
Fixed |
| No Topic Authorization | π **HIGH** | 7.5 | β
Fixed |
| Exposed Management Port | π **HIGH** | 6.8 | β
Fixed |
| Default Configuration | π‘ **MEDIUM** | 5.3 | β
Fixed |
---
## π οΈ Security Arsenal
### Offensive Tools
```yaml
Reconnaissance:
- Nmap 7.94
- Wireshark 4.0+
Exploitation:
- Mosquitto Clients
- MQTT Explorer
- Custom Python Scripts
```
### Defensive Tools
```yaml
Hardening:
- OpenSSL 3.0
- Mosquitto 2.0.x
- UFW / Windows Firewall
Configuration:
- ACL Files
- Password Database
- TLS Certificates
```
---
## π Quick Start
### Prerequisites
```bash
# Linux (Ubuntu/Debian)
sudo apt update
sudo apt install mosquitto mosquitto-clients wireshark nmap openssl
# Verify installation
mosquitto -h
```
### 1. Clone the Repository
```bash
git clone https://github.com/oussamaelmessaoudi/securing-mqtt.git
cd securing-mqtt
```
### 2. Initial Setup (Vulnerable State)
```bash
# Start with insecure configuration
sudo cp config/mosquitto.conf.vulnerable /etc/mosquitto/mosquitto.conf
sudo systemctl restart mosquitto
# Verify vulnerability
mosquitto_sub -h localhost -t '#' -v # No authentication required! π¨
```
### 3. Run Security Audit
```bash
# Network reconnaissance
sudo nmap -sV -p 1883,8883 localhost
# Traffic capture
sudo wireshark -i lo -f "tcp port 1883"
# Exploit demo
./scripts/exploit_demo.sh
```
### 4. Apply Hardening
```bash
# Generate certificates
./scripts/generate_certs.sh
# Create password database
sudo mosquitto_passwd -c /etc/mosquitto/passwd iotuser
# Apply secure configuration
sudo cp config/mosquitto.conf.secure /etc/mosquitto/mosquitto.conf
sudo cp acl/acl.conf /etc/mosquitto/
# Restart and verify
sudo systemctl restart mosquitto
./scripts/verify_hardening.sh
```
---
## π₯ Exploitation & Defense
### Before Hardening: Easy Access
```bash
# Anyone can subscribe to ALL topics
$ mosquitto_sub -h localhost -t '#' -v
sensor/temperature 23.5
sensor/humidity 65
home/lights/bedroom ON
camera/stream rtsp://192.168.1.100 # π± Privacy breach!
# Wireshark shows credentials in plaintext
MQTT Payload: username:admin password:admin123 # π¨ Exposed!
```
### After Hardening: Access Denied
```bash
# Connection without credentials fails
$ mosquitto_sub -h localhost -t '#'
Connection error: Not authorized
# TLS encryption required
$ mosquitto_sub -h localhost -p 8883 -t 'sensor/#' \
--cafile certs/ca.crt \
-u iotuser -P SecurePass123!
sensor/temperature 23.5 # β
Encrypted & Authenticated
# Wireshark shows encrypted traffic
TLSv1.3 [Application Data] # π Cannot be decrypted!
```
---
## π Security Improvements
### Vulnerability Remediation
| Metric | Before | After | Improvement |
|--------|--------|-------|-------------|
| **Open Ports** | 1883 (unsecured) | 8883 (TLS only) | π 100% encrypted |
| **Authentication** | β None | β
Password + ACL | π‘οΈ Full protection |
| **Encryption** | β Plaintext | β
TLS 1.3 | π Military grade |
| **Access Control** | β Global access | β
Topic-based | π― Granular control |
| **Attack Surface** | π΄ Critical | π’ Minimal | β¬οΈ 95% reduction |
### π¬ Visual Evidence
```
πΈ Screenshots included:
βββ nmap_scan_before.png # Port 1883 open, no encryption
βββ nmap_scan_after.png # Only port 8883, TLS enabled
βββ wireshark_plaintext.png # Captured passwords
βββ wireshark_encrypted.png # Encrypted traffic
βββ attack_success.png # Unauthorized access demo
βββ attack_blocked.png # Hardened system blocks attack
```
---
## π Documentation
### π Project Report (15-20 pages)
Comprehensive security audit documentation following professional standards:
- Executive Summary
- Vulnerability Analysis
- Exploitation Results
- Hardening Implementation
- Before/After Comparison
- Actionable Recommendations
π₯ **[Download Full Report](docs/MQTT_Security_Report.pdf)**
### π€ Presentation (10-15 slides)
Professional presentation covering:
- Problem Statement
- Attack Demonstrations
- Defense Implementation
- Live Demo
- Key Findings
π₯ **[View Presentation](presentation/MQTT_Security_Slides.pdf)**
---
## π Repository Structure
```
securing-mqtt/
βββ π config/
β βββ mosquitto.conf.vulnerable # Insecure baseline
β βββ mosquitto.conf.secure # Hardened configuration
β βββ README.md # Configuration guide
β
βββ π acl/
β βββ acl.conf # Topic-based access rules
β βββ examples/ # ACL patterns
β
βββ π certs/
β βββ ca.crt # Certificate Authority
β βββ server.crt # Server certificate
β βββ generate_certs.sh # Certificate generation script
β βββ .gitignore # (Private keys excluded)
β
βββ π scripts/
β βββ setup_vulnerable.sh # Deploy vulnerable broker
β βββ exploit_demo.sh # Demonstrate attacks
β βββ apply_hardening.sh # Secure the broker
β βββ verify_security.sh # Post-hardening tests
β βββ mqtt_test_client.py # Python testing tool
β
βββ π scans/
β βββ nmap_results/
β βββ wireshark_captures/
β βββ vulnerability_reports/
β
βββ π docs/
β βββ MQTT_Security_Report.pdf # Full technical report
β βββ Hardening_Checklist.md # Step-by-step guide
β
βββ π presentation/
β βββ MQTT_Security_Slides.pdf # Project presentation
β
βββ README.md # You are here! π―
```
---
## π Key Learnings
### π§ Technical Skills Acquired
- β
MQTT protocol analysis and security assessment
- β
TLS/SSL certificate generation and management
- β
Network traffic analysis with Wireshark
- β
Firewall configuration and port security
- β
Access Control List (ACL) design
- β
Penetration testing methodology
- β
Security hardening best practices
### π Cybersecurity Principles Applied
- **Defense in Depth**: Multiple security layers
- **Least Privilege**: Topic-based access control
- **Encryption at Rest & Transit**: TLS implementation
- **Authentication & Authorization**: Password + ACL
- **Security by Default**: Hardened configurations
---
## π‘οΈ Hardening Checklist
- [x] **Authentication**
- [x] Disable anonymous access
- [x] Implement password authentication
- [x] Use strong password policies
- [x] **Encryption**
- [x] Generate TLS certificates
- [x] Enable TLS 1.3
- [x] Disable insecure protocols (TLS 1.0/1.1)
- [x] **Access Control**
- [x] Configure topic-based ACL
- [x] Implement read/write separation
- [x] Test authorization rules
- [x] **Network Security**
- [x] Close unencrypted port (1883)
- [x] Configure firewall rules
- [x] Restrict broker to localhost/VPN
- [x] **Monitoring & Logging**
- [x] Enable security logging
- [x] Monitor failed connection attempts
- [x] Set up alerting
---
## π― Demonstration Highlights
### π΄ Attack Phase
```bash
β Successful anonymous connection
β Captured credentials via Wireshark
β Unauthorized topic subscription
β Message interception and modification
β Privacy breach demonstration
```
### π’ Defense Phase
```bash
β Connection attempts blocked
β Encrypted traffic (Wireshark verification)
β ACL preventing unauthorized access
β Firewall blocking external connections
β Security monitoring active
```
---
## π₯ Team
**IISE Students - Cybersecurity Project**
Oussama ELMESSAOUDI
Yassine EL ATIKI
Abdessamad ASKLOU
Nourreddine AIT MOULAY BRAHIM
*UniversitΓ© Ibn Zohr, FacultΓ© des Sciences d'Agadir*
> π‘ **Note**: This project was conducted in a controlled lab environment. All security testing was performed ethically on systems owned and operated by the project team.
---
## π License & Ethics
This project is for **educational purposes only**.
β οΈ **Ethical Guidelines:**
- All testing performed in isolated lab environment
- No unauthorized network scanning
- No attacks on production systems
- Compliant with academic integrity policies
---
## π References & Resources
- [MQTT Protocol Specification](http://mqtt.org)
- [Mosquitto Documentation](https://mosquitto.org/documentation/)
- [OWASP IoT Security](https://owasp.org/www-project-internet-of-things/)
- [NIST Cybersecurity Framework](https://www.nist.gov/cyberframework)
---
## π Contact & Feedback
For questions about this project:
- π§ Email: [oussama.elmessaoudi.39@edu.uiz.ac.ma]
- π Course: CyberSecurity - Prof. Monsef Boughrous
---
### β If you found this project helpful, please star the repository!
**Built with π by IISE Cybersecurity Team**
*Securing the IoT, one broker at a time*