Enrico Zini: nc sudo
Question: what does this command do?
Answer: it sends the password typed into sudo to the other endpoint of netcat.
I can reproduce this with both nc.traditional and nc.openbsd.
One might be tempted to just put sudo in front of everything, but it'll mean
that only nc will run as root:
The fix that I will never remember, thanks to twb on IRC, is to close nc's
stdin:
Or flip the table and just use
Updates
Harald Koenig suggested two alternative spellings that might be easier to remember:
And thinking along those lines, there could also be the disappointed face variant:
Matthias Urlichs suggested the approach of
precaching sudo's credentials, making the rest of the command lines more
straightforward (and TIL:
Or even better:
Shortcomings of nc tar
Tomas Janousek commented:
# Don't do this nc localhost 12345 sudo tar xf -
# This is probably not what you want sudo nc localhost 12345 tar xf -
<&- nc localhost 12345 sudo tar xf -
sudo -s
:
$ sudo -s # nc localhost 12345 tar xf -
nc localhost 12345 < /dev/null sudo tar xf - < /dev/null nc localhost 12345 sudo tar xf -
: nc localhost 12345 sudo tar xf -
sudo id
):
sudo id nc localhost 12345 sudo tar xf -
sudo id && nc localhost 12345 sudo tar xf -
There's one more problem with a plain tar nc tar without redirection or extra parameteres: it doesn't know when to stop. So the best way to use it, I believe, is:tar c nc -N
nc -d tar x
The-N
option terminates the sending end of the connection, and the-d
option tells the receiving netcat to never read any input. These two parameters, I hope, should also fix your sudo/password problem. Hope it helps!