def test_version_resp404(capsys): set_cwd(tempfile.mkdtemp()) responses.add(responses.POST, "http://api.cuckoosandbox.org/checkversion.php", status=404) check_version() out, err = capsys.readouterr() assert "Checking for" in out assert "Error checking for" in out
def test_version_resp404(capsys): set_cwd(tempfile.mkdtemp()) responses.add(responses.GET, "https://cuckoosandbox.org/updates.json", status=404) check_version() out, err = capsys.readouterr() assert "Checking for" in out assert "Error checking for" in out
def test_version_respnotjson(capsys): set_cwd(tempfile.mkdtemp()) responses.add( responses.GET, "https://cuckoosandbox.org/updates.json", status=200, body="thisisnotevenjson" ) check_version() out, err = capsys.readouterr() assert "Checking for" in out assert "Error checking for" in out
def test_version_respinvld(capsys): set_cwd(tempfile.mkdtemp()) responses.add( responses.POST, "http://api.cuckoosandbox.org/checkversion.php", status=200, json=["this is not a dictionary"] ) check_version() out, err = capsys.readouterr() assert "Checking for" in out assert "Error checking for" in out
def test_version_resp404(capsys): set_cwd(tempfile.mkdtemp()) responses.add( responses.POST, "http://api.cuckoosandbox.org/checkversion.php", status=404 ) check_version() out, err = capsys.readouterr() assert "Checking for" in out assert "Error checking for" in out
def test_version_respinvld(capsys): set_cwd(tempfile.mkdtemp()) responses.add(responses.POST, "http://api.cuckoosandbox.org/checkversion.php", status=200, json=["this is not a dictionary"]) check_version() out, err = capsys.readouterr() assert "Checking for" in out assert "Error checking for" in out
def test_version_respnotjson(capsys): set_cwd(tempfile.mkdtemp()) responses.add(responses.POST, "http://api.cuckoosandbox.org/checkversion.php", status=200, body="thisisnotevenjson") check_version() out, err = capsys.readouterr() assert "Checking for" in out assert "Error checking for" in out
def test_check_version_disabled(capsys): set_cwd(tempfile.mkdtemp()) cuckoo_create(cfg={ "cuckoo": { "cuckoo": { "version_check": False, }, }, }) check_version() out, err = capsys.readouterr() assert "Checking for" not in out
def test_check_version_disabled(capsys): set_cwd(tempfile.mkdtemp()) cuckoo_create(cfg={ "cuckoo": { "cuckoo": { "version_check": False, }, }, }) check_version() out, err = capsys.readouterr() assert "Checking for" not in out
def test_version_20rc1_noupd(capsys): set_cwd(tempfile.mkdtemp()) responses.add( responses.POST, "http://api.cuckoosandbox.org/checkversion.php", status=200, json={ "error": False, "current": "2.0-rc1", "response": "NO_UPDATES", } ) check_version() out, err = capsys.readouterr() assert "Checking for" in out assert "You're good to go" in out
def test_version_newer(capsys): set_cwd(tempfile.mkdtemp()) responses.add( responses.GET, "https://cuckoosandbox.org/updates.json", status=200, json={ "version": "20.0.0", "blogposts": [], } ) check_version() out, err = capsys.readouterr() assert "Checking for" in out assert "Outdated!" in out assert "Cuckoo Sandbox version 20.0.0 is available now" in out
def test_version_20rc1_noupd(capsys): set_cwd(tempfile.mkdtemp()) responses.add(responses.POST, "http://api.cuckoosandbox.org/checkversion.php", status=200, json={ "error": False, "current": "2.0-rc1", "response": "NO_UPDATES", }) check_version() out, err = capsys.readouterr() assert "Checking for" in out assert "You're good to go" in out
def test_version_newer(capsys): set_cwd(tempfile.mkdtemp()) responses.add(responses.GET, "https://cuckoosandbox.org/updates.json", status=200, json={ "version": "20.0.0", "blogposts": [], }) check_version() out, err = capsys.readouterr() assert "Checking for" in out assert "Outdated!" in out assert "Cuckoo Sandbox version 20.0.0 is available now" in out
def test_version_newer(capsys): set_cwd(tempfile.mkdtemp()) responses.add( responses.POST, "http://api.cuckoosandbox.org/checkversion.php", status=200, json={ "error": False, "current": "20.0.0", "response": "NEW_VERSION", } ) check_version() out, err = capsys.readouterr() assert "Checking for" in out assert "Outdated!" in out assert "Cuckoo Sandbox version 20.0.0 is available now" in out
def test_version_newer(capsys): set_cwd(tempfile.mkdtemp()) responses.add(responses.POST, "http://api.cuckoosandbox.org/checkversion.php", status=200, json={ "error": False, "current": "20.0.0", "response": "NEW_VERSION", }) check_version() out, err = capsys.readouterr() assert "Checking for" in out assert "Outdated!" in out assert "Cuckoo Sandbox version 20.0.0 is available now" in out
def test_version_garbage(capsys): set_cwd(tempfile.mkdtemp()) responses.add(responses.GET, "https://cuckoosandbox.org/updates.json", status=200, json={ "version": "thisisnotaversion", "blogposts": [], }) check_version() out, err = capsys.readouterr() assert "Checking for" in out assert "Outdated!" in out # Just to be sure we emit the garbage as well. assert "Cuckoo Sandbox version thisisnotaversion is available now" in out
def test_version_garbage(capsys): set_cwd(tempfile.mkdtemp()) responses.add( responses.GET, "https://cuckoosandbox.org/updates.json", status=200, json={ "version": "thisisnotaversion", "blogposts": [], } ) check_version() out, err = capsys.readouterr() assert "Checking for" in out assert "Outdated!" in out # Just to be sure we emit the garbage as well. assert "Cuckoo Sandbox version thisisnotaversion is available now" in out
def test_version_garbage(capsys): set_cwd(tempfile.mkdtemp()) responses.add( responses.POST, "http://api.cuckoosandbox.org/checkversion.php", status=200, json={ "error": False, "current": "thisisnotaversion", "response": "NEW_VERSION", } ) check_version() out, err = capsys.readouterr() assert "Checking for" in out assert "Outdated!" in out # Just to be sure we emit the garbage as well. assert "Cuckoo Sandbox version thisisnotaversion is available now" in out
def test_version_garbage(capsys): set_cwd(tempfile.mkdtemp()) responses.add(responses.POST, "http://api.cuckoosandbox.org/checkversion.php", status=200, json={ "error": False, "current": "thisisnotaversion", "response": "NEW_VERSION", }) check_version() out, err = capsys.readouterr() assert "Checking for" in out assert "Outdated!" in out # Just to be sure we emit the garbage as well. assert "Cuckoo Sandbox version thisisnotaversion is available now" in out
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 latest_updates(): """Updates the latest Cuckoo version & blogposts at maximum once a day.""" next_check = datetime.datetime.now() - datetime.timedelta(days=1) if updates and updates["timestamp"] > next_check: return updates # It is possible for check_version() to fail. In that case we'll just have # Cuckoo wait another day to try again (for now anyway). latest = check_version() latest and updates.update(latest) updates["timestamp"] = datetime.datetime.now()
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))
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))
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))