ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

linux – 如何知道我使用的是哪种netcat?

2019-08-14 07:53:13  阅读:18  来源: 互联网

标签:netcat linux



netcat有两种风格:netcat-openbsd和netcat-traditional.

如何知道我使用的netcat的味道是什么?我试过男人nc,但它没有说它是什么味道.

解决方法:

首先,您可以在机器中安装多种口味.所以答案取决于你安装了多少种口味以及你输入的命令.

netcat-traditional和netcat-openbsd可以通过Ubuntu中的包管理器apt安装.在我的情况下,我也从源代码构建,通过this official website安装GNU netcat flavor.

对于“openbsd”风格,您可以使用dpkg -L< package-name>找出位置二进制名称. (如果你的包管理器不合适,谷歌搜索自己找到相当于dpkg L):

$dpkg -L netcat-openbsd | grep /bin
/bin
/bin/nc.openbsd

然后使用type -a确认二进制名称nc.openbsd可以在$PATH中搜索并解释为命令:

$type -a nc.openbsd
nc.openbsd is /bin/nc.openbsd
nc.openbsd is /bin/nc.openbsd

对于“传统”的味道是相同的:

$dpkg -L netcat-traditional | grep /bin
/bin
/bin/nc.traditional
$type -a nc.traditional
nc.traditional is /bin/nc.traditional
nc.traditional is /bin/nc.traditional

这意味着我可以发出命令nc.openbsd来运行netcat-openbsd工具,并命令nc.traditional运行netcat-traditional工具. (可能会混淆命令包含’.’但包名称包含’ – ‘)

好像有通过apt安装3种口味:

$apt-cache search netcat --names-only
netcat-openbsd - TCP/IP swiss army knife
netcat - TCP/IP swiss army knife -- transitional package
netcat-traditional - TCP/IP swiss army knife

但实际上netcat只是虚拟包:

$apt-cache show netcat | grep Description-en  -A 2
Description-en: TCP/IP swiss army knife -- transitional package
 This is a "dummy" package that depends on lenny's default version of
 netcat, to ease upgrades. It may be safely removed.

因此,如果您需要,您只能通过apt安装netcat-openbsd和netcat-traditional:

sudo apt-get install netcat-openbsd
sudo apt-get install netcat-traditional

如何命令nc和netcat?它们可以绑定到$PATH可搜索的多种口味,如果你键入nc或netcat,其中一个路径就会运行.同样,您可以使用类型-a来检查,而优先级是第一行(如下面的粗体):

$type -a nc 
nc is /usr/local/bin/nc
nc is /bin/nc
nc is /usr/local/bin/nc
nc is /bin/nc
$type -a netcat
netcat is /usr/local/bin/netcat
netcat is /bin/netcat
netcat is /usr/local/bin/netcat
netcat is /bin/netcat

您可以使用realpath找出它们的已解析路径:

$realpath /usr/local/bin/netcat 
/usr/local/bin/netcat
$realpath /bin/netcat 
/bin/nc.openbsd
$realpath /usr/local/bin/nc
/usr/local/bin/netcat
$realpath /bin/nc
/bin/nc.openbsd

其中4个路径在我的系统中只有2个路径是唯一的,一个是“GNU”,另一个是“openbsd”:

$/usr/local/bin/netcat --version | head -1
netcat (The GNU Netcat) 0.7.1
$/bin/nc.openbsd -h |& head -1
OpenBSD netcat (Debian patchlevel 1.130-3)

这意味着如果我键入nc OR netcat,它将执行/usr/local/bin / netcat,这是“GNU Netcat”.

您可以尝试使用update-alternatives来调整已解析的符号链接路径:

$realpath /bin/nc
/bin/nc.openbsd
$realpath /bin/netcat
/bin/nc.openbsd
$sudo update-alternatives --config nc
There are 2 choices for the alternative nc (providing /bin/nc).

  Selection    Path                 Priority   Status
------------------------------------------------------------
  0            /bin/nc.openbsd       50        auto mode
* 1            /bin/nc.openbsd       50        manual mode
  2            /bin/nc.traditional   10        manual mode

Press <enter> to keep the current choice[*], or type selection number: 2
update-alternatives: using /bin/nc.traditional to provide /bin/nc (nc) in manual mode
$realpath /bin/nc
/bin/nc.traditional
$realpath /bin/netcat
/bin/nc.traditional

它将/ bin / nc和/ bin / netcat已解决的symlink¹更改为/bin/nc.traditional,但是如果我键入nc或netcat,它仍然没有改变味道,因为/usr/local/bin /仍然具有更高的优先级我的$PATH中的/ bin:

$/bin/nc -h |& head -1
[v1.10-41]
$nc -h |& head -1
GNU netcat 0.7.1, a rewrite of the famous networking tool.
$type -a nc | head -1
nc is /usr/local/bin/nc

请注意,有更多的netcat风格,例如ncat,socat,sbd,netcat6,pnetcatcryptcat.

¹更新的实际符号链接是/ etc / alternatives / nc和/ etc / alternatives / netcat,/ bin / nc和/ bin / netcat分别是/ etc / alternatives / nc和/ etc / alternatives / netcat的符号链接.



标签:netcat,linux

专注分享技术,共同学习,共同进步。

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有