📚 OpenRCE is preserved as a read-only archive. Launched at RECon Montreal in 2005. Registration and posting are disabled.








Flag: Tornado! Hurricane!

 Forums >>  Brainstorms - General  >>  VMWare Scripting

Topic created on: April 26, 2007 10:47 CDT by rman .

Hi all.  Looking for some good resources on scripting VMs to do various things, such as load, run something, then revert back to snapshot and repeat.
Does anyone have any good links to information on that?

  drew     April 26, 2007 12:52.20 CDT
vmrun will let you start and stop VMs:
http://www.vmware.com/support/ws5/doc/ws_learning_cli_vmrun.html

  Silvereyes   April 26, 2007 17:58.11 CDT
Doing all that is reasonably straight forward but does require two separate but coordinated 'processes'.

One operates on the host side and controls the virtual machine, start/stop/restore snapshot, etc. using the vmrun command (as drew mentioned).

The other operates within the guest and is responsible for fetching and/or running the 'something'. A simple way of doing this is to use wget and a suitable script.

If you are planning to use this for some form of automated malware analysis then I recommend you use Java to build your host control and monitoring programs. C++ is vunlerable to buffer overflows even if you are very careful.

  neoxfx     April 26, 2007 22:57.33 CDT
I've seen Vmware server (free edition) comes along with SDK, which has APIs to start, suspend, stop, revert a snapshot and can run process, copy files from host to guest and vice versa.
The next release is expected to have more APIs (which means more control).
HTH,
neox

  ZuTLe     April 27, 2007 02:40.23 CDT
VMware Workstation 6 comes with the VIX interface, and even adds to this (functions such as KillProcessInGuest(), RunScriptInGuest(), FileExistsInGuest()). New shapshot functions include GetChild(), GetParent(), and some of the older: ListProcessesInGuest(), CreateSnapshot(), GetCurrentSnapshot(), RevertToSnapshot(). You can download the Beta for free from VMware's own site.

The API is in C, but you can download a python wrapper from SourceForge called pyVIX, if you plan on using Python.

I have a hunger for info on this subject as well, so plz feel free to pm me if you have any luck q:]

  Silvereyes   April 27, 2007 14:56.43 CDT
These new features do sound very good for 'normal uses' but might reduce host/guest isolation. That would be a potential problem for more sensitive uses such as malware analysis.

  pedram     April 27, 2007 15:49.00 CDT
I knew about VIX and was considering writing a Python wrapper, thanks for pointing out that one already exists called PyVIX!

Here are the relevant portions of a Python servlet I wrote that wraps around the VMRun command:

    def vmcommand (self, command):
        '''
        Execute the specified command, keep trying in the event of a failure.

        @type  command: String
        @param command: VMRun command to execute
        '''

        while 1:
            self.log("executing: %s" % command, 5)

            pipe = os.popen(command)
            out  = pipe.readlines()
            pipe.close()

            if not out:
                break
            elif not out[0].lower().startswith("close failed"):
                break

            self.log("failed executing command '%s' (%s). will try again." % (command, out))
            time.sleep(1)

        return "".join(out)


    ###
    ### VMRUN COMMAND WRAPPERS
    ###


    def delete_snapshot (self, snap_name=None):
        if not snap_name:
            snap_name = self.snap_name

        self.log("deleting snapshot: %s" % snap_name, 2)
        return self.vmcommand("%s deleteSnapshot %s \"%s\"" % (self.vmrun, self.vmx, snap_name))


    def list (self):
        self.log("listing running images", 2)
        return self.vmcommand("%s list" % self.vmrun)


    def list_snapshots (self):
        self.log("listing snapshots", 2)
        return self.vmcommand("%s listSnapshots %s" % (self.vmrun, self.vmx))


    def reset (self):
        self.log("resetting image", 2)
        return self.vmcommand("%s reset %s" % (self.vmrun, self.vmx))


    def revert_to_snapshot (self, snap_name=None):
        if not snap_name:
            snap_name = self.snap_name

        self.log("reverting to snapshot: %s" % snap_name, 2)
        return self.vmcommand("%s revertToSnapshot %s \"%s\"" % (self.vmrun, self.vmx, snap_name))


    def snapshot (self, snap_name=None):
        if not snap_name:
            snap_name = self.snap_name

        self.log("taking snapshot: %s" % snap_name, 2)
        return self.vmcommand("%s snapshot %s \"%s\"" % (self.vmrun, self.vmx, snap_name))


    def start (self):
        self.log("starting image", 2)
        return self.vmcommand("%s start %s" % (self.vmrun, self.vmx))


    def stop (self):
        self.log("stopping image", 2)
        return self.vmcommand("%s stop %s" % (self.vmrun, self.vmx))


    def suspend (self):
        self.log("suspending image", 2)
        return self.vmcommand("%s suspend %s" % (self.vmrun, self.vmx))


    ###
    ### EXTENDED COMMANDS
    ###


    def restart_target (self):
        self.log("restarting virtual machine...")
        # revert to the specified snapshot and start the image.
        self.revert_to_snapshot()
        self.start()

        # wait for the snapshot to come alive.
        self.wait()


    def is_target_running (self):
        return self.vmx.lower() in self.list().lower()


    def wait (self):
        self.log("waiting for vmx to come up: %s" % self.vmx)
        while 1:
            if self.is_target_running():
                break

This servlet is part of a fuzzing framework I have been working on called Sulley. It'll be released at some point in the near future possibly at BlackHat and along side a book I co-authored called Fuzzing: Brute Force Vulnerability Discovery.

  asotirov     April 29, 2007 13:38.56 CDT
I have a Ruby wrapper around the vmrun command in VMWare Workstation 5, very similar to the Python code above. To control the OS inside the VM I used the Meterpreter from Metasploit. I wrote a simple Windows service that loads the Meterpreter DLL from disk and listens on a port. The Ruby code on the host connects to the Meterpreter and uses its functions to list processes, trasnfer files, start new applications, etc.

  MohammadHosein     May 1, 2007 06:53.37 CDT
why dont you share this code with us ? ;-)

  asotirov     May 29, 2007 22:37.37 CDT
Here's the code for my VMrun wrapper in Ruby and the Meterpreter service. They are released under a BSD license:

http://www.determina.com/security.research/utilities/

Enjoy!

Note: Registration is required to post to the forums.

There are 31,328 total registered users.


Recently Created Topics
[help] Unpacking VMP...
Mar/12
Reverse Engineering ...
Jul/06
let 'IDAPython' impo...
Sep/24
set 'IDAPython' as t...
Sep/24
GuessType return une...
Sep/20
About retrieving the...
Sep/07
How to find specific...
Aug/15
How to get data depe...
Jul/07
Identify RVA data in...
May/06
Question about memor...
Dec/12


Recent Forum Posts
Finding the procedur...
rolEYder
Question about debbu...
rolEYder
Identify RVA data in...
sohlow
let 'IDAPython' impo...
sohlow
How to find specific...
hackgreti
Problem with ollydbg
sh3dow
How can I write olly...
sh3dow
New LoadMAP plugin v...
mefisto...
Intel pin in loaded ...
djnemo
OOP_RE tool available?
Bl4ckm4n


Recent Blog Entries
halsten
Mar/14
Breaking IonCUBE VM

oleavr
Oct/24
Anatomy of a code tracer

hasherezade
Sep/24
IAT Patcher - new tool for ...

oleavr
Aug/27
CryptoShark: code tracer ba...

oleavr
Jun/25
Build a debugger in 5 minutes

More ...


Recent Blog Comments
nieo on:
Mar/22
IAT Patcher - new tool for ...

djnemo on:
Nov/17
Kernel debugger vs user mod...

acel on:
Nov/14
Kernel debugger vs user mod...

pedram on:
Dec/21
frida.github.io: scriptable...

capadleman on:
Jun/19
Using NtCreateThreadEx for ...

More ...


Imagery
SoySauce Blueprint
Jun 6, 2008

[+] expand

View Gallery (11) / Submit