That's typically what the -v
and -x
options of socat
are for.
-v
dumps the data to stderr with some transformation like the CR character becomes \r
so you can see it.
-x
does a hex dump (not very useful though as there's no timestamp or indication of what direction the dumped traffic is flowing in).
With -v
and -x
combined, you get a hd
type of dump with timestamp and direction:
> 2014/03/08 08:46:23.370824 length=4 from=0 to=3
61 64 73 0a ads.
--
< 2014/03/08 08:46:23.398666 length=1371 from=0 to=1370
48 54 54 50 2f 31 2e 30 20 34 30 30 20 42 61 64 HTTP/1.0 400 Bad
20 52 65 71 75 65 73 74 0d 0a Request..
43 6f 6e 74 65 6e 74 2d 54 79 70 65 3a 20 74 65 Content-Type: te
[...]
If you want it dumped to a file, you can redirect stderr to a file and the debugging output redirected to stdout with:
socat -d -d -lf /dev/stdout -x -v 2> dump.txt \
"READLINE,history=$HOME/s.hist" \
openssl:host:port,crnl,cafile=some.ca
You can also convert that to a pcap with text2pcap
(that comes with wireshark) after a little post-processing, using:
{
socat -d -d -lf /dev/stdout -x -v 2>&1 >&3 3>&- \
"READLINE,history=$HOME/s.hist" \
openssl:host:port,crnl,cafile=some.ca |
awk '/^[<>]/{a=0;print $1 == "<" ? "I" : "O", $2, $3; next}
{$0 = substr($0, 1, 48);printf "%.4x %s\n",a,$0;a+=NF}' |
text2pcap -l 147 -Dnqt '%Y/%m/%d %H:%M:%S.' - dump.pcap
} 3>&1
That pcap using encapsulation 147. That's not a link layer type, but wireshark understands it as a user encapsulation.
Then, we can tell wireshark that the packets contain HTTP traffic for instance with:
wireshark -o 'uat:user_dlts:"User 0 (DLT=147)","http","0","","0",""' \
-o 'gui.column.format:"No.","%m","Time","%Yt",
"Direction","%Cus:frame.packet_flags_direction:0:R","Protocol","%p",
"Length","%L","Information", "%i"' -r dump.pcap
(here also modifying the displayed columns as well, since there's no address, but we have the traffic direction (provided by text2pcap -D
after we've converted the <
, >
to I
, O
)).
You can see the traffic live with wireshark
by piping the text2pcap
output to wireshark
called with -ki -
instead of -r dump.pcap
, but then wireshark
only supports the old pcap
format, not pcap-ng
which means we have to drop the -n
option of text2pcap
and we lose the information of the direction:
{
socat -d -d -lf /dev/fd/3 -x -v 2>&1 >&3 3>&- \
"READLINE,history=$HOME/s.hist" \
openssl:host:port,crnl,cafile=some.ca |
awk '/^[<>]/{a=0;print $1 == "<" ? "I" : "O", $2, $3; next}
{$0 = substr($0, 1, 48);printf "%.4x %s\n",a,$0;a+=NF}' |
text2pcap -l 147 -Dqt '%Y/%m/%d %H:%M:%S.' - - |
wireshark -o 'uat:user_dlts:"User 0 (DLT=147)","http","0","","0",""' \
-o 'gui.column.format:"No.","%m","Time","%Yt",
"Direction","%Cus:frame.packet_flags_direction:0:R","Protocol","%p",
"Length","%L","Information", "%i"' -ki -
} 3>&1
socat
's-v
/-x
option?socat -v
/-x
.