Example #1
0
    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)
Example #2
0
 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
Example #3
0
 def validate_string(cls, string):
     string = refang(string)
     try:
         ipaddress.ip_address(string)
         return True
     except ValueError:
         return False
Example #4
0
 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)
Example #5
0
 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
Example #6
0
    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()
Example #7
0
    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)
Example #8
0
 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
Example #9
0
def test_refang():
    """Tests refanging URLs, Hostnames, and IPs"""
    for test, expected in REFANG_TESTS:
        assert helpers.refang(test) == expected
Example #10
0
 def normalize(self):
     value = str(ipaddress.ip_address(refang(self.value)))
     self._stix_object = STIXIPv4Address(value=value)