omnibus icon indicating copy to clipboard operation
omnibus copied to clipboard

Update modules for better Exception and API key handling

Open deadbits opened this issue 7 years ago • 1 comments

  • [ ] Update all modules so any Exceptions are caught in a way that is OK with Python3.x
    • and so it will past tests NO:
    pass

YES:

    logger.error('Caught exception in module {mod}: {err}'.format(mod=module_name, err=err)
  • [ ] In modules, API keys are returned in Plugin.init. By doing this we have no real way to exit a module w/o raising an exception if an API key is invalid or doesn't exist. Move the API key check to one of the functions the key needs to use so we can log an error message to the user and return from the class gracefully w/o needing to raise an exception

Example:

class Plugin(object):
    def __init__(self, artifact):
        self.artifact = artifact
        self.artifact['data']['censys'] = None
        self.api_key = get_apikey('censys')
        self.headers = {'User-Agent': 'OSINT Omnibus (https://github.com/InQuest/Omnibus)'}

    def run(self):
        if self.api_key == '':
            error('API keys cannot be left blank | set all keys in etc/apikeys.json')
            return

        url = 'https://censys.io/api/v1/view/ipv4{0}'.format(self.artifact['name'])

        try:
            status, response = get(url, auth=(self.api_key['token'], self.api_key['secret']), headers=self.headers)
            if status:
                self.artifact['data']['censys'] = response.json()
        except Exception as err:
            warning('Caught exception in module {0}'.format(err)

def main(artifact):
    plugin = Plugin(artifact)
    plugin.run()
    return plugin.artifact

deadbits avatar Aug 28 '18 11:08 deadbits

Completed in development branch

deadbits avatar Dec 29 '18 16:12 deadbits