Example #1
0
def cuckoo_main(max_analysis_count=0):
    """Cuckoo main loop.
    @param max_analysis_count: kill cuckoo after this number of analyses
    """
    rs, sched = None, None

    def stop():
        if sched:
            sched.running = False
        if rs:
            rs.instance.stop()

        Pidfile("cuckoo").remove()
        if sched:
            sched.stop()

    def handle_sigterm(sig, f):
        stop()

    # Handle a SIGTERM, to reduce the chance of Cuckoo exiting without
    # cleaning
    signal.signal(signal.SIGTERM, handle_sigterm)

    try:
        rs = ResultServer()
        sched = Scheduler(max_analysis_count)
        sched.start()
    except KeyboardInterrupt:
        log.info("CTRL+C detected! Stopping.. This can take a few seconds")
    finally:
        if Pidfile("cuckoo").exists():
            stop()
Example #2
0
def cuckoo_main(max_analysis_count=0):
    """Cuckoo main loop.
    @param max_analysis_count: kill cuckoo after this number of analyses
    """
    try:
        ResultServer()
        sched = Scheduler(max_analysis_count)
        sched.start()
    except KeyboardInterrupt:
        sched.stop()
def test_scheduler_initialize(p):
    set_cwd(tempfile.mkdtemp())
    cuckoo_create(
        cfg={
            "cuckoo": {
                "cuckoo": {
                    "machinery": "machin3",
                },
            },
            "routing": {
                "routing": {
                    "internet": "intern0t",
                },
                "vpn": {
                    "enabled": True,
                    "vpns": [
                        "a",
                    ],
                },
                "a": {
                    "name": "a",
                    "interface": "vpnint0",
                },
            },
        })
    Database().connect()
    s = Scheduler()

    m = mock.MagicMock()
    m.return_value.machines.return_value = [
        Dictionary(name="cuckoo1", interface="int1", ip="1.2.3.4"),
        Dictionary(name="cuckoo2", interface="int2", ip="5.6.7.8"),
    ]

    with mock.patch.dict(cuckoo.machinery.plugins, {"machin3": m}):
        s.initialize()

    m.return_value.initialize.assert_called_once_with("machin3")
    assert p.call_count == 4
    p.assert_any_call("forward_disable", "int1", "vpnint0", "1.2.3.4")
    p.assert_any_call("forward_disable", "int2", "vpnint0", "5.6.7.8")
    p.assert_any_call("forward_disable", "int1", "intern0t", "1.2.3.4")
    p.assert_any_call("forward_disable", "int2", "intern0t", "5.6.7.8")
Example #4
0
def test_scheduler_initialize(p):
    set_cwd(tempfile.mkdtemp())
    cuckoo_create(cfg={
        "cuckoo": {
            "cuckoo": {
                "machinery": "machin3",
            },
        },
        "routing": {
            "routing": {
                "internet": "intern0t",
            },
            "vpn": {
                "enabled": True,
                "vpns": [
                    "a",
                ],
            },
            "a": {
                "name": "a",
                "interface": "vpnint0",
            },
        },
    })
    Database().connect()
    s = Scheduler()

    m = mock.MagicMock()
    m.return_value.machines.return_value = [
        Dictionary(name="cuckoo1", interface="int1", ip="1.2.3.4"),
        Dictionary(name="cuckoo2", interface="int2", ip="5.6.7.8"),
    ]

    with mock.patch.dict(cuckoo.machinery.plugins, {"machin3": m}):
        s.initialize()

    m.return_value.initialize.assert_called_once_with("machin3")
    assert p.call_count == 4
    p.assert_any_call("forward_disable", "int1", "vpnint0", "1.2.3.4")
    p.assert_any_call("forward_disable", "int2", "vpnint0", "5.6.7.8")
    p.assert_any_call("forward_disable", "int1", "intern0t", "1.2.3.4")
    p.assert_any_call("forward_disable", "int2", "intern0t", "5.6.7.8")
Example #5
0
def test_scheduler_initialize_novpn(p):
    set_cwd(tempfile.mkdtemp())
    cuckoo_create(cfg={
        "cuckoo": {
            "cuckoo": {
                "machinery": "machin3",
            },
        },
    })
    Database().connect()
    s = Scheduler()

    m = mock.MagicMock()
    m.return_value.machines.return_value = [
        Dictionary(name="cuckoo1", interface="int1", ip="1.2.3.4"),
        Dictionary(name="cuckoo2", interface="int2", ip="5.6.7.8"),
    ]

    with mock.patch.dict(cuckoo.machinery.plugins, {"machin3": m}):
        s.initialize()

    m.return_value.initialize.assert_called_once_with("machin3")
    p.assert_not_called()
Example #6
0
def test_scheduler_initialize_novpn(p):
    set_cwd(tempfile.mkdtemp())
    cuckoo_create(cfg={
        "cuckoo": {
            "cuckoo": {
                "machinery": "machin3",
            },
        },
    })
    Database().connect()
    s = Scheduler()

    m = mock.MagicMock()
    m.return_value.machines.return_value = [
        Dictionary(name="cuckoo1", interface="int1", ip="1.2.3.4"),
        Dictionary(name="cuckoo2", interface="int2", ip="5.6.7.8"),
    ]

    with mock.patch.dict(cuckoo.machinery.plugins, {"machin3": m}):
        s.initialize()

    m.return_value.initialize.assert_called_once_with("machin3")
    p.assert_not_called()
Example #7
0
def cuckoo_main(max_analysis_count=0):
    """Cuckoo main loop.
    @param max_analysis_count: kill cuckoo after this number of analyses
    """
    try:
        ResultServer()
        sched = Scheduler(max_analysis_count)
        sched.start()
    except KeyboardInterrupt:
        sched.stop()