weh shell高大上?一文教你实现

weh shell高大上?一文教你实现


一、概述

在很多堡垒机、IT审计等平台中,基本上都会带上一个web版的ssh,实现了用户能在web界面对服务器进行shell操作。又或者我们在防火墙后面不能使用这些工具访问远程系统,或者防火墙只允许HTTPS流量才能通过。那我们怎么才能对服务器进行操作呢?


二、shellinaboxd

是由Markus Gutschke开发的一款自由开源的基于Web的Ajax的终端模拟器。使用shellainbox不需要安装任何类似于 XShell 或 Putty 的通讯工具,也不用安装任何插件或第三方应用软件,你只需要有一个支持 JavaScript 和 CSS 的现代浏览器,通过Web浏览器提供了类似原生的 Shell 的外观和感受。shellinaboxd守护进程实现了一个Web服务器,能够侦听指定的端口。但是,这并不一定是一个安全的软件,我不建议在公网上将其暴露出来。

1) 安装shellinabox

本文以centos 7.5为例

  • 使用yum安装

[root@yunwsn /]# yum install shellinabox -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package shellinabox.x86_64 0:2.20-5.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================
 Package               Arch             Version                Repository      Size
====================================================================================
Installing:
 shellinabox           x86_64           2.20-5.el7             epel           136 k

Transaction Summary
====================================================================================
Install  1 Package

Total download size136 k
Installed size503 k
Downloading packages:
shellinabox-2.20-5.el7.x86_64.rpm                            | 136 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : shellinabox-2.20-5.el7.x86_64                                    1/1 
  Verifying  : shellinabox-2.20-5.el7.x86_64                                    1/1 

Installed:
  shellinabox.x86_64 0:2.20-5.el7                                                   

Complete!
[root@yunwsn /]
  • 启动服务

[root@yunwsn /]# systemctl start shellinaboxd.service 
[root@yunwsn /]# systemctl status shellinaboxd.service 
● shellinaboxd.service - Shell In A Box daemon
   Loaded: loaded (/usr/lib/systemd/system/shellinaboxd.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2019-06-03 14:23:54 CST; 7s ago
     Docs: man:shellinaboxd(1)
 Main PID: 30454 (shellinaboxd)
   CGroup: /system.slice/shellinaboxd.service
           ├─30454 /usr/sbin/shellinaboxd -u shellinabox -g shellinabox --cert=/v...
           └─30455 /usr/sbin/shellinaboxd -u shellinabox -g shellinabox --cert=/v...
  • 查看端口

[root@yunwsn /]# netstat -natlp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      876/sshd            
tcp        0      0 0.0.0.0:4200            0.0.0.0:*               LISTEN      30454/shellinaboxd  

可以看到默认端口是4200

2) 使用shellainbox

  • 使用网页打开https://ip:4200(注意:一定是https打开)

  • 登录(注意,不支持root用户登录,只能使用普通用户登录)


3) 修改端口号

  • 修改配置文件,修改PORT即可

vi /etc/sysconfig/shellinaboxd
# Basic options
USER=shellinabox
GROUP=shellinabox
CERTDIR=/var/lib/shellinabox
PORT=443
OPTS="--disable-ssl-menu -s /:LOGIN"
  • 重启服务

systemctl restart shellinaboxd.service
  • 查看端口

tcp        0      0 10.104.145.137:443      116.21.13.32:39703      ESTABLISHED 31255/shellinaboxd 

微信公众号~运维少年


猜你喜欢

转载自blog.51cto.com/xiaowangzai/2404280