基于python實(shí)現(xiàn)弱密碼檢測(cè)工具
一、引用的python模塊
Crypto:
Python中一個(gè)強(qiáng)大的加密模塊,提供了許多常見的加密算法和工具。它建立在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ù)和變量來處理 Python 運(yùn)行時(shí)環(huán)境的不同部分。
二、實(shí)現(xiàn)過程
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()
注:破解密碼有兩種方式,一種是通過腳本pwd_suffix定義的后綴,另一種是調(diào)用密碼字典庫(kù)(/root/dict.txt)來破解。
三、演示效果
創(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)文章
詳解使用Pytorch Geometric實(shí)現(xiàn)GraphSAGE模型
這篇文章主要為大家介紹了詳解使用Pytorch Geometric實(shí)現(xiàn)GraphSAGE模型示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-04-04Windows和Linux下使用Python訪問SqlServer的方法介紹
這篇文章主要介紹了Windows和Linux下使用Python訪問SqlServer的方法介紹,本文講解了Windows下配置Python訪問Sqlserver、Linux下配置Python訪問SqlServer等內(nèi)容,需要的朋友可以參考下2015-03-03Python求兩點(diǎn)之間的直線距離(2種實(shí)現(xiàn)方法)
今天小編就為大家分享一篇Python求兩點(diǎn)之間的直線距離(2種實(shí)現(xiàn)方法),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-07-07詳解Tensorflow數(shù)據(jù)讀取有三種方式(next_batch)
本篇文章主要介紹了Tensorflow數(shù)據(jù)讀取有三種方式(next_batch),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-02-02Python:合并兩個(gè)numpy矩陣的實(shí)現(xiàn)
今天小編就為大家分享一篇Python:合并兩個(gè)numpy矩陣的實(shí)現(xiàn),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-12-12Python??Pandas教程之使用?pandas.read_csv()?讀取?csv
這篇文章主要介紹了Python Pandas教程之使用pandas.read_csv()讀取csv,文章通過圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-09-09Python最火、R極具潛力 2017機(jī)器學(xué)習(xí)調(diào)查報(bào)告
Python最火,R極具潛力,分享2017機(jī)器學(xué)習(xí)調(diào)查報(bào)告,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-12-12