PyMISP/pymisp/tools/urlobject.py

29 lines
862 B
Python
Raw Normal View History

2019-12-04 15:18:27 +01:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from .abstractgenerator import AbstractMISPObjectGenerator
import logging
2020-01-23 10:27:40 +01:00
from pyfaup.faup import Faup # type: ignore
2019-12-04 15:18:27 +01:00
from urllib.parse import unquote_plus
logger = logging.getLogger('pymisp')
faup = Faup()
class URLObject(AbstractMISPObjectGenerator):
2020-01-23 10:27:40 +01:00
def __init__(self, url: str, standalone: bool=True, **kwargs):
2019-12-04 15:18:27 +01:00
# PY3 way:
# super().__init__('file')
super(URLObject, self).__init__('url', standalone=standalone, **kwargs)
faup.decode(unquote_plus(url))
self.generate_attributes()
def generate_attributes(self):
self.add_attribute('url', value=faup.url.decode())
if faup.get_host():
self.add_attribute('host', value=faup.get_host())
if faup.get_domain():
self.add_attribute('domain', value=faup.get_domain())