Connecting to a Remote Serial Port over TCP/IP

Ever needed a way to communicate with some RS232 enabled device remotely? Well this is where socat, docker, and shellinabox comes in handy.

On a device that is connected via serial rs232 which will act as a host. Using the following install script one will have the environment setup:

#!/bin/bash

export DOCKERHOST=$(ifconfig | grep -E "([0-9]{1,3}\.){3}[0-9]{1,3}" | grep -v 127.0.0.1 | awk '{ print $2 }' | cut -f2 -d: | head -n1)

sudo apt install docker docker-compose socat

install -d $HOME/shell

cat -> $HOME/shell <<-DOCKERFILE
	# Dockerfile
	FROM sspreitzer/shellinabox:latest
	RUN apt -y install netcat unzip zip unrar-free wget ca-certificates
	ENV SIAB_PASSWORD=change
	ENV SIAB_SUDO=false
	ENV SIAB_SHELL=netcat dockerhost:8888
DOCKERFILE

cat -> $HOME/shell/docker/docker-compose.yml <<-DOCKERCOMPOSEYML
	services:
		shell:
    			build: .
    			restart: always
    			ports:
				- 443:4200/tcp
			extra_hosts:
				- "dockerhost:${DOCKERHOST}"
DOCKERCOMPOSEYML

crontab -l | sed '$@reboot bash -c "cd $HOME/shell; sudo docker-compose up -d"' | crontab
crontab -l | sed '$@reboot sudo socat /dev/ttyUSB0,raw,echo=0 tcp-listen:8888,reuseaddr' | crontab
sudo reboot

What this does is install the needed tools, deploys shellinabox via docker so one can visit the IP of the terminal server (raspberry pi or such) and directly access what is connected via com port 1.

Suggested devices

Why?

Say one has some old dos systems that they’re running as a bbs, or even a few arduino projects. Instead of trying to build a custom esp232 modem one can use established systems to remotely access devices. This also can be extended into Ham, IoT, and SCADA hacking or just about anything where a serial comms connection is available.

Best part is if one includes zerotier or dyndns then they can create a qr code which on scanning connects directly to that remote machine via a browser.

Additional reading

1 Like

Almost forgot:

dos commands to setup a remote console:

; autoexec.bat
@ECHO OFF
MODE COM1:9600,n,8,1
CTTY COM1

Besure to include a good menu program. Dos-shell or dosmenu are a good option: http://www.lanet.lv/ftp/simtelnet/msdos/menu/dosmenu.zip. So is quarterdeck’s DESQview.

For unix machines there’s getty - https://man.cx/getty(8) and other systems one can use a BBS system of choice.

userport systems would need a custom board made:

http://www.pitsch.de/stuff/magicdisk64/md8812.htm

update:
prebuilt device available for $35 - https://www.tindie.com/products/gglabs/glink-lt-commodore-64-user-port-rs-232-vic1011/

I would just VPN to my home router/firewall (Cisco) then ssh to my CCIE rack’s terminal server router where I could access every device’s serial console port. :slight_smile:

Network geeks do it differently than Linux geeks. :smiley:

1 Like

yeah that is the usual networking admin answer but not all of us are using rs232 for managing routers.

On Plan9 you can run TCP/IP over RS232 and RS232 over TCP/IP with ~zero effort too.: https://news.ycombinator.com/item?id=13500764

Scada uses it too: https://www.raveon.com/scada-and-telemetry-communications/
IoT as well: https://iotfactory.eu/products/iot-sensors/lorawan-to-rs232-converter/

Esp and BBSing use it nearly exclusively: http://biosrhythm.com/?p=1359

Ham does: https://www.hamradio.com/detail.cfm?pid=H0-016167

I came up with this as a solution for controlling old vintage/retro machines while also being a good solution for a LoRa, picosat, or APRS/ham lab instead of some ‘cult of the mac’ over engineered ios only design floating around.

Hell, the shell in a box part could just be dropped for haproxy and ftelnet.js instead.