Skip to content

Commit b40a4ed

Browse files
Merge pull request #3 from PSSecTools/updates
1.2.10
2 parents 9ae2d5e + 0d428d4 commit b40a4ed

26 files changed

+694
-277
lines changed

JEAnalyzer/JEAnalyzer.psd1

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44

55
# Version number of this module.
66

7-
ModuleVersion = '1.1.0'
7+
ModuleVersion = '1.2.10'
88

99
# ID used to uniquely identify this module
1010
GUID = '346caa76-534a-4651-88f5-359e85cd71c0'
1111

1212
# Author of this module
13-
Author = 'Miriam Wiesner'
13+
Author = 'Miriam Wiesner, Friedrich Weinmann'
1414

1515
# Company or vendor of this module
16-
CompanyName = 'Miriam Wiesner'
16+
CompanyName = ' '
1717

1818
# Copyright statement for this module
1919
Copyright = 'Copyright (c) 2018 Miriam Wiesner'
@@ -27,7 +27,7 @@
2727
# Modules that must be imported into the global environment prior to importing
2828
# this module
2929
RequiredModules = @(
30-
@{ ModuleName = 'PSFramework'; ModuleVersion = '1.0.12' }
30+
@{ ModuleName = 'PSFramework'; ModuleVersion = '1.4.150' }
3131
)
3232

3333
# Assemblies that must be loaded prior to importing this module
@@ -42,25 +42,28 @@
4242
# Functions to export from this module
4343
FunctionsToExport = @(
4444
'Add-JeaModuleRole'
45+
'Add-JeaModuleScript'
4546
'ConvertTo-JeaCapability'
47+
'Export-JeaModule'
48+
'Export-JeaRoleCapFile'
4649
'Import-JeaScriptFile'
50+
'Install-JeaModule'
4751
'New-JeaCommand'
4852
'New-JeaModule'
4953
'New-JeaRole'
5054
'Read-JeaScriptblock'
5155
'Read-JeaScriptFile'
52-
'Export-JeaModule'
53-
'Export-JeaRoleCapFile'
56+
'Test-JeaCommand'
5457
)
5558

5659
# Cmdlets to export from this module
57-
CmdletsToExport = ''
60+
# CmdletsToExport = ''
5861

5962
# Variables to export from this module
60-
VariablesToExport = ''
63+
# VariablesToExport = ''
6164

6265
# Aliases to export from this module
63-
AliasesToExport = ''
66+
# AliasesToExport = ''
6467

6568
# List of all modules packaged with this module
6669
ModuleList = @()

JEAnalyzer/bin/JEAnalyzer.dll

512 Bytes
Binary file not shown.

JEAnalyzer/bin/JEAnalyzer.pdb

1.54 KB
Binary file not shown.

JEAnalyzer/bin/JEAnalyzer.xml

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

JEAnalyzer/changelog.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Changelog
2+
3+
## 1.2.10
4+
5+
- New: Command Install-JeaModule - Installs a JEA module on the target computer
6+
- New: Command Add-JeaModuleScript - Adds a script to a JEA module
7+
- New: Command Test-JeaCommand - Test an individual command for safety to publish in an endpoint.
8+
- Upd: New-JeaModule - Added parameters for PreImport and PostImport scripts
9+
- Upd: New-JeaModule - New parameter `-RequiredModules` enables specifying prerequisites
10+
- Upd: New-JeaCommand - New parameter: `-CommandType` allows picking the type of command for unresolveable commands.
11+
- Upd: JeaModules - all roles will now automatically import the jea module, irrespective of commands used
12+
- Fix: Export-JeaModule - Does not write preimport and postimport scripts
13+
- Fix: New-JeaCommand - Fails for unknown commands
14+
- Fix: Export-JeaModule - New JEA modules will only try to load ps1 files on import.
15+
16+
## 1.1.0 (???)
17+
18+
- Pre-History

JEAnalyzer/en-us/strings.psd1

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,37 @@
11
@{
2-
# General
3-
'General.BoundParameters' = 'Bound parameters: {0}'
4-
5-
# Validation
6-
'Validate.FileSystem.Directory.Fail' = 'The input object could not be identified as a directory: {0}'
7-
8-
# Assembly
9-
'Assembly.Parameter.MissingName' = 'Could not convert from hashtable, must contain a "Name" element!'
10-
11-
# Command Add-JeaModuleRole
12-
'Add-JeaModuleRole.RolePresent' = 'Role {0} already exists in {1}! Use -Force to replace the existing role.'
13-
'Add-JeaModuleRole.AddingRole' = 'Adding role {0} to module {1}'
14-
15-
# Command ConvertTo-Capability
16-
'ConvertTo-Capability.CapabilityNotKnown' = 'Could not convert to capability: {0}'
17-
18-
# Command Export-JeaModule
19-
'Export-JeaModule.Folder.ModuleBaseExists' = "The module's base folder already exists: {0}"
20-
'Export-JeaModule.Folder.ModuleBaseNew' = 'Creating new module folder: {0}'
21-
'Export-JeaModule.Folder.VersionRoot' = 'Creating version specific module path: {0}\{1}'
22-
'Export-JeaModule.Folder.Content' = 'Creating subfolder: {0}'
23-
'Export-JeaModule.Folder.RoleCapailities' = 'Creating the folder to store Role Capability Files: {0}\RoleCapabilities'
24-
'Export-JeaModule.Role.NewRole' = 'Creating new Role: {0} ({1} Published Command Capabilities)'
25-
'Export-JeaModule.Role.VisibleCmdlet' = '[Role: {0}] Adding visible Cmdlet: {1}{2}'
26-
'Export-JeaModule.Role.VisibleFunction' = '[Role: {0}] Adding visible Function: {1}{2}'
27-
'Export-JeaModule.File.Create' = 'Creating File: {0}'
28-
29-
# Command Import-JeaScriptFile
30-
'Import-JeaScriptFile.ProcessingInput' = 'Processing file for import: {0}'
31-
'Import-JeaScriptFile.ParsingError' = 'Parsing error for file: {0}'
32-
'Import-JeaScriptFile.UnknownError' = 'Unknown error when processing file: {0}'
33-
34-
# Command New-JeaModule
35-
'New-JeaModule.Creating' = 'Creating JEA Module object for: {0} (v{1})'
36-
37-
# Command New-JeaRole
38-
'New-JeaRole.Creating' = 'Creating Role: {0}'
2+
'Add-JeaModuleRole.AddingRole' = 'Adding role {0} to module {1}' # $roleItem.Name, $Module.Name
3+
'Add-JeaModuleRole.RolePresent' = 'Role {0} already exists in {1}! Use -Force to replace the existing role.' # $roleItem.Name, $Module.Name
4+
5+
'ConvertTo-Capability.CapabilityNotKnown' = 'Could not convert to capability: {0}' # $inputItem
6+
7+
'Export-JeaModule.File.Create' = 'Creating File: {0}' # $Path
8+
'Export-JeaModule.Folder.Content' = 'Creating subfolder: {0}' # $folder
9+
'Export-JeaModule.Folder.ModuleBaseExists' = "The module's base folder already exists: {0}" # $moduleBase.FullName
10+
'Export-JeaModule.Folder.ModuleBaseNew' = 'Creating new module folder: {0}' # $moduleBase.FullName
11+
'Export-JeaModule.Folder.RoleCapailities' = 'Creating the folder to store Role Capability Files: {0}\RoleCapabilities' # $rootFolder.FullName
12+
'Export-JeaModule.Folder.VersionRoot' = 'Creating version specific module path: {0}\{1}' # $moduleBase.FullName, $moduleObject.Version
13+
'Export-JeaModule.Role.NewRole' = 'Creating new Role: {0} ({1} Published Command Capabilities)' # $role.Name, $role.CommandCapability.Count
14+
'Export-JeaModule.Role.VisibleCmdlet' = '[Role: {0}] Adding visible Cmdlet: {1}{2}' # $role.Name, $commandName, $parameterText
15+
'Export-JeaModule.Role.VisibleFunction' = '[Role: {0}] Adding visible Function: {1}{2}' # $role.Name, $commandName, $parameterText
16+
17+
'FileSystem.Directory.Fail' = 'Not a directory: {0}' # <user input>, <validation item>
18+
19+
'General.BoundParameters' = 'Bound parameters: {0}' # ($PSBoundParameters.Keys -join ", ")
20+
21+
'Import-JeaScriptFile.ParsingError' = 'Parsing error for file: {0}' # $file
22+
'Import-JeaScriptFile.ProcessingInput' = 'Processing file for import: {0}' # $file
23+
'Import-JeaScriptFile.UnknownError' = 'Unknown error when processing file: {0}' # $file
24+
25+
'Install-JeaModule.Connecting.Sessions' = 'Connecting via WinRM to {0}' # ($ComputerName -join ", ")
26+
'Install-JeaModule.Connections.Failed' = 'Failed to connect to {0}' # ($failedServers.TargetObject -join ", ")
27+
'Install-JeaModule.Connections.NoSessions' = 'No successful sessions established, terminating.' #
28+
'Install-JeaModule.Copying.Module' = 'Copying JEA module {0} to {1}' # $moduleObject.Name, $session.ComputerName
29+
'Install-JeaModule.Exporting.Module' = 'Exporting JEA module {0}' # $moduleObject.Name
30+
'Install-JeaModule.Installing.Module' = 'Installing JEA module {0}' # $moduleObject.Name
31+
32+
'New-JeaCommand.DangerousCommand' = 'Dangerous command detected: {0}. Interrupting, use "-Force" to accept insecure commands.' # $Name
33+
34+
'New-JeaModule.Creating' = 'Creating JEA Module object for: {0} (v{1})' # $Name, $Version
35+
36+
'New-JeaRole.Creating' = 'Creating Role: {0}' # $Name
3937
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
function Add-JeaModuleScript
2+
{
3+
<#
4+
.SYNOPSIS
5+
Adds a script to a JEA module.
6+
7+
.DESCRIPTION
8+
Adds a script to a JEA module.
9+
This script will be executed on import, either before or after loading functiosn contained in the module.
10+
Use this to add custom logic - such as logging - as users connect to the JEA endpoint.
11+
12+
.PARAMETER Module
13+
The JEA module to add the script to.
14+
Use New-JeaModule to create such a module object.
15+
16+
.PARAMETER Path
17+
Path to the scriptfile to add.
18+
19+
.PARAMETER Text
20+
Script-Code to add.
21+
22+
.PARAMETER Name
23+
Name of the scriptfile.
24+
This parameter is optional. What happens if you do NOT use it depends on other parameters:
25+
-Path : Uses the filename instead
26+
-Text : Uses a random guid
27+
This is mostly cosmetic, as you would generally not need to manually modify the output module.
28+
29+
.PARAMETER Type
30+
Whether the script is executed before or after the functions of the JEA module are available.
31+
It needs to run BEFORE loading the functions if defining PowerShell classes, AFTER if it uses the functions.
32+
If neither: Doesn't matter.
33+
Defaults to: PostScript
34+
35+
.EXAMPLE
36+
PS C:\> Add-JeaModuleScript -Module $Module -Path '.\connect.ps1'
37+
38+
Adds the connect.ps1 scriptfile as a script executed after loading functions.
39+
#>
40+
[CmdletBinding(DefaultParameterSetName = 'File')]
41+
Param (
42+
[Parameter(Mandatory = $true, Position = 0)]
43+
[JEAnalyzer.Module]
44+
$Module,
45+
46+
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true, ParameterSetName = 'File')]
47+
[PsfValidateScript('PSFramework.Validate.FSPath.File', ErrorString = 'PSFramework.Validate.FSPath.File')]
48+
[Alias('FullName')]
49+
[string]
50+
$Path,
51+
52+
[Parameter(Mandatory = $true, ParameterSetName = 'Text')]
53+
[string]
54+
$Text,
55+
56+
[string]
57+
$Name,
58+
59+
[ValidateSet('PreScript','PostScript')]
60+
[string]
61+
$Type = 'PostScript'
62+
)
63+
64+
process
65+
{
66+
if ($Path)
67+
{
68+
$file = [JEAnalyzer.ScriptFile]::new($Path)
69+
if ($Name) { $file.Name = $Name }
70+
}
71+
else
72+
{
73+
if (-not $Name) { $Name = [System.Guid]::NewGuid().ToString() }
74+
$file = [JEAnalyzer.ScriptFile]::new($Name, $Text)
75+
}
76+
switch ($Type)
77+
{
78+
'PreScript' { $Module.PreimportScripts[$file.Name] = $file }
79+
'PostScript' { $Module.PostimportScripts[$file.Name] = $file }
80+
}
81+
}
82+
}

JEAnalyzer/functions/construct/Import-JeaScriptFile.ps1

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ function {0}
145145
#region Case: Parse Error
146146
elseif ($testResult.ErrorType -eq 'ParseError')
147147
{
148-
Stop-PSFFunction -String 'Import-JeaScriptFile.ParsingError' -StringValues $file -Continue
148+
Stop-PSFFunction -String 'Import-JeaScriptFile.ParsingError' -StringValues $file -Continue -EnableException $EnableException
149149
}
150150
#endregion Case: Parse Error
151151

@@ -165,13 +165,9 @@ function {0}
165165
#region Case: Unknown State (Should never happen)
166166
else
167167
{
168-
Stop-PSFFunction -String 'Import-JeaScriptFile.UnknownError' -StringValues $file -Continue
168+
Stop-PSFFunction -String 'Import-JeaScriptFile.UnknownError' -StringValues $file -Continue -EnableException $EnableException
169169
}
170170
#endregion Case: Unknown State (Should never happen)
171171
}
172172
}
173-
end
174-
{
175-
176-
}
177173
}

JEAnalyzer/functions/construct/New-JeaCommand.ps1

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
By default, the command object will just be returned by this function.
2424
If you specify a role, it will instead only be added to the role.
2525
26+
.PARAMETER CommandType
27+
The type of command to add.
28+
Only applies when the command cannot be resolved.
29+
Defaults to function.
30+
2631
.PARAMETER Force
2732
Override the security warning when generating an unsafe command.
2833
By default, New-JeaCommand will refuse to create a command object for commands deemed unsafe for use in JEA.
@@ -49,6 +54,9 @@
4954
[JEAnalyzer.Role]
5055
$Role,
5156

57+
[System.Management.Automation.CommandTypes]
58+
$CommandType = [System.Management.Automation.CommandTypes]::Function,
59+
5260
[switch]
5361
$Force,
5462

@@ -72,8 +80,10 @@
7280

7381
$resultCommand = New-Object -TypeName 'JEAnalyzer.CapabilityCommand' -Property @{
7482
Name = $commandData.CommandName
75-
CommandType = $commandData.CommandObject.CommandType
7683
}
84+
if ($commandData.CommandObject) { $resultCommand.CommandType = $commandData.CommandObject.CommandType }
85+
else { $resultCommand.CommandType = $CommandType }
86+
7787
foreach ($parameterItem in $Parameter)
7888
{
7989
$resultCommand.Parameters[$parameterItem.Name] = $parameterItem

JEAnalyzer/functions/construct/New-JeaModule.ps1

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,25 @@
3737
The version of the JEA Module.
3838
A higher version will superseed all older versions of the same name.
3939
40+
.PARAMETER PreImport
41+
Scripts to execute during JEA module import, before loading functions.
42+
Offer either:
43+
- The path to the file to add
44+
- A hashtable with two keys: Name & Text
45+
46+
.PARAMETER PostImport
47+
Scripts to execute during JEA module import, after loading functions.
48+
Offer either:
49+
- The path to the file to add
50+
- A hashtable with two keys: Name & Text
51+
52+
.PARAMETER RequiredModules
53+
Any dependencies the module has.
54+
Note: Specify this in the same manner you would in a module manifest.
55+
Note2: Do not use this for modules you cannot publish in a repository if you want to distribute this JEA module in such.
56+
For example, taking a dependency on the Active Directory module would be disadvised.
57+
In this coses, instead import them as a PreImport-script.
58+
4059
.EXAMPLE
4160
PS C:\> New-JeaModule -Name 'JEA_ADUser' -Description 'Grants access to the Get-ADUser command'
4261
@@ -62,13 +81,18 @@
6281
$Company = (Get-PSFConfigValue -FullName 'JEAnalyzer.Company'),
6382

6483
[version]
65-
$Version = '1.0.0'
84+
$Version = '1.0.0',
85+
86+
[JEAnalyzer.ScriptFile[]]
87+
$PreImport,
88+
89+
[JEAnalyzer.ScriptFile[]]
90+
$PostImport,
91+
92+
[object]
93+
$RequiredModules
6694
)
6795

68-
begin
69-
{
70-
Write-PSFMessage -Level InternalComment -String 'General.BoundParameters' -StringValues ($PSBoundParameters.Keys -join ", ") -Tag 'debug', 'start', 'param'
71-
}
7296
process
7397
{
7498
Write-PSFMessage -String 'New-JeaModule.Creating' -StringValues $Name, $Version
@@ -80,6 +104,10 @@
80104
Company = $Company
81105
}
82106
if ($Identity) { $module.Roles[$Name] = New-JeaRole -Name $Name -Identity $Identity }
107+
if ($RequiredModules) { $module.RequiredModules = $RequiredModules }
108+
foreach ($scriptFile in $PreImport) { $module.PreimportScripts[$scriptFile.Name] = $scriptFile }
109+
foreach ($scriptFile in $PostImport) { $module.PostimportScripts[$scriptFile.Name] = $scriptFile }
110+
83111
$module
84112
}
85113
}

0 commit comments

Comments
 (0)