示例#1
0
    def export(request, task_id):
        if request.method == "POST":
            taken_dirs = request.POST.getlist("dirs")
            taken_files = request.POST.getlist("files")

            if not taken_dirs and not taken_files:
                return view_error(
                    request, "Please select at least one directory or file"
                    " to be exported."
                )

            zip = Task.create_zip(
                task_id=task_id, taken_dirs=taken_dirs, taken_files=taken_files
            )
            if not zip:
                return view_error(request, "Failed to create zip.")

            response = HttpResponse(
                zip.getvalue(), content_type="application/zip"
            )
            response["Content-Disposition"] = (
                "attachment; filename=%s.zip" % task_id
            )

            return response

        report = AnalysisController.get_report(task_id)

        dirs, files = Task.get_files(task_id)
        return render_template(
            request, "analysis/export.html", report=report, dirs=dirs,
            files=files
        )
示例#2
0
    def test_create_zip(self):
        fake_task = cwd(analysis=1)
        shutil.copytree("tests/files/sample_analysis_storage", fake_task)
        zfileio = Task.create_zip(
            1, ["logs", "report"], ["cuckoo.log", "files.json"]
        )

        assert isinstance(zfileio, io.BytesIO)

        zfile = zipfile.ZipFile(zfileio)
        assert len(zfile.read("files.json")) == 1856
        assert len(zfileio.getvalue()) == 13938
示例#3
0
    def get_files(self):
        """If the task_id and include_files are set, returns a
        zip file of the files for that task"""
        zipfile = io.BytesIO()
        if self.include_files:

            if not self.task_id:
                raise CuckooFeedbackError(
                    "No task ID was set. Cannot include files if task ID"
                    " is unknown.")

            if not os.path.isdir(cwd(analysis=self.task_id)):
                raise CuckooFeedbackError(
                    "Can't include the entire analysis for this analysis"
                    " as the analysis path doesn't exist.")

            zipfile = Task.create_zip(self.task_id,
                                      self.export_dirs,
                                      self.export_files,
                                      export=False)

        return {"file": zipfile}