天天看點

Linux掃描技術筆記

Linux掃描技術筆記

題記:

主機節點的存活的探測方法,我們日常用的最多的是ping,除此之外還有沒有其他方法?本文介紹了fping,hping相關操作以探測節點存活。

服務的存活,我們日常用的最多的是telnet,除此之外還有沒有其他方法?本文介紹了nmap,ncat對于服務存活的探測。

此外,本文還介紹了批量主機節點掃描,批量服務端口存活掃描,以及路由掃描以及安全防範措施。

0.網絡安全技術

1)資料真實、可靠、完整、可控(安全角度)。

舉例:擷取公用裝置的弱密碼

擷取常用指令:

tracert/traceroute //查詢到目的位址的路由跳數。

nmap //批量主機服務的掃描,擷取開放的端口(如80,23,22等)

嘗試暴力破解,如:

http://10.202.4.73

(admin/admin)

nc //進行互動式的shell登入

2)網絡入侵方式

踩點–網絡掃描–查點–提權 等

一.主機掃描

常用指令:

1)fping

特點:并行發送(批量主機發送)

2)hping

源碼包編譯步驟:

1)檢測配置 ./configure Makefile

2)編譯 make 二進制可執行檔案

3)安裝 make install 安裝到指定的路徑

以下是fping安裝好後的版本:

[root@localhost fping-3.13]# fping -v

fping: Version 3.13

fping: comments to [email protected]

1.fping參數介紹:

1)man -h 參數 檢視幫助

2)

-a 隻顯示存活的主機清單

-u 隻顯示沒有存活的主機

-g 支援主機段

-f 從檔案中讀取

example:

[root@localhost fping-3.13]# fping -a -g 114.114.114.1/24

114.114.114.110

114.114.114.114

114.114.114.119

1

2

3

4

fping -a -f ./ip_list.txt

fping -u -f ./ip_list.txt

2.hping主機掃描

1)特定端口發起tcp探測

-p 端口

-s 設定tcp模式的SYN包

寫入核心如下的參數可以進制icmp的通路:

sysctl -w net.ipv4.icmp_echo_ignore_all=1

//在即使主機禁止ping的前提下,依然可以使用hping指令探測端口的存活。

[root@localhost hping-master]# hping -p 135 -S 192.168.1.107

HPING 192.168.1.107 (eth0 192.168.1.107): S set, 40 headers + 0 data bytes

len=46 ip=192.168.1.107 ttl=64 DF id=841 sport=135 flags=SA seq=0 win=8192 rtt=2.7 ms

len=46 ip=192.168.1.107 ttl=64 DF id=1121 sport=135 flags=SA seq=1 win=8192 rtt=0.9 ms

len=46 ip=192.168.1.107 ttl=64 DF id=1374 sport=135 flags=SA seq=2 win=8192 rtt=0.8 ms

len=46 ip=192.168.1.107 ttl=64 DF id=1777 sport=135 flags=SA seq=3 win=8192 rtt=0.9 ms

5

6

2)僞造來源IP,模拟DDOS攻擊

二.路由掃描

作用:查詢到一個主機到另一個主機的跳數及延時。

指令:

1)traceroute;

2)mtr(測試主機到路由的連通性)

traceroute原理:預設30000端口以上的UDP資料包。

traceroute 參數:

-T tcp資料包

-P 端口

-I(大寫的i) icmp資料包

-n 不将IP位址解析為域名

舉例:

【方式一】:預設UDP方式通路。

[root@localhost hping-master]# traceroute www.baidu.com

traceroute to www.baidu.com (61.135.169.125), 30 hops max, 60 byte packets

1  192.168.1.1 (192.168.1.1)  3.377 ms  2.129 ms  3.747 ms

2  112.237.12.1 (112.237.12.1)  3.658 ms  3.287 ms  3.295 ms

3  221.0.68.245 (221.0.68.245)  8.835 ms  8.374 ms 221.0.68.45 (221.0.68.45)  6.011 ms

4  218.56.4.65 (218.56.4.65)  22.628 ms  22.172 ms  21.733 ms

5  219.158.98.229 (219.158.98.229)  28.242 ms 219.158.98.225 (219.158.98.225)  24.119 ms 219.158.96.33 (219.158.96.33)  27.358 ms

6  124.65.194.158 (124.65.194.158)  26.988 ms  27.691 ms  30.738 ms

7  124.65.59.166 (124.65.59.166)  60.235 ms  59.844 ms  59.422 ms

8  61.49.168.78 (61.49.168.78)  24.938 ms 61.49.168.82 (61.49.168.82)  23.435 ms 61.49.168.78 (61.49.168.78)  22.323 ms

9  * * *

10  * * *

11  * * *

12  * * *

13  * * *

14  * * *

15  * * *

16  * * *

17  * * *

18  * * *

19  * * *

20  * * *

21  * * *

22  * * *

23  * * *

24  * * *

25  * * *

26  * * *

27  * * *

28  * * *

29  * * *

30  * * *

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

//【方式二】 ICMP方式通路。

[root@localhost hping-master]# traceroute -I -n www.baidu.com

1  192.168.1.1  1.962 ms  2.268 ms  1.985 ms

2  112.237.12.1  3.588 ms  4.704 ms  4.505 ms

3  221.0.68.21  6.415 ms  6.062 ms  5.797 ms

4  218.56.4.65  22.058 ms  21.805 ms  21.701 ms

5  219.158.96.29  21.344 ms  21.184 ms  21.016 ms

6  124.65.194.158  26.865 ms  26.571 ms  26.289 ms

7  124.65.59.166  19.953 ms  24.586 ms  24.241 ms

8  61.49.168.78  23.946 ms  22.079 ms  21.584 ms

10  61.135.169.125  20.379 ms  22.970 ms  21.124 ms

//【方式三】TCP方式通路。

[root@localhost hping-master]# traceroute -T -p 80 -n www.baidu.com

1  192.168.1.1  10.428 ms  3.382 ms  3.105 ms

2  * * *

3  221.0.68.245  6.938 ms  6.462 ms 221.0.68.21  5.914 ms

4  * * *

5  219.158.96.33  29.864 ms 219.158.96.29  23.532 ms 219.158.96.37  23.160 ms

6  124.65.194.158  32.945 ms  32.642 ms  32.350 ms

7  124.65.59.166  24.625 ms  23.980 ms  25.939 ms

8  * * *

10  61.135.169.125  22.750 ms  22.076 ms *

通過nslooup 反查是可以得到www.baidu.com對應的IP位址61.135.169.125的。

結論:

traceroute以TCP或者ICMP的通路方式,是可以通路到目的網站的IP位址的。預設的UDP包則 不可以。

mtr指令舉例:

Mtr是 Linux中有一個非常棒的網絡連通性判斷工具,它結合了ping, traceroute,nslookup 的相關特性。

[root@localhost hping-master]# mtr www.baidu.com

                                                             My traceroute  [v0.75]

localhost.localdomain (0.0.0.0)                                                                                           Sat Nov 28 02:01:35 2015

Keys:  Help   Display mode   Restart statistics   Order of fields   quit

                                                                                                         Packets               Pings

Host                     Loss%   Snt   Last   Avg  Best  Wrst StDev

1. 192.168.1.1           0.0%    32    3.8   4.3   2.1  11.1   1.5

2. 112.237.12.1          0.0%    32    3.8   4.5   2.8  11.3   1.6

3. 221.0.68.21           0.0%    32    9.5   7.9   3.5  13.7   2.3

4. 218.56.4.65           0.0%    32   23.8  23.3  21.5  25.5   1.1

5. 219.158.98.221        0.0%    32   25.0  25.8  21.4  70.3   8.3

6. 124.65.194.166        0.0%    31   31.6  29.0  25.1  32.9   2.1

7. 124.65.58.62          0.0%    31   24.6  29.0  19.9  53.3  10.8

8. 123.125.248.46        0.0%    31   23.2  22.7  19.6  29.0   2.0

9. ???

10. ???

11. 61.135.169.121        0.0%    31   22.8  23.1  20.3  25.9   1.5

三.批量服務掃描

作用:

1)快捷擷取主機的存活狀态;

2)擷取主機服務的偵查狀态。

典型指令:

1)nmap

2)ncat(号稱瑞士軍刀)

1)nmap指令使用介紹:

nmap預設掃描的端口範圍(0-1024,以及常用服務端口)

nmap -p 0-30000

1)ICMP協定類型(-P) ping掃描 簡單、快速、有效 用于掃描主機存活

2)TCP SYN類型 (-sS) 半開放連接配接 1.高效,2.不易被檢測,3.通用

3)TCP connect類型(-sT) 全開放連接配接 1.模拟真實使用者的請求,2結果可靠

4)UDP掃描(-sU) UDP協定掃描 1比較慢,2有效透過防火牆政策

[root@localhost nmap-7.00]# nmap -sP 192.168.119.0/24

Starting Nmap 7.00 (

https://nmap.org

) at 2015-11-28 02:25 PST

Warning: File ./nmap-payloads exists, but Nmap is using /usr/local/bin/../share/nmap/nmap-payloads for security and consistency reasons.  set NMAPDIR=. to give priority to files in your local directory (may affect the other data files too).

Nmap scan report for 192.168.119.1

Host is up (0.00038s latency).

MAC Address: 00:50:56:C0:00:08 (VMware)

Nmap scan report for 192.168.119.2

Host is up (0.00013s latency).

MAC Address: 00:50:56:EC:C8:54 (VMware)

Nmap scan report for 192.168.119.254

Host is up (0.00011s latency).

MAC Address: 00:50:56:E0:02:E6 (VMware)

Nmap scan report for 192.168.119.128

Host is up.

Nmap done: 256 IP addresses (4 hosts up) scanned in 2.01 seconds

[root@localhost nmap-7.00]# nmap -sS 192.168.119.1

) at 2015-11-28 02:27 PST

Warning: File ./nmap-services exists, but Nmap is using /usr/local/bin/../share/nmap/nmap-services for security and consistency reasons.  set NMAPDIR=. to give priority to files in your local directory (may affect the other data files too).

Host is up (0.00021s latency).

Not shown: 987 closed ports

PORT      STATE SERVICE

80/tcp    open  http

135/tcp   open  msrpc

139/tcp   open  netbios-ssn

445/tcp   open  microsoft-ds

902/tcp   open  iss-realsecure

912/tcp   open  apex-mesh

1025/tcp  open  NFS-or-IIS

1026/tcp  open  LSA-or-nterm

1027/tcp  open  IIS

1028/tcp  open  unknown

1038/tcp  open  mtqp

5678/tcp  open  rrac

10000/tcp open  snet-sensor-mgmt

Nmap done: 1 IP address (1 host up) scanned in 1.39 seconds

2)ncat工具使用(端口掃描,預設TCP)

ncat -w 設定逾時時間

-z 輸入輸出模式

-v 顯示執行過程

-u 代表UDP

[root@localhost ~]# ncat -v -w2 202.118.66.66 80

Ncat: Version 7.00 (

https://nmap.org/ncat

)

Ncat: Connected to 202.118.66.66:80.

四.如何防範惡意掃描

常見的攻擊方法:

1)SYN攻擊——

利用TCP協定缺陷,導緻系統服務停止響應,網絡帶寬跑慢或者響應緩慢。

2)DDOS攻擊——

分布式拒絕通路服務攻擊。

正常的服務同一時間接收到N多類似正常服務的通路。

3)惡意掃描

SYN類型的DDOS攻擊預防

方式一:減少發送syn+ack包重發次數

sysctl -w net.ipv4.tcp_synack_retries=3

sysctl -w net.ipv4.tcp_syn_retries=3

方式二:SYN cookies技術(不建立三次握手)

sysctl -w net.ipv4.syncookies=1

方式三:增加backlog隊列

sysctl -w net.ipv4.tcp_max_syn_backlog=2048

Linux 下其他預防政策

政策1:如何關閉ICMP協定請求

sysctrl -w net.ipv4.icmp_echo_ignore_all=1

政策2:通過iptables防止掃描

iptables -A FORWARD -p tcp -syn -m limit -limit 1/s -limit-burst 5 -j ACCEPT

iptables -A FORWARD -p tcp -tcp-flags SYN,ACK,FIN,RST RST -m limit -limit 1/s -j ACCEPT

iptables -A FORWARD -p icmp -icmp-type echo-request -m limit -limit 1/s -j ACCEPT

以下連結可以學習:

http://www.cnblogs.com/ym123/category/697304.html

繼續閱讀