下载附件,给了一个流量包,拿到wireshark中进行流量分析
看到除了上面的几个包,其它的都是ICMP的包,上面的几个包也没发现什么有用的信息,就随便点开几个ICMP包看了下,发现它们的尾部都有一串相同格式的信息
使用tshark进行提取
提取出的data.txt中有大量重复信息
with open('data.txt', 'r') as file:
res_list = []
lines = file.readlines()
print('[+]去重之前一共{0}行'.format(len(lines)))
print('[+]开始去重,请稍等.....')
for i in lines:
if i not in res_list:
res_list.append(i)
print('[+]去重后一共{0}行'.format(len(res_list)))
print(res_list)
with open('data1.txt', 'w') as new_file:
for j in res_list:
new_file.write(j)
对文本进行去重后,再将文本的十六进制转化成字符串
import binascii
with open('data1.txt', 'r') as file:
with open('data2.txt', 'wb') as data:
for i in file.readlines():
data.write(binascii.unhexlify(i[:-1]))
转化成字符串后可以看见第一行和最后一行的格式是不相同的,还有重复的字符$$START$$对重复的字符进行删除
def remove_specific_string(input_file, output_file, target_string='$$START$$'):
with open(input_file, 'r', encoding='utf-8') as file:
content = file.read()
# 替换文件中的特定字符串
content = content.replace(target_string, '')
with open(output_file, 'w', encoding='utf-8') as file:
file.write(content)
# 使用示例
input_file = 'data2.txt' # 要处理的文件名
output_file = 'data3.txt' # 输出的文件名
remove_specific_string(input_file, output_file)
然后删除换行符
def remove_newlines(input_file, output_file):
with open(input_file, 'r', encoding='utf-8') as file:
content = file.read()
# 去除所有换行符
content = content.replace('\n', '').replace('\r', '')
with open(output_file, 'w', encoding='utf-8') as file:
file.write(content)
# 使用示例
input_file = 'data3.txt' # 要处理的文件名
output_file = 'data4.txt' # 输出的文件名
remove_newlines(input_file, output_file)
最后将data4.txt,转换成压缩包格式
import base64
with open('data4.txt', 'rb') as file:
with open('res.zip', 'wb') as new_file:
new_file.write(base64.b64decode(file.read()))
解压压缩包里面有张gif图片
在linux中使用indentify(这里identify是imagemagick的一个组件功能挺多的)输出文件格式
identify -format "%T" flag.jpg
将20替换成50替换成1
def replace_numbers(text):
# 替换20为0
text = text.replace("20", "0")
# 替换50为1
text = text.replace("50", "1")
return text
# 示例文本
text = "2050502050502050205020202050202020205050205020502050205050505050202050502020205020505050205020206666"
# 调用函数并打印结果
new_text = replace_numbers(text)
print(new_text)
然后二进制转字符串
再对结果进行加密
flag:flag{f0f1003afe4ae8ce4aa8e8487a8ab3b6}
标签:BUUCTF,text,file,output,input,蜘蛛侠,txt,open From: https://blog.csdn.net/2401_83972784/article/details/143388544