Exemplo n.º 1
0
    def test_copy_folder(self):
        """Tests recursive folder copy"""
        dirpath = tempfile.mkdtemp()
        set_cwd(dirpath)

        Folders.copy("tests/files/sample_analysis_storage", dirpath)
        assert os.path.isfile("%s/reports/report.json" % dirpath)
Exemplo n.º 2
0
 def test_multiple_folders(self):
     """Tests multiple folders creation."""
     Folders.create(self.tmp_dir, ["foo", "bar"])
     assert os.path.exists(os.path.join(self.tmp_dir, "foo"))
     assert os.path.exists(os.path.join(self.tmp_dir, "bar"))
     os.rmdir(os.path.join(self.tmp_dir, "foo"))
     os.rmdir(os.path.join(self.tmp_dir, "bar"))
Exemplo n.º 3
0
 def test_multiple_folders(self):
     """Tests multiple folders creation."""
     Folders.create(self.tmp_dir, ["foo", "bar"])
     assert os.path.exists(os.path.join(self.tmp_dir, "foo"))
     assert os.path.exists(os.path.join(self.tmp_dir, "bar"))
     os.rmdir(os.path.join(self.tmp_dir, "foo"))
     os.rmdir(os.path.join(self.tmp_dir, "bar"))
Exemplo n.º 4
0
 def test_create_temp(self):
     """Test creation of temporary directory."""
     dirpath1 = Folders.create_temp("/tmp")
     dirpath2 = Folders.create_temp("/tmp")
     assert os.path.exists(dirpath1)
     assert os.path.exists(dirpath2)
     assert dirpath1 != dirpath2
Exemplo n.º 5
0
def test_migration_201_202():
    set_cwd(tempfile.mkdtemp())
    Folders.create(cwd(), "conf")
    Files.create(
        cwd("conf"), "virtualbox.conf", """
[virtualbox]
machines = cuckoo1, cuckoo2
[cuckoo1]
platform = windows
[cuckoo2]
platform = windows
""")
    # Except for virtualbox.
    machineries = (
        "avd",
        "esx",
        "kvm",
        "physical",
        "qemu",
        "vmware",
        "vsphere",
        "xenserver",
    )
    for machinery in machineries:
        Files.create(cwd("conf"), "%s.conf" % machinery,
                     "[%s]\nmachines =" % machinery)
    cfg = Config.from_confdir(cwd("conf"), loose=True)
    cfg = migrate(cfg, "2.0.1", "2.0.2")
    assert cfg["virtualbox"]["cuckoo1"]["osprofile"] is None
    assert cfg["virtualbox"]["cuckoo2"]["osprofile"] is None
Exemplo n.º 6
0
def test_migration_203_204():
    set_cwd(tempfile.mkdtemp())
    Folders.create(cwd(), "conf")
    Files.create(cwd("conf"), "processing.conf", """
[dumptls]
enabled = on
""")
    Files.create(
        cwd("conf"), "qemu.conf", """
[qemu]
machines = ubuntu32, ubuntu64
[ubuntu32]
arch = x86
[ubuntu64]
arch = x64
    """)
    cfg = Config.from_confdir(cwd("conf"), loose=True)
    cfg = migrate(cfg, "2.0.3", "2.0.4")
    assert cfg["processing"]["extracted"]["enabled"] is True
    # Except for qemu.
    machineries = (
        "avd",
        "esx",
        "kvm",
        "physical",
        "virtualbox",
        "vmware",
        "vsphere",
        "xenserver",
    )
    for machinery in machineries:
        Files.create(cwd("conf"), "%s.conf" % machinery,
                     "[%s]\nmachines =" % machinery)
    assert cfg["qemu"]["ubuntu32"]["enable_kvm"] is False
    assert cfg["qemu"]["ubuntu32"]["snapshot"] is None
Exemplo n.º 7
0
 def test_create_temp(self):
     """Test creation of temporary directory."""
     dirpath1 = Folders.create_temp()
     dirpath2 = Folders.create_temp()
     assert os.path.exists(dirpath1)
     assert os.path.exists(dirpath2)
     assert dirpath1 != dirpath2
Exemplo n.º 8
0
    def test_copy_folder(self):
        """Tests recursive folder copy"""
        dirpath = tempfile.mkdtemp()
        set_cwd(dirpath)

        Folders.copy("tests/files/sample_analysis_storage", dirpath)
        assert os.path.isfile("%s/reports/report.json" % dirpath)
Exemplo n.º 9
0
def test_migration_201_202():
    set_cwd(tempfile.mkdtemp())
    Folders.create(cwd(), "conf")
    Files.create(cwd("conf"), "virtualbox.conf", """
[virtualbox]
machines = cuckoo1, cuckoo2
[cuckoo1]
platform = windows
[cuckoo2]
platform = windows
""")
    # Except for virtualbox.
    machineries = (
        "avd", "esx", "kvm", "physical", "qemu",
        "vmware", "vsphere", "xenserver",
    )
    for machinery in machineries:
        Files.create(
            cwd("conf"), "%s.conf" % machinery,
            "[%s]\nmachines =" % machinery
        )
    cfg = Config.from_confdir(cwd("conf"), loose=True)
    cfg = migrate(cfg, "2.0.1", "2.0.2")
    assert cfg["virtualbox"]["cuckoo1"]["osprofile"] is None
    assert cfg["virtualbox"]["cuckoo2"]["osprofile"] is None
Exemplo n.º 10
0
def test_migration_203_204():
    set_cwd(tempfile.mkdtemp())
    Folders.create(cwd(), "conf")
    Files.create(cwd("conf"), "processing.conf", """
[dumptls]
enabled = on
""")
    Files.create(cwd("conf"), "qemu.conf", """
[qemu]
machines = ubuntu32, ubuntu64
[ubuntu32]
arch = x86
[ubuntu64]
arch = x64
    """)
    cfg = Config.from_confdir(cwd("conf"), loose=True)
    cfg = migrate(cfg, "2.0.3", "2.0.4")
    assert cfg["processing"]["extracted"]["enabled"] is True
    # Except for qemu.
    machineries = (
        "avd", "esx", "kvm", "physical", "virtualbox",
        "vmware", "vsphere", "xenserver",
    )
    for machinery in machineries:
        Files.create(
            cwd("conf"), "%s.conf" % machinery, "[%s]\nmachines =" % machinery
        )
    assert cfg["qemu"]["ubuntu32"]["enable_kvm"] is False
    assert cfg["qemu"]["ubuntu32"]["snapshot"] is None
Exemplo n.º 11
0
    def test_create_tuple(self):
        dirpath = tempfile.mkdtemp()
        Folders.create(dirpath, "foo")
        Files.create((dirpath, "foo"), "a.txt", "bar")

        filepath = os.path.join(dirpath, "foo", "a.txt")
        assert open(filepath, "rb").read() == "bar"
Exemplo n.º 12
0
    def test_create_tuple(self):
        dirpath = tempfile.mkdtemp()
        Folders.create(dirpath, "foo")
        Files.create((dirpath, "foo"), "a.txt", "bar")

        filepath = os.path.join(dirpath, "foo", "a.txt")
        assert open(filepath, "rb").read() == "bar"
Exemplo n.º 13
0
    def create_folders(self):
        folders = "shots", "files", "logs", "buffer", "extracted"

        try:
            Folders.create(self.storagepath, folders)
        except CuckooOperationalError as e:
            log.error("Issue creating analyses folders: %s", e)
            return False
Exemplo n.º 14
0
def test_am_init_duplicate_analysis():
    am = am_init()

    Folders.create(cwd(analysis=1234))
    assert am.init() is False

    # Manually disable per-task logging initiated by init().
    task_log_stop(1234)
Exemplo n.º 15
0
def test_am_init_duplicate_analysis():
    am = am_init()

    Folders.create(cwd(analysis=1234))
    assert am.init() is False

    # Manually disable per-task logging initiated by init().
    task_log_stop(1234)
Exemplo n.º 16
0
    def create_folders(self):
        folders = "shots", "files", "logs", "buffer", "extracted"

        try:
            Folders.create(self.storagepath, folders)
        except CuckooOperationalError as e:
            log.error("Issue creating analyses folders: %s", e)
            return False
Exemplo n.º 17
0
def test_confdir():
    set_cwd(tempfile.mkdtemp())
    Folders.create(cwd(), "conf")
    Files.create(cwd("conf"), "cuckoo.conf", "[cuckoo]\ndelete_original = yes")
    Files.create(cwd("conf"), "virtualbox.conf",
                 "[virtualbox]\npath = /usr/bin/VBoxManage")
    cfg = Config.from_confdir(cwd("conf"))
    assert cfg["cuckoo"]["cuckoo"]["delete_original"] is True
    assert cfg["virtualbox"]["virtualbox"]["path"] == "/usr/bin/VBoxManage"
Exemplo n.º 18
0
def test_migration_100_110():
    set_cwd(tempfile.mkdtemp())
    Folders.create(cwd(), "conf")
    Files.create(cwd("conf"), "cuckoo.conf", """
[cuckoo]
delete_original = on
""")
    cfg = Config.from_confdir(cwd("conf"), loose=True)
    cfg = migrate(cfg, "1.0.0", "1.1.0")
    assert cfg["cuckoo"]["cuckoo"]["tmppath"] == "/tmp"
Exemplo n.º 19
0
def test_migration_200_201():
    set_cwd(tempfile.mkdtemp())
    Folders.create(cwd(), "conf")
    Files.create(cwd("conf"), "memory.conf", """
[mask]
pid_generic =
""")
    cfg = Config.from_confdir(cwd("conf"), loose=True)
    cfg = migrate(cfg, "2.0.0", "2.0.1")
    assert cfg["memory"]["mask"]["pid_generic"] == []
Exemplo n.º 20
0
def test_migration_200_201():
    set_cwd(tempfile.mkdtemp())
    Folders.create(cwd(), "conf")
    Files.create(cwd("conf"), "memory.conf", """
[mask]
pid_generic =
""")
    cfg = Config.from_confdir(cwd("conf"), loose=True)
    cfg = migrate(cfg, "2.0.0", "2.0.1")
    assert cfg["memory"]["mask"]["pid_generic"] == []
Exemplo n.º 21
0
def test_migration_204_205():
    set_cwd(tempfile.mkdtemp())
    Folders.create(cwd(), "conf")
    Files.create(cwd("conf"), "auxiliary.conf", """
[mitm]
script = mitm.py
""")
    cfg = Config.from_confdir(cwd("conf"), loose=True)
    cfg = migrate(cfg, "2.0.4", "2.0.5")
    assert cfg["auxiliary"]["mitm"]["script"] == "stuff/mitm.py"
Exemplo n.º 22
0
    def test_temp_conf(self):
        dirpath = tempfile.mkdtemp()
        set_cwd(dirpath)

        Folders.create(dirpath, "conf")
        with open(os.path.join(dirpath, "conf", "cuckoo.conf"), "wb") as f:
            f.write("[cuckoo]\ntmppath = %s" % dirpath)

        filepath = Files.temp_put("foo")
        assert filepath.startswith(os.path.join(dirpath, "cuckoo-tmp"))
Exemplo n.º 23
0
    def test_delete_invld(self):
        """Test deletion of a folder we can't access."""
        dirpath = tempfile.mkdtemp()

        os.chmod(dirpath, 0)
        with pytest.raises(CuckooOperationalError):
            Folders.delete(dirpath)

        os.chmod(dirpath, 0775)
        Folders.delete(dirpath)
Exemplo n.º 24
0
def test_migration_203_204():
    set_cwd(tempfile.mkdtemp())
    Folders.create(cwd(), "conf")
    Files.create(cwd("conf"), "processing.conf", """
[dumptls]
enabled = on
""")
    cfg = Config.from_confdir(cwd("conf"), loose=True)
    cfg = migrate(cfg, "2.0.3", "2.0.4")
    assert cfg["processing"]["extracted"]["enabled"] is True
Exemplo n.º 25
0
def test_migration_100_110():
    set_cwd(tempfile.mkdtemp())
    Folders.create(cwd(), "conf")
    Files.create(cwd("conf"), "cuckoo.conf", """
[cuckoo]
delete_original = on
""")
    cfg = Config.from_confdir(cwd("conf"), loose=True)
    cfg = migrate(cfg, "1.0.0", "1.1.0")
    assert cfg["cuckoo"]["cuckoo"]["tmppath"] == "/tmp"
Exemplo n.º 26
0
def cuckoo_cwd():
    """Create a temporary Cuckoo working directory"""
    path = tempfile.mkdtemp()
    print('Temporary path:', path)
    set_cwd(path)
    cuckoo_create()
    anal_path = cwd(analysis=1)
    Folders.create(anal_path, RESULT_DIRECTORIES)
    yield path
    shutil.rmtree(path)
Exemplo n.º 27
0
    def test_temp_conf(self):
        dirpath = tempfile.mkdtemp()
        set_cwd(dirpath)

        Folders.create(dirpath, "conf")
        with open(os.path.join(dirpath, "conf", "cuckoo.conf"), "wb") as f:
            f.write("[cuckoo]\ntmppath = %s" % dirpath)

        filepath = Files.temp_put("foo")
        assert filepath.startswith(dirpath)
Exemplo n.º 28
0
    def setup(self):
        set_cwd(tempfile.mkdtemp())
        Folders.create(cwd(), "conf")
        write_cuckoo_conf()

        with mock.patch("cuckoo.common.abstracts.Database") as p:
            p.return_value = mock.MagicMock()
            self.m = QEMU()

        self.m.set_options(Config("qemu"))
Exemplo n.º 29
0
    def test_delete_invld(self):
        """Test deletion of a folder we can't access."""
        dirpath = tempfile.mkdtemp()

        os.chmod(dirpath, 0)
        with pytest.raises(CuckooOperationalError):
            Folders.delete(dirpath)

        os.chmod(dirpath, 0775)
        Folders.delete(dirpath)
Exemplo n.º 30
0
def test_migration_203_204():
    set_cwd(tempfile.mkdtemp())
    Folders.create(cwd(), "conf")
    Files.create(cwd("conf"), "processing.conf", """
[dumptls]
enabled = on
""")
    cfg = Config.from_confdir(cwd("conf"), loose=True)
    cfg = migrate(cfg, "2.0.3", "2.0.4")
    assert cfg["processing"]["extracted"]["enabled"] is True
Exemplo n.º 31
0
    def setup(self):
        set_cwd(tempfile.mkdtemp())
        Folders.create(cwd(), "conf")

        self.vbox_path = cwd("conf", "virtualbox.conf")
        open(self.vbox_path, "wb").write(VIRTUALBOX_CONFIG_EXAMPLE)
        self.virtualbox = Config(file_name="virtualbox", cfg=self.vbox_path)

        filepath = cwd("conf", "cuckoo.conf")
        open(filepath, "wb").write(CUCKOO_CONFIG_EXAMPLE)
        self.cuckoo = Config(file_name="cuckoo", cfg=filepath)
Exemplo n.º 32
0
    def test_create_temp_conf(self):
        """Test creation of temporary directory with configuration."""
        dirpath = tempfile.mkdtemp()
        set_cwd(dirpath)

        Folders.create(dirpath, "conf")
        with open(os.path.join(dirpath, "conf", "cuckoo.conf"), "wb") as f:
            f.write("[cuckoo]\ntmppath = %s" % dirpath)

        dirpath2 = Folders.create_temp()
        assert dirpath2.startswith(os.path.join(dirpath, "cuckoo-tmp"))
Exemplo n.º 33
0
    def setup(self):
        set_cwd(tempfile.mkdtemp())
        Folders.create(cwd(), "conf")

        self.vbox_path = cwd("conf", "virtualbox.conf")
        open(self.vbox_path, "wb").write(VIRTUALBOX_CONFIG_EXAMPLE)
        self.virtualbox = Config(file_name="virtualbox", cfg=self.vbox_path)

        filepath = cwd("conf", "cuckoo.conf")
        open(filepath, "wb").write(CUCKOO_CONFIG_EXAMPLE)
        self.cuckoo = Config(file_name="cuckoo", cfg=filepath)
Exemplo n.º 34
0
    def setup(self):
        set_cwd(tempfile.mkdtemp())
        Folders.create(cwd(), "conf")
        write_cuckoo_conf()

        with mock.patch("cuckoo.common.abstracts.Database") as p:
            p.return_value = mock.MagicMock()
            self.m = VirtualBox()

        self.m.db.clean_machines.assert_called_once()
        self.m.set_options(Config("virtualbox"))
Exemplo n.º 35
0
    def setup(self):
        set_cwd(tempfile.mkdtemp())
        Folders.create(cwd(), "conf")
        write_cuckoo_conf()

        with mock.patch("cuckoo.common.abstracts.Database") as p:
            p.return_value = mock.MagicMock()
            self.m = QEMU()

        self.m.db.clean_machines.assert_called_once()
        self.m.set_options(Config("qemu"))
Exemplo n.º 36
0
    def test_create_temp_conf(self):
        """Test creation of temporary directory with configuration."""
        dirpath = tempfile.mkdtemp()
        set_cwd(dirpath)

        Folders.create(dirpath, "conf")
        with open(os.path.join(dirpath, "conf", "cuckoo.conf"), "wb") as f:
            f.write("[cuckoo]\ntmppath = %s" % dirpath)

        dirpath2 = Folders.create_temp()
        assert dirpath2.startswith(dirpath)
Exemplo n.º 37
0
def test_invalid_machinery():
    set_cwd(tempfile.mkdtemp())
    Folders.create(cwd(), "conf")
    write_cuckoo_conf({
        "cuckoo": {
            "cuckoo": {
                "machinery": "foobar",
            },
        },
    })
    with pytest.raises(CuckooStartupError) as e:
        check_configs()
    e.match("unknown machinery")
Exemplo n.º 38
0
def test_invalid_machinery():
    set_cwd(tempfile.mkdtemp())
    Folders.create(cwd(), "conf")
    write_cuckoo_conf({
        "cuckoo": {
            "cuckoo": {
                "machinery": "foobar",
            },
        },
    })
    with pytest.raises(CuckooStartupError) as e:
        check_configs()
    e.match("unknown machinery")
Exemplo n.º 39
0
def test_invalid_section():
    set_cwd(tempfile.mkdtemp())
    Folders.create(cwd(), "conf")

    Files.create(cwd("conf"), "cuckoo.conf", "[invalid_section]\nfoo = bar")
    with pytest.raises(CuckooConfigurationError) as e:
        Config("cuckoo", strict=True)
    e.match("Config section.*not found")

    Files.create(cwd("conf"), "cuckoo.conf", "[cuckoo]\ninvalid = entry")
    with pytest.raises(CuckooConfigurationError) as e:
        config("cuckoo:invalid:entry", strict=True)
    e.match("No such configuration value exists")
Exemplo n.º 40
0
def test_invalid_section():
    set_cwd(tempfile.mkdtemp())
    Folders.create(cwd(), "conf")

    Files.create(cwd("conf"), "cuckoo.conf", "[invalid_section]\nfoo = bar")
    with pytest.raises(CuckooConfigurationError) as e:
        Config("cuckoo", strict=True)
    e.match("Config section.*not found")

    Files.create(cwd("conf"), "cuckoo.conf", "[cuckoo]\ninvalid = entry")
    with pytest.raises(CuckooConfigurationError) as e:
        config("cuckoo:invalid:entry", strict=True)
    e.match("No such configuration value exists")
Exemplo n.º 41
0
def test_confdir():
    set_cwd(tempfile.mkdtemp())
    Folders.create(cwd(), "conf")
    Files.create(
        cwd("conf"), "cuckoo.conf",
        "[cuckoo]\ndelete_original = yes"
    )
    Files.create(
        cwd("conf"), "virtualbox.conf",
        "[virtualbox]\npath = /usr/bin/VBoxManage"
    )
    cfg = Config.from_confdir(cwd("conf"))
    assert cfg["cuckoo"]["cuckoo"]["delete_original"] is True
    assert cfg["virtualbox"]["virtualbox"]["path"] == "/usr/bin/VBoxManage"
Exemplo n.º 42
0
    def set_path(self, analysis_path):
        """Set analysis folder path.
        @param analysis_path: analysis folder path.
        """
        self.analysis_path = analysis_path
        self.file_path = os.path.realpath(self._get_analysis_path("binary"))
        self.reports_path = self._get_analysis_path("reports")
        self.shots_path = self._get_analysis_path("shots")
        self.pcap_path = self._get_analysis_path("dump.pcap")

        try:
            Folders.create(self.reports_path)
        except CuckooOperationalError as e:
            raise CuckooReportError(e)
Exemplo n.º 43
0
    def set_path(self, analysis_path):
        """Set analysis folder path.
        @param analysis_path: analysis folder path.
        """
        self.analysis_path = analysis_path
        self.file_path = os.path.realpath(self._get_analysis_path("binary"))
        self.reports_path = self._get_analysis_path("reports")
        self.shots_path = self._get_analysis_path("shots")
        self.pcap_path = self._get_analysis_path("dump.pcap")

        try:
            Folders.create(self.reports_path)
        except CuckooOperationalError as e:
            raise CuckooReportError(e)
Exemplo n.º 44
0
def test_sanitize():
    set_cwd(tempfile.mkdtemp())
    Folders.create(cwd(), "conf")
    Files.create(
        cwd("conf"), "cuckoo.conf", "[database]\n"
        "timeout = 42\n"
        "connection = postgresql://user:pass@localhost/cuckoo")
    cfg = Config.from_confdir(cwd("conf"))
    assert cfg["cuckoo"]["database"]["timeout"] == 42
    assert cfg["cuckoo"]["database"][
        "connection"] == "postgresql://*****:*****@localhost/cuckoo"

    cfg = Config.from_confdir(cwd("conf"), sanitize=True)
    assert cfg["cuckoo"]["database"]["timeout"] == 42
    assert cfg["cuckoo"]["database"]["connection"] == "*" * 8
Exemplo n.º 45
0
def test_migration_041_042():
    set_cwd(tempfile.mkdtemp())
    Folders.create(cwd(), "conf")
    Files.create(cwd("conf"), "cuckoo.conf", "[cuckoo]\ndelete_original = yes")
    Files.create(cwd("conf"), "virtualbox.conf",
                 "[virtualbox]\npath = /usr/bin/VBoxManage")
    cfg = Config.from_confdir(cwd("conf"), loose=True)
    cfg = migrate(cfg, "0.4.1", "0.4.2")
    assert cfg["cuckoo"]["cuckoo"]["analysis_size_limit"] == 104857600
    assert cfg["virtualbox"]["virtualbox"]["timeout"] == 300
    assert cfg["vmware"]["vmware"]["mode"] == "gui"
    assert cfg["vmware"]["vmware"]["path"] == "/usr/bin/vmrun"
    assert cfg["vmware"]["vmware"]["machines"] == ["cuckoo1"]
    assert cfg["vmware"]["cuckoo1"]["label"] == "../vmware-xp3.vmx,Snapshot1"
    assert cfg["vmware"]["cuckoo1"]["platform"] == "windows"
    assert cfg["vmware"]["cuckoo1"]["ip"] == "192.168.54.111"
Exemplo n.º 46
0
def test_sanitize():
    set_cwd(tempfile.mkdtemp())
    Folders.create(cwd(), "conf")
    Files.create(
        cwd("conf"), "cuckoo.conf",
        "[database]\n"
        "timeout = 42\n"
        "connection = postgresql://user:pass@localhost/cuckoo"
    )
    cfg = Config.from_confdir(cwd("conf"))
    assert cfg["cuckoo"]["database"]["timeout"] == 42
    assert cfg["cuckoo"]["database"]["connection"] == "postgresql://*****:*****@localhost/cuckoo"

    cfg = Config.from_confdir(cwd("conf"), sanitize=True)
    assert cfg["cuckoo"]["database"]["timeout"] == 42
    assert cfg["cuckoo"]["database"]["connection"] == "*"*8
Exemplo n.º 47
0
def tasks_delete(task_id):
    response = {}

    task = db.view_task(task_id)
    if not task:
        return json_error(404, "Task not found")

    if task.status == TASK_RUNNING:
        return json_error(
            500, "The task is currently being processed, cannot delete")

    if not db.delete_task(task_id):
        return json_error(500,
                          "An error occurred while trying to delete the task")

    Folders.delete(cwd("storage", "analyses", "%d" % task_id))
    response["status"] = "OK"
    return jsonify(response)
Exemplo n.º 48
0
    def create_dirs(self, id=None):
        """Create the folders for this analysis. Returns True if
        all folders were created. False if not"""
        if not id:
            id = self.id

        for task_dir in self.dirs:
            create_dir = cwd(task_dir, analysis=id)
            try:
                if not os.path.exists(create_dir):
                    Folders.create(create_dir)
            except CuckooOperationalError as e:
                log.error(
                    "Unable to create folder '%s' for task #%s Error: %s",
                    create_dir, id, e)
                return False

        return True
Exemplo n.º 49
0
def test_migration_050_060():
    set_cwd(tempfile.mkdtemp())
    Folders.create(cwd(), "conf")
    Files.create(cwd("conf"), "cuckoo.conf", "[cuckoo]")
    cfg = Config.from_confdir(cwd("conf"), loose=True)
    cfg = migrate(cfg, "0.5.0", "0.6.0")
    assert cfg["cuckoo"]["resultserver"] == {
        "ip": "192.168.56.1",
        "port": 2042,
        "store_csvs": False,
        "upload_max_size": 10485760,
    }
    assert cfg["processing"] == {
        "analysisinfo": {
            "enabled": True,
        },
        "behavior": {
            "enabled": True,
        },
        "debug": {
            "enabled": True,
        },
        "dropped": {
            "enabled": True,
        },
        "network": {
            "enabled": True,
        },
        "static": {
            "enabled": True,
        },
        "strings": {
            "enabled": True,
        },
        "targetinfo": {
            "enabled": True,
        },
        "virustotal": {
            "enabled":
            True,
            "key":
            "a0283a2c3d55728300d064874239b5346fb991317e8449fe43c902879d758088",
        },
    }
Exemplo n.º 50
0
def test_migration_050_060():
    set_cwd(tempfile.mkdtemp())
    Folders.create(cwd(), "conf")
    Files.create(cwd("conf"), "cuckoo.conf", "[cuckoo]")
    cfg = Config.from_confdir(cwd("conf"), loose=True)
    cfg = migrate(cfg, "0.5.0", "0.6.0")
    assert cfg["cuckoo"]["resultserver"] == {
        "ip": "192.168.56.1",
        "port": 2042,
        "store_csvs": False,
        "upload_max_size": 10485760,
    }
    assert cfg["processing"] == {
        "analysisinfo": {
            "enabled": True,
        },
        "behavior": {
            "enabled": True,
        },
        "debug": {
            "enabled": True,
        },
        "dropped": {
            "enabled": True,
        },
        "network": {
            "enabled": True,
        },
        "static": {
            "enabled": True,
        },
        "strings": {
            "enabled": True,
        },
        "targetinfo": {
            "enabled": True,
        },
        "virustotal": {
            "enabled": True,
            "key": "a0283a2c3d55728300d064874239b5346fb991317e8449fe43c902879d758088",
        },
    }
Exemplo n.º 51
0
def tasks_delete(task_id):
    response = {}

    task = db.view_task(task_id)
    if not task:
        return json_error(404, "Task not found")

    if task.status == TASK_RUNNING:
        return json_error(
            500, "The task is currently being processed, cannot delete"
        )

    if not db.delete_task(task_id):
        return json_error(
            500, "An error occurred while trying to delete the task"
        )

    Folders.delete(cwd("storage", "analyses", "%d" % task_id))
    response["status"] = "OK"
    return jsonify(response)
Exemplo n.º 52
0
def test_migration_042_050():
    set_cwd(tempfile.mkdtemp())
    Folders.create(cwd(), "conf")
    Files.create(
        cwd("conf"), "cuckoo.conf", """
[cuckoo]
delete_original = yes
analysis_timeout = 122
critical_timeout = 601
analysis_size_limit = 123456
use_sniffer = no
""")
    Files.create(
        cwd("conf"), "virtualbox.conf", """
[virtualbox]
path = /usr/bin/VBoxManage
timeout = 1337
""")
    cfg = Config.from_confdir(cwd("conf"), loose=True)
    cfg = migrate(cfg, "0.4.2", "0.5.0")
    assert "analysis_timeout" not in cfg["cuckoo"]["cuckoo"]
    assert cfg["cuckoo"]["cuckoo"]["version_check"] is True
    assert cfg["cuckoo"]["cuckoo"]["memory_dump"] is False
    assert "analysis_size_limit" not in cfg["cuckoo"]["cuckoo"]
    assert cfg["cuckoo"]["processing"]["analysis_size_limit"] == "123456"
    assert cfg["cuckoo"]["processing"]["resolve_dns"] is True
    assert cfg["cuckoo"]["database"]["connection"] is None
    assert cfg["cuckoo"]["database"]["timeout"] is None
    assert cfg["cuckoo"]["timeouts"]["default"] == 122
    assert cfg["cuckoo"]["timeouts"]["critical"] == 601
    assert cfg["cuckoo"]["timeouts"]["vm_state"] == 1337
    assert "use_sniffer" not in cfg["cuckoo"]["cuckoo"]
    assert cfg["cuckoo"]["sniffer"]["enabled"] == "no"
    assert cfg["cuckoo"]["sniffer"]["tcpdump"] == "/usr/sbin/tcpdump"
    assert cfg["cuckoo"]["sniffer"]["interface"] == "vboxnet0"
    assert cfg["cuckoo"]["sniffer"]["bpf"] is None
    assert cfg["cuckoo"]["graylog"]["enabled"] is False
    assert cfg["cuckoo"]["graylog"]["host"] == "localhost"
    assert cfg["cuckoo"]["graylog"]["port"] == 12201
    assert cfg["cuckoo"]["graylog"]["level"] == "error"
    assert "timeout" not in cfg["virtualbox"]["virtualbox"]
Exemplo n.º 53
0
def test_migration_041_042():
    set_cwd(tempfile.mkdtemp())
    Folders.create(cwd(), "conf")
    Files.create(
        cwd("conf"), "cuckoo.conf",
        "[cuckoo]\ndelete_original = yes"
    )
    Files.create(
        cwd("conf"), "virtualbox.conf",
        "[virtualbox]\npath = /usr/bin/VBoxManage"
    )
    cfg = Config.from_confdir(cwd("conf"), loose=True)
    cfg = migrate(cfg, "0.4.1", "0.4.2")
    assert cfg["cuckoo"]["cuckoo"]["analysis_size_limit"] == 104857600
    assert cfg["virtualbox"]["virtualbox"]["timeout"] == 300
    assert cfg["vmware"]["vmware"]["mode"] == "gui"
    assert cfg["vmware"]["vmware"]["path"] == "/usr/bin/vmrun"
    assert cfg["vmware"]["vmware"]["machines"] == ["cuckoo1"]
    assert cfg["vmware"]["cuckoo1"]["label"] == "../vmware-xp3.vmx,Snapshot1"
    assert cfg["vmware"]["cuckoo1"]["platform"] == "windows"
    assert cfg["vmware"]["cuckoo1"]["ip"] == "192.168.54.111"
Exemplo n.º 54
0
    def task_delete(request, task_id):
        """
        Deletes a task
        :param body: required: task_id
        :return:
        """
        task = db.view_task(task_id)
        if task:
            if task.status == TASK_RUNNING:
                return json_fatal_response("The task is currently being "
                                           "processed, cannot delete")

            if db.delete_task(task_id):
                Folders.delete(
                    os.path.join(cwd(), "storage", "analyses", "%d" % task_id))
            else:
                return json_fatal_response("An error occurred while trying to "
                                           "delete the task")
        else:
            return json_error_response("Task not found")

        return JsonResponse({"status": True})
Exemplo n.º 55
0
    def task_delete(request, task_id):
        """
        Deletes a task
        :param body: required: task_id
        :return:
        """
        task = db.view_task(task_id)
        if task:
            if task.status == TASK_RUNNING:
                return json_fatal_response("The task is currently being "
                                           "processed, cannot delete")

            if db.delete_task(task_id):
                Folders.delete(os.path.join(cwd(), "storage",
                                            "analyses", "%d" % task_id))
            else:
                return json_fatal_response("An error occurred while trying to "
                                           "delete the task")
        else:
            return json_error_response("Task not found")

        return JsonResponse({"status": True})
Exemplo n.º 56
0
def test_migration_042_050():
    set_cwd(tempfile.mkdtemp())
    Folders.create(cwd(), "conf")
    Files.create(cwd("conf"), "cuckoo.conf", """
[cuckoo]
delete_original = yes
analysis_timeout = 122
critical_timeout = 601
analysis_size_limit = 123456
use_sniffer = no
""")
    Files.create(cwd("conf"), "virtualbox.conf", """
[virtualbox]
path = /usr/bin/VBoxManage
timeout = 1337
""")
    cfg = Config.from_confdir(cwd("conf"), loose=True)
    cfg = migrate(cfg, "0.4.2", "0.5.0")
    assert "analysis_timeout" not in cfg["cuckoo"]["cuckoo"]
    assert cfg["cuckoo"]["cuckoo"]["version_check"] is True
    assert cfg["cuckoo"]["cuckoo"]["memory_dump"] is False
    assert "analysis_size_limit" not in cfg["cuckoo"]["cuckoo"]
    assert cfg["cuckoo"]["processing"]["analysis_size_limit"] == "123456"
    assert cfg["cuckoo"]["processing"]["resolve_dns"] is True
    assert cfg["cuckoo"]["database"]["connection"] is None
    assert cfg["cuckoo"]["database"]["timeout"] is None
    assert cfg["cuckoo"]["timeouts"]["default"] == 122
    assert cfg["cuckoo"]["timeouts"]["critical"] == 601
    assert cfg["cuckoo"]["timeouts"]["vm_state"] == 1337
    assert "use_sniffer" not in cfg["cuckoo"]["cuckoo"]
    assert cfg["cuckoo"]["sniffer"]["enabled"] == "no"
    assert cfg["cuckoo"]["sniffer"]["tcpdump"] == "/usr/sbin/tcpdump"
    assert cfg["cuckoo"]["sniffer"]["interface"] == "vboxnet0"
    assert cfg["cuckoo"]["sniffer"]["bpf"] is None
    assert cfg["cuckoo"]["graylog"]["enabled"] is False
    assert cfg["cuckoo"]["graylog"]["host"] == "localhost"
    assert cfg["cuckoo"]["graylog"]["port"] == 12201
    assert cfg["cuckoo"]["graylog"]["level"] == "error"
    assert "timeout" not in cfg["virtualbox"]["virtualbox"]
Exemplo n.º 57
0
def task(task_id, options, conf, results, filename="a.txt"):
    Folders.create(cwd(), ["conf", "storage"])
    Folders.create(cwd("storage"), ["analyses", "binaries"])
    Folders.create(cwd("storage", "analyses"), "%s" % task_id)
    Folders.create(cwd("storage", "analyses", "%s" % task_id), ["reports"])

    write_cuckoo_conf({
        "reporting": conf,
    })

    task = {
        "id": task_id,
        "options": options,
        "target": filename,
    }
    RunReporting(task, results).run()
Exemplo n.º 58
0
def task(task_id, options, conf, results, filename="a.txt"):
    Folders.create(cwd(), ["conf", "storage"])
    Folders.create(cwd("storage"), ["analyses", "binaries"])
    Folders.create(cwd("storage", "analyses"), "%s" % task_id)
    Folders.create(cwd("storage", "analyses", "%s" % task_id), [
        "reports"
    ])

    write_cuckoo_conf({
        "reporting": conf,
    })

    task = {
        "id": task_id,
        "options": options,
        "target": filename,
    }
    RunReporting(task, results).run()
Exemplo n.º 59
0
    def pre(self, submit_type, data, options=None):
        """
        The first step to submitting new analysis.
        @param submit_type: "files" or "strings"
        @param data: a list of dicts containing "name" (file name)
                and "data" (file data) or a list of strings (urls or hashes)
        @return: submit id
        """
        if submit_type not in ("strings", "files"):
            log.error("Bad parameter '%s' for submit_type", submit_type)
            return False

        path_tmp = Folders.create_temp()
        submit_data = {
            "data": [],
            "errors": [],
            "options": options or {},
        }

        if submit_type == "strings":
            for line in data:
                self._handle_string(submit_data, path_tmp, line.strip())

        if submit_type == "files":
            for entry in data:
                filename = Storage.get_filename_from_path(entry["name"])
                filepath = Files.create(path_tmp, filename, entry["data"])
                submit_data["data"].append({
                    "type": "file",
                    "data": filepath,
                    "options": self.translate_options_to(
                        entry.get("options", {})
                    ),
                })

        return db.add_submit(path_tmp, submit_type, submit_data)
Exemplo n.º 60
0
 def test_cuckoo_conf(self):
     Folders.create(cwd(), "conf")
     write_cuckoo_conf()