本文整理汇总了Python中cuckoo.common.config.Config类的典型用法代码示例。如果您正苦于以下问题:Python Config类的具体用法?Python Config怎么用?Python Config使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Config类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_no_superfluous_conf
def test_no_superfluous_conf(p):
"""Tests that upon CWD creation no superfluous configuration values are
writted out (which may happen after a configuration migration)."""
set_cwd(tempfile.mkdtemp())
cuckoo_create()
Config.from_confdir(cwd("conf"))
p.error.assert_not_called()
示例2: test_unknown_conf_file
def test_unknown_conf_file():
Files.create(
cwd("conf"), "foobar.conf",
"[derp]\nfoo = bar"
)
cfg = Config.from_confdir(cwd("conf"))
assert "derp" not in cfg["foobar"]
cfg = Config.from_confdir(cwd("conf"), loose=True)
assert cfg["foobar"]["derp"]["foo"] == "bar"
示例3: test_unknown_section
def test_unknown_section():
Files.create(
cwd("conf"), "cuckoo.conf",
"[virtualbox]\npath = /usr/bin/VBoxManage"
)
cfg = Config.from_confdir(cwd("conf"))
assert "virtualbox" not in cfg["cuckoo"]
cfg = Config.from_confdir(cwd("conf"), loose=True)
assert cfg["cuckoo"]["virtualbox"]["path"] == "/usr/bin/VBoxManage"
示例4: setup
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)
示例5: test_vms_count
def test_vms_count(self):
cfg = Config.from_confdir(self.DIRPATH, loose=True)
cfg = migrate(cfg, self.VERSION)
assert cfg["virtualbox"]["virtualbox"]["mode"] == "headless"
assert len(cfg["virtualbox"]["virtualbox"]["machines"]) == 5
assert cfg["virtualbox"]["cuckoo3"]["ip"] == "192.168.56.103"
assert cfg["virtualbox"]["cuckoo3"]["osprofile"] is None
示例6: test_migration_203_204
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
示例7: test_migration_201_202
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
示例8: test_sanitize
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:[email protected]/cuckoo"
)
cfg = Config.from_confdir(cwd("conf"))
assert cfg["cuckoo"]["database"]["timeout"] == 42
assert cfg["cuckoo"]["database"]["connection"] == "postgresql://user:[email protected]/cuckoo"
cfg = Config.from_confdir(cwd("conf"), sanitize=True)
assert cfg["cuckoo"]["database"]["timeout"] == 42
assert cfg["cuckoo"]["database"]["connection"] == "*"*8
示例9: test_migration_100_110
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"
示例10: test_env
def test_env():
path = tempfile.mkstemp()[1]
os.environ["CUCKOO_FOOBAR"] = "top"
os.environ["FOOBAR"] = "kek"
mkdir(cwd("footopbar"))
open(path, "wb").write(ENV_EXAMPLE)
c = Config("cuckoo", cfg=path)
assert c.get("cuckoo")["tmppath"] == cwd() + "/footopbar"
open(path, "wb").write(ENV2_EXAMPLE)
with pytest.raises(CuckooConfigurationError) as e:
Config("cuckoo", cfg=path)
e.match("Missing environment variable")
os.environ.pop("FOOBAR")
os.environ.pop("CUCKOO_FOOBAR")
示例11: test_migration_204_205
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"
示例12: test_migration_200_201
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"] == []
示例13: test_migration_203_204
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
示例14: cuckoo_machine
def cuckoo_machine(vmname, action, ip, platform, options, tags,
interface, snapshot, resultserver):
db = Database()
cfg = Config.from_confdir(cwd("conf"))
machinery = cfg["cuckoo"]["cuckoo"]["machinery"]
machines = cfg[machinery][machinery]["machines"]
if action == "add":
if not ip:
sys.exit("You have to specify a legitimate IP address for --add.")
if db.view_machine(vmname):
sys.exit("A Virtual Machine with this name already exists!")
if vmname in machines:
sys.exit("A Virtual Machine with this name already exists!")
if resultserver and resultserver.count(":") == 1:
resultserver_ip, resultserver_port = resultserver.split(":")
resultserver_port = int(resultserver_port)
else:
resultserver_ip = cfg["cuckoo"]["resultserver"]["ip"]
resultserver_port = cfg["cuckoo"]["resultserver"]["port"]
machines.append(vmname)
cfg[machinery][vmname] = {
"label": vmname,
"platform": platform,
"ip": ip,
"options": options,
"snapshot": snapshot,
"interface": interface,
"resultserver_ip": resultserver_ip,
"resultserver_port": resultserver_port,
"tags": tags,
}
db.add_machine(
vmname, vmname, ip, platform, options, tags, interface, snapshot,
resultserver_ip, int(resultserver_port)
)
db.unlock_machine(vmname)
if action == "delete":
# TODO Add a db.del_machine() function for runtime modification.
if vmname not in machines:
sys.exit("A Virtual Machine with this name doesn't exist!")
machines.remove(vmname)
cfg[machinery].pop(vmname)
write_cuckoo_conf(cfg=cfg)
示例15: test_all_config_written
def test_all_config_written():
set_cwd(tempfile.mkdtemp())
cuckoo_create()
cfg = Config.from_confdir(cwd("conf"))
# This one is extra, ignore.
cfg["virtualbox"].pop("honeyd", None)
set_cwd(tempfile.mkdtemp())
mkdir(cwd("conf"))
lookups = []
class LookupDict(dict):
parents = []
def __getitem__(self, key):
lookups.append(":".join(self.parents + [key]))
return dict.__getitem__(key)
class Template(jinja2.Template):
def render(self, kw):
orig_config = kw["config"]
def lookup_config(s):
# For some reason this is called multiple times (?).
if s not in lookups:
lookups.append(s)
return orig_config(s)
kw["config"] = lookup_config
for key, value in kw.items():
if key == "config":
continue
for key2, value2 in value.items():
value[key2] = LookupDict(value2)
value[key2].parents = [key, key2]
return jinja2.Template.render(self, kw)
with mock.patch("cuckoo.core.init.jinja2") as p:
p.Template = Template
write_cuckoo_conf(cfg)
for key, value in cfg.items():
for key2, value2 in value.items():
for key3, value3 in value2.items():
assert "%s:%s:%s" % (key, key2, key3) in lookups
assert sorted(lookups) == sorted(set(lookups))