Skip to content

Commit bf4cd40

Browse files
committed
[vbox] Install FLARE-VM in vbox-build-flare-vm.py
Execute the installation command in the guest VM. This requires to have previously disabled UAC in the `BUILD-READY` snapshot. The documentation includes instructions of how to do this.
1 parent bb3b31c commit bf4cd40

File tree

5 files changed

+42
-26
lines changed

5 files changed

+42
-26
lines changed

virtualbox/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,5 +130,9 @@ Done! 🙃
130130

131131
## Build FLARE-VM
132132

133-
[`vbox-build-flare-vm.py`](vbox-build-flare-vm.py) prepares a VirtualBox VM for building FLARE-VM.
134-
133+
[`vbox-build-flare-vm.py`](vbox-build-flare-vm.py) restores a `BUILD-READY` snapshot, copies files required for the installation (like the IDA Pro installer and the FLARE-VM configuration file) and starts the FLARE-VM installation.
134+
The `BUILD-READY` snapshot is expected to be an empty Windows installation that satisfies the FLARE-VM installation requirements and has UAC disabled
135+
To disable UAC execute in a cmd console with admin rights and restart the VM for the change to take effect:
136+
```
137+
%windir%\System32\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v EnableLUA /t REG_DWORD /d 0 /f
138+
```

virtualbox/vbox-adapter-check.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import textwrap
2121

2222
import gi
23+
2324
from vboxcommon import ensure_hostonlyif_exists, get_vm_state, run_vboxmanage
2425

2526
gi.require_version("Notify", "0.7")

virtualbox/vbox-build-vm.py

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,47 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

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+
"""
1620

1721
import os
1822

19-
import pyperclip
2023
from vboxcommon import ensure_vm_running, get_vm_uuid, restore_snapshot, run_vboxmanage
2124

2225
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
2329
BASE_SNAPSHOT = "BUILD-READY"
2430
GUEST_USERNAME = "flare"
2531
GUEST_PASSWORD = "password"
32+
script_directory = os.path.dirname(os.path.realpath(__file__))
2633
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"
2835
INSTALLATION_COMMAND = r"""
2936
$desktop=[Environment]::GetFolderPath("Desktop")
3037
cd $desktop
3138
Set-ExecutionPolicy Unrestricted -Force
3239
$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)
3442
Unblock-File .\install.ps1
35-
.\install.ps1 -password password -noWait -noGui -noChecks
43+
44+
start powershell "$file -password password -noWait -noGui -noChecks"
3645
"""
3746

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+
3857
vm_uuid = get_vm_uuid(VM_NAME)
3958
if not vm_uuid:
4059
print(f'❌ ERROR: "{VM_NAME}" not found')
@@ -45,23 +64,11 @@
4564
restore_snapshot(vm_uuid, BASE_SNAPSHOT)
4665
ensure_vm_running(vm_uuid)
4766

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}")
6069

61-
print(f"VM {vm_uuid} 📁 Required files copied")
6270

71+
control_guest(vm_uuid, ["run", "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", INSTALLATION_COMMAND])
6372

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!")

virtualbox/vbox-export-snapshots.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from datetime import datetime
2525

2626
import jsonschema
27+
2728
from vboxcommon import (
2829
ensure_hostonlyif_exists,
2930
ensure_vm_running,

virtualbox/vboxcommon.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@
1818

1919

2020
def format_arg(arg):
21-
"""Add quotes to the string arg if it contains spaces."""
22-
if " " in arg:
23-
return f"'{arg}'"
21+
"""Add quotes to the string arg if it contains special characters like spaces."""
22+
if any(c in arg for c in (" ", "\\", "/")):
23+
if "'" not in arg:
24+
return f"'{arg}'"
25+
if '"' not in arg:
26+
return f'"{arg}"'
2427
return arg
2528

2629

0 commit comments

Comments
 (0)