Nmap 스캔 플래그 사용 방법

NmapBeginner
지금 연습하기

소개

Nmap (Network Mapper) 은 네트워크 보안 및 관리에 필수적인 도구입니다. 이 랩에서는 효과적인 네트워크 정찰 및 취약점 평가를 수행할 수 있도록 해주는 Nmap 스캔 플래그를 소개합니다. 실습을 통해 다양한 Nmap 명령을 사용하여 네트워크에서 호스트를 검색하고, 포트를 스캔하며, 서비스를 식별하는 방법을 배우게 됩니다. 이러한 기술은 네트워크 관리자와 보안 전문가가 안전한 네트워크 환경을 유지하는 데 필수적입니다.

이것은 가이드 실험입니다. 학습과 실습을 돕기 위한 단계별 지침을 제공합니다.각 단계를 완료하고 실무 경험을 쌓기 위해 지침을 주의 깊게 따르세요. 과거 데이터에 따르면, 이것은 초급 레벨의 실험이며 완료율은 84%입니다.학습자들로부터 100%의 긍정적인 리뷰율을 받았습니다.

Nmap 설치 및 기본 스캔

Nmap 설치

대부분의 시스템에는 Nmap 이 사전 설치되어 있지 않으므로, 첫 번째 단계는 설치하는 것입니다. LabEx 환경에서 터미널을 열고 다음 명령을 실행합니다.

sudo apt update
sudo apt install nmap -y

설치가 완료된 후, Nmap 버전을 확인하여 제대로 설치되었는지 확인합니다.

nmap --version

다음과 유사한 출력을 볼 수 있습니다.

Nmap version 7.80 ( https://nmap.org )
Platform: x86_64-pc-linux-gnu
Compiled with: liblua-5.3.3 openssl-1.1.1f libssh2-1.8.0 libz-1.2.11 libpcre-8.39 libpcap-1.9.1 nmap-libdnet-1.12 ipv6
Compiled without:
Available nsock engines: epoll poll select

Nmap 기본 사항 이해

Nmap 은 특별히 제작된 패킷을 대상 호스트로 전송하고 응답을 분석하여 작동합니다. 이를 통해 다음을 확인할 수 있습니다.

  • 네트워크에서 사용 가능한 호스트
  • 제공하는 서비스 (포트)
  • 실행 중인 운영 체제
  • 사용 중인 패킷 필터/방화벽 유형

Nmap 명령의 기본 구문은 다음과 같습니다.

nmap [scan type] [options] target

여기서:

  • [scan type]은 수행할 스캔 유형을 지정합니다.
  • [options]는 스캔을 사용자 정의하기 위한 추가 매개변수입니다.
  • target은 스캔할 IP 주소, 호스트 이름 또는 IP 범위입니다.

첫 번째 스캔: Localhost 스캔

자신의 머신 (localhost) 을 간단하게 스캔하는 것으로 시작해 보겠습니다. 다음을 실행합니다.

nmap localhost

이 명령은 로컬 머신에서 가장 일반적인 1000 개의 TCP 포트를 스캔합니다. 출력은 다음과 유사합니다.

Starting Nmap 7.80 ( https://nmap.org ) at 2023-09-14 15:30 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00010s latency).
Not shown: 996 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
80/tcp   open  http
631/tcp  open  ipp
3306/tcp open  mysql

Nmap done: 1 IP address (1 host up) scanned in 0.11 seconds

출력은 다음을 보여줍니다.

  • 스캔 시작 시간
  • 스캔 중인 호스트 (localhost/127.0.0.1)
  • 열린 포트 및 관련 서비스
  • 스캔 완료 시간 및 통계

스캔 결과 이해

출력을 분석해 보겠습니다.

  • PORT: 포트 번호와 프로토콜을 표시합니다 (예: 22/tcp).
  • STATE: 포트가 열려 있는지, 닫혀 있는지 또는 필터링되었는지 나타냅니다.
  • SERVICE: 해당 포트와 일반적으로 관련된 서비스를 표시합니다.

가장 일반적인 포트 상태는 다음과 같습니다.

  • open: 포트가 연결을 허용합니다.
  • closed: 포트는 접근 가능하지만, 애플리케이션이 수신 대기 중이지 않습니다.
  • filtered: Nmap 은 패킷 필터링이 프로브를 차단하여 포트가 열려 있는지 확인할 수 없습니다.

특정 포트 스캔

특정 포트를 스캔하려면 -p 플래그 뒤에 포트 번호를 사용합니다.

nmap -p 22 localhost

출력은 포트 22 에만 집중됩니다.

Starting Nmap 7.80 ( https://nmap.org ) at 2023-09-14 15:35 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00013s latency).

PORT   STATE SERVICE
22/tcp open  ssh

Nmap done: 1 IP address (1 host up) scanned in 0.01 seconds

포트 범위 스캔

하이픈을 사용하여 포트 범위를 스캔할 수 있습니다.

nmap -p 20-25 localhost

이것은 포트 20 에서 25 까지 스캔합니다.

Starting Nmap 7.80 ( https://nmap.org ) at 2023-09-14 15:40 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00012s latency).

PORT   STATE  SERVICE
20/tcp closed ftp-data
21/tcp closed ftp
22/tcp open   ssh
23/tcp closed telnet
24/tcp closed priv-mail
25/tcp closed smtp

Nmap done: 1 IP address (1 host up) scanned in 0.03 seconds

이제 Nmap 을 설치하고 기본 포트 스캔을 수행하는 방법을 배웠습니다. 다음 단계에서는 다양한 Nmap 플래그를 사용하여 더 고급 스캔 기술을 탐색할 것입니다.

필수 Nmap 스캔 플래그 탐색

이제 Nmap 의 기본 사항을 이해했으므로, 스캔에서 더 많은 제어와 정보를 얻을 수 있는 몇 가지 필수 스캔 플래그를 살펴보겠습니다.

TCP SYN 스캔 (-sS)

TCP SYN 스캔은 root 권한으로 실행될 때 기본 스캔 유형입니다. TCP 연결을 완료하지 않기 때문에 "반개방형 (half-open)" 스캔이라고도 합니다. 상대적으로 은밀하고 빠릅니다.

localhost 에서 SYN 스캔을 실행해 보겠습니다.

sudo nmap -sS localhost

출력은 다음과 유사합니다.

Starting Nmap 7.80 ( https://nmap.org ) at 2023-09-14 16:00 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00011s latency).
Not shown: 996 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
80/tcp   open  http
631/tcp  open  ipp
3306/tcp open  mysql

Nmap done: 1 IP address (1 host up) scanned in 0.10 seconds

TCP Connect 스캔 (-sT)

TCP Connect 스캔은 Nmap 이 root 권한으로 실행되지 않을 때 기본 스캔입니다. 전체 TCP 핸드셰이크를 완료하므로 더 탐지 가능하지만, 경우에 따라 더 신뢰할 수 있습니다.

nmap -sT localhost

출력:

Starting Nmap 7.80 ( https://nmap.org ) at 2023-09-14 16:05 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00014s latency).
Not shown: 996 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
80/tcp   open  http
631/tcp  open  ipp
3306/tcp open  mysql

Nmap done: 1 IP address (1 host up) scanned in 0.15 seconds

서비스 버전 감지 (-sV)

버전 감지 플래그는 Nmap 에게 열린 포트에서 실행 중인 서비스의 버전을 확인하도록 지시합니다.

nmap -sV localhost

출력:

Starting Nmap 7.80 ( https://nmap.org ) at 2023-09-14 16:10 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00012s latency).
Not shown: 996 closed ports
PORT     STATE SERVICE  VERSION
22/tcp   open  ssh      OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0)
80/tcp   open  http     Apache httpd 2.4.41 ((Ubuntu))
631/tcp  open  ipp      CUPS 2.3
3306/tcp open  mysql    MySQL 8.0.30-0ubuntu0.20.04.2
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Nmap done: 1 IP address (1 host up) scanned in 6.41 seconds

이제 출력에 각 서비스에 대한 자세한 버전 정보가 포함되어 있음을 알 수 있습니다. 특정 버전에 알려진 취약점이 있을 수 있으므로, 이는 보안 평가에 매우 중요합니다.

OS 감지 (-O)

OS 감지 플래그는 대상의 운영 체제를 확인하려고 시도합니다.

sudo nmap -O localhost

출력:

Starting Nmap 7.80 ( https://nmap.org ) at 2023-09-14 16:15 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00011s latency).
Not shown: 996 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
80/tcp   open  http
631/tcp  open  ipp
3306/tcp open  mysql
Device type: general purpose
Running: Linux 4.X|5.X
OS CPE: cpe:/o:linux:linux_kernel:4 cpe:/o:linux:linux_kernel:5
OS details: Linux 4.15 - 5.6
Network Distance: 0 hops

OS detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 1.57 seconds

Nmap 이 시스템이 Linux 커널 버전 4.X 또는 5.X 를 실행 중임을 감지했음을 알 수 있습니다.

포괄적인 스캔을 위한 플래그 결합

더 포괄적인 결과를 얻기 위해 여러 플래그를 결합할 수 있습니다. 예를 들어, 서비스 버전 감지와 OS 감지를 결합해 보겠습니다.

sudo nmap -sV -O localhost

출력:

Starting Nmap 7.80 ( https://nmap.org ) at 2023-09-14 16:20 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00015s latency).
Not shown: 996 closed ports
PORT     STATE SERVICE  VERSION
22/tcp   open  ssh      OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0)
80/tcp   open  http     Apache httpd 2.4.41 ((Ubuntu))
631/tcp  open  ipp      CUPS 2.3
3306/tcp open  mysql    MySQL 8.0.30-0ubuntu0.20.04.2
Device type: general purpose
Running: Linux 4.X|5.X
OS CPE: cpe:/o:linux:linux_kernel:4 cpe:/o:linux:linux_kernel:5
OS details: Linux 4.15 - 5.6
Network Distance: 0 hops
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 7.23 seconds

공격적인 스캔 (-A)

공격적인 스캔 플래그는 OS 감지, 버전 감지, 스크립트 스캔 및 추적 경로를 포함한 여러 스캔 옵션을 결합합니다.

sudo nmap -A localhost

출력 (간결성을 위해 잘림):

Starting Nmap 7.80 ( https://nmap.org ) at 2023-09-14 16:25 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00014s latency).
Not shown: 996 closed ports
PORT     STATE SERVICE  VERSION
22/tcp   open  ssh      OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
|   3072 e2:5d:9c:5c:62:42:44:cd:fc:31:e0:a6:18:11:69:1c (RSA)
|   256 7d:95:f0:2f:7a:95:3a:4d:f3:52:ef:6f:6b:af:01:71 (ECDSA)
|_  256 90:12:20:de:cb:c0:76:3a:fb:15:db:75:4e:78:fc:d7 (ED25519)
80/tcp   open  http     Apache httpd 2.4.41 ((Ubuntu))
|_http-server-header: Apache/2.4.41 (Ubuntu)
|_http-title: Apache2 Ubuntu Default Page: It works
631/tcp  open  ipp      CUPS 2.3
|_http-server-header: CUPS/2.3 IPP/2.1
|_http-title: Home - CUPS 2.3.1
3306/tcp open  mysql    MySQL 8.0.30-0ubuntu0.20.04.2
| mysql-info:
|   Protocol: 10
|   Version: 8.0.30-0ubuntu0.20.04.2
|   Thread ID: 11
|   Capabilities flags: 65535
|   Some Capabilities: SupportsLoadDataLocal, Support41Auth, Speaks41ProtocolOld, IgnoreSigpipes, DontAllowDatabaseTableColumn, FoundRows, SupportsCompression, ConnectWithDatabase, LongPassword, InteractiveClient, SwitchToSSLAfterHandshake, ODBCClient, Speaks41ProtocolNew, IgnoreSpaceBeforeParenthesis, LongColumnFlag, SupportsTransactions, SupportsMultipleResults, SupportsAuthPlugins, SupportsMultipleStatments
|   Status: Autocommit
|   Salt: \x14\x12\x1Fjw\x182\x15\x0D\x12\x13C\x1F\x14\x0D\x07
|_  Auth Plugin Name: caching_sha2_password
Device type: general purpose
Running: Linux 4.X|5.X
OS CPE: cpe:/o:linux:linux_kernel:4 cpe:/o:linux:linux_kernel:5
OS details: Linux 4.15 - 5.6
Network Distance: 0 hops

OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 10.12 seconds

공격적인 스캔에서 SSH 키 정보, HTTP 서버 세부 정보 및 더 자세한 MySQL 서비스 정보를 포함하여 상당한 양의 추가 정보가 제공됨을 알 수 있습니다.

이 단계에서는 몇 가지 필수 Nmap 스캔 플래그와 더 포괄적인 결과를 얻기 위해 이를 결합하는 방법을 배웠습니다. 다음 단계에서는 다양한 시나리오에 대한 실용적인 스캔 전략을 탐색할 것입니다.

네트워크 스캔 전략 및 타이밍 제어

이 단계에서는 네트워크 스캔 전략과 Nmap 스캔의 타이밍 및 성능을 제어하는 방법에 대해 배우겠습니다. 이는 더 큰 네트워크를 스캔하거나 더 신중하게 스캔해야 할 때 중요합니다.

여러 호스트 스캔

Nmap 은 다양한 방식으로 여러 호스트를 스캔할 수 있습니다.

IP 목록 스캔

공백으로 구분된 여러 IP 주소를 지정할 수 있습니다.

nmap 127.0.0.1 127.0.0.2

IP 범위 스캔

CIDR 표기법을 사용하여 IP 주소 범위를 스캔할 수 있습니다.

nmap 127.0.0.1/30

이 명령은 127.0.0.0 부터 127.0.0.3 까지 스캔합니다. 출력은 다음과 같습니다.

Starting Nmap 7.80 ( https://nmap.org ) at 2023-09-14 16:35 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00013s latency).
Not shown: 996 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
80/tcp   open  http
631/tcp  open  ipp
3306/tcp open  mysql

Nmap scan report for 127.0.0.2
Host is up (0.00015s latency).
All 1000 scanned ports on 127.0.0.2 are closed

Nmap scan report for 127.0.0.3
Host is up (0.00013s latency).
All 1000 scanned ports on 127.0.0.3 are closed

Nmap done: 4 IP addresses (3 hosts up) scanned in 0.92 seconds

호스트 검색 옵션

Ping 스캔 (-sn)

때로는 포트를 스캔하지 않고 온라인 상태인 호스트만 알고 싶을 수 있습니다. Ping 스캔은 이에 완벽합니다.

nmap -sn 127.0.0.1/24

이 명령은 전체 127.0.0.1/24 서브넷을 스캔하지만, 포트 스캔 없이 호스트 검색만 수행합니다. 출력 길이가 길기 때문에, 일부만 표시하겠습니다.

Starting Nmap 7.80 ( https://nmap.org ) at 2023-09-14 16:40 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00011s latency).
Nmap scan report for 127.0.0.2
Host is up (0.00013s latency).
Nmap scan report for 127.0.0.3
Host is up (0.00014s latency).
...
Nmap done: 256 IP addresses (256 hosts up) scanned in 2.34 seconds

호스트 검색 건너뛰기 (-Pn)

때로는 방화벽이 ping 요청을 차단합니다. 이를 우회하고 ping 응답에 관계없이 모든 호스트를 스캔하려면 -Pn 플래그를 사용합니다.

nmap -Pn localhost

출력:

Starting Nmap 7.80 ( https://nmap.org ) at 2023-09-14 16:45 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00012s latency).
Not shown: 996 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
80/tcp   open  http
631/tcp  open  ipp
3306/tcp open  mysql

Nmap done: 1 IP address (1 host up) scanned in 0.12 seconds

타이밍 및 성능 제어

Nmap 은 다양한 스캔 매개변수를 조정하는 여러 타이밍 템플릿을 제공합니다.

  • -T0: Paranoid (매우 느림, IDS 회피에 사용)
  • -T1: Sneaky (느림, IDS 회피에 사용)
  • -T2: Polite (대역폭을 적게 사용하기 위해 속도를 늦춤)
  • -T3: Normal (기본값, 속도와 신뢰성 균형)
  • -T4: Aggressive (더 빠름, 합리적으로 빠르고 신뢰할 수 있는 네트워크 가정)
  • -T5: Insane (매우 빠름, 극도로 빠른 네트워크 가정)

공격적인 스캔을 시도해 보겠습니다.

nmap -T4 localhost

출력:

Starting Nmap 7.80 ( https://nmap.org ) at 2023-09-14 16:50 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00011s latency).
Not shown: 996 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
80/tcp   open  http
631/tcp  open  ipp
3306/tcp open  mysql

Nmap done: 1 IP address (1 host up) scanned in 0.09 seconds

스캔이 기본 스캔보다 약간 더 빨리 완료되었음을 알 수 있습니다.

출력 형식

Nmap 은 나중에 분석 또는 보고를 위해 다양한 형식으로 스캔 결과를 저장할 수 있습니다.

일반 출력 (-oN)

일반 형식으로 스캔 결과를 파일에 저장합니다.

nmap -oN scan_results.txt localhost

이 명령은 스캔 출력을 현재 디렉토리의 scan_results.txt에 저장합니다.

XML 출력 (-oX)

스캔 결과를 XML 형식으로 저장합니다. 이는 다른 도구로 구문 분석하는 데 유용합니다.

nmap -oX scan_results.xml localhost

모든 형식 (-oA)

스캔 결과를 모든 형식 (일반, XML 및 grepable) 으로 저장합니다.

nmap -oA scan_results localhost

이렇게 하면 scan_results.nmap, scan_results.xmlscan_results.gnmap의 세 개의 파일이 생성됩니다.

일반 출력 파일의 내용을 살펴보겠습니다.

cat scan_results.txt

출력:

## Nmap 7.80 scan initiated Thu Sep 14 16:55:23 2023 as: nmap -oN scan_results.txt localhost
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00013s latency).
Not shown: 996 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
80/tcp   open  http
631/tcp  open  ipp
3306/tcp open  mysql

## Nmap done at Thu Sep 14 16:55:23 2023 -- 1 IP address (1 host up) scanned in 0.12 seconds

실용적인 스캔 전략

배운 내용을 결합하여 포괄적인 스캔을 위한 실용적인 스캔 전략을 만들어 보겠습니다.

sudo nmap -sS -sV -O -T4 -oA comprehensive_scan localhost

이 명령은 다음을 수행합니다.

  • SYN 스텔스 스캔 사용 (-sS)
  • 서비스 버전 감지 (-sV)
  • OS 감지 시도 (-O)
  • 공격적인 타이밍 사용 (-T4)
  • 모든 형식으로 결과 저장 (-oA)

출력:

Starting Nmap 7.80 ( https://nmap.org ) at 2023-09-14 17:00 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00012s latency).
Not shown: 996 closed ports
PORT     STATE SERVICE  VERSION
22/tcp   open  ssh      OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0)
80/tcp   open  http     Apache httpd 2.4.41 ((Ubuntu))
631/tcp  open  ipp      CUPS 2.3
3306/tcp open  mysql    MySQL 8.0.30-0ubuntu0.20.04.2
Device type: general purpose
Running: Linux 4.X|5.X
OS CPE: cpe:/o:linux:linux_kernel:4 cpe:/o:linux:linux_kernel:5
OS details: Linux 4.15 - 5.6
Network Distance: 0 hops
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 7.42 seconds

이제 모든 출력 파일에서 포괄적인 스캔 결과를 볼 수 있습니다.

ls comprehensive_scan.*

출력:

comprehensive_scan.gnmap  comprehensive_scan.nmap  comprehensive_scan.xml

윤리적 고려 사항

네트워크 스캔은 자신이 소유하거나 스캔할 명시적인 권한이 있는 네트워크에서만 수행해야 합니다. 무단 스캔은 다음과 같습니다.

  1. 많은 관할 구역에서 불법입니다.
  2. 네트워크 관리자가 적대 행위로 간주합니다.
  3. 네트워크 서비스에 잠재적으로 지장을 줄 수 있습니다.

이 Lab 환경에서는 항상 허용되는 localhost만 스캔했습니다. 이는 자신의 시스템이기 때문입니다.

이제 다양한 네트워크 스캔 전략, 타이밍 제어 및 출력 형식에 대해 배웠습니다. Nmap 을 사용하여 효과적인 네트워크 정찰을 수행하는 데 필요한 모든 기본적인 지식을 갖추었습니다.

스크립트 스캔 및 대상 서비스 분석

이 단계에서는 Nmap 의 강력한 스크립팅 엔진 (NSE) 을 살펴보고 대상 서비스 분석을 수행하는 방법을 배우겠습니다. NSE 스크립트는 특정 서비스 및 취약점에 대한 더 자세한 스캔을 가능하게 하여 Nmap 의 기능을 확장합니다.

Nmap Scripting Engine(NSE) 소개

Nmap Scripting Engine 을 사용하면 사용자가 다양한 네트워킹 작업을 자동화하기 위해 스크립트를 작성하고 공유할 수 있습니다. Nmap 에는 다양한 그룹으로 분류된 수백 개의 사전 작성된 스크립트가 함께 제공됩니다.

  • auth: 인증 관련 스크립트
  • default: -sC로 기본적으로 실행되는 스크립트
  • discovery: 호스트 및 서비스 검색
  • exploit: 취약점 악용 시도
  • malware: 맬웨어 및 백도어 감지
  • safe: 안전하고 비침입적인 스크립트
  • vuln: 취약점 감지 스크립트

기본 스크립트 실행 (-sC)

-sC 플래그는 일반적으로 안전하고 유용한 정보를 제공하는 기본 스크립트 세트를 실행합니다.

nmap -sC localhost

출력:

Starting Nmap 7.80 ( https://nmap.org ) at 2023-09-14 17:10 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00012s latency).
Not shown: 996 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
| ssh-hostkey:
|   3072 e2:5d:9c:5c:62:42:44:cd:fc:31:e0:a6:18:11:69:1c (RSA)
|   256 7d:95:f0:2f:7a:95:3a:4d:f3:52:ef:6f:6b:af:01:71 (ECDSA)
|_  256 90:12:20:de:cb:c0:76:3a:fb:15:db:75:4e:78:fc:d7 (ED25519)
80/tcp   open  http
|_http-title: Apache2 Ubuntu Default Page: It works
631/tcp  open  ipp
|_http-server-header: CUPS/2.3 IPP/2.1
|_http-title: Home - CUPS 2.3.1
3306/tcp open  mysql
|_mysql-info: ERROR: Script execution failed (use -d to debug)

Nmap done: 1 IP address (1 host up) scanned in 3.42 seconds

스크립트가 SSH 호스트 키 및 HTTP 페이지 제목과 같이 각 서비스에 대한 추가 정보를 제공했음을 알 수 있습니다.

특정 스크립트 실행

--script 플래그와 스크립트 이름 또는 범주를 사용하여 특정 스크립트를 실행할 수 있습니다.

nmap --script=http-title localhost

이것은 HTTP 페이지의 제목을 검색하는 http-title 스크립트만 실행합니다.

Starting Nmap 7.80 ( https://nmap.org ) at 2023-09-14 17:15 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00013s latency).
Not shown: 996 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
80/tcp   open  http
|_http-title: Apache2 Ubuntu Default Page: It works
631/tcp  open  ipp
|_http-title: Home - CUPS 2.3.1
3306/tcp open  mysql

Nmap done: 1 IP address (1 host up) scanned in 0.68 seconds

범주별 스크립트 실행

특정 범주의 모든 스크립트를 실행할 수 있습니다.

nmap --script=discovery localhost

이것은 모든 검색 스크립트를 실행하며, 네트워크 서비스에 대한 많은 정보를 제공할 수 있습니다 (출력은 간결성을 위해 잘림).

Starting Nmap 7.80 ( https://nmap.org ) at 2023-09-14 17:20 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00014s latency).
Not shown: 996 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
| ssh-hostkey:
|   3072 e2:5d:9c:5c:62:42:44:cd:fc:31:e0:a6:18:11:69:1c (RSA)
|   256 7d:95:f0:2f:7a:95:3a:4d:f3:52:ef:6f:6b:af:01:71 (ECDSA)
|_  256 90:12:20:de:cb:c0:76:3a:fb:15:db:75:4e:78:fc:d7 (ED25519)
80/tcp   open  http
|_http-favicon: Unknown favicon MD5: 6D33949773573A11BEBE0D20AC1B7967
| http-methods:
|_  Supported Methods: GET POST OPTIONS HEAD
|_http-title: Apache2 Ubuntu Default Page: It works
631/tcp  open  ipp
| cups-info:
|   CUPS Server:
|     Server: CUPS/2.3 IPP/2.1
|_    Authentication-Method: Basic
| http-methods:
|_  Supported Methods: GET HEAD OPTIONS POST
|_http-server-header: CUPS/2.3 IPP/2.1
|_http-title: Home - CUPS 2.3.1
3306/tcp open  mysql
| mysql-info:
|   Protocol: 10
|   Version: 8.0.30-0ubuntu0.20.04.2
|   Thread ID: 15
|   Capabilities flags: 65535
|   Some Capabilities: ConnectWithDatabase, SupportsLoadDataLocal, SupportsTransactions, DontAllowDatabaseTableColumn, Support41Auth, InteractiveClient, Speaks41ProtocolOld, FoundRows, IgnoreSigpipes, ODBCClient, SwitchToSSLAfterHandshake, IgnoreSpaceBeforeParenthesis, LongColumnFlag, Speaks41ProtocolNew, SupportsMultipleStatments, LongPassword, SupportsCompression, SupportsMultipleResults, SupportsAuthPlugins
|   Status: Autocommit
|   Salt: \x7FeL)\x0C\x5C#S\x06N%\x1E\x7EYaC
|_  Auth Plugin Name: caching_sha2_password

Nmap done: 1 IP address (1 host up) scanned in 5.28 seconds

서비스 감지와 스크립트 스캔 결합

가장 포괄적인 결과를 얻으려면 서비스 감지와 스크립트 스캔을 결합하십시오.

nmap -sV -sC localhost

출력:

Starting Nmap 7.80 ( https://nmap.org ) at 2023-09-14 17:25 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00012s latency).
Not shown: 996 closed ports
PORT     STATE SERVICE VERSION
22/tcp   open  ssh     OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
|   3072 e2:5d:9c:5c:62:42:44:cd:fc:31:e0:a6:18:11:69:1c (RSA)
|   256 7d:95:f0:2f:7a:95:3a:4d:f3:52:ef:6f:6b:af:01:71 (ECDSA)
|_  256 90:12:20:de:cb:c0:76:3a:fb:15:db:75:4e:78:fc:d7 (ED25519)
80/tcp   open  http    Apache httpd 2.4.41 ((Ubuntu))
|_http-server-header: Apache/2.4.41 (Ubuntu)
|_http-title: Apache2 Ubuntu Default Page: It works
631/tcp  open  ipp     CUPS 2.3
|_http-server-header: CUPS/2.3 IPP/2.1
|_http-title: Home - CUPS 2.3.1
3306/tcp open  mysql   MySQL 8.0.30-0ubuntu0.20.04.2
|_mysql-info: ERROR: Script execution failed (use -d to debug)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 9.03 seconds

대상 서비스 분석

특정 서비스를 자세히 분석하는 데 집중해 보겠습니다.

HTTP 서비스 분석

HTTP 서비스를 자세히 분석하려면 http-* 스크립트를 사용할 수 있습니다.

nmap --script="http-*" -p 80 localhost

이것은 포트 80 에 대해 모든 HTTP 관련 스크립트를 실행합니다.

Starting Nmap 7.80 ( https://nmap.org ) at 2023-09-14 17:30 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00012s latency).

PORT   STATE SERVICE
80/tcp open  http
|_http-chrono: Request times for /; avg: 32.68ms; min: 32.68ms; max: 32.68ms
|_http-comments-displayer: Couldn't find any comments.
|_http-date: Thu, 14 Sep 2023 17:30:24 GMT; +6s from local time.
|_http-devframework: Couldn't determine the underlying framework or CMS. Try increasing 'httpspider.maxpagecount' value to spider more pages.
|_http-dombased-xss: Couldn't find any DOM based XSS.
|_http-favicon: Unknown favicon MD5: 6D33949773573A11BEBE0D20AC1B7967
|_http-feed: Couldn't find any feeds.
|_http-fetch: Please enter the complete path of the directory to save data in.
|_http-generator: Couldn't find any generator in the HTML headers and body
| http-methods:
|_  Supported Methods: GET POST OPTIONS HEAD
|_http-mobileversion-checker: No mobile version detected.
|_http-referer-checker: Couldn't find any cross-domain scripts.
|_http-security-headers:
| http-server-header:
|   Apache/2.4.41
|_  Apache/2.4.41 (Ubuntu)
|_http-title: Apache2 Ubuntu Default Page: It works
|_http-traceroute: ERROR: Script execution failed (use -d to debug)
|_http-useragent-tester:
|_http-xssed: No previously reported XSS vuln.

Nmap done: 1 IP address (1 host up) scanned in 2.31 seconds

SSH 서비스 분석

마찬가지로 SSH 서비스를 분석할 수 있습니다.

nmap --script="ssh-*" -p 22 localhost

출력:

Starting Nmap 7.80 ( https://nmap.org ) at 2023-09-14 17:35 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00013s latency).

PORT   STATE SERVICE
22/tcp open  ssh
| ssh-hostkey:
|   3072 e2:5d:9c:5c:62:42:44:cd:fc:31:e0:a6:18:11:69:1c (RSA)
|   256 7d:95:f0:2f:7a:95:3a:4d:f3:52:ef:6f:6b:af:01:71 (ECDSA)
|_  256 90:12:20:de:cb:c0:76:3a:fb:15:db:75:4e:78:fc:d7 (ED25519)
|_ssh-run: ERROR: Script execution failed (use -d to debug)

Nmap done: 1 IP address (1 host up) scanned in 0.26 seconds

취약점 스캔

Nmap 에는 잠재적인 취약점을 감지할 수 있는 스크립트가 포함되어 있습니다. vuln 범주를 사용하면 보안 문제를 식별하는 데 도움이 될 수 있습니다.

nmap --script=vuln localhost

이것은 다양한 취약점 검사를 실행하므로 시간이 걸릴 수 있습니다. 출력은 다음과 같습니다.

Starting Nmap 7.80 ( https://nmap.org ) at 2023-09-14 17:40 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00012s latency).
Not shown: 996 closed ports
PORT     STATE SERVICE
22/tcp   open  ssh
80/tcp   open  http
|_http-csrf: Couldn't find any CSRF vulnerabilities.
|_http-dombased-xss: Couldn't find any DOM based XSS.
| http-slowloris-check:
|   VULNERABLE:
|   Slowloris DOS attack
|     State: LIKELY VULNERABLE
|     IDs:  CVE:CVE-2007-6750
|       Slowloris tries to keep many connections to the target web server open and hold
|       them open as long as possible.  It accomplishes this by opening connections to
|       the target web server and sending a partial request. By doing so, it starves
|       the http server's resources causing Denial Of Service.
|
|     Disclosure date: 2009-09-17
|     References:
|       https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2007-6750
|_      http://ha.ckers.org/slowloris/
|_http-stored-xss: Couldn't find any stored XSS vulnerabilities.
631/tcp  open  ipp
3306/tcp open  mysql

Nmap done: 1 IP address (1 host up) scanned in 87.28 seconds

이 경우 Nmap 은 Apache 웹 서버가 Slowloris DoS 공격에 취약할 수 있음을 식별했습니다. 이 정보는 시스템을 보호하는 데 유용할 수 있습니다.

포괄적인 스캔 보고서 만들기

이제 배운 모든 것을 결합하여 포괄적인 보안 보고서를 만들어 보겠습니다.

sudo nmap -sS -sV -O -sC --script=vuln -T4 -oA comprehensive_security_report localhost

이 명령은 다음을 수행합니다.

  • SYN 스텔스 스캔 사용 (-sS)
  • 서비스 버전 감지 (-sV)
  • OS 감지 시도 (-O)
  • 기본 스크립트 실행 (-sC)
  • 취약점 감지 스크립트 실행 (--script=vuln)
  • 공격적인 타이밍 사용 (-T4)
  • 모든 형식으로 결과 저장 (-oA)

출력은 포괄적이며 완료하는 데 시간이 걸릴 수 있습니다. 완료되면 보안 분석을 위해 참조할 수 있는 다양한 형식 (일반, XML 및 grepable) 의 자세한 보안 보고서가 있습니다.

이 단계에서는 Nmap 의 스크립팅 엔진을 사용하여 서비스에 대한 자세한 정보를 수집하고 잠재적인 취약점을 감지하는 방법을 배웠습니다. 이러한 고급 기술은 포괄적인 네트워크 보안 평가에 필수적입니다.

요약

이 Lab 에서 네트워크 정찰 및 보안 평가를 위해 Nmap 을 사용하는 기본 사항을 배웠습니다. 이제 다음을 이해하게 되었습니다.

  1. Nmap 을 설치하고 호스트 및 포트의 기본 스캔을 수행하는 방법
  2. 다양한 유형의 스캔에 필수적인 Nmap 스캔 플래그를 사용하는 방법
  3. 효과적인 스캔 전략을 구현하고 타이밍 매개변수를 제어하는 방법
  4. 자세한 서비스 분석 및 취약점 감지를 위해 Nmap Scripting Engine 을 활용하는 방법

이러한 기술은 네트워크 보안 평가의 기초를 형성하며 사이버 보안 전문가에게 필수적입니다. 항상 이러한 기술을 책임감 있게 사용하고 스캔할 권한이 있는 네트워크에서만 사용하십시오.

사이버 보안 여정을 계속 진행하면서 사용자 지정 NSE 스크립트 개발, 방화벽 회피 기술 및 기타 보안 도구와의 통합과 같은 더 고급 Nmap 기능을 탐색해 보십시오. Nmap 을 정기적으로 연습하면 네트워크 환경에서 잠재적인 보안 문제를 식별하는 데 더 능숙해질 수 있습니다.