Skip to content

Tsharking

TheDiveO edited this page Dec 24, 2023 · 4 revisions

Real Programmer's Command

Yes, you can capture container traffic using tshark and the csharkextcap plugin. Yes, you'll admit that there are probably better ways to achieve your goal, such as using our csharg CLI tool and piping its output into tshark. But you're a Real Programmer.

Now that you've been warned, here's how to capture traffic from the network interfaces eth0 and lo from the container edgeshark-gostwire-1 with the hierarchical prefix services.linuxkit/01-docker. If you're not using Docker Desktop, simply leave out the "prefix" element in the JSON data. For the following command, you'll need jq to be installed in your system.

tshark -i mobyshark \
    -o "extcap.mobyshark.container:$(jq -rn --arg x '{"name":"edgeshark-gostwire-1","prefix":"services.linuxkit/01-docker","network-interfaces":["eth0,lo"]}' '$x|@uri')" \
    -o 'extcap.mobyshark.dockerhosturl:http://localhost:5001'

Please note that the extcap.mobyshark.container property is very picky in terms of (container) name and prefix. You see, all this is normally handled behind the scenes in perfection, based on detailed discovery information.

csharg

Ease the CLI pain using csharg: either go to the csharg project page and download a build binary, or if you have the go toolchain installed simply run go install github.com/siemens/csharg/cmd/csharg@latest. After installing the CLI binary...

# list available capture targets
csharg --host http://localhost:5001 list
# capture!
csharg --host http://localhost:5001 capture container edgeshark-gostwire-1 | tshark -i -

You might notice that csharg is much more forgiving in terms of prefixes. If you don't specify them it'll try to find a suitable match nevertheless. For more details, csharg help and csharg help capture container are your friends.

Clone this wiki locally