An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

          

# πŸ” MQTT Security Audit & Hardening Project

![MQTT Security](https://img.shields.io/badge/MQTT-Security%20Audit-red?style=for-the-badge&logo=mqtt)
![Status](https://img.shields.io/badge/Status-Complete-success?style=for-the-badge)
![License](https://img.shields.io/badge/License-Academic-blue?style=for-the-badge)

**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*