cisagov / ScubaGear

Automation to assess the state of your M365 tenant against CISA's baselines
https://www.cisa.gov/resources-tools/services/secure-cloud-business-applications-scuba-project
Creative Commons Zero v1.0 Universal
1.59k stars 215 forks source link

Adding a GUI to ScubaGear #856

Open buidav opened 8 months ago

buidav commented 8 months ago

💡 Summary

This ticket goes back to the olden days of the tool. There was a feature suggestion to add a PowerShell GUI to ScubaGear to lower the barrier for user entry. With the introduction of the config file, the barrier for user entry is now even higher. So, bringing back this feature request in this issue.

We also have some old code written that does need to be modified. See the comment below.

Motivation and context

To assist users who may not be so well versed in PowerShell/Config file writing in running the tool.

Implementation notes

There are a few ways to implement this. I'll suggest a few ways but feel free to implement any other methods.

Acceptance criteria

You're able to run ScubaGear via a GUI to some extent.

buidav commented 8 months ago

Here's the previous code way back when didn't even have a name for the tool. It will need to be modified to work with the current version of the ScubaGear.

Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
[System.Windows.Forms.Application]::EnableVisualStyles()

# function that opens folder navigator and writes location to a variable
Function Get-OutFolderNav($initialDirectory="") 
{
    $foldername = New-Object System.Windows.Forms.FolderBrowserDialog
    $foldername.Description = "Select an output folder"
    $foldername.SelectedPath = $initialDirectory

    if ($foldername.ShowDialog() -eq "OK")
    {
        $folder += $foldername.SelectedPath
    }

    return $folder
}

# function that sets app name to test 
Function SetAppName($AppSelectMenu)
{
    [string]$AppName = $AppSelectMenu.SelectedItem
    if($AppSelectMenu.SelectedItem -eq "Azure Active Directory") {$AppName = "aad"}
    if($AppSelectMenu.SelectedItem -eq "Exchange Online") {$AppName = "exo"}
    if($AppSelectMenu.SelectedItem -eq "Power Platform") {$AppName = "powerplatform"}
    if($AppSelectMenu.SelectedItem -eq "Defender") {$AppName = "defender"}
    if($AppSelectMenu.SelectedItem -eq "Teams") {$AppName = "teams"}
    return $AppName
}
# function that sets output folder for test
Function SetOutputFolder($OutLocationBox)
{
    [string]$OutFolder = $OutLocationBox.text
    return $OutFolder
}

#initializes form
$BaselineForm = New-Object System.Windows.Forms.Form
$BaselineForm.ClientSize = "500,500"
$BaselineForm.text = "Security Baseline Test"
$BaselineForm.BackColor = "#ffffff"

#title for app selection
$AppSelectTitle = New-Object System.Windows.Forms.Label
$AppSelectTitle.text = "Select a configuration to test"
$AppSelectTitle.AutoSize = $true
$AppSelectTitle.location = New-Object System.Drawing.Point(20,20)
$AppSelectTitle.Font = "Microsoft Sans Serif,12"

#app selection drop-down menu
$AppSelectMenu = New-Object System.Windows.Forms.ComboBox
$AppSelectMenu.width = 300
$AppSelectMenu.AutoSize = $true
$AppSelectMenu.location = New-Object System.Drawing.Point(20,50)
$AppSelectMenu.Font = "Microsoft Sans Serif,10"
#app selection options
@("Azure Active Directory", "Exchange Online", "Power Platform", "Defender", "Teams") | ForEach-Object{[void] $AppSelectMenu.Items.Add($_)}

# --- work in progress ---
# app selection checkbox menu
$AppSelectCheckedListBox = New-Object System.Windows.Forms.CheckedListBox
$AppSelectCheckedListBox.width = 300
$AppSelectCheckedListBox.AutoSize = $true
# location is below output folder box for now for testing purposes
$AppSelectCheckedListBox.location = New-Object System.Drawing.Point(20,200)
@("Azure Active Directory", "Exchange Online", "Power Platform", "Defender", "Teams") | ForEach-Object{[void] $AppSelectCheckedListBox.Items.Add($_)}
$AppSelectCheckedListBox.ClearSelected()
# TO DO: Add 'Select All' option
# TO DO: Change variable names throughout script to reference the apps selected here rather than drop-down menu

#title for output location selection
$OutLocationTitle = New-Object System.Windows.Forms.Label
$OutLocationTitle.text = "Select location of output folder"
$OutLocationTitle.AutoSize = $true
$OutLocationTitle.location = New-Object System.Drawing.Point(20,90)
$OutLocationTitle.Font = "Microsoft Sans Serif,12"

#output location browse button
$BaselineForm.Controls.Add($OutLocationBtn)

$OutLocationBtn = New-Object System.Windows.Forms.Button
$OutLocationBtn.BackColor = "#c0e5f1"
$OutLocationBtn.text = "Browse"
$OutLocationBtn.width = 90
$OutLocationBtn.height = 30
$OutLocationBtn.location = New-Object System.Drawing.Point(20,150)

#output location text box
$OutLocationBox = New-Object System.Windows.Forms.TextBox
$OutLocationBox.width = 300
$OutLocationBox.location = New-Object System.Drawing.Point(20,120)
$OutLocationBox.AutoSize = $true
$OutLocationBtn.Add_Click({$OutLocationBox.text = Get-OutFolderNav($folder)})
$OutLocationBox.Font = "Microsoft Sans Serif,10"

function Get-SCuBAOutput($AppName, $OutFolder)
{

    [string]$TheRealAppName = SetAppName($AppSelectMenu)
    [string]$TheRealOutFolder = SetOutputFolder($OutLocationBox)
    # TEST -----
    # $word = "anything"
    # Write-host $word
    # Write-host $TheRealAppName
    # Write-host $TheRealOutFolder
    # END TEST---------
    Invoke-Expression ".\SCuBA.ps1 $($TheRealAppName) $($TheRealOutFolder)"
 }

#run button
$RunBtn = New-Object System.Windows.Forms.Button
$RunBtn.BackColor = "#91ef71"
$RunBtn.text = "Run"
$RunBtn.width = 90
$RunBtn.height = 30
$RunBtn.location = New-Object System.Drawing.Point(390,450)
$RunBtn.Add_Click({Get-SCuBAOutput})

#adds elements to form
$BaselineForm.controls.AddRange(@($AppSelectTitle,$AppSelectMenu,$OutLocationTitle,$OutLocationBox,$OutLocationBtn,$RunBtn,$AppSelectCheckedListBox))

#displays form
[void]$BaselineForm.ShowDialog()