-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
first step towards a revamped vmcloak
- Loading branch information
Showing
12 changed files
with
462 additions
and
382 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
#!/usr/bin/env python | ||
# Copyright (C) 2014-2015 Jurriaan Bremer. | ||
# This file is part of VMCloak - http://www.vmcloak.org/. | ||
# See the file 'docs/LICENSE.txt' for copying permission. | ||
|
||
import argparse | ||
import logging | ||
import os.path | ||
import shutil | ||
import tempfile | ||
|
||
from vmcloak.winxp import WindowsXP | ||
from vmcloak.win7 import Windows7 | ||
from vmcloak.repository import image_path, Database, Image | ||
from vmcloak.vm import VirtualBox | ||
|
||
log = logging.getLogger("vmcloak") | ||
db = Database() | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument("name", type=str, help="Name of the new instance.") | ||
parser.add_argument("--winxp", action="store_true", help="This is a Windows XP instance.") | ||
parser.add_argument("--win7", action="store_true", help="This is a Windows 7 instance.") | ||
parser.add_argument("--x64", action="store_true", help="This is a 64-bit OS.") | ||
parser.add_argument("--win7x64", action="store_true", help="This is a Windows 7 64-bit instance.") | ||
parser.add_argument("--vm", type=str, default="virtualbox", help="Virtual Machinery.") | ||
parser.add_argument("--iso-mount", type=str, help="Mounted ISO Windows installer image.") | ||
parser.add_argument("--serial-key", type=str, help="Windows Serial Key.") | ||
parser.add_argument("--ip", type=str, default="192.168.56.2", help="Guest IP address.") | ||
parser.add_argument("--port", type=int, default=8000, help="Port to run the Agent on.") | ||
parser.add_argument("--netmask", type=str, default="255.255.255.0", help="Guest IP address.") | ||
parser.add_argument("--gateway", type=str, default="192.168.56.1", help="Guest IP address.") | ||
parser.add_argument("--tempdir", type=str, default=tempfile.gettempdir(), help="Temporary directory to build the ISO file.") | ||
parser.add_argument("--vm-visible", action="store_true", default=None, help="Start the Virtual Machine in GUI mode.") | ||
parser.add_argument("-d", "--debug", action="store_true", default=None, help="Install Virtual Machine in debug mode.") | ||
parser.add_argument("-v", "--verbose", action="store_true", default=None, help="Verbose logging.") | ||
args = parser.parse_args() | ||
|
||
if args.verbose: | ||
log.setLevel(logging.DEBUG) | ||
|
||
if args.vm != "virtualbox": | ||
log.error("Only the VirtualBox Machinery is supported at this point.") | ||
exit(1) | ||
|
||
if args.winxp: | ||
h = WindowsXP() | ||
osversion = "winxp" | ||
elif args.win7 or args.win7x64: | ||
h = Windows7() | ||
if args.x64 or args.win7x64: | ||
osversion = "win7x64" | ||
args.x64 = True | ||
else: | ||
osversion = "win7" | ||
else: | ||
log.error("Please provide either --winxp or --win7.") | ||
exit(1) | ||
|
||
if not os.path.isdir(args.iso_mount or h.mount): | ||
log.error("Please specify --iso-mount to a directory containing the " | ||
"mounted Windows Installer ISO image.") | ||
log.info("Refer to the documentation on mounting an .iso image.") | ||
exit(1) | ||
|
||
if not h.set_serial_key(args.serial_key): | ||
exit(1) | ||
|
||
h.configure(args) | ||
|
||
settings = dict( | ||
GUEST_IP=args.ip, | ||
AGENT_PORT=args.port, | ||
GUEST_MASK=args.netmask, | ||
GUEST_GATEWAY=args.gateway, | ||
DEBUG="yes" if args.debug else "no", | ||
) | ||
|
||
bootstrap = tempfile.mkdtemp(dir=args.tempdir) | ||
|
||
vmcloak_dir = os.path.join(bootstrap, "vmcloak") | ||
os.mkdir(vmcloak_dir) | ||
|
||
# Write the configuration values for bootstrap.bat. | ||
with open(os.path.join(vmcloak_dir, "settings.bat"), "wb") as f: | ||
for key, value in settings.items(): | ||
print>>f, "set %s=%s" % (key, value) | ||
|
||
hdd_path = os.path.join(image_path, "%s.vdi" % args.name) | ||
m = VirtualBox(name=args.name, tempdir=args.tempdir, hdd_path=hdd_path) | ||
|
||
if not h.buildiso(args.iso_mount or h.mount, m.iso_path, bootstrap, | ||
args.tempdir): | ||
shutil.rmtree(bootstrap) | ||
exit(1) | ||
|
||
shutil.rmtree(bootstrap) | ||
|
||
m.create_vm() | ||
m.os_type(os=h.name, sp=h.service_pack) | ||
m.create_hd() | ||
m.attach_iso(m.iso_path) | ||
m.hostonly(nictype=h.nictype) | ||
|
||
log.info("Starting the Virtual Machine %r to install Windows.", args.name) | ||
m.start_vm(visible=args.vm_visible) | ||
|
||
m.wait_for_state(shutdown=True) | ||
|
||
m.detach_iso() | ||
os.unlink(m.iso_path) | ||
|
||
m.remove_hd() | ||
m.compact_hd() | ||
m.remove_vm() | ||
|
||
log.info("Added image %r to the repository.", args.name) | ||
db.add(Image(name=args.name, path=hdd_path, osversion=osversion)) | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Copyright (C) 2014-2015 Jurriaan Bremer. | ||
# This file is part of VMCloak - http://www.vmcloak.org/. | ||
# See the file 'docs/LICENSE.txt' for copying permission. | ||
|
||
import requests | ||
|
||
class Agent(object): | ||
def __init__(self, ipaddr, port): | ||
self.ipaddr = ipaddr | ||
self.port = port | ||
|
||
def get(self, method, *args, **kwargs): | ||
url = "http://%s:%s%s" % (self.ipaddr, self.port, method) | ||
return requests.get(url, *args, **kwargs) | ||
|
||
def post(self, method, **kwargs): | ||
url = "http://%s:%s%s" % (self.ipaddr, self.port, method) | ||
return requests.post(url, data=kwargs) | ||
|
||
def postfile(self, method, files, **kwargs): | ||
url = "http://%s:%s%s" % (self.ipaddr, self.port, method) | ||
return requests.post(url, files=files, data=kwargs) |
Oops, something went wrong.