Linux – nmap – nc(ncat) 命令 – 扫描端口

nmap、ncat/nc既是一个端口扫描工具,也是一款安全工具,还能是一款监测工具

安装nmap

centOS安装

yum install -y nmap

debian安装

pkg install nmap -y

namp使用

[root@VM-4-12-centos ~]# nmap --help
Nmap 6.40 ( http://nmap.org )
Usage: nmap [Scan Type(s)] [Options] {target specification}
TARGET SPECIFICATION:
  可以传递主机名、IP地址、网络等。
  例如:scanme.nmap.org, microsoft.com/24, 192.168.0.1; 10.0.0-255.1-254
  -iL <inputfilename>: 来自主机/网络列表的输入
  -iR <num hosts>: 选择随机目标
  --exclude <host1[,host2][,host3],...>: 排除 hosts/networks
  --excludefile <exclude_file>: 从文件中排除列表

HOST DISCOVERY:
  -sL: List Scan - 只需列出要扫描的目标
  -sn: Ping Scan - 禁用端口扫描
  -Pn: Treat all hosts as online -- 跳过主机发现
  -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>: 仅扫描指定的端口
    Ex: -p22; -p1-65535; -p U:53,111,137,T:21-25,80,139,8080,S:9
  -F: Fast mode - 扫描比默认扫描更少的端口
  -r: Scan ports consecutively - 不要随机化
  --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 separted 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
  --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)
  --log-errors: Log errors/warnings to the normal-format output file
  --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.
例如:
  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
参见手册页 (http://nmap.org/book/man.html) 有关更多选项和示例

扫描全部端口

nmap IPv4 -p 端口/(端口-端口)

试验结果

> namp XXX.XXX.XXX.XXX -p 8080-8085
Nmap scan report for XXX.XXX.XXX.XXX
Host is up (0.00024s latency).
PORT     STATE    SERVICE
8080/tcp filtered http-proxy
8081/tcp filtered blackice-icecap
8082/tcp closed   blackice-alerts
8083/tcp closed   us-srv
8084/tcp filtered unknown
8085/tcp filtered unknown

nc命令

安装nc – ncat命令

yum -y nc

或者
yum install nmap-ncat -y

nc命令详解

[root@VM-4-12-centos ~]# nc --help
Ncat 7.50 ( https://nmap.org/ncat )
Usage: ncat [options] [hostname] [port]

Options taking a time assume seconds. Append 'ms' for milliseconds,
's' for seconds, 'm' for minutes, or 'h' for hours (e.g. 500ms).
  -4                         仅仅使用IPv4
  -6                         仅仅使用IPv6
  -U, --unixsock             Use Unix domain sockets only
  -C, --crlf                 Use CRLF for EOL sequence
  -c, --sh-exec <command>    Executes the given command via /bin/sh
  -e, --exec <command>       Executes the given command
      --lua-exec <filename>  Executes the given Lua script
  -g hop1[,hop2,...]         Loose source routing hop points (8 max)
  -G <n>                     Loose source routing hop pointer (4, 8, 12, ...)
  -m, --max-conns <n>        Maximum <n> simultaneous connections
  -h, --help                 Display this help screen
  -d, --delay <time>         Wait between read/writes
  -o, --output <filename>    Dump session data to a file
  -x, --hex-dump <filename>  Dump session data as hex to a file
  -i, --idle-timeout <time>  空闲读/写超时
  -p, --source-port port     指定要使用的源端口
  -s, --source addr          指定要使用的源地址(不影响-l)
  -l, --listen               Bind and listen for incoming connections
  -k, --keep-open            Accept multiple connections in listen mode
  -n, --nodns                Do not resolve hostnames via DNS
  -t, --telnet               Answer Telnet negotiations
  -u, --udp                  使用UDP而不是默认TCP
      --sctp                 Use SCTP instead of default TCP
  -v, --verbose              设置详细级别(可多次使用)
  -w, --wait <time>          连接超时
  -z                         Zero-I/O mode, report connection status only
      --append-output        Append rather than clobber specified output files
      --send-only            Only send data, ignoring received; quit on EOF
      --recv-only            Only receive data, never send anything
      --allow                Allow only given hosts to connect to Ncat
      --allowfile            A file of hosts allowed to connect to Ncat
      --deny                 Deny given hosts from connecting to Ncat
      --denyfile             A file of hosts denied from connecting to Ncat
      --broker               Enable Ncat's connection brokering mode
      --chat                 Start a simple Ncat chat server
      --proxy <addr[:port]>  Specify address of host to proxy through
      --proxy-type <type>    Specify proxy type ("http" or "socks4" or "socks5")
      --proxy-auth <auth>    Authenticate with HTTP or SOCKS proxy server
      --ssl                  Connect or listen with SSL
      --ssl-cert             Specify SSL certificate file (PEM) for listening
      --ssl-key              Specify SSL private key (PEM) for listening
      --ssl-verify           Verify trust and domain name of certificates
      --ssl-trustfile        PEM file containing trusted SSL certificates
      --ssl-ciphers          Cipherlist containing SSL ciphers to use
      --version              Display Ncat's version information and exit
特殊说明: 以上文章,均是我实际操作,写出来的笔记资料,不会盗用别人文章!烦请各位,请勿直接盗用!转载记得标注来源!
<think>好的,我现在要解决用户关于如何在Linux上安装nc(netcat)命令的问题。首先,我需要确认用户可能的需求是什么。通常,用户遇到“nc命令未找到”的错误,说明系统没有安装netcat。我的任务是引导他们正确安装。 首先,我得考虑不同的Linux发行版,因为安装命令可能不同。常见的发行版有Debian/Ubuntu、CentOS/RHEL、Fedora、Arch Linux等。我需要分别列出这些系统的安装方法。 对于基于Debian的系统,比如Ubuntu,应该使用apt-get命令。需要提醒用户更新软件包列表,然后安装netcat-openbsd或者netcat-traditional。这里可能需要解释这两个版本的区别,但用户可能只需要基本的nc功能,所以推荐netcat-openbsd。 接下来是CentOS或RHEL系统,使用yum或dnf。这里需要注意,CentOS 8之后可能使用dnf,而旧版用yum。同时,安装的软件包名称是nmap-ncat,可能需要确认是否正确,因为有时候包名可能不同。 对于Fedora,使用dnf install nc或者nmap-ncat,同样需要确认包名是否正确。Arch Linux用户则使用pacman来安装gnu-netcat。 另外,可能需要提醒用户安装后如何验证,比如运行nc -h或者man nc来查看帮助文档。还有可能需要说明不同版本netcat的功能差异,比如OpenBSD版本和传统版本的不同参数,但用户可能暂时不需要深入这些细节。 还要检查是否有拼写错误,比如包名是否正确,命令是否正确。例如,是否在安装前需要sudo权限,这点要明确写出,避免用户权限不足的问题。同时,提示用户如果遇到问题,可以尝试搜索对应的软件包,比如使用apt search netcat来查找正确的包名。 最后,确保步骤清晰,分点列出,让用户容易跟随。可能还需要在最后给出一个验证安装成功的步骤,比如执行nc -h查看版本信息。如果有常见问题,比如安装后仍然找不到命令,可能需要提示检查路径或者是否存在多个版本冲突,但根据问题复杂度,可能不需要深入,除非用户进一步询问。</think>在Linux系统中安装`nc`(netcat)命令的步骤如下: --- ### 1. **确认系统发行版** 首先确定你的Linux发行版类型,不同发行版的安装命令可能不同: - **Debian/Ubuntu**:使用 `apt` 包管理器 - **CentOS/RHEL**:使用 `yum` 或 `dnf` 包管理器 - **Fedora**:使用 `dnf` - **Arch Linux**:使用 `pacman` --- ### 2. **安装netcat** 根据发行版选择对应的命令: #### **Debian/Ubuntu** ```bash sudo apt update sudo apt install netcat-openbsd # 推荐安装OpenBSD版本(常用) # 或 sudo apt install netcat-traditional # 传统版本(功能更多但语法不同) ``` #### **CentOS/RHEL 7及以下** ```bash sudo yum install nc # 或安装nmap-ncat(功能更全) sudo yum install nmap-ncat ``` #### **CentOS/RHEL 8+ 或 Fedora** ```bash sudo dnf install nc # 或 sudo dnf install nmap-ncat ``` #### **Arch Linux** ```bash sudo pacman -S gnu-netcat ``` --- ### 3. **验证安装** 安装完成后,检查是否成功: ```bash nc -h # 或查看版本 nc -v ``` --- ### 4. **常见问题** - **找不到包名**:尝试搜索软件包: ```bash apt search netcat # Debian/Ubuntu dnf search netcat # CentOS/Fedora ``` - **权限问题**:确保使用 `sudo` 提权。 - **版本差异**:不同发行版的 `nc` 功能可能略有差异,可通过 `man nc` 查看文档。 --- ### 5. **基本使用示例** ```bash # 监听端口(服务端) nc -lvnp 1234 # 连接到服务端(客户端) nc 127.0.0.1 1234 ``` 通过以上步骤即可完成安装并使用 `nc` 命令
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值