Live data from Hacker News

Cool stuff you can do with netcat

en.wikipedia.org

11–20 of 44 posts

Re: Cool stuff you can do with netcat

#11

Don't forget easy ssh host hopping. ssh -oProxyCommand="ssh host1 nc host2 22" host2

I used nc to do just this for years until I switched companies and found that many of the hosts didn't have nc installed.

To get around that I just added the following to my bashrc

alias remote_host="ssh -t bastion ssh -t host1 ssh host2"

Re: Cool stuff you can do with netcat

#12

Anyone want to give a few examples of cool things they actually do with netcat?

1. Schlepping files between computers.

computer A:

    nc -l $ARBITRARY_PORT | tar vzxf -
computer B:

    tar vzcf - files_or_directories | nc computer_a $ARBITRARY_PORT
2. Testing socket servers:

    cat canned_request | nc server 80
There are probably other things, but I don't think, "Oh, this is a good use for netcat", I just do it. It's almost as handy as awk.

Re: Cool stuff you can do with netcat

#13
post #4

Anyone want to give a few examples of cool things they actually do with netcat?

I use it for: - creating quick and dirty proxies (nc > fifo > nc). (edit: you can also bridge udp->tcp this way, which makes proxying UDP through an ssh tunnel possible) - making simple GET requests (printf "GET / HTTP/1.0\r\nHost: www\r\n\r\n" | nc host 80, or save the full request and pipe that to netcat) - checking if a port is open (nc -p 8080 host, tends to be quicker than nmap and less to type) - dumb file tran…

I suggest, evolve. ssh, curl/wget, nmap, scp

But yeah, 10100111001

Re: Cool stuff you can do with netcat

#14

Anyone want to give a few examples of cool things they actually do with netcat?

This is pretty much the fastest way I've found to clone a disk over a network. To clone from one host's /dev/sda to another host's /dev/sda in Linux, try this.

On the target host, run the following:

nc -l 31337 | bzip2 -d | dd bs=16M of=/dev/sda

On the host you're copying from, do this:

dd bs=16M if=/dev/sda | bzip2 -c |nc dest.host.com 31337

Bear in mind that this isn't secure (everything goes over the wire in clear and there's no auth) and that for best results you should only do this from a live cd (if you're dd'ing from or to the live drive you've mounted there's a high risk that you'll change the filesystem mid-copy, depending on source FS used, this could corrupt the destination).

Re: Cool stuff you can do with netcat

#15

Anyone want to give a few examples of cool things they actually do with netcat?

A few days ago I was wondering if the link between two remote hosts was 100Mbps or 1Gbps, and didn't have root access to run ethtool (sidenote: is there an easier way for an unprivileged user to determine this?), so out came netcat and dd:

  host1$ dd if=/dev/zero | nc host2 5432

  host2$ nc -l 5432 > /dev/null
Let it run for a moment and then ctrl-C'd host1; the stats dd printed on exit gave a pretty clear answer to my question.

Re: Cool stuff you can do with netcat

#16

Anyone want to give a few examples of cool things they actually do with netcat?

I use netcat to simulate a network connectivity failures.

For instance, if server:port 1000 is the normal host and port my application would connect to, I set up a forward from port 2000:

    nc -L server:1000 2000
then run my application to connect to localhost:2000

    my_application --server=localhost --port=2000
Now my application is connected to localhost:2000, which is forwarded to server:1000 through netcat. To simulate a network connectivity failure I just kill netcat.

Re: Cool stuff you can do with netcat

#18

I actually got in trouble trying to use netcat for something quite legitimate in my former job at RandomBigCorp... Oops.

Please elaborate? At my current place of employment, "hacking tools" are banned. On that list is netcat. It is installed on every unix desktop and server, and I use it daily. I have decided to just not point out the stupidity of this -- they might do something that's even more stupid as a response.

I always wondered about screwball policies like that. It just seems so incredibly short-sighted to not use the best tools for the job.

"If you want me to defend you from the bad people on the net, then don't send me to a gun fight with only a knife."

Re: Cool stuff you can do with netcat

#19

I actually got in trouble trying to use netcat for something quite legitimate in my former job at RandomBigCorp... Oops.

Please elaborate? At my current place of employment, "hacking tools" are banned. On that list is netcat. It is installed on every unix desktop and server, and I use it daily. I have decided to just not point out the stupidity of this -- they might do something that's even more stupid as a response.

Yeah that is ridiculous. It's misleading for potential netcat users. And by banning it there can be no discussion about how to actually use it safely and responsibly.

"hacking tools" are banned.

If you are asked about it. The best way is to respond that you use it as a a diagnostic tool or analysis tool.

As for arguing it's not a hacking tool - A person could take something as innocent as VBScript for Office and write viruses with it. Nothing you can do about your tools ability to be abused.

Post reply on HN