BCLinux8.*安装部署nmap 7.94

RPM包二进制安装

rpm -ivh nmap-7.94-1.x86_64.rpm 
错误:依赖检测失败:
        python >= 3.0 被 nmap-2:7.94-1.x86_64 需要

yum -y install nmap-7.94-1.x86_64.rpm
错误:
 问题: conflicting requests
  - nothing provides python >= 3.0 needed by nmap-2:7.94-1.x86_64
(尝试添加 '--skip-broken' 来跳过无法安装的软件包 或 '--nobest' 来不只使用最佳选择的软件包) 

如上所示,通过RPM直接安装报错,通过检查python版本是符合要求的:

python -V
Python 3.6.8
yum list |grep '^python3.*devel'
python36-devel.x86_64                                             3.6.8-2.module+el8.2.0+10008+eff94df6               @AppStream         
python38-devel.x86_64                                             3.8.0-6.module+el8.2.0+10148+8d62840d               AppStream   

至此,RPM包安装方式

这个属于nmap打包rpm配置文件(nmap-7.94-1.spec)的一个BUG:因为在使用rpm包格式的linux发型版(例如:redhat等)python version 3.*版本的命名为:python3,而不是python

源码编译安装

下载并解压源码包

wget https://nmap.org/dist/nmap-7.94.tar.bz2
tar jxvf nmap-7.94.tar.bz2 

安装编译环境

yum -y groupinstall "Development Tools"
或
yum -y install gcc gcc-c++ make

安装依赖

# 需要安装的依赖包中有几个是需要通过epel源下载的
dnf install https://dl.Fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm -y
yum clean all
yum makecache
# 
yum -y install openssl-devel python3-devel libssh2-devel flex bison byacc libpcap epel-rpm-macros libtool

编译安装

./configure --prefix=/usr/local/
……
Configured with: ndiff zenmap nping openssl zlib libssh2 lua ncat
Configured without: localdirs
Type make (or gmake on some *BSD machines) to compile.

make
make install
……
NMAP SUCCESSFULLY INSTALLED

验证安装是否成功

nmap -V
Nmap version 7.94 ( https://nmap.org )
Platform: x86_64-unknown-linux-gnu
Compiled with: nmap-liblua-5.4.4 openssl-1.1.1k libssh2-1.9.0 libz-1.2.11 nmap-libpcre-7.6 nmap-libpcap-1.10.4 nmap-libdnet-1.12 ipv6
Compiled without:
Available nsock engines: epoll poll select

源码构建RPM包

在nmap官网,有通过如下命令从源码包重新编译

rpmbuild --rebuild https://nmap.org/dist/nmap-7.94-1.src.rpm

 但是,这么构建的RPM 跟官网下载的RPM一样,报同样的错误(rpmbuild/SPECS/nmap-7.94-1.spec 文档每次执行rpmbuild都会重新生成,就算改了也没用):

checking for gcc... gcc
checking whether the C compiler works... no

configure: error: in `/root/rpmbuild/BUILD/nmap-7.94':
configure: error: C compiler cannot create executables
See `config.log' for more details
错误:/var/tmp/rpm-tmp.WpzXgu (%build) 退出状态不好


RPM 构建错误:
    展开行 38 注释中的宏:%{_prefix}

    /var/tmp/rpm-tmp.WpzXgu (%build) 退出状态不好

通过rpmrebuild命令,修改spec文件,重新build

~$ sudo dnf install rpmrebuild 
~$ rpmrebuild -enp nmap-7.94-1.x86_64.rpm

-e,是--edit-specfile的缩写,启动编辑包的specfile;

-n,是--notest-install的缩写,禁止在构建过程结束时自动安装RPM包。

-p,是--package的缩写,指定“.rpm”包文件作为重建的基础,而不是使用已安装的rpm。

执行上面的命令后,默认文本编辑器将会打开spec文件。 我们只需要将Requires: python >= 3.0 修改为:Requires: python3 >= 3.0 。保存并退出,则会重新构建RPM包:

~$ ls $HOME/rpmbuild/RPMS/x86_64/
nmap-7.94-1.x86_64.rpm

再次安装就成功了:

也可以全手动构建RPM包了

1、鸠占鹊巢,使用rpmbuild --rebuild 遗留的rpmbuild目录即可

2、修改rpmbuild/SPECS/nmap-7.94-1.spec

下面的注释掉,我们不需要ndiff
# For Ndiff. 
#BuildRequires: python3-devel, epel-rpm-macros
#Requires: python >= 3.0

放开prefix的注释
Prefix: %{_prefix}

%configure --with-openssl=%{openssl} --without-zenmap --with-ndiff --with-libdnet=included --with-libpcap=included --with-libpcre=included --with-liblua=included --with-libz=included
改为:
./configure --prefix=%{_prefix} --with-openssl=%{openssl} --without-zenmap --without-ncat --without-nping --without-ndiff --with-libdnet=included --with-libpcap=included --with-libpcre=included --with-liblua=included --with-libz=included

%doc %{_prefix}/share/man/man1/nmap.1.gz
%doc %{_prefix}/share/man/*/man1/nmap.1.gz
改为:
%doc %{_prefix}/share/man/man1/nmap.1*
%doc %{_prefix}/share/man/*/man1/nmap.1*

删除ndiff、ncat、nping相关的配置,一直到%changelog行。

3、执行如下命令构建(--nodebuginfo 如果不带可能会报错)

rpmbuild --nodebuginfo -ba SPECS/nmap-7.94-1.spec

不带报错信息:

Requires(rpmlib): rpmlib(CompressedFileNames) <= 3.0.4-1 rpmlib(FileDigests) <= 4.6.0-1 rpmlib(PayloadFilesHavePrefix) <= 4.0-1
处理文件:nmap-debugsource-7.94-1.x86_64
错误:空 %file 文件 /root/rpmbuild/BUILD/nmap-7.94/debugsourcefiles.list

4、编译成功后可以看到

ll rpmbuild_bak/RPMS/x86_64/
总用量 6020
-rw-r--r--. 1 root root 6163680 6月   8 15:38 nmap-7.94-1.x86_64.rpm

5、传到其他服务器上安装

rpm -Uvh nmap-7.94-1.x86_64.rpm 
Verifying...                          ################################# [100%]
准备中...                          ################################# [100%]
正在升级/安装...
   1:nmap-2:7.94-1                    ################################# [ 50%]
正在清理/删除...
   2:nmap-2:7.70-5.el8                ################################# [100%] 

  • 5
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值