题目
解题
import string
import binascii
def Crack_4B(crc_list):
print('-------------Start Crack CRC 4B-------------')
#crc_list = [0xc0a3a573, 0x3cb6ab1c, 0x85bb0ad4, 0xf4fde00b]#文件的CRC32值列表,注意顺序
comment = ''
chars = string.printable
flag = 0
for crc_value in crc_list:
for char1 in chars:
for char2 in chars:
for char3 in chars:
for char4 in chars:
res_char = char1 + char2 + char3 + char4#获取遍历的任意4Byte字符
char_crc = binascii.crc32(res_char.encode())#获取遍历字符的CRC32值
calc_crc = char_crc & 0xffffffff#将遍历的字符的CRC32值与0xffffffff进行与运算
if calc_crc == crc_value:#将获取字符的CRC32值与每个文件的CRC32值进行匹配
print('[+] {}: {}'.format(hex(crc_value),res_char))
comment += res_char
flag = 1
break
if flag == 1:
break
if flag == 1:
break
if flag == 1:
break
flag = 0
print('-----------CRC Crack Completed-----------')
print('Result: {}'.format(comment))
crc_list = [0xce70d424,0xc3f17511,0xf90c8a70,0xf8ab2771,0xc0ce8ee6,0xb2a6cde9,0x8637fa85,0x62f8f1a9]
Crack_4B(crc_list)
-------------Start Crack CRC 4B-------------
[+] 0xce70d424: pass
[+] 0xc3f17511: word
[+] 0xf90c8a70: is
[+] 0xf8ab2771: gZin
[+] 0xc0ce8ee6: flAt
[+] 0xb2a6cde9: e_Ba
[+] 0x8637fa85: sE64
-----------CRC Crack Completed-----------
Result: password is gZinflAte_BasE64
# 读取文件内容
with open('1.txt', 'r') as file:
data = file.read()
# 替换逗号为换行符,并写入新文件
with open('1_new.txt', 'w') as file:
file.write(data.replace(',', '\n'))
# 读取文件的名称和路径
input_filename = '1_new.txt'
# 写入文件的名称和路径
output_filename = 'output.txt'
# 尝试打开文件以读取数据
try:
with open(input_filename, 'r', encoding='utf-8') as file:
# 初始化一个空字符串来保存结果
result = ''
# 逐行读取文件
for line in file:
# 去除行尾的换行符,并检查长度是否为8
if len(line.strip()) == 8:
# 添加到结果字符串中
result += line.strip()
# 如果需要,可以在每行之间加入换行符或分隔符
# result += '\n' # 如果你想要每8个字符的数据为一行
# 尝试打开文件以写入结果
with open(output_filename, 'w', encoding='utf-8') as outfile:
# 写入结果到文件
outfile.write(result)
except FileNotFoundError:
print(f"Error: File {input_filename} not found.")
except IOError as e:
print(f"I/O error({e.errno}): {e.strerror}")
# 如果一切顺利,输出提示信息
print(f"Data extracted and saved to {output_filename}")
DASCTF{6eada6e841c2ecb63bca0a6742889b08}