| 121 | raise NotImplementedError |
| 122 | |
| 123 | class ServiceScan(Plugin): |
| 124 | |
| 125 | def __init__(self): |
| 126 | super().__init__() |
| 127 | self.ports = {'tcp':[], 'udp':[]} |
| 128 | self.ignore_ports = {'tcp':[], 'udp':[]} |
| 129 | self.services = [] |
| 130 | self.service_names = [] |
| 131 | self.ignore_service_names = [] |
| 132 | self.run_once_boolean = False |
| 133 | self.require_ssl_boolean = False |
| 134 | self.max_target_instances = 0 |
| 135 | self.max_global_instances = 0 |
| 136 | |
| 137 | @final |
| 138 | def match_service(self, protocol, port, name, negative_match=False): |
| 139 | protocol = protocol.lower() |
| 140 | if protocol not in ['tcp', 'udp']: |
| 141 | print('Invalid protocol.') |
| 142 | sys.exit(1) |
| 143 | |
| 144 | if not isinstance(port, list): |
| 145 | port = [port] |
| 146 | |
| 147 | port = list(map(int, port)) |
| 148 | |
| 149 | if not isinstance(name, list): |
| 150 | name = [name] |
| 151 | |
| 152 | valid_regex = True |
| 153 | for r in name: |
| 154 | try: |
| 155 | re.compile(r) |
| 156 | except re.error: |
| 157 | print('Invalid regex: ' + r) |
| 158 | valid_regex = False |
| 159 | |
| 160 | if not valid_regex: |
| 161 | sys.exit(1) |
| 162 | |
| 163 | service = {'protocol': protocol, 'port': port, 'name': name, 'negative_match': negative_match} |
| 164 | self.services.append(service) |
| 165 | |
| 166 | @final |
| 167 | def match_port(self, protocol, port, negative_match=False): |
| 168 | protocol = protocol.lower() |
| 169 | if protocol not in ['tcp', 'udp']: |
| 170 | print('Invalid protocol.') |
| 171 | sys.exit(1) |
| 172 | else: |
| 173 | if not isinstance(port, list): |
| 174 | port = [port] |
| 175 | |
| 176 | port = list(map(int, port)) |
| 177 | |
| 178 | if negative_match: |
| 179 | self.ignore_ports[protocol] = list(set(self.ignore_ports[protocol] + port)) |
| 180 | else: |
nothing calls this directly
no outgoing calls
no test coverage detected