Beispiel #1
0
def decrypt (hashed_pass,possible_passwords):
    """Dado un password encriptado mediante MD5 y una lista de posibles passwords,
        devuelve el password que fue encriptado o None en caso que ninguno matchee"""
    for password in possible_passwords:
        if MD5(password).hexdigest() == hashed_pass:
            return password
    return None
Beispiel #2
0
 def insertData(self, item):
     # 数据库session
     session = self.Session()
     post_id = item.get("post_id", "")  # 帖子ID
     post_url = item.get("post_url", "")  # 帖子链接
     for comment_id, author_name, post_time, post_comment in zip(
             item.get("comment_ids", []),  # 主评论ID
             item.get("author_names", []),
             item.get("post_times", datetime.now()),  # 评论时间
             item.get("post_comments", [])):
         # 生成唯一索引
         data = post_id + comment_id + author_name + post_time + post_comment
         md5 = MD5(data.encode())
         model = ForumCommentItemsModel(
             md5_key=md5.hexdigest(),
             post_id=post_id,
             comment_id=comment_id,
             author_name=author_name.encode().decode(
                 "unicode_escape") if author_name.find(
                     r"\u") > -1 else author_name,  # 把\\u 转成中文
             post_time=post_time,
             post_comment=post_comment.strip(),
             post_url=post_url + \
             "&pid={0}#{0}".format(comment_id)  # 直接跳转到该楼层
         )
         session.merge(model)  # 存在则更新,不存在则插入
     session.commit()  # 批量提交
     session.close()
Beispiel #3
0
def find_salt(possible_passwords,possible_salts,hashed_pass):
    """Funcion que dada una lista de posibles passwords y sales, devuelve a que
        par password-sal corresponde la linea hasheada pasada. En caso de no coincidir,
        devuelve None-None"""
    for password in possible_passwords:
        for salt in possible_salts:
            salted_pass = "".join([password,salt])
            if MD5(salted_pass).hexdigest() == hashed_pass:
                return password,salt
    return None,None
Beispiel #4
0
def computePW(text: str, salt: str):
    """根据用户密码和数据库中的salt来计算返回md5的16进制值字符串

    :param text: 前端传来用户的密码(字符串)
    :param salt: 本地数据库存加密的盐(字符串)
    :return: 长md5后的32位16进制值字符串
    """
    # text = text.encode('utf-8')
    # s = text + salt
    # m = MD5(s)
    # return m.hexdigest().encode('utf-8')

    s = text + salt     # 不要调换位置,否则会导致hash结果不一致
    m = MD5(s.encode('utf-8'))  # 等效MD5(text.encode('utf-8') + salt.encode('utf-8'))
    return m.hexdigest()
Beispiel #5
0
def random_md5(size):
    '''
	Generate random string md5 | for security reasons
	'''
    try:
        universe = '0qwe1rty2uio3pas4dfg5hjk6lzx7cvb8nm9'
        rand_string = ''
        for i in range(size):
            rand_string += universe[randint(0, len(universe) - 1)]
        rand_string = rand_string.encode()

        #logging.info('[{}]\n\trandom string of size {} = {}'.format(time.asctime(), size, rand_string))
        hash = str(MD5(rand_string).hexdigest())
        return hash
    except Exception as e:
        print("\n\nCritical: ", str(time.asctime()), "\n\t(file, line) = (",
              filename, ", ",
              getframeinfo(currentframe()).lineno, ")\n\t", str(e), "\n\n")
        return False
Beispiel #6
0
def match_passwords_file(pass_file, password_len):
    """Dado un archivo abierto y una longitud de passwords, intenta desencriptar
        los passwords encriptados en el"""
    letter_list = [chr(x) for x in xrange(32, 127)]
    possible_passwords = [
        "".join(x) for x in combinations(letter_list, repeat=password_len)
    ]
    hashed_possible_passwords = [
        MD5(x).hexdigest() for x in possible_passwords
    ]

    line_number = 0

    for line in pass_file:
        line_number += 1
        line = line.rstrip()

        password = decrypt(line, possible_passwords, hashed_possible_passwords)
        print_password(password, line_number)
Beispiel #7
0
def upload_file(host, fd, absurl):
	rk = url_to_key(host, absurl)
	content = fd.read()
	rv = {}
	needs_write = False

	ct, enc = guess_type(absurl, strict=False)
	if not ct:
		ct = better_mimes(absurl)
		assert ct, "No good mime type for: %s" % absurl
	if not enc and ct and ct.startswith('text/'):
		enc = 'utf-8'

	ll = len(content)
	rv['Content-Length'] = ll

	if ll < MIN_Q_SIZE:
		rv['_content'] = content
		log_path(absurl, 'In-Memory')
	else:
		hh = MD5(content).hexdigest()
		if '.' in absurl:
			# add file extension; if present.
			ext = (absurl.split('.', 1)[-1]).lower()
			hh += '.' + ext
		
		rv['_hash'] = hh
		needs_write = True

		if not RDB.hexists('new_files', hh) and not RDB.sismember('all_files', hh):
			RDB.hset('new_files', hh, content)
			log_path(absurl, 'UPLOADED')
		else:
			log_path(absurl, 'skipped (got it)')

	rv['Content-Type'] = ct + ('' if not enc else '; charset="%s"' % enc)
	#print "%s => %r" % (rk, rv)
	RDB.hmset(rk, rv)

	return needs_write
Beispiel #8
0
def match_salted_passwords(pass_file, password_len, salt_len):
    """Dado un archivo abierto, una longitud de passwords y una longitud de sal, intenta
        desencriptar los passwords encriptados en el, tomando como sal la primer sal ha"""
    letter_list = [chr(x) for x in xrange(32, 127)]
    possible_passwords = [
        "".join(x) for x in combinations(letter_list, repeat=password_len)
    ]
    possible_salts = [
        "".join(x) for x in combinations(letter_list, repeat=salt_len)
    ]

    line_number = 0

    line = pass_file.readline().rstrip()

    password, salt = find_salt(possible_passwords, possible_salts, line)
    print_password(password, line_number)

    while not salt:
        line_number += 1
        password, salt = find_salt(possible_passwords, possible_salts, line)
        print_password(password, line_number)

    possible_passwords = [x + salt for x in possible_passwords]
    hashed_possible_passwords = [
        MD5(x).hexdigest() for x in possible_passwords
    ]

    for line in pass_file:
        line_number += 1
        line = line.rstrip()

        password = decrypt(line, possible_passwords, hashed_possible_passwords)
        if password:
            password = password[:password_len - salt_len - 1]
        print_password(password, line_number)
Beispiel #9
0
def allocVmMac(vmId, nicId):
    m = MD5()
    string = "%s/%s" % (vmId, nicId)
    m.update(string.encode())
    v = m.hexdigest()
    return "52:54:%s:%s:%s:%s" % (v[0:2], v[4:6], v[8:10], v[12:14])
Beispiel #10
0
def getEncPass(str):
	m = MD5()
	m.update("Octopus".encode())
	m.update(str.encode())
	m.update("Link".encode())
	return m.hexdigest()
Beispiel #11
0
 def checksum(cls, key, keyusage, text):
     ksign = HMAC.new(key.contents, b'signaturekey\x00', MD5).digest()
     md5hash = MD5(_RC4.usage_str(keyusage) + text).digest()
     return HMAC.new(ksign, md5hash, MD5).digest()
Beispiel #12
0
def md516(string):
    return MD5(string.encode('utf-8') if isinstance(string, unicode) else string).digest()
Beispiel #13
0
 def pureMD5(self, text):
     return MD5(text)
Beispiel #14
0
 def md5(self, text):
     return MD5(text).hexdigest()
Beispiel #15
0
 def calc_md5(self):
     self.md5 = MD5(self.data).digest()
Beispiel #16
0
def xmmd5(password: str) -> str:
    md5 = MD5(password.encode('utf-8')).digest()
    return ''.join(_XMMD5MAGIC[(a + b) % len(_XMMD5MAGIC)]
                   for a, b in zip(md5[0::2], md5[1::2]))[:8]