Bandit:一款Python代码安全漏洞检测工具

Bandit是一款用于检测Python代码安全问题的工具,它通过构建AST并运行检测插件来查找常见安全问题。用户可以使用pip安装,通过命令行运行,支持配置参数、基线报告和版本控制集成。此外,Bandit还允许用户扩展编写自定义检测插件。
摘要由CSDN通过智能技术生成

工具介绍

Bandit这款工具可以用来搜索Python代码中常见的安全问题,在检测过程中,Bandit会对每一份Python代码文件进行处理,并构建AST,然后针对每一个AST节点运行相应的检测插件。完成安全扫描之后,Bandit会直接给用户生成检测报告。

工具安装

Bandit使用PyPI来进行分发,建议广大用户直接使用pip来安装Bandit。

创建虚拟环境(可选):

virtualenv bandit-env

安装Bandit:

pip install bandit
# Or if you're working with a Python 3 project
pip3 install bandit

运行Bandit:

bandit -r path/to/your/code

用户还可以使用源码文件直接安装Bandit,先从PyPI下载原tarball,然后运行下列命令:

python setup.py install

工具使用

节点树使用样例:

bandit -r ~/your_repos/project

examples/目录遍历使用样例,显示三行内容,并只报告高危问题:

bandit examples/*.py -n 3 –lll

Bandit还能够结合配置参数一起运行,运行下列命令即可使用ShellInjection来对examples目录运行安全扫描:

bandit examples/*.py -p ShellInjection

Bandit还支持使用标准输入模式来扫描指定行数的代码:

cat examples/imports.py | bandit –

使用样例:

$bandit -h
usage:bandit [-h] [-r] [-a {file,vuln}] [-n CONTEXT_LINES] [-c CONFIG_FILE]
              [-p PROFILE] [-t TESTS] [-sSKIPS] [-l] [-i]
              [-f{csv,custom,html,json,screen,txt,xml,yaml}]
              [--msg-template MSG_TEMPLATE] [-o[OUTPUT_FILE]] [-v] [-d] [-q]
              [--ignore-nosec] [-x EXCLUDED_PATHS] [-bBASELINE]
              [--ini INI_PATH] [--version]
              [targets [targets ...]]
 
Bandit- a Python source code security analyzer
 
positionalarguments:
  targets               source file(s) or directory(s)to be tested
 
optionalarguments:
  -h, --help            show this help message and exit
  -r, --recursive       find and process files in subdirectories
  -a {file,vuln}, --aggregate {file,vuln}
                        aggregate output byvulnerability (default) or by
                        filename
  -n CONTEXT_LINES, --number CONTEXT_LINES
                        maximum number of codelines to output for each issue
  -c CONFIG_FILE, --configfile CONFIG_FILE
                        optional config file touse for selecting plugins and
                        overriding defaults
  -p PROFILE, --profile PROFILE
                        profile to use(defaults to executing all te
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值