主机扫描
fping
fping与ping不同的地方在于,fping可以在命令行中指定要ping的主机数量范围,也可以指定含有要ping的主机列表文件。
# fping 192.168.20.152 192.168.2.153
# fping -g 192.168.20.150 192.168.2.153
# fping -a -g 192.168.20.150 192.168.2.153
# fping -g 192.168.20.150 192.168.2.153 2>/dev/null
192.168.2.151 is alive
192.168.2.152 is alive
192.168.2.150 is unreachable
192.168.2.153 is unreachable
hping
官方站点:http://www.hping.org/
1.对指定目标端口发起tcp探测
hping -p 22 -S 192.168.20.151
#可以设置151机器禁ping查看效果: sysctl -w net.ipv4.icmp_echo_ignore_all=1
2.伪造来源IP,模拟Ddos攻击
hping -p 22 -S 192.168.20.151 -a 192.168.20.150
在151机器上开启tcpdump抓取来自攻击源的数据包:
# tcpdump -i eth0 src host 192.168.20.150
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
20:00:23.471610 IP 192.168.20.150.spice > 192.168.20.151.ssh: Flags [S], seq 1309245604:1309245704, win 512, length 100
20:00:24.471781 IP 192.168.20.150.xiip > 192.168.20.151.ssh: Flags [S], seq 1698714277:1698714377, win 512, length 100
20:00:25.472009 IP 192.168.20.150.discovery-port > 192.168.20.151.ssh: Flags [S], seq 1558244712:1558244812, win 512, length 100
20:00:26.472229 IP 192.168.20.150.egs > 192.168.20.151.ssh: Flags [S], seq 317559446:317559546, win 512, length 100
20:00:27.472494 IP 192.168.20.150.videte-cipc > 192.168.20.151.ssh: Flags [S], seq 1828776172:1828776272, win 512, length 100
补充:
tcpdump抓包常用参数和用法
tcpdump tcp -s 0 -i eth0 and host 192.168.20.151 -w /tools/0427.pcap
路由扫描
traceroute
1.traceroute 用法简单、最常用的用法
# traceroute www.baidu.com
2.跳数设置
# traceroute -m 10 www.baidu.com
3.显示IP地址,不查主机名
# traceroute -n www.baidu.com
4.探测包使用的基本UDP端口设置6888
# traceroute -p 6888 www.baidu.com
5.把探测包的个数设置为值4
# traceroute -q 4 www.baidu.com
6.绕过正常的路由表,直接发送到网络相连的主机
# traceroute -r www.baidu.com
7.把对外发探测包的等待响应时间设置为3秒
# traceroute -w 3 www.baidu.com
mtr
测试到目标主机 example.com 的流量的路由和连接质量: mtr -rw example.com
如果没有丢包丢失,可以使用更快的间隔时间运行:mtr -rwc 50 -i 0.2 example.com
批量主机服务扫描
nmap
NMap,也就是Network Mapper,是Linux下的网络扫描和嗅探工具包。包含四项基本功能:
主机发现(Host Discovery)
-sP :进行ping扫描
# nmap -sP 192.168.20.0/24//打印出对ping扫描做出响应的主机,不做进一步测试(如端口扫描或者操作系统探测)可以用于探测局域网有哪些机器
-sn: Ping Scan - disable port scan
# nmap -sn 192.168.20.0/24
-sA:发送tcp的ack包进行探测,可以探测主机是否存活
# nmap -sA 192.168.20.0/24
端口扫描(Port Scanning)
# nmap 192.168.20.215
# nmap 192.168.20.215 -p 1-65535//区别在于不加-p 时,显示的都是已知协议的端口,对于未知协议的端口没显示
# nmap 192.168.20.215 -p 1-100,27017,27018//连续的端口可以使用横线连起来,端口之间可以使用逗号隔开
# nmap -sU 192.168.20.215//对于udp端口扫描比较慢
-sU:表示udp scan , udp端口扫描
-Pn:不对目标进行ping探测(不判断主机是否在线)(直接扫描端口)
版本侦测(Version Detection)
# nmap -sV 192.168.20.215
Starting Nmap 5.51 ( http://nmap.org ) at 2018-04-21 13:48 CST
Nmap scan report for 192.168.20.215
Host is up (0.00046s latency).
Not shown: 998 closed ports
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.4 (protocol 2.0)
80/tcp open http Apache httpd 2.4.6 ((CentOS))
MAC Address: 00:0C:29:A5:9D:95 (VMware)
Service detection performed. Please report any incorrect results at http://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 6.24 seconds
操作系统侦测(Operating System Detection)
# nmap -O 192.168.20.215