Ejemplo n.º 1
0
def test_mongo_connect_store_file():
    set_cwd(tempfile.mkdtemp())
    cuckoo_create(cfg={
        "reporting": {
            "mongodb": {
                "enabled": True,
                "db": "cuckootest",
            },
        },
    })

    mongo.init()
    assert mongo.database == "cuckootest"

    fd, filepath = tempfile.mkstemp()
    os.write(fd, "hello world")
    os.close(fd)
    f = File(filepath)

    r = MongoDB()
    r.init_once()
    id1 = r.store_file(f, "foobar.txt")
    id2 = r.store_file(f, "foobar.txt")
    assert id1 == id2

    assert mongo.db.fs.files.find_one({
        "sha256": f.get_sha256(),
    })["_id"] == id1

    assert mongo.grid.get(id1).read() == "hello world"
Ejemplo n.º 2
0
def test_mongo_connect_store_file():
    set_cwd(tempfile.mkdtemp())
    cuckoo_create(cfg={
        "reporting": {
            "mongodb": {
                "enabled": True,
                "db": "cuckootest",
            },
        },
    })

    mongo.init()
    assert mongo.database == "cuckootest"

    fd, filepath = tempfile.mkstemp()
    os.write(fd, "hello world")
    os.close(fd)
    f = File(filepath)

    r = MongoDB()
    r.init_once()
    id1 = r.store_file(f, "foobar.txt")
    id2 = r.store_file(f, "foobar.txt")
    assert id1 == id2

    assert mongo.db.fs.files.find_one({
        "sha256": f.get_sha256(),
    })["_id"] == id1

    assert mongo.grid.get(id1).read() == "hello world"
Ejemplo n.º 3
0
def test_mongodb_init_once_new(p):
    p.init.return_value = True
    MongoDB().init_once()
    p.db.collection_names.return_value = []
    p.db.cuckoo_schema.save.assert_called_once_with({
        "version": "1",
    })
    p.db.fs.files.ensure_index.assert_called_once()
Ejemplo n.º 4
0
import uuid

from django.http import HttpResponse, StreamingHttpResponse, JsonResponse
from guacamole.client import GuacamoleClient, GuacamoleError

from cuckoo.common.config import config
from cuckoo.common.objects import File
from cuckoo.core.database import Database
from cuckoo.reporting.mongodb import MongoDB
from cuckoo.misc import cwd
from cuckoo.web.utils import csrf_exempt, json_error_response, api_post

# TODO Yes, this is far from optimal. In the future we should find a better
# way to get results from the Cuckoo Web Interface to the analysis report (or
# simply disable this functionality altogether).
mdb = MongoDB()
mdb.init_once()

db = Database()
log = logging.getLogger(__name__)

sockets = {}
sockets_lock = threading.RLock()
read_lock = threading.RLock()
write_lock = threading.RLock()
pending_read_request = threading.Event()


class ControlApi(object):
    @staticmethod
    @csrf_exempt
Ejemplo n.º 5
0
import uuid

from django.http import HttpResponse, StreamingHttpResponse, JsonResponse
from guacamole.client import GuacamoleClient, GuacamoleError

from cuckoo.common.config import config
from cuckoo.common.objects import File
from cuckoo.core.database import Database
from cuckoo.reporting.mongodb import MongoDB
from cuckoo.misc import cwd
from cuckoo.web.utils import csrf_exempt, json_error_response, api_post

# TODO Yes, this is far from optimal. In the future we should find a better
# way to get results from the Cuckoo Web Interface to the analysis report (or
# simply disable this functionality altogether).
mdb = MongoDB()
mdb.init_once()

db = Database()
log = logging.getLogger(__name__)

sockets = {}
sockets_lock = threading.RLock()
read_lock = threading.RLock()
write_lock = threading.RLock()
pending_read_request = threading.Event()

class ControlApi(object):
    @staticmethod
    @csrf_exempt
    def tunnel(request, task_id):