hacktricks/network-services-pentesting/1883-pentesting-mqtt-mosquitto.md

142 lines
7.7 KiB
Markdown
Raw Normal View History

2022-08-12 14:24:34 +00:00
# 1883 - Pentesting MQTT (Mosquitto)
2022-04-28 16:01:33 +00:00
<details>
<summary><strong>Jifunze kuhusu kuvamia AWS kutoka sifuri hadi shujaa na</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (Mtaalam wa Timu Nyekundu ya AWS ya HackTricks)</strong></a><strong>!</strong></summary>
2022-04-28 16:01:33 +00:00
2024-02-11 02:13:58 +00:00
Njia nyingine za kusaidia HackTricks:
2022-04-28 16:01:33 +00:00
* Ikiwa unataka kuona **kampuni yako ikitangazwa kwenye HackTricks** au **kupakua HackTricks kwa PDF** Angalia [**MIPANGO YA KUJIUNGA**](https://github.com/sponsors/carlospolop)!
* Pata [**bidhaa rasmi za PEASS & HackTricks**](https://peass.creator-spring.com)
* Gundua [**Familia ya PEASS**](https://opensea.io/collection/the-peass-family), mkusanyiko wetu wa [**NFTs**](https://opensea.io/collection/the-peass-family) ya kipekee
* **Jiunge na** 💬 [**Kikundi cha Discord**](https://discord.gg/hRep4RUj7f) au kikundi cha [**telegram**](https://t.me/peass) au **tufuate** kwenye **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks\_live)**.**
* **Shiriki mbinu zako za kuvamia kwa kuwasilisha PRs kwa** [**HackTricks**](https://github.com/carlospolop/hacktricks) na [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) repos za github.
2022-04-28 16:01:33 +00:00
</details>
2024-02-11 02:13:58 +00:00
## Taarifa Msingi
**MQ Telemetry Transport (MQTT)** inajulikana kama **itifaki ya ujumbe wa kuchapisha/kusikiliza** ambayo inajulikana kwa unyenyekevu wake wa kipekee na uzito wake mdogo. Itifaki hii imeundwa mahsusi kwa mazingira ambapo vifaa vina uwezo mdogo na vinatumika kwenye mitandao ambayo inajulikana kwa upungufu wa wigo wa bandari, kuchelewa kwa juu, au uhusiano usioaminika. Malengo makuu ya MQTT ni pamoja na kupunguza matumizi ya wigo wa mtandao na kupunguza mahitaji kwenye rasilimali za kifaa. Aidha, inalenga kudumisha mawasiliano yanayoweza kutegemewa na kutoa kiwango fulani cha uhakikisho wa utoaji. Malengo haya hufanya MQTT iweze kufaa sana kwa uwanja unaokua wa **mawasiliano ya mashine-kwa-mashine (M2M)** na **Intaneti ya Vitu (IoT)**, ambapo ni muhimu kuunganisha vifaa vingi kwa ufanisi. Zaidi ya hayo, MQTT ni muhimu sana kwa programu za simu, ambapo kuhifadhi wigo na maisha ya betri ni muhimu.
**Bandari ya msingi:** 1883
```
2020-09-24 18:58:31 +00:00
PORT STATE SERVICE REASON
1883/tcp open mosquitto version 1.4.8 syn-ack
```
## Kuchunguza trafiki
2020-09-24 18:58:31 +00:00
Wakati pakiti ya **CONNECT** inapopokelewa na wakala wa MQTT, pakiti ya **CONNACK** hutumwa kujibu. Pakiti hii ina msimbo wa kurudi ambao ni muhimu kwa kuelewa hali ya uhusiano. Msimbo wa kurudi wa **0x00** una maana kuwa anwani za siri zimekubaliwa, ikionyesha uhusiano uliofanikiwa. Kwa upande mwingine, msimbo wa kurudi wa **0x05** unamaanisha kuwa anwani za siri si sahihi, hivyo kuzuia uhusiano.
2024-02-08 21:36:35 +00:00
Kwa mfano, ikiwa wakala anakataa uhusiano kutokana na anwani za siri zisizo sahihi, hali ingeonekana kama hii:
2024-02-08 21:36:35 +00:00
```
{
2024-02-11 02:13:58 +00:00
"returnCode": "0x05",
"description": "Connection Refused, not authorized"
2024-02-08 21:36:35 +00:00
}
```
![](<../.gitbook/assets/image (973).png>)
2022-02-19 19:42:58 +00:00
### [**Kuvunja Nguvu MQTT**](../generic-methodologies-and-resources/brute-force.md#mqtt)
2022-02-19 19:42:58 +00:00
2022-08-12 14:24:34 +00:00
## Pentesting MQTT
**Uthibitishaji ni hiari kabisa** na hata kama uthibitishaji unafanywa, **encryption haiitwi kwa chaguo-msingi** (vitambulisho hutolewa kwa maandishi wazi). Mashambulizi ya MITM bado yanaweza kutekelezwa kuiba nywila.
Kuunganisha kwenye huduma ya MQTT unaweza kutumia: [https://github.com/bapowell/python-mqtt-client-shell](https://github.com/bapowell/python-mqtt-client-shell) na kujisajili kwenye mada zote kwa kufanya:
```
> 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/#"
```
2024-02-11 02:13:58 +00:00
Unaweza pia kutumia [**https://github.com/akamai-threat-research/mqtt-pwn**](https://github.com/akamai-threat-research/mqtt-pwn)
2024-02-11 02:13:58 +00:00
Unaweza pia kutumia:
2022-02-19 19:42:58 +00:00
```bash
apt-get install mosquitto mosquitto-clients
mosquitto_sub -t 'test/topic' -v #Subscribe to 'test/topic'
mosquitto_sub -h <host-ip> -t "#" -v #Subscribe to ALL topics.
2022-02-19 19:42:58 +00:00
```
Au unaweza **kutekeleza nambari hii ili kujaribu kuunganisha kwenye huduma ya MQTT bila uthibitishaji, kusajili kila mada na kuzisikiliza**:
```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):
2024-02-11 02:13:58 +00:00
client.subscribe('#', qos=1)
client.subscribe('$SYS/#')
def on_message(client, userdata, message):
2024-02-11 02:13:58 +00:00
print('Topic: %s | QOS: %s | Message: %s' % (message.topic, message.qos, message.payload))
def main():
2024-02-11 02:13:58 +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()
if __name__ == "__main__":
2024-02-11 02:13:58 +00:00
main()
```
2024-02-11 02:13:58 +00:00
## Taarifa zaidi
2024-02-11 02:13:58 +00:00
kutoka hapa: [https://morphuslabs.com/hacking-the-iot-with-mqtt-8edaf0d07b9b](https://morphuslabs.com/hacking-the-iot-with-mqtt-8edaf0d07b9b)
2024-02-11 02:13:58 +00:00
### Mfano wa Kuchapisha/Kusikiliza <a href="#b667" id="b667"></a>
2024-02-11 02:13:58 +00:00
Mfano wa kuchapisha/kusikiliza unajumuisha:
* **Mchapishaji**: huchapisha ujumbe kwa mada moja (au nyingi) kwenye mpatanishi.
* **Msikilizaji**: anasikiliza mada moja (au nyingi) kwenye mpatanishi na kupokea ujumbe wote uliotumwa na mchapishaji.
* **Mpatanishi**: huarifu ujumbe wote kutoka kwa wachapishaji kwenda kwa wasikilizaji.
* **Mada**: inajumuisha kiwango kimoja au zaidi kilichotenganishwa na mstari wa mbele (k.m., /smartshouse/livingroom/temperature).
2024-02-11 02:13:58 +00:00
### Muundo wa Pakiti <a href="#f15a" id="f15a"></a>
Kila pakiti ya MQTT ina kichwa kilichofungwa (Mchoro 02).Mchoro 02: Kichwa Kilichofungwa
2024-02-08 21:36:35 +00:00
![https://miro.medium.com/max/838/1\*k6RkAHEk0576geQGUcKSTA.png](https://miro.medium.com/max/838/1\*k6RkAHEk0576geQGUcKSTA.png)
2024-02-11 02:13:58 +00:00
### Aina za Pakiti
* CONNECT (1): Kuanzishwa na mteja kuomba uhusiano kwa seva.
* CONNACK (2): Kuthibitisha seva ya uhusiano uliofanikiwa.
* PUBLISH (3): Hutumiwa kutuma ujumbe kutoka kwa mteja kwenda kwa seva au kinyume chake.
* PUBACK (4): Kuthibitisha pakiti ya PUBLISH.
* PUBREC (5): Sehemu ya itifaki ya utoaji ujumbe ikidhibitisha ujumbe umepokelewa.
* PUBREL (6): Hakikisho zaidi katika utoaji wa ujumbe, ikionyesha kutolewa kwa ujumbe.
2024-02-11 02:13:58 +00:00
* PUBCOMP (7): Sehemu ya mwisho ya itifaki ya utoaji ujumbe, ikionyesha kukamilika.
* SUBSCRIBE (8): Ombi la mteja kusikiliza ujumbe kutoka kwa mada.
* SUBACK (9): Kuthibitisha ya seva ya ombi la SUBSCRIBE.
2024-02-11 02:13:58 +00:00
* UNSUBSCRIBE (10): Ombi la mteja kuacha kupokea ujumbe kutoka kwa mada.
* UNSUBACK (11): Majibu ya seva kwa ombi la UNSUBSCRIBE.
* PINGREQ (12): Ujumbe wa moyo unatumwa na mteja.
* PINGRESP (13): Majibu ya seva kwa ujumbe wa moyo.
* DISCONNECT (14): Kuanzishwa na mteja kumaliza uhusiano.
* Thamani mbili, 0 na 15, zimewekwa kama zilizohifadhiwa na matumizi yao ni marufuku.
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>
<summary><strong>Jifunze kuhusu kudukua AWS kutoka sifuri hadi shujaa na</strong> <a href="https://training.hacktricks.xyz/courses/arte"><strong>htARTE (HackTricks AWS Red Team Expert)</strong></a><strong>!</strong></summary>
2022-04-28 16:01:33 +00:00
2024-02-11 02:13:58 +00:00
Njia nyingine za kusaidia HackTricks:
2022-04-28 16:01:33 +00:00
* Ikiwa unataka kuona **kampuni yako ikitangazwa kwenye HackTricks** au **kupakua HackTricks kwa PDF** Angalia [**MIPANGO YA KUJIUNGA**](https://github.com/sponsors/carlospolop)!
* Pata [**bidhaa rasmi za PEASS & HackTricks**](https://peass.creator-spring.com)
* Gundua [**Familia ya PEASS**](https://opensea.io/collection/the-peass-family), mkusanyiko wetu wa [**NFTs**](https://opensea.io/collection/the-peass-family) ya kipekee
* **Jiunge na** 💬 [**Kikundi cha Discord**](https://discord.gg/hRep4RUj7f) au kikundi cha [**telegram**](https://t.me/peass) au **tufuate** kwenye **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks\_live)**.**
* **Shiriki mbinu zako za kudukua kwa kuwasilisha PRs kwa** [**HackTricks**](https://github.com/carlospolop/hacktricks) na [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
2022-04-28 16:01:33 +00:00
</details>