mips平台下交叉编译shellinabox

编译环境:openwrt-19.07 MT7621-MIPS

下载openwrt-shellinabox构建包

克隆openwrt-shellinabox到package/shellinabox 下

1
git clone https://github.com/openwrt-develop/openwrt-shellinabox package/shellinabox

openwrt-shellinabox的Makefile如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
include $(TOPDIR)/rules.mk

PKG_NAME:=shellinabox
PKG_VERSION:=2.20
PKG_RELEASE:=$(PKG_SOURCE_VERSION)

PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/shellinabox/shellinabox.git
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
PKG_SOURCE_VERSION:=98e6eebc6c2026fb126a458c6cb5a2541447258e
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz

PKG_FIXUP:=autoreconf

include $(INCLUDE_DIR)/package.mk

define Package/shellinabox
SECTION:=net
CATEGORY:=Network
TITLE:=a web based terminal emulator
URL:=https://github.com/shellinabox/shellinabox
DEPENDS:=+zlib +libopenssl +busybox +@BUSYBOX_CUSTOM +@BUSYBOX_CONFIG_LOGIN
endef

define Package/shellinabox/description
Shell In A Box implements a web server that
can export arbitrary command line tools to
a web based terminal emulator. This emulator
is accessible to any JavaScript and CSS
enabled web browser and does not require any additional browser plugins.
endef

CONFIGURE_ARGS += --disable-utmp

define Package/shellinabox/install
$(INSTALL_DIR) $(1)/usr/sbin $(1)/etc/init.d $(1)/etc/shellinabox
$(INSTALL_BIN) $(PKG_BUILD_DIR)/shellinaboxd $(1)/usr/sbin
$(INSTALL_BIN) ./files/shellinaboxd.init $(1)/etc/init.d/shellinaboxd
$(INSTALL_DATA) $(PKG_BUILD_DIR)/shellinabox/*.css $(1)/etc/shellinabox
$(PKG_BUILD_DIR)/make-chained-cert.sh > $(1)/etc/shellinabox/certificate.pem
endef

$(eval $(call BuildPackage,shellinabox))

编译

执行 make menuconfig ,按路径 net->Network->shellinabox 找到shellinabox, 然后按下空格键选中<*>shellinabox, 最后保存退出。

执行 make package/shellinabox/compile V=s 

在我的环境编译报报错如下

image-20211026175545356

看报错应该是没有链接到openssl库, 在往上看日志发现编译的时候根本没有链接openssl库

1
OpenWrt-libtool: link: mipsel-openwrt-linux-musl-gcc -g -std=gnu99 -Wall -Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -msoft-float -mips16 -minterlink-mips16 -iremap/home/openwrt-19.07/build_dir/target-mipsel_24kc_musl/shellinabox-2.20:shellinabox-2.20 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z -Wl,now -Wl,-z -Wl,relro -znow -zrelro -o shellinaboxd shellinabox/shellinaboxd.o shellinabox/externalfile.o shellinabox/launcher.o shellinabox/privileges.o shellinabox/service.o shellinabox/session.o shellinabox/usercss.o  -L/home/openwrt-19.07/staging_dir/target-mipsel_24kc_musl/usr/lib -L/home/openwrt-19.07/staging_dir/target-mipsel_24kc_musl/lib -L/home/openwrt-19.07/staging_dir/toolchain-mipsel_24kc_gcc-7.5.0_musl/usr/lib -L/home/openwrt-19.07/staging_dir/toolchain-mipsel_24kc_gcc-7.5.0_musl/lib ./.libs/liblogging.a ./.libs/libhttp.a -lz

查看shellinabox的编译配置发现只能当runtime_loading值为no的时候才会显示链接 -lssl -lcrypto

1
2
3
4
5
6
7
8
9
10
11
12
13
14
if test "x$enable_runtime_loading" == xno; then
dnl Link against OpenSSL libraries, unless SSL support has been disabled
if test "x$enable_ssl" != xno; then
AC_CHECK_HEADER(openssl/bio.h,
[AC_CHECK_HEADER(openssl/err.h,
[AC_CHECK_HEADER(openssl/ssl.h, [LIBS="-lssl -lcrypto $LIBS"])])])
fi

dnl Link against PAM libraries, unless PAM support has been disabled
if test "x$enable_pam" != xno; then
AC_CHECK_HEADER(security/pam_appl.h, [LIBS="-lpam $LIBS"])
AC_CHECK_HEADER(security/pam_misc.h, [LIBS="-lpam_misc $LIBS"])
fi
fi

接着查看runtime_loading的值, 默认runtime-loading的值是yes,

1
2
3
4
5
6
7
8
9
10
11
12
13
dnl We try to always use dlopen() instead of linking libraries dynamically, as
dnl this reduces the hard run-time dependencies that our binary has. But we
dnl allow users to disable this feature.
AC_ARG_ENABLE(runtime-loading,
[ --disable-runtime-loading ShellInABox will try to load the OpenSSL, and PAM
libraries at run-time, if it has been compiled with
support for these libraries, and if the operating
system supports dynamic loading of libraries. This
allows you to install the same binary on different
systems independent of whether they have OpenSSL
and PAM enabled. If you would rather directly link
these libraries into the binary, thus making them a
hard dependency, then disable runtime-loading.])

于是我们在Makefile里加上 --disable-runtime-loading 禁止掉runtime-loading

1
CONFIGURE_ARGS += --disable-utmp --disable-runtime-loading

继续 make package/shellinabox/compile V=s

然后又报错如下

1
2
3
4
5
6
7
8
9
10
11
12
Package shellinabox is missing dependencies for the following libraries:
libpam.so.0
libpam_misc.so.0
Makefile:45: recipe for target '/home/openwrt-19.07/bin/targets/ramips/mt7621/packages/shellinabox_2.20_mipsel_24kc.ipk' failed
make[2]: *** [/home/openwrt-19.07/bin/targets/ramips/mt7621/packages/shellinabox_2.20_mipsel_24kc.ipk] Error 1
make[2]: Leaving directory '/home/openwrt-19.07/feeds/linker/shellinabox'
time: package/feeds/linker/shellinabox/compile#15.89#1.39#24.26
package/Makefile:111: recipe for target 'package/feeds/linker/shellinabox/compile' failed
make[1]: *** [package/feeds/linker/shellinabox/compile] Error 2
make[1]: Leaving directory '/home/openwrt-19.07'
/home/openwrt-19.07/include/toplevel.mk:225: recipe for target 'package/feeds/linker/shellinabox/compile' failed
make: *** [package/feeds/linker/shellinabox/compile] Error 2

报错信息很清楚了,没有添加libpam的依赖。我们在Makefile中添加libpam依赖。如下:

1
2
3
4
5
6
7
define Package/shellinabox 
SECTION:=net
CATEGORY:=Network
TITLE:=a web based terminal emulator
URL:=https://github.com/shellinabox/shellinabox
DEPENDS:=+zlib +libopenssl +libpam +busybox +@BUSYBOX_CUSTOM +@BUSYBOX_CONFIG_LOGIN
endef

继续编译 make package/shellinabox/compile V=s

终于编译通过

完整的Makefile如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
include $(TOPDIR)/rules.mk

PKG_NAME:=shellinabox
PKG_VERSION:=2.20
PKG_RELEASE:=$(PKG_SOURCE_VERSION)

PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/shellinabox/shellinabox.git
PKG_SOURCE_SUBDIR:=$(PKG_NAME)-$(PKG_VERSION)
PKG_SOURCE_VERSION:=98e6eebc6c2026fb126a458c6cb5a2541447258e
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz

PKG_FIXUP:=autoreconf

include $(INCLUDE_DIR)/package.mk

define Package/shellinabox
SECTION:=net
CATEGORY:=Network
TITLE:=a web based terminal emulator
URL:=https://github.com/shellinabox/shellinabox
DEPENDS:=+zlib +libopenssl +libpam +busybox +@BUSYBOX_CUSTOM +@BUSYBOX_CONFIG_LOGIN
endef

define Package/shellinabox/description
Shell In A Box implements a web server that
can export arbitrary command line tools to
a web based terminal emulator. This emulator
is accessible to any JavaScript and CSS
enabled web browser and does not require any additional browser plugins.
endef

CONFIGURE_ARGS += --disable-utmp --disable-runtime-loading

define Package/shellinabox/install
$(INSTALL_DIR) $(1)/usr/sbin $(1)/etc/init.d $(1)/etc/shellinabox
$(INSTALL_BIN) $(PKG_BUILD_DIR)/shellinaboxd $(1)/usr/sbin
$(INSTALL_BIN) ./files/shellinaboxd.init $(1)/etc/init.d/shellinaboxd
$(INSTALL_DATA) $(PKG_BUILD_DIR)/shellinabox/*.css $(1)/etc/shellinabox
$(PKG_BUILD_DIR)/make-chained-cert.sh > $(1)/etc/shellinabox/certificate.pem
endef

$(eval $(call BuildPackage,shellinabox))

安装及测试

把生成的安装包移动到开发板上安装 <bin/targets/ramips/mt7621/packages/shellinabox_2.20_mipsel_24kc.ipk>

1
opkg install shellinabox_2.20_mipsel_24kc.ipk

然后测试

1
2
# -u是指定用户的意思,默认是用nobody运行,在我的环境上使用nobody用户报错,所以我使用-u指定了root用户
shellinaboxd -u root

在浏览器中访问 http://192.168.1.1:4200/ ,发现响应为空

google了下发现需要访问 https://192.168.1.1:4200 才行

如果你想继续使用http访问,可以执行下面的命令

1
2
# -t 代表禁止ssl
shellinaboxd -t -u root

mips平台下交叉编译shellinabox
http://example.com/2021/10/26/交叉编译shellinabox/
作者
John Doe
发布于
2021年10月26日
许可协议