NewStarCTF2023week2-base!(base低位隐写)

附件内容是很多的base64编码的字符串

常见的Base64隐写一般会给一个txt文本文档,内含多个经过base64编码的字符串。解码规则是将所有被修改过的base64字符串结尾的二进制值提取出来组成一个二进制串,以8位分割并转为十进制值,最终十进制对应的ASCII字符串即为base64隐写结果。

这里附上解密脚本:

python 复制代码
# base64隐写
import base64

import base
def get_diff(s1, s2):
    base64chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
    res = 0
    for i in range(len(s2)):
        if s1[i] != s2[i]:
            return abs(base64chars.index(s1[i]) - base64chars.index(s2[i]))
    return res


def b64_stego_decode():
    file = open("base.txt","rb")
    x = ''                                      # x即bin_str
    lines =  file.readlines()
    for line in lines:
        l = str(line, encoding = "utf-8")
        stego = l.replace('\n','')
        #print(stego)
        realtext = base64.b64decode(l)
        #print(realtext)
        realtext = str(base64.b64encode(realtext),encoding = "utf-8")
        #print(realtext)
        diff = get_diff(stego, realtext)        # diff为隐写字串与实际字串的二进制差值
        n = stego.count('=')
        if diff:
            x += bin(diff)[2:].zfill(n*2)
        else:
            x += '0' * n*2
            
    i = 0
    flag = ''
    while i < len(x):
        if int(x[i:i+8],2):
            flag += chr(int(x[i:i+8],2))
        i += 8
    print(flag)

if __name__ == '__main__':
    b64_stego_decode()

这里顺便说一个问题,不要将脚本命名为base64.py

否则会报错:module 'base64' has no attribute 'b64decode'

运行得到:

iDMb6ZMnTFMtFuouYZHwPTYAoWjC7Hjca8

将结果放入随波逐流,发现是base58

flag{b4se_1s_4_g0od_c0d3}

相关推荐
满怀101528 分钟前
【Flask全栈开发指南】从零构建企业级Web应用
前端·python·flask·后端开发·全栈开发
PWRJOY28 分钟前
Flask-SQLAlchemy_数据库配置
数据库·python·flask
mahuifa1 小时前
Qt图表绘制(QtCharts)- 性能优化(13)
python·qt·pyside6·开发经验·qtchart
Bugabooo1 小时前
python打卡DAY22
开发语言·python
低维歌者1 小时前
python训练营day27
java·开发语言·python
微刻时光2 小时前
影刀处理 Excel:智能工具带来的高效变革
人工智能·python·低代码·自动化·excel·rpa·影刀rpa
大帅不是我2 小时前
Python多进程编程执行任务
java·前端·python
Fu_lucas2 小时前
Python Logging 模块完全指南
开发语言·python
Eiceblue2 小时前
Python 在Excel单元格中应用多种字体样式
开发语言·vscode·python·pycharm·excel
Superstarimage4 小时前
使用conda创建python虚拟环境,并自定义路径
windows·python·conda