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
- https://www.amazon.com/USB-Serial-Adapter-Prolific-PL-2303/dp/B003WOWBBW/
- Amazon.com
- End system your remotely controlling
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.