Netcat 仅在我 CTRL-C 连接后发送应答
Netcat only sends answer after I CTRL-C the connection
当我运行这个命令cat index.html | nc -lnvp 2222
然后用这个header在浏览器中打开服务器的本地地址时:
GET / HTTP/1.1
Host: 192.168.146.131:2222
User-Agent: "my user agent here"
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
DNT: 1
Connection: keep-alive
这就是 index.html:hi whats up
(就是这样)
我在 netcat 正在 运行ning 的终端中收到 http 请求,我的另一台机器上的浏览器正在等待。只有当我 CTRL-C 在终端上连接时,我才会在浏览器中得到响应。
我的uname -a
打印出来:Linux kali 4.0.0-kali1-amd64 #1 SMP Debian 4.0.4-1+kali2 (2015-06-03) x86_64 GNU/Linux
当我尝试使用 cat index.html | nc -l 2222
时,它根本不起作用。我的 Kali 机器甚至没有收到 http 请求。当我在 Ubuntu 机器上尝试相同的操作时,它的工作方式就像我希望的那样:它只是将 index.html 发送到浏览器,而不等我到 CTRL-C netcat。
有人知道为什么 netcat 的行为如此奇怪吗?
有两种不同的 netcat
,您正在使用其中一种:
传统netcat
会默认避免关闭连接,因为客户端可能会发送更多数据。
OpenBSD netcat
在没有更多数据要发送时默认关闭连接。
旧版本的 HTTP(就像您正在回退一样)需要关闭连接,因此默认情况下它可以与 OpenBSD netcat 一起使用。
您也可以让传统的 netcat
关闭 eof 上的连接,使用 -q 0
:
stuff | nc.traditional -l -p 2222 -q 0
man nc
写道:
"netcat stays running until the network side closes" 所以您的浏览器将永远等待数据完成。使用 -q
选项退出,再次查看手册页:"after EOF on stdin, wait the specified number of seconds and then quit".
cat index.html | nc -lnvp 2222 -q 0
nc -l 2222
没有意义,需要用-p
指定端口
当我运行这个命令cat index.html | nc -lnvp 2222
然后用这个header在浏览器中打开服务器的本地地址时:
GET / HTTP/1.1
Host: 192.168.146.131:2222
User-Agent: "my user agent here"
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate
DNT: 1
Connection: keep-alive
这就是 index.html:hi whats up
(就是这样)
我在 netcat 正在 运行ning 的终端中收到 http 请求,我的另一台机器上的浏览器正在等待。只有当我 CTRL-C 在终端上连接时,我才会在浏览器中得到响应。
我的uname -a
打印出来:Linux kali 4.0.0-kali1-amd64 #1 SMP Debian 4.0.4-1+kali2 (2015-06-03) x86_64 GNU/Linux
当我尝试使用 cat index.html | nc -l 2222
时,它根本不起作用。我的 Kali 机器甚至没有收到 http 请求。当我在 Ubuntu 机器上尝试相同的操作时,它的工作方式就像我希望的那样:它只是将 index.html 发送到浏览器,而不等我到 CTRL-C netcat。
有人知道为什么 netcat 的行为如此奇怪吗?
有两种不同的 netcat
,您正在使用其中一种:
传统
netcat
会默认避免关闭连接,因为客户端可能会发送更多数据。OpenBSD
netcat
在没有更多数据要发送时默认关闭连接。
旧版本的 HTTP(就像您正在回退一样)需要关闭连接,因此默认情况下它可以与 OpenBSD netcat 一起使用。
您也可以让传统的 netcat
关闭 eof 上的连接,使用 -q 0
:
stuff | nc.traditional -l -p 2222 -q 0
man nc
写道:
"netcat stays running until the network side closes" 所以您的浏览器将永远等待数据完成。使用 -q
选项退出,再次查看手册页:"after EOF on stdin, wait the specified number of seconds and then quit".
cat index.html | nc -lnvp 2222 -q 0
nc -l 2222
没有意义,需要用-p
指定端口