예제 #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="virtualMachine"></param>
 protected void LoginGuest(VMWareVirtualMachine virtualMachine)
 {
     PowerOnVirtualMachine(virtualMachine);
     Log.LogMessage(string.Format("Logging in {0}", Filename));
     virtualMachine.LoginInGuest(GuestUsername, GuestPassword,
                                 _interactive ? Constants.VIX_LOGIN_IN_GUEST_REQUIRE_INTERACTIVE_ENVIRONMENT : 0,
                                 _loginTimeout);
 }
예제 #2
0
        /*
         * Rolls back the given virtual machine to the deployPoint snapshot,
         * powers the vm on and logs in to an interactive session as the standand user.
         * Then calls policySync
         */
        private static void revertAndLogin(VMWareVirtualMachine ivm)
        {
            Console.WriteLine("[i] Rolling back.");
            count = 0;
            deployPoint.RevertToSnapshot();

            ivm.PowerOn();
            ivm.WaitForToolsInGuest();
Login:
            try { ivm.LoginInGuest(domainName + @"\" + usrnm, psswd, 8, 300); }
            catch (Exception) { goto Login; }
            Console.WriteLine("[\u221A] Logged in.");
            policySync(ivm);
        }
예제 #3
0
 /*
  * Procedure for logging in interactively
  */
 private static void interactiveLogin(VMWareVirtualMachine ivm)
 {
     try
     {
         Console.Write("[i] Log in as " + domainName + @"\" + usrnm + " on the virtual machine, then press enter in the console.");
         Console.ReadLine();
         ivm.LoginInGuest(domainName + @"\" + usrnm, psswd, 8, 300);
         Console.WriteLine("[\u221A] Logged in.");
     }
     catch (Exception)
     {
         Console.WriteLine("[!] You did not log in correctly. Wait for all scripts to run, then try again.");
         interactiveLogin(ivm);
     }
 }
 public void GetEnvironmentVariablesSample()
 {
     #region Example: Enumerating Environment Variables on the GuestOS without VixCOM
     // connect to a local virtual machine and power it on
     VMWareVirtualHost virtualHost = new VMWareVirtualHost();
     virtualHost.ConnectToVMWareWorkstation();
     VMWareVirtualMachine virtualMachine = virtualHost.Open(@"C:\Users\dblock\Virtual Machines\Windows XP Pro SP3 25GB\WinXP Pro SP3 25GB.vmx");
     virtualMachine.PowerOn();
     virtualMachine.WaitForToolsInGuest();
     virtualMachine.LoginInGuest("Administrator", "admin123");
     Shell guestShell = new Shell(virtualMachine);
     Dictionary <string, string> guestEnvironmentVariables = guestShell.GetEnvironmentVariables();
     Console.WriteLine(guestEnvironmentVariables["ProgramFiles"]);
     #endregion
 }
예제 #5
0
        public void LoginInGuest(string username, string password, GuestLoginType logintype)
        {
            int loginOptions = 0;

            switch (logintype)
            {
            case GuestLoginType.interactive:
                ConsoleOutput.WriteLine(" Interactively logging on to 'Remote:{0}' as '{1}'", _name, username);
                loginOptions = Constants.VIX_LOGIN_IN_GUEST_REQUIRE_INTERACTIVE_ENVIRONMENT;
                break;

            default:
                ConsoleOutput.WriteLine(" Logging on to 'Remote:{0}' as '{1}'", _name, username);
                break;
            }

            if (!_simulationOnly)
            {
                _vm.LoginInGuest(username, password, loginOptions, VMWareInterop.Timeouts.LoginTimeout);
            }
        }
예제 #6
0
 public void GettingStartedWorkstation()
 {
     #region Example: Getting Started (Workstation)
     // declare a virtual host
     using (VMWareVirtualHost virtualHost = new VMWareVirtualHost())
     {
         // connect to a local VMWare Workstation virtual host
         virtualHost.ConnectToVMWareWorkstation();
         // open an existing virtual machine
         using (VMWareVirtualMachine virtualMachine = virtualHost.Open(@"C:\Virtual Machines\xp\xp.vmx"))
         {
             // power on this virtual machine
             virtualMachine.PowerOn();
             // wait for VMWare Tools
             virtualMachine.WaitForToolsInGuest();
             // login to the virtual machine
             virtualMachine.LoginInGuest("Administrator", "password");
             // run notepad
             virtualMachine.RunProgramInGuest("notepad.exe", string.Empty);
             // create a new snapshot
             string name = "New Snapshot";
             // take a snapshot at the current state
             VMWareSnapshot createdSnapshot = virtualMachine.Snapshots.CreateSnapshot(name, "test snapshot");
             createdSnapshot.Dispose();
             // power off
             virtualMachine.PowerOff();
             // find the newly created snapshot
             using (VMWareSnapshot foundSnapshot = virtualMachine.Snapshots.GetNamedSnapshot(name))
             {
                 // revert to the new snapshot
                 foundSnapshot.RevertToSnapshot();
                 // delete snapshot
                 foundSnapshot.RemoveSnapshot();
             }
         }
     }
     #endregion
 }
예제 #7
0
 public void GettingStartedVI()
 {
     #region Example: Getting Started (VI)
     // declare a virtual host
     using (VMWareVirtualHost virtualHost = new VMWareVirtualHost())
     {
         // connect to a remove (VMWare ESX) virtual machine
         virtualHost.ConnectToVMWareVIServer("esx.mycompany.com", "vmuser", "password");
         // open an existing virtual machine
         using (VMWareVirtualMachine virtualMachine = virtualHost.Open("[storage] testvm/testvm.vmx"))
         {
             // power on this virtual machine
             virtualMachine.PowerOn();
             // wait for VMWare Tools
             virtualMachine.WaitForToolsInGuest();
             // login to the virtual machine
             virtualMachine.LoginInGuest("Administrator", "password");
             // run notepad
             virtualMachine.RunProgramInGuest("notepad.exe", string.Empty);
             // create a new snapshot
             string name = "New Snapshot";
             // take a snapshot at the current state
             virtualMachine.Snapshots.CreateSnapshot(name, "test snapshot");
             // power off
             virtualMachine.PowerOff();
             // find the newly created snapshot
             using (VMWareSnapshot snapshot = virtualMachine.Snapshots.GetNamedSnapshot(name))
             {
                 // revert to the new snapshot
                 snapshot.RevertToSnapshot();
                 // delete snapshot
                 snapshot.RemoveSnapshot();
             }
         }
     }
     #endregion
 }
예제 #8
0
 /*
  * Procedure for logging in interactively
  */
 private static void interactiveLogin(VMWareVirtualMachine ivm)
 {
     try
     {
         Console.Write("[i] Log in as " + domainName + @"\" + usrnm + " on the virtual machine, then press enter in the console.");
         Console.ReadLine();
         ivm.LoginInGuest(domainName + @"\" + usrnm, psswd, 8, 300);
         Console.WriteLine("[\u221A] Logged in.");
     }
     catch (Exception)
     {
         Console.WriteLine("[!] You did not log in correctly. Wait for all scripts to run, then try again.");
         interactiveLogin(ivm);
     }
 }
예제 #9
0
        /*
         * Rolls back the given virtual machine to the deployPoint snapshot,
         * powers the vm on and logs in to an interactive session as the standand user.
         * Then calls policySync
         */
        private static void revertAndLogin(VMWareVirtualMachine ivm)
        {
            Console.WriteLine("[i] Rolling back.");
            count = 0;
            deployPoint.RevertToSnapshot();

            ivm.PowerOn();
            ivm.WaitForToolsInGuest();
        Login:
            try { ivm.LoginInGuest(domainName + @"\" + usrnm, psswd, 8, 300); }
            catch (Exception) { goto Login; }
            Console.WriteLine("[\u221A] Logged in.");
            policySync(ivm);
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="virtualMachine"></param>
 protected void LoginGuest(VMWareVirtualMachine virtualMachine)
 {
     PowerOnVirtualMachine(virtualMachine);
     Log.LogMessage(string.Format("Logging in {0}", Filename));
     virtualMachine.LoginInGuest(GuestUsername, GuestPassword,
         _interactive ? Constants.VIX_LOGIN_IN_GUEST_REQUIRE_INTERACTIVE_ENVIRONMENT : 0,
         _loginTimeout);
 }