affolter-engineering/mqattack

GitHub: affolter-engineering/mqattack

一款基于 Rust 的 MQTT 协议渗透测试工具,用于对 MQTT Broker 进行指纹识别、认证暴力破解、权限探测及 Will 注入等多种安全评估。

Stars: 0 | Forks: 0

# mqattack 一个基于 Rust 的 MQTT 命令行渗透测试工具。 ## 功能 ## 安装说明 ### 从源码构建(使用 Nix) ``` $ nix-shell $ cargo build --release ``` 二进制文件位于 `target/release/mqattack`。 ### 从源码构建(不使用 Nix) 需要 Rust 1.80+、C 编译器和 OpenSSL 开发头文件。 ``` $ cargo build --release ``` ## 用法 所有命令共享一组通用的连接和身份验证选项: ``` Connection options: -H, --host Broker hostname or IP [default: localhost] -p, --port Broker port [default: 1883] -u, --username Username -P, --password Password (mutually exclusive with --jwt) --jwt JWT token sent as MQTT password --client-id MQTT client identifier [default: mqattack] --keepalive Keep-alive interval [default: 60] TLS options: --tls Enable TLS with system root CAs --cafile Custom CA certificate in PEM format (implies --tls) --cert Client certificate for mTLS in PEM format (requires --key) --key Client private key for mTLS in PEM format (requires --cert) --insecure Disable certificate verification — for testing only ``` ### 发布 ``` $ mqattack publish [OPTIONS] -t -m -t, --topic Target topic -m, --message Payload; use '-' to read from stdin -q, --qos QoS level 0/1/2 [default: 0] -r, --retain Set the retain flag ``` ``` # 发布简单消息 $ mqattack publish -t test/topic -m 'hello' # 使用 QoS 1 和 retain 标志发布 $ mqattack publish -H 192.168.1.10 -t alerts/door -m 'open' -q 1 -r # 从 stdin 管道传输 payload $ echo '{"cmd":"reboot"}' | mqattack publish -t device/1/cmd -m - # 使用 JWT 通过 TLS 发布 $ mqattack publish --tls --jwt 'eyJhbGci...' \ -H broker.example.com -p 8883 -t device/1/cmd -m 'reboot' # mTLS 发布 $ mqattack publish --cert client.crt --key client.key --cafile ca.crt \ -H broker.example.com -p 8883 -t test -m 'hello' ``` ### 指纹识别 通过订阅 `$SYS/#` 并分析收集到的消息来识别 broker 软件及其版本。 除了标准的 SUBSCRIBE 包之外,不会发送任何其他数据包——broker 会通过其发布的消息暴露自身信息。 可识别的 broker 及其检测信号: | Broker | 检测信号 | | --- | --- | | Mosquitto | `$SYS/broker/version` 值以 `mosquitto version` 开头 | | HiveMQ | `$SYS/broker/version` 值以 `HiveMQ` 开头 | | VerneMQ | `$SYS/broker/version` 值以 `VerneMQ` 开头 | | EMQX | `$SYS/brokers/`(复数)下的 topic;从 topic 路径中提取节点名称 | | NanoMQ | `$SYS/nanomq/` 命名空间下的 topic | | RabbitMQ | `$SYS/broker/version` 值包含 `rabbitmq` | 当匹配到已知特征时,置信度报告为 `high`;当存在 `$SYS/broker/version` 但无法识别时报告为 `low`;当可以访问 $SYS 但未提供任何识别信息时报告为 `unknown`。 ``` $ mqattack fingerprint [OPTIONS] -w, --wait Collection window in seconds [default: 5] --verbose Print all collected $SYS messages after the summary ``` **示例** ``` # 对默认端口上的 broker 进行指纹识别 $ mqattack fingerprint -H 192.168.1.10 # 为慢速 broker 设置更长的收集窗口,然后转储所有内容 $ mqattack fingerprint -H 192.168.1.10 -w 10 --verbose # 使用凭据通过 TLS 进行指纹识别 $ mqattack fingerprint --cafile ca.crt -H broker.example.com -p 8883 \ -u admin -P secret ``` 示例输出(Mosquitto): ``` [+] Broker Fingerprint Software: Mosquitto Version: 2.0.18 Confidence: high Build info: With OpenSSL 3.0.2 15 Mar 2022 Uptime: 12345 seconds Clients connected: 3 Clients total: 47 Messages received: 1082 Messages sent: 2341 [*] 47 $SYS message(s) collected (use --verbose to see all) ``` ### 检查 ACL ``` $ mqattack check-acl [OPTIONS] (-t | -w ) -t, --topic Single topic to probe (mutually exclusive with --wordlist) -w, --wordlist File with one topic per line (mutually exclusive with --topic) --no-subscribe Skip subscribe permission tests --no-publish Skip publish permission tests --payload Payload used for publish probes [default: mqattack] -q, --qos QoS for publish probes (1 or 2) [default: 1] --wait Seconds to wait for a broker response per test [default: 5] ``` ### 枚举 topic ``` # Wordlist 枚举 mqattack enum-topics -H 192.168.1.10 -w mqtt-topics.txt # 对 "home/" 下的单层 topic 进行暴力破解 mqattack enum-topics -H 192.168.1.10 --brute --prefix home --max-length 4 # 使用更长窗口进行双层暴力破解 (home/word/word) mqattack enum-topics -H 192.168.1.10 --brute --prefix home --depth 2 -t 10 ``` ### 暴力破解身份验证 测试针对 broker 的用户名/密码组合。支持四种攻击模式, 所有模式都使用 broker 的 ConnAck 返回码来区分成功与失败(例如 `BadUserNamePassword` 与 `NotAuthorized`)。 | 模式 | 标志 | 用例 | |---|---|---| | 凭证对 | `-c FILE` | 测试预先生成的 `username:password` 列表 | | 单用户暴力破解 | `-u USER -W FILE` | 针对单个账号的字典攻击 | | 密码喷洒 | `-U FILE -P PASS` | 使用一个密码针对多个用户 | | 笛卡尔积 | `-U FILE -W FILE` | 所有组合(上限 10 000,使用 `--force` 可覆盖此限制) | `--try-anonymous` 会在尝试任何字典之前,先探测无凭证连接。 ``` $ mqattack brute-auth [OPTIONS] -c, --credentials Credential pairs file (username:password per line) -U, --user-list Username wordlist -W, --pass-list Password wordlist --try-anonymous Test anonymous access first --stop-on-success Stop after the first successful login --delay Milliseconds between attempts [default: 0] --timeout Seconds to wait per attempt [default: 5] --force Override the cross-product safety cap ``` 凭证对文件每行使用 `username:password` 格式。 空行和以 `#` 开头的行将被忽略。 第一个 `:` 为分隔符;密码可以包含额外的冒号。 ``` # credentials.txt admin:admin admin:password # 无密码 guest # 密码包含冒号 service:pass:word ``` ``` # 快速探测:测试匿名访问然后使用凭据列表,首次命中后停止 $ mqattack brute-auth -H 192.168.1.10 --try-anonymous -c credentials.txt --stop-on-success # 针对单个账户的字典攻击 $ mqattack brute-auth -H 192.168.1.10 -u admin -W /usr/share/wordlists/rockyou.txt # 密码喷射:一个密码对应多个用户(包含 500 毫秒延迟以避免锁定) $ mqattack brute-auth -H 192.168.1.10 -U users.txt -P 'Mqtt@2024' --delay 500 # 通过 TLS 进行完整的笛卡尔积暴力破解 $ mqattack brute-auth --cafile ca.crt -H broker.example.com -p 8883 \ -U users.txt -W passwords.txt # 将有效凭据直接管道传输到 enum-perms 以映射其权限 $ mqattack brute-auth -H 192.168.1.10 -c credentials.txt | grep 'SUCCESS' | \ awk '{print $2}' > valid.txt && \ mqattack enum-perms -H 192.168.1.10 -c valid.txt -w topics.txt ``` ### Will 注入 在 CONNECT 包中注册精心构造的 Last Will and Testament (LWT),将 连接保持一段可配置的时间,然后关闭 TCP socket, 而不发送 DISCONNECT 帧。broker 会将其视为异常断开连接, 并将 will 的 payload 发布给目标 topic 的当前以及(如果设置了 retained)未来的订阅者。 这可以用于: - 将消息注入到 ACL 原本会阻止直接发布的 topic - 毒化在 topic 上持久存在、直到被显式清除的 retained 消息 - 通过伪造传感器状态触发下游自动化或告警逻辑 ``` $ mqattack will-inject [OPTIONS] --topic -t, --topic Topic the broker publishes the will to on disconnect -m, --message Will payload [default: mqattack-will] -q, --qos QoS for the will (0, 1, or 2) [default: 1] -r, --retain Persist the will as a retained message --hold Seconds to stay connected before triggering [default: 2] --monitor Subscribe on a second connection to capture the delivery --monitor-wait Seconds to listen after disconnect [default: 5] ``` **示例** ``` # 向 alarm topic 注入保留的 "disarmed" 状态 $ mqattack will-inject -H 192.168.1.10 \ -t home/alarm/status -m "disarmed" -r # 注入 command payload 并验证其是否已交付 $ mqattack will-inject -H 192.168.1.10 \ -t device/42/cmd -m '{"action":"reboot"}' -q 1 \ --monitor device/42/cmd --monitor-wait 10 # 在触发之前作为长期存在的 client 混入 $ mqattack will-inject -H 192.168.1.10 \ -t sensors/temperature -m "999.9" --hold 60 --retain # 使用凭据通过 TLS 进行 Will injection $ mqattack will-inject --cafile ca.crt -H broker.example.com -p 8883 \ -u sensor01 -P secret -t sensors/temp -m "-99" -r ``` ## 许可证 MIT,详见 [LICENSE](LICENSE)。
标签:CISA项目, IP 地址批量处理, Rust, 可视化界面, 安全测试工具, 物联网安全, 网络流量审计, 通知系统