hatching / vmcloak

Automated Virtual Machine Generation and Cloaking for Cuckoo Sandbox.
481 stars 118 forks source link

"Backing file specified without backing format Detected format" Error #201

Open msil2 opened 1 year ago

msil2 commented 1 year ago

When creating snapshots of my win10base image, I encountered an error that read "Backing file specified without backing format Detected format."

Output on Error:

(venv) user@user-virtual-machine:/opt/cuckoo3$ vmcloak snapshot --count 1 win10base win10vm_
2022-10-30 18:36:03,591 vmcloak INFO: Creating snapshot: 'win10vm_' with IP '192.168.30.15'
2022-10-30 18:36:03,591 vmcloak INFO: Creating snapshot win10vm_ (192.168.30.15)
2022-10-30 18:36:03,591 vmcloak.platforms.qemu INFO: Create VM instance for win10vm_
2022-10-30 18:36:03,591 vmcloak.platforms.qemu INFO: Creating snapshot /home/user/.vmcloak/vms/qemu/win10vm_/disk.qcow2 with master /home/user/.vmcloak/image/win10base.qcow2
qemu-img: /home/user/.vmcloak/vms/qemu/win10vm_/disk.qcow2: Backing file specified without backing format
Detected format of qcow2.Traceback (most recent call last):
  File "/opt/cuckoo3/venv/bin/vmcloak", line 8, in <module>
    sys.exit(main())
  File "/opt/cuckoo3/venv/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/opt/cuckoo3/venv/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/opt/cuckoo3/venv/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/cuckoo3/venv/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/cuckoo3/venv/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/opt/cuckoo3/venv/lib/python3.10/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/opt/cuckoo3/venv/lib/python3.10/site-packages/vmcloak/main.py", line 797, in snapshot
    new_snapshot = _snapshot(image, vmname, attr, interactive)
  File "/opt/cuckoo3/venv/lib/python3.10/site-packages/vmcloak/main.py", line 546, in _snapshot
    p.create_snapshot_vm(image, vmname, attr)
  File "/opt/cuckoo3/venv/lib/python3.10/site-packages/vmcloak/platforms/qemu.py", line 198, in create_snapshot_vm
    _create_vm(name, attr, is_snapshot=True)
  File "/opt/cuckoo3/venv/lib/python3.10/site-packages/vmcloak/platforms/qemu.py", line 126, in _create_vm
    _create_snapshot_disk(attr["imgpath"], attr["path"])
  File "/opt/cuckoo3/venv/lib/python3.10/site-packages/vmcloak/platforms/qemu.py", line 39, in _create_snapshot_disk
    subprocess.check_call(["qemu-img", "create", "-f", "qcow2", "-o",
  File "/usr/lib/python3.10/subprocess.py", line 369, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['qemu-img', 'create', '-f', 'qcow2', '-o', 'lazy_refcounts=on,cluster_size=2M', '-b', '/home/user/.vmcloak/image/win10base.qcow2', '/home/user/.vmcloak/vms/qemu/win10vm_/disk.qcow2']' returned non-zero exit status 1.

My Fix (edit in vmcloak/platforms/qemu.py):

Add "-f", "qcow2", after the backing file parameter in the the _create_snapshot_disk function. In vmcloak/platforms/qemu.py, making the following edit will look like:

def _create_snapshot_disk(image_path, path):
    log.info("Creating snapshot %s with master %s", path, image_path)
    subprocess.check_call(["qemu-img", "create", "-F", "qcow2", "-o",
                           "lazy_refcounts=on,cluster_size=2M", "-b",
                           image_path, "-f", "qcow2", path])

And then the snapshot function just works :)