Nmap 요약 (ESP)
Tip
AWS Hacking을 배우고 연습하세요:
HackTricks Training AWS Red Team Expert (ARTE)
GCP Hacking을 배우고 연습하세요:HackTricks Training GCP Red Team Expert (GRTE)
Az Hacking을 배우고 연습하세요:HackTricks Training Azure Red Team Expert (AzRTE)
평가 트랙 (ARTA/GRTA/AzRTA)과 Linux Hacking Expert (LHE)를 보려면 전체 HackTricks Training 카탈로그를 둘러보세요.
HackTricks 지원하기
- subscription plans를 확인하세요!
- 💬 Discord group, telegram group에 참여하고, X/Twitter에서 @hacktricks_live를 팔로우하거나, LinkedIn page와 YouTube channel을 확인하세요.
- HackTricks 및 HackTricks Cloud github repos에 PR을 제출해 hacking tricks를 공유하세요.
nmap -sV -sC -O -n -oA nmapscan 192.168.0.1/24
매개변수
스캔할 IP
<ip>,<net/mask>: IP들을 직접 지정-iL <ips_file>: IP 목록-iR <number>: 무작위 IP 수.--exclude <Ips>또는--excludefile <file>로 제외할 IP를 지정할 수 있습니다.
장비 검색
기본적으로 Nmap은 다음으로 구성된 탐지 단계를 실행합니다: -PA80 -PS443 -PE -PP
-sL: 비침해적이며 대상 목록을 출력하기 위해 DNS 조회를 수행합니다. 예를 들어 www.prueba.es/24의 모든 IP가 대상인지 확인할 때 유용합니다.-Pn: Ping 사용 안 함. 모든 호스트가 활성화되어 있음을 알고 있을 때 유용합니다(아니면 많은 시간을 잃을 수 있으며, 이 옵션은 비활성으로 잘못 판단하는 false negative를 초래할 수 있음). 탐지 단계를 건너뜁니다.-sn: 포트 스캔 없음. 정찰 단계 완료 후 포트를 스캔하지 않습니다. 상대적으로 은밀하고 작은 네트워크 호스트 검색에 적합합니다. 권한이 있으면 80에 ACK(-PA), 443에 SYN(-PS) 및 echo 요청과 Timestamp 요청을 보냅니다. 권한이 없으면 항상 연결을 완료합니다. 대상이 네트워크일 경우 ARP(-PR)만 사용합니다. 다른 옵션과 함께 사용하면 해당 옵션의 패킷만 전송됩니다.-PR: ARP Ping. 같은 네트워크의 컴퓨터를 분석할 때 기본으로 사용되며 ping보다 빠릅니다. ARP 패킷을 사용하지 않으려면--send-ip를 사용하세요.-PS <ports>: SYN 패킷을 보냅니다. SYN/ACK를 받으면 열린 상태(연결을 끝내지 않기 위해 RST로 응답), RST를 받으면 닫힘, 응답이 없으면 도달 불가로 간주됩니다. 권한이 없으면 전체 연결이 자동으로 사용됩니다. 포트를 지정하지 않으면 기본적으로 80에 보냅니다.-PA <ports>: 이전과 유사하지만 ACK 사용. 둘을 조합하면 더 좋은 결과를 얻습니다.-PU <ports>: 반대 목적입니다. 닫혀있을 것으로 예상되는 포트로 보냅니다. 일부 방화벽은 TCP 연결만 검사합니다. 닫혀있으면 port unreachable로 응답하고, 다른 ICMP로 응답되거나 응답이 없으면 목적지 도달 불가로 남깁니다.-PE, -PP, -PM: ICMP PING: echo reply, timestamp, address-mask. 대상이 활성인지 확인하기 위해 전송합니다.-PY<ports>: 기본적으로 80에 SCTP INIT 프로브를 보냅니다. INIT-ACK(열림) 또는 ABORT(닫힘) 또는 응답 없음 또는 ICMP unreachable(비활성)로 응답할 수 있습니다.-PO <protocols>: 헤더에 프로토콜 번호를 지정합니다. 기본은 1(ICMP), 2(IGMP), 4(Encap IP). ICMP, IGMP, TCP(6), UDP(17)의 경우 프로토콜 헤더를 보내고, 나머지는 IP 헤더만 보냅니다. 헤더의 비정상성 때문에 Protocol unreachable 또는 동일 프로토콜의 응답을 받아 호스트 업 여부를 판단합니다.-n: DNS 사용 안 함-R: 항상 DNS--system-dns: Nmap의 병렬 stub resolver 대신 OS의 resolver를 강제 사용./etc/hosts, split-DNS, 또는 resolver 플러그인이 Nmap의 직접 질의와 다른 결과를 줄 때 유용합니다. 느리며, Nmap 7.96부터 forward lookups는 이미 병렬화되어 있으므로 보통 호환성 문제에서만 필요합니다.--dns-servers <server[,server],...>: 역방향 조회에 특정 DNS 서버를 강제 사용. 내부 평가에서 권한 있는(resolving) 또는 내부 resolver를 직접 조회하거나-sL/역방향 DNS 트래픽을 테스트어의 기본 resolver에서 우회시키는 데 유용합니다.
포트 스캔 기법
-sS: 연결을 완료하지 않아 흔적을 남기지 않습니다(권한 필요). 기본적으로 사용되는 방식입니다.-sT: 연결을 완료하므로 흔적을 남깁니다. 권한이 없을 때 기본으로 사용됩니다.-sU: UDP용으로 느립니다. 주로 DNS(53), SNMP(161,162), DHCP(67,68)에 사용됩니다. (-sU53,161,162,67,68): open(reply), closed(port unreachable), filtered(다른 ICMP), open/filtered(응답 없음). open/filtered의 경우 -sV가 nmap이 지원하는 다양한 요청을 보내 실제 상태를 탐지하려고 시도합니다. 시간이 많이 늘어납니다.-sY: SCTP 프로토콜에서 연결을 확립하지 못하므로 로그가 남지 않습니다. -PY와 유사하게 동작합니다.-sN,-sX,-sF: Null, Fin, Xmas. 일부 방화벽을 우회하거나 정보를 추출할 수 있습니다. 표준 준수 머신은 SYN, RST, ACK 비트가 없는 모든 요청에 RST로 응답해야 한다는 점에 기반합니다: open/filtered(응답 없음), closed(RST), filtered(ICMP unreachable). Windows, CIsco, BSDI, OS/400에서는 신뢰할 수 없고 Unix에서 동작합니다.-sM: Maimon 스캔: FIN과 ACK 플래그를 전송합니다. BSD용으로 사용되었으나 현재는 모두 닫힘으로 반환할 것입니다.-sA, sW: ACK 및 Window 스캔. 방화벽을 감지하고 포트가 필터링 되는지 알기 위해 사용합니다. -sW는 열린 포트와 닫힌 포트를 윈도우 값으로 구분합니다: open (RST, window != 0), closed (RST, window = 0), filtered (ICMP unreachable 또는 응답 없음). 모든 시스템이 이 방식으로 동작하지 않으므로, 모두 closed로 나오면 작동하지 않는 것이고, 일부만 open이면 정상 작동, 많은 open과 적은 closed이면 반대 방식으로 동작한다는 뜻입니다.-sI: Idle scan. 활성 방화벽이 있지만 특정 IP에는 필터링하지 않는 경우(또는 단순히 익명성을 원할 때) 좀비 스캐너를 사용합니다(모든 포트에 대해 동작). 가능한 좀비를 찾으려면 ipidseq 스크립트나 exploit auxiliary/scanner/ip/ipidseq를 사용할 수 있습니다. 이 스캐너는 IP 패킷의 IPID 번호에 기반합니다.--badsum: 체크섬을 잘못 설정해 전송합니다. 대상 호스트는 패킷을 버리지만 방화벽은 응답할 수 있어 방화벽 탐지에 사용됩니다.-sZ: “Weird” SCTP 스캐너. cookie echo fragments를 전송할 때 열려 있으면 드롭되어야 하고 닫혀 있으면 ABORT로 응답합니다. INIT으로 통과하지 못하는 방화벽을 통과할 수 있지만, filtered와 open을 구분하지 못합니다.-sO: IP 프로토콜 스캔. 때때로 프로토콜도 구분할 수 없을 정도로 비정상적인 빈 헤더를 보냅니다. ICMP unreachable protocol이 도착하면 닫힘, unreachable port가 도착하면 열림, 다른 오류면 filtered, 응답이 없으면 open|filtered로 간주합니다.-b <server>: FTP bounce -> 다른 호스트에서 스캔하는 데 사용합니다. 다른 머신의 FTP에 접속해 해당 머신으로 하여금 목적 포트로 파일을 전송하게 하여 응답으로 포트 상태를 판단합니다. 형식: [<user>:<password>@]<server>[:<port>]. 거의 모든 FTP 서버가 이를 허용하지 않으므로 실무적 유용성은 낮습니다.
심화 분석
-p: 스캔할 포트를 지정하는 데 사용합니다. 전체 65,535 포트를 선택하려면: -p- 또는 -p all. Nmap은 인기도(popularity)에 따른 내부 분류를 가지고 있습니다. 기본적으로 상위 1000 포트를 사용합니다. -F(빠른 스캔)로 상위 100개를 스캔합니다. **–top-ports
-sV 버전 탐지, 강도는 0에서 9까지 조절 가능, 기본값은 7.
–version-intensity
–version-light --version-intensity 2의 별칭. 큰 범위나 느린 UDP 서비스에 대한 첫 패스에 매우 유용합니다.
–version-all --version-intensity 9의 별칭. 모든 프로브를 강제하며, 서비스가 드문 프로브에만 응답할 때 유용합니다.
–allports nmap-service-probes에 의해 제외된 포트들(특히 TCP/9100)에 대해서도 버전 탐지를 강제합니다. 주의: 일부 프린터나 raw socket 리스너에서는 프로브 데이터를 인쇄하게 만들 수 있습니다.
-O OS 탐지
–osscan-limit 적절한 호스트 스캔을 위해서는 최소 하나의 open 포트와 하나의 closed 포트가 필요합니다. 이 조건이 충족되지 않으면(그리고 이 옵션을 설정했으면) OS 예측을 시도하지 않습니다(시간 절약).
–osscan-guess OS 탐지가 완벽하지 않을 때 더 강하게 시도합니다.
Scripts
–script
기본 스크립트를 사용하려면 -sC 또는 –script=default
사용 가능한 타입: auth, broadcast, default, discovery, dos, exploit, external, fuzzer, intrusive, malware, safe, version, vuln
- Auth: 사용 가능한 인증 관련 스크립트 모두 실행
- Default: 기본적인 도구 스크립트 실행
- Discovery: 대상이나 피해자로부터 정보를 수집
- External: 외부 자원 사용을 위한 스크립트
- Intrusive: 대상에 대해 침입성 있는 스크립트 실행
- Malware: 악성코드나 백도어가 연 연결을 검사
- Safe: 비침해적 스크립트 실행
- Vuln: 널리 알려진 취약점 탐지
- All: 사용 가능한 모든 NSE 확장 스크립트 전부 실행
스크립트 검색:
nmap –script-help=“http-*” -> http-로 시작하는 것들
nmap –script-help=“not intrusive” -> intrusive가 아닌 모든 것들
nmap –script-help=“default or safe” -> 둘 중 하나 또는 둘 다에 속하는 것들
nmap –script-help=“default and safe” –> 둘 다에 속하는 것들
nmap –script-help=“(default or safe or intrusive) and not http-*”
–script-args
–script-args-file
–script-help
–script-trace —> 스크립트 진행 상황에 대한 정보를 제공합니다
–script-updatedb
스크립트를 사용하려면 단순히: nmap –script Script_Name target –> 스크립트를 사용할 때 스크립트와 스캐너가 모두 실행되므로 스캐너 옵션도 추가할 수 있습니다. 안전한 스크립트만 실행하려면 **“safe=1”**을 추가할 수 있습니다.
시간 제어
Nmap은 초, 분, ms 단위 시간을 변경할 수 있습니다: –host-timeout 인수로 900000ms, 900, 900s, 15m는 모두 동일합니다.
Nmap은 스캔할 전체 호스트 수를 그룹으로 나누어 블록 단위로 분석합니다. 한 블록이 완전히 분석될 때까지 다음 블록으로 넘어가지 않으므로(사용자에게는 블록이 분석될 때까지 업데이트가 없습니다) 큰 그룹을 사용하는 것이 더 최적입니다. 기본적으로 class C에서는 256을 사용합니다.
이는 –min-hostgroup
병렬 스캐너 수를 제어할 수 있지만(Nmap은 네트워크 상태에 따라 자동 제어를 이미 포함하므로) 보통 변경하지 않는 것이 좋습니다: –min-parallelism
RTT 타임아웃을 수정할 수 있지만 보통 불필요합니다: –min-rtt-timeout , –max-rtt-timeout , –initial-rtt-timeout
재시도 횟수를 수정할 수 있습니다: –max-retries
호스트 당 스캔 시간을 수정할 수 있습니다: –host-timeout
각 테스트 사이의 지연을 늘려 스캔을 느리게 할 수 있습니다: –scan-delay ; –max-scan-delay
초당 패킷 수를 수정할 수 있습니다: –min-rate
많은 포트는 필터되었거나 닫혀있을 때 응답 시간이 깁니다. 열린 포트만 관심 있다면 더 빠르게 하려면: –defeat-rst-ratelimit
Nmap의 공격성을 정의하려면: -T paranoid|sneaky|polite|normal|aggressive|insane
-T (0-1)
-T0 –> 한 번에 포트 1개만 스캔하고 다음 스캔까지 5분 대기
-T1 및 T2 –> 매우 유사하지만 각 테스트 사이에 각각 15초와 0.4초 대기
-T3 –> 기본 동작, 병렬 스캔 포함
-T4 –> –max-rtt-timeout 1250ms –min-rtt-timeout 100ms –initial-rtt-timeout 500ms –max-retries 6 –max-scan-delay 10ms
-T5 –> –max-rtt-timeout 300ms –min-rtt-timeout 50ms –initial-rtt-timeout 250ms –max-retries 2 –host-timeout 15m –max-scan-delay 5ms
방화벽/IDS
포트 접근을 차단하고 패킷을 분석합니다.
-f 패킷을 분할(fragment)합니다. 기본적으로 헤더 이후 8바이트 단위로 분할합니다. 크기를 지정하려면 ..mtu를 사용하세요(이 경우 -f는 사용하지 마세요). 오프셋은 8의 배수여야 합니다. 버전 탐지기와 스크립트는 fragmentation을 지원하지 않습니다
-D decoy1,decoy2,ME Nmap은 스캐닝을 다른 IP 출처로 보이게 보냅니다(디코이). 이렇게 하면 당신을 숨길 수 있습니다. 목록에 ME를 넣으면 Nmap이 당신을 그 위치에 넣습니다. 완전히 숨기려면 당신 앞에 5~6개의 디코이를 두는 것이 좋습니다. RND:
무작위 IP 사용 예: nmap -D RND:10 Target_IP
-S IP Nmap이 당신의 IP를 확인하지 못할 때 명시적으로 제공할 수 있습니다. 또한 다른 타겟이 스캔하는 것처럼 보이게 하는 데 사용됩니다.
-e
많은 관리자가 시스템 동작을 위해 특정 포트를 전부 허용하는 방화벽 규칙을 둡니다(예: 20, 53, 67). 이런 취약점을 찾기 위해 Nmap은 –source-port
–data
–data-string
–data-length
IP 패킷을 완전히 구성하려면 –ip-options 사용
송수신되는 패킷의 옵션을 보려면 –packet-trace 지정. IP 옵션을 Nmap으로 사용하는 예제와 자세한 정보는 http://seclists.org/nmap-dev/2006/q3/52 참조.
–ttl
–randomize-hosts 공격을 덜 눈에 띄게 만듭니다
–spoof-mac <MAC address, prefix, or vendor name> MAC 변경 예: Apple, 0, 01:02:03:04:05:06, deadbeefcafe, 0020F2, Cisco
–proxies
-sP ARP로 네트워크 내 호스트 발견
많은 관리자가 특정 포트에서 오는 모든 패킷을 허용하는 방화벽 규칙을 만듭니다(예: 20,53,67). Nmap에게 이러한 포트로부터 패킷을 보내도록 할 수 있습니다: nmap –source-port 53 IP
출력
-oN file 일반 출력
-oX file XML 출력
-oS file Script kiddies 출력
-oG file Greppable 출력. 여전히 동작하지만 deprecated; XML이 자동화에 더 좋은 형식입니다(새로운 Nmap 기능이 먼저 XML에 추가됨). --resume을 원하면 -oN을 계속 사용하고, 기계 파싱에는 -oX/-oA를 권장합니다.
-oA file -oS를 제외한 모든 출력
–webxml XML 스타일시트 참조를 https://nmap.org/svn/docs/nmap.xsl로 변경하여 다른 머신에서 HTML로 열기 쉽게 만듭니다.
–stylesheet <path|url> 커스텀 XSL 스타일시트 사용. --webxml은 공식 호스팅 스타일시트의 단축키입니다.
-v level 자세도(verbosity)
-d level 디버깅 레벨
–reason 호스트 상태의 이유 출력
–stats-every time 지정한 주기마다 진행 상황 보고
–packet-trace 전송되는 패킷을 확인, 필터 지정 가능: –version-trace 또는 –script-trace
–open open, open|filtered 및 unfiltered만 표시
–resume file 중단된 스캔을 정상(-oN) 또는 grepable(-oG) 출력 파일에서 재개. 현재 워크플로우에서는 재개 가능성을 위해 -oN을 유지하고 파싱을 위해 -oX를 사용하는 것이 일반적입니다.
파싱/HTML 변환 워크플로우 예:
# Send only XML to stdout for tooling
nmap -sV -oX - 10.10.10.0/24
# Portable HTML-friendly XML
nmap -sV --webxml -oX scan.xml 10.10.10.10
기타
-6 IPv6 허용
-A 는 -O -sV -sC –traceroute 와 동일
런타임
Nmap 실행 중에 옵션을 변경할 수 있다:
v / V 출력 상세도 증가 / 감소
d / D 디버깅 레벨 증가 / 감소
p / P 패킷 추적 켜기 / 끄기
? 런타임 상호작용 도움말 화면 출력
Vulscan
오프라인 데이터베이스(다른 주요 데이터베이스에서 다운로드한)를 기반으로 서비스 버전을 검사해 잠재적 취약점을 반환하는 Nmap 스크립트
The DBs it uses are:
- Scipvuldb.csv | http://www.scip.ch/en/?vuldb
- Cve.csv | http://cve.mitre.org
- Osvdb.csv | http://www.osvdb.org
- Securityfocus.csv | http://www.securityfocus.com/bid/
- Securitytracker.csv | http://www.securitytracker.com
- Xforce.csv | http://xforce.iss.net
- Exploitdb.csv | http://www.exploit-db.com
- Openvas.csv | http://www.openvas.org
Nmap 폴더에 다운로드 및 설치하려면:
wget http://www.computec.ch/projekte/vulscan/download/nmap_nse_vulscan-2.0.tar.gz && tar -czvf nmap_nse_vulscan-2.0.tar.gz vulscan/ && sudo cp -r vulscan/ /usr/share/nmap/scripts/
또한 DB 패키지들을 다운로드해 /usr/share/nmap/scripts/vulscan/ 에 추가해야 한다.
사용법:
모두 사용하려면: sudo nmap -sV –script=vulscan HOST_TO_SCAN
특정 DB를 사용하려면: sudo nmap -sV –script=vulscan –script-args vulscandb=cve.csv HOST_TO_SCAN
인터넷 접속이 가능하다면, Nmap의 공식 vulners NSE 스크립트가 버전 기반 정보 보강에 대해 보통 가장 빠르게 유지되는 대안이다:
nmap -sV --script vulners --script-args mincvss=7.0 <IP>
This script belongs to the safe, external, and vuln categories. Because it depends on how accurate -sV was, validate hits manually when the service banner is generic or proxied.
Recent Practical Notes (7.94+)
- Since Nmap 7.94, UDP port scan (
-sU) and version detection (-sV) use the samenmap-service-probespayload source. A UDP response from the scan phase can immediately feed version matching, so-sU -sV --version-lightis now a good first pass against large or lossy ranges. - Since Nmap 7.94,
-sVcan also probe UDP services hidden behind DTLS, which is useful for modern management/ICS gear that wraps UDP protocols in DTLS. - Nmap 7.95 added a large batch of new service fingerprints, including
grpc,mysqlx,remotemouse, andtuya, plus new ICS-focused NSE coverage such ashartip-infoandiec61850-mms. If you are scanning OT or embedded estates, updating Nmap matters more than adding custom probes too early. - Since Nmap 7.96, forward DNS lookups are parallelized too. Large hostname lists are much faster now, so
--system-dnsshould usually be reserved for compatibility issues instead of performance.
Speed Up Nmap Service scan x16
According to this post you can speed up the nmap service analysis by modifying all the totalwaitms values in /usr/share/nmap/nmap-service-probes to 300 and tcpwrappedms to 200.
Moreover, probes which do not have a specifically defined servicewaitms use a default value of 5000. Therefore, we can either add values to each of the probes, or we can compile nmap ourselves and change the default value in service_scan.h.
If you don’t want to change the values of totalwaitms and tcpwrappedms at all in the /usr/share/nmap/nmap-service-probes file, you can edit the parsing code such that these values in the nmap-service-probes file are completely ignored.
Build a static Nmap for restricted environments
In hardened or minimal Linux environments (containers, appliances), dynamically linked Nmap binaries often fail due to missing runtime loaders or shared libraries (e.g., /lib64/ld-linux-x86-64.so.2, libc.so). Building your own statically linked Nmap and bundling NSE data allows execution without installing system packages.
High-level approach
- Use a clean amd64 Ubuntu builder via Docker.
- Build OpenSSL and PCRE2 as static libraries.
- Build Nmap linking statically and using the included libpcap/libdnet to avoid dynamic deps.
- Bundle NSE scripts and data directories with the binary.
Discover target architecture (example)
uname -a
# If building from macOS/ARM/etc., pin the builder arch:
docker run --rm --platform=linux/amd64 -v "$(pwd)":/out -w /tmp ubuntu:22.04 bash -lc 'echo ok'
1단계 — 툴체인 준비
set -euo pipefail
export DEBIAN_FRONTEND=noninteractive
apt-get update && apt-get install -y --no-install-recommends \
build-essential ca-certificates curl bzip2 xz-utils pkg-config perl python3 file git \
automake autoconf libtool m4 zlib1g-dev
2단계 — 정적 OpenSSL 빌드 (1.1.1w)
OSSL="1.1.1w"
curl -fsSLO "https://www.openssl.org/source/openssl-$OSSL.tar.gz"
tar xzf "openssl-$OSSL.tar.gz" && cd "openssl-$OSSL"
./Configure no-shared no-zlib linux-x86_64 -static --prefix=/opt/ossl
make -j"$(nproc)" && make install_sw
cd /tmp
3단계 — 정적 PCRE2 빌드 (10.43)
PCRE2=10.43
curl -fsSLO "https://github.com/PCRE2Project/pcre2/releases/download/pcre2-$PCRE2/pcre2-$PCRE2.tar.bz2"
tar xjf "pcre2-$PCRE2.tar.bz2" && cd "pcre2-$PCRE2"
./configure --disable-shared --enable-static --prefix=/opt/pcre2
make -j"$(nproc)" && make install
cd /tmp
4단계 — 정적 Nmap (7.98) 빌드
NMAP=7.98
curl -fsSLO "https://nmap.org/dist/nmap-$NMAP.tar.bz2"
tar xjf "nmap-$NMAP.tar.bz2" && cd "nmap-$NMAP"
export CPPFLAGS="-I/opt/ossl/include -I/opt/pcre2/include"
export LDFLAGS="-L/opt/ossl/lib -L/opt/pcre2/lib -static -static-libstdc++ -static-libgcc"
export LIBS="-lpcre2-8 -ldl -lpthread -lz"
./configure \
--with-openssl=/opt/ossl \
--with-libpcre=/opt/pcre2 \
--with-libpcap=included \
--with-libdnet=included \
--without-zenmap --without-ndiff --without-nmap-update
# Avoid building shared libpcap by accident
sed -i -e "s/^shared: /shared: #/" libpcap/Makefile || true
make -j1 V=1 nmap
strip nmap
Key points
- -static, -static-libstdc++, -static-libgcc는 정적 링크를 강제합니다.
- –with-libpcap=included/–with-libdnet=included를 사용하면 시스템 공유 라이브러리를 피할 수 있습니다.
- sed 조정은 존재하는 경우 공유 libpcap 타깃을 무력화합니다.
Step 5 — Bundle binary and NSE data
mkdir -p /out/nmap-bundle/nmap-data
cp nmap /out/nmap-bundle/nmap-linux-amd64-static
cp -r scripts nselib /out/nmap-bundle/nmap-data/
cp nse_main.lua nmap-services nmap-protocols nmap-service-probes \
nmap-mac-prefixes nmap-os-db nmap-payloads nmap-rpc \
/out/nmap-bundle/nmap-data/ 2>/dev/null || true
tar -C /out -czf /out/nmap-linux-amd64-static-bundle.tar.gz nmap-bundle
검증 및 운영 메모
- 아티팩트에서 file 명령으로 정적으로 링크되었는지 확인하세요.
- Nmap이 설치되지 않은 호스트에서 스크립트 일관성을 보장하려면 바이너리와 함께 NSE 데이터를 유지하세요.
- 정적 바이너리라도 AppArmor/seccomp/SELinux에 의해 실행이 차단될 수 있으니 DNS/egress가 여전히 작동하는지 확인하세요.
- Deterministic builds는 불투명한 “static” 바이너리를 다운로드하는 것보다 공급망 위험을 줄입니다.
원라이너 (Dockerized)
빌드, 번들 및 아티팩트 정보 출력
```bash docker run --rm --platform=linux/amd64 -v "$(pwd)":/out -w /tmp ubuntu:22.04 bash -lc ' set -euo pipefail export DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y --no-install-recommends \ build-essential ca-certificates curl bzip2 xz-utils pkg-config perl python3 file git \ automake autoconf libtool m4 zlib1g-devOSSL=“1.1.1w”; curl -fsSLO “https://www.openssl.org/source/openssl-$OSSL.tar.gz”
&& tar xzf “openssl-$OSSL.tar.gz” && cd “openssl-$OSSL”
&& ./Configure no-shared no-zlib linux-x86_64 -static –prefix=/opt/ossl
&& make -j“$(nproc)“ && make install_sw && cd /tmp
PCRE2=10.43; curl -fsSLO “https://github.com/PCRE2Project/pcre2/releases/download/pcre2-$PCRE2/pcre2-$PCRE2.tar.bz2”
&& tar xjf “pcre2-$PCRE2.tar.bz2” && cd “pcre2-$PCRE2”
&& ./configure –disable-shared –enable-static –prefix=/opt/pcre2
&& make -j“$(nproc)“ && make install && cd /tmp
NMAP=7.98; curl -fsSLO “https://nmap.org/dist/nmap-$NMAP.tar.bz2”
&& tar xjf “nmap-$NMAP.tar.bz2” && cd “nmap-$NMAP”
&& export CPPFLAGS=“-I/opt/ossl/include -I/opt/pcre2/include”
&& export LDFLAGS=“-L/opt/ossl/lib -L/opt/pcre2/lib -static -static-libstdc++ -static-libgcc”
&& export LIBS=“-lpcre2-8 -ldl -lpthread -lz”
&& ./configure –with-openssl=/opt/ossl –with-libpcre=/opt/pcre2 –with-libpcap=included –with-libdnet=included –without-zenmap –without-ndiff –without-nmap-update
&& sed -i -e “s/^shared: /shared: #/” libpcap/Makefile || true
&& make -j1 V=1 nmap && strip nmap
mkdir -p /out/nmap-bundle/nmap-data
&& cp nmap /out/nmap-bundle/nmap-linux-amd64-static
&& cp -r scripts nselib /out/nmap-bundle/nmap-data/
&& cp nse_main.lua nmap-services nmap-protocols nmap-service-probes nmap-mac-prefixes nmap-os-db nmap-payloads nmap-rpc /out/nmap-bundle/nmap-data/ 2>/dev/null || true
&& tar -C /out -czf /out/nmap-linux-amd64-static-bundle.tar.gz nmap-bundle
&& echo “===== OUTPUT =====”; ls -lah /out; echo “===== FILE TYPE =====”; file /out/nmap-bundle/nmap-linux-amd64-static || true
’
</details>
## 참고자료
- [Compiling static Nmap binary for jobs in restricted environments](https://www.pentestpartners.com/security-blog/compiling-static-nmap-binary-for-jobs-in-restricted-environments/)
- [Static Nmap Binary Generator (helper tool)](https://github.com/0x5ubt13/static_nmap_binary_generator)
- [OpenSSL sources](https://www.openssl.org/source/)
- [PCRE2 releases](https://github.com/PCRE2Project/pcre2/releases)
- [Nmap source tarballs](https://nmap.org/dist/)
- [Nmap Change Log](https://nmap.org/changelog.html)
- [Nmap Output Formats](https://nmap.org/book/man-output.html)
> [!TIP]
> AWS Hacking을 배우고 연습하세요:<img src="../../../../../images/arte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://hacktricks-training.com/courses/arte)<img src="../../../../../images/arte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">\
> GCP Hacking을 배우고 연습하세요: <img src="../../../../../images/grte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training GCP Red Team Expert (GRTE)**](https://hacktricks-training.com/courses/grte)<img src="../../../../../images/grte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">\
> Az Hacking을 배우고 연습하세요: <img src="../../../../../images/azrte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training Azure Red Team Expert (AzRTE)**](https://hacktricks-training.com/courses/azrte)<img src="../../../../../images/azrte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">
> 평가 트랙 (**ARTA/GRTA/AzRTA**)과 [**Linux Hacking Expert (LHE)**](https://hacktricks-training.com/courses/lhe/)를 보려면 [**전체 HackTricks Training 카탈로그**](https://hacktricks-training.com/courses/)를 둘러보세요.
>
> <details>
>
> <summary>HackTricks 지원하기</summary>
>
> - [**subscription plans**](https://github.com/sponsors/carlospolop)를 확인하세요!
> - 💬 [**Discord group**](https://discord.gg/hRep4RUj7f), [**telegram group**](https://t.me/peass)에 **참여**하고, X/Twitter에서 [**@hacktricks_live**](https://twitter.com/hacktricks_live)를 **팔로우**하거나, [**LinkedIn page**](https://www.linkedin.com/company/hacktricks/)와 [**YouTube channel**](https://www.youtube.com/@hacktricks_LIVE)을 확인하세요.
> - [**HackTricks**](https://github.com/carlospolop/hacktricks) 및 [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos에 PR을 제출해 hacking tricks를 공유하세요.
>
> </details>


