|
13 | 13 | # See the License for the specific language governing permissions and
|
14 | 14 | # limitations under the License.
|
15 | 15 |
|
| 16 | +""" |
| 17 | +Restore a `BUILD-READY` snapshot, copy files required for the installation (like the IDA Pro installer and |
| 18 | +the FLARE-VM configuration file) and start the FLARE-VM installation. |
| 19 | +""" |
16 | 20 |
|
17 | 21 | import os
|
18 | 22 |
|
19 |
| -import pyperclip |
20 | 23 | from vboxcommon import ensure_vm_running, get_vm_uuid, restore_snapshot, run_vboxmanage
|
21 | 24 |
|
22 | 25 | VM_NAME = "FLARE-VM.testing"
|
| 26 | +# The base snapshot is expected to be an empty Windows installation that satisfies the FLARE-VM installation requirements and has UAC disabled |
| 27 | +# To disable UAC execute in a cmd console with admin rights and restart the VM for the change to take effect: |
| 28 | +# %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0 /f |
23 | 29 | BASE_SNAPSHOT = "BUILD-READY"
|
24 | 30 | GUEST_USERNAME = "flare"
|
25 | 31 | GUEST_PASSWORD = "password"
|
| 32 | +script_directory = os.path.dirname(os.path.realpath(__file__)) |
26 | 33 | REQUIRED_FILES_DIR = os.path.expanduser("~/REQUIRED FILES")
|
27 |
| -REQUIRED_FILES_DEST = "C:\\Users\\flare\\Desktop" |
| 34 | +REQUIRED_FILES_DEST = f"C:\\Users\\{GUEST_USERNAME}\\Desktop" |
28 | 35 | INSTALLATION_COMMAND = r"""
|
29 | 36 | $desktop=[Environment]::GetFolderPath("Desktop")
|
30 | 37 | cd $desktop
|
31 | 38 | Set-ExecutionPolicy Unrestricted -Force
|
32 | 39 | $url="https://raw.githubusercontent.com/mandiant/flare-vm/main/install.ps1"
|
33 |
| -(New-Object net.webclient).DownloadFile($url,"$desktop/install.ps1") |
| 40 | +$file = "$desktop/install.ps1" |
| 41 | +(New-Object net.webclient).DownloadFile($url,$file) |
34 | 42 | Unblock-File .\install.ps1
|
35 |
| -.\install.ps1 -password password -noWait -noGui -noChecks |
| 43 | +
|
| 44 | +start powershell "$file -password password -noWait -noGui -noChecks" |
36 | 45 | """
|
37 | 46 |
|
| 47 | + |
| 48 | +def control_guest(vm_uuid, args): |
| 49 | + """Run a 'VBoxManage guestcontrol' command providing the username and password. |
| 50 | + Args: |
| 51 | + vm_uuid: VM UUID |
| 52 | + args: list of arguments starting with the guestcontrol sub-command |
| 53 | + """ |
| 54 | + run_vboxmanage(["guestcontrol", vm_uuid, f"--username={GUEST_USERNAME}", f"--password={GUEST_PASSWORD}"] + args) |
| 55 | + |
| 56 | + |
38 | 57 | vm_uuid = get_vm_uuid(VM_NAME)
|
39 | 58 | if not vm_uuid:
|
40 | 59 | print(f'❌ ERROR: "{VM_NAME}" not found')
|
|
45 | 64 | restore_snapshot(vm_uuid, BASE_SNAPSHOT)
|
46 | 65 | ensure_vm_running(vm_uuid)
|
47 | 66 |
|
48 |
| -run_vboxmanage( |
49 |
| - [ |
50 |
| - "guestcontrol", |
51 |
| - vm_uuid, |
52 |
| - f"--username={GUEST_USERNAME}", |
53 |
| - f"--password={GUEST_PASSWORD}", |
54 |
| - "copyto", |
55 |
| - "--recursive", |
56 |
| - f"--target-directory={REQUIRED_FILES_DEST}", |
57 |
| - REQUIRED_FILES_DIR, |
58 |
| - ] |
59 |
| -) |
| 67 | +control_guest(vm_uuid, ["copyto", "--recursive", f"--target-directory={REQUIRED_FILES_DEST}", REQUIRED_FILES_DIR]) |
| 68 | +print(f"VM {vm_uuid} 📁 Copied required files in: {REQUIRED_FILES_DIR}") |
60 | 69 |
|
61 |
| -print(f"VM {vm_uuid} 📁 Required files copied") |
62 | 70 |
|
| 71 | +control_guest(vm_uuid, ["run", "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", INSTALLATION_COMMAND]) |
63 | 72 |
|
64 |
| -print("\n🎀 READY TO BUILD FLARE-VM") |
65 |
| -input("Press any key to copy installation command...") |
66 |
| -pyperclip.copy(INSTALLATION_COMMAND) |
67 |
| -print("✅ COPIED! Paste the copied installation command in a PowerShell console with admin rights to install FLARE-VM") |
| 73 | +print(f"\nVM {vm_uuid} ✅ FLARE-VM is being installed... it will take some time,") |
| 74 | +print(" Go for an 🍦 and enjoy FLARE-VM when you are back!") |
0 commit comments