gpt4 book ai didi

linux - 简单的/etc/shadow Cracker

转载 作者:太空宇宙 更新时间:2023-11-04 12:45:16 26 4
gpt4 key购买 nike

我正在尝试让这个影子文件破解器正常工作,但我一直收到 TypeError: integer required.

我确定这是我使用 bytearray 函数的方式。我尝试用 bytearray 为“word”和“salt”创建一个新对象,但无济于事。因此,我尝试将 bytearray 构造函数传递给 pbkdf2 函数,但仍然没有。我将发布代码:

#!/usr/bin/python
# -*- coding: utf-8 -*-

import hashlib, binascii
import os,sys
import crypt
import codecs
from datetime import datetime,timedelta
import argparse
today = datetime.today()

# Takes in user and the encrypted passwords and does a simple
# Brute Force Attack useing the '==' operator. SHA* is defined by
# a number b/w $, the char's b/w the next $ marker would be the
# rounds, then the salt, and after that the hashed password.
# object.split("some symbol or char")[#], where # is the
# location/index within the list
def testPass(cryptPass,user):

digest = hashlib.sha512
dicFile = open ('Dictionary.txt','r')
ctype = cryptPass.split("$")[1]
if ctype == '6':
print "[+] Hash type SHA-512 detected ..."
print "[+] Be patien ..."
rounds = cryptPass.split("$")[2].strip('rounds=')
salt = cryptPass.split("$")[3]
print "[DEBUG]: " + rounds
print "[DEBUG]: " + salt
# insalt = "$" + ctype + "$" + salt + "$" << COMMENTED THIS OUT
for word in dicFile.readlines():
word = word.strip('\n')
print "[DEBUG]: " + word
cryptWord = hashlib.pbkdf2_hmac(digest().name,bytearray(word, 'utf-8'),bytearray(salt, 'utf-8'), rounds)
if (cryptWord == cryptPass):
time = time = str(datetime.today() - today)
print "[+] Found password for the user: " + user + " ====> " + word + " Time: "+time+"\n"
return
else:
print "Nothing found, bye!!"
exit

# argparse is used in main to parse arguments pass by the user.
# Path to shadow file is required as a argument.
def main():

parse = argparse.ArgumentParser(description='A simple brute force /etc/shadow .')
parse.add_argument('-f', action='store', dest='path', help='Path to shadow file, example: \'/etc/shadow\'')
argus=parse.parse_args()
if argus.path == None:
parse.print_help()
exit
else:
passFile = open (argus.path,'r', 1) # ADDING A 1 INDICATES A BUFFER OF A
for line in passFile.readlines(): # SINGLE LINE '1<=INDICATES
line = line.replace("\n","").split(":") # EXACT BUFFER SIZE
if not line[1] in [ 'x', '*','!' ]:
user = line[0]
cryptPass = line[1]
testPass(cryptPass,user)

if __name__=="__main__":
main()

输出:

[+] Hash type SHA-512 detected ...
[+] Be patien ...
[DEBUG]: 65536
[DEBUG]: A9UiC2ng
[DEBUG]: hellocat
Traceback (most recent call last):
File "ShadowFileCracker.py", line 63, in <module>
main()
File "ShadowFileCracker.py", line 60, in main
testPass(cryptPass,user)
File "ShadowFileCracker.py", line 34, in testPass
cryptWord = hashlib.pbkdf2_hmac(digest().name,bytearray(word, 'utf-8'),bytearray(salt, 'utf-8'), rounds)
TypeError: an integer is required

最佳答案

rounds 变量必须是整数,而不是字符串。正确的行应该是:

rounds = int(cryptPass.split("$")[2].strip('rounds='))

此外,strip() 可能不是删除前导“rounds=”的最佳方法。它会工作,但它会去除一组字符而不是字符串。稍微好一点的方法是:

rounds = int(cryptPass.split("$")[2].split("=")[1])

关于linux - 简单的/etc/shadow Cracker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38907450/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com