海运的博客

linux/ubuntu交叉静态编译mips tmux和dropbear/openssl/openssh/bash/iperf3/dnsmasq

发布时间:April 27, 2023 // 分类: // No Comments

下载mips musl交叉编译环境,也可以使用https://toolchains.bootlin.com/

wget https://musl.cc/mips-linux-musl-cross.tgz
tar zxf mips-linux-musl-cross.tgz
export PATH=$PATH:`pwd`/mips-linux-musl-cross/bin/

编译ncurses,后续要将/lib/terminfo/x/xterm-256color等复制到目标机器/data/terminfo目录,不然运行tmux提示找不到terminfo database。

wget https://ftp.gnu.org/pub/gnu/ncurses/ncurses-6.4.tar.gz
tar zxf ncurses-6.4.tar.gz
cd ncurses-6.4/
./configure --prefix /usr/local/tmux --with-default-terminfo-dir=/data/terminfo --enable-pc-files --host=mips-linux-musl
#解决错误:strip: Unable to recognise the format of the input file `/usr/local/tmux/bin/tic'
ln -s `pwd`/../mips-linux-musl-cross/bin/mips-linux-musl-strip /usr/local/bin/strip
make && make install
rm -rf /usr/local/bin/strip

编译libevent和tmux:

wget https://github.com/libevent/libevent/releases/download/release-2.1.12-stable/libevent-2.1.12-stable.tar.gz
tar zxf libevent-2.1.12-stable.tar.gz 
cd libevent-2.1.12-stable/
./configure --prefix /usr/local/tmux --host=mips-linux-musl --disable-openssl
make && make install

wget https://github.com/tmux/tmux/releases/download/3.3a/tmux-3.3a.tar.gz
tar zxf tmux-3.3a.tar.gz 
cd tmux-3.3a/
export CFLAGS="-I/usr/local/tmux/include -I/usr/local/tmux/include/ncurses"
export LDFLAGS="-L/usr/local/tmux/lib"
./configure --enable-static --prefix=/usr/local/tmux --host=mips-linux-musl
make && make install

静态编译dropbear,当前最新版本使用SRT关闭窗口后dropbear和执行的命令一直在后台不结束,使用dropbear-2020.81版本正常。

wget https://github.com/mkj/dropbear/archive/refs/tags/DROPBEAR_2022.83.tar.gz
tar zxf DROPBEAR_2022.83.tar.gz 
cd dropbear-DROPBEAR_2022.83/
./configure --enable-static --prefix=/usr/local/dropbear --host=mips-linux-musl --disable-zlib --disable-syslog --disable-harden --disable-lastlog --disable-utmp --disable-utmpx --disable-wtmp --disable-wtmpx --disable-pututline --disable-pututxline --disable-loginfunc 
PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp" MULTI=1 make strip

编译前可修改default_options.h定义dropbear运行时的PATH用来查找scp执行文件,sftp-server执行文件路径使用SFTP。

#define SFTPSERVER_PATH "/data/bin/sftp-server"
#define DROPBEAR_PATH_SSH_PROGRAM "/data/bin/dbclient"
#define DEFAULT_ROOT_PATH "/usr/sbin:/usr/bin:/sbin:/bin:/data/bin"
#define DEFAULT_PATH "/usr/bin:/bin:/data/bin"

编译的为单个文件dropbearmulti,使用时创建软链接:

ln -s /data/bin/dropbearmulti /data/bin/dropbear
ln -s /data/bin/dropbearmulti /data/bin/dropbearkey 
ln -s /data/bin/dropbearmulti /data/bin/scp     

静态编译openssl/openssh/sshd:

wget https://www.zlib.net/zlib-1.2.13.tar.gz
tar zxf zlib-1.2.13.tar.gz 
cd zlib-1.2.13/
CC=mips-linux-musl-gcc  ./configure --prefix=/usr/local/openssh --static 
make && make install

wget https://github.com/openssl/openssl/releases/download/OpenSSL_1_1_1t/openssl-1.1.1t.tar.gz
tar zxf openssl-1.1.1t.tar.gz 
cd openssl-1.1.1t
#./config no-asm no-shared --prefix=/usr/local/openssh --cross-compile-prefix=mips-linux-musl-
#sed -i 's/-m64//g' Makefile
./Configure linux-mips32 no-asm no-shared --prefix=/usr/local/openssh --cross-compile-prefix=mips-linux-musl-
make && make install

export CFLAGS="-I/usr/local/openssh/include/"
export LDFLAGS="-L/usr/local/openssh/lib/"
wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.3p1.tar.gz
tar zxf openssh-9.3p1.tar.gz 
cd openssh-9.3p1/
./configure --prefix=/usr/local/openssh --host=mips-linux-musl --with-ldflags=-static --disable-lastlog --disable-utmp  --disable-utmpx --disable-wtmp  --disable-wtmpx --disable-libutil --disable-pututline --disable-pututxline --with-default-path=/usr/bin:/bin:/usr/sbin:/sbin:/sbin:/usr/sbin:/bin:/usr/bin:/data/bin
make && make install

静态编译bash:

wget https://ftp.gnu.org/gnu/bash/bash-5.1.tar.gz
tar zxf bash-5.1.tar.gz 
cd bash-5.1/
./configure --enable-static-link --host=mips-linux-musl --without-bash-malloc
make
mips-linux-musl-strip -s bash

静态编译iperf3:

wget https://github.com/esnet/iperf/releases/download/3.15/iperf-3.15.tar.gz
tar zxf iperf-3.15.tar.gz 
cd iperf-3.15/
./configure --prefix=/usr/local/iperf3 --host=mips-linux-musl "LDFLAGS=--static" --disable-shared 
make

静态编译dnsmasq:

wget https://thekelleys.org.uk/dnsmasq/dnsmasq-2.89.tar.gz
tar zxf dnsmasq-2.89.tar.gz 
cd dnsmasq-2.89/
CC=mips-linux-musl-gcc make CFLAGS=-Os LDFLAGS=-static

使用squashfs-tools和binwalk修改路由/光猫固件rootfs文件

发布时间:April 26, 2023 // 分类: // No Comments

查看rootfs所在分区:

cat /proc/mtd 
dev:    size   erasesize  name
mtd0: 00040000 00020000 "bootloader"
mtd1: 00040000 00020000 "romfile"
mtd2: 00300000 00020000 "kernel"
mtd3: 01400000 00020000 "rootfs"

通过nc将mtd rootfs分区发送到远程机器上:

nc -l -p 3333 > rootfs.bin
cat /dev/mtd3 | nc 192.168.1.8 3333

查看确认备份的文件头部是squashfs格式:

head -c 4 rootfs.bin |hexdump -C
00000000  68 73 71 73                                       |hsqs|

查看squashfs打包参数:

binwalk rootfs.bin 

DECIMAL       HEXADECIMAL     DESCRIPTION
--------------------------------------------------------------------------------
0             0x0             Squashfs filesystem, little endian, version 4.0, compression:lzma, size: 17975011 bytes, 2288 inodes, blocksize: 131072 bytes, created: 2020-06-22 04:04:58

用binwalk解压:

binwalk -e rootfs.bin 
ls _rootfs.bin.extracted/
#0.squashfs为真正大小文件,其它空间为FF填充
0.squashfs  squashfs-root

用unsquashfs解压,推荐使用:

unsquashfs rootfs.bin 

修改squashfs-root目录内文件后重新打包,使用之前查看的参数:

mksquashfs squashfs-root rootfs-new.bin -comp lzma -b 131072

将修改的rootfs用mtd刷入:

mtd write rootfs-new.bin rootfs

校验下:

mtd verify rootfs-new.bin rootfs

注意:有的机器固件包含签名验证,修改后不能正常开机。

参考:
https://www.callmewing.com/2018/10/03/%E9%80%86%E5%90%91PT632_G2%E5%85%89%E7%8C%AB%E5%9B%BA%E4%BB%B6/
https://akbwe.com/posts/trying-to-modify-f7607p-rootfs/
https://github.com/csersoft/HWFW_GUI

此内容被密码保护

发布时间:April 23, 2023 // 分类: // No Comments

请输入密码访问

openwrt/immortalwrt编译内核模块并修改版本号

发布时间:April 21, 2023 // 分类: // No Comments

#编译工具链
make tools/install
make toolchain/install
#先进入菜单将要编译的模块选择为M
make menuconfig
make target/linux/{clean,compile}
make package/kernel/linux/{clean,compile}

使用现成工具链,省得编译浪费时间:

wget https://downloads.openwrt.org/releases/21.02.6/targets/mediatek/mt7622/openwrt-sdk-21.02.6-mediatek-mt7622_gcc-8.4.0_musl.Linux-x86_64.tar.xz
tar Jxf openwrt-sdk-21.02.6-mediatek-mt7622_gcc-8.4.0_musl.Linux-x86_64.tar.xz 
mv staging_dir staging_dir-back
mv openwrt-sdk-21.02.6-mediatek-mt7622_gcc-8.4.0_musl.Linux-x86_64/staging_dir ./

如mtkhnat模块和ipk位置:

build_dir/target-aarch64_cortex-a53_musl/linux-mediatek_mt7981/packages/ipkg-aarch64_cortex-a53/kmod-mediatek_hnat/lib/modules/5.4.238/mtkhnat.ko
bin/targets/mediatek/mt7981/packages/kmod-mediatek_hnat_5.4.238-1_aarch64_cortex-a53.ipk 

如果编译的最新模块小版本号与系统不一致可用sed修改,要确保模块无大更新,不然可能有兼容性问题。

sed -i 's/5\.4\.238/5\.4\.225/g' build_dir/target-aarch64_cortex-a53_musl/linux-mediatek_mt7981/packages/ipkg-aarch64_cortex-a53/kmod-mediatek_hnat/lib/modules/5.4.238/mtkhnat.ko

https://openwrt.org/docs/guide-developer/toolchain/single.package
https://forum.openwrt.org/t/how-to-build-an-additional-kernel-module/56575/2

联通贝尔光猫G-140W-UG修改为桥接/管理员密码并开启telnet

发布时间:April 20, 2023 // 分类: // 2 Comments

1.修改管理员密码,WEB修改普通用户密码用浏览器F12网络拦截或监听后编辑重发请求,修改url中的set为set_super,将POST参数中pswdNew替换成pswdNewSuper、pswdConfirm替换成pswdConfirmSuper。
2.设置拨号桥接:
internet.jpg
iptv配置:
iptv.jpg
备份下tr09参数,可以删除
tr09.jpg
3.访问 http://192.168.1.1/system.cgi?telnet 开启telnet。
如需修改SN和MAC:

ritool dump
ritool set YPSerialNum ALCLxxxxxxxx #SN码
ritool set MACAddress xx:xx:xx:xx #MAC地址 

这猫用来桥接够用了,跑满千m宽带不占用CPU资源,top查看sirq无占用,/proc/softirqs内NET_TX和NET_RX很小,说明走的是硬桥接。
但是IPTV走的是软桥接,流量也不大,CPU够用。
更新:IPTV协议封装选PPPOE是硬桥接。
https://wp.for-get.com/538.html
https://www.sohu.com/a/389057275_662688

分类
最新文章
最近回复
  • 海运: 恩山有很多。
  • swsend: 大佬可以分享一下固件吗,谢谢。
  • Jimmy: 方法一 nghtp3步骤需要改成如下才能编译成功: git clone https://git...
  • 海运: 地址格式和udpxy一样,udpxy和msd_lite能用这个就能用。
  • 1: 怎么用 编译后的程序在家里路由器内任意一台设备上运行就可以吗?比如笔记本电脑 m参数是笔记本的...
  • 孤狼: ups_status_set: seems that UPS [BK650M2-CH] is ...
  • 孤狼: 擦。。。。apcupsd会失联 nut在冲到到100的时候会ONBATT进入关机状态,我想想办...
  • 海运: 网络,找到相应的url编辑重发请求,firefox有此功能,其它未知。
  • knetxp: 用浏览器F12网络拦截或监听后编辑重发请求,修改url中的set为set_super,将POS...
  • Albert: 啊啊啊啊啊啊啊啊啊 我太激动了,终于好了英文区搜索了半天,翻遍了 pve 论坛没找到好方法,博...
归档