nmap 端口扫描/arp/ping,获取ssh服务器的ip地址/ nc / telnet

nmap可以用来扫描端口,也可以用来发现主机:

如果在局域网中你只知道某个设备的mac地址,需要找到对应的ip地址,可以通过 arp 或者 nmap 扫描来实现。

arp -na			//显示 ARP cache(保存mac地址和ip的mapping),必须同一个网段,如果用虚拟机桥接则不行(缓存的,如果某个ip没有出现,先ping一下就再查看可以了).
// 如果 arp cache 中不包含你的ip地址,可以 ping 一下广播地址,eg: ping -b 192.168.1.255  关于ping广播地址(已经废弃),见下文分析。也可以用nmap -sn 来 ping 所有地址(good), 然后再查看arp caceh.


sudo nmap -sn 192.168.1.*	// == 老版本的 -sP; 相当于 ping 所有的地址,不扫描端口。
// 如果要查找端口,可以man nmap,查看 Host Discovery 部分,-PS/PA/PU 选项。
sudo nmap -PS 192.168.1.11	// tcp单次握手连接扫描,获取端口开放信息,mac地址等,需要root权限。同 Port Scanning Techniques 部分的 -sS 选项。

// 查看 mac 地址,先 ping 一下,然后再 arp -n:
 guowei@guowei-pc:~$ ping -c 1 192.168.1.103 > /dev/null
 guowei@guowei-pc:~$ arp -n 192.168.1.103
 Address                  HWtype  HWaddress           Flags Mask            Iface
 192.168.1.103            ether   08:00:46:d4:1d:82   C                     eth0

关于 ping 广播地址(已经不适用了):

255.255.255.255 is a broadcast address, you are sending a ping to every device on your local network and you will get a reply from every device. The ping command is only showing the first reply it gets, in your case your own PC (127.0.0.1 is loopback) was the quickest. If you use a packet sniffer (like Wireshark) you will be able to see all replies.

Some devices will reply to a normal ping but will not reply to a ping sent to a broadcast address. This is to prevent an exploit called a Smurf attack.

255.255.255.255 will also broadcast to every device on the internet. For obvious reason this is blocked, the message will not leave your local network.

But, every modern operating system trends to ignores broadcasts pings as a security measure to avoid broadcast storms.(所以ping广播地址不实用)

注意:不同的参数对扫描时间和扫描结果有影响,可以尝试不同的参数组合(sudo nmap -PS -p22 --open 10.10.40.1/24),不过记得加上sudo,不然由于nmap不能发送raw package而可能探测不到主机。一般探测都要指定扫描某些特定端口(ssh 22,http 80等),不然会很费时间。

注意,nmap不要求目标机器在同一个网段,但是这样就不能得到目标主机的mac地址,例如虚拟机NAT模式扫描。如果在同一个网段(或者桥接模式),则能够得到更多信息(mac地址,vendor名称等等)

几个常用命令(运行nmap - -help):

// ICMP echo scanning,就是 ping 所有的ip地址。
sudo nmap -sn 192.168.1.*		// ==老版本的-sP; 即 Ping scan, diable port scan,快速找到主机.

see link: https://nmap.org/book/man-host-discovery.html

// TCP SYN scan(tcp三次握手中,握手一次就马上断开),-p 指定端口,--open只显示打开的端口;快速找允许tcp连接的并且打开22端口的主机,ssh登陆用。注:TCP SYN 扫描需要root权限。
sudo nmap -sS -p22 --open 192.168.1.*

// 如果要测试tcp三次握手成功,使用 -sT,且不需要root权限。
nmap -sT -p22 --open 192.168.1.*

see link: https://nmap.org/nmap_doc.html#syn

nmap各个参数的功能:

HOST DISCOVERY 部分:
-sn : 就是ping scan,不扫描端口,快速。
-PS/PA/PU/PY[portlist]: TCP SYN/ACK, UDP or SCTP discovery to given ports。

SCAN TECHNIQUES 部分:
-sS : TCP SYN scan(又称半开放,或隐身扫描,即tcp握手一次马上断开)
-sT : TCP connect scan(完成tcp的三次握手)192.168.1.* 或者  192.168.1.1/24
-p 22 : specifies the port to scan, ssh 端口默认为22
--open : suppress output for clients that are not listening
-F : Fast mode - Scan fewer ports than the default scan
-sV : Probe open ports to determine service/version info
-sP : Check which hosts are live and up in Network, with this option nmap skips port detection and other things, its fast.

关于各种nmap扫描类型:

  • ICMP Echo (TCP/IP Ping)
  • ARP Request
  • TCP SYN Ping
  • TCP ACK Ping
  • UDP Ping
  • Combination

各种扫描类型的介绍 和 nmap manual:
https://www.linux.org/threads/nmap-ping-commands.4553/
https://nmap.org/book/man.html



nc (nectcat)
nc [options] host port

nc -vzw 5 192.168.1.5 8080   # 用于测试 tcp 连接,端口是否 open
-v – enables verbose mode.
-z – sets nc to simply scan for listening daemons, without actually sending any data to them.
-w timeout sec
-n donnot resolve DNS, just use the ip address

nc -vuz 10.0.1.161 9998  # 测试 udp 连接
nc -z -n -v 198.51.100.0 1-1000  # 端口扫描

telnet
telnet host port

telnet ip port  # telnet 只能用户测试 tcp 连接
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值