Skip to content

Instantly share code, notes, and snippets.

@pboothe
Created June 6, 2018 17:34
Show Gist options
  • Save pboothe/c90b0a64fe5333bfd29d3538d9482729 to your computer and use it in GitHub Desktop.
Save pboothe/c90b0a64fe5333bfd29d3538d9482729 to your computer and use it in GitHub Desktop.
A command that spies on a binary by being run in its place, calling the original and forking all input and output to logfiles as well as the called subprocess
#!/bin/bash
OUTPUT=$(mktemp -d --tmpdir=/tmp "$(date -Iseconds).$(basename $0).XXXXXXX")
echo "$@" > "${OUTPUT}/cmdline"
env > "${OUTPUT}/env"
cat - \
| tee "${OUTPUT}/input" \
| /usr/cni/bin/$(basename $0) $@ \
| tee "${OUTPUT}/output"
cd "${OUTPUT}"
cat cmdline \
<(echo ===) \
env \
<(echo ===) \
input \
<(echo ===) \
output \
> summary
@pboothe
Copy link
Author

pboothe commented Jun 6, 2018

Currently only works with binaries in /usr/cin/bin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment