Passwords

如何使用側通道攻擊從執行簡單雜湊匹配的python程序二進製文件中提取儲存的密碼

  • August 10, 2022

為了防止攻擊者獲取密碼,我們計算使用者提供的密碼的雜湊值和儲存密碼的雜湊值。這是一個簡單的雜湊函式的實現。

import time
import timeit

#This is just to show the hashing implementation. We only have access to the binary file
flag = "ctf{its_dummy_flag}"
prime = 19

#for substitution of characters
def substitution(char):
   switch = {
       'a' : 'z',
       'b' : 'j',
       'c' : 's',
       'd' : 'q',
       'e' : 'r',
       'f' : 'y',
       'g' : 'i',
       'h' : 'w',
       'i' : 'm',
       'j' : 'h',
       'k' : 'f',
       'l' : 'g',
       'm' : 'b',
       'n' : 'c',
       'o' : 'x',
       'p' : 'e',
       'q' : 'a',
       'r' : 't',
       's' : 'u',
       't' : 'o',
       'u' : 'd',
       'v' : 'k',
       'w' : 'n',
       'x' : 'l',
       'y' : 'p',
       'z' : 'v',
       '{' : '=',
       '}' : '_',
       '=' : '}',
       '_' : '{'
       }
   return switch.get(char,char)

# compute hash of the supplied string
def compute_hash(password):
   password = password.ljust(prime,"=")[0:prime]
   hash = ""
   for i in range(prime):
       hash += substitution(password[(7*i+4)%prime])
   return hash

# to check the correctness of the supplied password
def password_checker(password):
   hash = compute_hash(password)
   for i in range(len(flag)):
       time.sleep(1)
       if(flag_hash[i]!=hash[i]):
           return False
   return True

def password_handler(password):
   if(password):
       # measure the time measured to check password correctness
       start = timeit.default_timer()
       if(password_checker(password)):
           print("Access Granted")
       else:
           print("Invalid password")
       end = timeit.default_timer()
       runtime = end-start
       print("Time taken to verify = ", runtime)

flag_hash = compute_hash(flag)
print("Enter the password:")
# take user input password
password = input()
password_handler(password)

在採取這種對策的情況下,如何從二進製文件中提取儲存的密碼?另外,我如何找到與儲存密碼具有相同雜湊值的其他密碼集

引用自:https://crypto.stackexchange.com/questions/101429