小米 4A 千兆版路由器禁 ping

cover

原文地址:https://alphahinex.github.io/2024/02/25/mir4ag-disable-ping/


description: "借助 OpenWRTInvasion 利用 Root Shell 漏洞实现小米 4A 千兆版路由器禁 ping"
date: 2024.02.25 10:26
categories:
- Python
- Shell
tags: [Python, Shell, Mac, OpenWRT]
keywords: mir4ag, ping, sysctl, openwrt, OpenWRTInvasion, debrick


小米路由器的官方固件中并不支持设置禁 ping。

本文借助 OpenWRTInvasion 利用 Root Shell 漏洞实现小米4A千兆版路由器禁 ping。

OpenWRTInvasion

OpenWRTInvasion 是一个可以获得小米路由器 Root Shell 权限的工具,支持多种路由型号和固件版本,也有一些写明 不支持的型号和固件版本

以小米4A千兆版路由器为例,分为国内版、国际版,还有 v1、v2 版本,可参照 这里 区分不同版本。

未写明支持或不支持的版本,也有能成功的可能,比如下面的过程是在 小米4A千兆版路由国内 v1 型号,固件版本为 2.28.58 上获得的 Root Shell 权限。

环境准备

该工具是 python + shell 脚本,如需在 Windows 环境中使用,可参考官方 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)

创建 conda 虚拟环境并安装依赖:

$ conda create -n openwrt python=3
$ conda activate openwrt
$ pip install -r requirements.txt

conda 工具安装配置可参照 JupyterLab 实战

脚本执行

运行环境连接至小米路由器后,获得路由地址,如 192.168.31.169。之后执行如下过程:

$ 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

通过本地文件服务将文件传输至路由时,可无需网络连接。

脚本执行成功后,可通过提供的三种方式连接至小米路由器,用户名密码均为 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 状态。

root@XiaoQiang:~# cat /etc/sysctl.conf|grep icmp_echo_ignore_all
net.ipv4.icmp_echo_ignore_all=1
root@XiaoQiang:~# sysctl -p

后记

最初是想通过给小米路由刷 OpenWRT 固件看看能不能设置禁 ping,无奈按照官方 wiki —— Xiaomi Mi Router 4A Gigabit Edition 尝试多次,每次写入 OpenWRT 官方固件后,路由器都会陷入橙灯常亮时而闪烁的状态。最终退而求其次在获得 Root Shell 权限后直接修改 sysctl 配置实现禁 ping。

将刷 OpenWRT 及变砖后的恢复过程记录如下,以备后续需要。

OpenWRT

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

当前文档中,23.05.2 版本 Factory imageSysupgrade image 是相同的镜像

文档中并未给出镜像文件的校验码,可在 固件选择 界面选择适合设备的 OpenWRT 版本进行下载,下载后可对比 shasum256 码。

下载镜像并通过 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)

在路由器中校验镜像,并写入:

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 可能需要等待个十几分钟,不顺利可能就一直处于橙灯常亮,偶尔闪烁状态了……

百兆版好像也有类似的情况:Cannot flash OpenWRT on Mi Router 4A 100M (Chinese version) firmware 2.28.62

Debrick

路由器变砖后,可使用官方提供的工具和固件进行恢复:

下载:

恢复过程可参考:https://forum.openwrt.org/t/xiaomi-mi-router-4a-gigabit-edition-r4ag-r4a-gigabit-fully-supported-and-flashable-with-openwrtinvasion/36685/747

Windows 环境设置静态 IP

  • IP:192.168.31.100
  • 子网掩码:255.255.255.0

连接路由

网线连接电脑及路由 LAN 口(不要连 WAN 口)

执行恢复

  • 打开修复工具,选镜像、网卡
  • 先给路由器断电,之后按住路由器上 reset 键通电,持续按住 8s 左右,路由器橙灯由常亮变成闪烁,修复工具弹出进度条开始写入固件
  • 写入完成后等待几分钟,蓝灯闪烁表示完成,断电重启路由即可
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 159,835评论 4 364
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 67,598评论 1 295
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 109,569评论 0 244
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 44,159评论 0 213
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 52,533评论 3 287
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 40,710评论 1 222
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 31,923评论 2 313
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 30,674评论 0 203
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 34,421评论 1 246
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 30,622评论 2 245
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 32,115评论 1 260
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 28,428评论 2 254
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 33,114评论 3 238
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 26,097评论 0 8
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 26,875评论 0 197
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 35,753评论 2 276
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 35,649评论 2 271

推荐阅读更多精彩内容