2012-11-28 27 views
0

目前我正在簡化在安全審計中提取Windows密碼散列的過程。就我個人而言,當我進行審計時,我想讓該過程更容易生成已恢復用戶及其密碼的列表。我認爲這對其他試圖比較和生成大量數據的人也有用。實現數據結構來比較NTLM散列文件

所以這裏的要點是:

當我提取所有從Windows系統文件中的數據,我簡化他們到格式的用戶:「a87f3a357d73085c45f9416be5787e86」散列,其中散列是NTLM哈希如

然後我會使用oclHashcat並試圖破解哈希,不管它是字典還是蠻力,都沒關係。我生成了所有已恢復散列的輸出,但是Hashcat使用hash:password格式生成它們。

現在,這裏是我的問題,我想要什麼輸入 - 我想產生的輸出作爲用戶:輸入文件給出的兩個密碼。考慮到我可以擁有數百個哈希,但只有少數恢復的密碼,因此沒有必要嘗試對列表進行排序。

我不確定哪種數據結構可能最有益於我。對於大型表格,數組效率太低。我研究過序列化,並且我一直在探索使用哈希映射和哈希表。鑑於哈希的大小,我沒有任何運氣實現這些方法,或者我做得不正確。

目前我正在運行的程序,像這樣:

program [user:hash file] [hash:password file] -o [user:password output] 

而且我有效嘗試運行的程序,像這樣(簡述):

Load Files 

// user:hash file 
For each line, split by ':' delimiter 
before delimiter = table1.user 
after delimiter = table1.hash 

// hash:password file 
For each line, split by ':' delimiter 
before delimiter = table2.hash 
after delimiter = table2.password 

// generate user:password file 
Check each entry of table1 vs table2 
if table1.hash = table2.hash 
    table1.user = output.user 
    table2.password = output.password 
    print to output "output.user:output.password" 

我只是想圖找出一種有效的方法來追蹤每一行,並將必要的數據提取到一個我可以輕鬆追蹤的數據結構中。

如果我需要澄清任何事情,請讓我知道。任何幫助表示讚賞!

+0

您能詳細說明一下哈希函數的問題嗎?另外,你爲什麼要實現你的哈希而不是使用stl中的哈希? – RonaldBarzell

+0

嗯,我想我是不正確地實施他們開始。但後來我開始懷疑是否還有其他更好的方法來存儲這些數據。 我使用哈希的原因是因爲它們是來自Hashcat和其他軟件的輸出,我需要那些用於比較。 – Signus

回答

0

我決定去一個shell腳本,我用一個關聯的數組來匹配req使用我需要的數據。

注意:這個程序大部分處理我的哈希文件格式化的方式。看看腳本中的評論。

#!/bin/bash 
# Signus 
# User-Password Hash Comparison Tool v1.0 
# Simple utility that allows for the comparison between a file with a 'user:hash' format to a separate file with a 'hash:password' format. The comparison matches the hashes and returns an output file in the format 'user:password' 

# Example of 'user:hash' -> george:c21cfaebe1d69ac9e2e4e1e2dc383bac 
# Example of 'hash:password' -> c21cfaebe1d69ac9e2e4e1e2dc383bac:password 
# 'user:hash' obtained from creddump suite: http://code.google.com/p/creddump/ 
# Note: Used custom 'dshashes.py' file: http://ptscripts.googlecode.com/svn/trunk/dshashes.py 
# 'hash:password' obtained from ocl-Hashcat output 

usage="Usage: $0 [-i user:hash input] [-t hash:password input] [-o output]" 

declare -a a1 
declare -a a2 
declare -A o 

index1=0 
index2=0 
countA1=0 
countA2=0 
matchCount=0 

if [ -z "$*" ]; then 
    echo $usage 
    exit 1 
fi 

if [ $# -ne 6 ]; then 
    echo "Error: Invalid number of arguments." 
    echo $usage 
    exit 1 
fi 

echo -e 
echo "---Checking Files---" 
while getopts ":i:t:o:" option; do 
    case $option in 
     i) inputFile1="$OPTARG" 
     if [ ! -f $inputFile1 ]; then 
      echo "Unable to find or open file: $inputFile1" 
      exit 1 
     fi 
     echo "Reading...$inputFile1" 
     ;; 
     t) inputFile2="$OPTARG" 
     if [ ! -f $inputFile2 ]; then 
      echo "Unable to find or open file: $inputFile2" 
      exit 1 
     fi 
     echo "Reading...$inputFile2" 
     ;; 
     o) outputFile="$OPTARG" 
     echo "Writing...$outputFile" 
     ;; 
     [?]) echo $usage >&2 
      exit 1 
     ;; 
    esac 
done 
shift $(($OPTIND-1)) 


#First read the files and cut each line into an array 
echo -e 
echo "---Reading Files---" 
while read LINE 
do 
    a1[$index1]="$LINE" 
    index1=$(($index1+1)) 
    countA1=$(($countA1+1)) 
done < $inputFile1 
echo "Read $countA1 lines in $inputFile1" 

while read LINE 
do 
    a2[$index2]="$LINE" 
    index2=$(($index2+1)) 
    countA2=$(($countA2+1)) 
done < $inputFile2 
echo "Read $countA2 lines in $inputFile2" 


#Then cut each item out of the array and store it into separate variables 
echo -e 
echo "Searching for Matches..." 
for ((j=0; j<${#a2[@]}; j++)) 
do 
    hash2=$(echo ${a2[$j]} | cut -d: -f1) 
    pword=$(echo ${a2[$j]} | cut -d: -f2) 

    for ((i=0; i<${#a1[@]}; i++)) 
    do 
     us=$(echo ${a1[$i]} | cut -d: -f1) 
     hash1=$(echo ${a1[$i]} | cut -d: -f2) 

     if [ "$hash2" = "$hash1" ]; then 
      matchCount=$(($matchCount+1)) 
      o["$us"]=$pword 
      echo -e "Match Found[$matchCount]: \t Username:$us \t Password:$pword" 
      break 
     fi 

    done 
done 

echo -e "Matches Found: $matchCount\n" >> $outputFile 
for k in ${!o[@]} 
do 
    echo -e "Username: $k \t Password: ${o[$k]}" >> $outputFile 
done 
echo -e "\nWrote $matchCount lines to $outputFile" 

unset o 
1

,我會爲我的數據結構

std::map<std::string,std::string> hash_user_map; 

沒有經歷所有的用戶這樣做,從表1

For each user in table1 
hash_user_map[table1.hash] = table1.user; 

沒有經歷所有破解的密碼與哈希值從表2

哈希
std::string user = hash_user_map[table2.hash]; 
std::cout << user << ":" << table2.password << "\n; 
+0

這是一個非常好的和簡單的方法。我最初嘗試哈希映射,我想我沒有指定鍵和值數據類型。 我也認爲這個實現將節省一些時間讀寫保存。我會給你一個鏡頭,讓你知道! – Signus

+0

我寫了一個簡單的方法,用bash中的關聯數組來做這件事,併發布它,隨時查看! – Signus