2023-08-03 19:12:22 +00:00
|
|
|
|
# 1883 - MQTT渗透测试(Mosquitto)
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
|
|
|
|
<details>
|
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
<summary><a href="https://cloud.hacktricks.xyz/pentesting-cloud/pentesting-cloud-methodology"><strong>☁️ HackTricks云 ☁️</strong></a> -<a href="https://twitter.com/hacktricks_live"><strong>🐦 Twitter 🐦</strong></a> - <a href="https://www.twitch.tv/hacktricks_live/schedule"><strong>🎙️ Twitch 🎙️</strong></a> - <a href="https://www.youtube.com/@hacktricks_LIVE"><strong>🎥 Youtube 🎥</strong></a></summary>
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
- 你在一家**网络安全公司**工作吗?你想在HackTricks中看到你的**公司广告**吗?或者你想获得**PEASS的最新版本或下载PDF格式的HackTricks**吗?请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
- 发现我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)收藏品[**The PEASS Family**](https://opensea.io/collection/the-peass-family)
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
- 获取[**官方PEASS和HackTricks周边产品**](https://peass.creator-spring.com)
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
- **加入**[**💬**](https://emojipedia.org/speech-balloon/) [**Discord群组**](https://discord.gg/hRep4RUj7f)或[**电报群组**](https://t.me/peass)或**关注**我在**Twitter**上的[**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/hacktricks_live)**。**
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
- **通过向[hacktricks repo](https://github.com/carlospolop/hacktricks)和[hacktricks-cloud repo](https://github.com/carlospolop/hacktricks-cloud)提交PR来分享你的黑客技巧。**
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
|
|
|
|
</details>
|
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
## 基本信息
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
MQTT代表MQ Telemetry Transport。它是一种发布/订阅的**极其简单和轻量级的消息传递协议**,专为受限设备和带宽有限、延迟高或不可靠的网络设计。设计原则是在尽量减少网络带宽和设备资源需求的同时,也尽量确保可靠性和一定程度的传递保证。这些原则也使得该协议成为新兴的“机器对机器”(M2M)或“物联网”世界中连接设备的理想选择,并适用于带宽和电池功耗有限的移动应用。
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
**默认端口:** 1883
|
2021-10-18 11:21:18 +00:00
|
|
|
|
```
|
2020-09-24 18:58:31 +00:00
|
|
|
|
PORT STATE SERVICE REASON
|
|
|
|
|
1883/tcp open mosquitto version 1.4.8 syn-ack
|
|
|
|
|
```
|
2023-08-03 19:12:22 +00:00
|
|
|
|
## 检查流量
|
2020-09-24 18:58:31 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
MQTT代理在收到CONNECT数据包后会发送CONNACK数据包作为响应。返回码0x00表示凭据有效,返回码0x05表示凭据无效。0x05示例:
|
2022-02-19 19:42:58 +00:00
|
|
|
|
|
2022-03-09 12:12:51 +00:00
|
|
|
|
![](<../.gitbook/assets/image (645) (1).png>)
|
2022-02-19 19:42:58 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
### [**暴力破解MQTT**](../generic-methodologies-and-resources/brute-force.md#mqtt)
|
2022-02-19 19:42:58 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
## MQTT渗透测试
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
**身份验证是完全可选的**,即使正在执行身份验证,**默认情况下不使用加密**(凭据以明文形式发送)。仍然可以执行中间人攻击来窃取密码。
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
要连接到MQTT服务,可以使用:[https://github.com/bapowell/python-mqtt-client-shell](https://github.com/bapowell/python-mqtt-client-shell),并订阅所有主题:
|
2021-10-18 11:21:18 +00:00
|
|
|
|
```
|
2020-07-15 15:43:14 +00:00
|
|
|
|
> connect (NOTICE that you need to indicate before this the params of the connection, by default 127.0.0.1:1883)
|
|
|
|
|
> subscribe "#" 1
|
|
|
|
|
> subscribe "$SYS/#"
|
|
|
|
|
```
|
2023-08-03 19:12:22 +00:00
|
|
|
|
你还可以使用[**https://github.com/akamai-threat-research/mqtt-pwn**](https://github.com/akamai-threat-research/mqtt-pwn)
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
你还可以使用:
|
2022-02-19 19:42:58 +00:00
|
|
|
|
```bash
|
|
|
|
|
apt-get install mosquitto mosquitto-clients
|
|
|
|
|
mosquitto_sub -t 'test/topic' -v #Subscriribe to 'test/topic'
|
|
|
|
|
```
|
2023-08-03 19:12:22 +00:00
|
|
|
|
或者你可以运行以下代码尝试连接到一个没有身份验证的MQTT服务,订阅所有主题并监听它们:
|
2020-07-15 15:43:14 +00:00
|
|
|
|
```python
|
|
|
|
|
#This is a modified version of https://github.com/Warflop/IOT-MQTT-Exploit/blob/master/mqtt.py
|
|
|
|
|
import paho.mqtt.client as mqtt
|
|
|
|
|
import time
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
HOST = "127.0.0.1"
|
|
|
|
|
PORT = 1883
|
|
|
|
|
|
|
|
|
|
def on_connect(client, userdata, flags, rc):
|
2023-08-03 19:12:22 +00:00
|
|
|
|
client.subscribe('#', qos=1)
|
|
|
|
|
client.subscribe('$SYS/#')
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
|
|
|
|
def on_message(client, userdata, message):
|
2023-08-03 19:12:22 +00:00
|
|
|
|
print('Topic: %s | QOS: %s | Message: %s' % (message.topic, message.qos, message.payload))
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
|
|
|
|
def main():
|
2023-08-03 19:12:22 +00:00
|
|
|
|
client = mqtt.Client()
|
|
|
|
|
client.on_connect = on_connect
|
|
|
|
|
client.on_message = on_message
|
|
|
|
|
client.connect(HOST, PORT)
|
|
|
|
|
client.loop_start()
|
|
|
|
|
#time.sleep(10)
|
|
|
|
|
#client.loop_stop()
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2023-08-03 19:12:22 +00:00
|
|
|
|
main()
|
2020-07-15 15:43:14 +00:00
|
|
|
|
```
|
2023-08-03 19:12:22 +00:00
|
|
|
|
## 更多信息
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
来自这里:[https://morphuslabs.com/hacking-the-iot-with-mqtt-8edaf0d07b9b](https://morphuslabs.com/hacking-the-iot-with-mqtt-8edaf0d07b9b)
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
### 发布/订阅模式 <a href="#b667" id="b667"></a>
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
发布/订阅模式由以下组成:
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
* **发布者**:将消息发布到代理中的一个或多个主题。
|
|
|
|
|
* **订阅者**:订阅代理中的一个或多个主题,并接收发布者发送的所有消息。
|
|
|
|
|
* **代理**:将发布者的所有消息路由到订阅者。
|
|
|
|
|
* **主题**:由一个或多个级别组成,级别之间用正斜杠分隔(例如,/smartshouse/livingroom/temperature)。
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2022-02-19 19:42:58 +00:00
|
|
|
|
![](https://miro.medium.com/max/1073/1\*sIxvchdgHSqAGebJjFHBAg.png)
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
### 数据包格式 <a href="#f15a" id="f15a"></a>
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
每个 MQTT 数据包都包含一个固定的标头(图 02)。图 02:固定标头
|
2020-07-15 15:43:14 +00:00
|
|
|
|
|
2021-10-18 11:21:18 +00:00
|
|
|
|
![](https://miro.medium.com/max/838/1\*k6RkAHEk0576geQGUcKSTA.png)
|
2020-09-21 23:14:27 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
固定标头的第一个字段表示 MQTT 数据包的类型。所有数据包类型都列在表 01 中。表 01:MQTT 数据包类型
|
2020-09-21 23:14:27 +00:00
|
|
|
|
|
2021-11-30 16:46:07 +00:00
|
|
|
|
![](https://miro.medium.com/max/1469/1\*z0fhdUVzGa0PLikH\_cyBmQ.png)
|
2020-09-21 23:14:27 +00:00
|
|
|
|
|
2022-08-12 14:24:34 +00:00
|
|
|
|
## Shodan
|
2020-09-21 23:14:27 +00:00
|
|
|
|
|
|
|
|
|
* `port:1883 MQTT`
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
|
|
|
|
<details>
|
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
<summary><a href="https://cloud.hacktricks.xyz/pentesting-cloud/pentesting-cloud-methodology"><strong>☁️ HackTricks 云 ☁️</strong></a> -<a href="https://twitter.com/hacktricks_live"><strong>🐦 Twitter 🐦</strong></a> - <a href="https://www.twitch.tv/hacktricks_live/schedule"><strong>🎙️ Twitch 🎙️</strong></a> - <a href="https://www.youtube.com/@hacktricks_LIVE"><strong>🎥 Youtube 🎥</strong></a></summary>
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
- 你在一家**网络安全公司**工作吗?想要在 HackTricks 中**宣传你的公司**吗?或者你想要**获取最新版本的 PEASS 或下载 PDF 格式的 HackTricks**吗?请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
- 发现我们的独家[**NFTs**](https://opensea.io/collection/the-peass-family)收藏品——[**The PEASS Family**](https://opensea.io/collection/the-peass-family)
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
- 获取[**官方 PEASS & HackTricks 商品**](https://peass.creator-spring.com)
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
- **加入**[**💬**](https://emojipedia.org/speech-balloon/) [**Discord 群组**](https://discord.gg/hRep4RUj7f) 或 [**Telegram 群组**](https://t.me/peass),或者**关注**我在**Twitter**上的[**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/hacktricks_live)**。**
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
2023-08-03 19:12:22 +00:00
|
|
|
|
- **通过向[hacktricks 仓库](https://github.com/carlospolop/hacktricks)和[hacktricks-cloud 仓库](https://github.com/carlospolop/hacktricks-cloud)提交 PR 来分享你的黑客技巧**。
|
2022-04-28 16:01:33 +00:00
|
|
|
|
|
|
|
|
|
</details>
|