TermPair lets developers securely share and control terminals in real time๐Ÿ”’

Overview

View and control remote terminals from your browser with end-to-end encryption

Documentation: https://cs01.github.io/termpair

Source Code: https://github.com/cs01/termpair

Try It: https://grassfedcode.com/termpair

PyPI version

What is TermPair?

TermPair lets developers securely share and control terminals in real time.

Usage

Start the TermPair server with termpair serve, or use the one already running at https://grassfedcode.com/termpair.

> termpair serve --port 8000
INFO:     Started server process [25289]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://localhost:8000 (Press CTRL+C to quit)
INFO:     ('127.0.0.1', 51924) - "WebSocket /connect_to_terminal" [accepted]

Then share your terminal by running termpair share:

> termpair share --port 8000
--------------------------------------------------------------------------------
Connection established with end-to-end encryption ๐Ÿ”’
Sharing '/bin/bash' at

http://localhost:8000/?terminal_id=fd96c0f84adc6be776872950e19caecc#GyMlK2LLTqvoyTNzJ+qwLg==

Type 'exit' or close terminal to stop sharing.
--------------------------------------------------------------------------------

You can share that URL with whoever you want. Note that anyone that has it can view and possibly control your terminal.

The server multicasts terminal output to all browsers that connect to the session.

Security

TermPair uses 128 bit end-to-end encryption for all terminal input and output.

The browser must be running in a secure context. This typically means running on localhost, or with secure http traffic (https).

How it Works

TermPair consists of three pieces:

  1. terminal client
  2. server
  3. browser client(s)

First, the termpair server is started (termpair serve). The server acts as a router that blindly forwards encrypted data between TermPair terminal clients and connected browsers.

It listens for termpair websocket connections from unix terminal clients, and maintains a mapping to any connected browsers.

Before the TermPair client sends terminal output to the server, it encrypts it using a secret key so the server cannot read it. The server forwards that data to connected browsers. When the browsers receive the data, they use the secret key to decrypt and display the terminal output. The browser obtains the secret key via a part of the url that is not sent to the server.

Likewise, when a browser sends input to the terminal, it is encrypted in the browser, forwarded from the server to the terminal, then decrypted in the terminal by TermPair, and finally written to the terminal's input.

Run With Latest Version

Use pipx to run the latest version without installing:

Serve:

> pipx run termpair serve

Then share:

> pipx run termpair share --open-browser

Note: pipx caches installations for a few days. To ignore the cache and force a fresh installation, use pipx run --no-cache termpair ....

Installation

You can install using pipx or pip:

> pipx install termpair

or

> pip install termpair

CLI API

> termpair --help
usage: termpair [-h] [--version] {share,serve} ...

View and control remote terminals from your browser

positional arguments:
  {share,serve}

optional arguments:
  -h, --help     show this help message and exit
  --version

To start the TermPair server:

> termpair serve --help
usage: termpair serve [-h] [--port PORT] [--host HOST] [--certfile CERTFILE]
                      [--keyfile KEYFILE]

Run termpair server to route messages between unix terminals and browsers. Run
this before connecting any clients. It is recommended to encrypt communication
by using SSL/TLS. To generate an SSL certificate and private key, run `openssl
req -newkey rsa:2048 -nodes -keyout host.key -x509 -days 365 -out host.crt`.
To skip questions and use defaults, add the `-batch` flag. You can ignore
warnings about self-signed certificates since you know you just made it. Then
use them, pass the '--certfile' and '--keyfile' arguments.

optional arguments:
  -h, --help            show this help message and exit
  --port PORT, -p PORT  Port to run the server on (default: 8000)
  --host HOST           Host to run the server on (0.0.0.0 exposes publicly)
                        (default: localhost)
  --certfile CERTFILE, -c CERTFILE
                        Path to SSL certificate file (commonly .crt extension)
                        (default: None)
  --keyfile KEYFILE, -k KEYFILE
                        Path to SSL private key .key file (commonly .key
                        extension) (default: None)

To share a terminal using the TermPair client:

> termpair share --help
usage: termpair share [-h] [--cmd CMD] [--port PORT] [--host HOST]
                      [--no-browser-control] [--open-browser]

Share your terminal session with one or more browsers. A termpair server must
be running before using this command.

optional arguments:
  -h, --help            show this help message and exit
  --cmd CMD             The command to run in this TermPair session. Defaults
                        to the SHELL environment variable (default: /bin/bash)
  --port PORT, -p PORT  port server is running on (default: None)
  --host HOST           host server is running on (default: http://localhost)
  --no-browser-control, -n
                        Do not allow browsers to control your terminal
                        remotely (default: False)
  --open-browser, -b    Open a browser tab to the terminal after you start
                        sharing (default: False)

System Requirements

Python: 3.6+

Operating System:

  • To view/control from the browser: All operating systems are supported.
  • To run the server, termpair serve: Tested on Linux. Should work on macOS. Might work on Windows.
  • To share your terminal, termpair share: Tested on Linux. Should work on macOS. Probably doesn't work on Windows.
Comments
  • Add contributing guidelines

    Add contributing guidelines

    Just cloned the repo and set it up so I thought I'd write down the process I took in a CONTRIBUTING.md so that it can be used by other people as well. :-)

    opened by florimondmanca 8
  • Secret encryption  key is not valid

    Secret encryption key is not valid

    Describe the bug I follow the instruction to run the programe , but at the last step , it says : secret encryption key is not valid ... could you give me some advise?

    image

    opened by dualven 5
  • --version commandline parsing error

    --version commandline parsing error

    Thanks for TermPair, it's an amazing project!

    Describe the bug

    $ termpair --version
    usage: termpair [-h] [--version] {share,serve} ...
    termpair: error: the following arguments are required: command
    

    termpair doesn't parse correctly --version expecting other arguments and options

    I've installed the latest version with pip, with python 3.9

    good first issue 
    opened by antenore 5
  • Cryptographic suggestions

    Cryptographic suggestions

    Termpair looks awesome and personally I am excited to start using it! I came to it via a thread on HN ... https://news.ycombinator.com/item?id=27338479 . That thread also includes some dissection of the cryptography in TermPair, some of the thoughts there are good, and some are off base. This issue is a summary of my own observations/suggestions in case they are interesting and useful:

    1. Termpair could use a key agreement protocol. Termpair is designed to avoid revealing keys to the server by encoding the key in the anchor fragment of the URL, which a server never sees. This is clever, but a server could still MITM by serving its own malicious HTML. It's actually very possible for two endpoints to share a key in a MITM proof way ... use a key agreement protocol such as ECDH. It's somewhat magical, but they can exchange material and agree a key without anyone in the middle ever being able to figure out what it is. There's some details to get right, like it's useful to have the ECDH be signed and verified by the parties involved, but it's all pretty straightforward.

    2. Keystroke timing is a practical attack. One of the perils of interactive terminal type applications is that human keystrokes can be timed and this timing can reveal what keys are being pressed. It's important to make sure that when a terminal is line-buffered, that the keys aren't sent one by one, but that the whole buffered line is encrypted and sent in one pass. Password inputs (like ssh and sudo) are expected to use line-buffering to mitigate keystroke timing issues. Additionally, it's a good idea to pad a line-buffered input up to a fixed size - this avoid leaking the length of the password entered.

    3. AES-GCM can safely use counters as nonces. This came from the HN thread, but they have a point; it's ok, and actually better to use the message count as the nonce for AES-GCM and it avoids the small odds of collisions occurring.

    4. It's good to use different keys in different directions. It's also a good idea to use a different encryption key in the direction of A to B than from B to A. These keys can be derived from a shared secret using HKDF.

    Some of these may be bewildering, but I'm happy to answer questions. Again, Termpair looks awesome and I don't mean these suggestions as some kind of ding!

    opened by colmmacc 5
  • Improve error message if server is not running

    Improve error message if server is not running

    Traceback (most recent call last): File "/Users/david/.local/bin/termpair", line 8, in sys.exit(main()) File "/Users/david/.local/pipx/venvs/termpair/lib/python3.9/site-packages/termpair/main.py", line 109, in main asyncio.get_event_loop().run_until_complete( File "/usr/local/Cellar/[email protected]/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete return future.result() File "/Users/david/.local/pipx/venvs/termpair/lib/python3.9/site-packages/termpair/share.py", line 231, in broadcast_terminal async with websockets.connect(ws_endpoint, ssl=ssl_context) as ws: File "/Users/david/.local/pipx/venvs/termpair/lib/python3.9/site-packages/websockets/client.py", line 517, in aenter return await self File "/Users/david/.local/pipx/venvs/termpair/lib/python3.9/site-packages/websockets/client.py", line 535, in await_impl transport, protocol = await self._create_connection() File "/usr/local/Cellar/[email protected]/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 1064, in create_connection raise OSError('Multiple exceptions: {}'.format( OSError: Multiple exceptions: [Errno 61] Connect call failed ('::1', 8000, 0, 0), [Errno 61] Connect call failed ('127.0.0.1', 8000)

    opened by wenchengxucool 4
  • allow frontend to be served statically

    allow frontend to be served statically

    This implements a static frontend as suggested in #36.

    background

    Currently, the browser contains decrypted data and the encryption key. If the browser's JavaScript were modified to be malicious and a malicious server were created, it would be hard to detect.

    this pr

    This PR allows the backend to accept cross origin requests, and the frontend to be served statically on GitHub pages, Vercel, or a local static server, which can be manually built. The static page still routes the terminal traffic through a (potentially) untrusted server, but that is okay since the traffic is encrypted before going over the wire.

    Changes

    • Accept cross origin requests on backend
    • Create script to publish built frontend to https://cs01.github.io/termpair/connect/
    • Make UI to define url of TermPair server where encrypted terminal data should be sent via websocket
    • Also added UI to let regular server specify Terminal ID on the landing page instead of requiring it in the URL
    • Update docs
    opened by cs01 3
  • Unable to connect to session if not served by localhost

    Unable to connect to session if not served by localhost

    Hi,

    if I start the server with termpair serve --host 192.168.x.x --port 8000 it successfully binds to the correct interface.

    The shared session is successful initiated with termpair share --host "http://192.168.x.x/" --port 8000

    Browser opens session and server sends HTTP 200 ok (304 for png & js) for every request but the session is always in "connection-pending" state.

    If served/shared using localhost instead, it works without issue.

    Do I miss something here? Any help appreciated.

    opened by 0xphk 3
  • when i close the terminal ,the termpair still runs in backround ,but it is useless in this case; how could i run it in backgroud?

    when i close the terminal ,the termpair still runs in backround ,but it is useless in this case; how could i run it in backgroud?

    termpair share --host https://10.60.100.192 --port 8000 then it is ok to be used ,

    but when I close the terminal , the link like this: https://10.60.100.192:8000/?terminal_id=02453c7728c8cf7a49dc2cbc8df6c109#ATM+7fg7q2hxT3GRtNdeyQ== will lose the effect .

    opened by dualven 2
  • Trying to run termpair on LAN with SSL

    Trying to run termpair on LAN with SSL

    Describe the bug Trying to launch termpair on on LAN (192.168.31.234 on my domestic network), not localhost (127.0.0.1) finishes with message on browser, that i can not use non-secure connection:

    termpair serve -p 8000 --host 192.168.31.234

    and on sharing window:

    termpair share -p 8000 --host 192.168.31.234

    When opening browser with link (which is HTTP) I get from sharing terminal I see next message:

    image

    I decided to run it on LAN, with --keyfile and --certificate options to make secure connection (it is going to set up "HTTPS", right?). So I created SSL certificate with openssl library. The key, certificate are located in /etc/httpd/httpscertificate/ folder . But when I try command:

    termpair serve -p 8000 --host 192.168.31.234 --certfile /etc/httpd/httpscertificate/192.168.31.234.crt --keyfile /etc/httpd/httpscertificate/192.168.31.234.key

    I receive an error:

    TermPair encountered an error. If you think this is a bug, it can be reported at https://github.com/cs01/termpair/issues

    Traceback (most recent call last): File "/home/ooolledj/.local/lib/python3.8/site-packages/termpair/main.py", line 140, in main run_command(args) File "/home/ooolledj/.local/lib/python3.8/site-packages/termpair/main.py", line 124, in run_command uvicorn.run( File "/home/ooolledj/.local/lib/python3.8/site-packages/uvicorn/main.py", line 393, in run server.run() File "/home/ooolledj/.local/lib/python3.8/site-packages/uvicorn/server.py", line 50, in run loop.run_until_complete(self.serve(sockets=sockets)) File "uvloop/loop.pyx", line 1494, in uvloop.loop.Loop.run_until_complete File "/home/ooolledj/.local/lib/python3.8/site-packages/uvicorn/server.py", line 57, in serve config.load() File "/home/ooolledj/.local/lib/python3.8/site-packages/uvicorn/config.py", line 284, in load self.ssl = create_ssl_context( File "/home/ooolledj/.local/lib/python3.8/site-packages/uvicorn/config.py", line 115, in create_ssl_context ctx.load_cert_chain(certfile, keyfile, get_password) PermissionError: [Errno 13] Permission denied

    Sudo command does not help with it

    sudo: termpair: command not found

    I created RSA key and SSL certificate with this guide: https://www.rosehosting.com/blog/how-to-generate-a-self-signed-ssl-certificate-on-linux/ Then I just set path to files them with --keyfile and --certfile options in termpair serve.

    Expected behavior It should accept my .key and .crt files and run termpair on LAN ip-address, which with I can use termpair share for example on my mobile phone and see and type commands

    I FOUND THE SOLUTION. UPDATE: I thought it happens because i can not input certificate password and it does not let me use It. Truly, while writing report I tried to change access to .key file:

    sudo chmod a+r /etc/httpd/httpscertificate/192.168.31.234.key

    After that all my termpair commands with serve, share and --keyfile, --certfile options run perfectly (you can see HTTPS connection is established):

    bkm

    Now the question: how can I protect my .key file from unauthorized access and still be available to run termpair on HTTPS without using chmod a+r on .key file?

    opened by OOOlledj 2
  • Is there an option for read-only sessions?

    Is there an option for read-only sessions?

    The web interface has a green light indicating that you can type, which implies there's an alternative, but I can't find a way to control that. Is there an option along the lines of termpair share --readonly that I just haven't found?

    Perhaps a useful related feature could start the session in read only mode, but a viewer could enter a password to enable typing? termpair share --readonly --password=$foo?

    opened by DaelonSuzuka 2
  • Bump eventsource from 1.1.0 to 1.1.1 in /termpair/frontend_src

    Bump eventsource from 1.1.0 to 1.1.1 in /termpair/frontend_src

    Bumps eventsource from 1.1.0 to 1.1.1.

    Changelog

    Sourced from eventsource's changelog.

    1.1.1

    • Do not include authorization and cookie headers on redirect to different origin (#273 Espen Hovlandsdal)
    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies javascript 
    opened by dependabot[bot] 1
  • About ModuleNotFoundError in windows

    About ModuleNotFoundError in windows

    When I'm using this project in windows ,I found that it cannot work because of there is no module "termios" supported in Windows and I have no idea on how to fix the problem. Is there anyone can make a fix on Windows? It's really helpful on changing it to useful on Windows.Thanks!!!

    help wanted 
    opened by MoonTracer732 2
Releases(v0.3.1.5)
  • v0.3.1.5(Jun 22, 2022)

    What's Changed

    • Bump tmpl from 1.0.4 to 1.0.5 in /termpair/frontend_src by @dependabot in https://github.com/cs01/termpair/pull/91
    • Bump follow-redirects from 1.14.2 to 1.14.7 in /termpair/frontend_src by @dependabot in https://github.com/cs01/termpair/pull/93
    • fix python 3.10 bug by updating dependencies by @cs01 in https://github.com/cs01/termpair/pull/104
    • update pex build command by @cs01 in https://github.com/cs01/termpair/pull/105
    • add pre commit file and run pre-commit run --all-files by @cs01 in https://github.com/cs01/termpair/pull/106

    Full Changelog: https://github.com/cs01/termpair/compare/v0.3.1.4...v0.3.1.5

    Source code(tar.gz)
    Source code(zip)
    termpair_linux.zip(23.06 MB)
    termpair_mac.zip(9.70 MB)
  • v0.3.1.4(Sep 1, 2021)

  • v0.3.1.3(Aug 31, 2021)

  • v0.3.1.2(Aug 23, 2021)

  • v0.3.1.1(Aug 23, 2021)

  • v0.3.1.0(Aug 14, 2021)

  • v0.3.0.0(Aug 10, 2021)

    Breaking API Changes In this version, TermPair clients from previous versions cannot connect to this TermPair server

    • Use new key sharing scheme: Different keys used in different directions; keys rotated
    • [bugfix] Terminal dimensions in browser match upon initial connection, instead of after resizing
    • Allow static site to route terminal traffic through other server. If static site is detected, user can enter the terminal id and server url in the browser UI.
    • Allow Terminal ID and initial encryption key to be entered on landing page
    • Add additional random string to each encrypted message
    • Display version in webpage
    • Add troubleshooting instructions to webpage
    • Rename --no-browser-control argument of termpair share to --read-only
    Source code(tar.gz)
    Source code(zip)
    termpair-linux(20.89 MB)
    termpair-mac(8.08 MB)
  • v0.2.0.0(Jul 20, 2021)

    0.2.0.0

    • Add ability to copy+paste using keystrokes (copy with ctrl+shift+c or ctrl+shift+x, and paste with ctrl+shift+v)
    • Add a status bar to the bottom of the page
    • Show terminal dimensions in bottom status bar
    • Add toasts to notify user of various events
    • Fix bug where connected browsers do not have their websocket connection closed when terminal closes, which makes it look like the terminal is still connected when it is not.
    • Improve error messages, in particular if there is no server running
    • Fixed bug where websocket connection is briefly accepted regardless of whether a valid terminal id is provided to /terminal/{terminal_id}. Instead of returning a JSON object with the TermPair version, a 404 error is now returned.
    • [dev] migrate codebase to typescript
    • [dev] use React functional component instead of class component for main application
    Source code(tar.gz)
    Source code(zip)
  • v0.1.1.1(Jun 2, 2021)

  • 0.1.1.0(Jun 2, 2021)

    0.1.1.0

    • Ensure error message is printed to browser's terminal if site is not served in a secure context (#39)
    • Make default TermPair terminal client port 8000 to match default server port (#38)
    • Always display port to connect to in browser's connection instructions
    Source code(tar.gz)
    Source code(zip)
  • 0.0.1.3(Feb 12, 2020)

  • 0.0.1.2(Feb 12, 2020)

Owner
Chad Smith
Creator of gdbgui, pipx, and various tools. Occasional blogger https://medium.com/@grassfedcode
Chad Smith
Chopper: An Automated Security Headers Analyzer

____ _ _ / ___| |__ ___ _ __ _ __ ___ _ __| | | | | '_ \ / _ \| '_ \| '_ \ / _ \ '__| | | |___| | | | (_) |

Kamran Saifullah (Frog Man) 2 Nov 27, 2022
A Command Line Calculator With Python

CalculadoraPY Usando no Termux apt install python3 apt install git pip3 install termcolor git clone https://github.com/kayke981/CalculadoraPY.git

kayake 5 Jan 30, 2022
โŒจ Toward a more useful keyboard

Toward a more useful keyboard Steve Losh's Modern Space Cadet is an inspiration. It opened my eyes to the fact that there's a more useful keyboard hid

Jason Rudolph 1.7k Jan 01, 2023
Command line tool for monitoring changes of File entities scoped in a Synapse File View

Synapse Monitoring Provides tools for monitoring and keeping track of File entity changes in Synapse with the use of File Views. Learn more about File

Sage Bionetworks 3 May 28, 2022
Easily turn single threaded command line applications into a fast, multi-threaded application with CIDR and glob support.

Easily turn single threaded command line applications into a fast, multi-threaded application with CIDR and glob support.

Michael Skelton 1k Jan 07, 2023
Simple Tool To Grab Like-Card Coupon

Simple Tool To Grab Like-Card Coupon

Soud 10 Jan 30, 2022
Tiny command-line utility for mapping broken keys to other positions.

brokenkey Tiny command-line utility for mapping broken keys to other positions. Installation Clone this repository using git: git clone https://github

0 Oct 04, 2021
An anime command-line system information tool written in python.

Animefetch - v0.0.3 An anime command-line system information tool written in python. Description Animefetch is an anime command-line system informatio

Thadeuks 6 Jun 17, 2022
Color preview command-line tool written in python

Color preview command-line tool written in python

Arnau 1 Dec 27, 2021
A project designed to make taking notes easier than ever - by doing it all on command line

A project designed to make taking notes easier than ever - by doing it all on command line! Yes, all of your files are easily accessible through one command interface, and can be written to at any ti

1 Dec 10, 2021
QueraToCSV is a simple python CLI project to convert the Quera results file into CSV files.

Quera is an Iranian Learning management system (LMS) that has an online judge for programming languages. Some Iranian universities use it to automate the evaluation of programming assignments.

Amirmahdi Namjoo 16 Nov 11, 2022
Command line tool for interacting and testing warehouse components

Warehouse debug CLI Example usage for Zumo debugging See all messages queued and handled. Enable by compiling the zumo-controller with -DDEBUG_MODE_EN

1 Jan 03, 2022
Interactive Redis: A Terminal Client for Redis with AutoCompletion and Syntax Highlighting.

Interactive Redis: A Cli for Redis with AutoCompletion and Syntax Highlighting. IRedis is a terminal client for redis with auto-completion and syntax

2.2k Dec 29, 2022
A Neat Application To Manage Your To-Do Lists.

WTD - What To Do? A Neat Application To Manage Your To-Do Lists. One folder can only have one to-do file. Running wth without any subcommands executes

Adam Vajda 1 Oct 24, 2021
Ros command - Unifying the ROS command line tools

Unifying the ROS command line tools One impairment to ROS 2 adoption is that all

37 Dec 15, 2022
A terminal client for connecting to hack.chat servers

A terminal client for connecting to hack.chat servers.

V9 2 Sep 21, 2022
py-image-dedup is a tool to sort out or remove duplicates within a photo library

py-image-dedup is a tool to sort out or remove duplicates within a photo library. Unlike most other solutions, py-image-dedup intentionally uses an approximate image comparison to also detect duplica

Markus Ressel 96 Jan 02, 2023
Multifunctional library for creating progress bars.

๐Ÿ‘‹ Content Installation Using github Using pypi Quickstart Flags Useful links Documentation Pypi Changelog TODO Contributing FAQ Bar structure โš™๏ธ Inst

DenyS 27 Jan 01, 2023
A simple automation script that logs into your kra account and files your taxes with one command

EASY_TAX A simple automation script that logs into your kra account and files your taxes with one command Currently works for Chrome users. Will creat

leon koech 13 Sep 23, 2021
xonsh is a Python-powered, cross-platform, Unix-gazing shell language and command prompt.

xonsh xonsh is a Python-powered, cross-platform, Unix-gazing shell language and command prompt. The language is a superset of Python 3.6+ with additio

xonsh 6.7k Jan 08, 2023