基于python實現弱密碼檢測工具
一、引用的python模塊
Crypto:
Python中一個強大的加密模塊,提供了許多常見的加密算法和工具。它建立在pyc.ypodome或pyc.ypto等底層加密庫之上,為Python程序員提供了簡單易用的API,使其可以輕松地實現各種加密功能。
commands:
commands 模塊是 Python 的內置模塊,它主要有三個函數:
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: 基礎系統(tǒng)模塊
sys模塊是與python解釋器交互的一個接口。sys 模塊提供了許多函數和變量來處理 Python 運行時環(huá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定義的后綴,另一種是調用密碼字典庫(/root/dict.txt)來破解。
三、演示效果
創(chuàng)建一個測試用戶testuser,密碼設置成123456,然后執(zhí)行檢測腳本。滴,弱密碼已被發(fā)現!
到此這篇關于基于python實現弱密碼檢測工具的文章就介紹到這了,更多相關python弱密碼檢測內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
詳解使用Pytorch Geometric實現GraphSAGE模型
這篇文章主要為大家介紹了詳解使用Pytorch Geometric實現GraphSAGE模型示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-04-04Windows和Linux下使用Python訪問SqlServer的方法介紹
這篇文章主要介紹了Windows和Linux下使用Python訪問SqlServer的方法介紹,本文講解了Windows下配置Python訪問Sqlserver、Linux下配置Python訪問SqlServer等內容,需要的朋友可以參考下2015-03-03詳解Tensorflow數據讀取有三種方式(next_batch)
本篇文章主要介紹了Tensorflow數據讀取有三種方式(next_batch),小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-02-02Python??Pandas教程之使用?pandas.read_csv()?讀取?csv
這篇文章主要介紹了Python Pandas教程之使用pandas.read_csv()讀取csv,文章通過圍繞主題展開詳細的內容介紹,具有一定的參考價值,需要的小伙伴可以參考一下2022-09-09