【问题标题】:Itarate password combinations to find key for string迭代密码组合以查找字符串的密钥
【发布时间】:2016-03-03 16:36:57
【问题描述】:

我在暴力破解使用 RC4/ARC4 加密的字符串的密钥时遇到问题。

这是加密的字符串: E7Ev08_MEojYBixHRKTKQnRSC4hkriZ7XPsy3p4xAHUPj41Dlzu9

而且字符串也是用base64散列的,所以完整的编码字符串是: RTdFdjA4X01Fb2pZQml4SFJLVEtRblJTQzRoa3JpWjdYUHN5M3A0eEFIVVBqNDFEbHp1OQ==

#-*- coding: utf-8 -*-
import threading
import sys
import time
import re
import itertools
from itertools import product
from Crypto.Cipher import ARC4
import base64


def special_match(strg):
  try:
    strg.decode('utf-8')
  except UnicodeDecodeError:
    pass
  else:
    print('\nkey found at %s, key: %s' % (time.ctime(), rc4_key))
    try:
            f=open('key.txt','ab')
            f.write('Key (%s): %s\n' % (time.ctime(), rc4_key))
            f.write('Decrypted string: ' + strg + '\n')
            f.close()
    except Exception as e:
            print('ERROR WRITING KEY TO FILE: ' + str(e))

chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
end_chars = chars[::-1][0:7]

encoded_string = 'RTdFdjA4X01Fb2pZQml4SFJLVEtRblJTQzRoa3JpWjdYUHN5M3A0eEFIVVBqNDFEbHp1OQ=='


spinner = itertools.cycle(['-', '/', '|', '\\'])

while 1:
      try:
        # Iteration processess of possibel keys
        for length in range(7,8): # only do length of 7
            for attempt in itertools.permutations(chars, length):
                rc4_key = ''.join(attempt) # This key is unknown, we are looking for it..
                Ckey = ARC4.new(rc4_key)
                decoded = Ckey.decrypt(encoded_string.decode('base64'))
                special_match(decoded)

                sys.stdout.write(spinner.next())  # write the next character
                sys.stdout.flush()                # flush stdout buffer (actual character display)
                sys.stdout.write('\b')            # erase the last written char

                # Exit the script when we have done all password-combination-iterations
                if (rc4_key == end_chars):
                  print('iteration of combinations done! No key found.. :(\n' + time.ctime())
                  exit()

      except KeyboardInterrupt:
        print('\nKeybord interrupt, exiting gracefully anyway on %s at %s' % (rc4_key, time.ctime()))
        sys.exit()

我使用http://crypo.bz.ms/secure-rc4-online 加密字符串并使用https://www.base64encode.org 使用UTF-8 对其进行编码。

问题

为什么我的脚本无法找到密钥?

(我没有收到任何错误消息,如果我遗漏了代码中的某些内容或问题的处理方法,这更像是一个普遍的问题。)

明文:This is something that I have encrypted,密钥:ABCFMSG

【问题讨论】:

  • 不一致的缩进会导致问题。
  • 如果提供正确的密钥,解密是否有效?
  • 还有 80 亿个可能的密钥,可能需要很长时间
  • @JeD 但在这种情况下,关键是ABCFMSG

标签: python encryption


【解决方案1】:

好吧,crypo.bz 似乎使用了一个非常奇怪的系统。基本上,他们有一个非常奇怪的编码,如果你简单地使用他们的字符,就会导致差异。

例如,使用键 'A' 编码 'a' 应该产生一个值为 163 的字符。

十六进制 A3。在 crypo.bz 中,我们得到 'oc'。

所以你有两种可能。要么做一些密文分析,要么使用另一个站点。我推荐这个,因为他们告诉你他们对结果的编码:

http://www.fyneworks.com/encryption/RC4-Encryption/index.asp

获取十六进制并将其转换为字符串,您应该能够破译它

顺便说一句,您的代码似乎可以正常工作;)

如果您还有其他问题,请告诉我

编辑:做了一些额外的分析,这真的很奇怪。 在 crypo.bz 中如果算法正确 163 是 oc

160 是 nc

但是 161 是 mc ??

如果有人知道这一点,请告诉我!

编辑编辑:

这里是加密但未编码的字符串 '#ÔèïH§¢6pbpÊ]õªœIôŒ>Yœ5îfäGuæxÖa...ë6°'

您的程序大约需要半秒钟才能找到密钥;)

【讨论】:

    猜你喜欢
    • 2011-05-02
    • 1970-01-01
    • 2012-06-14
    • 2012-02-25
    • 1970-01-01
    • 1970-01-01
    • 2012-11-10
    • 2019-02-02
    • 2015-07-31
    相关资源
    最近更新 更多