First test targeting Str nodes (binding to all interfaces)

This is the first test to target AST nodes of type Str.  It simply warns
on the existence of any strings matching "0.0.0.0", which indicate a possible
binding to all network interfaces of a network service / listener.
This commit is contained in:
Jamie Finnigan 2014-08-14 15:46:50 -07:00
parent 2d54a6a7a8
commit 7150e10c9b
3 changed files with 39 additions and 0 deletions

View File

@ -11,3 +11,6 @@ call_subprocess_popen = test_calls
call_no_cert_validation = test_calls
call_bad_permissions = test_calls
call_wildcard_injection = test_calls
[Str]
str_hardcoded_bind_all_interfaces = test_strs

5
examples/binding.py Normal file
View File

@ -0,0 +1,5 @@
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('0.0.0.0', 31137))
s.bind(('192.168.0.1', 8080))

31
plugins/test_strs.py Normal file
View File

@ -0,0 +1,31 @@
# -*- coding:utf-8 -*-
#
# Copyright 2014 Hewlett-Packard Development Company, L.P.
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.
"""Defines a set of tests targeting Str nodes in the AST."""
import bandit
from bandit import utils
import ast
import _ast
import re
# Str nodes are pretty simple - likely only basic string-matching tests
# will be defined here
def str_hardcoded_bind_all_interfaces(context):
if context['str'] == '0.0.0.0':
return(bandit.WARN, 'Possible binding to all interfaces')