![为什么 netcat-openbsd 缺少‘-e’选项?](https://linux22.com/image/1390486/%E4%B8%BA%E4%BB%80%E4%B9%88%20netcat-openbsd%20%E7%BC%BA%E5%B0%91%E2%80%98-e%E2%80%99%E9%80%89%E9%A1%B9%EF%BC%9F.png)
为什么软件包-e
中缺少该选项netcat-openbsd
?有一个netcat-traditional
软件包,但它缺少 OpenBSD 软件包中的许多功能。我正在运行 Linux Mint 16。
有人知道为什么这个不见了?它删除了 netcat 的一个相当大的功能。
答案1
因为该程序有各种版本。
与 POSIX 中指定的许多其他标准实用程序不同,没有“标准”来描述netcat
必须支持哪些选项。您可以使用netcat
OpenBSD、FreeBSD 和GNU 网络猫等等。
对于 OpenBSD 变体手册页指出:
There is no -c or -e option in this netcat, but you still can execute a
command after connection being established by redirecting file descriptors.
Be cautious here because opening a port and let anyone connected execute
arbitrary command on your site is DANGEROUS. If you really need to do this,
here is an example:
On ‘server’ side:
$ rm -f /tmp/f; mkfifo /tmp/f
$ cat /tmp/f | /bin/sh -i 2>&1 | nc -l 127.0.0.1 1234 > /tmp/f
On ‘client’ side:
$ nc host.example.com 1234
$ (shell prompt from host.example.com)
By doing this, you create a fifo at /tmp/f and make nc listen at port 1234
of address 127.0.0.1 on ‘server’ side, when a ‘client’ establishes a
connection successfully to that port, /bin/sh gets executed on ‘server’
side and the shell prompt is given to ‘client’ side.
When connection is terminated, nc quits as well. Use -k if you want it keep
listening, but if the command quits this option won't restart it or keep nc
running. Also don't forget to remove the file descriptor once you don't
need it anymore:
$ rm -f /tmp/f
答案2
在最新版本中,我发现一些来源中对 netcat 的定义也启用了执行命令。通常出于安全原因,它是被禁用的。
但我找到了另一种解决方法