コード例 #1
0
 def generateURL(self):
     # Generate a download URL for whichever results are in
     # the S3 bucket for that host, while keeping track of
     # missing results
     self.scan_output_dict, self.scan_output_list, status = self.__poll()
     if status == 404:
         return status, False, False
     else:
         # Does not matter if status is 200 or 202, we
         # will generate a signed URL, but also return
         # the result dictionary
         host_results_dir = os.path.join(self.base_results_path,
                                         self.hostname)
         ready = self.__prepareResults(host_results_dir)
         if ready:
             # Downloaded the output for the target on the "serverless" server
             # Now, we need to zip it up and upload back to S3.
             tgz_results = package_results(host_results_dir)
             s3_object = send_to_s3(self.hostname,
                                    tgz_results,
                                    client=self.s3_client,
                                    bucket=self.bucket)
             # We need to generate a signed URL now
             download_url = create_presigned_url(s3_object,
                                                 client=self.s3_client,
                                                 bucket=self.bucket)
             return status, self.scan_output_dict, download_url
         else:
             # Something went wrong, return False
             return status, False, False
コード例 #2
0
    def download(self):
        # While downloading, let's just download whatever
        # results exist for a given host
        host_results_dir = os.path.join(self.base_results_path, self.hostname)
        self.scan_output_list, status = self.__poll()
        # status here is either 200, 202 or 404

        if self.scan_output_list and len(self.scan_output_list):
            # We have results, but we do not care how many
            ready = self.__prepareResults(host_results_dir)
            if ready:
                # Downloaded the output for the target on the "serverless" server
                # Now, we need to zip it up and return
                tgz_results = package_results(host_results_dir)
                return tgz_results, status
            else:
                # Error when preparing results, return 500
                return False, 500
        else:
            # No results found, return False
            return False, status
コード例 #3
0
    def generateDownloadURL(self):
        # While generating a signed URL, let's only generate
        # a signed URL if all tool output is available

        # Setting default status, HTTP 202 means "Accepted"
        status = 202
        # TODO: We need a timeout function here
        while status == 202:
            self.scan_output_list, status = self.__poll()
            time.sleep(1)
        # status here is either 200 or 404

        if status != 404:
            host_results_dir = os.path.join(self.base_results_path,
                                            self.hostname)
            ready = self.__prepareResults(host_results_dir)
            if ready:
                # Downloaded the output for the target on the "serverless" server
                # Now, we need to zip it up and upload back to S3.
                tgz_results = package_results(host_results_dir)
                print(self.bucket)
                print(self.s3_client)
                s3_object = send_to_s3(self.hostname,
                                       tgz_results,
                                       client=self.s3_client,
                                       bucket=self.bucket)
                # We need to generate a signed URL now
                download_url = create_presigned_url(s3_object,
                                                    client=self.s3_client,
                                                    bucket=self.bucket)
                return download_url, status
            else:
                # Something went wrong, return False
                return False, status
        else:
            # No results for the host found
            return False, status