class TestAgent(object): def setup(self): self.a = Agent("localhost", 8000) def test_upload(self): def none(*args, **kwargs): pass self.a.postfile = none self.a.upload("/tmp/hello", "contents") self.a.upload("/tmp/hello", u"contents")
def zer0m0n(ipaddr, port): log.setLevel(logging.INFO) log.info("Checking if we can reach the VM..") a = Agent(ipaddr, port) try: status = a.ping() except requests.RequestException: log.error("Couldn't reach the VM, is it up-and-running? Aborting..") return if not isinstance(status, dict) or status.get("status") != "Cuckoo Agent!": log.error("Agent in VM isn't the new Cuckoo Agent? Aborting..") return log.info("Patching zer0m0n-related files.") vmcloak.dependencies.names["zer0m0n"](a=a).run() log.info("Good to go, now *reboot* and make a new *snapshot* of your VM!")
def zer0m0n(ipaddr, port): log.setLevel(logging.INFO) log.info("Checking if we can reach the VM..") a = Agent(ipaddr, port) try: status = a.ping().json() except requests.RequestException: log.error("Couldn't reach the VM, is it up-and-running? Aborting..") return if not isinstance(status, dict) or status.get("message") != "Cuckoo Agent!": log.error("Agent in VM isn't the new Cuckoo Agent? Aborting..") return h = Windows7x64() log.info("Patching zer0m0n-related files.") vmcloak.dependencies.names["zer0m0n"](a=a, h=h).run() log.info("Good to go, now *reboot* and make a new *snapshot* of your VM!")
def do_snapshot(image, vmname, ipaddr, resolution, ramsize, cpus, hostname, adapter, vm_visible): m, h = initvm(image, name=vmname, multi=True, ramsize=ramsize, cpus=cpus) m.start_vm(visible=vm_visible) wait_for_host(image.ipaddr, image.port) a = Agent(image.ipaddr, image.port) a.ping() # Assign a new hostname. a.hostname(hostname) a.reboot() a.kill() # Wait for the reboot to kick in. time.sleep(10) wait_for_host(image.ipaddr, image.port) a.ping() if resolution: width, height = resolution.split("x") a.resolution(width, height) a.remove("C:\\vmcloak") a.static_ip(ipaddr, image.netmask, image.gateway, h.interface) m.snapshot("vmcloak", "Snapshot created by VM Cloak.") m.stopvm() # Create a database entry for this snapshot. snapshot = Snapshot(image_id=image.id, vmname=vmname, ipaddr=ipaddr, port=image.port, hostname=hostname) return snapshot
def install(name, dependencies, vm_visible, recommended, debug): if debug: log.setLevel(logging.DEBUG) session = Session() image = session.query(Image).filter_by(name=name).first() if not image: log.error("Image not found: %s", name) exit(1) if image.mode != "normal": log.error("You can't install dependencies in this image as you have " "already made snapshots with it!") log.error("Please vmcloak-clone it and update the clone.") exit(1) m, h = initvm(image) if image.vm == "virtualbox": m.start_vm(visible=vm_visible) wait_for_host(image.ipaddr, image.port) a = Agent(image.ipaddr, image.port) a.ping() settings = {} deps = [] # Include all recommended dependencies if requested. for dependency in vmcloak.dependencies.plugins: if recommended and dependency.recommended: deps.append((dependency.name, dependency.default)) # Fetch the configuration settings off of the arguments. for dependency in dependencies: if "." in dependency and "=" in dependency: key, value = dependency.split("=", 1) settings[key.strip()] = value.strip() elif ":" in dependency: dependency, version = dependency.split(":", 1) deps.append((dependency, version)) else: deps.append((dependency, None)) for dependency, version in deps: if dependency not in vmcloak.dependencies.names: log.error("Unknown dependency %s..", dependency) break if version: log.info("Installing dependency %s %s..", dependency, version) else: log.info("Installing dependency %s..", dependency) try: # TODO Recursive install function. d = vmcloak.dependencies.names[dependency] # Check if there are any "childs" for dependencies. if d.depends: depends = d.depends if isinstance(depends, basestring): depends = [depends] for depend in depends: if ":" in depend: depend, dversion = depend.split(":", 1) else: dversion = None if dversion: log.info("Installing child dependency %s %s..", depend, dversion) else: log.info("Installing child dependency %s..", depend) # Install dependency child before dependency itself. dd = vmcloak.dependencies.names[depend] dd(h, m, a, image, dversion, settings).run() # Reboot the VM as we expect most dependencies to be related # to KB installs. a.reboot() time.sleep(10) wait_for_host(image.ipaddr, image.port) d(h, m, a, image, version, settings).run() except DependencyError: log.error("The dependency %s returned an error..", dependency) break if image.vm == "virtualbox": a.shutdown() m.wait_for_state(shutdown=True) m.remove_hd() m.compact_hd(image.path) m.delete_vm() else: a.reboot()
def do_snapshot(image, vmname, ipaddr, resolution, ramsize, cpus, hostname, adapter, vm_visible, vrde, vrde_port, interactive): m, h = initvm(image, name=vmname, multi=True, ramsize=ramsize, cpus=cpus) if vrde: m.vrde(port=vrde_port) m.start_vm(visible=vm_visible) wait_for_host(image.ipaddr, image.port) a = Agent(image.ipaddr, image.port) a.ping() # Assign a new hostname. a.hostname(hostname) a.reboot() a.kill() # Wait for the reboot to kick in. time.sleep(10) wait_for_host(image.ipaddr, image.port) a.ping() if resolution: width, height = resolution.split("x") a.resolution(width, height) if interactive: a.upload( "C:\\vmcloak\\interactive.txt", "Please make your final changes to this VM. When you're" "done, close this window and we'll create a snapshot.") log.info("You've started the snapshot creation in interactive mode!") log.info("Please make your last changes to the VM.") log.info( "When you're done close the spawned notepad process in the VM to take the final snapshot." ) a.execute("notepad.exe C:\\vmcloak\\interactive.txt", async=False) a.remove("C:\\vmcloak") a.static_ip(ipaddr, image.netmask, image.gateway, h.interface) m.snapshot("vmcloak", "Snapshot created by VMCloak.") m.stopvm() # Create a database entry for this snapshot. snapshot = Snapshot(image_id=image.id, vmname=vmname, ipaddr=ipaddr, port=image.port, hostname=hostname) return snapshot
def do_snapshot(image, vmname, ipaddr, resolution, ramsize, cpus, hostname, adapter, vm_visible, vrde, vrde_port, interactive): m, h = initvm(image, name=vmname, multi=True, ramsize=ramsize, cpus=cpus) if vrde: m.vrde(port=vrde_port) m.start_vm(visible=vm_visible) wait_for_host(image.ipaddr, image.port) a = Agent(image.ipaddr, image.port) a.ping() # Assign a new hostname. a.hostname(hostname) a.reboot() a.kill() # Wait for the reboot to kick in. time.sleep(10) wait_for_host(image.ipaddr, image.port) a.ping() if resolution: width, height = resolution.split("x") a.resolution(width, height) if interactive: a.upload("C:\\vmcloak\\interactive.txt", "Please make your final changes to this VM. When you're" "done, close this window and we'll create a snapshot.") log.info("You've started the snapshot creation in interactive mode!") log.info("Please make your last changes to the VM.") log.info("When you're done close the spawned notepad process in the VM to take the final snapshot.") a.execute("notepad.exe C:\\vmcloak\\interactive.txt", async=False) a.remove("C:\\vmcloak") a.static_ip(ipaddr, image.netmask, image.gateway, h.interface) m.snapshot("vmcloak", "Snapshot created by VMCloak.") m.stopvm() # Create a database entry for this snapshot. snapshot = Snapshot(image_id=image.id, vmname=vmname, ipaddr=ipaddr, port=image.port, hostname=hostname) return snapshot
def setup(self): self.a = Agent("localhost", 8000)
def snapshot(name, vmname, ipaddr, resolution, ramsize, cpus, hostname, adapter, vm_visible): session = Session() image = session.query(Image).filter_by(name=name).first() if not image: log.error("Image not found: %s", name) exit(1) # From now on this image is multiattach. image.mode = "multiattach" session.commit() m, h = initvm(image, name=vmname) m.start_vm(visible=vm_visible) wait_for_host(image.ipaddr, image.port) a = Agent(image.ipaddr, image.port) a.ping() # Assign a new hostname. a.hostname(hostname) a.reboot() a.kill() # Wait for the reboot to kick in. time.sleep(10) wait_for_host(image.ipaddr, image.port) a.ping() if resolution: width, height = resolution.split("x") a.resolution(width, height) a.remove("C:\\vmcloak") a.static_ip(ipaddr, image.netmask, image.gateway, h.interface) m.snapshot("vmcloak", "Snapshot created by VM Cloak.") m.stopvm() # Create a database entry for this snapshot. snapshot = Snapshot(image_id=image.id, vmname=vmname, ipaddr=ipaddr, port=image.port, hostname=hostname) session.add(snapshot) session.commit()