pip install bandit
检测是否安装成功, bandit -v (等同于: bandit --version)
(rpa_client) C:\Users\xxxxxx\rpa_client_re\transfer_data>bandit --version
bandit 1.7.4
python version = 3.7.13 (default, Mar 28 2022, 08:03:21) [MSC v.1916 64 bit (AMD64)]
(rpa_client) C:\Users\wang984\Desktop\Rpa_Re\rpa_client_re\transfer_data>bandit -v
usage: bandit [-h] [-r] [-a {file,vuln}] [-n CONTEXT_LINES] [-c CONFIG_FILE]
[-p PROFILE] [-t TESTS] [-s SKIPS]
[-l | --severity-level {all,low,medium,high}]
[-i | --confidence-level {all,low,medium,high}]
[-f {csv,custom,html,json,screen,txt,xml,yaml}]
[--msg-template MSG_TEMPLATE] [-o [OUTPUT_FILE]] [-v] [-d] [-q]
[--ignore-nosec] [-x EXCLUDED_PATHS] [-b BASELINE]
[--ini INI_PATH] [--exit-zero] [--version]
[targets [targets ...]]
-----------------------------------------------
B101 assert_used
B102 exec_used
B103 set_bad_file_permissions
B104 hardcoded_bind_all_interfaces
B105 hardcoded_password_string
B106 hardcoded_password_funcarg
B107 hardcoded_password_default
B108 hardcoded_tmp_directory
B110 try_except_pass
B112 try_except_continue
B201 flask_debug_true
B301 pickle
B302 marshal
B303 md5
B304 ciphers
B305 cipher_modes
B306 mktemp_q
B307 eval
B308 mark_safe
B309 httpsconnection
B310 urllib_urlopen
B311 random
B312 telnetlib
B313 xml_bad_cElementTree
B314 xml_bad_ElementTree
B315 xml_bad_expatreader
B316 xml_bad_expatbuilder
B317 xml_bad_sax
B318 xml_bad_minidom
B319 xml_bad_pulldom
B320 xml_bad_etree
B321 ftplib
B323 unverified_context
B324 hashlib_new_insecure_functions
B325 tempnam
B401 import_telnetlib
B402 import_ftplib
B403 import_pickle
B404 import_subprocess
B405 import_xml_etree
B406 import_xml_sax
B407 import_xml_expat
B408 import_xml_minidom
B409 import_xml_pulldom
B410 import_lxml
B411 import_xmlrpclib
B412 import_httpoxy
B413 import_pycrypto
B501 request_with_no_cert_validation
B502 ssl_with_bad_version
B503 ssl_with_bad_defaults
B504 ssl_with_no_version
B505 weak_cryptographic_key
B506 yaml_load
B507 ssh_no_host_key_verification
B601 paramiko_calls
B602 subprocess_popen_with_shell_equals_true
B603 subprocess_without_shell_equals_true
B604 any_other_function_with_shell_equals_true
B605 start_process_with_a_shell
B606 start_process_with_no_shell
B607 start_process_with_partial_path
B608 hardcoded_sql_expressions
B609 linux_commands_wildcard_injection
B610 django_extra_used
B611 django_rawsql_used
B701 jinja2_autoescape_false
B702 use_of_mako_templates
B703 django_mark_safe
————————————————
1. bandit -r 文件夹地址 (-r 必要参数,标识扫描内容)
2. bandit 文件地址 (eg: bandit test.py)
# 扫描当前文件夹下的所有py文件,并记录在文本呢文件中
1. bandit *.py -o test_bandit.txt -f txt # -o 指定文件
3.扫描结果记录至html文件中
# 扫描工程根目录下的所有文件 .点表示所有!
1. bandit -r . -o test_bandit.html -f html
1. bandit -r . -o test_bandit.html -f html -t B107 仅扫描是否存在B107
2. bandit -r . -o test_bandit.html -f html -t B107,B404 多个问题扫描使用逗号分隔
# 漏洞函数列表内自定义非 危险函数
方法(1):
1. bandit -r . -o test_bandit.html -f html -s B602,B404,B107
2. -s 参数拼接 屏蔽函数ID, 使用,间隔
方法(2):
1. 对扫描文件,具体函数追加注释 # nosec
2. from subprocess import Popen, PIPE # nosec
方法(3):
1. 在扫描文件夹目录中新建.bandit 文件
2. 编辑文件内容
[bandit]
skips: B404
3.多个问题屏蔽
[bandit]
skips: B404,B107,B602