pty

command
v0.0.0-...-377b236 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2015 License: Apache-2.0 Imports: 13 Imported by: 0

README

From simple reverse shell to remote tty and terminal resize

Simple

Connect a program's stdin/out/err to a socket and back:

  • server: socat TCP-LISTEN:1337,reuseaddr,fork EXEC:bash
  • client: socat - TCP:localhost:1337

Problems:

  • ^C quits your shell, not an app on the other end (very frustrating!)
  • it doesn't handle tty programs such as top or vim

TTY

Alright, we can do better:

  • server: socat TCP-LISTEN:1337,reuseaddr,fork EXEC:bash,pty,stderr,setsid,sigint,sane
  • client: socat FILE:`tty`,raw,echo=0 TCP:localhost:1337

Problems:

  • resizing the local terminal does not resize the remote terminal
  • we can use stty rows X cols Y but on every window resize it is painful

TTY and terminal resize

Signal SIGWINCH is delivered when the window size changes, and we can use ioctl TIOCGWINSZ to know the rows/cols of the local terminal. With that, we can send it over to the other end, and set the window size with the TIOCSWINSZ iotctl counterpart. However the socket is taken for relaying the tty data, so we need to multiplex some sort of control channel to send the window change event and window size information.

See: server and client.

Add some TLS and you're not too far from SSH! We could even add port forwarding or file transfer, why not even inline using the control channel to handle commands and multiplex new streams on the fly...

Documentation

Overview

Binary client connects to a remote tty shell on the network.

Binary server exposes a local tty shell on the network.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL