Exemple #1
0
 def get_result_by_api(api_key, email, hash_code):
     url = 'https://www.cmd5.org/api.ashx?email=' + email + '&key=' + api_key + '&hash=' + hash_code
     result = Qhttp.get(url)
     if result.status_code == 200:
         if ':' in result.content.decode():
             error_code = result.content.decode().split(':')[-1]
             if error_code == '-1':
                 raise InvalidInputError(' invalid input ')
             if error_code == '-2':
                 raise InsufficientCredit('InsufficientCredit')
             if error_code == '-3':
                 raise NetworkError('server failed on cmd5.org')
             if error_code == '-4':
                 raise InvalidInputError('unknown sipher text')
             if error_code == '-7':
                 raise InvalidInputError('hash type not supported')
             if error_code == '-999':
                 raise NetworkError('some thing wrong with cmd5.org')
         try:
             return_result = {'results': result.json()}
             return return_result
         except Exception:
             ResultNotFoundError(' unknown result format ')
     else:
         raise NetworkError(result.status_code)
Exemple #2
0
    def run(self):
        parser_data = self.params.get('data')
        if parser_data is None:
            raise InvalidInputError(' missing data keyword')

        # if input data has not method_id keyword raise exception
        if 'method_id' not in parser_data.keys():
            raise InvalidInputError('missing method_id keyword')
        if parser_data['method_id'] == 1:
            # if input data has not api_key keyword raise exception
            if 'api_key' not in parser_data.keys():
                raise InvalidInputError('missing api_key keyword')

            # if input data has not term keyword raise exception
            if 'term' not in parser_data.keys():
                raise InvalidInputError('missing term keyword')

            api_key = parser_data['api_key']
            query = parser_data['term']
            search = BingSearch(api_key, parent=self)
            if 'max_result' in parser_data:
                page_number = parser_data['max_result']
            else:
                page_number = search.pages
            self.result = search.api_searching(query, page_number)
        else:
            raise InvalidInputError('invalid method_id')
Exemple #3
0
 def whois_history(self, domain, api_key):
     """
     :param domain: whois_history domain requested
     :param api_key: optional, for whoxy.com api
     return whois info of domain
     """
     if not (validators.domain(domain)):
         raise InvalidInputError('invalid domain')
     try:
         url_request = "http://api.whoxy.com/?key=%s&history=%s" % (api_key,
                                                                    domain)
         with urllib.request.urlopen(url_request) as url:
             data = json.loads(url.read().decode())
             if 'status_reason' in data:
                 if data['status_reason'] == 'Incorrect API Key':
                     raise WrongApiKeyError('wrong or invalid api key')
                 else:
                     raise InvalidInputError(data['status_reason'])
             elif 'status' in data:
                 if data['status'] == 0:
                     raise InternalModuleError(
                         ' something goes wrong in api')
             if 'whois_records' not in data:
                 raise ResultNotFoundError(
                     'cant find any result for your request')
     except URLError:
         raise NetworkError('can not access whoxy.com')
     if self.parent:
         self.parent.check_point()
     result = {'results': self.parse_history(data['whois_records'])}
     return result
Exemple #4
0
    def run(self):
        parser_data = self.params.get('data')
        # if input data has not data keyword raise exception
        if parser_data is None:
            raise InvalidInputError(' missing data keyword')
        # if input data has not method_id keyword raise exception
        if 'method_id' not in parser_data.keys():
            raise InvalidInputError('missing method_id keyword')
        if parser_data['method_id'] == 1:
            # if input data has not term keyword raise exception
            if 'term' not in parser_data.keys():
                raise InvalidInputError('missing term keyword')

            # set values
            query = parser_data['term']
            # create GoogleSearch object and set number of expected result
            search = GoogleSearch(parent=self)
            if 'max_result' in parser_data:
                page_number = parser_data['max_result']
            else:
                page_number = search.page

            self.result = search.search(query, pages=page_number)

        else:
            raise InvalidInputError('invalid method_id')
Exemple #5
0
    def friends_list(self, user_id, count=None):
        """
        :param user_id: string, use as a user_id or screen_name search
        :param count: number of result
        :return: search result
        """
        self.update_progressbar(
            'request submitted successfully, request to twitter: friends_list',
            20)
        try:  # set request to twitter api, using different link if use id or screen_name and use count or not
            int(user_id)
            if count is not None:
                if count > 200:
                    count = 200
                timeline_endpoint = "https://api.twitter.com/1.1/friends/list.json?user_id=%s&count=%s" % (
                    str(user_id), str(count))
            else:
                timeline_endpoint = "https://api.twitter.com/1.1/friends/list.json?user_id=%s&count=%s" % (
                    str(user_id), str(self.default_number))
        except ValueError:
            if count is not None:
                if count > 200:
                    count = 200
                timeline_endpoint = "https://api.twitter.com/1.1/friends/list.json?screen_name=%s&count=%s" % (
                    str(user_id), str(count))
            else:
                timeline_endpoint = "https://api.twitter.com/1.1/friends/list.json?screen_name=%s&count=%s" % (
                    str(user_id), str(self.default_number))

        try:  # set request to twitter api
            if self.parent:
                self.parent.check_point()
            response, data = self.client.request(timeline_endpoint)
        except Exception:
            raise NetworkError('can not connect to twitter')
        self.update_progressbar('received data from api', 40)
        if self.parent:
            self.parent.check_point()
        if 'status' not in response:  # somethings goes wrong
            raise InvalidInputError("status not found")
        if response['status'] != '200':  # something goes wrong
            data_loads = json.loads(str(bytes.decode(data)))
            if data_loads['errors'][-1]['message'] == 'Rate limit exceeded':
                raise TwitterApiConstraint(
                    'Twitter rejected 3 consecutive attempts to access its API under your '
                    'Twitter account ')
            else:
                raise InvalidInputError(data_loads['errors'][-1]['message'])
        # parse result
        data_loads = json.loads(str(bytes.decode(data)))
        self.update_progressbar('parse_result', 75)
        return_result = Twitter.__parse_search(self, data_loads['users'])[0]
        return_result['has_media'] = True
        return return_result
Exemple #6
0
    def set_module_config(data):
        """
        :param  data: dictionary that contain data keyword, and value of that, is list of module_config
        like : {data:{[{module_1_config},{module_2_config}, ...]}}
        :return: status and message
        :rtype: dict
        """

        try:
            module_list = data['data']
            for module in module_list:
                # updating module category and active
                try:  # catch error if code does not exist
                    query = ModuleModel.select().where(
                        ModuleModel.code == module['code'])
                except DoesNotExist:
                    raise InvalidInputError(' can not find ' +
                                            str(module['code']))
                try:  # try updating
                    query = ModuleModel.update(
                        category=module['category'],
                        active=module['active']).where(
                            ModuleModel.code == module['code'])
                    query.execute()
                except Exception:
                    raise DatabaseError(' can not access database')

            # return status of operation
            return {
                'data': 'module_config update successfully',
                'status': constants.STATUS_SUCCESS
            }
        except KeyError as e:  # Occurs if one of config keyword missing in input
            return {'data': e, 'status': constants.STATUS_ERROR}
Exemple #7
0
    def search(self, query, count):
        """
        :param query: string, use as a query search
        :param count: string, use as a number of search result
        :return: search result
        """
        self.update_progressbar(
            'request submitted successfully, request to twitter: search query',
            20)

        if count is not None:
            if count > 200:
                count = 200
            timeline_endpoint = "https://api.twitter.com/1.1/users/search.json?q=%s&count=%s" % (
                query, str(count))

        else:
            timeline_endpoint = "https://api.twitter.com/1.1/users/search.json?q=%s&count=%s" % \
                                (query, str(self.default_number))

        try:  # set request to twitter api, using different link if use id or screen_name
            if self.parent:
                self.parent.check_point()
            response, data = self.client.request(timeline_endpoint)
        except Exception as e:  # can not access twitter
            raise NetworkError(e)
        self.update_progressbar('received data from api', 40)
        if self.parent:
            self.parent.check_point()
        if 'status' not in response:  # some thing goes wrong
            raise InvalidInputError("status not found")
        if response['status'] != '200':  # something goes wrong
            data_loads = json.loads(str(bytes.decode(data)))

            if data_loads['errors'][-1]['message'] == 'Rate limit exceeded':
                raise TwitterApiConstraint(
                    'Twitter rejected 3 consecutive attempts to access its API under your '
                    'Twitter account ')
            else:
                raise InvalidInputError(data_loads['errors'][-1]['message'])
        data_loads = json.loads(str(bytes.decode(data)))

        self.update_progressbar('parse_result', 75)
        # parse results
        return_result = Twitter.__parse_search(self, data_loads)[0]
        return_result['has_mdia'] = True
        return return_result
Exemple #8
0
 def run(self):
     # fet parameter from input
     parsed_data = self.params.get('data')
     if parsed_data is None:
         raise InvalidInputError('missing data keyword')
     if 'method_id' not in parsed_data.keys():
         raise InvalidInputError('missing method_id keyword')
     if parsed_data['method_id'] == 1:
         if 'domain' in parsed_data.keys():
             if not (validators.domain(parsed_data['domain'])):
                 raise InvalidInputError('invalid domain')
             sm = SimilarDomain(parent=self)
             self.result = sm.generate_domains(parsed_data['domain'])
         else:
             raise InvalidInputError(' missing domain keyword')
     else:
         raise InvalidInputError('invalid method_id')
Exemple #9
0
    def get_whois_by_domain(self, domain):
        """
        :param domain: whois domain requested
        return whois info of domain
        """
        if not (validators.domain(domain)):
            raise InvalidInputError('invalid domain')

        # use manual whois module for .ir domains
        try:  # using old version of whois

            whois = Whois(parent=self)
            parser = Parser()
            whois_res, dns = whois.get_whois_with_zone(domain)
        except gaierror:  # raise when can not access network
            raise NetworkError('Unable to find the server')
        has_dns = True
        if not dns:
            has_dns = False
        if whois_res == -1:
            raise IncorrectDataError('whois server not found for your domain ')
        unstructured_res = parser.get_main_srtucture(whois_res,
                                                     has_dns=has_dns)
        email_res = parser.get_emails(whois_res)
        phone_res = parser.get_phones(whois_res)
        name_res = parser.get_names(whois_res)
        result_list = []
        properties_list = []
        special_properties_list = []
        result = {'results': []}
        # create structure data from result
        if unstructured_res:
            result_list.append(unstructured_res['results'])
            special_properties_list = (unstructured_res['special_properties'])
            properties_list = (unstructured_res['properties'])
        # saving emails, phone, names in list of results
        for email in email_res:
            if email:
                result_list.append(email)
        for phone in phone_res:
            if phone:
                result_list.append(phone)
        for name in name_res:
            if name:
                result_list.append(name)
        # if our output is empty, create empty skeleton
        if len(special_properties_list) == 0:
            result['special_properties'] = ''
        else:
            result['special_properties'] = special_properties_list
        if len(properties_list) == 0:
            result['properties'] = ''
        else:
            result['properties'] = properties_list

        result['results'] = result_list
        return result
Exemple #10
0
    def run(self):
        parse_data = self.params.get('data')
        if parse_data is None:
            raise InvalidInputError(' missing data keyword')
        # if input data has not method_id keyword raise exception
        if 'method_id' not in parse_data.keys():
            raise InvalidInputError('missing method_id keyword')
        if parse_data['method_id'] == 1:
            if 'url' not in parse_data.keys():
                raise InvalidInputError(' missing url keyword')

            url = parse_data['url']
            if not (validators.url(url)):
                raise InvalidInputError('url not valid')

            # get dep from data
            if 'depth' in parse_data.keys():
                dep = parse_data['depth']
            else:
                dep = 1

            # get link_limit from data
            if 'link_limit' in parse_data.keys():
                if str(parse_data['link_limit']).isdigit():
                    link_limit = int(parse_data['link_limit'])
                else:
                    link_limit = 2000
            else:
                link_limit = 2000

            # get base_url_constraint from data
            if 'base_url_constraint' in parse_data.keys():
                if parse_data['base_url_constraint'] in [
                        True, 'True', 1, 'true', '1'
                ]:
                    data = urlparse(url)
                    base_url = data.scheme + '://' + data.netloc
                else:
                    base_url = None
            else:
                base_url = None
            self.crawl(base_url, link_limit, [url], dep, dep)
        else:
            raise InvalidInputError('invalid method_id')
Exemple #11
0
    def prepare(self):
        """
        convert json to dict and assign value to self.params

        :raise InternalModuleError: when data is not a valid json
        """
        try:
            # ApiLogging.info(str(self.__task_model.data) + str(type(self.__task_model.data)))
            self.params = json.loads(self.__task_model.data.decode())
        except Exception:  # JSONDecodeError
            raise InvalidInputError('Invalid input format')
Exemple #12
0
def get_whois_by_email(email, api_key):
    """
    :param email: whois email requested
    :param api_key: optional, for whoxy.com api
    return whois info of domain
    """
    pattern = re.compile("[\w\.-]+@[\w\.-]+\.\w+")
    if (pattern.match(email)) == None:
        raise InvalidInputError('email format is invalid')
    try:
        url_request = "http://api.whoxy.com/?key=%s&reverse=whois&email=%s" % (
            api_key, email)
        with urllib.request.urlopen(url_request) as url:
            data = json.loads(url.read().decode())
            if 'status_reason' in data:
                if data['status_reason'] == 'Incorrect API Key':
                    raise WrongApiKeyError('wrong or invalid api key')
                else:
                    raise InvalidInputError(data['status_reason'])
    except URLError:
        raise NetworkError('can not access whoxy.com')
    result = {'results': parse_reverse(data)}
    return result
Exemple #13
0
    def run(self):
        parser_data = self.params.get('data')
        if parser_data is None:
            raise InvalidInputError(' missing data keyword')

        # if input data has not method_id keyword raise exception
        if 'method_id' not in parser_data.keys():
            raise InvalidInputError('missing method_id keyword')
        if parser_data['method_id'] == 1:
            # if input data has not term keyword raise exception
            if 'term' not in parser_data.keys():
                raise InvalidInputError('missing term keyword')

            query = parser_data['term']
            search = BingSearch(parent=self)
            # use default page number or on user demand
            if 'max_result' in parser_data:
                page_number = parser_data['max_result']
            else:
                page_number = search.page
            self.result = search.search(query, page_number)
        else:
            raise InvalidInputError('invalid method_id')
Exemple #14
0
    def run(self):
        parser_data = self.params.get('data')
        if parser_data is None:
            raise InvalidInputError('missing data keyword')

        if 'method_id' in parser_data.keys():
            method_id = parser_data['method_id']
        else:
            raise InvalidInputError('missing method_id keyword')

        if 'email' in parser_data.keys():
            email = parser_data['email']
        else:
            raise InvalidInputError('missing email keyword')

        if 'password' in parser_data.keys():
            password = parser_data['password']
        else:
            raise InvalidInputError('missing password keyword')

        if 'region' in parser_data.keys():
            region = parser_data['region']
        else:
            raise InvalidInputError('missing region keyword')

        if 'number' in parser_data.keys():
            number = parser_data['number']
        else:
            raise InvalidInputError('missing number keyword')

        if method_id == 1:
            subprocess.call([
                'python3',
                '/home/dpe/PycharmProjects/F.SystemAPI.01/modules/truecaller/v_1_0/truecaller.py',
                email, password, region, number, self.task_model.process_id
            ])

            result_path = os.path.dirname(
                os.path.dirname(
                    os.path.dirname(os.path.dirname(
                        os.path.abspath(__file__))))
            ) + '/modules/truecaller/v_1_0/storage/' + self.task_model.process_id + '.pkl'
            try:
                with open(result_path, 'rb') as f:
                    content = pickle.load(f)
                    f.close()
                os.remove(result_path)
            except Exception as e:
                print(e)
        else:
            raise InvalidInputError('no such method id has been found')
Exemple #15
0
 def get_whois_by_domain_api(self, domain, api_key=None):
     # using api, for all domain except whois Retrieval failed error in api, that sent to old whois
     # if input data has not api_key keyword raise exception
     if domain.split('.')[-1] == 'ir':
         return self.get_whois_by_domain(domain)
     else:
         if api_key is None:
             raise InvalidInputError('missing api_key keyword')
         self.check_point()
         self.update_progressbar('connecting to whois_api', 40)
         whois_api = WhoisApi(api_key, domain, parent=self)
         try:
             whois_res = whois_api.get_result()
         except InvalidInputError:
             return self.get_whois_by_domain(domain)
         return whois_res
Exemple #16
0
    def search_number(self, number):
        if not self.isLoggedIn:
            self.login()
        contacts = []
        return_result = ''
        contact = dict()
        if not str(int(number)).isdigit():
            raise InvalidInputError('invalid phone number format')
        contact["phone_numbers"] = [number]
        contact["first_name"] = number
        contact["email_addresses"] = []
        contacts.append(contact)

        r = self.session.post(url=Instagram.sync_address_book_url,
                              data="contacts=" + json.dumps(contacts),
                              headers=self.headers)

        if r.status_code == 200:
            lastJson = json.loads(r.text)
            result = lastJson
            if result["status"] != "ok":
                raise ResultNotFoundError(' result is not ok')
            for item in result["items"]:
                try:
                    return_result = parse_search_contact(
                        item['user'], self.process_id)

                except Exception:
                    continue
            a = self.session.post(url=Instagram.unlink_address_book_url,
                                  headers=self.headers)
            if return_result:
                return return_result
            else:
                a = self.session.post(url=Instagram.unlink_address_book_url,
                                      headers=self.headers)
                raise ResultNotFoundError(
                    'user that belong to this phone number not found')
        else:
            a = self.session.post(url=Instagram.unlink_address_book_url,
                                  headers=self.headers)
            raise ResultNotFoundError(r.text)
Exemple #17
0
 def __domain_validate(self, domain):
     """
     :param domain: determine domain input
     :return: normalized and validate doamin if domain input is valid
     """
     valid_domain = None
     try:
         valid_domain = re.search(
             r'(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,6}',
             domain)
     except TypeError:
         pass
     if valid_domain is None:
         raise InvalidInputError("domain format is not valid!")
     domain = valid_domain.group(0)
     if not re.match(r'http(s?):', domain):
         domain = 'http://' + domain
     domain = urlparse(domain).netloc
     if domain.startswith("www"):
         domain = domain.replace("www.", "")
     return domain
Exemple #18
0
def get_whois_by_name(name, api_key):
    """
    :param name: whois name requested
    :param api_key: optional, for whoxy.com api
    return whois info of name
    """
    try:
        if ' ' in name:
            name = name.replace(' ', '+')
        url_request = "http://api.whoxy.com/?key=%s&reverse=whois&name=%s" % (
            api_key, name)
        with urllib.request.urlopen(url_request) as url:
            data = json.loads(url.read().decode())
            if 'status_reason' in data:
                if data['status_reason'] == 'Incorrect API Key':
                    raise WrongApiKeyError('wrong or invalid api key')
                else:
                    raise InvalidInputError(data['status_reason'])
    except URLError:
        raise NetworkError('can not access whoxy.com')
    result = {'results': parse_reverse(data)}
    return result
Exemple #19
0
    def check_balance(api_key):
        try:
            balance = ''
            key = api_key
            url_request = "http://api.whoxy.com/?key=%s&account=balance" % (key)
            with urllib.request.urlopen(
                    url_request) as url:
                data = json.loads(url.read().decode())
                if 'status_reason' in data:
                    if data['status_reason'] == 'Incorrect API Key':
                        raise WrongApiKeyError('wrong or invalid api key')
                    else:
                        raise InvalidInputError(data['status_reason'])

                if 'live_whois_balance' in data:
                    balance = data['live_whois_balance']

            if balance:
                return balance
            else:
                return 'can not get balance'
        except URLError:
            raise NetworkError('can not access whoxy.com')
Exemple #20
0
    def run(self):
        parser_data = self.params.get('data')
        if parser_data is None:
            raise InvalidInputError('missing data keyword')

        if 'method_id' not in parser_data.keys():
            raise InvalidInputError('missing method_id keyword')
        if 'username' not in parser_data.keys():
            raise InvalidInputError('missing username keyword')
        if 'password' not in parser_data.keys():
            raise InvalidInputError('missing password keyword')

        method_id = parser_data['method_id']
        username = parser_data['username']
        password = parser_data['password']

        if 'max_result' in parser_data.keys():
            number = int(parser_data['max_result'])  # optional
        else:
            number = None

        linkedin = Linkedin(username, password, parent=self)

        if method_id == 1:
            if 'linkedin_id' not in parser_data.keys():
                raise InvalidInputError('missing linkedin_id keyword')
            else:
                linkedin_id = parser_data['linkedin_id']
                self.result = linkedin.profile(linkedin_id)

        elif method_id == 2:
            if 'query' not in parser_data.keys():
                raise InvalidInputError('missing query keyword')
            else:
                query = parser_data['query']
                self.result = linkedin.search(query, number=number)

        else:
            raise InvalidInputError('no such method id has been found')
Exemple #21
0
    def run(self):
        # checking input and keys
        parser_data = self.params.get('data')
        if parser_data is None:
            raise InvalidInputError(' missing data keyword')

        if 'method_id' not in parser_data.keys():
            raise InvalidInputError('missing method_id keyword')
        if 'api_key' not in parser_data.keys():
            raise InvalidInputError('missing api_key keyword')

        # get value from input dic and set on local variable
        method_id = parser_data['method_id']
        api_key = parser_data['api_key']

        # initializing IP2Location object
        ip2location = IP2Location(api_key, parent=self)

        # get ip info
        if method_id == 1:
            if 'ip' not in parser_data.keys():
                raise InvalidInputError('missing ip keyword')
            self.result = ip2location.get_ip_info(parser_data['ip'])

        # check if ip is proxy
        elif method_id == 2:

            if 'ip' not in parser_data.keys():
                raise InvalidInputError('missing ip keyword')

            self.result = ip2location.ip_is_proxy(parser_data['ip'])
        # check api_balance
        elif method_id == 3:
            self.result = ip2location.get_ip_info_balance()
        elif method_id == 4:
            self.result = ip2location.get_ip_is_proxy_balance()
        else:
            raise InvalidInputError('invalid method_id')
Exemple #22
0
    def run(self):
        # checking input and keys
        parser_data = self.params.get('data')
        if parser_data is None:
            raise InvalidInputError(' missing data keyword')

        if 'method_id' not in parser_data.keys():
            raise InvalidInputError('missing method_id keyword')
        if 'consumer_key' not in parser_data.keys():
            raise InvalidInputError('missing consumer_key keyword')
        if 'consumer_secret' not in parser_data.keys():
            raise InvalidInputError('missing consumer_secret keyword')
        if 'access_key' not in parser_data.keys():
            raise InvalidInputError('missing access_key keyword')
        if 'access_secret' not in parser_data.keys():
            raise InvalidInputError('missing access_secret keyword')

        # get value from input dic and set on local variable
        method_id = parser_data['method_id']
        consumer_key = parser_data['consumer_key']
        consumer_secret = parser_data['consumer_secret']
        access_key = parser_data['access_key']
        access_secret = parser_data['access_secret']
        if 'max_result' in parser_data.keys():
            number = parser_data['max_result']  # optional
        else:
            number = None

        # initializing Twitter object
        twitter = Twitter(consumer_key,
                          consumer_secret,
                          access_key,
                          access_secret,
                          parent=self)

        # search twitter by query
        if method_id == 1:
            if 'query' not in parser_data.keys():
                raise InvalidInputError('missing query keyword')
            else:
                query = parser_data['query']
                self.result = twitter.search(query, number)

        # show user by username
        elif method_id == 2:
            if 'user_id' not in parser_data.keys():
                raise InvalidInputError('missing user_id keyword')
            else:
                user_id = parser_data['user_id']
                self.result = twitter.show_user(user_id)

        # get_friends by username
        elif method_id == 3:
            if 'user_id' not in parser_data.keys():
                raise InvalidInputError('missing user_id keyword')
            else:
                user_id = parser_data['user_id']
                self.result = twitter.friends_list(user_id, number)

        # get_followers by username
        elif method_id == 4:
            if 'user_id' not in parser_data.keys():
                raise InvalidInputError('missing user_id keyword')
            else:
                user_id = parser_data['user_id']
                self.result = twitter.follower_list(user_id, number)

        else:
            raise InvalidInputError('invalid method_id')
Exemple #23
0
    def run(self):
        parsed_data = self.params.get('data')
        if parsed_data is None:
            raise InvalidInputError('missing data keyword')
        try:
            if 'on_demand' in parsed_data:
                on_demand = parsed_data['on_demand']
                on_demand = ast.literal_eval(on_demand)
                if len(on_demand) == 0:
                    on_demand = [1, 2, 3, 4, 5, 12]
            else:
                on_demand = [1, 2, 3, 4, 5, 12]

        except Exception:
            on_demand = [1, 2, 3, 4, 12]
        if 'method_id' not in parsed_data.keys():
            raise InvalidInputError('missing method_id keyword')

        if 'region' in parsed_data:
            region = parsed_data['region']
        else:
            region = None

        if parsed_data['method_id'] == 1:
            # if method_id==1 parse content
            if 'content' not in parsed_data.keys():
                raise InvalidInputError('missing content keyword')
            parser_data = parsed_data['content']

        elif parsed_data['method_id'] == 2:
            # if method_id==2 parse from file
            if 'path' not in parsed_data.keys():
                raise InvalidInputError('missing path keyword')
            path = parsed_data['path']

            is_exists = os.path.exists(path)
            if is_exists:
                f = open(path, 'rb')
                parser_data = f.read().decode()
                f.close()

            else:

                parser_data = ""

        else:
            raise InvalidInputError('wrong method_id')

        self.check_point()
        parse = ParseElements()
        fetch = FetchResult()
        return_list = {}
        known_account = []
        e = []
        u = []
        p = []
        i = []
        d = []
        a = []
        if 2 in on_demand:
            # parsing emails from data
            emails = parse.parse_email(content=parser_data)

        else:
            emails = []
        if 4 in on_demand:
            # parsing phone from data
            phones = parse.parse_phone(content=parser_data, region=region)
        else:
            phones = []

        if 3 in on_demand:
            # parsing ip from data
            ips = parse.parse_ip(content=parser_data)
        else:
            ips = []

        if 1 in on_demand or 12 in on_demand or 5 in on_demand:
            # parsing url from data
            urls = parse.parse_url(content=parser_data)
        else:
            urls = []

        self.check_point()
        self.update_progressbar("extract phone, ip, email, urls from text ",
                                50)

        # preparing result
        for email in emails:
            email = email.replace("'", '')
            email = email.replace('"', '')
            if fetch.prepare_email_result(email) is None:
                continue
            else:
                e.append(fetch.prepare_email_result(email))

        for url in urls:
            # separating url and domain from each other
            if str(url).startswith('https://www.facebook.com/') or \
                str(url).startswith('https://www.twitter.com/') or \
                    str(url).startswith('https://www.instagram.com/'):

                if fetch.prepare_account(url) is None:
                    pass
                else:
                    if url not in known_account:
                        known_account.append(url)
                        a.append(fetch.prepare_account(url))
            if fetch.prepare_url_result(url) is None:
                pass
            else:
                u.append(fetch.prepare_url_result(url))
            if fetch.prepare_domain_name_result(url) is None:
                continue
            else:
                d.append(fetch.prepare_domain_name_result(url))
        # checking on demand input
        if 1 not in on_demand:
            u = []
        if 12 not in on_demand:
            d = []
        if 5 not in on_demand:
            a = []
        for phone in phones:
            phone = phone.replace("'", '')
            phone = phone.replace('"', '')
            p.append(fetch.prepare_phone_result(phone))

        for ip in ips:
            ip = ip.replace("'", '')
            ip = ip.replace('"', '')
            i.append(fetch.prepare_ip_result(ip))
        self.update_progressbar(" preparing result ", 100)

        return_list["results"] = e + u + p + i + d + a

        self.result = return_list
Exemple #24
0
    def run(self):
        # checking input and keys
        parser_data = self.params.get('data')
        if parser_data is None:
            raise InvalidInputError(' missing data keyword')
        if 'method_id' not in parser_data.keys():
            raise InvalidInputError('missing method_id keyword')
        if 'username' not in parser_data.keys():
            raise InvalidInputError('missing username keyword')
        if 'password' not in parser_data.keys():
            raise InvalidInputError('missing password keyword')
        # get value from input dic and set on local variable
        method_id = parser_data['method_id']
        username = parser_data['username']
        password = parser_data['password']

        if 'max_result' in parser_data.keys() and str(
                parser_data['max_result']).isdigit():
            if int(parser_data['max_result']) > 0:
                number = int(parser_data['max_result'])  # optional
            else:
                number = 20
        else:
            number = 20

        # initializing Instagram object
        instagram = Instagram(username, password, number, parent=self)

        # show user_id info in instagram
        if method_id == 1:
            if 'user_id' not in parser_data.keys():
                raise InvalidInputError('missing user_id keyword')
            else:
                user_id = parser_data['user_id']
                self.result = instagram.profile(user_id)[0]

        elif method_id == 2:
            if 'user_id' not in parser_data.keys():
                raise InvalidInputError('missing user_id keyword')
            else:
                user_id = parser_data['user_id']
                self.result = instagram.get_follower_following(
                    user_id, 'follower')

        elif method_id == 3:
            if 'user_id' not in parser_data.keys():
                raise InvalidInputError('missing user_id keyword')
            else:
                user_id = parser_data['user_id']
                self.result = instagram.get_follower_following(
                    user_id, 'following')

        elif method_id == 4:
            if 'phone_number' not in parser_data.keys():
                raise InvalidInputError('missing phone_number keyword')
            else:
                phone_number = parser_data['phone_number']
                self.result = instagram.search_number(phone_number)

        elif method_id == 5:
            if 'query' not in parser_data.keys():
                raise InvalidInputError('missing user_id keyword')
            else:
                query = parser_data['query']
                self.result = instagram.search_by_query(query)
        else:
            raise InvalidInputError(' in valid method_id')
Exemple #25
0
    def run(self):
        result = ''
        parser_data = self.params.get('data')
        if parser_data is None:
            raise InvalidInputError(' missing data keyword')

        if 'method_id' not in parser_data.keys():
            raise InvalidInputError('missing method_id keyword')
        if 'username' not in parser_data.keys():
            raise InvalidInputError('missing username keyword')
        if 'password' not in parser_data.keys():
            raise InvalidInputError('missing password keyword')

        method_id = parser_data['method_id']
        username = parser_data['username']
        password = parser_data['password']

        if 'max_result' in parser_data.keys():
            number = int(parser_data['max_result'])  # optional
        else:
            number = None
        facebook = Facebook(username, password, parent=self)

        # check_profile, parameter: facebook_id( alias or id)
        if method_id == 1:
            if 'facebook_id' not in parser_data.keys():
                raise InvalidInputError('missing facebook_id keyword')
            else:
                facebook_id = parser_data['facebook_id']
                result = facebook.profile(facebook_id)

        # get_friends, parameter: facebook_id( alias or id)
        elif method_id == 2:
            if 'facebook_id' not in parser_data.keys():
                raise InvalidInputError('missing facebook_id keyword')

            else:
                facebook_id = parser_data['facebook_id']
                result = facebook.get_friends(facebook_id, number)

        # get_follower, parameter: facebook_id( alias or id)
        elif method_id == 3:
            if 'facebook_id' not in parser_data.keys():
                raise InvalidInputError('missing facebook_id keyword')

            else:
                facebook_id = parser_data['facebook_id']
                result = facebook.get_followers(facebook_id, number)

        # get_following, parameter: facebook_id( alias or id)
        elif method_id == 4:
            if 'facebook_id' not in parser_data.keys():
                raise InvalidInputError('missing facebook_id keyword')

            else:
                facebook_id = parser_data['facebook_id']
                result = facebook.get_following(facebook_id, number)

        # search_all, parameter: term
        elif method_id == 5:
            if 'term' not in parser_data.keys():
                raise InvalidInputError('missing term keyword')

            else:
                query = parser_data['term']
                result = facebook.search_all(query, number)
        if result:
            self.result = result
        else:
            raise InvalidInputError('no such method id has been found')
Exemple #26
0
    def show_user(self, user_id):
        """
        :param user_id: string, use as a user_id or screen_name search
        :return: search result
        """
        return_result = {'results': [], 'has_media': True}
        self.update_progressbar(
            'request submitted successfully, request to twitter: show user',
            20)
        try:  # set request to twitter api, using different link if use id or screen_name
            int(user_id)
            timeline_endpoint = "https://api.twitter.com/1.1/users/show.json?user_id=%s" % (
                str(user_id))
        except ValueError:
            timeline_endpoint = "https://api.twitter.com/1.1/users/show.json?screen_name=%s" % (
                str(user_id))

        try:
            if self.parent:
                self.parent.check_point()
            response, data = self.client.request(timeline_endpoint)
        except Exception:
            raise NetworkError('can not connect to twitter')
        self.update_progressbar('received data from api', 40)
        if self.parent:
            self.parent.check_point()
        if 'status' not in response:  # something goes wrong
            raise InvalidInputError("status not found")
        if response['status'] != '200':  # something goes wrong
            data_loads = json.loads(str(bytes.decode(data)))
            if data_loads['errors'][-1]['message'] == 'Rate limit exceeded':
                raise TwitterApiConstraint(
                    'Twitter rejected 3 consecutive attempts to access its API under your '
                    'Twitter account ')
            else:
                raise InvalidInputError(data_loads['errors'][-1]['message'])
        data_loads = json.loads(str(bytes.decode(data)))
        info = [data_loads]
        # extract json demand format from parse result
        self.update_progressbar('parse_result', 75)
        return_value = Twitter.__parse_search(self, info)
        result = return_value[0]
        entity_list = return_value[1]
        return_result['special_properties'] = result['results'][-1][
            'special_properties']
        return_result['properties'] = result['results'][-1]['properties']

        for item in entity_list:
            data = {'data': '', 'type': ''}
            ref = {
                'ref': {
                    'task': 'twitter_profile',
                    'twitter_account': user_id,
                    'section': ''
                }
            }
            if 'name' in item.keys():
                data['data'] = item['name']
                data['type'] = 11
                ref['ref']['section'] = 'name'

            if 'location' in item.keys():
                ref['ref']['section'] = 'location'
                data['data'] = item['location']
                data['type'] = 8

            if 'screen_name' in item.keys():
                ref['ref']['section'] = 'screen_name'
                data['data'] = item['screen_name']
                data['type'] = 5

            data.update(ref)
            return_result['results'].append(data)
        return return_result
Exemple #27
0
    def get_result(self):
        """
        :return: whois info of domain
        """
        # build a whois request
        try:
            key = self.api_key
            domain = self.domain
            url_request = "http://api.whoxy.com/?key=%s&whois=%s" % (key, domain)
            with urllib.request.urlopen(
                    url_request) as url:
                data = json.loads(url.read().decode())
                if 'status_reason' in data:
                    if data['status_reason'] == 'Incorrect API Key':
                        raise WrongApiKeyError(data['status_reason'])
                    else:
                        raise InvalidInputError(data['status_reason'])
        except URLError:
            raise NetworkError('can not access whoxy.com')
        self.parent.check_point()
        self.update_progressbar('parsing result', 80)
        unstructured_res = WhoisApi.parse_unstructure(data)
        email_res = WhoisApi.get_emails(data)
        phone_res = WhoisApi.parse_phone(data)
        name_res = WhoisApi.get_names(data)

        result_list = []
        properties_list = []
        special_properties_list = []

        result = {'results': [], 'special_properties': [], 'properties': []}

        # create structure data from result
        if unstructured_res:
            result_list.append(unstructured_res['results'])
            special_properties_list = (unstructured_res['special_properties'])
            properties_list = (unstructured_res['properties'])

        # saving emails, phone, names in list of results
        for email in email_res:
            if email:
                result_list.append(email)
        for phone in phone_res:
            if phone:
                result_list.append(phone)

        for name in name_res:
            if name:
                result_list.append(name)

        if len(special_properties_list) == 0:
            result['special_properties'] = ''
        else:
            result['special_properties'] = special_properties_list
        if len(properties_list) == 0:
            result['properties'] = ''
        else:
            result['properties'] = properties_list

        result['results'] = result_list
        return result
Exemple #28
0
    def run(self):
        data = self.params.get('data')
        if data is None:
            raise InvalidInputError('missing data keyword')
        # if input data has not method_id keyword raise exception
        if 'method_id' not in data.keys():
            raise InvalidInputError('missing method_id keyword')
        if data['method_id'] == 1:
            # if input data has not hash_code keyword raise exception
            if 'hash_code' not in data.keys():
                raise InvalidInputError('missing hash_code keyword')
            else:
                hash_code = data.get('hash_code')

            # if input data has not username keyword raise exception
            if 'username' not in data.keys():
                raise InvalidInputError('missing username keyword')
            else:
                username = data.get('username')

            # if input data has not password keyword raise exception
            if 'password' not in data.keys():
                raise InvalidInputError('missing password keyword')
            else:
                password = data.get('password')

            if 'hash_type' is None:
                hash_type = 'md5'
            else:
                hash_type = data.get('hash_type')

            hash = Hash(username, password)
            result = {}
            result_list = []
            decoded = hash.decode(hash_type, hash_code)
            result_list.append({
                'type': 7,
                'data': decoded,
                'properties': [{}]
            })
            result['results'] = result_list
            self.result = result

        if data['method_id'] == 2:
            # if input data has not hash_code keyword raise exception
            if 'hash_code' not in data.keys():
                raise InvalidInputError('missing hash_code keyword')
            else:
                hash_code = data.get('hash_code')

            # if input data has not api_key keyword raise exception
            if 'api_key' not in data.keys():
                raise InvalidInputError('missing api_key keyword')
            else:
                api_key = data.get('api_key')

            # if input data has not email keyword raise exception
            if 'email' not in data.keys():
                raise InvalidInputError('missing email keyword')
            else:
                email = data.get('email')
            self.result = Hash.get_result_by_api(api_key, email, hash_code)

        else:
            raise InvalidInputError('invalid method_id')
Exemple #29
0
    def run(self):
        # checking input and calling appropriate method
        parser_data = self.params.get('data')
        if parser_data is None:
            raise InvalidInputError('missing data keyword')

        # if input data has not method_id keyword raise exception
        if 'method_id' not in parser_data.keys():
            raise InvalidInputError('missing method_id keyword')

        # get balance
        if parser_data['method_id'] == 0:
            if 'api_key' not in parser_data.keys():
                raise InvalidInputError(' missing api_key keyword')
            api_key = parser_data['api_key']
            self.check_point()
            self.update_progressbar('connecting to whois_api', 40)
            result = {
                'results': [{
                    'live_whois_balance':
                    WhoisApi.check_balance(api_key),
                    'type':
                    0
                }]
            }
            self.result = result
        # reverse by email
        elif parser_data['method_id'] == 1:
            if 'email' not in parser_data.keys():
                raise InvalidInputError(' missing email keyword')
            if 'api_key' not in parser_data.keys():
                raise InvalidInputError(' missing api_key keyword')
            api_key = parser_data['api_key']
            email = parser_data['email']
            self.check_point()
            self.update_progressbar('connecting to whois_api', 40)
            self.result = get_whois_by_email(email, api_key)

        # reverse by name
        elif parser_data['method_id'] == 2:
            if 'name' not in parser_data.keys():
                raise InvalidInputError(' missing name keyword')
            if 'api_key' not in parser_data.keys():
                raise InvalidInputError(' missing api_key keyword')
            api_key = parser_data['api_key']
            name = parser_data['name']
            self.check_point()
            self.update_progressbar('connecting to whois_api', 40)
            self.result = get_whois_by_name(name, api_key)

        # get whois by name
        elif parser_data['method_id'] == 3:
            if 'domain' in parser_data.keys():
                domain = parser_data['domain']
                api_key = None
            else:
                raise InvalidInputError('missing domain keyword')
            if 'api_key' in parser_data.keys():
                api_key = parser_data['api_key']

            self.result = self.get_whois_by_domain_api(domain, api_key)
        # get whois_history by name
        elif parser_data['method_id'] == 4:
            if 'domain' in parser_data.keys():
                domain = parser_data['domain']
            else:
                raise InvalidInputError('missing domain keyword')
            if 'api_key' in parser_data.keys():
                api_key = parser_data['api_key']
            else:
                raise InvalidInputError('missing api keyword')
            whois_history = WhoisHistory(parent=self)
            self.check_point()
            self.update_progressbar('get history of domain and parse result',
                                    70)
            self.result = whois_history.whois_history(domain, api_key)

        # get domains hosted from the given ip
        elif parser_data['method_id'] == 5:
            if 'api_key' in parser_data.keys():
                api_key = parser_data['api_key']
            else:
                raise InvalidInputError('missing api_key keyword')
            if 'host' in parser_data.keys():
                host = parser_data['host']
            else:
                raise InvalidInputError('missing host keyword')
            if 'max_results' in parser_data.keys():
                max_results = parser_data['max_results']
            else:
                max_results = 20
            if 'domain_count_flag' in parser_data.keys():
                domain_count_flag = parser_data['domain_count_flag']
            else:
                domain_count_flag = False
            reverse_object = Whois(parent=self)

            self.result = reverse_object.reverse_ip_lookup(
                host, api_key, domain_count_flag, max_results)
        else:
            raise InvalidInputError('Invalid method id')