nmap安装和使用

安装

官网地址 https://nmap.org/download.html

许多流行的Linux发行版(Redhat、Mandrake、Suse等)都使用RPM软件包管理系统,方便快速安装二进制软件包。我们已经写了一个详细的[安装我们的RPM包指南](https://nmap.org/book/inst linux.html\inst安装-rpm),尽管这些简单的命令通常能起到以下作用:

Many popular Linux distributions (Redhat, Mandrake, Suse, etc) use the RPM package management system for quick and easy binary package installation. We have written a detailed guide to installing our RPM packages, though these simple commands usually do the trick:

rpm -vhU https://nmap.org/dist/nmap-7.91-1.x86_64.rpm

使用

Map help 可以看到如下列表 但是大部分情况下只用到其中的几个

Can pass hostnames, IP addresses, networks, etc.
Ex: scanme.nmap.org, microsoft.com/24, 192.168.0.1; 10.0.0-255.1-254
-iL <inputfilename>: Input from list of hosts/networks
-iR <num hosts>: Choose random targets
--exclude <host1[,host2][,host3],...>: Exclude hosts/networks
--excludefile <exclude_file>: Exclude list from file
HOST DISCOVERY:
-sL: List Scan - simply list targets to scan
-sn: Ping Scan - disable port scan
-Pn: Treat all hosts as online -- skip host discovery
-PS/PA/PU/PY[portlist]: TCP SYN/ACK, UDP or SCTP discovery to given ports
-PE/PP/PM: ICMP echo, timestamp, and netmask request discovery probes
-PO[protocol list]: IP Protocol Ping
-n/-R: Never do DNS resolution/Always resolve [default: sometimes]
--dns-servers <serv1[,serv2],...>: Specify custom DNS servers
--system-dns: Use OS's DNS resolver
--traceroute: Trace hop path to each host
SCAN TECHNIQUES:
-sS/sT/sA/sW/sM: TCP SYN/Connect()/ACK/Window/Maimon scans
-sU: UDP Scan
-sN/sF/sX: TCP Null, FIN, and Xmas scans
--scanflags <flags>: Customize TCP scan flags
-sI <zombie host[:probeport]>: Idle scan
-sY/sZ: SCTP INIT/COOKIE-ECHO scans
-sO: IP protocol scan
-b <FTP relay host>: FTP bounce scan
PORT SPECIFICATION AND SCAN ORDER:
-p <port ranges>: Only scan specified ports
Ex: -p22; -p1-65535; -p U:53,111,137,T:21-25,80,139,8080,S:9
--exclude-ports <port ranges>: Exclude the specified ports from scanning
-F: Fast mode - Scan fewer ports than the default scan
-r: Scan ports consecutively - don't randomize
--top-ports <number>: Scan <number> most common ports
--port-ratio <ratio>: Scan ports more common than <ratio>
SERVICE/VERSION DETECTION:
-sV: Probe open ports to determine service/version info
--version-intensity <level>: Set from 0 (light) to 9 (try all probes)
--version-light: Limit to most likely probes (intensity 2)
--version-all: Try every single probe (intensity 9)
--version-trace: Show detailed version scan activity (for debugging)
SCRIPT SCAN:
-sC: equivalent to --script=default
--script=<Lua scripts>: <Lua scripts> is a comma separated list of
directories, script-files or script-categories
--script-args=<n1=v1,[n2=v2,...]>: provide arguments to scripts
--script-args-file=filename: provide NSE script args in a file
--script-trace: Show all data sent and received
--script-updatedb: Update the script database.
--script-help=<Lua scripts>: Show help about scripts.
<Lua scripts> is a comma-separated list of script-files or
script-categories.
OS DETECTION:
-O: Enable OS detection
--osscan-limit: Limit OS detection to promising targets
--osscan-guess: Guess OS more aggressively
TIMING AND PERFORMANCE:
Options which take <time> are in seconds, or append 'ms' (milliseconds),
's' (seconds), 'm' (minutes), or 'h' (hours) to the value (e.g. 30m).
-T<0-5>: Set timing template (higher is faster)
--min-hostgroup/max-hostgroup <size>: Parallel host scan group sizes
--min-parallelism/max-parallelism <numprobes>: Probe parallelization
--min-rtt-timeout/max-rtt-timeout/initial-rtt-timeout <time>: Specifies
probe round trip time.
--max-retries <tries>: Caps number of port scan probe retransmissions.
--host-timeout <time>: Give up on target after this long
--scan-delay/--max-scan-delay <time>: Adjust delay between probes
--min-rate <number>: Send packets no slower than <number> per second
--max-rate <number>: Send packets no faster than <number> per second
FIREWALL/IDS EVASION AND SPOOFING:
-f; --mtu <val>: fragment packets (optionally w/given MTU)
-D <decoy1,decoy2[,ME],...>: Cloak a scan with decoys
-S <IP_Address>: Spoof source address
-e <iface>: Use specified interface
-g/--source-port <portnum>: Use given port number
--proxies <url1,[url2],...>: Relay connections through HTTP/SOCKS4 proxies
--data <hex string>: Append a custom payload to sent packets
--data-string <string>: Append a custom ASCII string to sent packets
--data-length <num>: Append random data to sent packets
--ip-options <options>: Send packets with specified ip options
--ttl <val>: Set IP time-to-live field
--spoof-mac <mac address/prefix/vendor name>: Spoof your MAC address
--badsum: Send packets with a bogus TCP/UDP/SCTP checksum
OUTPUT:
-oN/-oX/-oS/-oG <file>: Output scan in normal, XML, s|<rIpt kIddi3,
and Grepable format, respectively, to the given filename.
-oA <basename>: Output in the three major formats at once
-v: Increase verbosity level (use -vv or more for greater effect)
-d: Increase debugging level (use -dd or more for greater effect)
--reason: Display the reason a port is in a particular state
--open: Only show open (or possibly open) ports
--packet-trace: Show all packets sent and received
--iflist: Print host interfaces and routes (for debugging)
--append-output: Append to rather than clobber specified output files
--resume <filename>: Resume an aborted scan
--stylesheet <path/URL>: XSL stylesheet to transform XML output to HTML
--webxml: Reference stylesheet from Nmap.Org for more portable XML
--no-stylesheet: Prevent associating of XSL stylesheet w/XML output
MISC:
-6: Enable IPv6 scanning
-A: Enable OS detection, version detection, script scanning, and traceroute
--datadir <dirname>: Specify custom Nmap data file location
--send-eth/--send-ip: Send using raw ethernet frames or IP packets
--privileged: Assume that the user is fully privileged
--unprivileged: Assume the user lacks raw socket privileges
-V: Print version number
-h: Print this help summary page.
EXAMPLES:
nmap -v -A scanme.nmap.org
nmap -v -sn 192.168.0.0/16 10.0.0.0/8
nmap -v -iR 10000 -Pn -p 80

这里我自己整理了一下常用的命令和解释方便更容易理解

// 扫描类型
-sT TCP connect() 扫描,这是最基本的 TCP 扫描方式。这种扫描很容易被检测到,在目标主机的日志中会记录大批的连接请求以及错误信息。
-sS TCP 同步扫描 (TCP SYN),因为不必全部打开一个 TCP 连接,所以这项技术通常称为半开扫描 (half-open)。这项技术最大的好处是,很少有系统能够把这记入系统日志。不过,你需要 root 权限来定制 SYN 数据包。
-sF,-sX,-sN 秘密 FIN 数据包扫描、圣诞树 (Xmas Tree)、空 (Null) 扫描模式。这些扫描方式的理论依据是:关闭的端口需要对你的探测包回应 RST 包,而打开的端口必需忽略有问题的包(参考 RFC 793 第 64 页)。
-sP ping 扫描,用 ping 方式检查网络上哪些主机正在运行。当主机阻塞 ICMP echo 请求包是 ping 扫描是无效的。nmap 在任何情况下都会进行 ping 扫描,只有目标主机处于运行状态,才会进行后续的扫描。
-sU UDP 的数据包进行扫描,如果你想知道在某台主机上提供哪些 UDP(用户数据报协议,RFC768) 服务,可以使用此选项。
-sA ACK 扫描,这项高级的扫描方法通常可以用来穿过防火墙。
-sW 滑动窗口扫描,非常类似于 ACK 的扫描。
-sR RPC 扫描,和其它不同的端口扫描方法结合使用。
-b FTP 反弹攻击 (bounce attack),连接到防火墙后面的一台 FTP 服务器做代理,接着进行端口扫描。
// 扫描参数
-P0 在扫描之前,不 ping 主机。
-PT 扫描之前,使用 TCP ping 确定哪些主机正在运行。
-PS 对于 root 用户,这个选项让 nmap 使用 SYN 包而不是 ACK 包来对目标主机进行扫描。
-PI 设置这个选项,让 nmap 使用真正的 ping(ICMP echo 请求)来扫描目标主机是否正在运行。
-PB 这是默认的 ping 扫描选项。它使用 ACK(-PT) 和 ICMP(-PI) 两种扫描类型并行扫描。如果防火墙能够过滤其中一种包,使用这种方法,你就能够穿过防火墙。
-O 这个选项激活对 TCP/IP 指纹特征 (fingerprinting) 的扫描,获得远程主机的标志,也就是操作系统类型。
-I 打开 nmap 的反向标志扫描功能。
-f 使用碎片 IP 数据包发送 SYN、FIN、XMAS、NULL。包增加包过滤、入侵检测系统的难度,使其无法知道你的企图。
-v 冗余模式。强烈推荐使用这个选项,它会给出扫描过程中的详细信息。
-S <IP> 在一些情况下,nmap 可能无法确定你的源地址 (nmap 会告诉你)。在这种情况使用这个选项给出你的 IP 地址。
-g port 设置扫描的源端口。一些天真的防火墙和包过滤器的规则集允许源端口为 DNS(53) 或者 FTP-DATA(20) 的包通过和实现连接。显然,如果攻击者把源端口修改为 20 或者 53,就可以摧毁防火墙的防护。
-oN 把扫描结果重定向到一个可读的文件 logfilename 中。
-oS 扫描结果输出到标准输出。
--host_timeout 设置扫描一台主机的时间,以毫秒为单位。默认的情况下,没有超时限制。
--max_rtt_timeout 设置对每次探测的等待时间,以毫秒为单位。如果超过这个时间限制就重传或者超时。默认值是大约 9000 毫秒。
--min_rtt_timeout 设置 nmap 对每次探测至少等待你指定的时间,以毫秒为单位。
-M count 置进行 TCP connect() 扫描时,最多使用多少个套接字进行并行的扫描。

运行实例

nmap www.baidu.com    #查看主机当前开放的端口
nmap -p 1024-65535 www.baidu.com #查看主机端口(1024-65535)中开放的端口
nmap -PS www.baidu.com #探测目标主机开放的端口
nmap -PS22,80,3306 www.baidu.com #探测该地址所列表出的端口是否开放
nmap -O www.baidu.com #探测目标主机操作系统类型
nmap -sP www.baidu.com #探测该地址是否在线
sudo nmap -sS -sV -Pn -v www.baidu.com # 跳过主机发现探测开放端口

nmap扫描原理介绍

扫描方式

  • 全连接扫描:三次握手 防火墙能有效拦截,故很少使用 (产生大量日志,很少使用)

  • 半链接扫描:三次握手前两次,SYN->SYN/ACK->RST 端口开放 SYN->RST/ACK端口关闭 (不记日志,隐蔽性好)

  • 秘密扫描:发送FIN,返回RST (端口关闭,回复RST包;端口开放,不回复)

  • 半链接扫描又叫做间接扫描。FIN扫描、Xmas扫描、Null扫描对Windows无效

整合到定时任务里面进行ip监测

 /**
* 直接在本地执行 shell
*
* @param commands 执行的脚本
* @return 执行结果信息
*/
public static String runLocalShell(String commands) {
Runtime runtime = Runtime.getRuntime(); StringBuilder stringBuffer;
BufferedReader reader;
Process process;
stringBuffer = new StringBuilder();
try {
process = runtime.exec(commands);
InputStream inputStream = process.getInputStream();
reader = new BufferedReader(new InputStreamReader(inputStream));
String buf;
while ((buf = reader.readLine()) != null) {
//舍弃PID 进程信息
if (buf.contains("PID")) {
break;
}
stringBuffer.append(buf.trim()).append(LINE_SEPARATOR);
} } catch (IOException e) {
e.printStackTrace();
return null;
}
return stringBuffer.toString();
} /**
* 调用方法
**/ public static String ContrastValue = "Host seems down"; public static String command = "nmap -sP 1.204.69.51"; /**
* Note: Host seems down. If it is really up, but blocking our ping probes, try -Pn
* Nmap done: 1 IP address (0 hosts up) scanned in 3.01 seconds
* @param args
*/
public static void main(String[] args) {
String resultCommand = ShellRunUtils.runLocalShell(command);
if (resultCommand.contains(ContrastValue)){
System.out.println("主机不在线 Host seems down");
}else{
System.out.println("1 host up");
}
}

nmap安装和使用的更多相关文章

  1. nmap安装过程

    nmap是一个网络扫描和主机检测工具. 功能:1.扫描目标主机开放的端口 2.扫描目标主机特定端口是否关闭 3.路由跟踪(到目标主机所经过的网络节点及其通过时间) 4.扫描一个网段下的所有IP 5.探 ...

  2. n-map安装实操

    强烈建议大家从官网下载nmap,而不是其他的第三方.官网地址:https://nmap.org/download.html 打开是这样的,感觉有点阴森森的色调.BTW,谁能逃得过真香定律呢. wind ...

  3. Centos6.5安装Nmap、tcpdump、mysql、tomcat、靶场WAVSEP

    nmap安装 输入命令如下: yum install nmap 安装完成后,输入nmap -h看是否安装成功. 安装tcpdump 安装tcpdump必须的库: yum install flex yu ...

  4. centos 怎么安装 g++

    centos 怎么安装 g++ 找了n久  找到一个实用的 有gcc  但是 是老版本的  tarball 编译 nmap 的时候说机器没有g++ 各种方法都试过 然后 找到下面这个方法: cento ...

  5. NMAP 基础教程

    原文地址: http://drops.wooyun.org/tips/2002 0x00 nmap 介绍 Nmap  (网络映射器)是由 Gordon Lyon设计,用来探测计算机网络上的主机和服务的 ...

  6. 安装完最小化 RHEL/CentOS 7 后需要做的 30 件事情(三)码农网

    12. 安装 Apache Tomcat Tomcat 是由 Apache 设计的用来运行 Java HTTP web 服务器的 servlet 容器.按照下面的方法安装 tomcat,但需要指出的是 ...

  7. 『安全工具』Nmap 强悍的端口扫描工具

    作为时下流行的端口扫描工具,Nmap有因其扫描的隐密性有“端口扫描之王”之称 上图是黑客帝国(The Matrix)中崔妮蒂用Nmap入侵核发电站的能源管理系统 0x 01 Nmap介绍 Nmap是一 ...

  8. 编写自己的Nmap(NSE)脚本

    编写自己的Nmap脚本 一.介绍 在上一篇文章Nmap脚本引擎原理中我们介绍了基本的NSE知识,这篇文章介绍如何基于Nmap框架编写简单的NSE脚本文件,下一篇文章,Nmap脚本文件分析(AMQP协议 ...

  9. nmap简介和使用

    文章链接:https://blog.csdn.net/m1585761297/article/details/80015726 参考链接:https://www.cnblogs.com/nmap/p/ ...

随机推荐

  1. SQL注入的一些学习

    -------------------------------------- 这是我之前发布到的其他的一个网址,这里的话我重新总结 可能分很多,我也不是很清楚,只是皮毛的研究了一下 1,sql按数据库 ...

  2. Albert学习记录

    albert相对BERT而言主要有三个改进方向: 1.对Embedding因式分解 在BERT中,词向量维度E和隐层维度H是相等的.而词嵌入学习的是单词与上下文无关的表示,而隐层则是学习与上下文相关的 ...

  3. Error response from daemon: conflict: unable to delete a2f2e369e78e (cannot be forced) - image has dependent child images

    错误现象: Error response from daemon: conflict: unable to delete a2f2e369e78e (cannot be forced) - image ...

  4. ansible-palybooks

    ansible-playbooks 如果用模块形式一般有幂等性,如果用shell或者command没有幂等性 playbooks相当于是shell脚本,可以把要执行的任务写到文件当中,一次执行,方便调 ...

  5. Spring Boot 加载application.properties顺序

    1.准备四份application.properties a.项目根目录下config/application.properties ,内容为:  test.user.name = a b.项目根目录 ...

  6. Python彩蛋、字典、列表高级用法、元类、混入、迭代器、生成器、生成式、git

    一.类与类的关系 关注公众号"轻松学编程"了解更多. is-a 继承 继承是指一个类(称为子类.子接口)继承另外一个类(称为父类.父接口)的功能, 并可以增加它自己的新功能的能力. ...

  7. .NET Core如何进行请求转发?

    前言 冒个泡,近日,有关注我公众号的小伙伴私信我,遇到一个问题搞了很久没解决,此问题具有参考意义,这里跟大家分享下,希望对后续可能有需要的你能有所参考和帮助. 请求转发问题 内网环境跟外网隔离,现在外 ...

  8. [Luogu P4147] 玉蟾宫 (网格DP)

    题面 传送门:https://www.luogu.org/problemnew/show/P4147 Solution 裸的求极大子矩阵 感谢wzj dalao的教学 首先,有一个很显然但很重要的结论 ...

  9. leetcode131:letter-combinations-of-a-phone-number

    题目描述 给出一个仅包含数字的字符串,给出所有可能的字母组合. 数字到字母的映射方式如下:(就像电话上数字和字母的映射一样) Input:Digit string "23"Outp ...

  10. C++动态存储方式与静态存储方式

    如果从变量值存在的时间(即生存期)来分,可将程序中的变量分为:动态存储方式和静态存储方式.它们所占用的存储空间区域不同. C++存储空间区域 代码区:存放可执行程序的程序代码.静态存储区:存放静态变量 ...