[ACTF新生赛2020]base64隐写
作者:互联网
[ACTF新生赛2020]base64隐写
有一个txt文件,看着很想base64加密,直接解密,发现不能直接解出来
根据网上搜索的做法是base64隐写,用脚本直接能跑出来
#encoding:utf-8
def get_base64_diff_value(s1, s2):
base64chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
res = 0
for i in xrange(len(s2)):
if s1[i] != s2[i]:
return abs(base64chars.index(s1[i]) - base64chars.index(s2[i]))
return res
def solve_stego():
with open('/home/kali/桌面/ComeOn!.txt', 'rb') as f:
file_lines = f.readlines()
bin_str = ''
for line in file_lines:
steg_line = line.replace('\n', '')
norm_line = line.replace('\n', '').decode('base64').encode('base64').replace('\n', '')
diff = get_base64_diff_value(steg_line, norm_line)
print diff
pads_num = steg_line.count('=')
if diff:
bin_str += bin(diff)[2:].zfill(pads_num * 2)
else:
bin_str += '0' * pads_num * 2
print goflag(bin_str)
res_str = ''
def goflag(bin_str):
res_str = ''
for i in xrange(0, len(bin_str), 8):
res_str += chr(int(bin_str[i:i + 8], 2))
return res_str
print(res_str)
if __name__ == '__main__':
solve_stego()
要注意的是这个只能用python2运行,而且网上的代码可能会有那个res_str未定义的问题,以及路径,编码问题,注意加上#encoding:utf-8,以及自己的文件所在的路径。并且定义那个res_str变量
标签:bin,隐写,res,base64,2020,str,diff,line 来源: https://www.cnblogs.com/Jinx8823/p/16533510.html