Some time has passed since I dealt with this topic, and actually could not verify what my friend, Denis Vlasenko , accompanying Busybox, proposed as a solution for me several months ago. Since I just checked my StackOverflow account and saw this question again, let me share my thoughts with you. Maybe this is useful for someone:
One relatively easy hack I can offer is this:
I assume that you have a working server application that opened a listening socket for a Unix domain (say /tmp/some.socket
), and client programs connect to it and talk to the server.
- rename
/tmp/some.socket
β /tmp/some.socket1
- create a new socket /tmp/some.socket
- listen to it for new client connections
- for each such connection, open another connection with
/tmp/some.socket1
with the original server process. - pump data (client β server) for the resulting pairs of sockets (the code for this is very similar to the telnetd server) until the EOF is on both sides.
While you are pumping data, itβs easy to view it, save it, and even change it if you need to.
The disadvantage is that this sniffer program must be restarted each time the original server program is restarted.
This is similar to what Celada answered. Thanks to him! However, Denys answer was a bit more specific.
I asked:
It sounds hacked, yes, due to the need to reboot, but possible. I am not a C programmer, I continue to wonder if you know a command line tool that can do pass-through and logging event-based work for me. I have one guy from our project in mind who could crack a little C for this, but I'm not sure if he likes to do this. If there is anything in advance, I would prefer. Can it even be done with (a combination of) BusyBox applets, perhaps?
Denys answered again:
You need to build busybox with CONFIG_FEATURE_UNIX_LOCAL=y
.
Start the capture server:
busybox tcpsvd -vvvE local:/tmp/socket 0 ./script.sh
Where script.sh is a simple end-to-end connection to the "source server":
#!/bin/sh busybox nc -o /tmp/hexdump.$$ local:/tmp/socket1 0
As an example, I added hexadecimal logging to the file ( -o FILE
).
Test it by running the emulated "source server":
busybox tcpsvd -vvvE local:/tmp/socket1 0 sh -c 'echo PID:$$'
and connecting to the "interception server":
echo Hello world | busybox nc local:/tmp/socket 0
You should see the message "PID: 19094" and have a new /tmp/hexdump.19093
file with the data reset. Both tcpsvd processes should print some kind of log too (they run with -vvv
verbosity).
If you need more complex processing, replace the nc call in script.sh
with the user program.