def normalize(self): self.value = refang(self.value.lower()) if self.value.endswith('.'): self.value = self.value[:-1] self.value = idna.decode(self.value) self.idna = idna.encode(self.value)
def validate_string(cls, string): match = COMPILED_FULL_REGEX.match(refang(string)) if match and ((match.group('search').find('/') != -1) and (hostname.Hostname.validate_string(match.group('host')) or ip.IP.validate_string(match.group('host')))): return True return False
def validate_string(cls, string): string = refang(string) try: ipaddress.ip_address(string) return True except ValueError: return False
def normalize(self): value = refang(self.value.lower()) if value.endswith('.'): value = value[:-1] value = idna.decode(value) serialized = json.loads(self._stix_object.serialize()) serialized['value'] = value self._stix_object = DomainName(**serialized)
def validate_string(cls, string): match = COMPILED_FULL_REGEX.match(string) if match and match.group('pre') != '/' and match.group('post') != '/': value = refang(match.group('search')) if len(value) <= 255 and '_' not in value: parts = extract(value) if parts.suffix and parts.domain: return True return False
def normalize(self): self.value = refang(self.value).lower() if COMPILED_PREFIX_REGEX.match(self.value) is None: # if no schema is specified, assume http:// self.value = 'http://' + self.value # NOTE: url_normalize converts the URL to IDNA, it would be nice to also # keep the encoded URL self.value = url_normalize(self.value) self.parse()
def normalize(self): serialized = json.loads(self._stix_object.serialize()) value = refang(serialized['value']).lower() if COMPILED_PREFIX_REGEX.match(value) is None: # if no schema is specified, assume http:// value = 'http://' + value # NOTE: url_normalize converts the URL to IDNA, it would be nice to also # keep the encoded URL serialized['value'] = url_normalize(value) self._stix_object = StixURL(**serialized)
def normalize(self): self.value = refang(self.value) ipaddr_object = ipaddress.ip_address(self.value) self.value = str(ipaddr_object) self.version = ipaddr_object.version
def test_refang(): """Tests refanging URLs, Hostnames, and IPs""" for test, expected in REFANG_TESTS: assert helpers.refang(test) == expected
def normalize(self): value = str(ipaddress.ip_address(refang(self.value))) self._stix_object = STIXIPv4Address(value=value)