def test_init_routing_vpns(p): set_cwd(tempfile.mkdtemp()) cuckoo_create(cfg={ "routing": { "vpn": { "enabled": True, "vpns": [ "1", "2", ], }, "1": { "name": "1", "interface": "tun1", "rt_table": "main", }, "2": { "name": "2", "interface": "tun2", "rt_table": "main", }, }, }) init_routing() assert p.call_count == 12 p.assert_any_call("nic_available", "tun1") p.assert_any_call("rt_available", "main") p.assert_any_call("nic_available", "tun2") p.assert_any_call("disable_nat", "tun1") p.assert_any_call("disable_nat", "tun2") p.assert_any_call("enable_nat", "tun1") p.assert_any_call("enable_nat", "tun2") p.assert_any_call("flush_rttable", "main") p.assert_any_call("init_rttable", "main", "tun1") p.assert_any_call("init_rttable", "main", "tun2")
def test_init_routing_vpns(p): set_cwd(tempfile.mkdtemp()) cuckoo_create(cfg={ "routing": { "vpn": { "enabled": True, "vpns": [ "1", "2", ], }, "1": { "name": "1", "interface": "tun1", "rt_table": "main", }, "2": { "name": "2", "interface": "tun2", "rt_table": "main", }, }, }) init_routing() assert p.call_count == 12 p.assert_any_call("nic_available", "tun1") p.assert_any_call("rt_available", "main") p.assert_any_call("nic_available", "tun2") p.assert_any_call("disable_nat", "tun1") p.assert_any_call("disable_nat", "tun2") p.assert_any_call("enable_nat", "tun1") p.assert_any_call("enable_nat", "tun2") p.assert_any_call("flush_rttable", "main") p.assert_any_call("init_rttable", "main", "tun1") p.assert_any_call("init_rttable", "main", "tun2")
def test_init_routing_internet_exc(p): set_cwd(tempfile.mkdtemp()) cuckoo_create(cfg={ "routing": { "routing": { "internet": "eth0", }, }, }) def nic_notavail(cmd, arg): return False def rt_notavail(cmd, arg): if cmd == "rt_available": return False return True p.side_effect = nic_notavail with pytest.raises(CuckooStartupError) as e: init_routing() p.assert_called_once() e.match("configured as dirty line is not") p.side_effect = rt_notavail with pytest.raises(CuckooStartupError) as e: init_routing() e.match("routing table that has been")
def test_init_routing_internet_exc(p): set_cwd(tempfile.mkdtemp()) cuckoo_create(cfg={ "routing": { "routing": { "internet": "eth0", }, }, }) def nic_notavail(cmd, arg): return False def rt_notavail(cmd, arg): if cmd == "rt_available": return False return True p.side_effect = nic_notavail with pytest.raises(CuckooStartupError) as e: init_routing() p.assert_called_once() e.match("configured as dirty line is not") p.side_effect = rt_notavail with pytest.raises(CuckooStartupError) as e: init_routing() e.match("routing table that has been")
def test_init_routing_unknown(p): set_cwd(tempfile.mkdtemp()) cuckoo_create(cfg={ "routing": { "routing": { "route": "notaroute", }, }, }) with pytest.raises(CuckooStartupError) as e: init_routing() e.match("is it supposed to be a VPN")
def test_init_routing_unknown(p): set_cwd(tempfile.mkdtemp()) cuckoo_create(cfg={ "routing": { "routing": { "route": "notaroute", }, }, }) with pytest.raises(CuckooStartupError) as e: init_routing() e.match("is it supposed to be a VPN")
def test_init_routing_tor_inetsim_noint(p): set_cwd(tempfile.mkdtemp()) cuckoo_create(cfg={ "routing": { "tor": { "enabled": True, }, "inetsim": { "enabled": True, }, }, }) init_routing() p.assert_not_called()
def test_init_routing_tor_inetsim_noint(p): set_cwd(tempfile.mkdtemp()) cuckoo_create(cfg={ "routing": { "tor": { "enabled": True, }, "inetsim": { "enabled": True, }, }, }) init_routing() p.assert_not_called()
def cuckoo_init(level, ctx, cfg=None): """Initialize Cuckoo configuration. @param quiet: enable quiet mode. """ logo() # It would appear this is the first time Cuckoo is being run (on this # Cuckoo Working Directory anyway). if not os.path.isdir(cwd()) or not os.listdir(cwd()): cuckoo_create(ctx.user, cfg) sys.exit(0) # Determine if this is a proper CWD. if not os.path.exists(cwd(".cwd")): sys.exit( "No proper Cuckoo Working Directory was identified, did you pass " "along the correct directory?" ) init_console_logging(level) check_configs() check_version() ctx.log and init_logging(level) # Determine if any CWD updates are required and if so, do them. current = open(cwd(".cwd"), "rb").read().strip() latest = open(cwd(".cwd", private=True), "rb").read().strip() if current != latest: migrate_cwd() open(cwd(".cwd"), "wb").write(latest) Database().connect() # Load additional Signatures. load_signatures() init_modules() init_tasks() init_yara(True) init_binaries() init_rooter() init_routing()
def cuckoo_init(level, ctx, cfg=None): """Initialize Cuckoo configuration. @param quiet: enable quiet mode. """ logo() # It would appear this is the first time Cuckoo is being run (on this # Cuckoo Working Directory anyway). if not os.path.isdir(cwd()) or not os.listdir(cwd()): cuckoo_create(ctx.user, cfg) sys.exit(0) # Determine if this is a proper CWD. if not os.path.exists(cwd(".cwd")): sys.exit( "No proper Cuckoo Working Directory was identified, did you pass " "along the correct directory?" ) # Determine if any CWD updates are required. current = open(cwd(".cwd"), "rb").read() latest = open(cwd(".cwd", private=True), "rb").read() if current != latest: pass check_configs() check_version() if ctx.log: init_logging(level) else: init_console_logging(level) Database().connect() # Load additional Signatures. load_signatures() init_modules() init_tasks() init_yara(True) init_binaries() init_rooter() init_routing()
def test_init_routing_internet_normal(p): set_cwd(tempfile.mkdtemp()) cuckoo_create(cfg={ "routing": { "routing": { "internet": "eth0", "rt_table": "table", }, }, }) p.side_effect = True, True, None, None, None, None init_routing() assert p.call_count == 6 p.assert_any_call("nic_available", "eth0") p.assert_any_call("rt_available", "table") p.assert_any_call("disable_nat", "eth0") p.assert_any_call("enable_nat", "eth0") p.assert_any_call("flush_rttable", "table") p.assert_any_call("init_rttable", "table", "eth0")
def test_init_routing_internet_normal(p): set_cwd(tempfile.mkdtemp()) cuckoo_create(cfg={ "routing": { "routing": { "internet": "eth0", "rt_table": "table", }, }, }) p.side_effect = True, True, None, None, None, None init_routing() assert p.call_count == 6 p.assert_any_call("nic_available", "eth0") p.assert_any_call("rt_available", "table") p.assert_any_call("disable_nat", "eth0") p.assert_any_call("enable_nat", "eth0") p.assert_any_call("flush_rttable", "table") p.assert_any_call("init_rttable", "table", "eth0")
def test_init_routing_vpndisabled(p): set_cwd(tempfile.mkdtemp()) cuckoo_create(cfg={ "routing": { "routing": { "route": "thisisvpn", }, "vpn": { "vpns": [ "thisisvpn", ], }, "thisisvpn": { "name": "vpn1", "description": "this is vpn", }, }, }) with pytest.raises(CuckooStartupError) as e: init_routing() e.match("VPNs have not been enabled")
def test_init_routing_vpndisabled(p): set_cwd(tempfile.mkdtemp()) cuckoo_create(cfg={ "routing": { "routing": { "route": "thisisvpn", }, "vpn": { "vpns": [ "thisisvpn", ], }, "thisisvpn": { "name": "vpn1", "description": "this is vpn", }, }, }) with pytest.raises(CuckooStartupError) as e: init_routing() e.match("VPNs have not been enabled")
red("In order to use the Cuckoo Web Interface it is required to have " "MongoDB up-and-running and enabled in Cuckoo. Please refer to our " "official documentation as well as the $CWD/conf/reporting.conf file." )) mongo.connect() # Connect to ElasticSearch (optional). elastic.init() elastic.connect() # In case we have VPNs enabled we need to initialize through the following # two methods as they verify the interaction with VPNs as well as gather # which VPNs are available (for representation upon File/URL submission). init_rooter() init_routing() DEBUG = False # Database settings. We don't need it. DATABASES = {} SITE_ID = 1 # If you set this to False, Django will make some optimizations so as not # to load the internationalization machinery. USE_I18N = True # If you set this to False, Django will not format dates, numbers and # calendars according to the current locale. USE_L10N = True
def test_init_routing_default(p): set_cwd(tempfile.mkdtemp()) cuckoo_create() init_routing() p.assert_not_called()
def cuckoo_init(level, ctx, cfg=None): """Initialize Cuckoo configuration. @param quiet: enable quiet mode. """ logo() # It would appear this is the first time Cuckoo is being run (on this # Cuckoo Working Directory anyway). if not os.path.isdir(cwd()) or not os.listdir(cwd()): cuckoo_create(ctx.user, cfg) sys.exit(0) # Determine if this is a proper CWD. if not os.path.exists(cwd(".cwd")): sys.exit( "No proper Cuckoo Working Directory was identified, did you pass " "along the correct directory? For new installations please use a " "non-existant directory to build up the CWD! You can craft a CWD " "manually, but keep in mind that the CWD layout may change along " "with Cuckoo releases (and don't forget to fill out '$CWD/.cwd')!") init_console_logging(level) # Only one Cuckoo process should exist per CWD. Run this check before any # files are possibly modified. Note that we mkdir $CWD/pidfiles/ here as # its CWD migration rules only kick in after the pidfile check. mkdir(cwd("pidfiles")) pidfile = Pidfile("cuckoo") if pidfile.exists(): log.error(red("Cuckoo is already running. PID: %s"), pidfile.pid) sys.exit(1) pidfile.create() check_configs() check_version() ctx.log and init_logging(level) # Determine if any CWD updates are required and if so, do them. current = open(cwd(".cwd"), "rb").read().strip() latest = open(cwd(".cwd", private=True), "rb").read().strip() if current != latest: migrate_cwd() open(cwd(".cwd"), "wb").write(latest) # Ensure the user is able to create and read temporary files. if not ensure_tmpdir(): sys.exit(1) Database().connect() # Load additional Signatures. load_signatures() init_modules() init_tasks() init_yara() init_binaries() init_rooter() init_routing() signatures = 0 for sig in cuckoo.signatures: if not sig.enabled: continue signatures += 1 if not signatures: log.warning( "It appears that you haven't loaded any Cuckoo Signatures. " "Signatures are highly recommended and improve & enrich the " "information extracted during an analysis. They also make up " "for the analysis score that you see in the Web Interface - so, " "pretty important!") log.warning( "You'll be able to fetch all the latest Cuckoo Signaturs, Yara " "rules, and more goodies by running the following command:") log.info("$ %s", green(format_command("community")))
def cuckoo_init(level, ctx, cfg=None): """Initialize Cuckoo configuration. @param quiet: enable quiet mode. """ logo() # It would appear this is the first time Cuckoo is being run (on this # Cuckoo Working Directory anyway). if not os.path.isdir(cwd()) or not os.listdir(cwd()): cuckoo_create(ctx.user, cfg) sys.exit(0) # Determine if this is a proper CWD. if not os.path.exists(cwd(".cwd")): sys.exit( "No proper Cuckoo Working Directory was identified, did you pass " "along the correct directory? For new installations please use a " "non-existant directory to build up the CWD! You can craft a CWD " "manually, but keep in mind that the CWD layout may change along " "with Cuckoo releases (and don't forget to fill out '$CWD/.cwd')!" ) init_console_logging(level) # Only one Cuckoo process should exist per CWD. Run this check before any # files are possibly modified. Note that we mkdir $CWD/pidfiles/ here as # its CWD migration rules only kick in after the pidfile check. mkdir(cwd("pidfiles")) pidfile = Pidfile("cuckoo") if pidfile.exists(): log.error(red("Cuckoo is already running. PID: %s"), pidfile.pid) sys.exit(1) pidfile.create() check_configs() check_version() ctx.log and init_logging(level) # Determine if any CWD updates are required and if so, do them. current = open(cwd(".cwd"), "rb").read().strip() latest = open(cwd(".cwd", private=True), "rb").read().strip() if current != latest: migrate_cwd() open(cwd(".cwd"), "wb").write(latest) Database().connect() # Load additional Signatures. load_signatures() init_modules() init_tasks() init_yara() init_binaries() init_rooter() init_routing() signatures = 0 for sig in cuckoo.signatures: if not sig.enabled: continue signatures += 1 if not signatures: log.warning( "It appears that you haven't loaded any Cuckoo Signatures. " "Signatures are highly recommended and improve & enrich the " "information extracted during an analysis. They also make up " "for the analysis score that you see in the Web Interface - so, " "pretty important!" ) log.warning( "You'll be able to fetch all the latest Cuckoo Signaturs, Yara " "rules, and more goodies by running the following command:" ) raw = cwd(raw=True) if raw == "." or raw == "~/.cuckoo": command = "cuckoo community" elif " " in raw or "'" in raw: command = 'cuckoo --cwd "%s" community' % raw else: command = "cuckoo --cwd %s community" % raw log.info("$ %s", green(command))
"In order to use the Cuckoo Web Interface it is required to have " "MongoDB up-and-running and enabled in Cuckoo. Please refer to our " "official documentation as well as the $CWD/conf/reporting.conf file." )) mongo.connect() # Connect to ElasticSearch (optional). elastic.init() elastic.connect() # In case we have VPNs enabled we need to initialize through the following # two methods as they verify the interaction with VPNs as well as gather # which VPNs are available (for representation upon File/URL submission). init_rooter() init_routing() DEBUG = False # Database settings. We don't need it. DATABASES = {} SITE_ID = 1 # If you set this to False, Django will make some optimizations so as not # to load the internationalization machinery. USE_I18N = True # If you set this to False, Django will not format dates, numbers and # calendars according to the current locale. USE_L10N = True
def cuckoo_init(level, ctx, cfg=None): """Initialize Cuckoo configuration. @param quiet: enable quiet mode. """ logo() # It would appear this is the first time Cuckoo is being run (on this # Cuckoo Working Directory anyway). if not os.path.isdir(cwd()) or not os.listdir(cwd()): cuckoo_create(ctx.user, cfg) sys.exit(0) # Determine if this is a proper CWD. if not os.path.exists(cwd(".cwd")): sys.exit( "No proper Cuckoo Working Directory was identified, did you pass " "along the correct directory? For new installations please use a " "non-existant directory to build up the CWD! You can craft a CWD " "manually, but keep in mind that the CWD layout may change along " "with Cuckoo releases (and don't forget to fill out '$CWD/.cwd')!" ) init_console_logging(level) check_configs() check_version() ctx.log and init_logging(level) # Determine if any CWD updates are required and if so, do them. current = open(cwd(".cwd"), "rb").read().strip() latest = open(cwd(".cwd", private=True), "rb").read().strip() if current != latest: migrate_cwd() open(cwd(".cwd"), "wb").write(latest) Database().connect() # Load additional Signatures. load_signatures() init_modules() init_tasks() init_yara() init_binaries() init_rooter() init_routing() signatures = 0 for sig in cuckoo.signatures: if not sig.enabled: continue signatures += 1 if not signatures: log.warning( "It appears that you haven't loaded any Cuckoo Signatures. " "Signatures are highly recommended and improve & enrich the " "information extracted during an analysis. They also make up " "for the analysis score that you see in the Web Interface - so, " "pretty important!" ) log.warning( "You'll be able to fetch all the latest Cuckoo Signaturs, Yara " "rules, and more goodies by running the following command:" ) raw = cwd(raw=True) if raw == "." or raw == "~/.cuckoo": command = "cuckoo community" elif " " in raw or "'" in raw: command = 'cuckoo --cwd "%s" community' % raw else: command = "cuckoo --cwd %s community" % raw log.info("$ %s", green(command))
def test_init_routing_default(p): set_cwd(tempfile.mkdtemp()) cuckoo_create() init_routing() p.assert_not_called()
def cuckoo_init(level, ctx, cfg=None): """Initialize Cuckoo configuration. @param quiet: enable quiet mode. """ logo() # It would appear this is the first time Cuckoo is being run (on this # Cuckoo Working Directory anyway). if not os.path.isdir(cwd()) or not os.listdir(cwd()): cuckoo_create(ctx.user, cfg) sys.exit(0) # Determine if this is a proper CWD. if not os.path.exists(cwd(".cwd")): sys.exit( "No proper Cuckoo Working Directory was identified, did you pass " "along the correct directory?" ) init_console_logging(level) check_configs() check_version() ctx.log and init_logging(level) # Determine if any CWD updates are required and if so, do them. current = open(cwd(".cwd"), "rb").read().strip() latest = open(cwd(".cwd", private=True), "rb").read().strip() if current != latest: migrate_cwd() open(cwd(".cwd"), "wb").write(latest) Database().connect() # Load additional Signatures. load_signatures() init_modules() init_tasks() init_yara() init_binaries() init_rooter() init_routing() signatures = 0 for sig in cuckoo.signatures: if not sig.enabled: continue signatures += 1 if not signatures: log.warning( "It appears that you haven't loaded any Cuckoo Signatures. " "Signatures are highly recommended and improve & enrich the " "information extracted during an analysis. They also make up " "for the analysis score that you see in the Web Interface - so, " "pretty important!" ) log.warning( "You'll be able to fetch all the latest Cuckoo Signaturs, Yara " "rules, and more goodies by running the following command:" ) raw = cwd(raw=True) if raw == "." or raw == "~/.cuckoo": command = "cuckoo community" elif " " in raw or "'" in raw: command = 'cuckoo --cwd "%s" community' % raw else: command = "cuckoo --cwd %s community" % raw log.info("$ %s", green(command))