1. 程式人生 > >弱口令檢測、端口掃描

弱口令檢測、端口掃描

Linux弱口令安全檢測 NMAP掃描端口 破解密碼與密碼字典

前言:在inter環境中,過於簡單的口令是服務器面臨的最大風險。對於任何一個承擔這安全責任的管理員,及時找出這些弱口令是非常必要的,這樣便於采取進一步的安全措施,

使用John the Ripper 檢測Linux、Unix系統用戶的密碼強度,使用NMAP掃描端口,可以找出網絡中不可控的應用服務,及時關閉不安全的服務,減小安全風險。


1、弱口令探測(john the ripper

1)下載並安裝:官方網站是http://openwall.com/john/,在該網站可以獲取最新的穩定版源碼包

現在解壓安裝



[root@localhost ~]# mount /dev/cdrom /media/                
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# cd /media/
[root@localhost media]# ls
john-1.8.0.tar.tar
[root@localhost media]# tar zxf john-1.8.0.tar.tar -C /usr/src/
[root@localhost media]# cd /usr/src/john-1.8.0/
[root@localhost john-1.8.0]# cd src/
[root@localhost src]# pwd
/usr/src/john-1.8.0/src
[root@localhost src]# make clean linux-x86-64
......省略編譯信息
[root@localhost src]# ls ../run/john                        //確定已生成可執行程序john
../run/john

John the Ripper 不需要特別的安裝操作,編譯完成後的run子目錄中包括可執行程序John及相關配置文件、字典文件等,可以復制到任何位置使用。

2)檢測弱口令

[root@localhost src]# cp /etc/shadow /root/shadow.txt            //準備待破解的密碼文件
[root@localhost src]# cd ../run
[root@localhost run]# ./john /root/shadow.txt                    //執行暴力破解
0g 0:00:00:42 86% 1/3 0g/s 168.7p/s 168.7c/s 168.7C/s root9999900000..Root000000
0g 0:00:00:43 89% 1/3 0g/s 168.6p/s 168.6c/s 168.6C/s user1555555..u999991982
0g 0:00:00:47 94% 1/3 0g/s 168.6p/s 168.6c/s 168.6C/s 999992010..r999991955
123456           (zhangsan)
123456           (root)
123456           (user1)                   
......省略部分
......//按Ctrl+C組合鍵終止後續過程
[root@localhost run]# ./john --show /root/shadow.txt             //查看已破解出的賬戶列表
root:123456:17552:0:99999:7::: 
zhangsan:123456:17591:0:30:7:::
user1:123456:17592:0:99999:7:::

3 password hashes cracked, 0 left

3)使用密碼字典文件破解,默認的字典文件為password.lst

對於密碼的暴力破解,字典文件的選擇很關鍵。只要字典文件足夠完整,密碼破解只是時間問題,

[root@localhost run]# :>john.pot                    //清空已破解出的賬戶列表,以便重新分析
[root@localhost run]# ./john --show /root/shadow.txt 
0 password hashes cracked, 3 left
[root@localhost run]# passwd user1                  //修改強密碼pwd@123
更改用戶 user1 的密碼 。
新的 密碼:
重新輸入新的 密碼:
passwd: 所有的身份驗證令牌已經成功更新。
[root@localhost run]# vim password.lst              //將pwd@123寫入密碼字典裏
123456
12345
pwd@123                 //需要新添加

執行破解(破解之前需要重新拷貝shadow文件)

[root@localhost run]# cp /etc/shadow /root/shadow.txt 
cp:是否覆蓋"/root/shadow.txt"? y
[root@localhost run]# ./john --wordlist=./password.lst /root/shadow.txt 
Loaded 3 password hashes with 3 different salts (crypt, generic crypt(3) [?/64])
Press 'q' or Ctrl-C to abort, almost any other key for status
123456           (zhangsan)
pwd@123          (user1)
123456           (root)
3g 0:00:00:01 100% 1.886g/s 60.37p/s 181.1c/s 181.1C/s 123456..pamela
Use the "--show" option to display all of the cracked passwords reliably
Session completed

2、網絡掃描(NMAP

NMAP是一個強大的端口掃描類安全評測工具,官方網站是http://nmap.org/ NMAP被設計為檢測主機數量眾多的巨大網絡,支持ping掃描、多端口檢測、OS識別等多種技術

1安裝NMAP包

[root@localhost ~]# mount /dev/cdrom /media/
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# cd /media/
[root@localhost media]# ls
nmap-7.60-1.x86_64.rpm
[root@localhost media]# 
[root@localhost media]# rpm -ivh nmap-7.60-1.x86_64.rpm 
Preparing...                ########################################### [100%]
   1:nmap                   ########################################### [100%]


2)、掃描語法及類型

nmap [掃描類型] [選項] [掃描目標...]
其中,掃描目標可以是主機名、IP地址或網絡地址等,多個目標以空格分割;常用的選項有“-p”、“-n”,分別用來指定掃描的端口、禁用反向DNS解析(以加快掃描速度);
掃描類型決定這檢測的方式,也直接影響掃描的結果。
比較常用的幾種掃描類型如下:
NMAP的掃描語法
nmap  [掃描類型]  [選項]  <掃描目標 ...>
常用的掃描類型
-sS,TCP SYN掃描(半開)
-sT,TCP 連接掃描(全開)
-sF,TCP FIN掃描
-sU,UDP掃描
-sP,ICMP掃描
-P0,跳過ping檢測

3)針對本機進行掃描,檢查開放了哪些常用的tcp端口,udp端口



[root@localhost ~]# nmap 127.0.0.1                             //掃描常用的TCP端口
Starting Nmap 7.60 ( https://nmap.org ) at 2018-03-03 00:34 CST
mass_dns: warning: Unable to determine any DNS servers. Reverse DNS is disabled. Try using --system-dns or specify valid servers with --dns-servers
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000010s latency).
Not shown: 996 closed ports
PORT    STATE SERVICE
22/tcp  open  ssh
25/tcp  open  smtp
111/tcp open  rpcbind
631/tcp open  ipp
Nmap done: 1 IP address (1 host up) scanned in 0.20 seconds

4)掃描常用的udp端口
[root@localhost ~]# nmap -sU 127.0.0.1                        //掃描常用的UDP端口

Starting Nmap 7.60 ( https://nmap.org ) at 2018-03-03 00:35 CST
mass_dns: warning: Unable to determine any DNS servers. Reverse DNS is disabled. Try using --system-dns or specify valid servers with --dns-servers
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000028s latency).
Not shown: 997 closed ports
PORT    STATE         SERVICE
111/udp open          rpcbind
631/udp open|filtered ipp
780/udp open|filtered wpgs

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

在掃描結果中,STATE列若為open則表示端口為開放狀態,為filtered表示為可能被防火墻過濾,為closed表示端口為關閉狀態。

[root@localhost ~]# nmap -p 21 192.168.1.0                  //檢查哪些主機提供FTP服務
Starting Nmap 7.60 ( https://nmap.org ) at 2018-03-03 00:40 CST
mass_dns: warning: Unable to determine any DNS servers. Reverse DNS is disabled. Try using --system-dns or specify valid servers with --dns-servers
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 0.57 seconds


[root@localhost ~]# nmap -p 21 192.168.1.0                  //檢查網段中哪些存活主機(能ping通)

Starting Nmap 7.60 ( https://nmap.org ) at 2018-03-03 00:42 CST
mass_dns: warning: Unable to determine any DNS servers. Reverse DNS is disabled. Try using --system-dns or specify valid servers with --dns-servers
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 0.57 seconds
[root@localhost ~]# nmap -p 139,455 192.168.1.1-100           //檢查192.168.1.1-100主機是否開啟共享服務
Starting Nmap 7.60 ( https://nmap.org ) at 2018-03-03 00:43 CST
mass_dns: warning: Unable to determine any DNS servers. Reverse DNS is disabled. Try using --system-dns or specify valid servers with --dns-servers
Nmap scan report for 192.168.1.1
Host is up (0.00024s latency).
PORT    STATE  SERVICE
139/tcp closed netbios-ssn
455/tcp closed creativepartnr
Nmap scan report for 192.168.1.12
Host is up (0.00016s latency).
PORT    STATE  SERVICE
139/tcp open   netbios-ssn
455/tcp closed creativepartnr
MAC Address: 00:50:56:C0:00:08 (VMware)
Nmap done: 100 IP addresses (2 hosts up) scanned in 1.99 seconds


弱口令檢測、端口掃描