def generate(self): file_loader = FileSystemLoader( os.path.dirname(os.path.realpath(__file__)) + "/templates/") env = Environment(loader=file_loader) template = env.get_template("html_report_template.html") metadata = {"command": self.get_command(), "date": time.ctime()} results = [] for entry in self.entries: for e in entry.results: header_name = "{0}://{1}:{2}/{3}".format( entry.protocol, entry.host, entry.port, entry.base_path) status_color_class = '' if e.status >= 200 and e.status <= 299: status_color_class = "text-success" elif e.status >= 300 and e.status <= 399: status_color_class = "text-warning" elif e.status >= 400 and e.status <= 599: status_color_class = "text-danger" results.append({ "url": header_name + e.path, "path": e.path, "status": e.status, "statusColorClass": status_color_class, "contentLength": human_size(e.response.length), "contentType": e.get_content_type(), "redirect": e.response.redirect }) return template.render(metadata=metadata, results=results)
def status_report(self, response, full_url, added_to_queue): status = response.status content_length = human_size(response.length) message = "{0} - {1} - {2}".format(status, content_length.rjust(6, " "), response.url) if status in (200, 201, 204): message = self.colorizer.color(message, fore="green") elif status == 401: message = self.colorizer.color(message, fore="yellow") elif status == 403: message = self.colorizer.color(message, fore="blue") elif status in range(500, 600): message = self.colorizer.color(message, fore="red") elif status in range(300, 400): message = self.colorizer.color(message, fore="cyan") else: message = self.colorizer.color(message, fore="magenta") if response.redirect: message += " -> {0}".format(response.redirect) if added_to_queue: message += " (Added to queue)" for redirect in response.history: message += "\n--> {0}".format(redirect) with self.mutex: self.new_line(message)
def is_valid(self, path, res): if res.status in self.options.exclude_status_codes: return False if res.status not in (self.options.include_status_codes or range(100, 1000)): return False if self.blacklists.get(res.status) and path in self.blacklists.get( res.status): return False if human_size(res.length) in self.options.exclude_sizes: return False if res.length < self.options.minimum_response_size: return False if res.length > self.options.maximum_response_size != 0: return False for exclude_text in self.options.exclude_texts: if exclude_text in res.content: return False for exclude_regexp in self.options.exclude_regexps: if re.search(exclude_regexp, res.content) is not None: return False for exclude_redirect in self.options.exclude_redirects: if res.redirect and exclude_redirect in res.redirect or (re.match( exclude_redirect, res.redirect)): return False return True
def status_report(self, response, full_url, added_to_queue): status = response.status content_length = human_size(response.length) show_path = self.url + response.full_path if full_url else response.full_path message = "[{0}] {1} - {2} - {3}".format( time.strftime("%H:%M:%S"), status, content_length.rjust(6, ' '), show_path, ) if status in (200, 201, 204): message = self.colorizer.color(message, fore="green") elif status == 401: message = self.colorizer.color(message, fore="yellow") elif status == 403: message = self.colorizer.color(message, fore="blue") elif status in range(500, 600): message = self.colorizer.color(message, fore="red") elif status in range(300, 400): message = self.colorizer.color(message, fore="cyan") else: message = self.colorizer.color(message, fore="magenta") if response.redirect: message += " -> {0}".format(response.redirect) if added_to_queue: message += " (Added to queue)" for redirect in response.history: message += "\n--> {0}".format(redirect) with self.mutex: self.new_line(message)
def generate(self): result = self.generate_header() for entry in self.entries: for e in entry.results: if (entry.protocol, entry.host, entry.port, entry.base_path, e.path) not in self.written_entries: result += "{0} ".format(e.status) result += "{0} ".format(human_size(e.response.length).rjust(6, ' ')) result += "{0}://{1}:{2}/".format(entry.protocol, entry.host, entry.port) result += ( "{0}".format(e.path) if entry.base_path == '' else "{0}/{1}".format(entry.base_path, e.path) ) location = e.response.redirect if location: result += " -> REDIRECTS TO: {0}".format(location) result += NEW_LINE self.written_entries.append((entry.protocol, entry.host, entry.port, entry.base_path, e.path)) return result
def is_valid(self, path, res): if res.status in self.options["exclude_status_codes"]: return False if res.status not in (self.options["include_status_codes"] or range(100, 1000)): return False if self.blacklists.get(res.status) and path in self.blacklists.get( res.status): return False if human_size(res.length) in self.options["exclude_sizes"]: return False if res.length < self.options["minimum_response_size"]: return False if res.length > self.options["maximum_response_size"] != 0: return False if any(ex_text in res.content for ex_text in self.options["exclude_texts"]): return False if self.options["exclude_regex"] and re.search( self.options["exclude_regex"], res.content) is not None: return False if self.options["exclude_redirect"] and ( self.options["exclude_redirect"] in res.redirect or re.search(self.options["exclude_redirect"], res.redirect) is not None): return False return True