Closed Karneades closed 2 years ago
If the PR is merged in the future, then the wiki can be updated to reflect the tab completion support.
This seems amazing. I'll check it out but just wanted to let you know that I will be out on vacation for a couple weeks and won't be able to test until after that. I do have a question about if you can support an atomic technique of "All" which is something we currently allow. For example, Invoke-AtomicTest All -CheckPrereqs
Oh, good point with the All value... right, this would fail currently because the file does (obviously) not exist... I will work on that now to get the "All" to the validate set.
Instead of just using the file listing, I add the All first and extend that list.
PS> $ValidateSetAtomics = @("All")
PS> $ValidateSetAtomics += $(((gci $PathToAtomicsFolder\T*\* -Filter *.yaml).name) -replace "\.yaml","")
PS> $ValidateSetAtomics
All
T1003
T1003.001
T1003.002
T1003.003
Thanks for offering this, @Karneades! So that we can better understand the use case, can you let us know how you use this to help save you time? Thanks! For example, I'm thinking, do you use the tab completion to identify which ATT&CK Technique IDs you want to test? Do you use it tab-complete a parent ATT&CK Technique ID so that you can see what sub-techniques are available? In other words, do you use it more to save keystrokes on an technique ID you already know you want to execute or do you use it more to discover what techniques IDs are available?
Yes, typing only some numbers and then tab complete or listing the available techniques. If it really helps is also for me unclear with the IDs currently. You already have to know the ID when using the command and then you can copy paste it. But if you type the number manually it helps quickly jump through the IDs. I saw a video from Red Canary yesterday, where I saw that someone typed the ID by hand and then thought adding that tap completion.
The speed gain with tab complete is obvisouly not very high here... so maybe it's unneeded code for what it provides :D That tab completion could be extended to allow using the display name (human readable) in the command which is then translated to the ID.
Thanks for the explanation! I could see this being helpful for some but a concern I've always had with dynamic parameters is that they break PowerShell's ability to self-document with Get-Help. What looks like a happy middle ground where you'd be able to keep the original parameter while also supporting tab completion is with the Register-ArgumentCompleter cmdlet but that's only available in PowerShell Core. My personal workflow for learning any new cmdlet/function is to call Get-Help which is why I've always struggled with dynamic parameters since they break that. Thoughts?
Yes, that missing self-documentation for get-help
is an issue. It's a tradeoff between the functionality and the documentation. If the help outweighs the tab complete functionality, then I'm totally fine to close the PR.
The missing self-documentation could be compensated by adding further information to the Wiki and the files itself. Documentation for the dynamic parameter could be added to the DESCRIPTION or EXAMPLE section in the PS1 file and you generally already have a good documentation in the wiki and elsewhere about Invoke-AtomicRedTeam. Because the parameter is mandatory it will popup if someone is missing that.
In my other modules I use PlatyPS for generating the PS help files where I was able to include the dynamic parameter information in the description which is then displayed in get-help. This is disproportionately for the current case, I guess.
Thanks for that additional context, @Karneades! Sorry for the late reply. I'd love to get @clr2of8's input on this. Thanks!
I'm going to close this out for now, in favor of leaving the Get-Help functional, but we do appreciate all the time and effort invested and hope that you will continue to contribute in the future.
Improve usability by adding dynamic parameter support for atomic techniques. This allows tab completion support for the available techniques. Further improvement could be to use the display name of the technique instead of the ID and translate that later to the technique ID in the code.
The important part is the following - getting all the filenames from the path (either default or given by the user) and remove the extension.
I don't use the framework much, so I'm thankful if someone could test if anything breaks due to the change. Parameter settings like pipeline support or the position are still ensured.
Use
<tab>
to jump through the techniques or use<ctrl-space>
to list them.If you directly give the technique without explicitly use the parameter name, tab completion is missing but the value is still checked against the validate set