|
本帖最后由 skyxingcheng 于 2023-9-17 17:26 编辑
前排提醒 搞机有风险 自行承担!
首先根据大神帖子开启telnet
- https://www.right.com.cn/forum/thread-8230876-1-1.html
复制代码
下面是破解流程 理论上适用于任何光猫 前提是找到合适的切入点
telnet登陆后 查询文件系统挂载
- ~ # df -h
- Filesystem Size Used Available Use% Mounted on
- ubi0:rootfs_ubifs 31.6M 25.9M 5.7M 82% /
- /dev/ubi0_3 17.9M 13.6M 4.4M 76% /fhrom
- ubi2:Apps 42.7M 17.3M 25.4M 41% /opt/cu/apps
- ubi2:data 7.1M 236.0K 6.8M 3% /fhconf
- ubi2:factory 3.1M 40.0K 3.1M 1% /fhdata
- /dev/mtdblock4 4.9M 4.9M 0 100% /opt/cu/framework
- overlay 42.7M 17.3M 25.4M 41% /CuInform
复制代码
经实测 可写入目录为 `/fhconf`、`/fhdata`、`/opt/cu/apps`
其中 `/opt/cu/apps` 容量最大 适合放我们自己的程序
查询所有shell脚本 寻找合适的切入点
我们主要关心的就是 `/etc/init.d/` 下面的脚本(此目录里面的脚本都会在开机自动运行),看了一下并没有调用上述三个可写目录的地方
换个思路
查询emmc分区
- ~ # cat /proc/mtd
- dev: size erasesize name
- mtd0: 04d00000 00020000 "rootfsA"
- mtd1: 04d00000 00020000 "rootfsB"
- mtd2: 04400000 00020000 "data"
- mtd3: 00100000 00020000 "nvram"
- mtd4: 01000000 00020000 "frameworkA"
- mtd5: 01000000 00020000 "frameworkB"
- mtd6: 02435000 0001f000 "rootfs_ubifs"
- mtd7: 0001f000 0001f000 "METADATA"
- mtd8: 0001f000 0001f000 "METADATACOPY"
- mtd9: 01550000 0001f000 "app_ubifs"
- mtd10: 007c0000 0001f000 "felix"
- mtd11: 002f38b0 0001f000 "filestruct_full.bin"
- mtd12: 02435000 0001f000 "rootfs_ubifs"
- mtd13: 0001f000 0001f000 "METADATA"
- mtd14: 0001f000 0001f000 "METADATACOPY"
- mtd15: 01550000 0001f000 "app_ubifs"
- mtd16: 007c0000 0001f000 "felix"
- mtd17: 002de380 0001f000 "filestruct_full.bin"
- mtd18: 03032000 0001f000 "Apps"
- mtd19: 00991000 0001f000 "data"
- mtd20: 00554000 0001f000 "factory"
复制代码
由 `/etc/init.d/mount-fs.sh` 我们可以得知 `/` 根目录挂载的分区为 rootfs
分区为常见A/B分区 理论上讲只要不瞎搞 就不会切分区
我们使用 dd 命令将 rootfsA 导出 (也就是mtd0)
- dd if=/dev/mtd0 of=/opt/cu/apps/rootfsa.bin
复制代码
当然 空间肯定是不够的 不过够我们分析了
导出后使用 tftp 拉到电脑上
- udpsvd -vE 0.0.0.0 69 tftpd /
复制代码
- tftpd 192.168.1.1
- mode octet
- get /opt/cu/apps/rootfsa.bin
复制代码
使用winhex打开镜像文件
然后搜索字符串 `/bin/sh` 发现结果还是挺多的
经一番搜索后 发现了一个合适的切入点 `spdsvcinit.sh`
此文件位于 `/etc/init.d/spdsvcinit.sh` 文件大小只有 99 字节 非常适合偷梁换柱(雾
使用 `tftp` 拉出此文件, 文件内容如下
- #!/bin/sh
- echo Applying Speed Service License
- cat /etc/spdsvc_license.txt > /proc/spdsvc/license
复制代码
思路: 我们只需要将 `echo Applying Speed Service License` 替换为 `sh /path/to/your/custom/shell.sh` 就达成执行自定义脚本的目的了 (乐
我们通过winhex显示的偏移量 计算出需要跳过 `46778224/512≈91363 blocks`
使用 `dd` 命令跳过 `91363 blocks` 读取 `512 Bytes`
- dd if=/dev/mtd0 of=/opt/cu/apps/test0 skip=91363 count=1 bs=512
复制代码
然后查看导出的文件
刚好就是我们想要的扇区数据
使用 tftp 拉到电脑上 用 winhex 打开此文件
将 `echo Applying Speed Service License` 替换为我们的启动脚本, 例如:
(防止出问题 字节数补全成长度一致的)
修改好的文件 tftp 回光猫
- # -c 参数表示允许put
- udpsvd -vE 0.0.0.0 69 tftpd -c /opt/cu/apps/
复制代码
- tftpd 192.168.1.1
- mode octet
- put test1
复制代码
查看一下我们修改好的文件结构是否与原来一致
我们可以发现 除了替换的自定义脚本 都是一致的 仅仅是替换了字符串
使用 `dd` 命令, 跳过 `91363 blocks` 写入 `512 Bytes` 到 `mtd0`
- dd if=/opt/cu/apps/test1 of=/dev/mtd0 seek=91363 count=1 bs=512
复制代码
然后就发现写不进去 (恼
但是换个思路 写到block设备上 (参见 `/etc/init.d/mount-fs.sh`)
- dd if=/opt/cu/apps/test1 of=/dev/mtdblock0 seek=91363 count=1 bs=512
复制代码
很快啊 啪的一下就写进去了!!!
然后我们再来一遍上面的导出步骤 看下写入是否成功
- dd if=/dev/mtd0 of=/opt/cu/apps/test2 skip=91363 count=1 bs=512
复制代码
可以看到我们的 `512 Bytes` 成功写入 (偷梁换柱成功
加入我们的自定义脚本(此文件建议仅用于调用,因为`init.d`下的脚本不应由与我们添加的脚本而影响时长)
- ~ # cat /fhconf/start_custom_111.sh
- #!/bin/sh
- echo "success" > /fhconf/123.txt
- exit 0
复制代码
然后满怀激动的心重启光猫 发现脚本已经执行了 破解成功!!!

添加脚本开机自动修改密码 启动ssh(dropbear)、telnetd、关闭某些端口的防火墙
软件需要使用 `armv5` 的版本 如果过大可以用 `upx` 压缩一下 效果显著(对于go来说)
===== 自用脚本 仅供参考 =====
入口中转
- ~ # cat /fhconf/start_custom_111.sh
- #!/bin/sh
- # 入口文件一定不要阻塞
- sh /opt/cu/apps/custom/main.sh &
- exit 0
复制代码
我的启动脚本
- #!/bin/sh
- # sleep一下确保其他进程已启动
- sleep 30
- echo "run myapp time: $(date +%Y%m%d-%H:%M:%S)" >> /opt/cu/apps/custom/start.log
- # 取消 INPUT方向 21,22,23 等端口的 DROP
- iptables -D INPUT_WAN -p tcp -m multiport --dports 80,8080,443,21,22,23,137,138,139,389 -j REJECT --reject-with icmp-port-unreachable
- # 取消 INPUT方向 仅允许来自 br 的 DROP
- # iptables -D INPUT_FIREWALL ! -i br+ -p tcp -s 0.0.0.0/0 -d 0.0.0.0/0 --dport 80 -j DROP
- # iptables -D INPUT_FIREWALL ! -i br+ -p tcp -s 0.0.0.0/0 -d 0.0.0.0/0 --dport 23 -j DROP
- iptables -D INPUT_FIREWALL ! -i br+ -p tcp -s 0.0.0.0/0 -d 0.0.0.0/0 --dport 22 -j DROP
- # WARN: 放行端口后 会直接暴露公网端口 仅建议暴露22端口 或自行转发
- # 如果需要端口转发 可以修改并取消注释下述 iptables 命令
- # iptables -t nat -A PORT_MAPP_WANCD_1 -p tcp -m tcp --dport 10012 -j DNAT --to-destination 192.168.1.1:22
- # iptables -t nat -A PORT_MAPP_WANCD_1 -p tcp -m tcp --dport 10013 -j DNAT --to-destination 192.168.1.1:23
- # 修改 telnet 的密码
- echo "admin:替换为你的密码:0:0:Telnet user:/var:/bin/ash" > /var/tel_passwd
- # 启动 telnetd 服务
- /fhrom/bin/telnetd -p 23
- # 修改 ssh root 密码
- echo root:替换为你的密码|chpasswd
- # 由于 /etc/passwd 存在一丢丢问题(坑)
- # 末尾的登录 shell 居然是 bin/sh 而不是 /bin/sh 所以登录不上
- # 本想直接使用 sed 替换 但由于 /etc/目录不可写
- # (神奇的是 /etc/passwd 可写) 所以需要中转一下
- sed -e 's/:\/:bin\/sh/:\/:\/bin\/sh/g' /etc/passwd > /opt/cu/apps/custom/passwd
- cat /opt/cu/apps/custom/passwd > /etc/passwd
- # 由于没有找到原来的启动脚本
- # 所以用 shell 简单写了一个 sshd 守护进程
- # 这里还有一个坑 sshd 进程!必须!守护
- # 因为 sshd 接收到入方向流量断开后会把自己kill掉(或是退出)
- sh /opt/cu/apps/custom/drop.sh &
- # 使用简单好用的 ddns-go
- sh /opt/cu/apps/custom/ddns/start.sh &
- # 经典穿透软件 防止失联(
- sh /opt/cu/apps/custom/frpc/start_frpc.sh &
- sh /opt/cu/apps/custom/frps/frps.sh &
- exit 0
复制代码
sshd守护脚本
- ~ # cat /opt/cu/apps/custom/drop.sh
- #!/bin/sh
- while true; do
- if ! pgrep sshd > /dev/null; then
- sshd -R -P /var/run/dropbear.1.pid -a -p 22 -K 300 -T 3 > /dev/null 2>&1
- fi
- done
复制代码
ddns守护脚本
ddns-go 必须指定配置文件目录 默认根目录无法写入 保存配置后就不需要启动web了
- ~ # cat /opt/cu/apps/custom/ddns/start.sh
- #!/bin/sh
- workpath=$(dirname $0)
- cd ${workpath}
- while true; do
- ./ddns-go -noweb -skipVerify -c ./config.yaml >> /var/log/ddns-go.log
- done
复制代码
上面的 ddns 使用了 `-skipVerify` 这是由于系统中不含根证书
所以不能进行 https 请求,我们要部署的程序需要避免使用 https
如果非要使用 https 可以使用 chroot 建立虚拟 lxc 将根证书塞进 /etc/ssl/cert.pem 即可
THE END
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
×
|