BCLinux8.*安装部署nmap

目录

RPM包二进制安装

源码编译安装

下载并解压源码包

安装编译环境

安装依赖

编译安装

验证安装是否成功

源码构建RPM包

只能改选全手动构建RPM包了

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包安装方式

(其实这里对python3的依赖不是nmap的而是ndiff的,nmap的rpm包连带ndiff功能一起打包了)

源码编译安装

下载并解压源码包

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

 但是,并不能重构成功(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) 退出状态不好

只能改选全手动构建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%] 

你可能感兴趣的:(nmap,操作系统,nmap,rpmbuild,bclinux)