WebSSH

157次阅读
没有评论

共计 2601 个字符,预计需要花费 7 分钟才能阅读完成。

介绍

一个简单的 Web 应用程序,用作 ssh 客户端,用于连接到 ssh 服务器。它写在Python,基于龙卷风,帕拉米科和xterm.js。

特征

  • 支持 SSH 密码身份验证,包括空密码。
  • 支持 SSH 公钥身份验证,包括 DSA RSA ECDSA Ed25519 密钥。
  • 支持加密密钥。
  • 支持双因素身份验证(基于时间的一次性密码)。
  • 支持全屏终端。
  • 终端窗口可调整大小。
  • 自动检测 ssh 服务器的默认编码。
  • 支持现代浏览器,包括Chrome浏览器、火狐浏览器、Safari浏览器、边缘浏览器、歌剧浏览器。

预览

WebSSH WebSSH

工作原理

+---------+     http     +--------+    ssh    +-----------+
| browser | <==========> | webssh | <=======> | ssh server|
+---------+   websocket  +--------+    ssh    +-----------+

要求

  • Python 2.7/3.4°

快速入门

  1. 安装此应用程序,运行命令pip install webssh
  2. 启动 Web 服务器,运行命令wssh
  3. 打开浏览器,导航到127.0.0.1:8888
  4. 输入数据,提交表单。

服务器选项

# start a http server with specified listen address and listen port
wssh --address='2.2.2.2' --port=8000

# start a https server, certfile and keyfile must be passed
wssh --certfile='/path/to/cert.crt' --keyfile='/path/to/cert.key'

# missing host key policy
wssh --policy=reject

# logging level
wssh --logging=debug

# log to file
wssh --log-file-prefix=main.log

# more options
wssh --help

浏览器控制台

// connect to your ssh server
wssh.connect(hostname, port, username, password, privatekey, passphrase, totp);

// pass an object to wssh.connect
var opts = {
  hostname: 'hostname',
  port: 'port',
  username: 'username',
  password: 'password',
  privatekey: 'the private key text',
  passphrase: 'passphrase',
  totp: 'totp'
};
wssh.connect(opts);

// without an argument, wssh will use the form data to connect
wssh.connect();

// set a new encoding for client to use
wssh.set_encoding(encoding);

// reset encoding to use the default one
wssh.reset_encoding();

// send a command to the server
wssh.send('ls -l');

自定义字体

要使用自定义字体,请将字体文件放在目录中并重新启动服务器。webssh/static/css/fonts/

URL 参数

支持通过 URL(查询或片段)传递参数,例如以下示例:

传递表单数据(密码必须在 base64 中编码,不支持私钥)

http://localhost:8888/?hostname=xx&username=yy&password=str_base64_encoded

传递终端背景颜色

http://localhost:8888/#bgcolor=green

传递用户定义的标题

http://localhost:8888/?title=my-ssh-server

传递编码

http://localhost:8888/#encoding=gbk

在登录后立即传递执行的命令

http://localhost:8888/?command=pwd

传递终端类型

http://localhost:8888/?term=xterm-256color

使用 Docker

启动应用

docker-compose up

拆解应用程序

docker-compose down

测试

要求

pip install pytest pytest-cov codecov flake8 mock

使用单元测试运行所有测试

python -m unittest discover tests

使用 pytest 运行所有测试

python -m pytest tests

部署

在 Nginx 服务器后面运行

wssh --address='127.0.0.1' --port=8888 --policy=reject
# Nginx config example
location / {
    proxy_pass http://127.0.0.1:8888;
    proxy_http_version 1.1;
    proxy_read_timeout 300;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $http_host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Real-PORT $remote_port;
}

作为独立服务器运行

wssh --port=8080 --sslport=4433 --certfile='cert.crt' --keyfile='cert.key' --xheaders=False --policy=reject

技巧

  • 无论您选择何种部署选择,都不要忘记启用 SSL。
  • 默认情况下,来自公共网络的普通 http 请求将被重定向或阻止,被重定向优先于被阻止。
  • 尝试使用拒绝策略作为缺少的主机密钥策略以及经过验证的known_hosts,这将防止中间人攻击。其思路是,它检查系统主机密钥文件(”*/.ssh/known_hosts”)和应用程序主机密钥文件(”./known_hosts”),如果找不到 ssh 服务器的主机名或密钥不匹配,连接将中止。
正文完
 
admin
版权声明:本站原创文章,由 admin 2020-03-25发表,共计2601字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)
验证码