Giter VIP home page Giter VIP logo

websocket-tty's Introduction

websocket-tty

This incredible piece of software allows you to execute shell commands on your local machine, from your browser, via websockets.

Why would anyone do such a thing, you ask? I'm using it to demonstrate shell-based stuff in my browser-based presentations using Shower. As soon as I've made the JavaScript side of this process presentable, I will open-source it and link it here.

Security warning

The server allows to execute arbitrary commands, only limited by the permissions of the user it is being run with (read: don't run as root please). The server binds to localhost, and will not accept any remote connections by default.

How to use?

Clone, run go get (because we depend on go.net/websocket) and then go run main.go -path initial/working/directory. You can now send websocket messages to http://localhost:8080/exec, according to the protocol defined below.

How are commands executed?

They're executed using exec.Command, wrapped into a bash -c 'your command' invocation. This allows you to do bash stuff like touch bar && cat foo > bar.

An exception is the cd command. Since commands executed using exec.Command run using the parent processes working directory, running bash -c 'cd ..' would be quite useless, as it doesn't change the working directory of the parent. Thus if the command begins with cd (cd followed by a space), the command is not run using bash -c and instead changes the working directory of the websocket-tty process.

"Protocol"

After spending several minutes researching state of the art command execution protocols, I came up with the following JSON messages.

Request:

{ "Cmd": "ls -la" }

Response:

{ "Result": "foo\nbar\nbaz", "Error": "" }

If "Error" is empty in the response, no error occurred.

Contributing

If that's something you want, I'd be thrilled :) Drop me a pull request.

websocket-tty's People

Contributors

x3ro avatar

Watchers

James Cloos avatar lelequ avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.