CI/DI (四)OWASP ZAP python

练习Test方法
SAST, DAST, SAC
DAST案例四, APIs接口扫描测试,但是是针对单个接口的。我练习用的是免费版的,商业版支持自动修复,也可能支持swagger整合。

snapshot:
打开程序安装目录运行zap.bat(因为我本地使用jdk版本过高)
点击这里闪电tab,录入项目url地址,点击Attack开始扫描页面所有关联性的url地址。
在这里插入图片描述

Alerts扫描问题结果
在这里插入图片描述
修复常见header和CSRF问题,留下两个low级别bug
在这里插入图片描述

fix问题:

Cross-Site Request Forgery (CSRF)
flask 启动类添加全局变量

csrf = CSRFProtect(app)![在这里插入图片描述](https://img-blog.csdnimg.cn/b145184ddfdc4cd790dbccd5adfb4fef.png)

html post请求

    <form action="{{ url_for('login') }}" method="POST" >
        <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
    </form>

Python, Flask: How to set response header for all responses

@app.after_request
def apply_caching(response):
    response.headers["X-Frame-Options"] = "SAMEORIGIN"
    return response

Security Headers完整配置:

@app.after_request
def apply_caching(response):
    #XSS
    response.headers["X-Frame-Options"] = "SAMEORIGIN"
    response.headers["X-XSS-Protection"] = "0"
    response.headers["X-Content-Type-Options"] = "nosniff"
    response.headers["Content-Type"] = "text/html; charset=utf-8"

    app.config.update(
        SESSION_COOKIE_SECURE=True,
        SESSION_COOKIE_HTTPONLY=True,
        SESSION_COOKIE_SAMESITE='Lax',
    )

    response.set_cookie('username', 'flask', secure=True, httponly=True, samesite='Lax')
    return response

启动问题: zap使用的是jdk1.8我本地安装的是jdk12(支持sonarQube)
Problem starting OWASP ZAP with OpenJDK 11 installed
This application requires a Java Runime Eviroment 1.8.0
https://www.zaproxy.org/faq/what-versions-of-java-are-supported/

Reference:
Download ZAP
https://www.zaproxy.org/download/

CSRF Protection
https://flask-wtf.readthedocs.io/en/1.0.x/csrf/

Security Headers
https://owasp.org/www-community/Security_Headers

Security Considerations
https://flask.palletsprojects.com/en/2.1.x/security/

Python, Flask: How to set response header for all responses
https://stackoverflow.com/questions/30717152/python-flask-how-to-set-response-header-for-all-responses

owasp zap jdk requirement
https://stackoverflow.com/questions/67968805/problem-starting-owasp-zap-with-openjdk-11-installed

test project (zap branch, fix bug)
https://github.com/WillingChin/flaskProject

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值