• Stars
    star
    134
  • Rank 270,967 (Top 6 %)
  • Language
    Shell
  • Created over 4 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

patch XiaoQiang images to maintain SSH & UART access

xqrepack

These scripts allow you to modify the Xiaomi AX3600 (R3600) and Xiaomi AX1800 (RM1800) firmware image to make sure SSH and UART access is always enabled.

The default root password is password. Please remember to login to the router and change that after the upgrade. Your router settings like IP address and SSIDs are stored in the nvram and should stay the same.

⚠ The script also tries its best to remove or disable phone-home binaries, and also the smart controller (AIoT) parts, leaving you with a (close to) OpenWRT router that you can configure via UCI or /etc/config. Between preserving stock functionality and privacy concerns, I would err on the side of caution and rather that some functionality be sacrificed for a router that I have more confidence to connect to the Internet.

Note that in order to get SSH access to the router initially, you need to downgrade the AX3600 to version 1.0.17 and exploit it first / downgrade the AX1800 to version 1.0.378 (or below) and exploit it first. Once you have SSH, you can use this repacking method to maintain SSH access for newer versions.

Requirements

You will need to install the following tools:

  • ubi_reader
  • ubinize
  • unsquashfs / mksquashfs
  • fakeroot

Usage

  1. Download the firmware from miwifi.com. It should be something like miwifi_r3600_firmware_xxxx_y.y.yyy.bin or miwifi_rm1800_firmware_xxxx_y.y.yyy.bin.

  2. Use the ubireader_extract_images utility from ubi_reader to unpack the UBI image from the firmware. Technically there's junk at the front, but the script will ignore it:

     ubireader_extract_images -w miwifi_r3600_firmware_xxx_yyy.bin
    

    The unpacked files will be in the ubifs-root/miwifi_r3600_firmware... directory.

  3. Patch the rootfs using the repack-squashfs.sh script:

     fakeroot -- ./repack-squashfs.sh ubifs-root/miwifi_r3600_firmware.../img-264..._vol-ubi_rootfs.ubifs
    

    The script will create a new squashfs image with the .new suffix. You will need fakeroot in order to create files and devices as root. You could also run this script as root, but please don't.

  4. Recombine the kernel and patched rootfs with ubinize.sh:

    for R3600:

     ./ubinize.sh ubifs-root/miwifi_r3600_firmware.../...kernel.ubifs \
                  ubifs-root/miwifi_r3600_firmware.../...ubi_rootfs.ubifs.new
    

    for RM1800:

     ./ubinize.sh ubifs-root/miwifi_rm1800_firmware.../...kernel.ubifs \
                  ubifs-root/miwifi_rm1800_firmware.../...ubi_rootfs.ubifs.new \
                  --data
    

    Note the use of the .ubifs.new file. The combined output file will be r3600-raw-img.bin, even if you are using a rm1800 image!

  5. Flash this file directly into the router using SSH. You cannot use the web UI because this is a raw image, and more importantly has no signature.

    If you are using a recently xqrepack'ed firmware, you can use the xqflash utility on the router to flash an update image:

     xqflash /tmp/r3600-raw-img.bin
    

    After it completes successfully, you should be able to reboot.

    If the xqflash utility is not available, you can manually flash the update image described in the following section.

Manual Flashing

The R3600 firmware uses an A/B partition system, called rootfs and rootfs_1. This corresponds to mtd12 and mtd13. Find the partition that is not the one in use and use ubiformat to write the raw image onto the partition:

ubiformat /dev/mtd12 -f /tmp/r3600-raw-img.bin -s 2048 -O 2048

Set the nvram variable to re-initialize /etc (and I think to switch partitions also):

nvram set flag_ota_reboot=1
nvram commit
reboot

A/B Partitions

You can check the MTD partitions from /proc/mtd:

root@XiaoQiang:~# grep rootfs /proc/mtd
mtd12: 023c0000 00020000 "rootfs"
mtd13: 023c0000 00020000 "rootfs_1"
mtd17: 015cc000 0001f000 "ubi_rootfs"

root@XiaoQiang:~# nvram get flag_boot_rootfs
1

The flag_boot_rootfs nvram variable indicates which partition is booted, 0 or 1. You should pick the partition that is not in use, otherwise ubiformat will complain:

ubiformat: error!: please, first detach mtd13 (/dev/mtd13) from ubi0

License

xqrepack is licensed under the 3-clause ("modified") BSD License.

Copyright (C) 2020-2021 Darell Tan

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

More Repositories

1

mdns-repeater

mDNS repeater
C
190
star
2

t20-rtspd

RTSP server + Ingenic T20 SDK
C++
28
star
3

siglent-bin2sr

Converts Siglent SDS-1000X-E waveform binary files into the Sigrok srzip format
Go
18
star
4

fibfs

Fake iOS Backup Filesystem
Python
9
star
5

zigbee-mpcie-card

CC2538 Zigbee mPCIe card
9
star
6

blwipe

Crypto-erase tool for BitLocker volumes
Go
8
star
7

badger

X-CTF 2016 badge firmware
C++
4
star
8

mdns-repeater-hg

mDNS repeater daemon
C
4
star
9

ffsendr

another unofficial Firefox Send client
Go
4
star
10

pscout-maps

Android permission-utilizing APIs found using PScout
Python
3
star
11

docker-centos-ffmpeg

Docker image for building FFmpeg
Shell
2
star
12

circular-layout-ulp

Cloud-enabling a bathroom scale that uses infrared signals
2
star
13

docker-centos-ipynb

CentOS-based IPython Docker base image
Shell
2
star
14

hapz2m

barebones HomeKit <-> Zigbee2MQTT bridge, written purely in Go
Go
2
star
15

kicad-norm

normalizes KiCad files for source control
Go
2
star
16

aegisub-scripts

Lua scripts for Aegisub
Lua
1
star
17

pocket-origurls-crx

Chrome extension to rewrite original URLs in Pocket to NOT point to their server for tracking
JavaScript
1
star
18

regelwerk

poor man's home assistant. a set of rules to react to MQTT events, mainly from zigbee2mqtt
Go
1
star
19

dracut-gmcrypt

Dracut module to provide passwordless unlocking of LUKS-encrypted root volumes
Shell
1
star
20

spdif2analog-pcb

PCB design for a S/PDIF optical to analog audio converter
1
star
21

firebut

Firebase Upload Tool
Go
1
star
22

collectd-asuswrt

build scripts for cross-compiling collectd for ASUSWRT routers
C
1
star
23

simtriplets

FreeRADIUS module for EAP-SIM authentication
Python
1
star
24

cloud-bathroom-scale

Cloud-enabling a bathroom scale that uses infrared signals
Python
1
star
25

minimal-centos-ks

Minimal CentOS Kickstart configuration
Python
1
star
26

nps-iphone-smsimport

imports SMS from Samsung New PC Studio to iPhone
Python
1
star