2016-08-11 2 views
0

이 그림자 파일 크래커가 작동하도록 노력하고 있지만 계속 TypeError : 정수가 필요합니다.Simple/etc/shadow 크래커

필자는 bytearray 기능을 사용하고있는 방법이라고 확신합니다. 나는 "word"와 "salt"를위한 bytearray라는 새로운 객체를 만들려고 노력했지만 아무 소용이 없다. 그래서 나는 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 

답변

0

rounds 변수 요구 사항이 정수가 아닌 문자열이어야합니다. 올바른 행은 다음과 같습니다

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

, strip()가 선두 "라운드 ="를 제거하는 가장 좋은 방법하지 않을 수 있습니다. 작동하지만 스트링이 아닌 문자 세트를 제거합니다. 약간 더 나은 방법은 다음과 같습니다.

rounds = int(cryptPass.split("$")[2].split("=")[1]) 
관련 문제