我在這裏有一個腳本,其中包含一些基本功能: 函數1-wget打開一個網頁並將其保存到本地變量中,然後關閉。 函數2 - 爲這個網頁抓取md5散列值。 函數3 - 獲取散列值並使用常用密碼字典對它們進行破解。不知道如何輸入一個函數的輸出作爲另一個函數的輸入
我的問題是從函數2獲取我的輸出並將其插入到函數3中。部分原因是函數2的輸出爲列表,而函數3正在查找散列值。
你們很有可能通過閱讀我的代碼來了解更多,下面是我的代碼到目前爲止。
import sys, hashlib, re, urllib
def wget(url): # could import webpage_get and use wget() from there instead
'''Read the contents of a webpage from a specified URL'''
print '[+]---------------------------------------------------------------------------- ' #CHANGE THIS
# open URL
webpage = urllib.urlopen(url) # opens url like a file
# get page contents
page_contents = webpage.read() # reads content of webpage
return page_contents
page_contents = webpage.close() # close webpage
def findmd5(text):
'''Find all md5 hash values'''
md5value = re.findall(r'([a-fA-F\d]{32})', text)
count = len(md5value)
print "[+] Total number of md5 hash values found: %s" % count
for x in md5value:
print x
def dict_attack(passwd_hash):
dic = ['123','1234','12345','123456','1234567','12345678','password','qwerty','abc','abcd','abc123','111111','monkey','arsenal','letmein','trustno1','dragon','baseball','superman','iloveyou','starwars','montypython','cheese','123123','football','password','batman']
passwd_found = False
for value in dic:
hashvalue = hashlib.md5(value).hexdigest()
if hashvalue == passwd_hash:
passwd_found = True
recovered_password = value
if passwd_found == True:
print '[+] Password recovered: %s'% (recovered_password)
else:
print '[-] Password not recovered'
def main():
# temp testing url argument
sys.argv.append('URL HERE!')
# Check args
if len(sys.argv) != 2:
print '[-] Usage: email_analysis URL/filename'
return
#call functions
try:
print '[+] md5 values found: '
print findmd5(wget(sys.argv[1]))
print '[+] Cracking hash values: '
except IOError:
print 'Error'
if __name__ == '__main__':
main()
任何幫助,非常感謝!
我看到一個關於這個完全相同的任務不到一個小時前的問題。你能和你的同學一起工作嗎? – TigerhawkT3