海运的博客

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

发布时间: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使用autoconf生成
./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     

使用:

mkdir /etc/dropbear/
./dropbearkey -t ecdsa -s 256 -f /etc/dropbear/dropbear_ecdsa_host_key
./dropbearkey -t ed25519 -f /etc/dropbear/dropbear_ed25519_host_key
./dropbearkey -t dss -f /etc/dropbear/dropbear_dss_host_key
./dropbearkey -t rsa -s 3072 -f /etc/dropbear/dropbear_rsa_host_key
./dropbear -r /etc/dropbear/dropbear_rsa_host_key

静态编译openssl/openssh/sshd:

wget https://github.com/madler/zlib/releases/download/v1.2.13/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

使用:

mkdir /etc/ssh
ssh-keygen -A
cat <<EOF > /etc/ssh/sshd.conf
Port 22
PermitRootLogin yes
ChallengeResponseAuthentication no
Subsystem       sftp    /data/bin/sftp-server

PubkeyAuthentication yes

HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
EOF

/src/openssh-9.3p1/sshd -f /etc/ssh/sshd.conf

静态编译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

EcoNet EN751221 SOC MIPS 34Kc uclibc编译vnstat:

#gcc版本太高vnstat编译失败,由于目标是uclibc,使用上面的musl编译后不能运行
wget https://toolchains.bootlin.com/downloads/releases/toolchains/mips32/tarballs/mips32--uclibc--stable-2022.08-1.tar.bz2
tar jxf mips32--uclibc--stable-2022.08-1.tar.bz2
export PATH=$PATH:`pwd`/mips32--uclibc--stable-2022.08-1/bin/

wget https://www.sqlite.org/2025/sqlite-autoconf-3490100.tar.gz
tar zxf sqlite-autoconf-3490100.tar.gz 
cd sqlite-autoconf-3490100/
./configure --host=mips-linux --disable-shared --enable-static --prefix=/usr/local/sqlite
make && make install
  
cd ../
wget https://humdi.net/vnstat/vnstat-2.13.tar.gz
tar zxf vnstat-2.13.tar.gz 
cd vnstat-2.13/
CPPFLAGS="-I/usr/local/sqlite/include/" LDFLAGS="-L/usr/local/sqlite/lib/ -static" ./configure --host=mips-linux --disable-shared --enable-static --prefix=/usr/local/vnstat
make && make install

使用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

贝尔光猫G-140W-UG优化CPU和内存

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

默认占用CPU和内存高,内存高因为java,通过/etc/scripts/osgi_admin.sh/osgi_start.sh启动,sysmon调用/etc/scripts/jwatchdog.sh 不停检测java是否退出,导致cpu占用高。
还有内核模块ORTP_TASK每2分左右占用单核心CPU 100%,通过/etc/init.d/rcS判断猫是否支持电话加载,修改此文件无效果,估计使用的/usr/etc/,通过rmmod /lib/modules/pcm1.ko减小到20%,如果rmmod不能用可以下载openwrt mips34kc软件包或编译使用。
也可下载完整版busybox使用:https://busybox.net/downloads/binaries/1.31.0-defconfig-multiarch-musl/

修改/etc/scripts/pcm_startup.sh文件让它开机后kill程序和rmmod模块,优化后CPU 0占用,ORTP_TASK每2分钟占用一次20%,解决这个估计要修改固件了。

一个小问题,使用go编译的sshd服务端非要在telnet终端内启动,不然在ssh连接终端使用ctrl+c不能终止程序,x86没问题。

/etc/pkill.sh &
exit

以下/etc/pkill.sh为脚本内容,也可添加到/etc/rc.d/S10pkill脚本,开机也能执行:

#!/bin/sh
sleep 60
/etc/rmmod /lib/modules/pcm1.ko   
pkill -9 sysmon #占用大幅降低
pkill -9 voip
pkill -9 evtmgr  

pkill -9 dropbear
pkill -9 dnsproxy
pkill -9 samba
pkill -9 homenas
pkill -9 storageSrv
pkill -9 securitySrv
pkill -9 batch_upgrade
pkill -9 xl2tpd
pkill -9 udhcpd
pkill -9 dhcp6s 
pkill -9 radvd

pkill -9 http_traffic_process
pkill -9 traffic_mirror
pkill -9 lanhostsd
pkill -9 wifihostd
pkill -9 arpwan
pkill -9 umonitor

pkill -9 tcwdog
pkill -9 spccu
pkill -9 nffd
pkill -9 appmgr
pkill -9 ramond
pkill -9 usrbh

#禁用pcm启动后以下未启动
#pkill -9 trafficsrv
#pkill -9 usbsrv
#pkill -9 syssrv
#pkill -9 wifisrv
#pkill -9 wansrv
#pkill -9 lansrv
#pkill -9 diagsrv
#pkill -9 pcmcu

#pkill -9 omciMgr #这个kill后pon断线后不重连
#上面全部关闭后下面才能关闭,不然重启
#pkill -9 msgmgr #这两个关闭后网页不能登录
#pkill -9 cfgmgr
#pkill -9 parse #这两个ocmimgr依赖
pkill -9 alarmd
/etc/rmmod /lib/modules/sys_mod.ko                                                  
/etc/rmmod /lib/modules/DSPCore.ko                                                                                                                                  
/etc/rmmod /lib/modules/pcm1.ko                                                     
/etc/rmmod /lib/modules/lec.ko                                                                 
/etc/rmmod /lib/modules/spi.ko                                                      
/etc/rmmod /lib/modules/slic3_sep.ko 
/etc/rmmod /lib/modules/fxs3.ko                                         
/etc/rmmod /lib/modules/ksocket.ko                                      
/etc/rmmod /lib/modules/ortp.ko                                         
/etc/rmmod /lib/modules/acodec_x.ko                                     
/etc/rmmod /lib/modules/foip.ko                                         
#/etc/rmmod /lib/modules/ovdsp.ko                                        
/etc/rmmod /lib/modules/pcmDump.ko     
/etc/rmmod /lib/modules/lantiq/drv_ifxos.ko                                        
/etc/rmmod /lib/modules/lantiq/drv_tapi.ko                                                                                                                          
/etc/rmmod /lib/modules/lantiq/drv_dxs.ko 

修改rootfs分区禁止加载voip相关模块ORTP_TASK后CPU依然每2分钟占用单核50%左右,通过top查看是软中断占用的CPU,查看软中断wifi_ratelimit占用CPU0明显超高:

cat /proc/softirqs 
                    CPU0       CPU1       
          HI:   24304711          0
       TIMER:    2495627    2495649
      NET_TX:      81335      77293
      NET_RX:      81699     182716
       BLOCK:          0          0
BLOCK_IOPOLL:          0          0
     TASKLET:         30          4
       SCHED:    2488517     155237
     HRTIMER:          0          0
         RCU:      21636    2500274
cat /proc/interrupts
           CPU0       CPU1       
  1:      72432          0      MIPS  TC3162 UART
  7:   24950419          0      MIPS  wifi_ratelimit
  8:      21236       4723      MIPS  IPI_resched
  9:        819       3594      MIPS  IPI_call
 10:          0          0      MIPS  watchdog
 18:          0          0      MIPS  xhci-hcd:usb1
 19:          0          0      MIPS  dying gasp
 22:     244212          0      MIPS  qdma_lan
 23:          0     250646      MIPS  qdma_wan
 24:        138          0      MIPS
 31:    2496872    2496886      MIPS  timer
 33:          0          0      MIPS  bus timeout
ERR:          0
qdmamgr_lan set rxratelimit config Disable packet
qdmamgr_wan set rxratelimit config Disable packet
/etc/rmmod /lib/modules/wlan_ratelimit

到此CPU占用完全恢复正常,基本保持在0占用。

使用sshd没有ctrl+c不能终止的问题了
https://github.com/darkerego/mips-binaries/tree/master/openssh

UsePrivilegeSeparation no
Port 22
PermitRootLogin yes
ChallengeResponseAuthentication no
Subsystem       sftp    /data/sftp-server

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

分类
最新文章
最近回复
  • opnfense: 谢谢博主!!!解决问题了!!!我之前一直以为内置的odhcp6就是唯一管理ipv6的方式
  • liyk: 这个方法获取的IPv6大概20分钟之后就会失效,默认路由先消失,然后Global IPV6再消失
  • 海运: 不好意思,没有。
  • zongboa: 您好,請問一下有immortalwrt設定guest Wi-Fi的GUI教學嗎?感謝您。
  • 海运: 恩山有很多。
  • swsend: 大佬可以分享一下固件吗,谢谢。
  • Jimmy: 方法一 nghtp3步骤需要改成如下才能编译成功: git clone https://git...
  • 海运: 地址格式和udpxy一样,udpxy和msd_lite能用这个就能用。
  • 1: 怎么用 编译后的程序在家里路由器内任意一台设备上运行就可以吗?比如笔记本电脑 m参数是笔记本的...
  • 孤狼: ups_status_set: seems that UPS [BK650M2-CH] is ...