Exemplo n.º 1
0
 def os(self, os, version):
     '''
     Endpoint that allows to filter by ios family version
     '''
     if self.token != None:
         headers = {
             'Accept': 'application/json',
             'Authorization': 'Bearer ' + self.token
         }
         try:
             loggerService.info(self.api + '/' + os + '?version=' +
                                str(version))
             response = requests.get(self.api + '/' + os + '?version=' +
                                     str(version),
                                     headers=headers,
                                     verify=False)
             if response.status_code == 200:
                 data = [response.json()]
             else:
                 return response.status_code
         except Exception as e:
             loggerService.error('Error trying to get data: ' + str(e))
             data = str(e)
         return data
     else:
         loggerService.error('No valid token available for query')
Exemplo n.º 2
0
    def request_token(self):
        '''
        Get a token from API and make it available for other 
        methods within the class
        '''
        headers = {'Content-Type': 'application/x-www-form-urlencoded'}

        login_info = {
            'client_id': self.key,
            'client_secret': self.secret,
            'grant_type': 'client_credentials'
        }

        try:
            response = requests.post(config['api']['oauth'],
                                     data=login_info,
                                     headers=headers)
            loggerService.info(response)
            if response.status_code == 200 and 'access_token' in response.json(
            ):
                loggerService.info('Token success!')
                loggerService.info('Token:' +
                                   str(response.json()['access_token']))
                self.token_time = datetime.now()
                loggerService.info('Token time:' + str(self.token_time))
                self.token = response.json()['access_token']
                return self.token
        except Exception as e:
            loggerService.error('Error getting token')

        return None
Exemplo n.º 3
0
 def show_bot_advisories(self, os, version):
     '''
     Shows in a pretty way advisories from ios images
     for bot service
     '''
     try:
         data = self.os(os, version)
         i = 0
         result = '<b>Total vulnerabilities: </b>' + str(
             len(data[0]['advisories'])) + '\n'
         result += '-------------------- \n'
         for advisorie in data[0]['advisories']:
             for key, value in advisorie.items():
                 if key == 'advisoryTitle' and i <= 5:
                     result += '<b>' + key + ': </b>' + value + '\n'
                     if 'sir' in advisorie:
                         result += '<b>Severity: </b>' + advisorie[
                             'sir'] + '\n'
                     if 'publicationUrl' in advisorie:
                         result += '<b>Publication Url: </b><a href="' + advisorie[
                             'publicationUrl'][8:] + '">click</a>\n'
                     if 'lastUpdated' in advisorie:
                         result += '<b>Updated: </b>' + advisorie[
                             'lastUpdated'] + '\n'
                     result += '-------------------- \n'
             i += 1
         return result
     except Exception as e:
         loggerService.error(data)
         return 'Empty advisory list'
Exemplo n.º 4
0
 def show_os_advisories(self, os, version):
     '''
     Shows in a pretty way advisories from ios images
     '''
     try:
         data = self.os(os, version)
         self.show_advisories(data[0])
     except Exception as e:
         loggerService.error(data)
Exemplo n.º 5
0
 def save_to_file(self, filename, data):
     '''
     Function that allows to generate a dump information
     with endpoints data
     '''
     try:
         f = open(filename, 'w')
         for line in data:
             f.write(str(line))
         f.close()
     except Exception as e:
         loggerService.error(f"Error trying to create the file {filename}")
         loggerService.error("Error: " + str(e))
 def request(self, endpoint, params=''):
     '''
     Make generic http request
     '''
     headers = {
         'Accept': 'application/json',
         'Authorization': 'Bearer ' + tokenService.get_token()
     }
     try:
         loggerService.info(self.api + '/' + endpoint + params)
         response = requests.get(self.api + '/' + endpoint + params,
                                 headers=headers,
                                 verify=False)
         if response.status_code == 200:
             data = [response.json()]
         else:
             loggerService.error('Error: ' + str(response.json()))
             return response.status_code
     except Exception as e:
         loggerService.error('Error trying to get data: ' + str(e))
         data = str(e)
     return data
Exemplo n.º 7
0
 def all(self):
     '''
     Gets all information available from Cisco Vuln API
     '''
     if self.token != None:
         headers = {
             'Accept': 'application/json',
             'Authorization': 'Bearer ' + self.token
         }
         try:
             loggerService.info(self.api + '/all')
             response = requests.get(self.api + '/all',
                                     headers=headers,
                                     verify=False)
             if response.status_code == 200:
                 data = [response.json()]
             else:
                 return response.status_code
         except Exception as e:
             loggerService.error('Error trying to get data: ' + str(e))
             data = str(e)
         return data
     else:
         loggerService.error('No valid token available for query')
Exemplo n.º 8
0
import sys
sys.path.append('../')
from services.MSTeamsService import send_teams_message
from config.settings import config
from services.loggerService import loggerService

if __name__ == '__main__':
    try:
        msg = sys.argv[1]
        send_teams_message(msg)
    except Exception as e:
        loggerService.error('Missing parameter or error sending message: ' + str(e))
Exemplo n.º 9
0
import sys

sys.path.append('../')
import os
from config.settings import config
from services.loggerService import loggerService
if __name__ == '__main__':
    try:
        env = sys.argv[1]
        if env in config['BUILDING']:
            result = config['BUILDING'][env]
            print(result, end='')
        else:
            loggerService.warning('env not found!')
    except Exception as e:
        loggerService.error('Parameter missing!')