
原文地址:https://alphahinex.github.io/2024/02/25/mir4ag-disable-ping/
description: "借助 OpenWRTInvasion 利用 Root Shell 漏洞實(shí)現(xiàn)小米 4A 千兆版路由器禁 ping"
date: 2024.02.25 10:26
categories:
- Python
- Shell
tags: [Python, Shell, Mac, OpenWRT]
keywords: mir4ag, ping, sysctl, openwrt, OpenWRTInvasion, debrick
小米路由器的官方固件中并不支持設(shè)置禁 ping。
本文借助 OpenWRTInvasion 利用 Root Shell 漏洞實(shí)現(xiàn)小米4A千兆版路由器禁 ping。
OpenWRTInvasion
OpenWRTInvasion 是一個(gè)可以獲得小米路由器 Root Shell 權(quán)限的工具,支持多種路由型號和固件版本,也有一些寫明 不支持的型號和固件版本。
以小米4A千兆版路由器為例,分為國內(nèi)版、國際版,還有 v1、v2 版本,可參照 這里 區(qū)分不同版本。
未寫明支持或不支持的版本,也有能成功的可能,比如下面的過程是在 小米4A千兆版路由國內(nèi) v1 型號,固件版本為 2.28.58 上獲得的 Root Shell 權(quán)限。
環(huán)境準(zhǔn)備
該工具是 python + shell 腳本,如需在 Windows 環(huán)境中使用,可參考官方 README 中 Using Docker (also works on Windows) 部分。
先從 GitHub 克隆倉庫:
$ git clone https://github.com/acecilia/OpenWRTInvasion.git
$ cd OpenWRTInvasion
$ git log
commit fcec03a49d78d700d62f7be82093bd8e349d9a55 (HEAD -> master, origin/master, origin/HEAD)
Author: BugC0der <60848096+BugC0der@users.noreply.github.com>
Date: Mon Mar 13 01:15:11 2023 +0100
Ensure correct line ending for script.sh when used from Windows (#171)
創(chuàng)建 conda 虛擬環(huán)境并安裝依賴:
$ conda create -n openwrt python=3
$ conda activate openwrt
$ pip install -r requirements.txt
conda 工具安裝配置可參照 JupyterLab 實(shí)戰(zhàn) 。
腳本執(zhí)行
運(yùn)行環(huán)境連接至小米路由器后,獲得路由地址,如 192.168.31.169。之后執(zhí)行如下過程:
$ python remote_command_execution_vulnerability.py
Router IP address [press enter for using the default 'miwifi.com']: 192.168.31.169
Enter router admin password: xxxxxx
There two options to provide the files needed for invasion:
1. Use a local TCP file server runing on random port to provide files in local directory `script_tools`.
2. Download needed files from remote github repository. (choose this option only if github is accessable inside router device.)
Which option do you prefer? (default: 1)1
****************
router_ip_address: 192.168.31.169
stok: xxxxxxxxx
file provider: local file server
****************
start uploading config file...
start exec command...
local file server is runing on 0.0.0.0:50423. root='script_tools'
local file server is getting 'busybox-mipsel' for 192.168.31.169.
local file server is getting 'dropbearStaticMipsel.tar.bz2' for 192.168.31.169.
done! Now you can connect to the router using several options: (user: root, password: root)
* telnet 192.168.31.169
* ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 -oHostKeyAlgorithms=+ssh-rsa -c 3des-cbc -o UserKnownHostsFile=/dev/null root@192.168.31.169
* ftp: using a program like cyberduck
通過本地文件服務(wù)將文件傳輸至路由時(shí),可無需網(wǎng)絡(luò)連接。
腳本執(zhí)行成功后,可通過提供的三種方式連接至小米路由器,用戶名密碼均為 root:
$ ssh -oKexAlgorithms=+diffie-hellman-group1-sha1 -oHostKeyAlgorithms=+ssh-rsa -c 3des-cbc -o UserKnownHostsFile=/dev/null root@192.168.31.169
The authenticity of host '192.168.31.169 (192.168.31.169)' can't be established.
RSA key fingerprint is SHA256:VS1Ef5kgBMO6ghA+PD2lcKYM6cTOnwE/eO4PRUYV6Jg.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.31.169' (RSA) to the list of known hosts.
root@192.168.31.169's password:
BusyBox v1.19.4 (2019-06-11 03:26:58 UTC) built-in shell (ash)
Enter 'help' for a list of built-in commands.
-----------------------------------------------------
Welcome to XiaoQiang!
-----------------------------------------------------
$$$$$$\ $$$$$$$\ $$$$$$$$\ $$\ $$\ $$$$$$\ $$\ $$\
$$ __$$\ $$ __$$\ $$ _____| $$ | $$ | $$ __$$\ $$ | $$ |
$$ / $$ |$$ | $$ |$$ | $$ | $$ | $$ / $$ |$$ |$$ /
$$$$$$$$ |$$$$$$$ |$$$$$\ $$ | $$ | $$ | $$ |$$$$$ /
$$ __$$ |$$ __$$< $$ __| $$ | $$ | $$ | $$ |$$ $$<
$$ | $$ |$$ | $$ |$$ | $$ | $$ | $$ | $$ |$$ |\$$\
$$ | $$ |$$ | $$ |$$$$$$$$\ $$$$$$$$$ | $$$$$$ |$$ | \$$\
\__| \__|\__| \__|\________| \_________/ \______/ \__| \__|
root@XiaoQiang:~#
禁 ping
編輯 /etc/sysctl.conf 文件,加入或修改 net.ipv4.icmp_echo_ignore_all 字段值為 1,之后使配置生效即可。路由重啟后也是禁 ping 狀態(tài)。
root@XiaoQiang:~# cat /etc/sysctl.conf|grep icmp_echo_ignore_all
net.ipv4.icmp_echo_ignore_all=1
root@XiaoQiang:~# sysctl -p
后記
最初是想通過給小米路由刷 OpenWRT 固件看看能不能設(shè)置禁 ping,無奈按照官方 wiki —— Xiaomi Mi Router 4A Gigabit Edition 嘗試多次,每次寫入 OpenWRT 官方固件后,路由器都會陷入橙燈常亮?xí)r而閃爍的狀態(tài)。最終退而求其次在獲得 Root Shell 權(quán)限后直接修改 sysctl 配置實(shí)現(xiàn)禁 ping。
將刷 OpenWRT 及變磚后的恢復(fù)過程記錄如下,以備后續(xù)需要。
OpenWRT
- 官方文檔:Xiaomi Mi Router 4A Gigabit Edition
- 設(shè)備 SKU:
DVB4218CN
2019 model is shielded
Warning Xiaomi is currently shipping Mi Router 4A Gigabit Edition devices without proper shielding since 2020. Be aware that those might cause problems due to radio interference. Nevertheless, it's flashable.
在 Installation 部分下載 Factory image
當(dāng)前文檔中,23.05.2 版本
Factory image和Sysupgrade image是相同的鏡像
文檔中并未給出鏡像文件的校驗(yàn)碼,可在 固件選擇 界面選擇適合設(shè)備的 OpenWRT 版本進(jìn)行下載,下載后可對比 shasum256 碼。
sha256sum:da95d78bbb590e3f81e078d63bb1a3a129364c0a6a586caab9c5249ede183116
sha256sum:66c58c3c05d4d43c88cb6f98e831ee0d518f80a248aba3314d7895983b91deff
下載鏡像并通過 ftp(賬號 root/root)上傳至路由器:
$ curl https://downloads.openwrt.org/releases/23.05.2/targets/ramips/mt7621/openwrt-23.05.2-ramips-mt7621-xiaomi_mi-router-4a-gigabit-squashfs-sysupgrade.bin --output firmware.bin
$ ftp 192.168.31.169
Connected to 192.168.31.169.
220 Operation successful
Name (192.168.31.169:alphahinex): root
331 Specify password
Password:
230 Operation successful
ftp> cd tmp
250 Operation successful
ftp> put firmware.bin
200 Operation successful
150 Ok to send data
226 Operation successful
6579470 bytes sent in 0.519 seconds (12.1 Mbytes/s)
在路由器中校驗(yàn)鏡像,并寫入:
root@XiaoQiang:/tmp# /tmp/busybox sha256sum firmware.bin
66c58c3c05d4d43c88cb6f98e831ee0d518f80a248aba3314d7895983b91deff firmware.bin
root@XiaoQiang:/tmp# mtd -e OS1 -r write firmware.bin OS1
Unlocking OS1 ...
Erasing OS1 ...
Writing from firmware.bin to OS1 ...
Rebooting ...
順利的話,Rebooting 可能需要等待個(gè)十幾分鐘,不順利可能就一直處于橙燈常亮,偶爾閃爍狀態(tài)了……
百兆版好像也有類似的情況:Cannot flash OpenWRT on Mi Router 4A 100M (Chinese version) firmware 2.28.62
Debrick
路由器變磚后,可使用官方提供的工具和固件進(jìn)行恢復(fù):
下載:
Windows 環(huán)境設(shè)置靜態(tài) IP
- IP:
192.168.31.100 - 子網(wǎng)掩碼:
255.255.255.0
連接路由
網(wǎng)線連接電腦及路由 LAN 口(不要連 WAN 口)
執(zhí)行恢復(fù)
- 打開修復(fù)工具,選鏡像、網(wǎng)卡
- 先給路由器斷電,之后按住路由器上 reset 鍵通電,持續(xù)按住 8s 左右,路由器橙燈由常亮變成閃爍,修復(fù)工具彈出進(jìn)度條開始寫入固件
- 寫入完成后等待幾分鐘,藍(lán)燈閃爍表示完成,斷電重啟路由即可