简化bruteforce程序并添加功能

2024-10-02 12:38:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个密码蛮力,它可以处理三个字母,但我必须分别输入所有三个字母。有没有办法让它成为可能,这样我就可以同时把这三个都放进去?我将单词转换为其ancii代码,并将1添加到测试变量中,该变量与密码进行比较。 我的守则如下:

def bruteforce(pw1, pw2, pw3):
    test1 = 64
    pwo1 = ord(pw1)
    test2 = 64
    pwo2 = ord(pw2)
    test3 = 64
    pwo3 = ord(pw3)

    while(test1 != pwo1):
        test1 += 1
    while(test2 != pwo2):
        test2 += 1
    while(test3 != pwo3):
        test3 += 1

    
    print("The password is " + chr(pwo1) + chr(pwo2) + chr(pwo3))

我尝试的是将字符串转换为列表,并将“单词”拆分为字符。这对我不起作用,至少我无法在线找到解释如何将字符串中的字符输出到单个参数/变量中


Tags: 密码字母单词test1test2whilepw3test3
1条回答
网友
1楼 · 发布于 2024-10-02 12:38:30
import random
import time
from colorama import Fore, Back, Style
#from pyfiglet import Figlet

def time_convert(sec):
  mins = sec // 60
  sec = sec % 60
  hours = mins // 60
  mins = mins % 60
  print("Time Lapsed = {0}:{1}:{2}".format(int(hours),int(mins),sec))

times_to_do = 1

actuall_password = input(Fore.BLUE + 'What password would you like to brute force:   ')
start_time = time.time()

chars = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
#'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 

while True:
  char_picked1 = (random.choice(chars))
  char_picked2 = (random.choice(chars))
  char_picked3 = (random.choice(chars))
  char_picked4 = (random.choice(chars))
  char_picked5 = (random.choice(chars))
  char_picked6 = (random.choice(chars))
  total_password = (char_picked1 + char_picked2 + char_picked3 + char_picked4 + char_picked5 + char_picked6)
  if total_password == actuall_password:
    print(Fore.GREEN + 'Tried:  ' + total_password)
    print(Fore.GREEN + 'Sucess, your password was:  ', total_password)
    print('This process took', times_to_do, 'attempts!')
    end_time = time.time()
    time_lapsed = end_time - start_time
    print('This process took', time_lapsed, 'seconds to complete this attack')
    break
  else:
    print(Fore.RED + 'Tried: ', total_password)
    times_to_do = (times_to_do + 1)

这是一个简单的版本,我与颜色

相关问题 更多 >

    热门问题