Linux nmap 命令实战示例

LinuxBeginner
立即练习

简介

在本实验中,我们将探索 Linux 的 nmap 命令,这是一个强大的网络发现和安全审计工具。我们将从了解 nmap 的基础知识开始,包括如何安装它以及执行简单的网络扫描。然后,我们将深入探讨 nmap 的高级功能,例如版本检测和操作系统指纹识别。

本实验涵盖以下步骤:

  1. 理解 nmap 的基础知识
  2. 使用 nmap 进行网络扫描
  3. 利用 nmap 的高级功能

在本实验中,我们将在 Ubuntu 22.04 的 Docker 容器中使用 nmap 命令。如果你需要安装 nmap,实验提供了必要的命令。总的来说,本实验旨在让你掌握使用 nmap 进行网络探索和安全评估的知识和技能。

Linux 命令速查表

理解 nmap 的基础知识

在这一步中,我们将学习 nmap(Network Mapper)命令的基础知识,这是一个用于网络发现和安全审计的强大工具。nmap 是一个免费且开源的实用程序,可用于扫描网络和主机、识别运行的服务以及检测潜在的漏洞。

首先,让我们在 Ubuntu 22.04 的 Docker 容器中安装 nmap

sudo apt-get update
sudo apt-get install -y nmap

示例输出:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  liblinear6 libpcap0.8 libpcre2-8-0 libsqlite3-0 libssl-dev libssl1.1 zlib1g
Suggested packages:
  nmap-frontend
The following NEW packages will be installed:
  liblinear6 libpcap0.8 libpcre2-8-0 libsqlite3-0 libssl-dev libssl1.1 nmap zlib1g
0 upgraded, 8 newly installed, 0 to remove and 0 not upgraded.

现在我们已经安装了 nmap,让我们探索一些基本用法:

  1. 对目标主机执行简单的 TCP 连接扫描:
nmap 192.168.1.100

示例输出:

Starting Nmap scan on 192.168.1.100
Nmap scan report for 192.168.1.100
PORT     STATE SERVICE
22/tcp   open  ssh
80/tcp   open  http
443/tcp  open  https
  1. 执行更详细的扫描,包括版本检测和操作系统指纹识别:
nmap -sV -O 192.168.1.100

示例输出:

Starting Nmap scan on 192.168.1.100
Nmap scan report for 192.168.1.100
PORT     STATE SERVICE VERSION
22/tcp   open  ssh     OpenSSH 8.2p1 Ubuntu 4.1 (protocol 2.0)
80/tcp   open  http    Apache httpd 2.4.41 ((Ubuntu))
443/tcp  open  ssl/http Apache httpd 2.4.41 ((Ubuntu))
OS CPE: cpe:/o:linux:linux_kernel
OS details: Linux 5.4.0 - 5.15.0

在这一步中,我们学习了 nmap 命令的基本用法,包括执行简单的 TCP 连接扫描以及带有版本检测和操作系统指纹识别的更详细扫描。在下一步中,我们将探索更多 nmap 的高级功能和技巧。

使用 nmap 进行网络扫描

在这一步中,我们将深入探讨如何使用 nmap 进行网络扫描,并探索其一些高级功能。

首先,让我们尝试 SYN 扫描,这是一种隐蔽的网络扫描方式:

sudo nmap -sS 192.168.1.1-254

示例输出:

Starting Nmap scan on 192.168.1.0/24
Nmap scan report for 192.168.1.1
PORT     STATE SERVICE
22/tcp   open  ssh
80/tcp   open  http
443/tcp  open  https

Nmap scan report for 192.168.1.100
PORT     STATE SERVICE
22/tcp   open  ssh
80/tcp   open  http
443/tcp  open  https

接下来,我们执行 UDP 扫描以识别开放的 UDP 端口:

sudo nmap -sU 192.168.1.100

示例输出:

Starting Nmap UDP scan on 192.168.1.100
Nmap scan report for 192.168.1.100
PORT    STATE SERVICE
123/udp open  ntp

我们还可以使用 nmap 扫描特定的端口范围:

sudo nmap -p 1-1000 192.168.1.100

示例输出:

Starting Nmap scan on 192.168.1.100
Nmap scan report for 192.168.1.100
PORT     STATE SERVICE
22/tcp   open  ssh
80/tcp   open  http
443/tcp  open  https

最后,让我们尝试带有版本检测和操作系统指纹识别的 TCP SYN 扫描:

sudo nmap -sS -sV -O 192.168.1.100

示例输出:

Starting Nmap scan on 192.168.1.100
Nmap scan report for 192.168.1.100
PORT     STATE SERVICE VERSION
22/tcp   open  ssh     OpenSSH 8.2p1 Ubuntu 4.1 (protocol 2.0)
80/tcp   open  http    Apache httpd 2.4.41 ((Ubuntu))
443/tcp  open  ssl/http Apache httpd 2.4.41 ((Ubuntu))
OS CPE: cpe:/o:linux:linux_kernel
OS details: Linux 5.4.0 - 5.15.0

在这一步中,我们学习了如何使用 nmap 执行各种网络扫描,包括 SYN 扫描、UDP 扫描、端口范围扫描以及带有版本检测和操作系统指纹识别的扫描。这些技术对于网络发现、安全审计和故障排除非常有用。

利用 nmap 的高级功能

在这最后一步中,我们将探索 nmap 的一些高级功能,以及如何将它们用于更复杂的网络扫描和分析。

首先,让我们执行脚本扫描以检测目标主机上的潜在漏洞:

sudo nmap -sV --script=vuln 192.168.1.100

示例输出:

Starting Nmap scan on 192.168.1.100
Nmap scan report for 192.168.1.100
PORT     STATE SERVICE VERSION
22/tcp   open  ssh     OpenSSH 8.2p1 Ubuntu 4.1 (protocol 2.0)
| ssh-hostkey:
|   3072 c4:f8:9c:0c:cb:8a:d0:95:87:04:a9:44:b2:2e:ac:e5 (RSA)
|   256 ac:00:66:17:63:c0:80:9d:43:bd:ee:e9:a6:ca:e5:84 (ECDSA)
|_  256 f5:90:d8:9e:6b:b3:19:e5:7c:ab:02:5a:c1:4b:08:e4 (ED25519)
80/tcp   open  http    Apache httpd 2.4.41 ((Ubuntu))
| http-slowloris-check:
|   VULNERABLE:
|   Slowloris DOS attack
|     State: VULNERABLE
|     IDs:  CVE-2007-6750, CWE-476
|       Slowloris tries to keep many connections to the target web server open and hold
|       them for as long as possible.  This can effectively starve the web server of
|       resources, slowing it down or causing it to crash.
|
|     Disclosure date: 2009-09-03
|     References:
|       https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-6750
|_      http://ha.ckers.org/slowloris/
443/tcp  open  ssl/http Apache httpd 2.4.41 ((Ubuntu))
| http-slowloris-check:
|   VULNERABLE:
|   Slowloris DOS attack
|     State: VULNERABLE
|     IDs:  CVE-2007-6750, CWE-476
|       Slowloris tries to keep many connections to the target web server open and hold
|       them for as long as possible.  This can effectively starve the web server of
|       resources, slowing it down or causing it to crash.
|
|     Disclosure date: 2009-09-03
|     References:
|       https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-6750
|_      http://ha.ckers.org/slowloris/

我们还可以使用 nmap 执行 TCP 连接扫描并将结果保存到文件中:

sudo nmap -oA nmap_results 192.168.1.100

示例输出:

Starting Nmap scan on 192.168.1.100
Nmap scan report for 192.168.1.100
PORT     STATE SERVICE
22/tcp   open  ssh
80/tcp   open  http
443/tcp  open  https

结果保存在以下文件中:

  • nmap_results.nmap
  • nmap_results.gnmap
  • nmap_results.xml

最后,让我们尝试执行带有服务和版本检测、操作系统指纹识别以及脚本扫描的 TCP SYN 扫描:

sudo nmap -sS -sV -O -sC 192.168.1.100

示例输出:

Starting Nmap scan on 192.168.1.100
Nmap scan report for 192.168.1.100
PORT     STATE SERVICE VERSION
22/tcp   open  ssh     OpenSSH 8.2p1 Ubuntu 4.1 (protocol 2.0)
| ssh-hostkey:
|   3072 c4:f8:9c:0c:cb:8a:d0:95:87:04:a9:44:b2:2e:ac:e5 (RSA)
|   256 ac:00:66:17:63:c0:80:9d:43:bd:ee:e9:a6:ca:e5:84 (ECDSA)
|_  256 f5:90:d8:9e:6b:b3:19:e5:7c:ab:02:5a:c1:4b:08:e4 (ED25519)
80/tcp   open  http    Apache httpd 2.4.41 ((Ubuntu))
| http-server-header:
|   Apache/2.4.41 (Ubuntu)
|_  Server: Apache/2.4.41 (Ubuntu)
443/tcp  open  ssl/http Apache httpd 2.4.41 ((Ubuntu))
| http-server-header:
|   Apache/2.4.41 (Ubuntu)
|_  Server: Apache/2.4.41 (Ubuntu)
OS CPE: cpe:/o:linux:linux_kernel
OS details: Linux 5.4.0 - 5.15.0

在这最后一步中,我们探索了 nmap 的一些高级功能,包括用于漏洞检测的脚本扫描、将扫描结果保存到文件,以及执行包含服务和版本检测、操作系统指纹识别和脚本扫描的综合扫描。这些技术对于网络安全评估和故障排除非常宝贵。

总结

在本实验中,我们学习了 nmap(Network Mapper)命令的基础知识,这是一个用于网络发现和安全审计的强大工具。我们首先在 Ubuntu 22.04 的 Docker 容器中安装了 nmap,然后探索了其基本用法,包括执行简单的 TCP 连接扫描以及带有版本检测和操作系统指纹识别的更详细扫描。我们学习了如何使用 nmap 命令来识别目标主机上运行的服务并检测潜在的漏洞。在下一步中,我们将探索更多 nmap 的高级功能,以进一步增强我们的网络扫描和安全评估能力。

Linux 命令速查表