基于python實(shí)現(xiàn)弱密碼檢測(cè)工具
一、引用的python模塊
Crypto:
Python中一個(gè)強(qiáng)大的加密模塊,提供了許多常見(jiàn)的加密算法和工具。它建立在pyc.ypodome或pyc.ypto等底層加密庫(kù)之上,為Python程序員提供了簡(jiǎn)單易用的API,使其可以輕松地實(shí)現(xiàn)各種加密功能。
commands:
commands 模塊是 Python 的內(nèi)置模塊,它主要有三個(gè)函數(shù):
FUNCTIONS
getoutput(cmd)
Return output (stdout or stderr) of executing cmd in a shell.getstatus(file)
Return output of "ls -ld <file>" in a string.getstatusoutput(cmd)
Return (status, 'output) of executing cmd in a shell.
SYS: 基礎(chǔ)系統(tǒng)模塊
sys模塊是與python解釋器交互的一個(gè)接口。sys 模塊提供了許多函數(shù)和變量來(lái)處理 Python 運(yùn)行時(shí)環(huán)境的不同部分。
二、實(shí)現(xiàn)過(guò)程
python腳本如下:
import crypt
import commands
import sys
def testPass(user,cryptPass,ipaddr):
#dictfile=open('dictionary.txt','r')
start_index=cryptPass.find("$")
finish_index=cryptPass.rfind("$")
salt=cryptPass[start_index:finish_index+1]
dictfile=open('/root/dict.txt','r')
pwd_suffix = ['','.','..','!','!@#','1','123','1234','12345','123456','888','666','999','2006','2007','2008','2009','2010','2011','2012','2013','2014','2015','2016','2017','2018','2019']
for sfx in pwd_suffix:
#print user+sfx
for separator in ['','@','#','&']:
cryptWord=crypt.crypt('%s%s%s'%(user,separator,sfx),salt)
if cryptWord==cryptPass:
#print ipaddr + " [+] Found Password: " +user+'/'+user+sfx+ " \n"
print '%s [+] Found Passwd: %s/%s%s%s \n'%(ipaddr,user,user,separator,sfx)
break
cryptWord=crypt.crypt('%s%s%s'%(user,sfx,separator),salt)
if cryptWord==cryptPass:
#print ipaddr + " [+] Found Password: " +user+'/'+user+sfx+ " \n"
print '%s [+] Found Passwd: %s/%s%s%s \n'%(ipaddr,user,user,sfx,separator)
break
for word in dictfile.readlines():
#print word
word=word.strip()
cryptWord=crypt.crypt(word,salt)
if cryptWord==cryptPass:
print ipaddr + " [+] Found Password: " +user+'/'+word+ " \n"
break
print('[-] Password not found!')
def main():
cmd = "ifconfig|grep \"inet addr\"|grep -v 127.0.0.1|awk '{print $2}'"
ipaddr = commands.getoutput(cmd).replace('addr:','').replace('\n','|')
shadowfile=open('/etc/shadow')
for line in shadowfile.readlines():
user=line.split(':')[0]
cryptPass=line.split(':')[1].strip('\n')
if not (cryptPass.startswith('*') or cryptPass.startswith('!')):
print "[*] Cracking Password For: " +user
testPass(user,cryptPass,ipaddr)
if __name__=='__main__':
main()注:破解密碼有兩種方式,一種是通過(guò)腳本pwd_suffix定義的后綴,另一種是調(diào)用密碼字典庫(kù)(/root/dict.txt)來(lái)破解。
三、演示效果
創(chuàng)建一個(gè)測(cè)試用戶testuser,密碼設(shè)置成123456,然后執(zhí)行檢測(cè)腳本。滴,弱密碼已被發(fā)現(xiàn)!

到此這篇關(guān)于基于python實(shí)現(xiàn)弱密碼檢測(cè)工具的文章就介紹到這了,更多相關(guān)python弱密碼檢測(cè)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
使用Python設(shè)置tmpfs來(lái)加速項(xiàng)目的教程
這篇文章主要介紹了使用Python設(shè)置tmpfs來(lái)加速項(xiàng)目的教程,文中給出方法使用Python腳本將tmpfs保存于內(nèi)存中的程序存儲(chǔ)到本地硬盤上,需要的朋友可以參考下2015-04-04
Python實(shí)現(xiàn)曲線擬合操作示例【基于numpy,scipy,matplotlib庫(kù)】
這篇文章主要介紹了Python實(shí)現(xiàn)曲線擬合操作,結(jié)合實(shí)例形式分析了Python基于numpy,scipy,matplotlib庫(kù)讀取csv數(shù)據(jù)、計(jì)算曲線擬合及圖形繪制相關(guān)操作技巧,需要的朋友可以參考下2018-07-07
詳解Python實(shí)現(xiàn)同時(shí)支持帶調(diào)用和不調(diào)用帶裝飾器
一般來(lái)說(shuō),不帶參數(shù)裝飾器,再使用時(shí)不加括號(hào),帶參數(shù)的裝飾器使用時(shí)必須加括號(hào),這篇文章主要介紹了Python實(shí)現(xiàn)同時(shí)支持帶調(diào)用和不調(diào)用帶裝飾器的相關(guān)知識(shí),需要的朋友可以參考下2023-06-06
Pandas數(shù)據(jù)查詢的集中實(shí)現(xiàn)方法
本文主要介紹了Pandas數(shù)據(jù)查詢的集中實(shí)現(xiàn)方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-02-02
python類參數(shù)定義及數(shù)據(jù)擴(kuò)展方式unsqueeze/expand
本文主要介紹了python類參數(shù)定義及數(shù)據(jù)擴(kuò)展方式unsqueeze/expand,文章通過(guò)圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-08-08
python之wxPython應(yīng)用實(shí)例
這篇文章主要介紹了python之wxPython應(yīng)用實(shí)例,以加載圖片為例講述了wxPython的用法,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2014-09-09

