Skip to content

Commit 00245ef

Browse files
committed
Improve functionality to select and and new packages
Add links for the choco community and VM-Packages wiki Improve font to make it bigger. Validate that the package didn't exist in the listBox before adding a new one. Disable the button Add Package if the text in the textbox changes when it is enabled. Allow to add additional packages to the listBox that are displayed as textboxes.
1 parent 5405ff9 commit 00245ef

File tree

1 file changed

+109
-84
lines changed

1 file changed

+109
-84
lines changed

install.ps1

Lines changed: 109 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,6 @@ Start-Sleep 1
469469
$configXml = [xml](Get-Content $configPath)
470470

471471
if (-not $noGui.IsPresent) {
472-
473472
$errorColor = [System.Drawing.ColorTranslator]::FromHtml("#c80505")
474473
$successColor = [System.Drawing.ColorTranslator]::FromHtml("#417505")
475474

@@ -542,10 +541,31 @@ if (-not $noGui.IsPresent) {
542541
return $packagesByCategory
543542
}
544543

544+
# Function that returns an array of all the packages that are displayed sorted by category from $packagesByCategory
545+
function Get-AllPackages{
546+
$listedPackages = $packagesByCategory.Values | ForEach-Object { $_ } | Select-Object -ExpandProperty PackageName
547+
return $listedPackages
548+
}
549+
550+
# Function that returns additional packages from the config that are not displayed in the textboxes
551+
# which includes both Choco packages and packages from excluded categories
552+
function Get-AdditionalPackages{
553+
$additionalPackages=@()
554+
555+
# Packages from the config that are not displayed
556+
$additionalPackages = $packagesToInstall | where-Object { $listedPackages -notcontains $_}
557+
return $additionalPackages
558+
}
559+
545560
# Gather lists of packages
546561
$envs = [ordered]@{}
547562
$configXml.config.envs.env.ForEach({ $envs[$_.name] = $_.value })
563+
$excludedCategories=@('Command and Control','Credential Access','Exploitation','Forensic','Lateral Movement', 'Payload Development','Privilege Scalation','Reconnaissance','Wordlists','Web Application')
564+
# Read packages to install from the config
565+
$packagesToInstall = $configXml.config.packages.package.name
548566
$packagesByCategory = Get-Packages-Categories
567+
$listedPackages = Get-AllPackages
568+
$additionalPackages = Get-AdditionalPackages
549569

550570
$formEnv = New-Object system.Windows.Forms.Form
551571
$formEnv.ClientSize = New-Object System.Drawing.Point(750,350)
@@ -804,14 +824,15 @@ if (-not $noGui.IsPresent) {
804824
}
805825

806826
# Function that adds a new package to the listBox of additional packages
827+
# If the package already exists it returns $false
807828
function Add-NewPackage {
808829
param (
809830
[Parameter(Mandatory=$true)]
810831
[string]$packageName
811832
)
812-
813-
if ($packageName -notin $listedPackages)
814-
{
833+
#$packageName = $packageName.Trim()
834+
$packageName = $packageName -replace '^\s+|\s+$', ''
835+
if ($packageName -notin $additionalPackagesBox.Items){
815836
$additionalPackagesBox.Items.Add($packageName) | Out-Null
816837
return $true
817838
}
@@ -871,37 +892,38 @@ if (-not $noGui.IsPresent) {
871892

872893
Add-Type -AssemblyName System.Windows.Forms
873894
[System.Windows.Forms.Application]::EnableVisualStyles()
874-
$excludedCategories=@('Command and Control','Credential Access','Exploitation','Forensic','Lateral Movement', 'Payload Development','Privilege Scalation','Reconnaissance','Wordlists')
875-
# Read packages to install from the config
876-
$packagesToInstall = $configXml.config.packages.package.name
877-
$packagesByCategory = Get-Packages-Categories
878-
$listedPackages = Get-AllPackages
879-
$additionalPackages = Get-AdditionalPackages
880895

881896
$formCategories = New-Object system.Windows.Forms.Form
882897
$formCategories.ClientSize = New-Object System.Drawing.Point(1015,850)
883-
$formCategories.text = "FLAREVM Package selection"
898+
$formCategories.text = "FLARE-VM Package selection"
884899
$formCategories.StartPosition = 'CenterScreen'
885900
$formCategories.TopMost = $true
886901

887902
if ([string]::IsNullOrEmpty($customConfig)) {
888-
$textLabel = "Select packages to install. The default configuration (recommended for reverse engineering) is pre-selected.`nClick on the reset button to restore the default configuration."
903+
$textLabel = "The default configuration (recommended) is pre-selected. Click on the reset button to restore the default configuration."
889904
} else {
890-
$textLabel = "Select packages to install. The provided custom configuration is pre-selected.`nClick on the reset button to restore the custom configuration."
905+
$textLabel = "The provided custom configuration is pre-selected. Click on the reset button to restore the custom configuration."
891906
}
892907

893908
$labelCategories = New-Object system.Windows.Forms.Label
894-
$labelCategories.text = $textLabel
909+
$labelCategories.text = "Select packages to install"
895910
$labelCategories.AutoSize = $true
896911
$labelCategories.width = 25
897912
$labelCategories.height = 10
898913
$labelCategories.location = New-Object System.Drawing.Point(30,20)
899-
$labelCategories.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
914+
$labelCategories.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10,[System.Drawing.FontStyle]([System.Drawing.FontStyle]::Bold))
915+
916+
917+
$labelCategories2 = New-Object system.Windows.Forms.Label
918+
$labelCategories2.text = $textLabel
919+
$labelCategories2.AutoSize = $true
920+
$labelCategories2.location = New-Object System.Drawing.Point(30,40)
921+
$labelCategories2.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
900922

901923
$panelCategories = New-Object system.Windows.Forms.Panel
902-
$panelCategories.height = 580
924+
$panelCategories.height = 550
903925
$panelCategories.width = 970
904-
$panelCategories.location = New-Object System.Drawing.Point(30,30)
926+
$panelCategories.location = New-Object System.Drawing.Point(30,60)
905927
$panelCategories.AutoScroll = $true
906928

907929
$resetButton = New-Object system.Windows.Forms.Button
@@ -953,7 +975,7 @@ if (-not $noGui.IsPresent) {
953975
# Create checkboxes for each package
954976
$checkboxesPackages = New-Object System.Collections.Generic.List[System.Object]
955977
# Initial vertical position for checkboxes
956-
$verticalPosition = 30
978+
$verticalPosition = 25
957979
$numCheckBoxPackages = 1
958980
$packages = @()
959981
foreach ($category in $packagesByCategory.Keys |Sort-Object) {
@@ -999,20 +1021,20 @@ if (-not $noGui.IsPresent) {
9991021
Set-InitialPackages
10001022

10011023
$additionalPackagesLabel = New-Object system.Windows.Forms.Label
1002-
$additionalPackagesLabel.text = "Additional packages to install:"
1024+
$additionalPackagesLabel.text = "Additional packages to install"
10031025
$additionalPackagesLabel.AutoSize = $true
10041026
$additionalPackagesLabel.width = 25
10051027
$additionalPackagesLabel.height = 10
1006-
$additionalPackagesLabel.location = New-Object System.Drawing.Point(50,615)
1007-
$additionalPackagesLabel.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
1028+
$additionalPackagesLabel.location = New-Object System.Drawing.Point(30,615)
1029+
$additionalPackagesLabel.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10,[System.Drawing.FontStyle]([System.Drawing.FontStyle]::Bold))
10081030

10091031
$additionalPackagesBox = New-Object system.Windows.Forms.ListBox
10101032
$additionalPackagesBox.text = "listBox"
10111033
$additionalPackagesBox.SelectionMode = 'MultiSimple'
10121034
$additionalPackagesBox.Sorted = $true
10131035
$additionalPackagesBox.width = 130
1014-
$additionalPackagesBox.height = 155
1015-
$additionalPackagesBox.location = New-Object System.Drawing.Point(50,635)
1036+
$additionalPackagesBox.height = 140
1037+
$additionalPackagesBox.location = New-Object System.Drawing.Point(50,640)
10161038

10171039
$deletePackageButton = New-Object system.Windows.Forms.Button
10181040
$deletePackageButton.text = "-"
@@ -1023,40 +1045,45 @@ if (-not $noGui.IsPresent) {
10231045
$deletePackageButton.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',12,[System.Drawing.FontStyle]::Bold)
10241046
$deletePackageButton.Add_Click({Remove-SelectedPackages})
10251047

1026-
1027-
$groupAbout = New-Object system.Windows.Forms.Groupbox
1028-
$groupAbout.height = 85
1029-
$groupAbout.width = 360
1030-
$groupAbout.location = New-Object System.Drawing.Point(280,620)
1031-
$groupAbout.Text = "About"
1032-
1033-
10341048
$packageLabel = New-Object system.Windows.Forms.Label
1035-
$packageLabel.text = "FLARE-VM uses Chocolatey packages. You can add Community packages from"
1036-
$packageLabel.width = 230
1049+
$packageLabel.text = "FLARE-VM uses Chocolatey packages. You can add additional packages from:"
1050+
$packageLabel.width = 260
10371051
$packageLabel.height = 35
1038-
$packageLabel.location = New-Object System.Drawing.Point(300,620)
1039-
$packageLabel.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',9)
1040-
1041-
$packageUrlLabel = New-Object system.Windows.Forms.Label
1042-
$packageUrlLabel.text = "https://community.chocolatey.org/packages"
1043-
$packageUrlLabel.width = 250
1044-
$packageUrlLabel.height = 21
1045-
$packageUrlLabel.location = New-Object System.Drawing.Point(300,652)
1046-
$packageUrlLabel.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',9,[System.Drawing.FontStyle]([System.Drawing.FontStyle]::Underline))
1047-
1048-
$packageVMLabel = New-Object system.Windows.Forms.Label
1049-
$packageVMLabel.text = "and VM-Packages"
1050-
$packageVMLabel.width = 120
1051-
$packageVMLabel.height = 22
1052-
$packageVMLabel.location = New-Object System.Drawing.Point(548,652)
1053-
$packageVMLabel.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',9)
1054-
1055-
$packageUrl2Label = New-Object system.Windows.Forms.Label
1056-
$packageUrl2Label.text = "https://github.com/mandiant/VM-Packages/wiki/Packages"
1057-
$packageUrl2Label.AutoSize = $true
1058-
$packageUrl2Label.location = New-Object System.Drawing.Point(300,670)
1059-
$packageUrl2Label.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',9,[System.Drawing.FontStyle]([System.Drawing.FontStyle]::Underline))
1052+
$packageLabel.AutoSize = $true
1053+
$packageLabel.location = New-Object System.Drawing.Point(300,640)
1054+
$packageLabel.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
1055+
1056+
$labelChoco = New-Object System.Windows.Forms.Label
1057+
$labelChoco.Location = New-Object System.Drawing.Point(300,660)
1058+
$labelChoco.Size = New-Object System.Drawing.Size(280,20)
1059+
$labelChoco.AutoSize = $true
1060+
$labelChoco.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
1061+
$labelChoco.Text = "Community Packages"
1062+
1063+
$linkLabelChoco = New-Object System.Windows.Forms.linkLabel
1064+
$linkLabelChoco.Location = New-Object System.Drawing.Point(440,660)
1065+
$linkLabelChoco.AutoSize = $true
1066+
$linkLabelChoco.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
1067+
$linkLabelChoco.LinkColor = "BLUE"
1068+
$linkLabelChoco.ActiveLinkColor = "RED"
1069+
$linkLabelChoco.Text = "https://community.chocolatey.org/packages"
1070+
$linkLabelChoco.add_Click({[system.Diagnostics.Process]::start("https://community.chocolatey.org/packages")})
1071+
1072+
$labelFlarevm = New-Object System.Windows.Forms.Label
1073+
$labelFlarevm.Location = New-Object System.Drawing.Point(300,680)
1074+
$labelFlarevm.Size = New-Object System.Drawing.Size(280,20)
1075+
$labelFlarevm.AutoSize = $true
1076+
$labelFlarevm.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
1077+
$labelFlarevm.Text = "FLARE-VM Packages"
1078+
1079+
$linkLabelFlarevm = New-Object System.Windows.Forms.linkLabel
1080+
$linkLabelFlarevm.Location = New-Object System.Drawing.Point(440,680)
1081+
$linkLabelFlarevm.AutoSize = $true
1082+
$linkLabelFlarevm.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
1083+
$linkLabelFlarevm.LinkColor = "BLUE"
1084+
$linkLabelFlarevm.ActiveLinkColor = "RED"
1085+
$linkLabelFlarevm.Text = "https://github.com/mandiant/VM-Packages/wiki/Packages"
1086+
$linkLabelFlarevm.add_Click({[system.Diagnostics.Process]::start("https://github.com/mandiant/VM-Packages/wiki/Packages")})
10601087

10611088
Set-AdditionalPackages
10621089

@@ -1065,56 +1092,59 @@ if (-not $noGui.IsPresent) {
10651092
$chocoPackageLabel.AutoSize = $true
10661093
$chocoPackageLabel.width = 25
10671094
$chocoPackageLabel.height = 10
1068-
$chocoPackageLabel.location = New-Object System.Drawing.Point(300,705)
1095+
$chocoPackageLabel.location = New-Object System.Drawing.Point(300,715)
10691096
$chocoPackageLabel.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
10701097

10711098
$packageTextBox = New-Object system.Windows.Forms.TextBox
10721099
$packageTextBox.multiline = $false
10731100
$packageTextBox.width = 210
10741101
$packageTextBox.height = 20
1075-
$packageTextBox.location = New-Object System.Drawing.Point(300,725)
1102+
$packageTextBox.location = New-Object System.Drawing.Point(300,735)
10761103
$packageTextBox.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
1104+
$packageTextBox.Add_TextChanged({
1105+
if ($addPackageButton.Enabled -eq $true){
1106+
$addPackageButton.Enabled = $false
1107+
}
1108+
1109+
})
10771110

10781111
$chocoPackageErrorLabel = New-Object system.Windows.Forms.Label
10791112
$chocoPackageErrorLabel.text = ""
10801113
$chocoPackageErrorLabel.AutoSize = $true
10811114
$chocoPackageErrorLabel.visible = $false
10821115
$chocoPackageErrorLabel.width = 25
10831116
$chocoPackageErrorLabel.height = 10
1084-
$chocoPackageErrorLabel.location = New-Object System.Drawing.Point(300,755)
1117+
$chocoPackageErrorLabel.location = New-Object System.Drawing.Point(300,765)
10851118
$chocoPackageErrorLabel.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10,[System.Drawing.FontStyle]([System.Drawing.FontStyle]::Bold))
10861119

10871120
$findPackageButton = New-Object system.Windows.Forms.Button
10881121
$findPackageButton.text = "Find Package"
10891122
$findPackageButton.width = 118
10901123
$findPackageButton.height = 30
10911124
$findPackageButton.enabled = $true
1092-
$findPackageButton.location = New-Object System.Drawing.Point(520,720)
1125+
$findPackageButton.location = New-Object System.Drawing.Point(520,730)
10931126
$findPackageButton.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
10941127
$findPackageButton.Add_Click({
1095-
$chocoPackageErrorLabel.Visible = $false
1096-
$vmPackage = Get-VMPackage -PackageName $packageTextBox.Text
1128+
$chocoPackageErrorLabel.Visible = $true
1129+
$chocoPackageErrorLabel.text = "Finding package ..."
1130+
$vmPackage = Get-VMPackage -PackageName $packageTextBox.Text.Trim()
10971131
if ($vmPackage){
10981132
$packageName = $vmPackage | Select-Object -ExpandProperty Name
10991133
$chocoPackageErrorLabel.text = "Found VM package"
11001134
$chocoPackageErrorLabel.ForeColor = $successColor
1101-
$chocoPackageErrorLabel.Visible = $true
11021135
$packageTextBox.Text = $packageName
11031136
$addPackageButton.enabled = $true
1104-
} else {
1137+
} else {
11051138
$chocoPackage = Get-ChocoPackage -PackageName $packageTextBox.Text
1106-
if ($chocoPackage) {
1107-
$chocoPackageErrorLabel.text = "Found Choco package"
1108-
$chocoPackageErrorLabel.ForeColor = $successColor
1109-
$chocoPackageErrorLabel.Visible = $true
1110-
$addPackageButton.enabled = $true
1111-
}else {
1112-
$chocoPackageErrorLabel.text = "package not found"
1113-
$chocoPackageErrorLabel.ForeColor = $errorColor
1114-
$chocoPackageErrorLabel.Visible = $true
1115-
$addPackageButton.enabled = $false
1139+
if ($chocoPackage) {
1140+
$chocoPackageErrorLabel.text = "Found Choco package"
1141+
$chocoPackageErrorLabel.ForeColor = $successColor
1142+
$addPackageButton.enabled = $true
1143+
} else {
1144+
$chocoPackageErrorLabel.text = "Package not found"
1145+
$chocoPackageErrorLabel.ForeColor = $errorColor
1146+
$addPackageButton.enabled = $false
11161147
}
1117-
11181148
}
11191149
})
11201150

@@ -1123,23 +1153,21 @@ if (-not $noGui.IsPresent) {
11231153
$addPackageButton.width = 118
11241154
$addPackageButton.height = 30
11251155
$addPackageButton.enabled = $false
1126-
$addPackageButton.location = New-Object System.Drawing.Point(400,775)
1156+
$addPackageButton.location = New-Object System.Drawing.Point(650,730)
11271157
$addPackageButton.Font = New-Object System.Drawing.Font('Microsoft Sans Serif',10)
11281158
$addPackageButton.Add_Click({
1129-
If ($packageTextBox.Text -ne ""){
11301159
if (Add-NewPackage -PackageName $packageTextBox.Text){
11311160
$chocoPackageErrorLabel.ForeColor = $successColor
11321161
$chocoPackageErrorLabel.text = "Package added"
11331162
}else {
11341163
$chocoPackageErrorLabel.ForeColor = $errorColor
1135-
$chocoPackageErrorLabel.text = "Error to add the package"
1164+
$chocoPackageErrorLabel.text = "Error to add the package: duplicated"
11361165
}
1137-
}
1138-
$addPackageButton.enabled = $false
1166+
$addPackageButton.enabled = $false
11391167
})
11401168

1141-
$formCategories.controls.AddRange(@($additionalPackagesLabel,$packageLabel,$packageUrlLabel,$packageUrl2Label,$packageVMLabel,$additionalPackagesBox,$deletePackageButton,$chocoPackageButton,$chocoPackageLabel,$packageTextBox,$chocoPackageErrorLabel,$findPackageButton,$addPackageButton))
1142-
$formCategories.controls.AddRange(@($labelCategories,$panelCategories,$installButton,$resetButton,$allPackagesButton,$cancelButton,$clearPackagesButton))
1169+
$formCategories.controls.AddRange(@($additionalPackagesLabel,$packageLabel,$labelChoco,$labelFlarevm,$linkLabelChoco,$linkLabelFlarevm,$linkLabelFlarevm,$additionalPackagesBox,$deletePackageButton,$chocoPackageButton,$chocoPackageLabel,$packageTextBox,$chocoPackageErrorLabel,$findPackageButton,$addPackageButton))
1170+
$formCategories.controls.AddRange(@($labelCategories,$labelCategories2,$panelCategories,$installButton,$resetButton,$allPackagesButton,$cancelButton,$clearPackagesButton))
11431171
$formCategories.Add_Shown({$formCategories.Activate()})
11441172
$resultCategories = $formCategories.ShowDialog()
11451173
if ($resultCategories -eq [System.Windows.Forms.DialogResult]::OK){
@@ -1150,9 +1178,6 @@ if (-not $noGui.IsPresent) {
11501178
exit 1
11511179
}
11521180

1153-
1154-
1155-
11561181
################################################################################
11571182
## END GUI
11581183
################################################################################

0 commit comments

Comments
 (0)