更優(yōu)于Shellinabox的webshell工具--ttyd-創(chuàng)新互聯(lián)

ttyd 是一個(gè)運(yùn)行在服務(wù)端,客戶端通過(guò)web瀏覽器訪問(wèn)從而連接后臺(tái) tty (pts偽終端)接口的程序,把 shell 終端搬到 web 瀏覽器中。
更優(yōu)于 Shellinabox 的 web shell 工具 -- ttyd

成都創(chuàng)新互聯(lián)公司 - 成都服務(wù)器托管,四川服務(wù)器租用,成都服務(wù)器租用,四川網(wǎng)通托管,綿陽(yáng)服務(wù)器托管,德陽(yáng)服務(wù)器托管,遂寧服務(wù)器托管,綿陽(yáng)服務(wù)器托管,四川云主機(jī),成都云主機(jī),西南云主機(jī),成都服務(wù)器托管,西南服務(wù)器托管,四川/成都大帶寬,機(jī)柜大帶寬租用·托管,四川老牌IDC服務(wù)商

WebSocket

WebSocket 是 HTML5 開(kāi)始提供的一種基于HTTP協(xié)議與服務(wù)器WebServer進(jìn)行單會(huì)話、長(zhǎng)連接、全雙工的網(wǎng)絡(luò)技術(shù),依靠這種技術(shù)可以實(shí)現(xiàn)客戶端和服務(wù)端的長(zhǎng)連接,雙向?qū)崟r(shí)通信,以及基于服務(wù)端主動(dòng)向客戶端的實(shí)時(shí)消息推送交互的底層技術(shù)棧。
它的大特點(diǎn)就是,服務(wù)器可以主動(dòng)向客戶端推送信息,客戶端也可以主動(dòng)向服務(wù)器發(fā)送信息, 是真正的雙向平等對(duì)話,屬于服務(wù)器推送技術(shù)的一種。

其他特點(diǎn)包括:

  • 建立在 TCP 協(xié)議之上,服務(wù)器端的實(shí)現(xiàn)比較容易。
  • 與 HTTP 協(xié)議有著良好的兼容性。默認(rèn)端口也是 80 和 443,并且握手階段采用 HTTP 協(xié)議,因此握手時(shí)不容易屏蔽,能通過(guò)各種 HTTP 代理服務(wù)器。
  • 數(shù)據(jù)格式比較輕量,性能開(kāi)銷小,通信高效。
  • 可以發(fā)送文本,也可以發(fā)送二進(jìn)制數(shù)據(jù)。
  • 沒(méi)有同源限制,客戶端可以與任意服務(wù)器通信。
  • 協(xié)議標(biāo)識(shí)符是ws(如果加密,則為wss),服務(wù)器網(wǎng)址就是 URL。

    ttyd 不同于 Shellinabox 項(xiàng)目的底層原理,它使用基于HTML5的 WebSocket 協(xié)議,更少的http交互帶來(lái)更高效、更高性能、更低延時(shí)的交互式會(huì)話服務(wù)。

ttyd 也可以通過(guò) Nginx 7層HTTP代理訪問(wèn),更高的靈活性。

ttyd 內(nèi)建支持 SSL/TLS 傳輸層認(rèn)證加密,支持客戶端/服務(wù)端的單向/雙向證書(shū)認(rèn)證加密,更高的安全性。

OS Support:

* macOS
* Linux
* Microsoft Windows
* FreeBSD/OpenBSD
* OpenWrt/LEDE

Feature:

* C語(yǔ)言內(nèi)建`libwebsockets`核心庫(kù),高速、低內(nèi)存消耗、高性能特性。 
* 基于`Xterm.js`的全功能終端,支持 CJK 不同語(yǔ)言和 IME 輸入法字符輸入。
* 窗口圖形化 `ZMODEM` 支持,服務(wù)端需安裝 `lrzsz` 程序。
* 可實(shí)現(xiàn)基于簡(jiǎn)單的 Basic Auth 基本認(rèn)證(不加密通信)。
* 可實(shí)現(xiàn)基于 OpenSSL 的傳輸層加密通信支持(加密通信)。
* 跨平臺(tái): macOS, Linux, FreeBSD/OpenBSD, OpenWrt/LEDE, Windows

Linux 平臺(tái)安裝方式:

  • 方式一:下載二進(jìn)制程序文件,本地直接運(yùn)行即可(推薦)
  • 方式二:下載源碼文件,安裝依賴庫(kù)編譯安裝
    sudo apt-get install cmake g++ pkg-config git vim-common libwebsockets-dev libjson-c-dev libssl-dev
    git clone https://github.com/tsl0922/ttyd.git
    cd ttyd && mkdir build && cd build
    cmake ..
    make && make install

    如果安裝libwebsockets-dev(版本過(guò)時(shí))失敗,你可能需要單獨(dú)編譯安裝libwebsockets。

使用方式:

####程序幫助信息:

ttyd is a tool for sharing terminal over the web

USAGE:
    ttyd [options] <command> [<arguments...>]

VERSION:
    1.5.2

OPTIONS:
    -p, --port              Port to listen (default: 7681, use `0` for random port)
    -i, --interface         Network interface to bind (eg: eth0), or UNIX domain socket path (eg: /var/run/ttyd.sock)
    -c, --credential        Credential for Basic Authentication (format: username:password)
    -u, --uid               User id to run with
    -g, --gid               Group id to run with
    -s, --signal            Signal to send to the command when exit it (default: 1, SIGHUP)
    -a, --url-arg           Allow client to send command line arguments in URL (eg: http://localhost:7681?arg=foo&arg=bar)
    -R, --readonly          Do not allow clients to write to the TTY
    -t, --client-option     Send option to client (format: key=value), repeat to add more options
    -T, --terminal-type     Terminal type to report, default: xterm-256color
    -O, --check-origin      Do not allow websocket connection from different origin
    -m, --max-clients       Maximum clients to support (default: 0, no limit)
    -o, --once              Accept only one client and exit on disconnection
    -B, --browser           Open terminal with the default system browser
    -I, --index             Custom index.html path
    -6, --ipv6              Enable IPv6 support
    -S, --ssl               Enable SSL
    -C, --ssl-cert          SSL certificate file path
    -K, --ssl-key           SSL key file path
    -A, --ssl-ca            SSL CA file path for client certificate verification
    -d, --debug             Set log level (default: 7)
    -v, --version           Print the version and exit
    -h, --help              Print this text and exit

Visit https://github.com/tsl0922/ttyd to get more information and report bugs.
用例:
./ttyd -p 8080 bash -x
# 頁(yè)面以當(dāng)前用戶的身份和環(huán)境變量進(jìn)行后臺(tái)連接,fork 的方式為 bash 調(diào)試方式運(yùn)行。
./ttyd --max-clients 2 -u 500 top
# 以指定的系統(tǒng)用戶身份的uid運(yùn)行服務(wù),登錄頁(yè)面即為運(yùn)行 top 命令的輸出結(jié)果。

運(yùn)行系統(tǒng)賬戶登錄認(rèn)證

./ttyd --max-clients 2 login
# 以當(dāng)前用戶身份運(yùn)行服務(wù)。

注意:如需root身份登錄終端,需要在屬主屬組為 root 的 /etc/securetty文件中增加可登錄的終端類型pts/0 pts/1 pts/2,當(dāng)然也需要運(yùn)行 ttyd 程序的用戶有可讀 /etc/securetty 文件的權(quán)限(當(dāng)然也就是以 root 身份啟動(dòng) ttyd 服務(wù))。
所以,為安全性考慮,不建議以 root 身份啟動(dòng) ttyd 服務(wù),也就不建議直接以 root 賬戶登錄 ttyd websockets頁(yè)面?zhèn)谓K端。

運(yùn)行特定的后臺(tái)交互式服務(wù)

# console
./ttyd --max-clients 2 -a mysql -h localhost 
// -a, --url-arg 允許url攜帶參數(shù),參數(shù)將直接應(yīng)用到 command 程序中。

# browser 1  使用 command 默認(rèn)參數(shù)
http://localhost:7681

Warning: Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

# browser 2   在url請(qǐng)求中使用指定的 command 參數(shù)
http://localhost:7681/?arg=-uadmin&arg=-pPASSWORD&arg=mysql

mysql> show tables;
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| event                     |
| func                      |
| general_log               |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| innodb_index_stats        |
| innodb_table_stats        |
| ndb_binlog_index          |
| plugin                    |
| proc                      |
| procs_priv                |
| proxies_priv              |
| servers                   |
| slave_master_info         |
| slave_relay_log_info      |
| slave_worker_info         |
| slow_log                  |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
28 rows in set (0.00 sec)

通過(guò) ZMODEM 上傳下載文件,服務(wù)端需安裝 lrzsz

# 向客戶端發(fā)送本地文件
sz a.log

更優(yōu)于 Shellinabox 的 web shell 工具 -- ttyd

# 服務(wù)端接收客戶端上傳的文件
rz

更優(yōu)于 Shellinabox 的 web shell 工具 -- ttyd

使用 SSL 加密傳輸流量

本例使用本地自簽證書(shū)示例

# CA certificate (FQDN must be different from server/client)
openssl genrsa -out ca.key 2048
openssl req -new -x509 -days 365 -key ca.key -subj "/C=CN/ST=GD/L=SZ/O=Acme, Inc./CN=Acme Root CA" -out ca.crt

# server certificate (for multiple domains, change subjectAltName to: DNS:example.com,DNS:www.example.com)
openssl req -newkey rsa:2048 -nodes -keyout server.key -subj "/C=CN/ST=GD/L=SZ/O=Acme, Inc./CN=localhost" -out server.csr
openssl x509 -sha256 -req -extfile <(printf "subjectAltName=DNS:localhost") -days 365 -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt

# 雙向認(rèn)證 client certificate (the p12/pem format may be useful for some clients)(可選)
openssl req -newkey rsa:2048 -nodes -keyout client.key -subj "/C=CN/ST=GD/L=SZ/O=Acme, Inc./CN=client" -out client.csr
openssl x509 -req -days 365 -in client.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out client.crt
openssl pkcs12 -export -clcerts -in client.crt -inkey client.key -out client.p12
openssl pkcs12 -in client.p12 -out client.pem -clcerts

服務(wù)端單向認(rèn)證

./ttyd --ssl --ssl-cert server.crt --ssl-key server.key bash

更優(yōu)于 Shellinabox 的 web shell 工具 -- ttyd

客戶端/服務(wù)端雙向認(rèn)證,需增加--ssl-ca選項(xiàng),桌面瀏覽器另外需要單獨(dú)安裝 client.p12證書(shū)到本地

./ttyd --ssl --ssl-cert server.crt --ssl-key server.key --ssl-ca ca.crt bash

更優(yōu)于 Shellinabox 的 web shell 工具 -- ttyd
更優(yōu)于 Shellinabox 的 web shell 工具 -- ttyd

在 curl 中測(cè)試證書(shū)驗(yàn)證

curl --insecure --cert client.p12[:password] -v https://localhost:7681

如需把服務(wù)掛靠在 Nginx 后端,請(qǐng)配置增加如下 ws 參數(shù):

        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection upgrade;
        proxy_read_timeout 3600

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。

網(wǎng)站欄目:更優(yōu)于Shellinabox的webshell工具--ttyd-創(chuàng)新互聯(lián)
標(biāo)題路徑:http://bm7419.com/article6/geiig.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供自適應(yīng)網(wǎng)站、企業(yè)網(wǎng)站制作、虛擬主機(jī)做網(wǎng)站、微信小程序、品牌網(wǎng)站建設(shè)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

網(wǎng)站建設(shè)網(wǎng)站維護(hù)公司