Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update modules for better Exception and API key handling #25

Open
2 tasks
deadbits opened this issue Aug 28, 2018 · 1 comment
Open
2 tasks

Update modules for better Exception and API key handling #25

deadbits opened this issue Aug 28, 2018 · 1 comment
Assignees
Labels
bug module New module or module enhancement
Projects

Comments

@deadbits
Copy link
Contributor

  • 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 deadbits added bug module New module or module enhancement labels Aug 28, 2018
@deadbits deadbits self-assigned this Aug 28, 2018
@deadbits deadbits added this to Backlog in Version 1.0 via automation Aug 28, 2018
@deadbits
Copy link
Contributor Author

Completed in development branch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug module New module or module enhancement
Projects
Version 1.0
  
Backlog
Development

No branches or pull requests

1 participant