5 ms·
A Unix Utility You Should Know About: Netcat
- neovive 18y agoVery interesting utility. It's mini-apps like these that make Unix such a powerful and flexible platform. I have to try it out on Ubuntu.
- old-gregg 18y agoHm... Neat, but it looks like unencrypted mini-ssh to me, at least that's what I use to quickly send files or tunnel X between machines. What did I miss?
- pwk 18y agoMost of the things one wants or needs to do on the net are most easily accomplished with dedicated tools, so places where only netcat will serve are rare. It comes in handy for odd corner cases, or in restricted environments where dedicated tools might not be present (it was invaluable when I was a consultant).
- reconbot 18y agoIt's tiny, you don't need keys, it can run any any port privileged or not with or without an install. It can take a port and pipe it to a shell, or a program, or the file system. I guess I didn't say anything the article didn't, I've mostly seen it as part of rootkits honestly. Good tools can be used for anything good or bad.
- biohacker42 18y agoThink of *nix as Lego. You can build anything with just plain white bricks but it's fun to play with the special brightly colored ones too.
- yan 18y agonc is also great for redirecting *sqldump over the wire and importing directly on another machine. Using "nc -l" (for listen) and pointing a browser to it also let's you know plenty about what headers a browser is sending. (Yes, you can get a tool made especially for that, but when you don't, it's a great two second hack.)
- pwk 18y agoSometimes handy for me: if you have information that you've sent in an HTTP POST, and you need to recover it for whatever reason, there's often no easy way to get at it from the browser interface. The browser will send the data again if you reload the page, so: 1. In a terminal, startup netcat as a listener: nc -l -p9999 2. In your browser, configure the connection preferences to use manual proxy settings of host "localhost" and port "9999" 3. Hit reload on the browser, and tell it "yup, send the POST data again" 4. Look at the output of netcat (Don't forget to change your proxy settings back!)
- there 18y agoa firefox extension like tamper data is much easier than doing all that - https://addons.mozilla.org/en-US/firefox/addon/966 https://addons.mozilla.org/en-US/firefox/addon/966 or just use a sniffer like wireshark and let it reconstruct the tcp stream - http://www.wireshark.org/ http://www.wireshark.org/
- pwk 18y agoAbsolutely. I already wrote in another part of this discussion "Most of the things one wants or needs to do on the net are most easily accomplished with dedicated tools, so places where only netcat will serve are rare." On the other hand, my little trick does just take a few seconds, and is probably easier than getting ethereal (oops, wireshark) set up for someone new to it. I do think it's still useful to be aware of and play with tools like netcat, even when there are dedicated tools to accomplish most tasks. It's a bit like hacking in assembly... probably not practical in many cases, but you'll learn how stuff works underneath, and that understanding can still be really useful even when working at a higher level of abstraction.
- yeahit 18y agoYou might also like this way of looking at all the requests your browser is doing to a certain host: http://en.gibney.org/capture_webtraffic/ http://en.gibney.org/capture_webtraffic/
- shax 18y agoI'm surprised to hear that people have forgotten about Netcat!
- kurtosis 18y agosocat is better IMHO http://www.dest-unreach.org/socat/ http://www.dest-unreach.org/socat/
- ruby_roo 18y agoUs Rubyists are used to using curl for testing our REST apps. What additional help/insight can netcat provide when building REST apps? Or Rails apps in general? Is there any?
- tlrobinson 18y agocurl is higher level. It implements a number of protocols like HTTP. nc is basically raw sockets. You can listen on a port with curl like you can with nc.
- tlrobinson 18y ago"can't listen on a port with curl" Sorry, waited too long to edit.
- mct 18y agoMy favorite nc trick of late is using it in combination with ssh_config(5)'s "ProxyCommand" directive. "ProxyCommand" tells ssh to use the specified command's stdin and stdout to communicate with the destination host, rather than establishing a TCP connection itself. For example, if I can connect to the host "bastion", and if "bastion" can connect to the host "destination", but I cannot connect directly to "destination", I can stick the following in my ~/.ssh/ssh_config file: host destination ProxyCommand ssh bastion nc -w 1 destination 22 Much cleaner, and easier to manage than tunnels.
- paulgb 18y agoAnother use of netcat is to stream video or audio from one computer to another. All you need is a player that supports playing from standard input.
- tlrobinson 18y agonc is one of the first tools I install on a fresh OS.
- jncraton 18y agoTheir link to netcat for windows supposedly from security focus definitely points to my website. I'm not actually affiliated with security focus in any way... http://joncraton.org/files/nc111nt.zip http://joncraton.org/files/nc111nt.zip edit: They've fixed the link to actually point to securityfocus
- fuzzbang 18y agoNetcat is an old and venerable Unix hacker tool. If you want to be a better hacker the netcat README is required reading. I would also recommend reading the source code, in particular the comments. Hobbit can be quite funny at times. Netcat is usually installed on linux systems these days, but it is seldom compiled with -DGAPING_SECURITY_HOLE like it should be. Those really were the good old days...