├── .github └── workflows │ └── dotnet-desktop.yml ├── .gitignore ├── Binary └── poshsecframework.zip ├── Documentation └── ExposedMethods.txt ├── LICENSE ├── PoshSec.Framework.Test ├── AppSettingsTest.cs ├── PoshSec.Framework.Test.csproj ├── Properties │ └── AssemblyInfo.cs └── packages.config ├── README.md ├── poshsecframework.sln ├── poshsecframework.sln.DotSettings └── poshsecframework ├── Comparers └── ListViewColumnSorter.cs ├── Controls ├── PSAlertList.cs ├── PSAlertList.resx ├── PSObjectGrid.cs ├── PSTabItem.cs ├── PSTabItem.resx ├── PSTextBox.cs └── RichTextBoxCaret.cs ├── Enums └── EnumValues.cs ├── Events ├── ScheduleEventArgs.cs ├── WriteEventArgs.cs └── WriteProgressEventArgs.cs ├── Extensions.cs ├── FirstTimeSetup ├── Steps.cs ├── frmFirstTime.Designer.cs ├── frmFirstTime.cs └── frmFirstTime.resx ├── Images ├── psficon.ico └── psficon_alert.ico ├── Interface ├── ProxyPreference.cs ├── ProxyPreferenceGroupBox.Designer.cs ├── ProxyPreferenceGroupBox.cs ├── SystemForm.Designer.cs ├── SystemForm.cs ├── SystemForm.resx ├── frmAddNetwork.Designer.cs ├── frmAddNetwork.cs ├── frmAddNetwork.resx ├── frmMain.Designer.cs ├── frmMain.cs ├── frmMain.resx ├── frmNetworkBrowser.Designer.cs ├── frmNetworkBrowser.cs ├── frmNetworkBrowser.resx ├── frmParams.Designer.cs ├── frmParams.cs ├── frmParams.resx ├── frmRepository.Designer.cs ├── frmRepository.cs ├── frmRepository.resx ├── frmScan.Designer.cs ├── frmScan.cs ├── frmScan.resx ├── frmSchedule.Designer.cs ├── frmSchedule.cs ├── frmSchedule.resx ├── frmSettings.Designer.cs ├── frmSettings.cs ├── frmSettings.resx ├── frmStartup.Designer.cs ├── frmStartup.cs └── frmStartup.resx ├── Network ├── NetworkBrowser.cs ├── NetworkScanCompleteEventArgs.cs ├── NetworkType.cs ├── NetworksTreeView.cs └── Syslog.cs ├── PShell ├── pscredentialeditor.cs ├── pscript.cs ├── pseventargs.cs ├── psexception.cs ├── psfhost.cs ├── psfhostinterface.cs ├── psfhostrawinterface.cs ├── psfilenameeditor.cs ├── pshell.cs ├── pshosteditor.cs ├── psmethods.cs ├── psparameter.cs ├── psparamtype.cs └── psvariables.cs ├── Program.cs ├── Properties ├── AssemblyInfo.cs ├── Resources.Designer.cs ├── Resources.resx ├── Settings.Designer.cs └── Settings.settings ├── Resources ├── Diagram.png ├── Server.png ├── Server1.png ├── ServerExecute.png ├── application-x-powershellscript.png ├── application-x-shellscript.png ├── application-x-shellscript1.png ├── caret_underline.png ├── computer-add.png ├── computer-delete.png ├── dialog-accept.png ├── dialog-cancel-5.png ├── dialog-error-3.png ├── dialog-error-4.png ├── dialog-information-4.png ├── dialog-no-2.png ├── dialog-warning-2.png ├── dialog-warning-3.png ├── dialog-yes.png ├── document-export-4.png ├── document-import.png ├── document-open-7.png ├── document-open-folder.png ├── edit-clear-list.png ├── edit-delete-6.png ├── exclamation.png ├── help.png ├── network-transmit-receive-2.png ├── page-white_add.png ├── page-white_delete.png ├── page-white_edit.png ├── page-white_get.png ├── psf_logo_rev1.png ├── psficon.ico ├── psficonalert.ico ├── run.png ├── system-run-3.png ├── system-run-31.png ├── system-settings.png ├── tab-close-3.png ├── table-save.png ├── tag-blue.png ├── tag-green.png ├── tag-red.png ├── test.png ├── view-calendar-tasks.png └── view-refresh-7.png ├── Scans ├── ScanIpEventArgs.cs └── ScanStatusEventArgs.cs ├── Settings.cs ├── Settings └── AppSettings.cs ├── Strings └── StringValue.cs ├── Systems ├── CurrentNetworkChangedEventArgs.cs ├── DomainNetwork.cs ├── INetworkNode.cs ├── IPAddressConverter.cs ├── LocalNetwork.cs ├── Network.cs ├── NetworkNode.cs ├── Networks.cs ├── SystemsAddedEventArgs.cs ├── SystemsListView.cs └── SystemsListViewItem.cs ├── Utility ├── AlertFilter.cs ├── ExportObject.cs ├── Schedule.cs ├── ScheduleItem.cs └── ScheduleTime.cs ├── Web ├── GithubClient.cs └── GithubJsonItem.cs ├── app.config ├── packages.config ├── poshsecframework.csproj └── poshsecframework.csproj.DotSettings /.github/workflows/dotnet-desktop.yml: -------------------------------------------------------------------------------- 1 | # This workflow uses actions that are not certified by GitHub. 2 | # They are provided by a third-party and are governed by 3 | # separate terms of service, privacy policy, and support 4 | # documentation. 5 | 6 | # This workflow will build, test, sign and package a WPF or Windows Forms desktop application 7 | # built on .NET Core. 8 | # To learn how to migrate your existing application to .NET Core, 9 | # refer to https://docs.microsoft.com/en-us/dotnet/desktop-wpf/migration/convert-project-from-net-framework 10 | # 11 | # To configure this workflow: 12 | # 13 | # 1. Configure environment variables 14 | # GitHub sets default environment variables for every workflow run. 15 | # Replace the variables relative to your project in the "env" section below. 16 | # 17 | # 2. Signing 18 | # Generate a signing certificate in the Windows Application 19 | # Packaging Project or add an existing signing certificate to the project. 20 | # Next, use PowerShell to encode the .pfx file using Base64 encoding 21 | # by running the following Powershell script to generate the output string: 22 | # 23 | # $pfx_cert = Get-Content '.\SigningCertificate.pfx' -Encoding Byte 24 | # [System.Convert]::ToBase64String($pfx_cert) | Out-File 'SigningCertificate_Encoded.txt' 25 | # 26 | # Open the output file, SigningCertificate_Encoded.txt, and copy the 27 | # string inside. Then, add the string to the repo as a GitHub secret 28 | # and name it "Base64_Encoded_Pfx." 29 | # For more information on how to configure your signing certificate for 30 | # this workflow, refer to https://github.com/microsoft/github-actions-for-desktop-apps#signing 31 | # 32 | # Finally, add the signing certificate password to the repo as a secret and name it "Pfx_Key". 33 | # See "Build the Windows Application Packaging project" below to see how the secret is used. 34 | # 35 | # For more information on GitHub Actions, refer to https://github.com/features/actions 36 | # For a complete CI/CD sample to get started with GitHub Action workflows for Desktop Applications, 37 | # refer to https://github.com/microsoft/github-actions-for-desktop-apps 38 | 39 | name: .NET Core Desktop 40 | 41 | on: 42 | push: 43 | branches: [ "master" ] 44 | pull_request: 45 | branches: [ "master" ] 46 | 47 | jobs: 48 | 49 | build: 50 | 51 | strategy: 52 | matrix: 53 | configuration: [Debug, Release] 54 | 55 | runs-on: windows-latest # For a list of available runner types, refer to 56 | # https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on 57 | 58 | env: 59 | Solution_Name: your-solution-name # Replace with your solution name, i.e. MyWpfApp.sln. 60 | Test_Project_Path: your-test-project-path # Replace with the path to your test project, i.e. MyWpfApp.Tests\MyWpfApp.Tests.csproj. 61 | Wap_Project_Directory: your-wap-project-directory-name # Replace with the Wap project directory relative to the solution, i.e. MyWpfApp.Package. 62 | Wap_Project_Path: your-wap-project-path # Replace with the path to your Wap project, i.e. MyWpf.App.Package\MyWpfApp.Package.wapproj. 63 | 64 | steps: 65 | - name: Checkout 66 | uses: actions/checkout@v3 67 | with: 68 | fetch-depth: 0 69 | 70 | # Install the .NET Core workload 71 | - name: Install .NET Core 72 | uses: actions/setup-dotnet@v3 73 | with: 74 | dotnet-version: 6.0.x 75 | 76 | # Add MSBuild to the PATH: https://github.com/microsoft/setup-msbuild 77 | - name: Setup MSBuild.exe 78 | uses: microsoft/setup-msbuild@v1.0.2 79 | 80 | # Execute all unit tests in the solution 81 | - name: Execute unit tests 82 | run: dotnet test 83 | 84 | # Restore the application to populate the obj folder with RuntimeIdentifiers 85 | - name: Restore the application 86 | run: msbuild $env:Solution_Name /t:Restore /p:Configuration=$env:Configuration 87 | env: 88 | Configuration: ${{ matrix.configuration }} 89 | 90 | # Decode the base 64 encoded pfx and save the Signing_Certificate 91 | - name: Decode the pfx 92 | run: | 93 | $pfx_cert_byte = [System.Convert]::FromBase64String("${{ secrets.Base64_Encoded_Pfx }}") 94 | $certificatePath = Join-Path -Path $env:Wap_Project_Directory -ChildPath GitHubActionsWorkflow.pfx 95 | [IO.File]::WriteAllBytes("$certificatePath", $pfx_cert_byte) 96 | 97 | # Create the app package by building and packaging the Windows Application Packaging project 98 | - name: Create the app package 99 | run: msbuild $env:Wap_Project_Path /p:Configuration=$env:Configuration /p:UapAppxPackageBuildMode=$env:Appx_Package_Build_Mode /p:AppxBundle=$env:Appx_Bundle /p:PackageCertificateKeyFile=GitHubActionsWorkflow.pfx /p:PackageCertificatePassword=${{ secrets.Pfx_Key }} 100 | env: 101 | Appx_Bundle: Always 102 | Appx_Bundle_Platforms: x86|x64 103 | Appx_Package_Build_Mode: StoreUpload 104 | Configuration: ${{ matrix.configuration }} 105 | 106 | # Remove the pfx 107 | - name: Remove the pfx 108 | run: Remove-Item -path $env:Wap_Project_Directory\GitHubActionsWorkflow.pfx 109 | 110 | # Upload the MSIX package: https://github.com/marketplace/actions/upload-a-build-artifact 111 | - name: Upload build artifacts 112 | uses: actions/upload-artifact@v3 113 | with: 114 | name: MSIX Package 115 | path: ${{ env.Wap_Project_Directory }}\AppPackages 116 | -------------------------------------------------------------------------------- /Binary/poshsecframework.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/Binary/poshsecframework.zip -------------------------------------------------------------------------------- /Documentation/ExposedMethods.txt: -------------------------------------------------------------------------------- 1 | Exposed Methods 2 | === 3 | This documentation will guide you through on the exposed Methods that are available to use within your PowerShell script, function, or Cmdlet when running it from within the PoshSec Framework. Note: If you reference these variables directly from PowerShell they will do nothing or you will receive an error. These exposed variables are intended to only be used from within the PoshSec Framework. 4 | 5 | Methods 6 | === 7 | - $PSMessageBox 8 | - $PSAlert 9 | - $PSStatus 10 | - $PSHosts 11 | - $PSTab 12 | 13 | How to use an Exposed Method 14 | === 15 | Each of the defined methods listed below will give you an example of how to use them. However, you may also use the Get-Member Cmdlet to discover the methods, and functions available with each exposed Method. 16 | 17 | For example: 18 | $PSMessageBox | Get-Member 19 | 20 | $PSMessageBox 21 | === 22 | The $PSMessageBox method exposes the System.Window.Forms.MessageBox class to your PowerShell script, function, or Cmdlet. This will display a MessageBox within the PoshSec Framework displaying the text you provide. This is useful if you wish to get the attention of the person running the PoshSec framework. 23 | 24 | Members: 25 | --- 26 | 27 | Name MemberType Definition 28 | ---- ---------- ---------- 29 | Equals Method bool Equals(System.Object obj) 30 | GetHashCode Method int GetHashCode() 31 | GetType Method type GetType() 32 | Show Method void Show(string message, string title) 33 | ToString Method string ToString() 34 | 35 | $PSMessageBox.Show() 36 | --- 37 | This function will show a message box from within your script, function, or cmdlet in the PoshSec Framework interface. 38 | 39 | Parameters 40 | --- 41 | 42 | - message (String) [Required] 43 | The message you wish to display in the Message Box 44 | - title (String) [Not Required] 45 | The title of the Message Box window. 46 | 47 | Usage 48 | --- 49 | psf > $PSMessageBox.Show("Hello World", "My Custom MessageBox") 50 | psf > $PSMessageBox.Show("Hi, without title") 51 | 52 | 53 | $PSAlert 54 | === 55 | The $PSAlert method exposes the Alerts ListView control to your script, function, or cmdlet. This allows you to add an Alert to the ListView control. This is useful when you want to keep track of any errors, warnings, or informational messages and display that in the PoshSec Framework interface. 56 | 57 | Members 58 | --- 59 | 60 | Name MemberType Definition 61 | ---- ---------- ---------- 62 | Add Method void Add(string message, poshsecframework.PShell.psmethods+PSAlert+AlertType alerttype) 63 | Add Method void Add(string message, int alerttype) 64 | Equals Method bool Equals(System.Object obj) 65 | GetAlertTypeFromString Method poshsecframework.PShell.psmethods+PSAlert+AlertType GetAlertTypeFromString(string alerttype) 66 | GetHashCode Method int GetHashCode() 67 | GetType Method type GetType() 68 | ToString Method string ToString() 69 | ScriptName Property string ScriptName {get;set;} 70 | 71 | $PSAlert.Add() 72 | --- 73 | This function adds an alert to the Alerts ListView control within the PoshSec Framework. 74 | 75 | Parameters 76 | --- 77 | - message (String) [Required] 78 | The message to display for the alert. 79 | - alerttype (AlertType or Integer) 80 | The type of alert. Valid types are [0] Information, [1] Error, [2] Warning, [3] Severe, [4] Critical 81 | 82 | Usage 83 | --- 84 | psf > $psalert.add("Test", [poshsecframework.PShell.psmethods+PSAlert+AlertType]::Critical) 85 | psf > $psalert.add("Test", 4) 86 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, PowerShell Security 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | Redistributions in binary form must reproduce the above copyright notice, this 11 | list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | Neither the name of the {organization} nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /PoshSec.Framework.Test/AppSettingsTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using Microsoft.VisualStudio.TestTools.UnitTesting; 5 | 6 | namespace PoshSec.Framework.Test 7 | { 8 | public class AppSettingsTest 9 | { 10 | class MySettings 11 | { 12 | public MySettings() 13 | { 14 | ListOfStringsSetting = new List(); 15 | } 16 | public int IntegerSetting { get; set; } 17 | public string StringSetting { get; set; } 18 | public List ListOfStringsSetting { get; } 19 | } 20 | 21 | [TestClass] 22 | public class Save 23 | { 24 | [TestMethod] 25 | public void SaveSettings_ToDefaultPath_FileExists() 26 | { 27 | var settings = new MySettings 28 | { 29 | IntegerSetting = 3, 30 | StringSetting = "four" 31 | }; 32 | settings.ListOfStringsSetting.AddRange(new[] { "five", "six" }); 33 | 34 | AppSettings.Save(settings); 35 | Assert.IsTrue(File.Exists(AppSettings.Path)); 36 | } 37 | 38 | [TestMethod] 39 | public void SaveSettings_ToSpecificPath_FileExists() 40 | { 41 | var settings = new MySettings 42 | { 43 | IntegerSetting = 3, 44 | StringSetting = "four" 45 | }; 46 | settings.ListOfStringsSetting.AddRange(new[] { "five", "six" }); 47 | 48 | AppSettings.Save(settings, "mysettings.json"); 49 | Assert.IsTrue(File.Exists(AppSettings.Path)); 50 | } 51 | } 52 | 53 | [TestClass] 54 | public class Load 55 | { 56 | [TestMethod] 57 | public void LoadSettings_FromDefaultPath_SettingsNotNull() 58 | { 59 | var settings = AppSettings.Load(); 60 | Assert.IsNotNull(settings); 61 | } 62 | 63 | [TestMethod] 64 | public void LoadSettings_FromSpecificPath_SettingsNotNull() 65 | { 66 | var settings = AppSettings.Load("mysettings.json"); 67 | Assert.IsNotNull(settings); 68 | } 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /PoshSec.Framework.Test/PoshSec.Framework.Test.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {B1AC6AA0-2F1A-4696-BF4B-0E41CF2F4B6B} 8 | Library 9 | Properties 10 | PoshSec.Framework.Test 11 | PoshSec.Framework.Test 12 | v4.6.1 13 | 512 14 | {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 15 | 15.0 16 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 17 | $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages 18 | False 19 | UnitTest 20 | 21 | 22 | 23 | 24 | true 25 | full 26 | false 27 | bin\Debug\ 28 | DEBUG;TRACE 29 | prompt 30 | 4 31 | 32 | 33 | pdbonly 34 | true 35 | bin\Release\ 36 | TRACE 37 | prompt 38 | 4 39 | 40 | 41 | 42 | ..\packages\MSTest.TestFramework.1.2.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll 43 | 44 | 45 | ..\packages\MSTest.TestFramework.1.2.1\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | {156f1b6c-69b5-44e5-bd5e-ee19516f9d4a} 60 | poshsecframework 61 | 62 | 63 | 64 | 65 | 66 | 67 | This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /PoshSec.Framework.Test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | [assembly: AssemblyTitle("PoshSec.Framework.Test")] 6 | [assembly: AssemblyDescription("")] 7 | [assembly: AssemblyConfiguration("")] 8 | [assembly: AssemblyCompany("")] 9 | [assembly: AssemblyProduct("PoshSec.Framework.Test")] 10 | [assembly: AssemblyCopyright("Copyright © 2018")] 11 | [assembly: AssemblyTrademark("")] 12 | [assembly: AssemblyCulture("")] 13 | 14 | [assembly: ComVisible(false)] 15 | 16 | [assembly: Guid("b1ac6aa0-2f1a-4696-bf4b-0e41cf2f4b6b")] 17 | 18 | // [assembly: AssemblyVersion("1.0.*")] 19 | [assembly: AssemblyVersion("1.0.0.0")] 20 | [assembly: AssemblyFileVersion("1.0.0.0")] 21 | -------------------------------------------------------------------------------- /PoshSec.Framework.Test/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /poshsecframework.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27428.2015 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "poshsecframework", "poshsecframework\poshsecframework.csproj", "{156F1B6C-69B5-44E5-BD5E-EE19516F9D4A}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PoshSec.Framework.Test", "PoshSec.Framework.Test\PoshSec.Framework.Test.csproj", "{B1AC6AA0-2F1A-4696-BF4B-0E41CF2F4B6B}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Release|Any CPU = Release|Any CPU 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {156F1B6C-69B5-44E5-BD5E-EE19516F9D4A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {156F1B6C-69B5-44E5-BD5E-EE19516F9D4A}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {156F1B6C-69B5-44E5-BD5E-EE19516F9D4A}.Release|Any CPU.ActiveCfg = Release|Any CPU 19 | {156F1B6C-69B5-44E5-BD5E-EE19516F9D4A}.Release|Any CPU.Build.0 = Release|Any CPU 20 | {B1AC6AA0-2F1A-4696-BF4B-0E41CF2F4B6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {B1AC6AA0-2F1A-4696-BF4B-0E41CF2F4B6B}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {B1AC6AA0-2F1A-4696-BF4B-0E41CF2F4B6B}.Release|Any CPU.ActiveCfg = Release|Any CPU 23 | {B1AC6AA0-2F1A-4696-BF4B-0E41CF2F4B6B}.Release|Any CPU.Build.0 = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {2CFC9554-0DE0-4B3C-9C20-C6C2CF23B7AA} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /poshsecframework.sln.DotSettings: -------------------------------------------------------------------------------- 1 |  2 | IP -------------------------------------------------------------------------------- /poshsecframework/Comparers/ListViewColumnSorter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Windows.Forms; 4 | 5 | namespace PoshSec.Framework.Comparers 6 | { 7 | class ListViewColumnSorter : IComparer 8 | { 9 | private int ColumnToSort; 10 | private SortOrder OrderOfSort; 11 | private CaseInsensitiveComparer ObjectCompare; 12 | 13 | public ListViewColumnSorter() 14 | { 15 | ColumnToSort = 0; 16 | OrderOfSort = SortOrder.None; 17 | ObjectCompare = new CaseInsensitiveComparer(); 18 | } 19 | 20 | public int Compare(object x, object y) 21 | { 22 | int compareResult; 23 | ListViewItem listviewX, listviewY; 24 | 25 | listviewX = (ListViewItem)x; 26 | listviewY = (ListViewItem)y; 27 | 28 | compareResult = ObjectCompare.Compare(listviewX.SubItems[ColumnToSort].Text, listviewY.SubItems[ColumnToSort].Text); 29 | if (OrderOfSort == SortOrder.Ascending) 30 | { 31 | return compareResult; 32 | } 33 | else if (OrderOfSort == SortOrder.Descending) 34 | { 35 | return (-compareResult); 36 | } 37 | else 38 | { 39 | return 0; 40 | } 41 | } 42 | 43 | public int SortColumn 44 | { 45 | set 46 | { 47 | ColumnToSort = value; 48 | } 49 | get 50 | { 51 | return ColumnToSort; 52 | } 53 | } 54 | 55 | public SortOrder Order 56 | { 57 | set 58 | { 59 | OrderOfSort = value; 60 | } 61 | get 62 | { 63 | return OrderOfSort; 64 | } 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /poshsecframework/Controls/PSObjectGrid.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections.ObjectModel; 4 | using System.Linq; 5 | using System.Management.Automation; 6 | using System.Text; 7 | using System.Windows.Forms; 8 | using PoshSec.Framework.Enums; 9 | using PoshSec.Framework.Strings; 10 | 11 | namespace PoshSec.Framework.Controls 12 | { 13 | class PSObjectGrid : ListView 14 | { 15 | #region Private Variables 16 | private ToolStrip parstrip = null; 17 | System.Object[] psobj = null; 18 | #endregion 19 | 20 | #region Public Methods 21 | 22 | public PSObjectGrid(System.Object[] CustomObject) 23 | { 24 | psobj = CustomObject; 25 | Init(); 26 | } 27 | 28 | public void Export(object sender, EventArgs e) 29 | { 30 | String expfilter = StringValue.ExportFormats; 31 | SaveFileDialog dlgExport = new SaveFileDialog(); 32 | dlgExport.Filter = expfilter; 33 | dlgExport.CheckFileExists = false; 34 | dlgExport.CheckPathExists = true; 35 | dlgExport.Title = "Export As..."; 36 | if (dlgExport.ShowDialog() == DialogResult.OK) 37 | { 38 | ExportObject((EnumValues.FilterType)dlgExport.FilterIndex, dlgExport.FileName); 39 | } 40 | dlgExport.Dispose(); 41 | dlgExport = null; 42 | } 43 | #endregion 44 | 45 | #region Private Methods 46 | private void Init() 47 | { 48 | this.Dock = DockStyle.Fill; 49 | this.View = System.Windows.Forms.View.Details; 50 | this.FullRowSelect = true; 51 | BuildGrid(); 52 | } 53 | 54 | private void AddButtons() 55 | { 56 | if (parstrip != null) 57 | { 58 | ToolStripButton exp = new ToolStripButton(); 59 | exp.Text = "Export"; 60 | exp.Image = Properties.Resources.table_save; 61 | exp.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; 62 | exp.ToolTipText = "Export Grid Data"; 63 | exp.Alignment = ToolStripItemAlignment.Left; 64 | exp.Click += new EventHandler(Export); 65 | parstrip.Items.Add(exp); 66 | } 67 | } 68 | 69 | private void BuildGrid() 70 | { 71 | if (psobj != null && psobj.Count() > 0) 72 | { 73 | CreateHeaders(psobj[0]); 74 | if (psobj[0].GetType() == typeof(PSObject)) 75 | { 76 | foreach (PSObject pobj in psobj) 77 | { 78 | ListViewItem lvw = new ListViewItem(); 79 | int sidx = -1; 80 | foreach (PSPropertyInfo prop in pobj.Properties) 81 | { 82 | sidx++; 83 | if (prop != null) 84 | { 85 | if (sidx == 0) 86 | { 87 | try 88 | { 89 | lvw.Text = (prop.Value ?? "").ToString(); 90 | } 91 | catch (GetValueException) 92 | { 93 | lvw.Text = ""; 94 | } 95 | 96 | } 97 | else 98 | { 99 | try 100 | { 101 | lvw.SubItems.Add((prop.Value ?? "").ToString()); 102 | } 103 | catch (GetValueInvocationException) 104 | { 105 | lvw.SubItems.Add(""); 106 | } 107 | 108 | } 109 | } 110 | } 111 | this.Items.Add(lvw); 112 | } 113 | } 114 | } 115 | } 116 | 117 | private void CreateHeaders(Object pobj) 118 | { 119 | if (pobj.GetType() == typeof(PSObject)) 120 | { 121 | PSObject p = (PSObject)pobj; 122 | foreach (PSPropertyInfo prop in p.Properties) 123 | { 124 | ColumnHeader col = new ColumnHeader(); 125 | col.Text = prop.Name; 126 | col.Width = -2; 127 | this.Columns.Add(col); 128 | } 129 | } 130 | } 131 | 132 | private void ExportObject(EnumValues.FilterType type, String filename) 133 | { 134 | if (psobj != null && psobj.Count() > 0) 135 | { 136 | Utility.ExportObject exobj = new Utility.ExportObject(); 137 | switch (type) 138 | { 139 | case EnumValues.FilterType.XML: 140 | exobj.XML(psobj, filename); 141 | break; 142 | case EnumValues.FilterType.CSV: 143 | exobj.CSV(psobj, filename); 144 | break; 145 | case EnumValues.FilterType.TXT: 146 | exobj.TXT(psobj, filename); 147 | break; 148 | } 149 | exobj = null; 150 | } 151 | } 152 | #endregion 153 | 154 | #region Public Properties 155 | public ToolStrip ParentStrip 156 | { 157 | set 158 | { 159 | parstrip = value; 160 | AddButtons(); 161 | } 162 | } 163 | #endregion 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /poshsecframework/Controls/PSTabItem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections.ObjectModel; 4 | using System.Linq; 5 | using System.Management.Automation; 6 | using System.Text; 7 | using System.Windows.Forms; 8 | 9 | namespace PoshSec.Framework.Controls 10 | { 11 | public class PSTabItem : TabPage 12 | { 13 | #region Private Variables 14 | private ToolStrip tbTools = new ToolStrip(); 15 | #endregion 16 | 17 | #region Private Methods 18 | #endregion 19 | 20 | #region Public Methods 21 | public PSTabItem() 22 | { 23 | tbTools.Dock = DockStyle.Top; 24 | tbTools.GripStyle = ToolStripGripStyle.Hidden; 25 | ToolStripButton tbClose = new ToolStripButton(); 26 | tbClose.Text = "Close"; 27 | tbClose.Image = Properties.Resources.tabclose3; 28 | tbClose.ImageAlign = System.Drawing.ContentAlignment.MiddleRight; 29 | tbClose.ToolTipText = "Close Tab"; 30 | tbClose.Alignment = ToolStripItemAlignment.Right; 31 | tbClose.Click += new EventHandler(CloseTab); 32 | tbTools.Items.Add(tbClose); 33 | this.Controls.Add(tbTools); 34 | } 35 | 36 | public void AddGrid(System.Object[] CustomObject) 37 | { 38 | PSObjectGrid pgrid = new PSObjectGrid(CustomObject); 39 | pgrid.ParentStrip = tbTools; 40 | this.Controls.Add(pgrid); 41 | this.Controls.SetChildIndex(pgrid, 0); 42 | } 43 | 44 | public void AddText(String Text) 45 | { 46 | PSTextBox txt = new PSTextBox(); 47 | txt.Text = Text; 48 | txt.ParentStrip = tbTools; 49 | this.Controls.Add(txt); 50 | this.Controls.SetChildIndex(txt, 0); 51 | } 52 | 53 | public PSAlertList CreateAlertTab(string scriptname) 54 | { 55 | PSAlertList psal = new PSAlertList(scriptname, this); 56 | psal.ParentStrip = tbTools; 57 | this.Controls.Add(psal); 58 | this.Controls.SetChildIndex(psal, 0); 59 | return psal; 60 | } 61 | #endregion 62 | 63 | #region Private Events 64 | private void CloseTab(object sender, EventArgs e) 65 | { 66 | if (this.Parent.GetType() == typeof(TabControl)) 67 | { 68 | TabControl parent = (TabControl)this.Parent; 69 | if (parent != null) 70 | { 71 | parent.TabPages.Remove(this); 72 | } 73 | } 74 | } 75 | #endregion 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /poshsecframework/Controls/PSTabItem.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | False 122 | 123 | -------------------------------------------------------------------------------- /poshsecframework/Controls/PSTextBox.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows.Forms; 7 | 8 | namespace PoshSec.Framework.Controls 9 | { 10 | class PSTextBox : TextBox 11 | { 12 | #region Private Variables 13 | private ToolStrip parstrip = null; 14 | #endregion 15 | 16 | #region Public Methods 17 | public PSTextBox() 18 | { 19 | Init(); 20 | } 21 | #endregion 22 | 23 | #region Private Methods 24 | private void Init() 25 | { 26 | this.Dock = DockStyle.Fill; 27 | this.Multiline = true; 28 | this.ScrollBars = System.Windows.Forms.ScrollBars.Both; 29 | this.Font = new System.Drawing.Font("Lucida Console", (float)9.75); 30 | AddButtons(); 31 | } 32 | 33 | private void AddButtons() 34 | { 35 | if (parstrip != null) 36 | { 37 | ToolStripButton exp = new ToolStripButton(); 38 | exp.Text = "Save"; 39 | exp.Image = Properties.Resources.table_save; 40 | exp.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; 41 | exp.ToolTipText = "Save"; 42 | exp.Alignment = ToolStripItemAlignment.Left; 43 | exp.Click += new EventHandler(Save); 44 | parstrip.Items.Add(exp); 45 | } 46 | } 47 | 48 | private void Save(object sender, EventArgs e) 49 | { 50 | SaveFileDialog sdlg = new SaveFileDialog(); 51 | sdlg.CheckPathExists = true; 52 | sdlg.Title = "Save As..."; 53 | sdlg.Filter = "Text Document (*.txt)|*.txt|All Documents (*.*)|*.*"; 54 | if (sdlg.ShowDialog() == DialogResult.OK) 55 | { 56 | System.IO.StreamWriter wtr = System.IO.File.CreateText(sdlg.FileName); 57 | wtr.Write(this.Text); 58 | wtr.Flush(); 59 | wtr.Close(); 60 | MessageBox.Show(Strings.StringValue.FileSavedSuccessfully); 61 | } 62 | } 63 | #endregion 64 | 65 | #region Public Properties 66 | public ToolStrip ParentStrip 67 | { 68 | set 69 | { 70 | parstrip = value; 71 | AddButtons(); 72 | } 73 | } 74 | #endregion 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /poshsecframework/Controls/RichTextBoxCaret.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Drawing; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Windows.Forms; 7 | using System.Runtime.InteropServices; 8 | 9 | namespace PoshSec.Framework.Controls 10 | { 11 | class RichTextBoxCaret : RichTextBox 12 | { 13 | [DllImport("user32.dll")] 14 | static extern bool CreateCaret(IntPtr hWnd, IntPtr hBitmap, int nWidth, int nHeight); 15 | [DllImport("user32.dll")] 16 | static extern bool ShowCaret(IntPtr hWnd); 17 | IntPtr caret; 18 | int tbidx = 0; 19 | bool filter = true; 20 | List cmds = null; 21 | List acmds = null; 22 | int cmdstart = 0; 23 | int cmdstop = 0; 24 | const int WM_USER = 0x0400; 25 | const int WM_NOTIFY = 0x004E; 26 | const int WM_REFLECT = WM_USER + 0x1C00; 27 | const int WM_PAINT = 0xF; 28 | 29 | public RichTextBoxCaret() 30 | { 31 | InitializeComponent(); 32 | Bitmap bmp = Properties.Resources.caret_underline; 33 | caret = bmp.GetHbitmap(Color.White); 34 | } 35 | 36 | private void InitializeComponent() 37 | { 38 | this.KeyDown += this_KeyDown; 39 | } 40 | 41 | protected override void OnMouseDown(MouseEventArgs e) 42 | { 43 | base.OnMouseDown(e); 44 | DrawCaret(); 45 | } 46 | 47 | protected override void WndProc(ref Message m) 48 | { 49 | base.WndProc(ref m); 50 | 51 | if ((m.Msg == (WM_REFLECT + WM_NOTIFY)) || (m.Msg == WM_PAINT)) 52 | { 53 | DrawCaret(); 54 | } 55 | } 56 | 57 | private void this_KeyDown(object sender, KeyEventArgs e) 58 | { 59 | if (e.KeyCode == Keys.Tab) 60 | { 61 | e.Handled = true; 62 | e.SuppressKeyPress = true; 63 | if (cmds != null) 64 | { 65 | AutoComplete(); 66 | } 67 | } 68 | else if (!e.Control && !e.Shift && !e.Alt) 69 | { 70 | tbidx = 0; 71 | filter = true; 72 | } 73 | } 74 | 75 | private void AutoComplete() 76 | { 77 | String cmdtxt = ""; 78 | if (filter) 79 | { 80 | if (acmds != null && acmds.Count > 0) 81 | { 82 | acmds.Clear(); 83 | } 84 | cmdstart = this.Text.LastIndexOf(' ', this.SelectionStart - 1) + 1; 85 | cmdstop = this.SelectionStart; 86 | cmdtxt = this.Text.Substring(cmdstart, cmdstop - cmdstart); 87 | if (cmdtxt != "") 88 | { 89 | acmds = cmds.Where(cmd => cmd.StartsWith(cmdtxt, StringComparison.OrdinalIgnoreCase)).ToList(); 90 | filter = false; 91 | } 92 | } 93 | if (acmds != null && acmds.Count > 0) 94 | { 95 | this.Text = this.Text.Substring(0, cmdstart); 96 | this.Text += acmds[tbidx]; 97 | this.SelectionStart = this.Text.Length; 98 | tbidx++; 99 | if (tbidx >= acmds.Count) 100 | { 101 | tbidx = 0; 102 | } 103 | } 104 | } 105 | 106 | protected override bool IsInputKey(Keys keyData) 107 | { 108 | switch (keyData) 109 | { 110 | case Keys.Tab: 111 | return true; 112 | default: 113 | return base.IsInputKey(keyData); 114 | } 115 | } 116 | 117 | public void DrawCaret() 118 | { 119 | try 120 | { 121 | CreateCaret(this.Handle, caret, 8, 13); 122 | ShowCaret(this.Handle); 123 | } 124 | catch (Exception) 125 | { 126 | //fail silently 127 | } 128 | } 129 | 130 | public List AutoCompleteCommands 131 | { 132 | set { cmds = value; } 133 | } 134 | 135 | public int CurrentColumn 136 | { 137 | get { return this.SelectionStart - this.GetFirstCharIndexOfCurrentLine() + 1; } 138 | } 139 | 140 | public int CurrentLine 141 | { 142 | get { return this.GetLineFromCharIndex(this.SelectionStart) + 1; } 143 | } 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /poshsecframework/Enums/EnumValues.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace PoshSec.Framework.Enums 7 | { 8 | public static class EnumValues 9 | { 10 | public enum RunAs 11 | { 12 | CurrentUser = 0, 13 | DifferentUser 14 | } 15 | 16 | public enum TimeFrequency 17 | { 18 | Once = 0, 19 | Daily, 20 | Weekly, 21 | Monthly 22 | } 23 | 24 | public enum FilterType 25 | { 26 | XML = 1, 27 | CSV, 28 | TXT 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /poshsecframework/Events/ScheduleEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace PoshSec.Framework.Utility 7 | { 8 | public class ScheduleEventArgs : EventArgs 9 | { 10 | private ScheduleItem sched; 11 | 12 | public ScheduleEventArgs(ScheduleItem schedule) 13 | { 14 | sched = schedule; 15 | } 16 | 17 | public ScheduleItem Schedule 18 | { 19 | get { return sched; } 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /poshsecframework/Events/WriteEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace PoshSec.Framework.Events 8 | { 9 | class WriteEventArgs: EventArgs 10 | { 11 | String message = ""; 12 | 13 | public WriteEventArgs(String Message) 14 | { 15 | message = Message; 16 | } 17 | 18 | public String Message 19 | { 20 | get { return message; } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /poshsecframework/Events/WriteProgressEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace PoshSec.Framework.Events 8 | { 9 | class WriteProgressEventArgs : EventArgs 10 | { 11 | System.Management.Automation.ProgressRecord record = null; 12 | 13 | public WriteProgressEventArgs(System.Management.Automation.ProgressRecord Record) 14 | { 15 | record = Record; 16 | } 17 | 18 | public System.Management.Automation.ProgressRecord ProgressRecord 19 | { 20 | get { return record; } 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /poshsecframework/Extensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace PoshSec.Framework 9 | { 10 | public static class Extensions 11 | { 12 | public static void Clear(this ConcurrentBag bag) 13 | { 14 | while (!bag.IsEmpty) 15 | { 16 | bag.TryTake(out T item); 17 | } 18 | } 19 | 20 | public static void AddRange(this ConcurrentBag bag, IEnumerable items) 21 | { 22 | foreach (var item in items) 23 | { 24 | bag.Add(item); 25 | } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /poshsecframework/FirstTimeSetup/Steps.cs: -------------------------------------------------------------------------------- 1 | namespace PoshSec.Framework.FirstTimeSetup 2 | { 3 | public enum Steps 4 | { 5 | Check_Settings = 0, 6 | InitialDownload, 7 | Unblock_Files, 8 | Update_Help, 9 | Set_Execution_Policy 10 | } 11 | } -------------------------------------------------------------------------------- /poshsecframework/Images/psficon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Images/psficon.ico -------------------------------------------------------------------------------- /poshsecframework/Images/psficon_alert.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Images/psficon_alert.ico -------------------------------------------------------------------------------- /poshsecframework/Interface/ProxyPreference.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace PoshSec.Framework 8 | { 9 | public enum ProxyPreference 10 | { 11 | System, 12 | None, 13 | Manual 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /poshsecframework/Interface/ProxyPreferenceGroupBox.Designer.cs: -------------------------------------------------------------------------------- 1 |  -------------------------------------------------------------------------------- /poshsecframework/Interface/ProxyPreferenceGroupBox.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows.Forms; 7 | 8 | namespace PoshSec.Framework.Interface 9 | { 10 | public class ProxyPreferenceGroupBox : GroupBox 11 | { 12 | public event EventHandler SelectedChanged = delegate { }; 13 | 14 | ProxyPreference _selected; 15 | 16 | public ProxyPreference Selected 17 | { 18 | get 19 | { 20 | return _selected; 21 | } 22 | set 23 | { 24 | ProxyPreference val = ProxyPreference.System; 25 | var radioButton = Controls.OfType() 26 | .FirstOrDefault(radio => 27 | radio.Tag != null 28 | && Enum.TryParse(radio.Tag.ToString(), out val) && val == value); 29 | 30 | if (radioButton != null) 31 | { 32 | radioButton.Checked = true; 33 | _selected = val; 34 | } 35 | } 36 | } 37 | 38 | protected override void OnControlAdded(ControlEventArgs e) 39 | { 40 | base.OnControlAdded(e); 41 | 42 | if (e.Control is RadioButton radioButton) 43 | radioButton.CheckedChanged += RadioButton_CheckedChanged; 44 | } 45 | 46 | void RadioButton_CheckedChanged(object sender, EventArgs e) 47 | { 48 | var radio = (RadioButton)sender; 49 | if (radio.Checked && radio.Tag != null 50 | && Enum.TryParse(radio.Tag.ToString(), out ProxyPreference val)) 51 | { 52 | _selected = val; 53 | SelectedChanged(this, new EventArgs()); 54 | } 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /poshsecframework/Interface/SystemForm.cs: -------------------------------------------------------------------------------- 1 | using System.Windows.Forms; 2 | 3 | namespace PoshSec.Framework.Interface 4 | { 5 | public partial class SystemForm : Form 6 | { 7 | public SystemForm() 8 | { 9 | InitializeComponent(); 10 | } 11 | 12 | public string SystemName 13 | { 14 | get => txbSystemName.Text; 15 | set => txbSystemName.Text = value; 16 | } 17 | 18 | public string IpAddress 19 | { 20 | get => txbIpAddress.Text; 21 | set => txbIpAddress.Text = value; 22 | } 23 | 24 | public string Description 25 | { 26 | get => txbDescription.Text; 27 | set => txbDescription.Text = value; 28 | } 29 | 30 | private void btnOK_Click(object sender, System.EventArgs e) 31 | { 32 | DialogResult = DialogResult.OK; 33 | Close(); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /poshsecframework/Interface/SystemForm.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /poshsecframework/Interface/frmAddNetwork.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using System.Windows.Forms; 10 | 11 | namespace PoshSec.Framework.Interface 12 | { 13 | public partial class frmAddNetwork : Form 14 | { 15 | private string networkname = ""; 16 | 17 | public frmAddNetwork() 18 | { 19 | InitializeComponent(); 20 | } 21 | 22 | public string NetworkName 23 | { 24 | get { return networkname; } 25 | } 26 | 27 | private void btnOK_Click(object sender, EventArgs e) 28 | { 29 | CheckName(); 30 | } 31 | 32 | private void CheckName() 33 | { 34 | if (txtNetworkName.Text.Trim() != "" && txtNetworkName.Text.Trim() != Strings.StringValue.LocalNetwork) 35 | { 36 | networkname = txtNetworkName.Text.Trim(); 37 | this.DialogResult = System.Windows.Forms.DialogResult.OK; 38 | this.Close(); 39 | } 40 | else 41 | { 42 | MessageBox.Show(Strings.StringValue.InvalidNetworkName); 43 | } 44 | } 45 | 46 | private void txtNetworkName_KeyDown(object sender, KeyEventArgs e) 47 | { 48 | if (e.KeyCode == Keys.Enter) 49 | { 50 | e.Handled = true; 51 | CheckName(); 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /poshsecframework/Interface/frmAddNetwork.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /poshsecframework/Interface/frmNetworkBrowser.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.ObjectModel; 3 | using System.DirectoryServices; 4 | using System.DirectoryServices.ActiveDirectory; 5 | using System.Linq; 6 | using System.Management.Automation; 7 | using System.Threading; 8 | using System.Threading.Tasks; 9 | using System.Windows.Forms; 10 | using PoshSec.Framework.Properties; 11 | using PoshSec.Framework.Strings; 12 | 13 | namespace PoshSec.Framework.Interface 14 | { 15 | public partial class frmNetworkBrowser : Form 16 | { 17 | private readonly Networks _networks = new Networks(); 18 | private readonly Collection _hosts = new Collection(); 19 | 20 | 21 | public frmNetworkBrowser() 22 | { 23 | InitializeComponent(); 24 | LoadNetworks(); 25 | ListSystems(); 26 | } 27 | 28 | private void NetworkBrowserScanComplete(object sender, NetworkScanCompleteEventArgs e) 29 | { 30 | if (InvokeRequired) 31 | { 32 | MethodInvoker del = delegate { NetworkBrowserScanComplete(sender, e); }; 33 | Invoke(del); 34 | } 35 | else 36 | { 37 | 38 | var systems = e.Network.Nodes; 39 | _lvwSystems.Load(systems); 40 | _lvwSystems.Sorting = SortOrder.Ascending; 41 | _lvwSystems.Sort(); 42 | 43 | EnableControls(); 44 | } 45 | } 46 | 47 | private void NetworkBrowserScanCancelled(object sender, EventArgs e) 48 | { 49 | EnableControls(); 50 | } 51 | 52 | private void cmbNetworks_SelectedIndexChanged(object sender, EventArgs e) 53 | { 54 | cmbNetworks.Enabled = false; 55 | btnRefresh.Enabled = false; 56 | btnOK.Enabled = false; 57 | btnCancel.Enabled = false; 58 | var selectedItem = cmbNetworks.SelectedItem; 59 | Scan((Network)selectedItem); 60 | } 61 | 62 | private void btnOK_Click(object sender, EventArgs e) 63 | { 64 | if (_lvwSystems.CheckedItems.Count > 0) 65 | { 66 | var lvwitms = _lvwSystems.CheckedItems; 67 | foreach (ListViewItem lvw in lvwitms) 68 | { 69 | var pobj = new PSObject(); 70 | var idx = -1; 71 | foreach (ColumnHeader col in _lvwSystems.Columns) 72 | { 73 | idx++; 74 | pobj.Properties.Add(new PSNoteProperty(col.Text.Replace(" ", "_"), lvw.SubItems[idx].Text)); 75 | } 76 | 77 | _hosts.Add(pobj); 78 | } 79 | 80 | DialogResult = DialogResult.OK; 81 | Close(); 82 | } 83 | else 84 | { 85 | MessageBox.Show(StringValue.SelectSystems); 86 | } 87 | } 88 | 89 | private void LoadNetworks() 90 | { 91 | cmbNetworks.Items.Clear(); 92 | cmbNetworks.Items.Add(StringValue.LocalNetwork); 93 | try 94 | { 95 | //Get Domain Name 96 | var hostForest = Forest.GetCurrentForest(); 97 | var domains = hostForest.Domains; 98 | 99 | foreach (Domain domain in domains) 100 | { 101 | var network = new DomainNetwork(domain.Name); 102 | cmbNetworks.Items.Add(domain); 103 | } 104 | } 105 | catch 106 | { 107 | //fail silently because it's not on A/D 108 | } 109 | } 110 | 111 | private void ListSystems() 112 | { 113 | if (Settings.Default.Systems != null && Settings.Default.Systems.Count > 0) 114 | { 115 | _lvwSystems.Items.Clear(); 116 | foreach (var system in Settings.Default.Systems) 117 | { 118 | var systemparts = system.Split('|'); 119 | var lvwItm = new ListViewItem(); 120 | lvwItm.Text = systemparts[0]; 121 | lvwItm.SubItems.Add(systemparts[1]); 122 | lvwItm.SubItems.Add(systemparts[2]); 123 | lvwItm.SubItems.Add(systemparts[4]); 124 | lvwItm.ImageIndex = 2; 125 | _lvwSystems.Items.Add(lvwItm); 126 | } 127 | } 128 | } 129 | 130 | private void EnableControls() 131 | { 132 | if (InvokeRequired) 133 | { 134 | MethodInvoker del = delegate { EnableControls(); }; 135 | Invoke(del); 136 | } 137 | else 138 | { 139 | _lvwSystems.UseWaitCursor = false; 140 | cmbNetworks.Enabled = true; 141 | btnRefresh.Enabled = true; 142 | btnOK.Enabled = true; 143 | btnCancel.Enabled = true; 144 | } 145 | } 146 | 147 | private void Scan(Network network) 148 | { 149 | _lvwSystems.UseWaitCursor = true; 150 | 151 | Task.Run(() => 152 | { 153 | var networkBrowser = new NetworkBrowser(network); 154 | networkBrowser.NetworkScanComplete += NetworkBrowserScanComplete; 155 | networkBrowser.NetworkScanCancelled += NetworkBrowserScanCancelled; 156 | networkBrowser.ScanAsync().ContinueWith(t => 157 | { 158 | networkBrowser.NetworkScanComplete -= NetworkBrowserScanComplete; 159 | networkBrowser.NetworkScanCancelled -= NetworkBrowserScanCancelled; 160 | }); 161 | }); 162 | } 163 | 164 | public string SerializedHosts => PSSerializer.Serialize(_hosts); 165 | } 166 | } -------------------------------------------------------------------------------- /poshsecframework/Interface/frmParams.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace PoshSec.Framework.Interface 2 | { 3 | partial class frmParams 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.panel1 = new System.Windows.Forms.Panel(); 32 | this.btnRun = new System.Windows.Forms.Button(); 33 | this.btnCancel = new System.Windows.Forms.Button(); 34 | this.pgParams = new System.Windows.Forms.PropertyGrid(); 35 | this.panel1.SuspendLayout(); 36 | this.SuspendLayout(); 37 | // 38 | // panel1 39 | // 40 | this.panel1.Controls.Add(this.btnRun); 41 | this.panel1.Controls.Add(this.btnCancel); 42 | this.panel1.Dock = System.Windows.Forms.DockStyle.Bottom; 43 | this.panel1.Location = new System.Drawing.Point(0, 273); 44 | this.panel1.Name = "panel1"; 45 | this.panel1.Size = new System.Drawing.Size(314, 37); 46 | this.panel1.TabIndex = 0; 47 | // 48 | // btnRun 49 | // 50 | this.btnRun.Location = new System.Drawing.Point(155, 8); 51 | this.btnRun.Name = "btnRun"; 52 | this.btnRun.Size = new System.Drawing.Size(75, 23); 53 | this.btnRun.TabIndex = 1; 54 | this.btnRun.Text = "&Run"; 55 | this.btnRun.UseVisualStyleBackColor = true; 56 | this.btnRun.Click += new System.EventHandler(this.btnOK_Click); 57 | // 58 | // btnCancel 59 | // 60 | this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; 61 | this.btnCancel.Location = new System.Drawing.Point(236, 8); 62 | this.btnCancel.Name = "btnCancel"; 63 | this.btnCancel.Size = new System.Drawing.Size(75, 23); 64 | this.btnCancel.TabIndex = 0; 65 | this.btnCancel.Text = "&Cancel"; 66 | this.btnCancel.UseVisualStyleBackColor = true; 67 | // 68 | // pgParams 69 | // 70 | this.pgParams.CommandsVisibleIfAvailable = false; 71 | this.pgParams.Dock = System.Windows.Forms.DockStyle.Fill; 72 | this.pgParams.Location = new System.Drawing.Point(0, 0); 73 | this.pgParams.Name = "pgParams"; 74 | this.pgParams.Size = new System.Drawing.Size(314, 273); 75 | this.pgParams.TabIndex = 1; 76 | this.pgParams.ToolbarVisible = false; 77 | // 78 | // frmParams 79 | // 80 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 81 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 82 | this.CancelButton = this.btnCancel; 83 | this.ClientSize = new System.Drawing.Size(314, 310); 84 | this.Controls.Add(this.pgParams); 85 | this.Controls.Add(this.panel1); 86 | this.Font = new System.Drawing.Font("Tahoma", 8.25F); 87 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; 88 | this.MaximizeBox = false; 89 | this.MinimizeBox = false; 90 | this.Name = "frmParams"; 91 | this.ShowIcon = false; 92 | this.ShowInTaskbar = false; 93 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; 94 | this.panel1.ResumeLayout(false); 95 | this.ResumeLayout(false); 96 | 97 | } 98 | 99 | #endregion 100 | 101 | private System.Windows.Forms.Panel panel1; 102 | private System.Windows.Forms.PropertyGrid pgParams; 103 | private System.Windows.Forms.Button btnRun; 104 | private System.Windows.Forms.Button btnCancel; 105 | 106 | } 107 | } -------------------------------------------------------------------------------- /poshsecframework/Interface/frmParams.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Windows.Forms; 9 | using PoshSec.Framework.Strings; 10 | 11 | namespace PoshSec.Framework.Interface 12 | { 13 | public partial class frmParams : Form 14 | { 15 | private DialogResult _frmresult = DialogResult.Cancel; 16 | 17 | public frmParams() 18 | { 19 | InitializeComponent(); 20 | } 21 | 22 | public void ShowFromThread() 23 | { 24 | _frmresult = this.ShowDialog(); 25 | } 26 | 27 | public void SetParameters(PShell.psparamtype p) 28 | { 29 | pgParams.SelectedObject = p; 30 | } 31 | 32 | public DialogResult FormCloseResult 33 | { 34 | get { return _frmresult; } 35 | } 36 | 37 | private void btnOK_Click(object sender, EventArgs e) 38 | { 39 | bool hasrequired = true; 40 | PShell.psparamtype p = (PShell.psparamtype)pgParams.SelectedObject; 41 | foreach (PShell.psparameter parm in p.Properties) 42 | { 43 | if (parm.Category == "Required" && parm.Value == null && parm.DefaultValue == null) 44 | { 45 | hasrequired = false; 46 | } 47 | } 48 | 49 | if (hasrequired) 50 | { 51 | this.DialogResult = System.Windows.Forms.DialogResult.OK; 52 | this.Close(); 53 | } 54 | else 55 | { 56 | MessageBox.Show(StringValue.RequireParams); 57 | } 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /poshsecframework/Interface/frmParams.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /poshsecframework/Interface/frmRepository.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 17, 17 122 | 123 | 124 | 37 125 | 126 | -------------------------------------------------------------------------------- /poshsecframework/Interface/frmScan.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Forms; 3 | using PoshSec.Framework.Strings; 4 | 5 | namespace PoshSec.Framework 6 | { 7 | public partial class frmScan : Form 8 | { 9 | public frmScan() 10 | { 11 | InitializeComponent(); 12 | } 13 | 14 | private void btnOK_Click(object sender, EventArgs e) 15 | { 16 | if (cmbIPs.Text.Trim() != "") 17 | { 18 | SelectedIP = cmbIPs.Text; 19 | DialogResult = DialogResult.OK; 20 | Close(); 21 | } 22 | else 23 | { 24 | MessageBox.Show(StringValue.SelectIPScan); 25 | } 26 | } 27 | 28 | private string[] ips; 29 | 30 | public string[] IPs 31 | { 32 | set 33 | { 34 | ips = value; 35 | if (ips != null && ips.Length > 0) 36 | { 37 | cmbIPs.Items.Clear(); 38 | foreach (var ip in ips) cmbIPs.Items.Add(ip); 39 | cmbIPs.SelectedIndex = 0; 40 | } 41 | } 42 | } 43 | 44 | public string SelectedIP { get; private set; } 45 | } 46 | } -------------------------------------------------------------------------------- /poshsecframework/Interface/frmScan.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /poshsecframework/Interface/frmSchedule.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Windows.Forms; 9 | using PoshSec.Framework.Utility; 10 | 11 | namespace PoshSec.Framework.Interface 12 | { 13 | public partial class frmSchedule : Form 14 | { 15 | #region Private Variables 16 | private ScheduleTime schedtime = new ScheduleTime(); 17 | #endregion 18 | 19 | #region Public Methods 20 | public frmSchedule() 21 | { 22 | InitializeComponent(); 23 | schedtime.Frequency = Enums.EnumValues.TimeFrequency.Once; 24 | schedtime.StartTime = datStartTime.Value; 25 | schedtime.StartDate = datStartDate.Value; 26 | } 27 | #endregion 28 | 29 | #region Private Events 30 | private void optOnce_CheckedChanged(object sender, EventArgs e) 31 | { 32 | tcSettings.SelectedTab = tbDaily; 33 | schedtime.Frequency = Enums.EnumValues.TimeFrequency.Once; 34 | } 35 | 36 | private void optDaily_CheckedChanged(object sender, EventArgs e) 37 | { 38 | tcSettings.SelectedTab = tbDaily; 39 | schedtime.Frequency = Enums.EnumValues.TimeFrequency.Daily; 40 | } 41 | 42 | private void optWeekly_CheckedChanged(object sender, EventArgs e) 43 | { 44 | tcSettings.SelectedTab = tbWeekly; 45 | schedtime.Frequency = Enums.EnumValues.TimeFrequency.Weekly; 46 | } 47 | 48 | private void optMonthly_CheckedChanged(object sender, EventArgs e) 49 | { 50 | tcSettings.SelectedTab = tbMonthly; 51 | schedtime.Frequency = Enums.EnumValues.TimeFrequency.Monthly; 52 | } 53 | 54 | private void datStartTime_ValueChanged(object sender, EventArgs e) 55 | { 56 | schedtime.StartTime = datStartTime.Value; 57 | } 58 | 59 | private void datStartDate_ValueChanged(object sender, EventArgs e) 60 | { 61 | schedtime.StartDate = datStartDate.Value; 62 | } 63 | 64 | private void btnSave_Click(object sender, EventArgs e) 65 | { 66 | bool save = false; 67 | switch (schedtime.Frequency) 68 | { 69 | case Enums.EnumValues.TimeFrequency.Daily: case Enums.EnumValues.TimeFrequency.Once: 70 | save = true; 71 | break; 72 | case Enums.EnumValues.TimeFrequency.Weekly: 73 | if (lstDays.CheckedItems.Count > 0) 74 | { 75 | List daysofweek = new List(); 76 | foreach (int idx in lstDays.CheckedIndices) 77 | { 78 | daysofweek.Add(idx); 79 | } 80 | schedtime.DaysofWeek = daysofweek; 81 | save = true; 82 | } 83 | else 84 | { 85 | MessageBox.Show(Strings.StringValue.SelectWeekdays); 86 | } 87 | break; 88 | case Enums.EnumValues.TimeFrequency.Monthly: 89 | if (lstMonths.CheckedItems.Count > 0 && lstDates.CheckedItems.Count > 0) 90 | { 91 | List mons = new List(); 92 | List dates = new List(); 93 | foreach (int idx in lstMonths.CheckedIndices) 94 | { 95 | mons.Add(idx + 1); 96 | } 97 | foreach (int idx in lstDates.CheckedIndices) 98 | { 99 | dates.Add(idx + 1); 100 | } 101 | schedtime.Months = mons; 102 | schedtime.Dates = dates; 103 | save = true; 104 | } 105 | else 106 | { 107 | MessageBox.Show(Strings.StringValue.SelectMonths); 108 | } 109 | break; 110 | } 111 | if (save) 112 | { 113 | this.DialogResult = System.Windows.Forms.DialogResult.OK; 114 | this.Close(); 115 | } 116 | } 117 | #endregion 118 | 119 | #region Public Properties 120 | public ScheduleTime ScheduledTime 121 | { 122 | get { return this.schedtime; } 123 | } 124 | #endregion 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /poshsecframework/Interface/frmSchedule.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /poshsecframework/Interface/frmStartup.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace PoshSec.Framework.Interface 2 | { 3 | partial class frmStartup 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.pictureBox1 = new System.Windows.Forms.PictureBox(); 32 | this.lblStatus = new System.Windows.Forms.Label(); 33 | ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); 34 | this.SuspendLayout(); 35 | // 36 | // pictureBox1 37 | // 38 | this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; 39 | this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Top; 40 | this.pictureBox1.Image = global::PoshSec.Framework.Properties.Resources.psf_logo_rev1; 41 | this.pictureBox1.Location = new System.Drawing.Point(0, 0); 42 | this.pictureBox1.Name = "pictureBox1"; 43 | this.pictureBox1.Size = new System.Drawing.Size(527, 329); 44 | this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage; 45 | this.pictureBox1.TabIndex = 1; 46 | this.pictureBox1.TabStop = false; 47 | // 48 | // lblStatus 49 | // 50 | this.lblStatus.BackColor = System.Drawing.Color.White; 51 | this.lblStatus.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; 52 | this.lblStatus.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 53 | this.lblStatus.Location = new System.Drawing.Point(137, 333); 54 | this.lblStatus.Name = "lblStatus"; 55 | this.lblStatus.Size = new System.Drawing.Size(252, 21); 56 | this.lblStatus.TabIndex = 2; 57 | this.lblStatus.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; 58 | // 59 | // frmStartup 60 | // 61 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 62 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 63 | this.BackColor = System.Drawing.Color.Black; 64 | this.ClientSize = new System.Drawing.Size(527, 359); 65 | this.ControlBox = false; 66 | this.Controls.Add(this.lblStatus); 67 | this.Controls.Add(this.pictureBox1); 68 | this.Font = new System.Drawing.Font("Tahoma", 8.25F); 69 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; 70 | this.MaximizeBox = false; 71 | this.MinimizeBox = false; 72 | this.Name = "frmStartup"; 73 | this.ShowIcon = false; 74 | this.ShowInTaskbar = false; 75 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; 76 | this.Text = "PoshSec Framework - Loading"; 77 | this.TopMost = true; 78 | ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); 79 | this.ResumeLayout(false); 80 | 81 | } 82 | 83 | #endregion 84 | 85 | private System.Windows.Forms.PictureBox pictureBox1; 86 | private System.Windows.Forms.Label lblStatus; 87 | 88 | } 89 | } -------------------------------------------------------------------------------- /poshsecframework/Interface/frmStartup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Windows.Forms; 9 | 10 | namespace PoshSec.Framework.Interface 11 | { 12 | public partial class frmStartup : Form 13 | { 14 | public frmStartup() 15 | { 16 | InitializeComponent(); 17 | } 18 | 19 | public void SetStatus(String message) 20 | { 21 | if (this.InvokeRequired) 22 | { 23 | MethodInvoker del = delegate 24 | { 25 | SetStatus(message); 26 | }; 27 | this.Invoke(del); 28 | } 29 | else 30 | { 31 | lblStatus.Text = message; 32 | lblStatus.Refresh(); 33 | } 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /poshsecframework/Interface/frmStartup.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /poshsecframework/Network/NetworkScanCompleteEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | 4 | namespace PoshSec.Framework 5 | { 6 | public class NetworkScanCompleteEventArgs : EventArgs 7 | { 8 | public NetworkScanCompleteEventArgs(Network network) 9 | { 10 | Network = network; 11 | } 12 | 13 | public Network Network { get; set; } 14 | } 15 | } -------------------------------------------------------------------------------- /poshsecframework/Network/NetworkType.cs: -------------------------------------------------------------------------------- 1 | namespace PoshSec.Framework 2 | { 3 | public enum NetworkType 4 | { 5 | Local = 1, 6 | Domain 7 | } 8 | } -------------------------------------------------------------------------------- /poshsecframework/Network/NetworksTreeView.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.DirectoryServices.ActiveDirectory; 3 | using System.Windows.Forms; 4 | using PoshSec.Framework.Strings; 5 | 6 | namespace PoshSec.Framework 7 | { 8 | public class NetworksTreeView : TreeView 9 | { 10 | private void Add(TreeNode network) 11 | { 12 | Nodes[0].Nodes.Add(network); 13 | } 14 | 15 | public void Load(Networks networks) 16 | { 17 | SuspendLayout(); 18 | Nodes[0].Nodes.Clear(); 19 | foreach (var network in networks) 20 | { 21 | var name = network.Name; 22 | switch (network) 23 | { 24 | case LocalNetwork _: 25 | Add(new LocalNetworkTreeNode(name)); 26 | break; 27 | case DomainNetwork _: 28 | Add(new DomainNetworkTreeNode(name)); 29 | break; 30 | } 31 | } 32 | 33 | Nodes[0].Expand(); 34 | ResumeLayout(true); 35 | Refresh(); 36 | } 37 | 38 | public int Count => Nodes[0].Nodes.Count; 39 | 40 | private class LocalNetworkTreeNode : TreeNode 41 | { 42 | public LocalNetworkTreeNode(string name) : base(name, 3, 3) 43 | { 44 | Name = name; 45 | Tag = NetworkType.Local; 46 | } 47 | } 48 | 49 | 50 | private class DomainNetworkTreeNode : TreeNode 51 | { 52 | public DomainNetworkTreeNode(string name) : base(name, 3, 3) 53 | { 54 | Name = name; 55 | Tag = NetworkType.Domain; 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /poshsecframework/Network/Syslog.cs: -------------------------------------------------------------------------------- 1 | /* This class was rewritten using syslog.cs, written by Michiel Fortuin, as 2 | * a template. While Michiel's code is not directly in this class, I wanted to 3 | * recognize Michiel for giving me the base template to write this class. 4 | * 5 | * Michiel Fortuin's syslog.cs blog post: http://blog.micfort.org/2011/06/syslog-c.html 6 | * 7 | * */ 8 | using System; 9 | using System.Collections.Generic; 10 | using System.Net; 11 | using System.Net.Sockets; 12 | using System.Text; 13 | using PoshSec.Framework.Strings; 14 | 15 | namespace PoshSec.Framework 16 | { 17 | class Syslog 18 | { 19 | private UdpClient slclient = null; 20 | private IPEndPoint server; 21 | 22 | private enum SyslogLevel 23 | { 24 | Information=6, 25 | Error=3, 26 | Warning=4, 27 | Severe=2, 28 | Critical=1 29 | } 30 | 31 | public Syslog(IPEndPoint Server) 32 | { 33 | server = Server; 34 | slclient = new UdpClient(); 35 | } 36 | 37 | public void Close() 38 | { 39 | slclient.Close(); 40 | } 41 | 42 | public void SendMessage(PShell.psmethods.PSAlert.AlertType AlertLevel, String Source, String Message) 43 | { 44 | int level = (int)GetLevel(AlertLevel) + (20 * 8); //Local4.(AlertLevel) 45 | string priority = String.Format(StringValue.PriorityFormat, level); 46 | string timestamp = DateTime.Now.ToString(StringValue.SyslogTimeFormat); 47 | string hostname = Dns.GetHostName(); 48 | string version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); 49 | List msg = new List(); 50 | string msgstring = String.Format(StringValue.SyslogFormat, priority, timestamp, hostname, StringValue.psftitle.Replace(" ", ""), Source, Message); 51 | msg.AddRange(Encoding.ASCII.GetBytes(msgstring)); 52 | SendMessage(msg.ToArray()); 53 | } 54 | 55 | private void SendMessage(byte[] data) 56 | { 57 | try 58 | { 59 | slclient.Send(data, data.Length, server); 60 | } 61 | catch (Exception e) 62 | { 63 | throw new Exception(e.Message); 64 | } 65 | } 66 | 67 | private SyslogLevel GetLevel(PShell.psmethods.PSAlert.AlertType level) 68 | { 69 | SyslogLevel rtn = SyslogLevel.Information; 70 | bool found = false; 71 | int idx = 0; 72 | int[] sidx = { 1, 2, 3, 4, 6 }; 73 | do 74 | { 75 | SyslogLevel lvl = (SyslogLevel)sidx[idx]; 76 | if (lvl.ToString() == level.ToString()) 77 | { 78 | found = true; 79 | rtn = lvl; 80 | } 81 | idx++; 82 | } while (!found && idx < sidx.Length); 83 | return rtn; 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /poshsecframework/PShell/pscredentialeditor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using System.Collections.Generic; 4 | using System.Collections.ObjectModel; 5 | using System.ComponentModel.Design; 6 | using System.Linq; 7 | using System.Net; 8 | using System.Management.Automation; 9 | using System.Runtime.InteropServices; 10 | using System.Text; 11 | using System.Windows.Forms; 12 | 13 | namespace PoshSec.Framework.PShell 14 | { 15 | class pscredentialeditor : System.Drawing.Design.UITypeEditor 16 | { 17 | [DllImport("credui.dll", CharSet = CharSet.Auto)] 18 | private static extern int CredUIPromptForWindowsCredentials(ref CREDUI_INFO notUsedHere, 19 | int authError, 20 | ref uint authPackage, 21 | IntPtr InAuthBuffer, 22 | uint InAuthBufferSize, 23 | out IntPtr refOutAuthBuffer, 24 | out uint refOutAuthBufferSize, 25 | ref bool fSave, 26 | int flags); 27 | 28 | [DllImport("credui.dll", CharSet = CharSet.Auto)] 29 | private static extern bool CredUnPackAuthenticationBuffer(int dwFlags, 30 | IntPtr pAuthBuffer, 31 | uint cbAuthBuffer, 32 | StringBuilder pszUserName, 33 | ref int pcchMaxUserName, 34 | StringBuilder pszDomainName, 35 | ref int pcchMaxDomainame, 36 | StringBuilder pszPassword, 37 | ref int pcchMaxPassword); 38 | 39 | [DllImport("ole32.dll")] 40 | public static extern void CoTaskMemFree(IntPtr ptr); 41 | 42 | public override System.Drawing.Design.UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context) 43 | { 44 | return System.Drawing.Design.UITypeEditorEditStyle.Modal; 45 | } 46 | 47 | [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] 48 | private struct CREDUI_INFO 49 | { 50 | public int cbSize; 51 | public IntPtr hwndParent; 52 | public string pszMessageText; 53 | public string pszCaptionText; 54 | public IntPtr hbmBanner; 55 | } 56 | 57 | [RefreshProperties(System.ComponentModel.RefreshProperties.All)] 58 | public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) 59 | { 60 | if (context == null || context.Instance == null) 61 | { 62 | return base.EditValue(context, provider, value); 63 | } 64 | else 65 | { 66 | value = null; 67 | NetworkCredential creds = GetCredential(); 68 | if (creds != null) 69 | { 70 | System.Security.SecureString pwd = new System.Security.SecureString(); 71 | foreach(var c in creds.Password) 72 | { 73 | pwd.AppendChar(c); 74 | } 75 | PSCredential rtncrds = new PSCredential(creds.UserName, pwd); 76 | creds = null; 77 | pwd = null; 78 | GC.Collect(); 79 | value = rtncrds; 80 | } 81 | return value; 82 | } 83 | } 84 | 85 | public static NetworkCredential GetCredential() 86 | { 87 | CREDUI_INFO credui = new CREDUI_INFO(); 88 | credui.pszCaptionText = "Please enter the credentials."; 89 | credui.pszMessageText = "DisplayedMessage"; 90 | credui.cbSize = Marshal.SizeOf(credui); 91 | uint authPackage = 0; 92 | IntPtr outCredBuffer = new IntPtr(); 93 | uint outCredSize; 94 | bool save = false; 95 | int result = CredUIPromptForWindowsCredentials(ref credui,0,ref authPackage,IntPtr.Zero,0,out outCredBuffer,out outCredSize,ref save,0x1); 96 | 97 | var usernameBuf = new StringBuilder(100); 98 | var passwordBuf = new StringBuilder(100); 99 | var domainBuf = new StringBuilder(100); 100 | 101 | int maxUserName = 100; 102 | int maxDomain = 100; 103 | int maxPassword = 100; 104 | NetworkCredential netcreds = null; 105 | if (result == 0) 106 | { 107 | if (CredUnPackAuthenticationBuffer(0, outCredBuffer, outCredSize, usernameBuf, ref maxUserName, domainBuf, ref maxDomain, passwordBuf, ref maxPassword)) 108 | { 109 | CoTaskMemFree(outCredBuffer); 110 | netcreds = new NetworkCredential(usernameBuf.ToString(), passwordBuf.ToString(), domainBuf.ToString()); 111 | } 112 | } 113 | 114 | return netcreds; 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /poshsecframework/PShell/pseventargs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Windows.Forms; 6 | 7 | namespace PoshSec.Framework.PShell 8 | { 9 | class pseventargs : EventArgs 10 | { 11 | #region " Private Variables " 12 | private String rslts; 13 | private ListViewItem lvw; 14 | private bool cancelled; 15 | #endregion 16 | 17 | #region " Public Methods " 18 | public pseventargs(String ResultsText, ListViewItem ScriptListView, bool Cancelled) 19 | { 20 | rslts = ResultsText; 21 | lvw = ScriptListView; 22 | cancelled = Cancelled; 23 | } 24 | #endregion 25 | 26 | #region " Public Properties " 27 | public String Results 28 | { 29 | get 30 | { 31 | return rslts; 32 | } 33 | } 34 | 35 | public ListViewItem ScriptListView 36 | { 37 | get { return lvw; } 38 | } 39 | 40 | public bool Cancelled 41 | { 42 | get { return cancelled; } 43 | } 44 | #endregion 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /poshsecframework/PShell/psexception.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Management.Automation.Runspaces; 6 | 7 | namespace PoshSec.Framework.PShell 8 | { 9 | class psexception 10 | { 11 | #region " Public Methods " 12 | public String psexceptionhandler(Exception e, bool iscommand = true, CommandCollection commands = null) 13 | { 14 | String rtn = ""; 15 | if (iscommand) 16 | { 17 | rtn += Environment.NewLine; 18 | } 19 | else 20 | { 21 | rtn += "Script Failed to Run!" + Environment.NewLine + Environment.NewLine; 22 | } 23 | switch (e.GetType().Name) 24 | { 25 | case "PSSecurityException": 26 | rtn += PSSecurityException((System.Management.Automation.PSSecurityException)e); 27 | break; 28 | case "CmdletInvocationException": 29 | rtn += CmdletInvocationException((System.Management.Automation.CmdletInvocationException)e); 30 | break; 31 | case "ParameterBindingException": 32 | rtn += ParameterBindingException((System.Management.Automation.ParameterBindingException)e); 33 | break; 34 | case "ParameterBindingValidationException": 35 | rtn += ParameterBindingValidationException((System.Management.Automation.ParameterBindingException)e); 36 | break; 37 | case "CommandNotFoundException": 38 | rtn += CommandNotFoundException((System.Management.Automation.CommandNotFoundException)e); 39 | break; 40 | default: 41 | rtn += PSException(e); 42 | break; 43 | } 44 | return rtn; 45 | } 46 | #endregion 47 | 48 | #region 49 | private String PSException(Exception e) 50 | { 51 | String rtn = ""; 52 | rtn += "Exception Type: " + e.GetType().ToString() + Environment.NewLine; 53 | rtn += "Message:" + Environment.NewLine; 54 | rtn += e.Message.ToString() + Environment.NewLine; 55 | rtn += "Stack Trace:" + Environment.NewLine; 56 | rtn += e.StackTrace.ToString(); 57 | return rtn; 58 | } 59 | 60 | private String CommandNotFoundException(System.Management.Automation.CommandNotFoundException e) 61 | { 62 | String rtn = e.Message.ToString(); 63 | return rtn; 64 | } 65 | 66 | private String PSSecurityException(System.Management.Automation.PSSecurityException e) 67 | { 68 | String rtn = ""; 69 | rtn += "You need to run the following command from a PowerShell prompt with administrative privileges:" + Environment.NewLine + Environment.NewLine; 70 | rtn += "Set-ExecutionPolicy RemoteSigned" + Environment.NewLine + Environment.NewLine; 71 | rtn += "When asked: " + Environment.NewLine + "Do you want to change the execution policy?" + Environment.NewLine + "[Y] Yes [N] No [S] Suspend [?] Help (default is \"Y\"):" + Environment.NewLine + Environment.NewLine + "Type Y and press enter." + Environment.NewLine + Environment.NewLine; 72 | rtn += "Error Message:" + Environment.NewLine; 73 | rtn += e.Message.ToString(); 74 | return rtn; 75 | } 76 | 77 | private String CmdletInvocationException(System.Management.Automation.CmdletInvocationException e, CommandCollection commands = null) 78 | { 79 | String rtn = ""; 80 | rtn += "There was an error in your script or command. Please see the error message below." + Environment.NewLine + Environment.NewLine; 81 | rtn += "Error Message:" + Environment.NewLine; 82 | rtn += e.Message.ToString() + Environment.NewLine; 83 | rtn += e.ErrorRecord.ScriptStackTrace.Replace(Strings.StringValue.ScriptBlockNoFile, ""); 84 | if (commands != null) 85 | { 86 | rtn += "Commands: " + Environment.NewLine; 87 | foreach (Command cmd in commands) 88 | { 89 | rtn += cmd.CommandText.ToString() + Environment.NewLine; 90 | } 91 | } 92 | return rtn; 93 | } 94 | 95 | private String ParameterBindingException(System.Management.Automation.ParameterBindingException e) 96 | { 97 | String rtn = ""; 98 | rtn += "Missing Parameters!" + Environment.NewLine + Environment.NewLine; 99 | rtn += "Please check the command or script file and ensure that the parameters are defined properly." + Environment.NewLine + Environment.NewLine; 100 | rtn += "Error Message:" + Environment.NewLine; 101 | rtn += e.Message.ToString(); 102 | return rtn; 103 | } 104 | 105 | private String ParameterBindingValidationException(System.Management.Automation.ParameterBindingException e) 106 | { 107 | String rtn = ""; 108 | rtn += "Invalid parameter value!" + Environment.NewLine + Environment.NewLine; 109 | rtn += "You entered an invalid parameter value. Please see the error message below." + Environment.NewLine + Environment.NewLine; 110 | rtn += "Error Message:" + Environment.NewLine; 111 | rtn += e.Message.ToString(); 112 | return rtn; 113 | } 114 | #endregion 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /poshsecframework/PShell/psfhost.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation.Host; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace PoshSec.Framework.PShell 9 | { 10 | class psfhost : PSHost 11 | { 12 | private psfhostinterface psfi; 13 | private Guid gid = Guid.NewGuid(); 14 | private System.Globalization.CultureInfo originalCultureInfo = System.Threading.Thread.CurrentThread.CurrentCulture; 15 | private System.Globalization.CultureInfo originalUICultureInfo = System.Threading.Thread.CurrentThread.CurrentUICulture; 16 | 17 | public psfhost(frmMain parent) 18 | { 19 | psfi = new psfhostinterface(parent); 20 | } 21 | 22 | public override void EnterNestedPrompt() 23 | { 24 | System.Windows.Forms.MessageBox.Show("Enter nested prompt"); 25 | //throw new NotImplementedException(); 26 | } 27 | 28 | public override void ExitNestedPrompt() 29 | { 30 | System.Windows.Forms.MessageBox.Show("Exit nested prompt"); 31 | //throw new NotImplementedException(); 32 | } 33 | 34 | public override void NotifyBeginApplication() 35 | { 36 | return; 37 | } 38 | 39 | public override void NotifyEndApplication() 40 | { 41 | return; 42 | } 43 | 44 | public override void SetShouldExit(int exitCode) 45 | { 46 | 47 | } 48 | 49 | public override PSHostUserInterface UI 50 | { 51 | get { return psfi; } 52 | } 53 | 54 | public override System.Globalization.CultureInfo CurrentCulture 55 | { 56 | get { return originalCultureInfo; } 57 | } 58 | 59 | public override System.Globalization.CultureInfo CurrentUICulture 60 | { 61 | get { return originalUICultureInfo; } 62 | } 63 | 64 | public override Guid InstanceId 65 | { 66 | get { return gid; } 67 | } 68 | 69 | public override string Name 70 | { 71 | get { return "PoshSec Framework"; } 72 | } 73 | 74 | public override System.Management.Automation.PSObject PrivateData 75 | { 76 | get 77 | { 78 | return base.PrivateData; 79 | } 80 | } 81 | 82 | public override System.Version Version 83 | { 84 | // return the powershell version supported, not psf version. 85 | get { return new System.Version(3, 0, 0, 0); } 86 | } 87 | 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /poshsecframework/PShell/psfhostrawinterface.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation.Host; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace PoshSec.Framework.PShell 9 | { 10 | class psfhostrawinterface : PSHostRawUserInterface 11 | { 12 | public override ConsoleColor BackgroundColor 13 | { 14 | get 15 | { 16 | return System.ConsoleColor.Blue; 17 | } 18 | set 19 | { 20 | throw new NotImplementedException(); 21 | } 22 | } 23 | 24 | public override Size BufferSize 25 | { 26 | get 27 | { 28 | return new System.Management.Automation.Host.Size(80, 80); 29 | } 30 | set 31 | { 32 | throw new NotImplementedException(); 33 | } 34 | } 35 | 36 | public override Coordinates CursorPosition 37 | { 38 | get 39 | { 40 | throw new NotImplementedException(); 41 | } 42 | set 43 | { 44 | throw new NotImplementedException(); 45 | } 46 | } 47 | 48 | public override int CursorSize 49 | { 50 | get 51 | { 52 | throw new NotImplementedException(); 53 | } 54 | set 55 | { 56 | throw new NotImplementedException(); 57 | } 58 | } 59 | 60 | public override void FlushInputBuffer() 61 | { 62 | throw new NotImplementedException(); 63 | } 64 | 65 | public override ConsoleColor ForegroundColor 66 | { 67 | get 68 | { 69 | return ConsoleColor.Black; 70 | } 71 | set 72 | { 73 | throw new NotImplementedException(); 74 | } 75 | } 76 | 77 | public override BufferCell[,] GetBufferContents(Rectangle rectangle) 78 | { 79 | throw new NotImplementedException(); 80 | } 81 | 82 | public override bool KeyAvailable 83 | { 84 | get { throw new NotImplementedException(); } 85 | } 86 | 87 | public override Size MaxPhysicalWindowSize 88 | { 89 | get { throw new NotImplementedException(); } 90 | } 91 | 92 | public override Size MaxWindowSize 93 | { 94 | get { throw new NotImplementedException(); } 95 | } 96 | 97 | public override KeyInfo ReadKey(ReadKeyOptions options) 98 | { 99 | throw new NotImplementedException(); 100 | } 101 | 102 | public override void ScrollBufferContents(Rectangle source, Coordinates destination, Rectangle clip, BufferCell fill) 103 | { 104 | throw new NotImplementedException(); 105 | } 106 | 107 | public override void SetBufferContents(Rectangle rectangle, BufferCell fill) 108 | { 109 | throw new NotImplementedException(); 110 | } 111 | 112 | public override void SetBufferContents(Coordinates origin, BufferCell[,] contents) 113 | { 114 | throw new NotImplementedException(); 115 | } 116 | 117 | public override Coordinates WindowPosition 118 | { 119 | get 120 | { 121 | throw new NotImplementedException(); 122 | } 123 | set 124 | { 125 | throw new NotImplementedException(); 126 | } 127 | } 128 | 129 | public override Size WindowSize 130 | { 131 | get 132 | { 133 | throw new NotImplementedException(); 134 | } 135 | set 136 | { 137 | throw new NotImplementedException(); 138 | } 139 | } 140 | 141 | public override string WindowTitle 142 | { 143 | get 144 | { 145 | throw new NotImplementedException(); 146 | } 147 | set 148 | { 149 | throw new NotImplementedException(); 150 | } 151 | } 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /poshsecframework/PShell/psfilenameeditor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.ComponentModel.Design; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Windows.Forms; 8 | 9 | namespace PoshSec.Framework.PShell 10 | { 11 | class psfilenameeditor : System.Drawing.Design.UITypeEditor 12 | { 13 | public override System.Drawing.Design.UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context) 14 | { 15 | return System.Drawing.Design.UITypeEditorEditStyle.Modal; 16 | } 17 | 18 | [RefreshProperties(System.ComponentModel.RefreshProperties.All)] 19 | public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) 20 | { 21 | if (context == null || context.Instance == null) 22 | { 23 | return base.EditValue(context, provider, value); 24 | } 25 | else 26 | { 27 | OpenFileDialog dlg = new OpenFileDialog(); 28 | dlg.Title = "Select " + context.PropertyDescriptor.DisplayName; 29 | dlg.FileName = (string)value; 30 | dlg.Filter = "All Files (*.*)|*.*"; 31 | dlg.CheckFileExists = false; 32 | if (dlg.ShowDialog() == DialogResult.OK) 33 | { 34 | value = dlg.FileName; 35 | } 36 | dlg.Dispose(); 37 | dlg = null; 38 | return value; 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /poshsecframework/PShell/pshosteditor.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using System.Collections.Generic; 4 | using System.Collections.ObjectModel; 5 | using System.ComponentModel.Design; 6 | using System.Linq; 7 | using System.Management.Automation; 8 | using System.Text; 9 | using System.Windows.Forms; 10 | 11 | namespace PoshSec.Framework.PShell 12 | { 13 | class pshosteditor : System.Drawing.Design.UITypeEditor 14 | { 15 | public override System.Drawing.Design.UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context) 16 | { 17 | return System.Drawing.Design.UITypeEditorEditStyle.Modal; 18 | } 19 | 20 | [RefreshProperties(System.ComponentModel.RefreshProperties.All)] 21 | public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) 22 | { 23 | if (context == null || context.Instance == null) 24 | { 25 | return base.EditValue(context, provider, value); 26 | } 27 | else 28 | { 29 | value = null; 30 | Object x = provider; 31 | Interface.frmNetworkBrowser nb = new Interface.frmNetworkBrowser(); 32 | if (nb.ShowDialog() == DialogResult.OK) 33 | { 34 | value = nb.SerializedHosts; 35 | } 36 | nb = null; 37 | return value; 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /poshsecframework/PShell/psparameter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Xml.Serialization; 7 | 8 | namespace PoshSec.Framework.PShell 9 | { 10 | public class psparameter 11 | { 12 | #region " Public Properties " 13 | 14 | #region " Parameter " 15 | [Category("Parameters"), 16 | Browsable(true), 17 | ReadOnly(false), 18 | Bindable(false), 19 | DesignOnly(false)] 20 | public String Name { get; set; } 21 | public String Description { get; set; } 22 | public String Category { get; set; } 23 | public Object Value { get; set; } 24 | public Object DefaultValue { get; set; } 25 | public Boolean IsFileName { get; set; } 26 | public Boolean IsHostList { get; set; } 27 | public Boolean IsCredential { get; set; } 28 | private Type type; 29 | 30 | [XmlIgnore()] 31 | public Type Type 32 | { 33 | get { return type; } 34 | set 35 | { 36 | type = value; 37 | } 38 | } 39 | 40 | public String TypeName 41 | { 42 | get 43 | { 44 | if (Value != null || DefaultValue != null) 45 | { 46 | return (Value ?? DefaultValue).GetType().ToString(); 47 | } 48 | else 49 | { 50 | return ""; 51 | } 52 | } 53 | set { type = System.Type.GetType(value); } 54 | } 55 | #endregion 56 | 57 | #endregion 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /poshsecframework/PShell/psparamtype.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace PoshSec.Framework.PShell 8 | { 9 | [TypeConverter(typeof(psparamtype.psparamobject))] 10 | public class psparamtype 11 | { 12 | [Category("Standard")] 13 | private readonly List psparams = new List(); 14 | 15 | [Browsable(false)] 16 | public List Properties 17 | { 18 | get { return psparams; } 19 | } 20 | 21 | private Dictionary values = new Dictionary(); 22 | 23 | public object this[String name] 24 | { 25 | get 26 | { 27 | object val; 28 | values.TryGetValue(name, out val); 29 | return val; 30 | } 31 | set 32 | { 33 | values.Remove(name); 34 | } 35 | } 36 | 37 | private class psparamobject : ExpandableObjectConverter 38 | { 39 | public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes) 40 | { 41 | var props = base.GetProperties(context, value, attributes); 42 | psparamtype parm = value as psparamtype; 43 | List psprops = null; 44 | int propcnt = props.Count; 45 | if (parm != null) 46 | { 47 | psprops = parm.Properties; 48 | propcnt += psprops.Count; 49 | } 50 | PropertyDescriptor[] psdescs = new PropertyDescriptor[propcnt]; 51 | props.CopyTo(psdescs, 0); 52 | 53 | if (psprops != null) 54 | { 55 | int idx = props.Count; 56 | foreach (psparameter psparam in psprops) 57 | { 58 | psdescs[idx++] = new psparamdescriptor(psparam); 59 | } 60 | } 61 | return new PropertyDescriptorCollection(psdescs); 62 | } 63 | } 64 | 65 | private class psparamdescriptor : PropertyDescriptor 66 | { 67 | private readonly psparameter psparam; 68 | 69 | public psparamdescriptor(psparameter psparam) : base(psparam.Name, null) 70 | { 71 | this.psparam = psparam; 72 | } 73 | 74 | public override string Category 75 | { 76 | get { return psparam.Category; } 77 | } 78 | 79 | public override string Description 80 | { 81 | get { return psparam.Description; } 82 | } 83 | 84 | public override string Name 85 | { 86 | get { return psparam.Name; } 87 | } 88 | 89 | public override bool ShouldSerializeValue(object component) 90 | { 91 | return ((psparamtype)component)[psparam.Name] != null; 92 | } 93 | 94 | public override void ResetValue(object component) 95 | { 96 | ((psparamtype)component)[psparam.Name] = null; 97 | } 98 | 99 | public override bool IsReadOnly 100 | { 101 | get { return false; } 102 | } 103 | 104 | public override Type PropertyType 105 | { 106 | get { return psparam.Type; } 107 | } 108 | 109 | public override bool CanResetValue(object component) 110 | { 111 | return true; 112 | } 113 | 114 | public override Type ComponentType 115 | { 116 | get { return typeof(psparamtype); } 117 | } 118 | 119 | public override void SetValue(object component, object value) 120 | { 121 | psparam.Value = value; 122 | } 123 | 124 | public override object GetValue(object component) 125 | { 126 | return psparam.Value ?? psparam.DefaultValue ; 127 | } 128 | 129 | public override object GetEditor(Type editorBaseType) 130 | { 131 | if (psparam.IsFileName) 132 | { 133 | return new psfilenameeditor(); 134 | } 135 | else if (psparam.IsHostList) 136 | { 137 | return new pshosteditor(); 138 | } 139 | else if (psparam.IsCredential) 140 | { 141 | return new pscredentialeditor(); 142 | } 143 | else 144 | { 145 | return base.GetEditor(editorBaseType); 146 | } 147 | } 148 | } 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /poshsecframework/PShell/psvariables.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Management.Automation; 5 | using System.Text; 6 | using PoshSec.Framework.Properties; 7 | 8 | namespace PoshSec.Framework.PShell 9 | { 10 | class psvariables 11 | { 12 | public class PSRoot : PSVariable 13 | { 14 | private String psroot = Settings.Default.ScriptPath; 15 | 16 | public PSRoot(string name): base(name) { } 17 | 18 | public override Object Value 19 | { 20 | get { return psroot; } 21 | } 22 | } 23 | 24 | public class PSModRoot : PSVariable 25 | { 26 | private String psmodroot = Settings.Default.ModulePath; 27 | 28 | public PSModRoot(string name) : base(name) { } 29 | 30 | public override Object Value 31 | { 32 | get { return psmodroot; } 33 | } 34 | } 35 | 36 | public class PSFramework : PSVariable 37 | { 38 | private String psf = Settings.Default.GithubAPIKey; 39 | 40 | public PSFramework(string name) : base(name) { } 41 | 42 | public override Object Value 43 | { 44 | get { return psf; } 45 | } 46 | } 47 | 48 | public class PSExec : PSVariable 49 | { 50 | private String psexec = Settings.Default.PSExecPath; 51 | 52 | public PSExec(string name) : base(name) { } 53 | 54 | public override Object Value 55 | { 56 | get { return psexec; } 57 | } 58 | } 59 | 60 | public class PSScheduleFile : PSVariable 61 | { 62 | private String schedulefile = Settings.Default.ScheduleFile; 63 | 64 | public PSScheduleFile(string name) : base(name) { } 65 | 66 | public override Object Value 67 | { 68 | get { return schedulefile; } 69 | } 70 | } 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /poshsecframework/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Windows.Forms; 4 | using System.Net; 5 | using PoshSec.Framework.Interface; 6 | 7 | namespace PoshSec.Framework 8 | { 9 | static class Program 10 | { 11 | /// 12 | /// The main entry point for the application. 13 | /// 14 | [STAThread] 15 | static void Main() 16 | { 17 | ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11; 18 | SetDefaultWebProxy(); 19 | 20 | try 21 | { 22 | Application.EnableVisualStyles(); 23 | Application.SetCompatibleTextRenderingDefault(false); 24 | Application.Run(new frmMain()); 25 | } 26 | catch (Exception e) 27 | { 28 | //Safety Net 29 | //This is a global exception handler. 30 | MessageBox.Show("Unhandled Exception" + Environment.NewLine + e.Message + Environment.NewLine + "Stack Trace: " + Environment.NewLine + e.StackTrace, "Unhandled Exception. Program Will Halt."); 31 | Application.Exit(); 32 | } 33 | } 34 | 35 | public static void SetDefaultWebProxy() 36 | { 37 | var proxyPreference = Properties.Settings.Default.ProxyPreference; 38 | switch (proxyPreference) 39 | { 40 | case ProxyPreference.System: 41 | WebRequest.DefaultWebProxy = WebRequest.GetSystemWebProxy(); 42 | break; 43 | case ProxyPreference.None: 44 | WebRequest.DefaultWebProxy = null; 45 | break; 46 | case ProxyPreference.Manual: 47 | var host = Properties.Settings.Default.ProxyHost; 48 | var port = Properties.Settings.Default.ProxyPort; 49 | if (!string.IsNullOrWhiteSpace(host) && port > 0) 50 | WebRequest.DefaultWebProxy = new WebProxy(host, port); 51 | else if (!string.IsNullOrWhiteSpace(host)) 52 | WebRequest.DefaultWebProxy = new WebProxy(host); 53 | else 54 | WebRequest.DefaultWebProxy = new WebProxy(); 55 | break; 56 | default: 57 | break; 58 | } 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /poshsecframework/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("poshsecframework")] 9 | [assembly: AssemblyDescription("PoshSec Framework")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("PoshSec")] 12 | [assembly: AssemblyProduct("poshsecframework")] 13 | [assembly: AssemblyCopyright("Copyright © 2013")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("78bfcfc2-ef1c-4514-bce6-934b251666d2")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | [assembly: AssemblyVersion("1.0.0.0")] 33 | [assembly: AssemblyFileVersion("1.0.0.0")] 34 | -------------------------------------------------------------------------------- /poshsecframework/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | .\Scripts\ 7 | 8 | 9 | 10 | 11 | 12 | .\Modules\ 13 | 14 | 15 | 0 16 | 17 | 18 | 19 | 20 | 21 | .\Scripts\schedule.xml 22 | 23 | 24 | True 25 | 26 | 27 | <?xml version="1.0" encoding="utf-16"?> 28 | <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 29 | <string>PoshSec|PoshSec/PoshSec|PoshSec|</string> 30 | </ArrayOfString> 31 | 32 | 33 | True 34 | 35 | 36 | 37 | 38 | 39 | True 40 | 41 | 42 | 43 | 44 | 45 | True 46 | 47 | 48 | .\Logs\psfoutput.log 49 | 50 | 51 | True 52 | 53 | 54 | .\Logs\psfalerts.log 55 | 56 | 57 | 58 | 59 | 60 | False 61 | 62 | 63 | 64 | 65 | 66 | 514 67 | 68 | 69 | True 70 | 71 | 72 | 73 | 74 | 75 | 0 76 | 77 | 78 | System 79 | 80 | 81 | -------------------------------------------------------------------------------- /poshsecframework/Resources/Diagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/Diagram.png -------------------------------------------------------------------------------- /poshsecframework/Resources/Server.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/Server.png -------------------------------------------------------------------------------- /poshsecframework/Resources/Server1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/Server1.png -------------------------------------------------------------------------------- /poshsecframework/Resources/ServerExecute.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/ServerExecute.png -------------------------------------------------------------------------------- /poshsecframework/Resources/application-x-powershellscript.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/application-x-powershellscript.png -------------------------------------------------------------------------------- /poshsecframework/Resources/application-x-shellscript.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/application-x-shellscript.png -------------------------------------------------------------------------------- /poshsecframework/Resources/application-x-shellscript1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/application-x-shellscript1.png -------------------------------------------------------------------------------- /poshsecframework/Resources/caret_underline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/caret_underline.png -------------------------------------------------------------------------------- /poshsecframework/Resources/computer-add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/computer-add.png -------------------------------------------------------------------------------- /poshsecframework/Resources/computer-delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/computer-delete.png -------------------------------------------------------------------------------- /poshsecframework/Resources/dialog-accept.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/dialog-accept.png -------------------------------------------------------------------------------- /poshsecframework/Resources/dialog-cancel-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/dialog-cancel-5.png -------------------------------------------------------------------------------- /poshsecframework/Resources/dialog-error-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/dialog-error-3.png -------------------------------------------------------------------------------- /poshsecframework/Resources/dialog-error-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/dialog-error-4.png -------------------------------------------------------------------------------- /poshsecframework/Resources/dialog-information-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/dialog-information-4.png -------------------------------------------------------------------------------- /poshsecframework/Resources/dialog-no-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/dialog-no-2.png -------------------------------------------------------------------------------- /poshsecframework/Resources/dialog-warning-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/dialog-warning-2.png -------------------------------------------------------------------------------- /poshsecframework/Resources/dialog-warning-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/dialog-warning-3.png -------------------------------------------------------------------------------- /poshsecframework/Resources/dialog-yes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/dialog-yes.png -------------------------------------------------------------------------------- /poshsecframework/Resources/document-export-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/document-export-4.png -------------------------------------------------------------------------------- /poshsecframework/Resources/document-import.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/document-import.png -------------------------------------------------------------------------------- /poshsecframework/Resources/document-open-7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/document-open-7.png -------------------------------------------------------------------------------- /poshsecframework/Resources/document-open-folder.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/document-open-folder.png -------------------------------------------------------------------------------- /poshsecframework/Resources/edit-clear-list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/edit-clear-list.png -------------------------------------------------------------------------------- /poshsecframework/Resources/edit-delete-6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/edit-delete-6.png -------------------------------------------------------------------------------- /poshsecframework/Resources/exclamation.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/exclamation.png -------------------------------------------------------------------------------- /poshsecframework/Resources/help.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/help.png -------------------------------------------------------------------------------- /poshsecframework/Resources/network-transmit-receive-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/network-transmit-receive-2.png -------------------------------------------------------------------------------- /poshsecframework/Resources/page-white_add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/page-white_add.png -------------------------------------------------------------------------------- /poshsecframework/Resources/page-white_delete.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/page-white_delete.png -------------------------------------------------------------------------------- /poshsecframework/Resources/page-white_edit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/page-white_edit.png -------------------------------------------------------------------------------- /poshsecframework/Resources/page-white_get.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/page-white_get.png -------------------------------------------------------------------------------- /poshsecframework/Resources/psf_logo_rev1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/psf_logo_rev1.png -------------------------------------------------------------------------------- /poshsecframework/Resources/psficon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/psficon.ico -------------------------------------------------------------------------------- /poshsecframework/Resources/psficonalert.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/psficonalert.ico -------------------------------------------------------------------------------- /poshsecframework/Resources/run.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/run.png -------------------------------------------------------------------------------- /poshsecframework/Resources/system-run-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/system-run-3.png -------------------------------------------------------------------------------- /poshsecframework/Resources/system-run-31.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/system-run-31.png -------------------------------------------------------------------------------- /poshsecframework/Resources/system-settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/system-settings.png -------------------------------------------------------------------------------- /poshsecframework/Resources/tab-close-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/tab-close-3.png -------------------------------------------------------------------------------- /poshsecframework/Resources/table-save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/table-save.png -------------------------------------------------------------------------------- /poshsecframework/Resources/tag-blue.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/tag-blue.png -------------------------------------------------------------------------------- /poshsecframework/Resources/tag-green.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/tag-green.png -------------------------------------------------------------------------------- /poshsecframework/Resources/tag-red.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/tag-red.png -------------------------------------------------------------------------------- /poshsecframework/Resources/test.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/test.png -------------------------------------------------------------------------------- /poshsecframework/Resources/view-calendar-tasks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/view-calendar-tasks.png -------------------------------------------------------------------------------- /poshsecframework/Resources/view-refresh-7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PoshSec/PoshSecFramework/f8c3847bf538dc5db4b3ee0801722146d1e1e286/poshsecframework/Resources/view-refresh-7.png -------------------------------------------------------------------------------- /poshsecframework/Scans/ScanIpEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace PoshSec.Framework 4 | { 5 | internal class ScanIpEventArgs : EventArgs 6 | { 7 | public ScanIpEventArgs(string ipAddress, string hostname, bool isUp, int index) 8 | { 9 | IpAddress = ipAddress; 10 | Hostname = hostname; 11 | IsUp = isUp; 12 | Index = index; 13 | } 14 | 15 | public string IpAddress { get; } 16 | 17 | public string Hostname { get; } 18 | 19 | public bool IsUp { get; } 20 | 21 | public int Index { get; } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /poshsecframework/Scans/ScanStatusEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace PoshSec.Framework 4 | { 5 | public class ScanStatusEventArgs : EventArgs 6 | { 7 | public ScanStatusEventArgs(string status, int currentIndex, int maxIndex) 8 | { 9 | Status = status; 10 | CurrentIndex = currentIndex; 11 | MaxIndex = maxIndex; 12 | } 13 | 14 | public string Status { get; } 15 | 16 | public int CurrentIndex { get; } 17 | 18 | public int MaxIndex { get; } 19 | } 20 | } -------------------------------------------------------------------------------- /poshsecframework/Settings.cs: -------------------------------------------------------------------------------- 1 | namespace PoshSec.Framework.Properties { 2 | 3 | 4 | // This class allows you to handle specific events on the settings class: 5 | // The SettingChanging event is raised before a setting's value is changed. 6 | // The PropertyChanged event is raised after a setting's value is changed. 7 | // The SettingsLoaded event is raised after the setting values are loaded. 8 | // The SettingsSaving event is raised before the setting values are saved. 9 | internal sealed partial class Settings { 10 | 11 | public Settings() { 12 | // // To add event handlers for saving and changing settings, uncomment the lines below: 13 | // 14 | // this.SettingChanging += this.SettingChangingEventHandler; 15 | // 16 | this.SettingsSaving += this.SettingsSavingEventHandler; 17 | // 18 | } 19 | 20 | private void SettingChangingEventHandler(object sender, System.Configuration.SettingChangingEventArgs e) { 21 | // Add code to handle the SettingChangingEvent event here. 22 | } 23 | 24 | private void SettingsSavingEventHandler(object sender, System.ComponentModel.CancelEventArgs e) { 25 | // Add code to handle the SettingsSaving event here. 26 | Program.SetDefaultWebProxy(); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /poshsecframework/Settings/AppSettings.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Management.Automation; 4 | using System.Windows.Forms; 5 | using Newtonsoft.Json; 6 | 7 | namespace PoshSec.Framework 8 | { 9 | public class AppSettings where TSettings : class, new() 10 | { 11 | private static string _settingsDirectory = Application.LocalUserAppDataPath; 12 | private static string _settingsFilename = "settings.json"; 13 | 14 | private static JsonSerializerSettings _serializerSettings = new JsonSerializerSettings 15 | { 16 | TypeNameHandling = TypeNameHandling.Auto, 17 | Formatting = Formatting.Indented 18 | }; 19 | 20 | public static string Path => System.IO.Path.Combine(_settingsDirectory, _settingsFilename); 21 | 22 | public static TSettings Load(string path = "") 23 | { 24 | path = HandlePath(path); 25 | 26 | if (!File.Exists(path)) 27 | return new TSettings(); 28 | 29 | var text = File.ReadAllText(path); 30 | var settings = JsonConvert.DeserializeObject(text, _serializerSettings) ?? new TSettings(); 31 | SavePath(path); 32 | 33 | return settings; 34 | } 35 | 36 | public static void Save(TSettings settings, string path = "") 37 | { 38 | path = HandlePath(path); 39 | var text = JsonConvert.SerializeObject(settings, _serializerSettings); 40 | File.WriteAllText(path, text); 41 | 42 | SavePath(path); 43 | } 44 | 45 | private static void SavePath(string path) 46 | { 47 | _settingsDirectory = System.IO.Path.GetDirectoryName(path); 48 | _settingsFilename = System.IO.Path.GetFileName(path); 49 | } 50 | 51 | private static string HandlePath(string path) 52 | { 53 | if (string.IsNullOrWhiteSpace(path)) 54 | path = System.IO.Path.Combine(_settingsDirectory, _settingsFilename); 55 | var filename = System.IO.Path.GetFileName(path); 56 | if (string.IsNullOrWhiteSpace(filename)) 57 | filename = _settingsFilename; 58 | var directory = System.IO.Path.GetDirectoryName(path) ?? _settingsDirectory; 59 | if (string.IsNullOrWhiteSpace(directory)) 60 | directory = _settingsDirectory; 61 | path = System.IO.Path.Combine(directory, filename); 62 | return path; 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /poshsecframework/Systems/CurrentNetworkChangedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace PoshSec.Framework 4 | { 5 | public class CurrentNetworkChangedEventArgs : EventArgs 6 | { 7 | public Network Network { get; } 8 | 9 | public CurrentNetworkChangedEventArgs(Network network) 10 | { 11 | Network = network; 12 | } 13 | } 14 | } -------------------------------------------------------------------------------- /poshsecframework/Systems/DomainNetwork.cs: -------------------------------------------------------------------------------- 1 | namespace PoshSec.Framework 2 | { 3 | public class DomainNetwork : Network 4 | { 5 | public DomainNetwork(string name) 6 | { 7 | Name = name; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /poshsecframework/Systems/INetworkNode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | 4 | namespace PoshSec.Framework 5 | { 6 | public interface INetworkNode 7 | { 8 | string Name { get; set; } 9 | IPAddress IpAddress { get; set; } 10 | string MacAddress { get; set; } 11 | string Description { get; set; } 12 | string Status { get; set; } 13 | string ClientInstalled { get; set; } 14 | int Alerts { get; set; } 15 | DateTime LastScanned { get; set; } 16 | } 17 | } -------------------------------------------------------------------------------- /poshsecframework/Systems/IPAddressConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | using Newtonsoft.Json; 4 | 5 | namespace PoshSec.Framework 6 | { 7 | public class IPAddressConverter : JsonConverter 8 | { 9 | public override bool CanConvert(Type objectType) 10 | { 11 | return (objectType == typeof(IPAddress)); 12 | } 13 | 14 | public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) 15 | { 16 | writer.WriteValue(value.ToString()); 17 | } 18 | 19 | public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) 20 | { 21 | return IPAddress.Parse((string)reader.Value); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /poshsecframework/Systems/LocalNetwork.cs: -------------------------------------------------------------------------------- 1 | namespace PoshSec.Framework 2 | { 3 | public class LocalNetwork : Network 4 | { 5 | public LocalNetwork() 6 | { 7 | Name = "Local Network"; 8 | } 9 | } 10 | } -------------------------------------------------------------------------------- /poshsecframework/Systems/Network.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Concurrent; 2 | using System.Collections.Generic; 3 | using Newtonsoft.Json; 4 | 5 | namespace PoshSec.Framework 6 | { 7 | [JsonObject] 8 | public abstract class Network 9 | { 10 | public static Network Empty { get; } 11 | 12 | static Network() 13 | { 14 | Empty = new EmptyNetwork(); 15 | } 16 | 17 | [JsonProperty("Name")] 18 | public string Name { get; set; } 19 | 20 | [JsonProperty("Nodes")] 21 | public ConcurrentBag Nodes { get; protected set; } 22 | 23 | protected Network() 24 | { 25 | Nodes = new ConcurrentBag(); 26 | } 27 | 28 | private class EmptyNetwork : Network 29 | { 30 | } 31 | 32 | public override string ToString() 33 | { 34 | return Name; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /poshsecframework/Systems/NetworkNode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | using Newtonsoft.Json; 4 | using Newtonsoft.Json.Serialization; 5 | 6 | namespace PoshSec.Framework 7 | { 8 | [JsonObject] 9 | public class NetworkNode : INetworkNode 10 | { 11 | [JsonProperty("Name")] 12 | public string Name { get; set; } 13 | 14 | [JsonConverter(typeof(IPAddressConverter))] 15 | public IPAddress IpAddress { get; set; } 16 | 17 | [JsonProperty("MacAddress")] 18 | public string MacAddress { get; set; } 19 | 20 | [JsonProperty("Description")] 21 | public string Description { get; set; } 22 | 23 | [JsonIgnore] 24 | public string Status { get; set; } 25 | 26 | [JsonProperty("ClientInstalled")] 27 | public string ClientInstalled { get; set; } 28 | 29 | [JsonIgnore] 30 | public int Alerts { get; set; } 31 | 32 | [JsonProperty("LastScanned")] 33 | public DateTime LastScanned { get; set; } 34 | } 35 | } -------------------------------------------------------------------------------- /poshsecframework/Systems/Networks.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | 5 | namespace PoshSec.Framework 6 | { 7 | public class Networks : List 8 | { 9 | private Network _currentNetwork; 10 | 11 | public Networks() 12 | { 13 | _currentNetwork = Network.Empty; 14 | } 15 | 16 | public event EventHandler CurrentNetworkChanged; 17 | 18 | public Network CurrentNetwork 19 | { 20 | get => _currentNetwork; 21 | set 22 | { 23 | _currentNetwork = value ?? Network.Empty; 24 | OnCurrentNetworkChanged(_currentNetwork); 25 | 26 | } 27 | } 28 | 29 | private void OnCurrentNetworkChanged(Network network) 30 | { 31 | var handler = CurrentNetworkChanged; 32 | handler?.Invoke(this, new CurrentNetworkChangedEventArgs(network)); 33 | } 34 | 35 | public bool IsValid(string name) 36 | { 37 | return this.All(n => n.Name != name); 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /poshsecframework/Systems/SystemsAddedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | 4 | namespace PoshSec.Framework 5 | { 6 | public class SystemsAddedEventArgs 7 | { 8 | public IEnumerable Items { get; } 9 | 10 | public SystemsAddedEventArgs(IEnumerable items) 11 | { 12 | Items = items; 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /poshsecframework/Systems/SystemsListView.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Windows.Forms; 5 | 6 | namespace PoshSec.Framework 7 | { 8 | public class SystemsListView : ListView 9 | { 10 | public event EventHandler SystemsAdded; 11 | private bool _loadExecuting; 12 | 13 | private void Add(SystemsListViewItem item) 14 | { 15 | Items.Add(item); 16 | if (!_loadExecuting) 17 | OnSystemsAdded(); 18 | } 19 | 20 | public void Add(INetworkNode system) 21 | { 22 | var item = new SystemsListViewItem(system); 23 | Add(item); 24 | } 25 | 26 | public bool IsValid(string systemName) 27 | { 28 | var isUnique = Items.Cast().All(i => i.Text != systemName); 29 | return isUnique; 30 | } 31 | 32 | public void Load(IEnumerable networkNodes) 33 | { 34 | _loadExecuting = true; 35 | BeginUpdate(); 36 | Items.Clear(); 37 | foreach (var node in networkNodes) 38 | { 39 | Add(node); 40 | } 41 | EndUpdate(); 42 | Refresh(); 43 | OnSystemsAdded(); 44 | _loadExecuting = false; 45 | } 46 | 47 | protected virtual void OnSystemsAdded() 48 | { 49 | SystemsAdded?.Invoke(this, new SystemsAddedEventArgs(Items.OfType())); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /poshsecframework/Systems/SystemsListViewItem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net; 3 | using System.Windows.Forms; 4 | using PoshSec.Framework.Strings; 5 | 6 | namespace PoshSec.Framework 7 | { 8 | public class SystemsListViewItem : ListViewItem, INetworkNode 9 | { 10 | private SystemsListViewItem() 11 | { 12 | ImageIndex = 2; 13 | SubItems.Add(new ListViewSubItem(this,string.Empty){Name = "ip"}); 14 | SubItems.Add(new ListViewSubItem(this,string.Empty){Name = "mac"}); 15 | SubItems.Add(new ListViewSubItem(this,string.Empty){Name = "description"}); 16 | SubItems.Add(new ListViewSubItem(this,string.Empty){Name = "status"}); 17 | SubItems.Add(new ListViewSubItem(this,string.Empty){Name = "installed"}); 18 | SubItems.Add(new ListViewSubItem(this,string.Empty){Name = "alerts"}); 19 | SubItems.Add(new ListViewSubItem(this,string.Empty){Name = "lastscanned"}); 20 | } 21 | 22 | public SystemsListViewItem(INetworkNode node) : this() 23 | { 24 | Name = node.Name; 25 | Text = node.Name; 26 | IpAddress = node.IpAddress; 27 | MacAddress = node.MacAddress; 28 | Description = node.Description; 29 | Status = node.Status; 30 | ClientInstalled = node.ClientInstalled; 31 | Alerts = node.Alerts; 32 | LastScanned = node.LastScanned; 33 | } 34 | 35 | public IPAddress IpAddress 36 | { 37 | get => IPAddress.TryParse(SubItems["ip"].Text, out var ipAddress) ? ipAddress : null; 38 | set => SubItems["ip"].Text = value.ToString(); 39 | } 40 | 41 | public string MacAddress 42 | { 43 | get => SubItems["mac"].Text; 44 | set => SubItems["mac"].Text = value; 45 | } 46 | 47 | public string Description 48 | { 49 | get => SubItems["description"].Text; 50 | set => SubItems["description"].Text = value; 51 | } 52 | 53 | public string Status 54 | { 55 | get => SubItems["status"].Text; 56 | set => SubItems["status"].Text = value; 57 | } 58 | 59 | public string ClientInstalled 60 | { 61 | get => SubItems["installed"].Text; 62 | set => SubItems["installed"].Text = value; 63 | } 64 | 65 | public int Alerts 66 | { 67 | get => int.Parse(SubItems["alerts"].Text); 68 | set => SubItems["alerts"].Text = value.ToString(); 69 | } 70 | 71 | public DateTime LastScanned 72 | { 73 | get => DateTime.Parse(SubItems["lastscanned"].Text); 74 | set => SubItems["lastscanned"].Text = value.ToString(StringValue.TimeFormat); 75 | } 76 | } 77 | } -------------------------------------------------------------------------------- /poshsecframework/Utility/AlertFilter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace PoshSec.Framework.Utility 8 | { 9 | internal static class AlertFilter 10 | { 11 | static bool info = true; 12 | static bool error = true; 13 | static bool warning = true; 14 | static bool severe = true; 15 | static bool critical = true; 16 | 17 | public static bool Informational 18 | { 19 | get { return info; } 20 | set { info = value; } 21 | } 22 | 23 | public static bool Error 24 | { 25 | get { return error; } 26 | set { error = value; } 27 | } 28 | 29 | public static bool Warning 30 | { 31 | get { return warning; } 32 | set { warning = value; } 33 | } 34 | 35 | public static bool Severe 36 | { 37 | get { return severe; } 38 | set { severe = value; } 39 | } 40 | 41 | public static bool Critical 42 | { 43 | get { return critical; } 44 | set { critical = value; } 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /poshsecframework/Utility/ExportObject.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Collections.ObjectModel; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Management.Automation; 7 | using System.Xml; 8 | using System.Text; 9 | using System.Windows.Forms; 10 | using PoshSec.Framework.Enums; 11 | 12 | namespace PoshSec.Framework.Utility 13 | { 14 | class ExportObject 15 | { 16 | public void XML(System.Object[] CustomObject, String filename) 17 | { 18 | try 19 | { 20 | if (CustomObject != null && CustomObject.Count() > 0) 21 | { 22 | if (CustomObject[0].GetType() == typeof(PSObject)) 23 | { 24 | StreamWriter outfile = File.CreateText(filename); 25 | XmlTextWriter xmlwtr = new XmlTextWriter(outfile); 26 | xmlwtr.Formatting = Formatting.Indented; 27 | xmlwtr.WriteStartDocument(); 28 | xmlwtr.WriteStartElement("Collection"); 29 | foreach (PSObject pobj in CustomObject) 30 | { 31 | xmlwtr.WriteStartElement("PSObject"); 32 | foreach (PSPropertyInfo prop in pobj.Properties) 33 | { 34 | if (prop != null) 35 | { 36 | xmlwtr.WriteStartElement("PSNoteProperty"); 37 | xmlwtr.WriteAttributeString("Name", prop.Name); 38 | try 39 | { 40 | xmlwtr.WriteAttributeString("Value", (prop.Value ?? "").ToString()); 41 | } 42 | catch (GetValueException) 43 | { 44 | xmlwtr.WriteAttributeString("Value", ""); 45 | } 46 | xmlwtr.WriteEndElement(); 47 | } 48 | } 49 | xmlwtr.WriteEndElement(); 50 | } 51 | 52 | xmlwtr.WriteEndElement(); 53 | xmlwtr.WriteEndDocument(); 54 | xmlwtr.Flush(); 55 | xmlwtr.Close(); 56 | xmlwtr = null; 57 | } 58 | } 59 | } 60 | catch (Exception e) 61 | { 62 | if (e.InnerException != null) 63 | { 64 | MessageBox.Show("Unable to export object." + Environment.NewLine + e.Message + Environment.NewLine + e.InnerException.Message); 65 | } 66 | else 67 | { 68 | MessageBox.Show("Unable to export object." + Environment.NewLine + e.Message); 69 | } 70 | } 71 | } 72 | 73 | public void CSV(System.Object[] CustomObject, String filename) 74 | { 75 | ExportDelim(CustomObject, filename, ","); 76 | } 77 | 78 | public void TXT(System.Object[] CustomObject, String filename) 79 | { 80 | ExportDelim(CustomObject, filename, "\t"); 81 | } 82 | 83 | private void ExportDelim(System.Object[] CustomObject, String filename, String Delimiter) 84 | { 85 | try 86 | { 87 | if (CustomObject != null && CustomObject.Count() > 0) 88 | { 89 | if (CustomObject[0].GetType() == typeof(PSObject)) 90 | { 91 | StreamWriter outfile = File.CreateText(filename); 92 | int idx = -1; 93 | foreach (PSObject pobj in CustomObject) 94 | { 95 | idx++; 96 | if (idx == 0) 97 | { 98 | //Header Row 99 | String header = ""; 100 | foreach (PSPropertyInfo prop in pobj.Properties) 101 | { 102 | if (prop != null) 103 | { 104 | header += prop.Name + Delimiter; 105 | } 106 | } 107 | if (header.EndsWith(Delimiter)) 108 | { 109 | header = header.Substring(0, header.Length - 1); 110 | } 111 | outfile.WriteLine(header); 112 | outfile.Flush(); 113 | } 114 | String value = ""; 115 | foreach (PSPropertyInfo prop in pobj.Properties) 116 | { 117 | if (prop != null) 118 | { 119 | try 120 | { 121 | value += prop.Value + Delimiter; 122 | } 123 | catch (GetValueException) 124 | { 125 | value += "" + Delimiter; 126 | } 127 | } 128 | } 129 | if (value.EndsWith(Delimiter)) 130 | { 131 | value = value.Substring(0, value.Length - 1); 132 | } 133 | outfile.WriteLine(value); 134 | outfile.Flush(); 135 | } 136 | 137 | outfile.Flush(); 138 | outfile.Close(); 139 | outfile = null; 140 | } 141 | } 142 | } 143 | catch (Exception e) 144 | { 145 | if (e.InnerException != null) 146 | { 147 | MessageBox.Show("Unable to export object." + Environment.NewLine + e.Message + Environment.NewLine + e.InnerException.Message); 148 | } 149 | else 150 | { 151 | MessageBox.Show("Unable to export object." + Environment.NewLine + e.Message); 152 | } 153 | } 154 | } 155 | } 156 | } 157 | -------------------------------------------------------------------------------- /poshsecframework/Utility/ScheduleItem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using PoshSec.Framework.Enums; 6 | using PoshSec.Framework.PShell; 7 | 8 | namespace PoshSec.Framework.Utility 9 | { 10 | public class ScheduleItem 11 | { 12 | private String scriptname = ""; 13 | private String scriptpath = ""; 14 | private psparamtype param = new psparamtype(); 15 | private ScheduleTime schedtime = null; 16 | private EnumValues.RunAs runas = EnumValues.RunAs.CurrentUser; 17 | private String lastrun = "Never"; 18 | private String msg = ""; 19 | private int idx; 20 | 21 | public String ScriptName 22 | { 23 | get { return scriptname; } 24 | set { scriptname = value; } 25 | } 26 | 27 | public String ScriptPath 28 | { 29 | get { return scriptpath; } 30 | set { scriptpath = value; } 31 | } 32 | 33 | public psparamtype Parameters 34 | { 35 | get { return param; } 36 | set { param = value; } 37 | } 38 | 39 | public ScheduleTime ScheduledTime 40 | { 41 | get { return schedtime; } 42 | set { schedtime = value; } 43 | } 44 | 45 | public EnumValues.RunAs RunAs 46 | { 47 | get { return runas; } 48 | set { runas = value; } 49 | } 50 | 51 | public String LastRunTime 52 | { 53 | get { return lastrun; } 54 | set { lastrun = value; } 55 | } 56 | 57 | public String Message 58 | { 59 | get { return msg; } 60 | set { msg = value; } 61 | } 62 | 63 | public int Index 64 | { 65 | get { return idx; } 66 | set { idx = value; } 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /poshsecframework/Utility/ScheduleTime.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using PoshSec.Framework.Enums; 6 | 7 | namespace PoshSec.Framework.Utility 8 | { 9 | public class ScheduleTime 10 | { 11 | public DateTime StartTime { get; set; } 12 | public DateTime StartDate { get; set; } 13 | public EnumValues.TimeFrequency Frequency { get; set; } 14 | public List DaysofWeek { get; set; } 15 | public List Months { get; set; } 16 | public List Dates { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /poshsecframework/Web/GithubJsonItem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Reflection; 6 | 7 | namespace PoshSec.Framework.Web 8 | { 9 | class GithubJsonItem 10 | { 11 | #region Private Variables 12 | private string _name = ""; 13 | private string _path = ""; 14 | private string _sha = ""; 15 | private string _size = ""; 16 | private string _url = ""; 17 | private string _html_url = ""; 18 | private string _git_url = ""; 19 | private string _type = ""; 20 | private string _content = ""; 21 | private string _encoding = ""; 22 | private string _date = ""; 23 | #endregion 24 | 25 | #region Public Methods 26 | public GithubJsonItem(String json) 27 | { 28 | json = json.Replace("{", "").Replace("}", ""); 29 | string[] elements = json.Split(','); 30 | if (elements != null && elements.Count() > 0) 31 | { 32 | foreach (string element in elements) 33 | { 34 | AssignValue(element); 35 | } 36 | } 37 | } 38 | #endregion 39 | 40 | #region Private Methods 41 | private void AssignValue(string element) 42 | { 43 | String[] split = new String[] { "\":" }; 44 | string[] elemvalue = element.Split(split, StringSplitOptions.None); 45 | if (elemvalue != null && elemvalue.Count() > 0) 46 | { 47 | FieldInfo[] fields = typeof(GithubJsonItem).GetFields(BindingFlags.Instance | BindingFlags.NonPublic); 48 | if (fields != null && fields.Count() > 0) 49 | { 50 | bool found = false; 51 | int idx = 0; 52 | do 53 | { 54 | FieldInfo field = fields[idx]; 55 | if (field.Name.Replace("_", "") == elemvalue[0].Replace("_", "").Replace("\"", "")) 56 | { 57 | found = true; 58 | field.SetValue(this, elemvalue[1].Replace("\"", "")); 59 | } 60 | idx++; 61 | } while (!found && idx < fields.Count()); 62 | } 63 | } 64 | } 65 | #endregion 66 | 67 | #region Public Properties 68 | public string Name { get { return _name; } } 69 | public string Path { get { return _path; } } 70 | public string SHA { get { return _sha; } } 71 | public string Size { get { return _size; } } 72 | public string URL { get { return _url; } } 73 | public string HTML_URL { get { return _html_url; } } 74 | public string Git_URL { get { return _git_url; } } 75 | public string Type { get { return _type; } } 76 | public string Content { get { return _content; } } 77 | public string Encoding { get { return _encoding; } } 78 | public string Date { get { return _date; } } 79 | #endregion 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /poshsecframework/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
6 |
7 | 8 | 9 | 10 | 11 | 12 | .\Scripts\ 13 | 14 | 15 | 16 | 17 | 18 | .\Modules\ 19 | 20 | 21 | 0 22 | 23 | 24 | 25 | 26 | 27 | .\Scripts\schedule.xml 28 | 29 | 30 | True 31 | 32 | 33 | 34 | 36 | PoshSec|PoshSec/PoshSec|PoshSec| 37 | 38 | 39 | 40 | 41 | True 42 | 43 | 44 | True 45 | 46 | 47 | 48 | 49 | 50 | True 51 | 52 | 53 | .\Logs\psfoutput.log 54 | 55 | 56 | True 57 | 58 | 59 | .\Logs\psfalerts.log 60 | 61 | 62 | False 63 | 64 | 65 | 66 | 67 | 68 | 514 69 | 70 | 71 | True 72 | 73 | 74 | 75 | 76 | 77 | 0 78 | 79 | 80 | 81 | 82 | .\Scripts\ 83 | 84 | 85 | 86 | 87 | 88 | .\Modules\ 89 | 90 | 91 | 0 92 | 93 | 94 | 95 | 96 | 97 | .\Scripts\schedule.xml 98 | 99 | 100 | True 101 | 102 | 103 | 104 | 105 | PoshSec|PoshSec/PoshSec|PoshSec| 106 | 107 | 108 | 109 | 110 | True 111 | 112 | 113 | True 114 | 115 | 116 | 117 | 118 | 119 | True 120 | 121 | 122 | .\Logs\psfoutput.log 123 | 124 | 125 | True 126 | 127 | 128 | .\Logs\psfalerts.log 129 | 130 | 131 | False 132 | 133 | 134 | 135 | 136 | 137 | 514 138 | 139 | 140 | True 141 | 142 | 143 | 144 | 145 | 146 | 0 147 | 148 | 149 | System 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | -------------------------------------------------------------------------------- /poshsecframework/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /poshsecframework/poshsecframework.csproj.DotSettings: -------------------------------------------------------------------------------- 1 |  2 | True 3 | True 4 | True 5 | True 6 | True --------------------------------------------------------------------------------