Questions tagged [socat]

The program socat is a relay for bidirectional data transfer between two independent data channels.

socat - Multipurpose relay

From the README:

socat is a relay for bidirectional data transfer between two independent data channels. Each of these data channels may be a file, pipe, device (serial line etc. or a pseudo terminal), a socket (UNIX, IP4, IP6 - raw, UDP, TCP), an SSL socket, proxy CONNECT connection, a file descriptor (stdin etc.), the GNU line editor (readline), a program, or a combination of two of these.

These modes include generation of "listening" sockets, named pipes, and pseudo terminals.

socat can be used, e.g., as TCP port forwarder (one-shot or daemon), as an external socksifier, for attacking weak firewalls, as a shell interface to UNIX sockets, IP6 relay, for redirecting TCP oriented programs to a serial line, to logically connect serial lines on different computers, or to establish a relatively secure environment (su and chroot) for running client or server shell scripts with network connections.

Many options are available to refine socats behaviour: terminal parameters, open() options, file permissions, file and process owners, basic socket options like bind address, advanced socket options like IP source routing, linger, TTL, TOS (type of service), or TCP performance tuning.

148 questions
18
votes
4 answers

Tell socat to listen to connections from a single IP address

socat TCP-LISTEN:22,fork TCP:192.168.0.15:5900 How can I tell to socat, that port 22 is only trusted from the remote IP address 8.8.8.8, and it should not accept connections from other IP addresses? This is on a Linux server.
user11085
17
votes
1 answer

Stop socat from terminating when other end closes

I'd like to redirect an applications input and output to a unix socket and connect to that socket from another session. What I'm doing so far is the following: On the "server" side: socat EXEC:"command" UNIX-LISTEN:/tmp/comm And on the "client"…
bot47
  • 1,238
  • 4
  • 14
  • 23
12
votes
1 answer

How does moving a unix domain socket enable socat to monitor traffic?

socat can be used to monitor traffic across a Unix domain socket: sudo mv /path/to/sock /path/to/sock.original sudo socat -t100 -x -v UNIX-LISTEN:/path/to/sock,mode=777,reuseaddr,fork UNIX-CONNECT:/path/to/sock.original I don't quite understand how…
Matt R
  • 375
  • 4
  • 10
10
votes
1 answer

Comunicate with remote Serial over TCP/IP as /dev/ttyX device

I've one serial device on 192.168.x.x:yyyy (where "x" and "y" are real number) and it works correctly. But I want to communicate with this as /dev/ttyX device. I've tested socat command but not working correctly $ while true; do socat…
Domenico M.
  • 241
  • 1
  • 2
  • 8
9
votes
1 answer

Can socat be started directly by systemd?

The following socat command-line works as expected when entered at a shell prompt: # /usr/bin/socat UDP-RECV:4321 STDOUT It listens on UDP port 4321 and writes everything received to standard output. The following is an attempt at starting this…
starfry
  • 7,302
  • 6
  • 47
  • 69
8
votes
3 answers

How to record an interactive socat TCP/TLS session?

Socat is great for interactively testing line based human readable protocols like HTTP or IMAP. For example: $ socat -d -d READLINE,history=$HOME/s.hist openssl:host:port,crnl,cafile=some.ca For better analyzing I need to capture such an…
maxschlepzig
  • 56,316
  • 50
  • 205
  • 279
7
votes
2 answers

How can I add message delimiters to a UDP stream socat is piping?

I am using socat to intercept UDP messages and send them to a named pipe: socat UDP-LISTEN:9999,fork PIPE:/tmp/mypipe,append I am able to tail this pipe and see all the messages it receives. I would like to pipe the output of tail -f /tmp/mypipe to…
abc
  • 73
  • 5
7
votes
1 answer

socat gives error (read(6, 0xf97acc0, 8192): Permission denied)

I'm trying to use socat as a port mapper to map IPv4 connections to my OpenVPN server running behind a DS-Lite IPv6 cable connection. //edit I tried with a non root user and root. But I get the same result with both users. //edit Goal is to be able…
devployment
  • 181
  • 1
  • 3
7
votes
1 answer

Create UDP to TCP bridge with socat/netcat to relay control commands for vlc media-player

The UDP - must listen on port. The TCP - must connect to a server. I tried netcat and socat. nc -v -u -l -p 3333 | nc -v 127.0.0.1 50000 socat -v UDP-LISTEN:3333,fork TCP:localhost:50000 Both work -- they delivered the message -- but the line is…
Mihai Popescu
  • 95
  • 1
  • 1
  • 5
7
votes
1 answer

How can I redirect all UDP traffic from one port to another on BSD / OS X?

On Mac OS X 10.9.5 I am running boot2docker and would like to temporarily forward a non-privileged UDP port 69 to port 69 of the boot2docker virtual machine. Virtualbox only supports forwarding privileged ports. I've tried running socat like…
cwd
  • 44,479
  • 71
  • 146
  • 167
6
votes
1 answer

Virtual serial port between docker containers

I can create two linked virtual serial ports on a Linux system with socat, and pretend one end is a serial device, and the other one is some code that uses the device. The socat command would look like: socat -d -d pty,raw,echo=1 pty,raw,echo=0 And…
JonasVautherin
  • 395
  • 1
  • 9
  • 19
6
votes
1 answer

socat - UART logging and redirecting

I am currently trying to log all communication from and to /dev/ttyUSB0 and simultaneously be able to connect minicom/screen to the same device for interaction. I tried a couple of tools and tutorials but they all seem to occupy the device, so I…
Chris
  • 63
  • 1
  • 1
  • 3
6
votes
1 answer

How can I repeatedly send the contents of a file via socat / ncat to a socket

I'm running some performance testing, and I'm trying to send the same file repeatedly to a socket. If I do something like: $ socat -b1048576 -u OPEN:/dev/zero TCP4-LISTEN:9899,reuseaddr,fork $ socat -b1048576 -u TCP:127.0.0.1:9899…
Alun
  • 409
  • 1
  • 4
  • 7
6
votes
0 answers

Using socat to Tunnel/Proxy TCP want to split send/receive into separate files

I'm using socat to dump plain TCP (e.g. HTTP) traffic: socat -v tcp-listen:$PORT,reuseaddr,fork,keepalive tcp:$TARGET_HOST:$TARGET_PORT At the moment all send and receive traffic is dumped into output stream. I'd like to split the send/receive into…
6
votes
2 answers

socat duplicate stdin to each connected client

ncat (from the nmap folk) has a neat default action of duplicating any input to all connected clients. E.g.: Start a server on terminal 1: % mkfifo messages % exec 8<>messages # hold the fifo open % ncat -l 5555 -k --send-only < messages Start…
whiteinge
  • 255
  • 3
  • 9
1
2 3
9 10