0

Not sure if this belongs on here, StackOverflow, or SuperUser.

I have a device running a reverse telnet server that I need to be able to send/receive data to. I'm able to play with it if I run socat like so and telnet into port 8002:

sudo socat TCP-LISTEN:8001 TCP-LISTEN:8002

However, it sends information it shouldn't, and I'm trying to use sed to filter this data out. I'd like this communication to remain bi-directional (that is, anything I type into telnet on localhost:8002 gets sent out through localhost:8001 and vise versa).

I've tried using a bash script containing:

#!/bin/bash
sed (my regex here) | socat - TCP-LISTEN:8002

and then running:

sudo socat TCP-LISTEN:8001 SYSTEM:./replace.sh

But that outputs nothing in the telnet console. I've also tried EXEC: to the same nothing happening.

I've even tried:

sudo socat TCP-LISTEN:8001 "SYSTEM:'sed (my regex here)' || TCP-LISTEN:8002"

to no effect.

0

You are just missing the fork bit. The command line would then be:

socat TCP-LISTEN:8002,fork SYSTEM:/path/to/replace.sh

then, the file /path/to/replace.sh should have the execution permission and could contain something like (this will change all 'a's to 'b's):

#!/bin/bash

sed -u 's/a/b/g'

If you are using sed, it is important to add the -u (unbuffered) flag.

1
  • Thank you! This worked perfectly! I was wondering how to go around sed's character buffering with this!
    – DDPWNAGE
    Jan 7 '20 at 17:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.