def __get_version_standalone(self): """ detects the version of the wordpress :return: a list of tuples: [(whether the domain operates over Wordpress, doesn't return the version),..] """ try: response_list = [] for url in _VERSION_DETECTABLE_URLS: complete_url_https = 'https://' + str(self._domain) + url complete_url_http = 'http://' + str(self._domain) + url http_handler = HTTPRequestHandler(proxies=self._proxies, retries=0, timeout=5) response = http_handler.send_http_request( method='get', url=complete_url_https) if response is None: response = http_handler.send_http_request( method='get', url=complete_url_http) response_list.append( self.__detect_version_logic(response.content, url)) possible_outcomes = [] outcome = None for item in response_list: if item[0]: possible_outcomes.append(item) for outcome in possible_outcomes: if 'version' not in outcome[1]: return outcome return outcome except Exception as e: print(e)
def is_wordpress_no_url(self, proxies=None, timeout=5, retries=0): """ This function cheks if a domain is running WordPress even if there aren't any urls givven :param proxies: working via HTTP proxies. If None, the constructor's proxies are used (if any) :param retries: The number of tries that each HTTP request will be sent until it will succeed :param timeout: How much time each HTTP request will wait for an answer :return: List of tuples of all the indications [(True/False, if a version was discovered) """ response_list = [] url = 'https://' + str(self._domain) http_handler = HTTPRequestHandler(proxies=proxies, retries=retries, timeout=timeout) response = http_handler.send_http_request(method='get', url=url) response_list += self._find_version_by_php(response.headers) response_list += self._is_wordpress_by_resource(response=response, url=url) if response is None: url = 'http://' + str(self._domain) http_handler = HTTPRequestHandler(proxies=proxies, retries=retries, timeout=timeout) response = http_handler.send_http_request(method='get', url=url) if response is None: pass if str(response.status_code) != '200': response_list.append((False, "Could'nt detect version")) return response_list else: if not response_list: response_list = [] # check in source code if important 'wp-'s in: count = 0 http_handler = HTTPRequestHandler(proxies=proxies, retries=retries, timeout=timeout) response = http_handler.send_http_request(method='get', url=url) if 'wp-content' in str(response.content): count += 1 if 'wordpress' in str(response.content).lower(): count += 1 if 'wp-admin' in str(response.content): count += 1 if 'wp-includes' in str(response.content): count += 1 if 'wp-json' in str(response.content): count += 1 if 5 >= count >= 3: response_list.append((True, "Could'nt detect version")) else: response_list.append((False, "Could'nt detect version")) if 'name="generator" content="wordpress"' in str( response.content).lower(): response_list.append( self.get_version(response.content, url + '/wp-admin')) return response_list return response_list
def get_version(self, timeout=5, retries=0): """ detects the version of the drupal :param timeout:How much time each HTTP request will wait for an answer :param retries:The number of tries that each HTTP request will be sent until it will succeed :return: string: (return the version of this drupal website) """ url = 'https://' + self._domain http_handler = HTTPRequestHandler(proxies=self._proxies, retries=retries, timeout=timeout) response = http_handler.send_http_request(method='get', url=url) if response.text.__contains__('/sites') or response.text.__contains__('drupal 7'): return 'version 7' if response.text.__contains__('/core'): return 'version 8' return "Could'nt detect version"
def get_info(self, timeout, retries): """ this function is resposable for checking the template id and version """ complete_url = 'http://' + str(self._domain) http_handler = HTTPRequestHandler(proxies=self._proxies, retries=retries, timeout=timeout) response = http_handler.send_http_request(method='get', url=complete_url) if response is None: return False if response.status_code is 200: text = response.text list = text.split('"') index = list.index('templateVersion') version = list[index + 2] index = list.index('templateId') TemplateId = list[index + 2] return TemplateId + ',' + version else: return False
def is_drupal(self, urls=None, proxies=None, timeout=5, retries=0): ''' This function detects if the website runs over drupal :param urls: URLs to analyze; make sure the URLs are relevant for the domain :param proxies: working via HTTP proxies. If None, the constructor's proxies are used (if any) :param timeout: The number of tries that each HTTP request will be sent until it will succeed :param retries: How much time each HTTP request will wait for an answer :return: a tuple: (whether the domain operates over Wordpress, its version) ''' url = 'https://' + self._domain if not urls: http_handler = HTTPRequestHandler(proxies=proxies, retries=retries, timeout=timeout) response = http_handler.send_http_request(method='get', url=url) if response is None: pass elif str(response.status_code) != ('200' or '403'): return False else: if "drupal" in str(response.content).lower(): return True for fold in _DRUPAL_DETECTABLE_FOLDER: if fold in str(response.content).lower(): return True else: http_handler = HTTPRequestHandler(proxies=proxies, retries=retries, timeout=timeout) response = http_handler.send_http_request(method='get', url=url) if response: if self.header_check(response): return True if self.resources_detector(response, url): return True for u in urls: complete_url = url + u http_handler = HTTPRequestHandler(proxies=proxies, retries=retries, timeout=timeout) response = http_handler.send_http_request(method='get', url=complete_url) if response is None: pass else: if str(response.status_code) != ('200' or '403' or '401'): pass else: if "drupal" in str(response.content).lower(): return True for fold in _DRUPAL_DETECTABLE_FOLDER: if fold in str(response.content).lower(): return True return False
def is_squarespace(self, urls=None, proxies=None, timeout=5, retries=0): """ This function detects if the website runs over SquareSpace :param urls: URLs to analyze; make sure the URLs are relevant for the domain :param proxies: working via HTTP proxies. If None, the constructor's proxies are used (if any) :param retries: The number of tries that each HTTP request will be sent until it will succeed :param timeout: How much time each HTTP request will wait for an answer :return: boolean: (whether the domain operates over SquareSpace) """ url = self.formaturl(self._domain) if urls is None: httpreq = HTTPRequestHandler(proxies=proxies, retries=retries, timeout=timeout) r = httpreq.send_http_request(method='get', url=url) if r is None: pass if r.status_code is not (200 or 403): print(r.status_code) print("could'nt establish a connection") return False else: if r.status_code is (200 or 403): if self.public_route_search(r) or self.non_public_route_search(r): return True return False
def is_wordpress(self, urls=None, proxies=None, timeout=5, retries=0): """ This function detects if the website runs over wordpress :param urls: URLs to analyze; make sure the URLs are relevant for the domain :param proxies: working via HTTP proxies. If None, the constructor's proxies are used (if any) :param retries: The number of tries that each HTTP request will be sent until it will succeed :param timeout: How much time each HTTP request will wait for an answer :return: a tuple: (whether the domain operates over Wordpress, its version) """ try: response_list = [] if not urls: response_list += self.is_wordpress_no_url(proxies=proxies, timeout=timeout, retries=retries) else: response_list = [] for url in urls: complete_url = 'https://' + str(self._domain) + url http_handler = HTTPRequestHandler(proxies=proxies, retries=retries, timeout=timeout) response = http_handler.send_http_request(method='get', url=complete_url) if response is None: complete_url = 'http://' + str(self._domain) + url http_handler = HTTPRequestHandler(proxies=proxies, retries=retries, timeout=timeout) response = http_handler.send_http_request( method='get', url=complete_url) if response is None: break if 'licence' in url: count = 0 if str(response.status_code) == '200': if 'WordPress - Web publishing software' in str( response.content): count += 1 if 'WordPress is released under the GPL' in str( response.content): count += 1 if 'The source code for any program binaries or compressed scripts that are' in str( response.content) and \ 'included with WordPress can be freely obtained at the following URL:' \ in str(response.content): count += 1 if 3 >= count >= 2: response_list.append( self.get_version(response.content, url)) if 'readme' in url: if str(response.status_code ) == '200' and 'readme' in response.url: if 'wordpress-logo.png' in str(response.content): response_list.append( (True, "Could'nt detect version")) response_list.append( (False, "Could'nt detect version")) if 'feed' in url: if str(response.status_code ) == '200' and 'feed' in response.url: response_list.append( self.get_version(response.content, url)) if 'wp-links-opml' in url and 'wp-links-opml' in response.url: response_list.append( self.get_version(response.content, url)) if 'upgrade' in url and 'upgrade' in response.url: if 'wordpress-logo.png' in str(response.content): response_list.append( (True, "Could'nt detect version")) response_list.append( (False, "Could'nt detect version")) if 'admin' in url: count = 0 if 'wp-content' in str(response.content): count += 1 elif 'wordpress' in str(response.content): count += 1 if 'wp-admin' in str(response.content): count += 1 if 'wp-includes' in str(response.content): count += 1 if 'wp-json' in str(response.content): count += 1 if 5 >= count >= 3: response_list.append( (True, "Could'nt detect version")) response_list.append( self.get_version(response.content, url + '/wp-admin')) if 'robots' in url: list_of_paths = [ 'wp-admin', 'WP rules', 'wordpress rules', 'wp-includes', '/feed', 'wp-content' ] for l in list_of_paths: if l in str(response.content): response_list.append( (True, "Could'nt detect version")) response_list.append( (False, "Could'nt detect version")) response_list += self.is_wordpress_no_url(proxies=proxies, timeout=timeout, retries=retries) possible_outcomes = [] is_word_press = False for item in response_list: if item[0]: possible_outcomes.append(item) for outcome in possible_outcomes: if outcome[0]: is_word_press = True if 'version' not in outcome[1] and len(possible_outcomes) > 1: return outcome if is_word_press and len(possible_outcomes) > 1: return True, "Could'nt detect version" return False, "Could'nt detect version" except Exception as e: print(e)